summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'chromeos/dbus')
-rw-r--r--chromeos/dbus/mock_shill_manager_client.cc2
-rw-r--r--chromeos/dbus/mock_shill_manager_client.h5
-rw-r--r--chromeos/dbus/mock_shill_profile_client.h1
-rw-r--r--chromeos/dbus/shill_device_client.h2
-rw-r--r--chromeos/dbus/shill_manager_client.cc63
-rw-r--r--chromeos/dbus/shill_manager_client.h13
-rw-r--r--chromeos/dbus/shill_manager_client_stub.cc49
-rw-r--r--chromeos/dbus/shill_manager_client_stub.h5
-rw-r--r--chromeos/dbus/shill_profile_client.cc6
-rw-r--r--chromeos/dbus/shill_profile_client.h17
-rw-r--r--chromeos/dbus/shill_profile_client_stub.cc125
-rw-r--r--chromeos/dbus/shill_profile_client_stub.h20
-rw-r--r--chromeos/dbus/shill_service_client.h2
-rw-r--r--chromeos/dbus/shill_service_client_stub.cc47
-rw-r--r--chromeos/dbus/shill_service_client_stub.h2
15 files changed, 293 insertions, 66 deletions
diff --git a/chromeos/dbus/mock_shill_manager_client.cc b/chromeos/dbus/mock_shill_manager_client.cc
index 2016e2b..309b48e 100644
--- a/chromeos/dbus/mock_shill_manager_client.cc
+++ b/chromeos/dbus/mock_shill_manager_client.cc
@@ -4,6 +4,8 @@
#include "chromeos/dbus/mock_shill_manager_client.h"
+#include "dbus/object_path.h"
+
namespace chromeos {
MockShillManagerClient::MockShillManagerClient() {}
diff --git a/chromeos/dbus/mock_shill_manager_client.h b/chromeos/dbus/mock_shill_manager_client.h
index 57f2449..d507762 100644
--- a/chromeos/dbus/mock_shill_manager_client.h
+++ b/chromeos/dbus/mock_shill_manager_client.h
@@ -41,6 +41,11 @@ class MockShillManagerClient : public ShillManagerClient {
MOCK_METHOD3(ConfigureService, void(const base::DictionaryValue& properties,
const ObjectPathCallback& callback,
const ErrorCallback& error_callback));
+ MOCK_METHOD4(ConfigureServiceForProfile,
+ void(const dbus::ObjectPath& profile_path,
+ const base::DictionaryValue& properties,
+ const ObjectPathCallback& callback,
+ const ErrorCallback& error_callback));
MOCK_METHOD3(GetService, void(const base::DictionaryValue& properties,
const ObjectPathCallback& callback,
const ErrorCallback& error_callback));
diff --git a/chromeos/dbus/mock_shill_profile_client.h b/chromeos/dbus/mock_shill_profile_client.h
index 078bb60..b18a843 100644
--- a/chromeos/dbus/mock_shill_profile_client.h
+++ b/chromeos/dbus/mock_shill_profile_client.h
@@ -39,6 +39,7 @@ class MockShillProfileClient : public ShillProfileClient {
const std::string& entry_path,
const base::Closure& callback,
const ErrorCallback& error_callback));
+ MOCK_METHOD0(GetTestInterface, TestInterface*());
};
} // namespace chromeos
diff --git a/chromeos/dbus/shill_device_client.h b/chromeos/dbus/shill_device_client.h
index e865753..6a3fb35 100644
--- a/chromeos/dbus/shill_device_client.h
+++ b/chromeos/dbus/shill_device_client.h
@@ -55,7 +55,7 @@ class CHROMEOS_EXPORT ShillDeviceClient {
virtual std::string GetDevicePathForType(const std::string& type) = 0;
protected:
- ~TestInterface() {}
+ virtual ~TestInterface() {}
};
virtual ~ShillDeviceClient();
diff --git a/chromeos/dbus/shill_manager_client.cc b/chromeos/dbus/shill_manager_client.cc
index 1be4bf2..c5f05ff 100644
--- a/chromeos/dbus/shill_manager_client.cc
+++ b/chromeos/dbus/shill_manager_client.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/chromeos/chromeos_version.h"
+#include "base/logging.h"
#include "base/message_loop.h"
#include "base/values.h"
#include "chromeos/dbus/shill_manager_client_stub.h"
@@ -21,13 +22,41 @@ namespace chromeos {
namespace {
+const char kIncompleteServiceProperties[] = "Error.IncompleteServiceProperties";
+const char kIncompleteServicePropertiesMessage[] =
+ "Service properties are incomplete.";
+
// Returns whether the properties have the required keys or not.
-bool AreServicePropertiesValid(const base::DictionaryValue& properties) {
- if (properties.HasKey(flimflam::kGuidProperty))
+bool AreServicePropertiesValidWithMode(
+ const base::DictionaryValue& properties,
+ const ShillManagerClient::ErrorCallback& error_callback) {
+ if (properties.HasKey(flimflam::kGuidProperty) ||
+ (properties.HasKey(flimflam::kTypeProperty) &&
+ properties.HasKey(flimflam::kSecurityProperty) &&
+ properties.HasKey(flimflam::kModeProperty) &&
+ properties.HasKey(flimflam::kSSIDProperty))) {
return true;
- return properties.HasKey(flimflam::kTypeProperty) &&
- properties.HasKey(flimflam::kSecurityProperty) &&
- properties.HasKey(flimflam::kSSIDProperty);
+ }
+ error_callback.Run(kIncompleteServiceProperties,
+ kIncompleteServicePropertiesMessage);
+ return false;
+}
+
+// DEPRECATED: Keep this only for backward compatibility with NetworkLibrary.
+// Returns whether the properties have the required keys or not.
+// TODO(pneubeck): remove this once NetworkLibrary is gone (crbug/230799).
+bool AreServicePropertiesValid(
+ const base::DictionaryValue& properties,
+ const ShillManagerClient::ErrorCallback& error_callback) {
+ if (properties.HasKey(flimflam::kGuidProperty) ||
+ (properties.HasKey(flimflam::kTypeProperty) &&
+ properties.HasKey(flimflam::kSecurityProperty) &&
+ properties.HasKey(flimflam::kSSIDProperty))) {
+ return true;
+ }
+ error_callback.Run(kIncompleteServiceProperties,
+ kIncompleteServicePropertiesMessage);
+ return false;
}
// Appends a string-to-variant dictionary to the writer.
@@ -146,7 +175,10 @@ class ShillManagerClientImpl : public ShillManagerClient {
const base::DictionaryValue& properties,
const ObjectPathCallback& callback,
const ErrorCallback& error_callback) OVERRIDE {
- DCHECK(AreServicePropertiesValid(properties));
+ if (!AreServicePropertiesValid(properties, error_callback)) {
+ NOTREACHED() << kIncompleteServicePropertiesMessage;
+ return;
+ }
dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
flimflam::kConfigureServiceFunction);
dbus::MessageWriter writer(&method_call);
@@ -156,6 +188,25 @@ class ShillManagerClientImpl : public ShillManagerClient {
error_callback);
}
+ virtual void ConfigureServiceForProfile(
+ const dbus::ObjectPath& profile_path,
+ const base::DictionaryValue& properties,
+ const ObjectPathCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ if (!AreServicePropertiesValidWithMode(properties, error_callback)) {
+ NOTREACHED() << kIncompleteServicePropertiesMessage;
+ return;
+ }
+ dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface,
+ shill::kConfigureServiceForProfileFunction);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendObjectPath(dbus::ObjectPath(profile_path));
+ AppendServicePropertiesDictionary(&writer, properties);
+ helper_.CallObjectPathMethodWithErrorCallback(&method_call,
+ callback,
+ error_callback);
+ }
+
virtual void GetService(
const base::DictionaryValue& properties,
const ObjectPathCallback& callback,
diff --git a/chromeos/dbus/shill_manager_client.h b/chromeos/dbus/shill_manager_client.h
index a67113d..80116bd 100644
--- a/chromeos/dbus/shill_manager_client.h
+++ b/chromeos/dbus/shill_manager_client.h
@@ -8,14 +8,15 @@
#include <string>
#include "base/basictypes.h"
-#include "base/callback.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/dbus_client_implementation_type.h"
+#include "chromeos/dbus/dbus_method_call_status.h"
#include "chromeos/dbus/shill_client_helper.h"
namespace dbus {
class Bus;
+class ObjectPath;
} // namespace dbus
@@ -59,7 +60,7 @@ class CHROMEOS_EXPORT ShillManagerClient {
virtual void ClearProperties() = 0;
protected:
- ~TestInterface() {}
+ virtual ~TestInterface() {}
};
virtual ~ShillManagerClient();
@@ -125,6 +126,14 @@ class CHROMEOS_EXPORT ShillManagerClient {
const ObjectPathCallback& callback,
const ErrorCallback& error_callback) = 0;
+ // Calls ConfigureServiceForProfile method.
+ // |callback| is called with the created service if the method call succeeds.
+ virtual void ConfigureServiceForProfile(
+ const dbus::ObjectPath& profile_path,
+ const base::DictionaryValue& properties,
+ const ObjectPathCallback& callback,
+ const ErrorCallback& error_callback) = 0;
+
// Calls GetService method.
// |callback| is called after the method call succeeds.
virtual void GetService(const base::DictionaryValue& properties,
diff --git a/chromeos/dbus/shill_manager_client_stub.cc b/chromeos/dbus/shill_manager_client_stub.cc
index 9350076..d77dab6 100644
--- a/chromeos/dbus/shill_manager_client_stub.cc
+++ b/chromeos/dbus/shill_manager_client_stub.cc
@@ -12,6 +12,7 @@
#include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_device_client.h"
+#include "chromeos/dbus/shill_profile_client.h"
#include "chromeos/dbus/shill_property_changed_observer.h"
#include "chromeos/dbus/shill_service_client.h"
#include "dbus/bus.h"
@@ -182,9 +183,6 @@ void ShillManagerClientStub::ConfigureService(
if (callback.is_null())
return;
- // For the purposes of this stub, we're going to assume that the GUID property
- // is set to the service path because we don't want to re-implement Shill's
- // property matching magic here.
ShillServiceClient::TestInterface* service_client =
DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
@@ -199,34 +197,57 @@ void ShillManagerClientStub::ConfigureService(
return;
}
+ // For the purposes of this stub, we're going to assume that the GUID property
+ // is set to the service path because we don't want to re-implement Shill's
+ // property matching magic here.
+ std::string service_path = guid;
+
std::string ipconfig_path;
properties.GetString(shill::kIPConfigProperty, &ipconfig_path);
- // Add the service to the service client stub if not already there.
- service_client->AddServiceWithIPConfig(guid, guid, type, flimflam::kStateIdle,
- ipconfig_path, true);
// Merge the new properties with existing properties, if any.
- scoped_ptr<base::DictionaryValue> merged_properties;
const base::DictionaryValue* existing_properties =
- service_client->GetServiceProperties(guid);
- if (existing_properties) {
- merged_properties.reset(existing_properties->DeepCopy());
- } else {
- merged_properties.reset(new base::DictionaryValue);
+ service_client->GetServiceProperties(service_path);
+ if (!existing_properties) {
+ // Add a new service to the service client stub because none exists, yet.
+ service_client->AddServiceWithIPConfig(service_path, guid, type,
+ flimflam::kStateIdle, ipconfig_path,
+ true); // Add service to watch list.
+ existing_properties = service_client->GetServiceProperties(service_path);
}
+
+ scoped_ptr<base::DictionaryValue> merged_properties(
+ existing_properties->DeepCopy());
merged_properties->MergeDictionary(&properties);
// Now set all the properties.
for (base::DictionaryValue::Iterator iter(*merged_properties);
!iter.IsAtEnd(); iter.Advance()) {
- service_client->SetServiceProperty(guid, iter.key(), iter.value());
+ service_client->SetServiceProperty(service_path, iter.key(), iter.value());
}
+ ShillProfileClient::TestInterface* profile_test =
+ DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
+ profile_test->AddService(service_path);
+
MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, dbus::ObjectPath(guid)));
+ FROM_HERE, base::Bind(callback, dbus::ObjectPath(service_path)));
+}
+
+void ShillManagerClientStub::ConfigureServiceForProfile(
+ const dbus::ObjectPath& profile_path,
+ const base::DictionaryValue& properties,
+ const ObjectPathCallback& callback,
+ const ErrorCallback& error_callback) {
+ std::string profile_property;
+ properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty,
+ &profile_property);
+ CHECK(profile_property == profile_path.value());
+ ConfigureService(properties, callback, error_callback);
}
+
void ShillManagerClientStub::GetService(
const base::DictionaryValue& properties,
const ObjectPathCallback& callback,
diff --git a/chromeos/dbus/shill_manager_client_stub.h b/chromeos/dbus/shill_manager_client_stub.h
index f80362f..314713f 100644
--- a/chromeos/dbus/shill_manager_client_stub.h
+++ b/chromeos/dbus/shill_manager_client_stub.h
@@ -50,6 +50,11 @@ class ShillManagerClientStub : public ShillManagerClient,
const base::DictionaryValue& properties,
const ObjectPathCallback& callback,
const ErrorCallback& error_callback) OVERRIDE;
+ virtual void ConfigureServiceForProfile(
+ const dbus::ObjectPath& profile_path,
+ const base::DictionaryValue& properties,
+ const ObjectPathCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE;
virtual void GetService(
const base::DictionaryValue& properties,
const ObjectPathCallback& callback,
diff --git a/chromeos/dbus/shill_profile_client.cc b/chromeos/dbus/shill_profile_client.cc
index a86ff78..511a22e 100644
--- a/chromeos/dbus/shill_profile_client.cc
+++ b/chromeos/dbus/shill_profile_client.cc
@@ -20,12 +20,10 @@ namespace chromeos {
namespace {
-// The ShillProfileClient implementation.
class ShillProfileClientImpl : public ShillProfileClient {
public:
explicit ShillProfileClientImpl(dbus::Bus* bus);
- /////////////////////////////////////
// ShillProfileClient overrides.
virtual void AddPropertyChangedObserver(
const dbus::ObjectPath& profile_path,
@@ -51,6 +49,10 @@ class ShillProfileClientImpl : public ShillProfileClient {
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE;
+ virtual TestInterface* GetTestInterface() OVERRIDE {
+ return NULL;
+ }
+
private:
typedef std::map<std::string, ShillClientHelper*> HelperMap;
diff --git a/chromeos/dbus/shill_profile_client.h b/chromeos/dbus/shill_profile_client.h
index 2c45ac7..4d653ff 100644
--- a/chromeos/dbus/shill_profile_client.h
+++ b/chromeos/dbus/shill_profile_client.h
@@ -41,6 +41,20 @@ class CHROMEOS_EXPORT ShillProfileClient {
DictionaryValueCallbackWithoutStatus;
typedef ShillClientHelper::ErrorCallback ErrorCallback;
+ // Interface for setting up services for testing. Accessed through
+ // GetTestInterface(), only implemented in the stub implementation.
+ class TestInterface {
+ public:
+ virtual void AddProfile(const std::string& profile_path) = 0;
+ virtual void AddEntry(const std::string& profile_path,
+ const std::string& entry_path,
+ const base::DictionaryValue& properties) = 0;
+ virtual bool AddService(const std::string& service_path) = 0;
+
+ protected:
+ virtual ~TestInterface() {}
+ };
+
virtual ~ShillProfileClient();
// Factory function, creates a new instance which is owned by the caller.
@@ -79,6 +93,9 @@ class CHROMEOS_EXPORT ShillProfileClient {
const base::Closure& callback,
const ErrorCallback& error_callback) = 0;
+ // Returns an interface for testing (stub only), or returns NULL.
+ virtual TestInterface* GetTestInterface() = 0;
+
protected:
// Create() should be used instead.
ShillProfileClient();
diff --git a/chromeos/dbus/shill_profile_client_stub.cc b/chromeos/dbus/shill_profile_client_stub.cc
index 9b427bb..e249cd5 100644
--- a/chromeos/dbus/shill_profile_client_stub.cc
+++ b/chromeos/dbus/shill_profile_client_stub.cc
@@ -5,10 +5,13 @@
#include "chromeos/dbus/shill_profile_client_stub.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
#include "base/values.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_property_changed_observer.h"
+#include "chromeos/dbus/shill_service_client.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
@@ -17,7 +20,38 @@
namespace chromeos {
-ShillProfileClientStub::ShillProfileClientStub() : weak_ptr_factory_(this) {
+namespace {
+
+void PassEmptyDictionary(
+ const ShillProfileClient::DictionaryValueCallbackWithoutStatus& callback) {
+ base::DictionaryValue dictionary;
+ if (callback.is_null())
+ return;
+ callback.Run(dictionary);
+}
+
+void PassDictionary(
+ const ShillProfileClient::DictionaryValueCallbackWithoutStatus& callback,
+ const base::DictionaryValue* dictionary) {
+ if (callback.is_null())
+ return;
+ callback.Run(*dictionary);
+}
+
+base::DictionaryValue* GetOrCreateDictionary(const std::string& key,
+ base::DictionaryValue* dict) {
+ base::DictionaryValue* nested_dict = NULL;
+ dict->GetDictionaryWithoutPathExpansion(key, &nested_dict);
+ if (!nested_dict) {
+ nested_dict = new base::DictionaryValue;
+ dict->SetWithoutPathExpansion(key, nested_dict);
+ }
+ return nested_dict;
+}
+
+} // namespace
+
+ShillProfileClientStub::ShillProfileClientStub() {
}
ShillProfileClientStub::~ShillProfileClientStub() {
@@ -37,13 +71,21 @@ void ShillProfileClientStub::GetProperties(
const dbus::ObjectPath& profile_path,
const DictionaryValueCallbackWithoutStatus& callback,
const ErrorCallback& error_callback) {
- if (callback.is_null())
+ base::DictionaryValue* profile = GetProfile(profile_path, error_callback);
+ if (!profile)
return;
+
+ scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue);
+ base::ListValue* entry_paths = new base::ListValue;
+ properties->SetWithoutPathExpansion(flimflam::kEntriesProperty, entry_paths);
+ for (base::DictionaryValue::Iterator it(*profile); !it.IsAtEnd();
+ it.Advance()) {
+ entry_paths->AppendString(it.key());
+ }
+
MessageLoop::current()->PostTask(
FROM_HERE,
- base::Bind(&ShillProfileClientStub::PassEmptyDictionaryValue,
- weak_ptr_factory_.GetWeakPtr(),
- callback));
+ base::Bind(&PassDictionary, callback, base::Owned(properties.release())));
}
void ShillProfileClientStub::GetEntry(
@@ -51,28 +93,83 @@ void ShillProfileClientStub::GetEntry(
const std::string& entry_path,
const DictionaryValueCallbackWithoutStatus& callback,
const ErrorCallback& error_callback) {
- if (callback.is_null())
+ base::DictionaryValue* profile = GetProfile(profile_path, error_callback);
+ if (!profile)
+ return;
+
+ base::DictionaryValue* entry = NULL;
+ profile->GetDictionaryWithoutPathExpansion(entry_path, &entry);
+ if (!entry) {
+ error_callback.Run("Error.InvalidProfileEntry", "Invalid profile entry");
return;
+ }
+
MessageLoop::current()->PostTask(
FROM_HERE,
- base::Bind(&ShillProfileClientStub::PassEmptyDictionaryValue,
- weak_ptr_factory_.GetWeakPtr(),
- callback));
+ base::Bind(&PassDictionary, callback, base::Owned(entry->DeepCopy())));
}
void ShillProfileClientStub::DeleteEntry(const dbus::ObjectPath& profile_path,
const std::string& entry_path,
const base::Closure& callback,
const ErrorCallback& error_callback) {
- if (callback.is_null())
+ base::DictionaryValue* profile = GetProfile(profile_path, error_callback);
+ if (!profile)
return;
+
+ if (!profile->RemoveWithoutPathExpansion(entry_path, NULL)) {
+ error_callback.Run("Error.InvalidProfileEntry", "Invalid profile entry");
+ return;
+ }
+
MessageLoop::current()->PostTask(FROM_HERE, callback);
}
-void ShillProfileClientStub::PassEmptyDictionaryValue(
- const DictionaryValueCallbackWithoutStatus& callback) const {
- base::DictionaryValue dictionary;
- callback.Run(dictionary);
+ShillProfileClient::TestInterface* ShillProfileClientStub::GetTestInterface() {
+ return this;
+}
+
+void ShillProfileClientStub::AddProfile(const std::string& profile_path) {
+ profile_entries_.SetWithoutPathExpansion(profile_path,
+ new base::DictionaryValue);
+}
+
+void ShillProfileClientStub::AddEntry(const std::string& profile_path,
+ const std::string& entry_path,
+ const base::DictionaryValue& properties) {
+ base::DictionaryValue* profile = GetOrCreateDictionary(profile_path,
+ &profile_entries_);
+ profile->SetWithoutPathExpansion(entry_path,
+ properties.DeepCopy());
+}
+
+bool ShillProfileClientStub::AddService(const std::string& service_path) {
+ ShillServiceClient::TestInterface* service_test =
+ DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
+ const base::DictionaryValue* properties =
+ service_test->GetServiceProperties(service_path);
+ std::string profile_path;
+ if (!properties)
+ return false;
+
+ properties->GetStringWithoutPathExpansion(flimflam::kProfileProperty,
+ &profile_path);
+ if (profile_path.empty())
+ return false;
+
+ AddEntry(profile_path, service_path, *properties);
+ return true;
+}
+
+base::DictionaryValue* ShillProfileClientStub::GetProfile(
+ const dbus::ObjectPath& profile_path,
+ const ErrorCallback& error_callback) {
+ base::DictionaryValue* profile = NULL;
+ profile_entries_.GetDictionaryWithoutPathExpansion(profile_path.value(),
+ &profile);
+ if (!profile)
+ error_callback.Run("Error.InvalidProfile", "Invalid profile");
+ return profile;
}
} // namespace chromeos
diff --git a/chromeos/dbus/shill_profile_client_stub.h b/chromeos/dbus/shill_profile_client_stub.h
index b26b5a7..efc86ce 100644
--- a/chromeos/dbus/shill_profile_client_stub.h
+++ b/chromeos/dbus/shill_profile_client_stub.h
@@ -13,7 +13,8 @@
namespace chromeos {
// A stub implementation of ShillProfileClient.
-class ShillProfileClientStub : public ShillProfileClient {
+class ShillProfileClientStub : public ShillProfileClient,
+ public ShillProfileClient::TestInterface {
public:
ShillProfileClientStub();
virtual ~ShillProfileClientStub();
@@ -37,14 +38,21 @@ class ShillProfileClientStub : public ShillProfileClient {
const std::string& entry_path,
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE;
+ virtual ShillProfileClient::TestInterface* GetTestInterface() OVERRIDE;
+
+ // ShillProfileClient::TestInterface overrides.
+ virtual void AddProfile(const std::string& profile_path) OVERRIDE;
+ virtual void AddEntry(const std::string& profile_path,
+ const std::string& entry_path,
+ const base::DictionaryValue& properties) OVERRIDE;
+ virtual bool AddService(const std::string& service_path) OVERRIDE;
private:
- void PassEmptyDictionaryValue(
- const DictionaryValueCallbackWithoutStatus& callback) const;
+ base::DictionaryValue* GetProfile(const dbus::ObjectPath& profile_path,
+ const ErrorCallback& error_callback);
- // 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<ShillProfileClientStub> weak_ptr_factory_;
+ // This maps profile path -> entry path -> Shill properties.
+ base::DictionaryValue profile_entries_;
DISALLOW_COPY_AND_ASSIGN(ShillProfileClientStub);
};
diff --git a/chromeos/dbus/shill_service_client.h b/chromeos/dbus/shill_service_client.h
index 05713be..1a96fa4 100644
--- a/chromeos/dbus/shill_service_client.h
+++ b/chromeos/dbus/shill_service_client.h
@@ -64,7 +64,7 @@ class CHROMEOS_EXPORT ShillServiceClient {
virtual void ClearServices() = 0;
protected:
- ~TestInterface() {}
+ virtual ~TestInterface() {}
};
virtual ~ShillServiceClient();
diff --git a/chromeos/dbus/shill_service_client_stub.cc b/chromeos/dbus/shill_service_client_stub.cc
index 3b8f1de..677f9d6 100644
--- a/chromeos/dbus/shill_service_client_stub.cc
+++ b/chromeos/dbus/shill_service_client_stub.cc
@@ -32,6 +32,13 @@ void PassStubListValue(const ShillServiceClient::ListValueCallback& callback,
callback.Run(*value);
}
+void PassStubServiceProperties(
+ const ShillServiceClient::DictionaryValueCallback& callback,
+ DBusMethodCallStatus call_status,
+ const base::DictionaryValue* properties) {
+ callback.Run(call_status, *properties);
+}
+
} // namespace
ShillServiceClientStub::ShillServiceClientStub() : weak_ptr_factory_(this) {
@@ -62,12 +69,29 @@ void ShillServiceClientStub::GetProperties(
const DictionaryValueCallback& callback) {
if (callback.is_null())
return;
+
+ base::DictionaryValue* nested_dict = NULL;
+ scoped_ptr<base::DictionaryValue> result_properties;
+ DBusMethodCallStatus call_status;
+ stub_services_.GetDictionaryWithoutPathExpansion(service_path.value(),
+ &nested_dict);
+ if (nested_dict) {
+ result_properties.reset(nested_dict->DeepCopy());
+ // Remove credentials that Shill wouldn't send.
+ result_properties->RemoveWithoutPathExpansion(flimflam::kPassphraseProperty,
+ NULL);
+ call_status = DBUS_METHOD_CALL_SUCCESS;
+ } else {
+ result_properties.reset(new base::DictionaryValue);
+ call_status = DBUS_METHOD_CALL_FAILURE;
+ }
+
MessageLoop::current()->PostTask(
FROM_HERE,
- base::Bind(&ShillServiceClientStub::PassStubServiceProperties,
- weak_ptr_factory_.GetWeakPtr(),
- service_path,
- callback));
+ base::Bind(&PassStubServiceProperties,
+ callback,
+ call_status,
+ base::Owned(result_properties.release())));
}
void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path,
@@ -77,7 +101,7 @@ void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path,
const ErrorCallback& error_callback) {
base::DictionaryValue* dict = NULL;
if (!stub_services_.GetDictionaryWithoutPathExpansion(
- service_path.value(), &dict)) {
+ service_path.value(), &dict)) {
error_callback.Run("Error.InvalidService", "Invalid Service");
return;
}
@@ -374,19 +398,6 @@ void ShillServiceClientStub::SetDefaultProperties() {
add_to_watchlist);
}
-void ShillServiceClientStub::PassStubServiceProperties(
- const dbus::ObjectPath& service_path,
- const DictionaryValueCallback& callback) {
- base::DictionaryValue* dict = NULL;
- if (!stub_services_.GetDictionaryWithoutPathExpansion(
- service_path.value(), &dict)) {
- base::DictionaryValue empty_dictionary;
- callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary);
- return;
- }
- callback.Run(DBUS_METHOD_CALL_SUCCESS, *dict);
-}
-
void ShillServiceClientStub::NotifyObserversPropertyChanged(
const dbus::ObjectPath& service_path,
const std::string& property) {
diff --git a/chromeos/dbus/shill_service_client_stub.h b/chromeos/dbus/shill_service_client_stub.h
index 507f95f..2e9bfdd 100644
--- a/chromeos/dbus/shill_service_client_stub.h
+++ b/chromeos/dbus/shill_service_client_stub.h
@@ -91,8 +91,6 @@ class ShillServiceClientStub : public ShillServiceClient,
typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList;
void SetDefaultProperties();
- void PassStubServiceProperties(const dbus::ObjectPath& service_path,
- const DictionaryValueCallback& callback);
void NotifyObserversPropertyChanged(const dbus::ObjectPath& service_path,
const std::string& property);
base::DictionaryValue* GetModifiableServiceProperties(