| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 } | 368 } |
| 369 | 369 |
| 370 virtual ShillDeviceClient::TestInterface* GetTestInterface() OVERRIDE { | 370 virtual ShillDeviceClient::TestInterface* GetTestInterface() OVERRIDE { |
| 371 return this; | 371 return this; |
| 372 } | 372 } |
| 373 | 373 |
| 374 // ShillDeviceClient::TestInterface overrides. | 374 // ShillDeviceClient::TestInterface overrides. |
| 375 | 375 |
| 376 virtual void AddDevice(const std::string& device_path, | 376 virtual void AddDevice(const std::string& device_path, |
| 377 const std::string& type, | 377 const std::string& type, |
| 378 const std::string& object_path, | 378 const std::string& object_path) OVERRIDE { |
| 379 const std::string& connection_path) OVERRIDE { | |
| 380 base::DictionaryValue* properties = GetDeviceProperties(device_path); | 379 base::DictionaryValue* properties = GetDeviceProperties(device_path); |
| 381 properties->SetWithoutPathExpansion( | 380 properties->SetWithoutPathExpansion( |
| 382 flimflam::kTypeProperty, | 381 flimflam::kTypeProperty, |
| 383 base::Value::CreateStringValue(type)); | 382 base::Value::CreateStringValue(type)); |
| 384 properties->SetWithoutPathExpansion( | 383 properties->SetWithoutPathExpansion( |
| 385 flimflam::kDBusObjectProperty, | 384 flimflam::kDBusObjectProperty, |
| 386 base::Value::CreateStringValue(object_path)); | 385 base::Value::CreateStringValue(object_path)); |
| 387 properties->SetWithoutPathExpansion( | 386 properties->SetWithoutPathExpansion( |
| 388 flimflam::kDBusConnectionProperty, | 387 flimflam::kDBusConnectionProperty, |
| 389 base::Value::CreateStringValue(connection_path)); | 388 base::Value::CreateStringValue("/stub")); |
| 390 } | 389 } |
| 391 | 390 |
| 392 virtual void RemoveDevice(const std::string& device_path) OVERRIDE { | 391 virtual void RemoveDevice(const std::string& device_path) OVERRIDE { |
| 393 stub_devices_.RemoveWithoutPathExpansion(device_path, NULL); | 392 stub_devices_.RemoveWithoutPathExpansion(device_path, NULL); |
| 394 } | 393 } |
| 395 | 394 |
| 396 virtual void ClearDevices() OVERRIDE { | 395 virtual void ClearDevices() OVERRIDE { |
| 397 stub_devices_.Clear(); | 396 stub_devices_.Clear(); |
| 398 } | 397 } |
| 399 | 398 |
| 399 virtual void SetDeviceProperty(const std::string& device_path, |
| 400 const std::string& name, |
| 401 const base::Value& value) { |
| 402 SetProperty(dbus::ObjectPath(device_path), name, value, |
| 403 base::Bind(&base::DoNothing), |
| 404 base::Bind(&ShillDeviceClientStubImpl::ErrorFunction)); |
| 405 } |
| 406 |
| 400 private: | 407 private: |
| 401 typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList; | 408 typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList; |
| 402 | 409 |
| 403 void SetDefaultProperties() { | 410 void SetDefaultProperties() { |
| 404 // Add a wifi device. Note: path matches Manager entry. | 411 // Add a wifi device. Note: path matches Manager entry. |
| 405 AddDevice("stub_wifi_device1", flimflam::kTypeWifi, | 412 AddDevice("stub_wifi_device1", flimflam::kTypeWifi, "/device/wifi1"); |
| 406 "/device/wifi1", "/stub"); | |
| 407 | 413 |
| 408 // Add a cellular device. Used in SMS stub. Note: path matches | 414 // Add a cellular device. Used in SMS stub. Note: path matches |
| 409 // Manager entry. | 415 // Manager entry. |
| 410 AddDevice("stub_cellular_device1", flimflam::kTypeCellular, | 416 AddDevice("stub_cellular_device1", flimflam::kTypeCellular, |
| 411 "/device/cellular1", "/stub"); | 417 "/device/cellular1"); |
| 412 } | 418 } |
| 413 | 419 |
| 414 void PassStubDeviceProperties(const dbus::ObjectPath& device_path, | 420 void PassStubDeviceProperties(const dbus::ObjectPath& device_path, |
| 415 const DictionaryValueCallback& callback) const { | 421 const DictionaryValueCallback& callback) const { |
| 416 const base::DictionaryValue* device_properties = NULL; | 422 const base::DictionaryValue* device_properties = NULL; |
| 417 if (!stub_devices_.GetDictionaryWithoutPathExpansion( | 423 if (!stub_devices_.GetDictionaryWithoutPathExpansion( |
| 418 device_path.value(), &device_properties)) { | 424 device_path.value(), &device_properties)) { |
| 419 base::DictionaryValue empty_dictionary; | 425 base::DictionaryValue empty_dictionary; |
| 420 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); | 426 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); |
| 421 return; | 427 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path) { | 470 PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path) { |
| 465 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 471 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 466 observer_list_.find(device_path); | 472 observer_list_.find(device_path); |
| 467 if (iter != observer_list_.end()) | 473 if (iter != observer_list_.end()) |
| 468 return *(iter->second); | 474 return *(iter->second); |
| 469 PropertyObserverList* observer_list = new PropertyObserverList(); | 475 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 470 observer_list_[device_path] = observer_list; | 476 observer_list_[device_path] = observer_list; |
| 471 return *observer_list; | 477 return *observer_list; |
| 472 } | 478 } |
| 473 | 479 |
| 480 static void ErrorFunction(const std::string& error_name, |
| 481 const std::string& error_message) { |
| 482 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; |
| 483 } |
| 484 |
| 474 // Dictionary of <device_name, Dictionary>. | 485 // Dictionary of <device_name, Dictionary>. |
| 475 base::DictionaryValue stub_devices_; | 486 base::DictionaryValue stub_devices_; |
| 476 // Observer list for each device. | 487 // Observer list for each device. |
| 477 std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_; | 488 std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_; |
| 478 | 489 |
| 479 // Note: This should remain the last member so it'll be destroyed and | 490 // Note: This should remain the last member so it'll be destroyed and |
| 480 // invalidate its weak pointers before any other members are destroyed. | 491 // invalidate its weak pointers before any other members are destroyed. |
| 481 base::WeakPtrFactory<ShillDeviceClientStubImpl> weak_ptr_factory_; | 492 base::WeakPtrFactory<ShillDeviceClientStubImpl> weak_ptr_factory_; |
| 482 | 493 |
| 483 DISALLOW_COPY_AND_ASSIGN(ShillDeviceClientStubImpl); | 494 DISALLOW_COPY_AND_ASSIGN(ShillDeviceClientStubImpl); |
| 484 }; | 495 }; |
| 485 | 496 |
| 486 } // namespace | 497 } // namespace |
| 487 | 498 |
| 488 ShillDeviceClient::ShillDeviceClient() {} | 499 ShillDeviceClient::ShillDeviceClient() {} |
| 489 | 500 |
| 490 ShillDeviceClient::~ShillDeviceClient() {} | 501 ShillDeviceClient::~ShillDeviceClient() {} |
| 491 | 502 |
| 492 // static | 503 // static |
| 493 ShillDeviceClient* ShillDeviceClient::Create( | 504 ShillDeviceClient* ShillDeviceClient::Create( |
| 494 DBusClientImplementationType type, | 505 DBusClientImplementationType type, |
| 495 dbus::Bus* bus) { | 506 dbus::Bus* bus) { |
| 496 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 507 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 497 return new ShillDeviceClientImpl(bus); | 508 return new ShillDeviceClientImpl(bus); |
| 498 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 509 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 499 return new ShillDeviceClientStubImpl(); | 510 return new ShillDeviceClientStubImpl(); |
| 500 } | 511 } |
| 501 | 512 |
| 502 } // namespace chromeos | 513 } // namespace chromeos |
| OLD | NEW |