Index: chromeos/dbus/shill_service_client.cc |
diff --git a/chromeos/dbus/shill_service_client.cc b/chromeos/dbus/shill_service_client.cc |
index b4840b6f8c21f03ecca6dcb0a392729edbda1120..86b79329a059a15adc73521967932dcff2593151 100644 |
--- a/chromeos/dbus/shill_service_client.cc |
+++ b/chromeos/dbus/shill_service_client.cc |
@@ -10,6 +10,7 @@ |
#include "base/values.h" |
#include "chromeos/dbus/shill_property_changed_observer.h" |
#include "chromeos/dbus/shill_service_client_stub.h" |
+#include "chromeos/network/network_event_log.h" |
#include "dbus/bus.h" |
#include "dbus/message.h" |
#include "dbus/object_proxy.h" |
@@ -50,7 +51,8 @@ void OnGetDictionaryError( |
} |
// The ShillServiceClient implementation. |
-class ShillServiceClientImpl : public ShillServiceClient { |
+class ShillServiceClientImpl : public ShillServiceClient, |
+ public ShillClientHelper::Owner { |
public: |
explicit ShillServiceClientImpl() |
: bus_(NULL), |
@@ -222,14 +224,29 @@ class ShillServiceClientImpl : public ShillServiceClient { |
return it->second; |
// There is no helper for the profile, create it. |
+ NET_LOG_DEBUG("AddShillClientHelper", service_path.value()); |
dbus::ObjectProxy* object_proxy = |
bus_->GetObjectProxy(flimflam::kFlimflamServiceName, service_path); |
- ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy); |
+ ShillClientHelper* helper = new ShillClientHelper(object_proxy); |
+ helper->SetOwner(this); |
helper->MonitorPropertyChanged(flimflam::kFlimflamServiceInterface); |
helpers_.insert(HelperMap::value_type(service_path.value(), helper)); |
return helper; |
} |
+ // ShillClientHelper::Owner |
+ virtual void NotifyReleased(ShillClientHelper* helper) OVERRIDE { |
+ // New Shill Service DBus objects are created relatively frequently, so |
+ // remove them when they become inactive (no observers and no active method |
+ // calls). |
+ const dbus::ObjectPath& object_path = helper->object_proxy()->object_path(); |
+ NET_LOG_DEBUG("RemoveShillClientHelper", object_path.value()); |
+ bus_->RemoveObjectProxy(flimflam::kFlimflamServiceName, |
+ object_path, base::Bind(&base::DoNothing)); |
+ helpers_.erase(object_path.value()); |
+ delete helper; |
+ } |
+ |
dbus::Bus* bus_; |
HelperMap helpers_; |
STLValueDeleter<HelperMap> helpers_deleter_; |