Chromium Code Reviews| Index: chromeos/dbus/flimflam_profile_client.cc |
| diff --git a/chromeos/dbus/flimflam_profile_client.cc b/chromeos/dbus/flimflam_profile_client.cc |
| index 81aedb6bb1aa571532566260e75d364cfd949690..9bc637c6cf9964748544928fc896269a31fb6914 100644 |
| --- a/chromeos/dbus/flimflam_profile_client.cc |
| +++ b/chromeos/dbus/flimflam_profile_client.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/bind.h" |
| #include "base/message_loop.h" |
| +#include "base/stl_util.h" |
| #include "dbus/bus.h" |
| #include "dbus/message.h" |
| #include "dbus/object_path.h" |
| @@ -24,15 +25,24 @@ 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: |
| + typedef std::map<std::string, FlimflamClientHelper*> HelpersMap; |
|
stevenjb
2012/04/12 17:34:36
s/HelpersMap/HelperMap/
hashimoto
2012/04/13 05:27:22
Done.
|
| + |
| + // Returns the corresponding FlimflamClientHelper for the profile. |
| + FlimflamClientHelper* GetHelper(const dbus::ObjectPath& profile_path); |
| // Handles the result of signal connection setup. |
| void OnSignalConnected(const std::string& interface, |
| const std::string& signal, |
| @@ -45,53 +55,72 @@ class FlimflamProfileClientImpl : public FlimflamProfileClient { |
| void OnDictionaryValueMethod(const DictionaryValueCallback& callback, |
| dbus::Response* response); |
| - dbus::ObjectProxy* proxy_; |
| - FlimflamClientHelper helper_; |
| + dbus::Bus* bus_; |
| + HelpersMap helpers_; |
| + STLValueDeleter<HelpersMap> 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) { |
| + HelpersMap::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(HelpersMap::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. |
| @@ -103,13 +132,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, |
| @@ -118,7 +150,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, |
| @@ -128,7 +161,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, |