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 // Add/Remove/ClearService should only be called from ShillServiceClient.
65 virtual void AddManagerService(const std::string
& service_path
,
66 bool add_to_visible_list
,
67 bool add_to_watch_list
) = 0;
68 virtual void RemoveManagerService(const std::string
& service_path
) = 0;
69 virtual void ClearManagerServices() = 0;
71 // Called by ShillServiceClient when a service's State property changes,
72 // before notifying observers. Sets the DefaultService property to empty
73 // if the state changes to a non-connected state.
74 virtual void ServiceStateChanged(const std::string
& service_path
,
75 const std::string
& state
) = 0;
77 // Called by ShillServiceClient when a service's State property changes,
78 // after notifying observers. Services are sorted first by Active or
79 // Inactive State, then by Type.
80 virtual void SortManagerServices() = 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;
90 virtual ~TestInterface() {}
93 // Properties used to verify the origin device.
94 struct VerificationProperties
{
95 VerificationProperties();
96 ~VerificationProperties();
98 // A string containing a PEM-encoded X.509 certificate for use in verifying
100 std::string certificate
;
102 // A string containing a PEM-encoded RSA public key to be used to compare
103 // with the one in signedData
104 std::string public_key
;
106 // A string containing a base64-encoded random binary data for use in
107 // verifying the signed data.
110 // A string containing the identifying data string signed by the device.
111 std::string signed_data
;
113 // A string containing the serial number of the device.
114 std::string device_serial
;
116 // A string containing the SSID of the device. Only set if the device has
117 // already been setup once.
118 std::string device_ssid
;
120 // A string containing the BSSID of the device. Only set if the device has
121 // already been setup.
122 std::string device_bssid
;
125 virtual ~ShillManagerClient();
127 // Factory function, creates a new instance which is owned by the caller.
128 // For normal usage, access the singleton via DBusThreadManager::Get().
129 static ShillManagerClient
* Create();
131 // Adds a property changed |observer|.
132 virtual void AddPropertyChangedObserver(
133 ShillPropertyChangedObserver
* observer
) = 0;
135 // Removes a property changed |observer|.
136 virtual void RemovePropertyChangedObserver(
137 ShillPropertyChangedObserver
* observer
) = 0;
139 // Calls GetProperties method.
140 // |callback| is called after the method call succeeds.
141 virtual void GetProperties(const DictionaryValueCallback
& callback
) = 0;
143 // Calls GetNetworksForGeolocation method.
144 // |callback| is called after the method call succeeds.
145 virtual void GetNetworksForGeolocation(
146 const DictionaryValueCallback
& callback
) = 0;
148 // Calls SetProperty method.
149 // |callback| is called after the method call succeeds.
150 virtual void SetProperty(const std::string
& name
,
151 const base::Value
& value
,
152 const base::Closure
& callback
,
153 const ErrorCallback
& error_callback
) = 0;
155 // Calls RequestScan method.
156 // |callback| is called after the method call succeeds.
157 virtual void RequestScan(const std::string
& type
,
158 const base::Closure
& callback
,
159 const ErrorCallback
& error_callback
) = 0;
161 // Calls EnableTechnology method.
162 // |callback| is called after the method call succeeds.
163 virtual void EnableTechnology(const std::string
& type
,
164 const base::Closure
& callback
,
165 const ErrorCallback
& error_callback
) = 0;
167 // Calls DisableTechnology method.
168 // |callback| is called after the method call succeeds.
169 virtual void DisableTechnology(const std::string
& type
,
170 const base::Closure
& callback
,
171 const ErrorCallback
& error_callback
) = 0;
173 // Calls ConfigureService method.
174 // |callback| is called after the method call succeeds.
175 virtual void ConfigureService(const base::DictionaryValue
& properties
,
176 const ObjectPathCallback
& callback
,
177 const ErrorCallback
& error_callback
) = 0;
179 // Calls ConfigureServiceForProfile method.
180 // |callback| is called with the created service if the method call succeeds.
181 virtual void ConfigureServiceForProfile(
182 const dbus::ObjectPath
& profile_path
,
183 const base::DictionaryValue
& properties
,
184 const ObjectPathCallback
& callback
,
185 const ErrorCallback
& error_callback
) = 0;
187 // Calls GetService method.
188 // |callback| is called after the method call succeeds.
189 virtual void GetService(const base::DictionaryValue
& properties
,
190 const ObjectPathCallback
& callback
,
191 const ErrorCallback
& error_callback
) = 0;
193 // Verify that the given data corresponds to a trusted device, and return true
194 // to the callback if it is.
195 virtual void VerifyDestination(const VerificationProperties
& properties
,
196 const BooleanCallback
& callback
,
197 const ErrorCallback
& error_callback
) = 0;
199 // Verify that the given data corresponds to a trusted device, and if it is,
200 // return the encrypted credentials for connecting to the network represented
201 // by the given |service_path|, encrypted using the |public_key| for the
202 // trusted device. If the device is not trusted, return the empty string.
203 virtual void VerifyAndEncryptCredentials(
204 const VerificationProperties
& properties
,
205 const std::string
& service_path
,
206 const StringCallback
& callback
,
207 const ErrorCallback
& error_callback
) = 0;
209 // Verify that the given data corresponds to a trusted device, and return the
210 // |data| encrypted using the |public_key| for the trusted device. If the
211 // device is not trusted, return the empty string.
212 virtual void VerifyAndEncryptData(const VerificationProperties
& properties
,
213 const std::string
& data
,
214 const StringCallback
& callback
,
215 const ErrorCallback
& error_callback
) = 0;
217 // For each technology present, connect to the "best" service available.
218 // Called once the user is logged in and certificates are loaded.
219 virtual void ConnectToBestServices(const base::Closure
& callback
,
220 const ErrorCallback
& error_callback
) = 0;
222 // Returns an interface for testing (stub only), or returns NULL.
223 virtual TestInterface
* GetTestInterface() = 0;
226 friend class ShillManagerClientTest
;
228 // Create() should be used instead.
229 ShillManagerClient();
232 DISALLOW_COPY_AND_ASSIGN(ShillManagerClient
);
235 } // namespace chromeos
237 #endif // CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_