Chromium Code Reviews| Index: chromeos/dbus/shill_service_client.cc |
| diff --git a/chromeos/dbus/shill_service_client.cc b/chromeos/dbus/shill_service_client.cc |
| index 46fe0f4e67c18fff289b29cebcdc591d8bc49c84..a20c398237357ef766b36effc845fb851e536abd 100644 |
| --- a/chromeos/dbus/shill_service_client.cc |
| +++ b/chromeos/dbus/shill_service_client.cc |
| @@ -153,6 +153,10 @@ class ShillServiceClientImpl : public ShillServiceClient { |
| return GetHelper(service_path)->CallVoidMethodAndBlock(&method_call); |
| } |
| + virtual ShillServiceClient::TestInterface* GetTestInterface() { |
|
hashimoto
2012/11/01 04:54:34
nit: OVERRIDE
stevenjb
2012/11/01 18:45:59
Done.
|
| + return NULL; |
| + } |
| + |
| private: |
| typedef std::map<std::string, ShillClientHelper*> HelperMap; |
| @@ -179,28 +183,37 @@ class ShillServiceClientImpl : public ShillServiceClient { |
| }; |
| // A stub implementation of ShillServiceClient. |
| -class ShillServiceClientStubImpl : public ShillServiceClient { |
| +class ShillServiceClientStubImpl : public ShillServiceClient, |
| + public ShillServiceClient::TestInterface { |
| public: |
| - ShillServiceClientStubImpl() : weak_ptr_factory_(this) {} |
| + ShillServiceClientStubImpl() : weak_ptr_factory_(this) { |
| + SetDefaultProperties(); |
| + } |
| - virtual ~ShillServiceClientStubImpl() {} |
| + virtual ~ShillServiceClientStubImpl() { |
| + } |
| - /////////////////////////////////// |
| // ShillServiceClient overrides. |
| + |
| virtual void AddPropertyChangedObserver( |
| const dbus::ObjectPath& service_path, |
| - ShillPropertyChangedObserver* observer) OVERRIDE {} |
| + ShillPropertyChangedObserver* observer) OVERRIDE { |
| + observer_list_.AddObserver(observer); |
| + } |
| virtual void RemovePropertyChangedObserver( |
| const dbus::ObjectPath& service_path, |
| - ShillPropertyChangedObserver* observer) OVERRIDE {} |
| + ShillPropertyChangedObserver* observer) OVERRIDE { |
| + observer_list_.RemoveObserver(observer); |
| + } |
| virtual void GetProperties(const dbus::ObjectPath& service_path, |
| const DictionaryValueCallback& callback) OVERRIDE { |
| MessageLoop::current()->PostTask( |
| FROM_HERE, |
| - base::Bind(&ShillServiceClientStubImpl::PassEmptyDictionaryValue, |
| + base::Bind(&ShillServiceClientStubImpl::PassStubDictionaryValue, |
| weak_ptr_factory_.GetWeakPtr(), |
| + service_path, |
| callback)); |
| } |
| @@ -209,13 +222,31 @@ class ShillServiceClientStubImpl : public ShillServiceClient { |
| const base::Value& value, |
| const base::Closure& callback, |
| const ErrorCallback& error_callback) OVERRIDE { |
| + base::DictionaryValue* dict = NULL; |
| + std::string ssid = service_path.value(); |
|
hashimoto
2012/11/01 04:54:34
Since this method is used not only for wifi networ
stevenjb
2012/11/01 18:45:59
Done.
|
| + if (!stub_services_.GetDictionaryWithoutPathExpansion(ssid, &dict)) { |
| + error_callback.Run("StubError", "Service not found"); |
| + return; |
| + } |
| + dict->SetWithoutPathExpansion(name, value.DeepCopy()); |
| MessageLoop::current()->PostTask(FROM_HERE, callback); |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&ShillServiceClientStubImpl::NotifyObserversPropertyChanged, |
| + weak_ptr_factory_.GetWeakPtr(), service_path, name)); |
| } |
| virtual void ClearProperty(const dbus::ObjectPath& service_path, |
| const std::string& name, |
| const base::Closure& callback, |
| const ErrorCallback& error_callback) OVERRIDE { |
| + base::DictionaryValue* dict = NULL; |
| + std::string ssid = service_path.value(); |
| + if (!stub_services_.GetDictionaryWithoutPathExpansion(ssid, &dict)) { |
| + error_callback.Run("StubError", "Service not found"); |
| + return; |
| + } |
| + dict->Remove(name, NULL); |
| MessageLoop::current()->PostTask(FROM_HERE, callback); |
| } |
| @@ -251,12 +282,118 @@ class ShillServiceClientStubImpl : public ShillServiceClient { |
| return true; |
| } |
| + virtual ShillServiceClient::TestInterface* GetTestInterface() { |
|
hashimoto
2012/11/01 04:54:34
nit: OVERRIDE
stevenjb
2012/11/01 18:45:59
Done.
|
| + return this; |
| + } |
| + |
| + // ShillServiceClient::TestInterface overrides. |
| + |
| + virtual void AddService(const std::string& service_path, |
| + const std::string& name, |
| + const std::string& type, |
| + const std::string& state, |
| + const std::string& security) OVERRIDE { |
| + base::DictionaryValue* properties = GetServiceProperties(service_path); |
| + properties->SetWithoutPathExpansion( |
| + flimflam::kSSIDProperty, |
| + base::Value::CreateStringValue(service_path)); |
| + properties->SetWithoutPathExpansion( |
| + flimflam::kNameProperty, |
| + base::Value::CreateStringValue(name)); |
| + properties->SetWithoutPathExpansion( |
| + flimflam::kTypeProperty, |
| + base::Value::CreateStringValue(type)); |
| + properties->SetWithoutPathExpansion( |
| + flimflam::kStateProperty, |
| + base::Value::CreateStringValue(state)); |
| + properties->SetWithoutPathExpansion( |
| + flimflam::kSecurityProperty, |
| + base::Value::CreateStringValue(security)); |
| + } |
| + |
| + virtual void RemoveService(const std::string& service_path) { |
| + stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
| + } |
| + |
| + virtual void SetServiceProperty(const std::string& service_path, |
| + const std::string& property, |
| + const base::Value& value) OVERRIDE { |
| + SetProperty(dbus::ObjectPath(service_path), property, value, |
| + base::Bind(&base::DoNothing), ErrorCallback()); |
| + } |
| + |
| + virtual void ClearServices() OVERRIDE { |
| + stub_services_.Clear(); |
| + } |
| + |
| private: |
| - void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { |
| - base::DictionaryValue dictionary; |
| - callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); |
| + void SetDefaultProperties() { |
| + // Add stub services. Note: names match Manager stub impl. |
| + AddService("stub_ethernet", "eth0", |
| + flimflam::kTypeEthernet, |
| + flimflam::kStateOnline, |
| + flimflam::kSecurityNone); |
| + AddService("stub_wifi1", "wifi1", |
| + flimflam::kTypeWifi, |
| + flimflam::kStateOnline, |
| + flimflam::kSecurityNone); |
| + AddService("stub_wifi2", "wifi2_PSK", |
| + flimflam::kTypeWifi, |
| + flimflam::kStateIdle, |
| + flimflam::kSecurityPsk); |
| + AddService("stub_cellular1", "cellular1", |
| + flimflam::kTypeCellular, |
| + flimflam::kStateIdle, |
| + flimflam::kSecurityNone); |
| + SetServiceProperty("stub_cellular1", |
| + flimflam::kNetworkTechnologyProperty, |
| + base::StringValue(flimflam::kNetworkTechnologyGsm)); |
| + } |
| + |
| + void PassStubDictionaryValue(const dbus::ObjectPath& service_path, |
| + const DictionaryValueCallback& callback) { |
| + base::DictionaryValue* dict = NULL; |
| + std::string ssid = service_path.value(); |
| + if (!stub_services_.GetDictionaryWithoutPathExpansion(ssid, &dict)) { |
| + callback.Run(DBUS_METHOD_CALL_FAILURE, base::DictionaryValue()); |
| + return; |
| + } |
| + callback.Run(DBUS_METHOD_CALL_SUCCESS, *dict); |
| + } |
| + |
| + void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path, |
| + const std::string& property) { |
| + base::DictionaryValue* dict = NULL; |
| + std::string ssid = service_path.value(); |
| + if (!stub_services_.GetDictionaryWithoutPathExpansion(ssid, &dict)) { |
| + LOG(ERROR) << "Notify for unknown service: " << ssid; |
| + return; |
| + } |
| + base::Value* value; |
|
hashimoto
2012/11/01 04:54:34
nit: = NULL;
stevenjb
2012/11/01 18:45:59
Done.
|
| + if (!dict->GetWithoutPathExpansion(property, &value)) { |
| + LOG(ERROR) << "Notify for unknown property: " |
| + << ssid << " : " << property; |
| + return; |
| + } |
| + FOR_EACH_OBSERVER(ShillPropertyChangedObserver, |
| + observer_list_, |
| + OnPropertyChanged(property, *value)); |
| } |
| + base::DictionaryValue* GetServiceProperties(const std::string& service_path) { |
| + base::DictionaryValue* properties; |
|
hashimoto
2012/11/01 04:54:34
nit: = NULL;
stevenjb
2012/11/01 18:45:59
Done.
|
| + if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| + service_path, &properties)) { |
| + properties = new base::DictionaryValue; |
| + stub_services_.Set(service_path, properties); |
| + } |
| + return properties; |
| + } |
| + |
| + |
| + base::DictionaryValue stub_services_; |
| + ObserverList<ShillPropertyChangedObserver> observer_list_; |
| + |
| // Note: This should remain the last member so it'll be destroyed and |
| // invalidate its weak pointers before any other members are destroyed. |
| base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_; |