Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Unified Diff: chromeos/dbus/shill_service_client.cc

Issue 26289002: Track active references in ShillClientHelper (Take 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/shill_profile_client.cc ('k') | dbus/bus.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/shill_service_client.cc
diff --git a/chromeos/dbus/shill_service_client.cc b/chromeos/dbus/shill_service_client.cc
index 40143f66caf2e011a4c7f9742f4b141ec375d670..696fb63cd95b9bb11238e2c9401ba4ab883e56ae 100644
--- a/chromeos/dbus/shill_service_client.cc
+++ b/chromeos/dbus/shill_service_client.cc
@@ -5,11 +5,13 @@
#include "chromeos/dbus/shill_service_client.h"
#include "base/bind.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
#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"
@@ -54,7 +56,18 @@ class ShillServiceClientImpl : public ShillServiceClient {
public:
explicit ShillServiceClientImpl()
: bus_(NULL),
- helpers_deleter_(&helpers_) {
+ weak_ptr_factory_(this) {
+ }
+
+ virtual ~ShillServiceClientImpl() {
+ for (HelperMap::iterator iter = helpers_.begin();
+ iter != helpers_.end(); ++iter) {
+ ShillClientHelper* helper = iter->second;
+ bus_->RemoveObjectProxy(shill::kFlimflamServiceName,
+ helper->object_proxy()->object_path(),
+ base::Bind(&base::DoNothing));
+ delete helper;
+ }
}
virtual void AddPropertyChangedObserver(
@@ -222,17 +235,33 @@ 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(shill::kFlimflamServiceName, service_path);
- ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy);
+ ShillClientHelper* helper = new ShillClientHelper(object_proxy);
+ helper->SetReleasedCallback(
+ base::Bind(&ShillServiceClientImpl::NotifyReleased,
+ weak_ptr_factory_.GetWeakPtr()));
helper->MonitorPropertyChanged(shill::kFlimflamServiceInterface);
helpers_.insert(HelperMap::value_type(service_path.value(), helper));
return helper;
}
+ void NotifyReleased(ShillClientHelper* helper) {
+ // New Shill Service DBus objects are created relatively frequently, so
+ // remove them when they become inactive (no observers and no active method
+ // calls).
+ dbus::ObjectPath object_path = helper->object_proxy()->object_path();
+ NET_LOG_DEBUG("RemoveShillClientHelper", object_path.value());
+ bus_->RemoveObjectProxy(shill::kFlimflamServiceName,
+ object_path, base::Bind(&base::DoNothing));
+ helpers_.erase(object_path.value());
+ delete helper;
+ }
+
dbus::Bus* bus_;
HelperMap helpers_;
- STLValueDeleter<HelperMap> helpers_deleter_;
+ base::WeakPtrFactory<ShillServiceClientImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl);
};
« no previous file with comments | « chromeos/dbus/shill_profile_client.cc ('k') | dbus/bus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698