1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "chromeos/chromeos_export.h"
12 #include "chromeos/dbus/dbus_client.h"
13 #include "chromeos/dbus/dbus_method_call_status.h"
14 #include "chromeos/dbus/shill_client_helper.h"
24 class ShillPropertyChangedObserver
;
26 // ShillManagerClient is used to communicate with the Shill Manager
27 // service. All methods should be called from the origin thread which
28 // initializes the DBusThreadManager instance.
29 class CHROMEOS_EXPORT ShillManagerClient
: public DBusClient
{
31 typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler
;
32 typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback
;
33 typedef ShillClientHelper::ErrorCallback ErrorCallback
;
34 typedef ShillClientHelper::StringCallback StringCallback
;
35 typedef ShillClientHelper::BooleanCallback BooleanCallback
;
37 // Interface for setting up devices, services, and technologies for testing.
38 // Accessed through GetTestInterface(), only implemented in the Stub Impl.
41 virtual void AddDevice(const std::string
& device_path
) = 0;
42 virtual void RemoveDevice(const std::string
& device_path
) = 0;
43 virtual void ClearDevices() = 0;
44 virtual void AddTechnology(const std::string
& type
, bool enabled
) = 0;
45 virtual void RemoveTechnology(const std::string
& type
) = 0;
46 virtual void SetTechnologyInitializing(const std::string
& type
,
47 bool initializing
) = 0;
48 virtual void AddGeoNetwork(const std::string
& technology
,
49 const base::DictionaryValue
& network
) = 0;
51 // Does not create an actual profile in the ProfileClient but update the
52 // profiles list and sends a notification to observers. This should only be
53 // called by the ProfileStub. In all other cases, use
54 // ShillProfileClient::TestInterface::AddProfile.
55 virtual void AddProfile(const std::string
& profile_path
) = 0;
57 // Used to reset all properties; does not notify observers.
58 virtual void ClearProperties() = 0;
60 // Set manager property.
61 virtual void SetManagerProperty(const std::string
& key
,
62 const base::Value
& value
) = 0;
64 // Modify services in the Manager's list.
65 virtual void AddManagerService(const std::string
& service_path
,
66 bool notify_observers
) = 0;
67 virtual void RemoveManagerService(const std::string
& service_path
) = 0;
68 virtual void ClearManagerServices() = 0;
70 // Called by ShillServiceClient when a service's State property changes,
71 // before notifying observers. Sets the DefaultService property to empty
72 // if the state changes to a non-connected state.
73 virtual void ServiceStateChanged(const std::string
& service_path
,
74 const std::string
& state
) = 0;
76 // Called by ShillServiceClient when a service's State or Visibile
77 // property changes. If |notify| is true, notifies observers if a list
78 // changed. Services are sorted first by active, inactive, or disabled
79 // state, then by type.
80 virtual void SortManagerServices(bool notify
) = 0;
82 // Sets up the default fake environment based on default initial states
83 // or states provided by the command line.
84 virtual void SetupDefaultEnvironment() = 0;
86 // Returns the interactive delay specified on the command line, 0 for none.
87 virtual int GetInteractiveDelay() const = 0;
89 // Sets the 'best' service to connect to on a ConnectToBestServices call.
90 virtual void SetBestServiceToConnect(const std::string
& service_path
) = 0;
93 virtual ~TestInterface() {}
96 // Properties used to verify the origin device.
97 struct VerificationProperties
{
98 VerificationProperties();
99 ~VerificationProperties();
101 // A string containing a PEM-encoded X.509 certificate for use in verifying
103 std::string certificate
;
105 // A string containing a PEM-encoded RSA public key to be used to compare
106 // with the one in signedData
107 std::string public_key
;
109 // A string containing a base64-encoded random binary data for use in
110 // verifying the signed data.
113 // A string containing the identifying data string signed by the device.
114 std::string signed_data
;
116 // A string containing the serial number of the device.
117 std::string device_serial
;
119 // A string containing the SSID of the device. Only set if the device has
120 // already been setup once.
121 std::string device_ssid
;
123 // A string containing the BSSID of the device. Only set if the device has
124 // already been setup.
125 std::string device_bssid
;
128 virtual ~ShillManagerClient();
130 // Factory function, creates a new instance which is owned by the caller.
131 // For normal usage, access the singleton via DBusThreadManager::Get().
132 static ShillManagerClient
* Create();
134 // Adds a property changed |observer|.
135 virtual void AddPropertyChangedObserver(
136 ShillPropertyChangedObserver
* observer
) = 0;
138 // Removes a property changed |observer|.
139 virtual void RemovePropertyChangedObserver(
140 ShillPropertyChangedObserver
* observer
) = 0;
142 // Calls GetProperties method.
143 // |callback| is called after the method call succeeds.
144 virtual void GetProperties(const DictionaryValueCallback
& callback
) = 0;
146 // Calls GetNetworksForGeolocation method.
147 // |callback| is called after the method call succeeds.
148 virtual void GetNetworksForGeolocation(
149 const DictionaryValueCallback
& callback
) = 0;
151 // Calls SetProperty method.
152 // |callback| is called after the method call succeeds.
153 virtual void SetProperty(const std::string
& name
,
154 const base::Value
& value
,
155 const base::Closure
& callback
,
156 const ErrorCallback
& error_callback
) = 0;
158 // Calls RequestScan method.
159 // |callback| is called after the method call succeeds.
160 virtual void RequestScan(const std::string
& type
,
161 const base::Closure
& callback
,
162 const ErrorCallback
& error_callback
) = 0;
164 // Calls EnableTechnology method.
165 // |callback| is called after the method call succeeds.
166 virtual void EnableTechnology(const std::string
& type
,
167 const base::Closure
& callback
,
168 const ErrorCallback
& error_callback
) = 0;
170 // Calls DisableTechnology method.
171 // |callback| is called after the method call succeeds.
172 virtual void DisableTechnology(const std::string
& type
,
173 const base::Closure
& callback
,
174 const ErrorCallback
& error_callback
) = 0;
176 // Calls ConfigureService method.
177 // |callback| is called after the method call succeeds.
178 virtual void ConfigureService(const base::DictionaryValue
& properties
,
179 const ObjectPathCallback
& callback
,
180 const ErrorCallback
& error_callback
) = 0;
182 // Calls ConfigureServiceForProfile method.
183 // |callback| is called with the created service if the method call succeeds.
184 virtual void ConfigureServiceForProfile(
185 const dbus::ObjectPath
& profile_path
,
186 const base::DictionaryValue
& properties
,
187 const ObjectPathCallback
& callback
,
188 const ErrorCallback
& error_callback
) = 0;
190 // Calls GetService method.
191 // |callback| is called after the method call succeeds.
192 virtual void GetService(const base::DictionaryValue
& properties
,
193 const ObjectPathCallback
& callback
,
194 const ErrorCallback
& error_callback
) = 0;
196 // Verify that the given data corresponds to a trusted device, and return true
197 // to the callback if it is.
198 virtual void VerifyDestination(const VerificationProperties
& properties
,
199 const BooleanCallback
& callback
,
200 const ErrorCallback
& error_callback
) = 0;
202 // Verify that the given data corresponds to a trusted device, and if it is,
203 // return the encrypted credentials for connecting to the network represented
204 // by the given |service_path|, encrypted using the |public_key| for the
205 // trusted device. If the device is not trusted, return the empty string.
206 virtual void VerifyAndEncryptCredentials(
207 const VerificationProperties
& properties
,
208 const std::string
& service_path
,
209 const StringCallback
& callback
,
210 const ErrorCallback
& error_callback
) = 0;
212 // Verify that the given data corresponds to a trusted device, and return the
213 // |data| encrypted using the |public_key| for the trusted device. If the
214 // device is not trusted, return the empty string.
215 virtual void VerifyAndEncryptData(const VerificationProperties
& properties
,
216 const std::string
& data
,
217 const StringCallback
& callback
,
218 const ErrorCallback
& error_callback
) = 0;
220 // For each technology present, connect to the "best" service available.
221 // Called once the user is logged in and certificates are loaded.
222 virtual void ConnectToBestServices(const base::Closure
& callback
,
223 const ErrorCallback
& error_callback
) = 0;
225 // Returns an interface for testing (stub only), or returns NULL.
226 virtual TestInterface
* GetTestInterface() = 0;
229 friend class ShillManagerClientTest
;
231 // Create() should be used instead.
232 ShillManagerClient();
235 DISALLOW_COPY_AND_ASSIGN(ShillManagerClient
);
238 } // namespace chromeos
240 #endif // CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_