| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/shill_device_client.h" | 5 #include "chromeos/dbus/shill_device_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // The ShillDeviceClient implementation. | 22 // The ShillDeviceClient implementation. |
| 23 class ShillDeviceClientImpl : public ShillDeviceClient { | 23 class ShillDeviceClientImpl : public ShillDeviceClient { |
| 24 public: | 24 public: |
| 25 explicit ShillDeviceClientImpl(dbus::Bus* bus) | 25 explicit ShillDeviceClientImpl(dbus::Bus* bus) |
| 26 : bus_(bus), | 26 : bus_(bus), |
| 27 helpers_deleter_(&helpers_) { | 27 helpers_deleter_(&helpers_) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 /////////////////////////////////////// | 30 /////////////////////////////////////// |
| 31 // ShillDeviceClient overrides. | 31 // ShillDeviceClient overrides. |
| 32 virtual void SetPropertyChangedHandler( | 32 virtual void AddPropertyChangedObserver( |
| 33 const dbus::ObjectPath& device_path, | 33 const dbus::ObjectPath& device_path, |
| 34 const PropertyChangedHandler& handler) OVERRIDE { | 34 PropertyChangedObserver* observer) OVERRIDE { |
| 35 GetHelper(device_path)->SetPropertyChangedHandler(handler); | 35 GetHelper(device_path)->AddPropertyChangedObserver(observer); |
| 36 } | 36 } |
| 37 | 37 |
| 38 virtual void ResetPropertyChangedHandler( | 38 virtual void RemovePropertyChangedObserver( |
| 39 const dbus::ObjectPath& device_path) OVERRIDE { | 39 const dbus::ObjectPath& device_path, |
| 40 GetHelper(device_path)->ResetPropertyChangedHandler(); | 40 PropertyChangedObserver* observer) OVERRIDE { |
| 41 GetHelper(device_path)->RemovePropertyChangedObserver(observer); |
| 41 } | 42 } |
| 42 | 43 |
| 43 virtual void GetProperties(const dbus::ObjectPath& device_path, | 44 virtual void GetProperties(const dbus::ObjectPath& device_path, |
| 44 const DictionaryValueCallback& callback) OVERRIDE { | 45 const DictionaryValueCallback& callback) OVERRIDE { |
| 45 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, | 46 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, |
| 46 flimflam::kGetPropertiesFunction); | 47 flimflam::kGetPropertiesFunction); |
| 47 GetHelper(device_path)->CallDictionaryValueMethod(&method_call, callback); | 48 GetHelper(device_path)->CallDictionaryValueMethod(&method_call, callback); |
| 48 } | 49 } |
| 49 | 50 |
| 50 virtual base::DictionaryValue* CallGetPropertiesAndBlock( | 51 virtual base::DictionaryValue* CallGetPropertiesAndBlock( |
| 51 const dbus::ObjectPath& device_path) OVERRIDE { | 52 const dbus::ObjectPath& device_path) OVERRIDE { |
| 52 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, | 53 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, |
| 53 flimflam::kGetPropertiesFunction); | 54 flimflam::kGetPropertiesFunction); |
| 54 return GetHelper(device_path)->CallDictionaryValueMethodAndBlock( | 55 return GetHelper(device_path)->CallDictionaryValueMethodAndBlock( |
| 55 &method_call); | 56 &method_call); |
| 56 } | 57 } |
| 57 | 58 |
| 58 virtual void ProposeScan(const dbus::ObjectPath& device_path, | 59 virtual void ProposeScan(const dbus::ObjectPath& device_path, |
| 59 const VoidDBusMethodCallback& callback) OVERRIDE { | 60 const VoidDBusMethodCallback& callback) OVERRIDE { |
| 60 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, | 61 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, |
| 61 flimflam::kProposeScanFunction); | 62 flimflam::kProposeScanFunction); |
| 62 GetHelper(device_path)->CallVoidMethod(&method_call, callback); | 63 GetHelper(device_path)->CallVoidMethod(&method_call, callback); |
| 63 } | 64 } |
| 64 | 65 |
| 65 virtual void SetProperty(const dbus::ObjectPath& device_path, | 66 virtual void SetProperty(const dbus::ObjectPath& device_path, |
| 66 const std::string& name, | 67 const std::string& name, |
| 67 const base::Value& value, | 68 const base::Value& value, |
| 68 const VoidDBusMethodCallback& callback) OVERRIDE { | 69 const base::Closure& callback, |
| 70 const ErrorCallback& error_callback) OVERRIDE { |
| 69 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, | 71 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, |
| 70 flimflam::kSetPropertyFunction); | 72 flimflam::kSetPropertyFunction); |
| 71 dbus::MessageWriter writer(&method_call); | 73 dbus::MessageWriter writer(&method_call); |
| 72 writer.AppendString(name); | 74 writer.AppendString(name); |
| 73 ShillClientHelper::AppendValueDataAsVariant(&writer, value); | 75 ShillClientHelper::AppendValueDataAsVariant(&writer, value); |
| 74 GetHelper(device_path)->CallVoidMethod(&method_call, callback); | 76 GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call, |
| 77 callback, |
| 78 error_callback); |
| 75 } | 79 } |
| 76 | 80 |
| 77 virtual void ClearProperty(const dbus::ObjectPath& device_path, | 81 virtual void ClearProperty(const dbus::ObjectPath& device_path, |
| 78 const std::string& name, | 82 const std::string& name, |
| 79 const VoidDBusMethodCallback& callback) OVERRIDE { | 83 const VoidDBusMethodCallback& callback) OVERRIDE { |
| 80 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, | 84 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, |
| 81 flimflam::kClearPropertyFunction); | 85 flimflam::kClearPropertyFunction); |
| 82 dbus::MessageWriter writer(&method_call); | 86 dbus::MessageWriter writer(&method_call); |
| 83 writer.AppendString(name); | 87 writer.AppendString(name); |
| 84 GetHelper(device_path)->CallVoidMethod(&method_call, callback); | 88 GetHelper(device_path)->CallVoidMethod(&method_call, callback); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 base::Value::CreateStringValue(":stub.0")); | 232 base::Value::CreateStringValue(":stub.0")); |
| 229 cellular_properties->SetWithoutPathExpansion( | 233 cellular_properties->SetWithoutPathExpansion( |
| 230 flimflam::kDBusObjectProperty, | 234 flimflam::kDBusObjectProperty, |
| 231 base::Value::CreateStringValue( | 235 base::Value::CreateStringValue( |
| 232 "/org/freedesktop/ModemManager1/stub/0")); | 236 "/org/freedesktop/ModemManager1/stub/0")); |
| 233 stub_devices_.Set(kStubCellular2, cellular_properties); | 237 stub_devices_.Set(kStubCellular2, cellular_properties); |
| 234 } | 238 } |
| 235 | 239 |
| 236 virtual ~ShillDeviceClientStubImpl() {} | 240 virtual ~ShillDeviceClientStubImpl() {} |
| 237 | 241 |
| 238 // ShillDeviceClient override. | 242 /////////////////////////////////// |
| 239 virtual void SetPropertyChangedHandler( | 243 // ShillDeviceClient overrides. |
| 244 virtual void AddPropertyChangedObserver( |
| 240 const dbus::ObjectPath& device_path, | 245 const dbus::ObjectPath& device_path, |
| 241 const PropertyChangedHandler& handler) OVERRIDE {} | 246 PropertyChangedObserver* observer) OVERRIDE {} |
| 242 | 247 |
| 243 // ShillDeviceClient override. | 248 virtual void RemovePropertyChangedObserver( |
| 244 virtual void ResetPropertyChangedHandler( | 249 const dbus::ObjectPath& device_path, |
| 245 const dbus::ObjectPath& device_path) OVERRIDE {} | 250 PropertyChangedObserver* observer) OVERRIDE {} |
| 246 | 251 |
| 247 // ShillDeviceClient override. | |
| 248 virtual void GetProperties(const dbus::ObjectPath& device_path, | 252 virtual void GetProperties(const dbus::ObjectPath& device_path, |
| 249 const DictionaryValueCallback& callback) OVERRIDE { | 253 const DictionaryValueCallback& callback) OVERRIDE { |
| 250 MessageLoop::current()->PostTask( | 254 MessageLoop::current()->PostTask( |
| 251 FROM_HERE, | 255 FROM_HERE, |
| 252 base::Bind(&ShillDeviceClientStubImpl::PassStubDevicePrperties, | 256 base::Bind(&ShillDeviceClientStubImpl::PassStubDeviceProperties, |
| 253 weak_ptr_factory_.GetWeakPtr(), | 257 weak_ptr_factory_.GetWeakPtr(), |
| 254 device_path, callback)); | 258 device_path, callback)); |
| 255 } | 259 } |
| 256 | 260 |
| 257 // ShillDeviceClient override. | |
| 258 virtual base::DictionaryValue* CallGetPropertiesAndBlock( | 261 virtual base::DictionaryValue* CallGetPropertiesAndBlock( |
| 259 const dbus::ObjectPath& device_path) OVERRIDE { | 262 const dbus::ObjectPath& device_path) OVERRIDE { |
| 260 return new base::DictionaryValue; | 263 return new base::DictionaryValue; |
| 261 } | 264 } |
| 262 | 265 |
| 263 // ShillProfileClient override. | |
| 264 virtual void ProposeScan(const dbus::ObjectPath& device_path, | 266 virtual void ProposeScan(const dbus::ObjectPath& device_path, |
| 265 const VoidDBusMethodCallback& callback) OVERRIDE { | 267 const VoidDBusMethodCallback& callback) OVERRIDE { |
| 266 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); | 268 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); |
| 267 } | 269 } |
| 268 | 270 |
| 269 // ShillDeviceClient override. | |
| 270 virtual void SetProperty(const dbus::ObjectPath& device_path, | 271 virtual void SetProperty(const dbus::ObjectPath& device_path, |
| 271 const std::string& name, | 272 const std::string& name, |
| 272 const base::Value& value, | 273 const base::Value& value, |
| 273 const VoidDBusMethodCallback& callback) OVERRIDE { | 274 const base::Closure& callback, |
| 275 const ErrorCallback& error_callback) OVERRIDE { |
| 274 base::DictionaryValue* device_properties = NULL; | 276 base::DictionaryValue* device_properties = NULL; |
| 275 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { | 277 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { |
| 276 PostVoidCallback(callback, DBUS_METHOD_CALL_FAILURE); | 278 std::string error_name("org.chromium.flimflam.Error.Failure"); |
| 279 std::string error_message("Failed"); |
| 280 MessageLoop::current()->PostTask(FROM_HERE, |
| 281 base::Bind(error_callback, |
| 282 error_name, |
| 283 error_message)); |
| 277 return; | 284 return; |
| 278 } | 285 } |
| 279 device_properties->Set(name, value.DeepCopy()); | 286 device_properties->Set(name, value.DeepCopy()); |
| 280 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); | 287 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 281 } | 288 } |
| 282 | 289 |
| 283 // ShillDeviceClient override. | |
| 284 virtual void ClearProperty(const dbus::ObjectPath& device_path, | 290 virtual void ClearProperty(const dbus::ObjectPath& device_path, |
| 285 const std::string& name, | 291 const std::string& name, |
| 286 const VoidDBusMethodCallback& callback) OVERRIDE { | 292 const VoidDBusMethodCallback& callback) OVERRIDE { |
| 287 base::DictionaryValue* device_properties = NULL; | 293 base::DictionaryValue* device_properties = NULL; |
| 288 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { | 294 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { |
| 289 PostVoidCallback(callback, DBUS_METHOD_CALL_FAILURE); | 295 PostVoidCallback(callback, DBUS_METHOD_CALL_FAILURE); |
| 290 return; | 296 return; |
| 291 } | 297 } |
| 292 device_properties->Remove(name, NULL); | 298 device_properties->Remove(name, NULL); |
| 293 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); | 299 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); |
| 294 } | 300 } |
| 295 | 301 |
| 296 // ShillDeviceClient override. | |
| 297 virtual void AddIPConfig( | 302 virtual void AddIPConfig( |
| 298 const dbus::ObjectPath& device_path, | 303 const dbus::ObjectPath& device_path, |
| 299 const std::string& method, | 304 const std::string& method, |
| 300 const ObjectPathDBusMethodCallback& callback) OVERRIDE { | 305 const ObjectPathDBusMethodCallback& callback) OVERRIDE { |
| 301 MessageLoop::current()->PostTask(FROM_HERE, | 306 MessageLoop::current()->PostTask(FROM_HERE, |
| 302 base::Bind(callback, | 307 base::Bind(callback, |
| 303 DBUS_METHOD_CALL_SUCCESS, | 308 DBUS_METHOD_CALL_SUCCESS, |
| 304 dbus::ObjectPath())); | 309 dbus::ObjectPath())); |
| 305 } | 310 } |
| 306 | 311 |
| 307 // ShillDeviceClient override. | |
| 308 virtual dbus::ObjectPath CallAddIPConfigAndBlock( | 312 virtual dbus::ObjectPath CallAddIPConfigAndBlock( |
| 309 const dbus::ObjectPath& device_path, | 313 const dbus::ObjectPath& device_path, |
| 310 const std::string& method) OVERRIDE { | 314 const std::string& method) OVERRIDE { |
| 311 return dbus::ObjectPath(); | 315 return dbus::ObjectPath(); |
| 312 } | 316 } |
| 313 | 317 |
| 314 // ShillDeviceClient override. | |
| 315 virtual void RequirePin(const dbus::ObjectPath& device_path, | 318 virtual void RequirePin(const dbus::ObjectPath& device_path, |
| 316 const std::string& pin, | 319 const std::string& pin, |
| 317 bool require, | 320 bool require, |
| 318 const base::Closure& callback, | 321 const base::Closure& callback, |
| 319 const ErrorCallback& error_callback) OVERRIDE { | 322 const ErrorCallback& error_callback) OVERRIDE { |
| 320 MessageLoop::current()->PostTask(FROM_HERE, callback); | 323 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 321 } | 324 } |
| 322 | 325 |
| 323 // ShillDeviceClient override. | |
| 324 virtual void EnterPin(const dbus::ObjectPath& device_path, | 326 virtual void EnterPin(const dbus::ObjectPath& device_path, |
| 325 const std::string& pin, | 327 const std::string& pin, |
| 326 const base::Closure& callback, | 328 const base::Closure& callback, |
| 327 const ErrorCallback& error_callback) OVERRIDE { | 329 const ErrorCallback& error_callback) OVERRIDE { |
| 328 MessageLoop::current()->PostTask(FROM_HERE, callback); | 330 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 329 } | 331 } |
| 330 | 332 |
| 331 // ShillDeviceClient override. | |
| 332 virtual void UnblockPin(const dbus::ObjectPath& device_path, | 333 virtual void UnblockPin(const dbus::ObjectPath& device_path, |
| 333 const std::string& puk, | 334 const std::string& puk, |
| 334 const std::string& pin, | 335 const std::string& pin, |
| 335 const base::Closure& callback, | 336 const base::Closure& callback, |
| 336 const ErrorCallback& error_callback) OVERRIDE { | 337 const ErrorCallback& error_callback) OVERRIDE { |
| 337 MessageLoop::current()->PostTask(FROM_HERE, callback); | 338 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 338 } | 339 } |
| 339 | 340 |
| 340 // ShillDeviceClient override. | |
| 341 virtual void ChangePin(const dbus::ObjectPath& device_path, | 341 virtual void ChangePin(const dbus::ObjectPath& device_path, |
| 342 const std::string& old_pin, | 342 const std::string& old_pin, |
| 343 const std::string& new_pin, | 343 const std::string& new_pin, |
| 344 const base::Closure& callback, | 344 const base::Closure& callback, |
| 345 const ErrorCallback& error_callback) OVERRIDE { | 345 const ErrorCallback& error_callback) OVERRIDE { |
| 346 MessageLoop::current()->PostTask(FROM_HERE, callback); | 346 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 347 } | 347 } |
| 348 | 348 |
| 349 // ShillDeviceClient override. | |
| 350 virtual void Register(const dbus::ObjectPath& device_path, | 349 virtual void Register(const dbus::ObjectPath& device_path, |
| 351 const std::string& network_id, | 350 const std::string& network_id, |
| 352 const base::Closure& callback, | 351 const base::Closure& callback, |
| 353 const ErrorCallback& error_callback) OVERRIDE { | 352 const ErrorCallback& error_callback) OVERRIDE { |
| 354 MessageLoop::current()->PostTask(FROM_HERE, callback); | 353 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 355 } | 354 } |
| 356 | 355 |
| 357 private: | 356 private: |
| 358 void PassStubDevicePrperties(const dbus::ObjectPath& device_path, | 357 void PassStubDeviceProperties(const dbus::ObjectPath& device_path, |
| 359 const DictionaryValueCallback& callback) const { | 358 const DictionaryValueCallback& callback) const { |
| 360 const base::DictionaryValue* device_properties = NULL; | 359 const base::DictionaryValue* device_properties = NULL; |
| 361 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { | 360 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { |
| 362 base::DictionaryValue empty_dictionary; | 361 base::DictionaryValue empty_dictionary; |
| 363 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); | 362 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); |
| 364 return; | 363 return; |
| 365 } | 364 } |
| 366 callback.Run(DBUS_METHOD_CALL_SUCCESS, *device_properties); | 365 callback.Run(DBUS_METHOD_CALL_SUCCESS, *device_properties); |
| 367 } | 366 } |
| 368 | 367 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 393 ShillDeviceClient* ShillDeviceClient::Create( | 392 ShillDeviceClient* ShillDeviceClient::Create( |
| 394 DBusClientImplementationType type, | 393 DBusClientImplementationType type, |
| 395 dbus::Bus* bus) { | 394 dbus::Bus* bus) { |
| 396 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 395 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 397 return new ShillDeviceClientImpl(bus); | 396 return new ShillDeviceClientImpl(bus); |
| 398 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 397 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 399 return new ShillDeviceClientStubImpl(); | 398 return new ShillDeviceClientStubImpl(); |
| 400 } | 399 } |
| 401 | 400 |
| 402 } // namespace chromeos | 401 } // namespace chromeos |
| OLD | NEW |