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. 4 5#ifndef CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_ 6#define CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_ 7 8#include <string> 9 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" 15 16namespace dbus { 17 18class ObjectPath; 19 20} // namespace dbus 21 22namespace chromeos { 23 24class ShillPropertyChangedObserver; 25 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. 29class CHROMEOS_EXPORT ShillManagerClient : public DBusClient { 30 public: 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; 36 37 // Interface for setting up devices, services, and technologies for testing. 38 // Accessed through GetTestInterface(), only implemented in the Stub Impl. 39 class TestInterface { 40 public: 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; 50 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; 56 57 // Used to reset all properties; does not notify observers. 58 virtual void ClearProperties() = 0; 59 60 // Add/Remove/ClearService should only be called from ShillServiceClient. 61 virtual void AddManagerService(const std::string& service_path, 62 bool add_to_visible_list, 63 bool add_to_watch_list) = 0; 64 virtual void RemoveManagerService(const std::string& service_path) = 0; 65 virtual void ClearManagerServices() = 0; 66 67 // Called by ShillServiceClient when a service's State property changes. 68 // Services are sorted first by Active vs. Inactive State, then by Type. 69 virtual void SortManagerServices() = 0; 70 71 protected: 72 virtual ~TestInterface() {} 73 }; 74 75 // Properties used to verify the origin device. 76 struct VerificationProperties { 77 VerificationProperties(); 78 ~VerificationProperties(); 79 80 // A string containing a PEM-encoded X.509 certificate for use in verifying 81 // the signed data. 82 std::string certificate; 83 84 // A string containing a PEM-encoded RSA public key to be used to compare 85 // with the one in signedData 86 std::string public_key; 87 88 // A string containing a base64-encoded random binary data for use in 89 // verifying the signed data. 90 std::string nonce; 91 92 // A string containing the identifying data string signed by the device. 93 std::string signed_data; 94 95 // A string containing the serial number of the device. 96 std::string device_serial; 97 98 // A string containing the SSID of the device. Only set if the device has 99 // already been setup once. 100 std::string device_ssid; 101 102 // A string containing the BSSID of the device. Only set if the device has 103 // already been setup. 104 std::string device_bssid; 105 }; 106 107 virtual ~ShillManagerClient(); 108 109 // Factory function, creates a new instance which is owned by the caller. 110 // For normal usage, access the singleton via DBusThreadManager::Get(). 111 static ShillManagerClient* Create(); 112 113 // Adds a property changed |observer|. 114 virtual void AddPropertyChangedObserver( 115 ShillPropertyChangedObserver* observer) = 0; 116 117 // Removes a property changed |observer|. 118 virtual void RemovePropertyChangedObserver( 119 ShillPropertyChangedObserver* observer) = 0; 120 121 // Calls GetProperties method. 122 // |callback| is called after the method call succeeds. 123 virtual void GetProperties(const DictionaryValueCallback& callback) = 0; 124 125 // Calls GetNetworksForGeolocation method. 126 // |callback| is called after the method call succeeds. 127 virtual void GetNetworksForGeolocation( 128 const DictionaryValueCallback& callback) = 0; 129 130 // Calls SetProperty method. 131 // |callback| is called after the method call succeeds. 132 virtual void SetProperty(const std::string& name, 133 const base::Value& value, 134 const base::Closure& callback, 135 const ErrorCallback& error_callback) = 0; 136 137 // Calls RequestScan method. 138 // |callback| is called after the method call succeeds. 139 virtual void RequestScan(const std::string& type, 140 const base::Closure& callback, 141 const ErrorCallback& error_callback) = 0; 142 143 // Calls EnableTechnology method. 144 // |callback| is called after the method call succeeds. 145 virtual void EnableTechnology(const std::string& type, 146 const base::Closure& callback, 147 const ErrorCallback& error_callback) = 0; 148 149 // Calls DisableTechnology method. 150 // |callback| is called after the method call succeeds. 151 virtual void DisableTechnology(const std::string& type, 152 const base::Closure& callback, 153 const ErrorCallback& error_callback) = 0; 154 155 // Calls ConfigureService method. 156 // |callback| is called after the method call succeeds. 157 virtual void ConfigureService(const base::DictionaryValue& properties, 158 const ObjectPathCallback& callback, 159 const ErrorCallback& error_callback) = 0; 160 161 // Calls ConfigureServiceForProfile method. 162 // |callback| is called with the created service if the method call succeeds. 163 virtual void ConfigureServiceForProfile( 164 const dbus::ObjectPath& profile_path, 165 const base::DictionaryValue& properties, 166 const ObjectPathCallback& callback, 167 const ErrorCallback& error_callback) = 0; 168 169 // Calls GetService method. 170 // |callback| is called after the method call succeeds. 171 virtual void GetService(const base::DictionaryValue& properties, 172 const ObjectPathCallback& callback, 173 const ErrorCallback& error_callback) = 0; 174 175 // Verify that the given data corresponds to a trusted device, and return true 176 // to the callback if it is. 177 virtual void VerifyDestination(const VerificationProperties& properties, 178 const BooleanCallback& callback, 179 const ErrorCallback& error_callback) = 0; 180 181 // Verify that the given data corresponds to a trusted device, and if it is, 182 // return the encrypted credentials for connecting to the network represented 183 // by the given |service_path|, encrypted using the |public_key| for the 184 // trusted device. If the device is not trusted, return the empty string. 185 virtual void VerifyAndEncryptCredentials( 186 const VerificationProperties& properties, 187 const std::string& service_path, 188 const StringCallback& callback, 189 const ErrorCallback& error_callback) = 0; 190 191 // Verify that the given data corresponds to a trusted device, and return the 192 // |data| encrypted using the |public_key| for the trusted device. If the 193 // device is not trusted, return the empty string. 194 virtual void VerifyAndEncryptData(const VerificationProperties& properties, 195 const std::string& data, 196 const StringCallback& callback, 197 const ErrorCallback& error_callback) = 0; 198 199 // For each technology present, connect to the "best" service available. 200 // Called once the user is logged in and certificates are loaded. 201 virtual void ConnectToBestServices(const base::Closure& callback, 202 const ErrorCallback& error_callback) = 0; 203 204 // Returns an interface for testing (stub only), or returns NULL. 205 virtual TestInterface* GetTestInterface() = 0; 206 207 protected: 208 friend class ShillManagerClientTest; 209 210 // Create() should be used instead. 211 ShillManagerClient(); 212 213 private: 214 DISALLOW_COPY_AND_ASSIGN(ShillManagerClient); 215}; 216 217} // namespace chromeos 218 219#endif // CHROMEOS_DBUS_SHILL_MANAGER_CLIENT_H_ 220