| 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..52972a269b99f6bc16a8237bca890e639735f682 100644
|
| --- a/chromeos/dbus/shill_service_client.cc
|
| +++ b/chromeos/dbus/shill_service_client.cc
|
| @@ -181,7 +181,29 @@ class ShillServiceClientImpl : public ShillServiceClient {
|
| // A stub implementation of ShillServiceClient.
|
| class ShillServiceClientStubImpl : public ShillServiceClient {
|
| public:
|
| - ShillServiceClientStubImpl() : weak_ptr_factory_(this) {}
|
| + ShillServiceClientStubImpl() : weak_ptr_factory_(this) {
|
| + // Add stub services. Note: names match Manager stub impl.
|
| + PopulateNetworkDictionary("stub_ethernet", "eth0",
|
| + flimflam::kTypeEthernet,
|
| + flimflam::kStateOnline,
|
| + flimflam::kSecurityNone);
|
| + PopulateNetworkDictionary("stub_wifi1", "wifi1",
|
| + flimflam::kTypeWifi,
|
| + flimflam::kStateOnline,
|
| + flimflam::kSecurityNone);
|
| + PopulateNetworkDictionary("stub_wifi2", "wifi2_PSK",
|
| + flimflam::kTypeWifi,
|
| + flimflam::kStateIdle,
|
| + flimflam::kSecurityPsk);
|
| + base::DictionaryValue* cellular1 =
|
| + PopulateNetworkDictionary("stub_cellular1", "cellular1",
|
| + flimflam::kTypeCellular,
|
| + flimflam::kStateIdle,
|
| + flimflam::kSecurityNone);
|
| + cellular1->SetWithoutPathExpansion(
|
| + flimflam::kNetworkTechnologyProperty,
|
| + base::Value::CreateStringValue(flimflam::kNetworkTechnologyGsm));
|
| + }
|
|
|
| virtual ~ShillServiceClientStubImpl() {}
|
|
|
| @@ -189,18 +211,23 @@ class ShillServiceClientStubImpl : public ShillServiceClient {
|
| // 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 +236,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();
|
| + 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);
|
| }
|
|
|
| @@ -252,11 +297,61 @@ class ShillServiceClientStubImpl : public ShillServiceClient {
|
| }
|
|
|
| private:
|
| - void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const {
|
| - base::DictionaryValue dictionary;
|
| - callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary);
|
| + 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);
|
| }
|
|
|
| + base::DictionaryValue* PopulateNetworkDictionary(
|
| + const std::string& ssid,
|
| + const std::string& name,
|
| + const std::string& type,
|
| + const std::string& state,
|
| + const std::string& security) {
|
| + base::DictionaryValue* dict = new base::DictionaryValue;
|
| + dict->SetWithoutPathExpansion(flimflam::kSSIDProperty,
|
| + base::Value::CreateStringValue(ssid));
|
| + dict->SetWithoutPathExpansion(flimflam::kNameProperty,
|
| + base::Value::CreateStringValue(name));
|
| + dict->SetWithoutPathExpansion(flimflam::kTypeProperty,
|
| + base::Value::CreateStringValue(type));
|
| + dict->SetWithoutPathExpansion(flimflam::kStateProperty,
|
| + base::Value::CreateStringValue(state));
|
| + dict->SetWithoutPathExpansion(flimflam::kSecurityProperty,
|
| + base::Value::CreateStringValue(security));
|
| + stub_services_.Set(ssid, dict);
|
| + return 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;
|
| + 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 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_;
|
|
|