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

Side by Side Diff: trunk/src/chromeos/dbus/shill_service_client.cc

Issue 26075002: Revert 227100 "Track active references in ShillClientHelper (Tak..." (Closed) Base URL: svn://svn.chromium.org/chrome/
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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/chromeos/dbus/shill_profile_client.cc ('k') | trunk/src/dbus/object_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/shill_service_client.h" 5 #include "chromeos/dbus/shill_service_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 9 #include "base/stl_util.h"
11 #include "base/values.h" 10 #include "base/values.h"
12 #include "chromeos/dbus/shill_property_changed_observer.h" 11 #include "chromeos/dbus/shill_property_changed_observer.h"
13 #include "chromeos/dbus/shill_service_client_stub.h" 12 #include "chromeos/dbus/shill_service_client_stub.h"
14 #include "chromeos/network/network_event_log.h"
15 #include "dbus/bus.h" 13 #include "dbus/bus.h"
16 #include "dbus/message.h" 14 #include "dbus/message.h"
17 #include "dbus/object_proxy.h" 15 #include "dbus/object_proxy.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h" 16 #include "third_party/cros_system_api/dbus/service_constants.h"
19 17
20 namespace chromeos { 18 namespace chromeos {
21 19
22 namespace { 20 namespace {
23 21
24 #ifndef DBUS_ERROR_UNKNOWN_OBJECT 22 #ifndef DBUS_ERROR_UNKNOWN_OBJECT
(...skipping 24 matching lines...) Expand all
49 47
50 base::DictionaryValue empty_dictionary; 48 base::DictionaryValue empty_dictionary;
51 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); 49 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary);
52 } 50 }
53 51
54 // The ShillServiceClient implementation. 52 // The ShillServiceClient implementation.
55 class ShillServiceClientImpl : public ShillServiceClient { 53 class ShillServiceClientImpl : public ShillServiceClient {
56 public: 54 public:
57 explicit ShillServiceClientImpl() 55 explicit ShillServiceClientImpl()
58 : bus_(NULL), 56 : bus_(NULL),
59 weak_ptr_factory_(this) { 57 helpers_deleter_(&helpers_) {
60 }
61
62 virtual ~ShillServiceClientImpl() {
63 for (HelperMap::iterator iter = helpers_.begin();
64 iter != helpers_.end(); ++iter) {
65 ShillClientHelper* helper = iter->second;
66 bus_->RemoveObjectProxy(shill::kFlimflamServiceName,
67 helper->object_proxy()->object_path(),
68 base::Bind(&base::DoNothing));
69 delete helper;
70 }
71 } 58 }
72 59
73 virtual void AddPropertyChangedObserver( 60 virtual void AddPropertyChangedObserver(
74 const dbus::ObjectPath& service_path, 61 const dbus::ObjectPath& service_path,
75 ShillPropertyChangedObserver* observer) OVERRIDE { 62 ShillPropertyChangedObserver* observer) OVERRIDE {
76 GetHelper(service_path)->AddPropertyChangedObserver(observer); 63 GetHelper(service_path)->AddPropertyChangedObserver(observer);
77 } 64 }
78 65
79 virtual void RemovePropertyChangedObserver( 66 virtual void RemovePropertyChangedObserver(
80 const dbus::ObjectPath& service_path, 67 const dbus::ObjectPath& service_path,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 private: 215 private:
229 typedef std::map<std::string, ShillClientHelper*> HelperMap; 216 typedef std::map<std::string, ShillClientHelper*> HelperMap;
230 217
231 // Returns the corresponding ShillClientHelper for the profile. 218 // Returns the corresponding ShillClientHelper for the profile.
232 ShillClientHelper* GetHelper(const dbus::ObjectPath& service_path) { 219 ShillClientHelper* GetHelper(const dbus::ObjectPath& service_path) {
233 HelperMap::iterator it = helpers_.find(service_path.value()); 220 HelperMap::iterator it = helpers_.find(service_path.value());
234 if (it != helpers_.end()) 221 if (it != helpers_.end())
235 return it->second; 222 return it->second;
236 223
237 // There is no helper for the profile, create it. 224 // There is no helper for the profile, create it.
238 NET_LOG_DEBUG("AddShillClientHelper", service_path.value());
239 dbus::ObjectProxy* object_proxy = 225 dbus::ObjectProxy* object_proxy =
240 bus_->GetObjectProxy(shill::kFlimflamServiceName, service_path); 226 bus_->GetObjectProxy(shill::kFlimflamServiceName, service_path);
241 ShillClientHelper* helper = new ShillClientHelper(object_proxy); 227 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy);
242 helper->SetReleasedCallback(
243 base::Bind(&ShillServiceClientImpl::NotifyReleased,
244 weak_ptr_factory_.GetWeakPtr()));
245 helper->MonitorPropertyChanged(shill::kFlimflamServiceInterface); 228 helper->MonitorPropertyChanged(shill::kFlimflamServiceInterface);
246 helpers_.insert(HelperMap::value_type(service_path.value(), helper)); 229 helpers_.insert(HelperMap::value_type(service_path.value(), helper));
247 return helper; 230 return helper;
248 } 231 }
249 232
250 void NotifyReleased(ShillClientHelper* helper) {
251 // New Shill Service DBus objects are created relatively frequently, so
252 // remove them when they become inactive (no observers and no active method
253 // calls).
254 const dbus::ObjectPath& object_path = helper->object_proxy()->object_path();
255 NET_LOG_DEBUG("RemoveShillClientHelper", object_path.value());
256 bus_->RemoveObjectProxy(shill::kFlimflamServiceName,
257 object_path, base::Bind(&base::DoNothing));
258 helpers_.erase(object_path.value());
259 delete helper;
260 }
261
262 dbus::Bus* bus_; 233 dbus::Bus* bus_;
263 HelperMap helpers_; 234 HelperMap helpers_;
264 base::WeakPtrFactory<ShillServiceClientImpl> weak_ptr_factory_; 235 STLValueDeleter<HelperMap> helpers_deleter_;
265 236
266 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl); 237 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl);
267 }; 238 };
268 239
269 } // namespace 240 } // namespace
270 241
271 ShillServiceClient::ShillServiceClient() {} 242 ShillServiceClient::ShillServiceClient() {}
272 243
273 ShillServiceClient::~ShillServiceClient() {} 244 ShillServiceClient::~ShillServiceClient() {}
274 245
275 // static 246 // static
276 ShillServiceClient* ShillServiceClient::Create( 247 ShillServiceClient* ShillServiceClient::Create(
277 DBusClientImplementationType type) { 248 DBusClientImplementationType type) {
278 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 249 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
279 return new ShillServiceClientImpl(); 250 return new ShillServiceClientImpl();
280 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 251 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
281 return new ShillServiceClientStub(); 252 return new ShillServiceClientStub();
282 } 253 }
283 254
284 } // namespace chromeos 255 } // namespace chromeos
OLDNEW
« no previous file with comments | « trunk/src/chromeos/dbus/shill_profile_client.cc ('k') | trunk/src/dbus/object_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698