diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-17 01:22:10 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-17 01:22:10 +0000 |
commit | 4b90452ae334ce1401b5408c4576262f628dc2de (patch) | |
tree | 843e27da78d75c1ee4d85b3d6414f3ad443d6cd5 /chromeos/dbus/flimflam_profile_client.cc | |
parent | 8737cec4bd7341fc4f2b0fb0fa63caabb5409dec (diff) | |
download | chromium_src-4b90452ae334ce1401b5408c4576262f628dc2de.zip chromium_src-4b90452ae334ce1401b5408c4576262f628dc2de.tar.gz chromium_src-4b90452ae334ce1401b5408c4576262f628dc2de.tar.bz2 |
Reimplement Libcros fucntions using FlimflamProfileClient
Change FlimflamProfileClient's interface to deal with multiple profile objects
Change FlimflamProfileClient's interface to send an entry's path as a string, not an ObjectPath
Add non-Libcros implementations of CrosDeleteServiceFromProfile, CrosRequestNetworkProfileProperties and CrosRequestNetworkProfileEntryProperties
Add EnableNonLibcrosNetworkFunctions
Add --enable-non-libcros-network-functions commandline option
Rename existing CrosNetworkFunctionsTest to CrosNetworkFunctionsLibcrosTest
Add new CrosNetworkFunctionsTest which tests the non Libcros implementation
BUG=chromium-os:16557
TEST=unit_tests --gtest_filter="CrosNetworkFunctions*"
Review URL: https://chromiumcodereview.appspot.com/9958045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132502 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus/flimflam_profile_client.cc')
-rw-r--r-- | chromeos/dbus/flimflam_profile_client.cc | 100 |
1 files changed, 61 insertions, 39 deletions
diff --git a/chromeos/dbus/flimflam_profile_client.cc b/chromeos/dbus/flimflam_profile_client.cc index 9079109..edc7ce6 100644 --- a/chromeos/dbus/flimflam_profile_client.cc +++ b/chromeos/dbus/flimflam_profile_client.cc @@ -6,11 +6,11 @@ #include "base/bind.h" #include "base/message_loop.h" +#include "base/stl_util.h" #include "base/values.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_path.h" -#include "dbus/object_proxy.h" #include "dbus/values_util.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -25,74 +25,91 @@ class FlimflamProfileClientImpl : public FlimflamProfileClient { // FlimflamProfileClient overrides: virtual void SetPropertyChangedHandler( + const dbus::ObjectPath& profile_path, const PropertyChangedHandler& handler) OVERRIDE; - virtual void ResetPropertyChangedHandler() OVERRIDE; - virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE; - virtual void GetEntry(const dbus::ObjectPath& path, + virtual void ResetPropertyChangedHandler( + const dbus::ObjectPath& profile_path) OVERRIDE; + virtual void GetProperties(const dbus::ObjectPath& profile_path, + const DictionaryValueCallback& callback) OVERRIDE; + virtual void GetEntry(const dbus::ObjectPath& profile_path, + const std::string& entry_path, const DictionaryValueCallback& callback) OVERRIDE; - virtual void DeleteEntry(const dbus::ObjectPath& path, + virtual void DeleteEntry(const dbus::ObjectPath& profile_path, + const std::string& entry_path, const VoidCallback& callback) OVERRIDE; private: - // Handles the result of signal connection setup. - void OnSignalConnected(const std::string& interface, - const std::string& signal, - bool success); - // Handles PropertyChanged signal. - void OnPropertyChanged(dbus::Signal* signal); - // Handles responses for methods without results. - void OnVoidMethod(const VoidCallback& callback, dbus::Response* response); - // Handles responses for methods with DictionaryValue results. - void OnDictionaryValueMethod(const DictionaryValueCallback& callback, - dbus::Response* response); - - dbus::ObjectProxy* proxy_; - FlimflamClientHelper helper_; + typedef std::map<std::string, FlimflamClientHelper*> HelperMap; + + // Returns the corresponding FlimflamClientHelper for the profile. + FlimflamClientHelper* GetHelper(const dbus::ObjectPath& profile_path); + + dbus::Bus* bus_; + HelperMap helpers_; + STLValueDeleter<HelperMap> helpers_deleter_; DISALLOW_COPY_AND_ASSIGN(FlimflamProfileClientImpl); }; FlimflamProfileClientImpl::FlimflamProfileClientImpl(dbus::Bus* bus) - : proxy_(bus->GetObjectProxy( - flimflam::kFlimflamServiceName, - dbus::ObjectPath(flimflam::kFlimflamServicePath))), - helper_(proxy_) { - helper_.MonitorPropertyChanged(flimflam::kFlimflamProfileInterface); + : bus_(bus), + helpers_deleter_(&helpers_) { +} + +FlimflamClientHelper* FlimflamProfileClientImpl::GetHelper( + const dbus::ObjectPath& profile_path) { + HelperMap::iterator it = helpers_.find(profile_path.value()); + if (it != helpers_.end()) + return it->second; + + // There is no helper for the profile, create it. + dbus::ObjectProxy* object_proxy = + bus_->GetObjectProxy(flimflam::kFlimflamServiceName, profile_path); + FlimflamClientHelper* helper = new FlimflamClientHelper(object_proxy); + helper->MonitorPropertyChanged(flimflam::kFlimflamProfileInterface); + helpers_.insert(HelperMap::value_type(profile_path.value(), helper)); + return helper; } void FlimflamProfileClientImpl::SetPropertyChangedHandler( + const dbus::ObjectPath& profile_path, const PropertyChangedHandler& handler) { - helper_.SetPropertyChangedHandler(handler); + GetHelper(profile_path)->SetPropertyChangedHandler(handler); } -void FlimflamProfileClientImpl::ResetPropertyChangedHandler() { - helper_.ResetPropertyChangedHandler(); +void FlimflamProfileClientImpl::ResetPropertyChangedHandler( + const dbus::ObjectPath& profile_path) { + GetHelper(profile_path)->ResetPropertyChangedHandler(); } void FlimflamProfileClientImpl::GetProperties( + const dbus::ObjectPath& profile_path, const DictionaryValueCallback& callback) { dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, flimflam::kGetPropertiesFunction); - helper_.CallDictionaryValueMethod(&method_call, callback); + GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback); } void FlimflamProfileClientImpl::GetEntry( - const dbus::ObjectPath& path, + const dbus::ObjectPath& profile_path, + const std::string& entry_path, const DictionaryValueCallback& callback) { dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, flimflam::kGetEntryFunction); dbus::MessageWriter writer(&method_call); - writer.AppendObjectPath(path); - helper_.CallDictionaryValueMethod(&method_call, callback); + writer.AppendString(entry_path); + GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback); } -void FlimflamProfileClientImpl::DeleteEntry(const dbus::ObjectPath& path, - const VoidCallback& callback) { +void FlimflamProfileClientImpl::DeleteEntry( + const dbus::ObjectPath& profile_path, + const std::string& entry_path, + const VoidCallback& callback) { dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, flimflam::kDeleteEntryFunction); dbus::MessageWriter writer(&method_call); - writer.AppendObjectPath(path); - helper_.CallVoidMethod(&method_call, callback); + writer.AppendString(entry_path); + GetHelper(profile_path)->CallVoidMethod(&method_call, callback); } // A stub implementation of FlimflamProfileClient. @@ -104,13 +121,16 @@ class FlimflamProfileClientStubImpl : public FlimflamProfileClient { // FlimflamProfileClient override. virtual void SetPropertyChangedHandler( + const dbus::ObjectPath& profile_path, const PropertyChangedHandler& handler) OVERRIDE {} // FlimflamProfileClient override. - virtual void ResetPropertyChangedHandler() OVERRIDE {} + virtual void ResetPropertyChangedHandler( + const dbus::ObjectPath& profile_path) OVERRIDE {} // FlimflamProfileClient override. - virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE { + virtual void GetProperties(const dbus::ObjectPath& profile_path, + const DictionaryValueCallback& callback) OVERRIDE { MessageLoop::current()->PostTask( FROM_HERE, base::Bind(&FlimflamProfileClientStubImpl::PassEmptyDictionaryValue, @@ -119,7 +139,8 @@ class FlimflamProfileClientStubImpl : public FlimflamProfileClient { } // FlimflamProfileClient override. - virtual void GetEntry(const dbus::ObjectPath& path, + virtual void GetEntry(const dbus::ObjectPath& profile_path, + const std::string& entry_path, const DictionaryValueCallback& callback) OVERRIDE { MessageLoop::current()->PostTask( FROM_HERE, @@ -129,7 +150,8 @@ class FlimflamProfileClientStubImpl : public FlimflamProfileClient { } // FlimflamProfileClient override. - virtual void DeleteEntry(const dbus::ObjectPath& path, + virtual void DeleteEntry(const dbus::ObjectPath& profile_path, + const std::string& entry_path, const VoidCallback& callback) OVERRIDE { MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, |