| Index: chromeos/dbus/shill_profile_client_stub.cc
|
| diff --git a/chromeos/dbus/shill_profile_client_stub.cc b/chromeos/dbus/shill_profile_client_stub.cc
|
| index 9b427bb4be508f39e0a0f5b56d6d12bd90cb627d..e249cd551ef7469941e93040ad1187ac94813f81 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
|
|
|