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