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

Side by Side Diff: chromeos/dbus/shill_client_helper.cc

Issue 12220128: Shill: Delay the ConnectToSignal call until an observer is added. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: nits addressed Created 7 years, 10 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
« no previous file with comments | « chromeos/dbus/shill_client_helper.h ('k') | no next file » | 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_client_helper.h" 5 #include "chromeos/dbus/shill_client_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "dbus/message.h" 9 #include "dbus/message.h"
10 #include "dbus/object_proxy.h" 10 #include "dbus/object_proxy.h"
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 29
30 ShillClientHelper::~ShillClientHelper() { 30 ShillClientHelper::~ShillClientHelper() {
31 LOG_IF(ERROR, observer_list_.size() != 0u) 31 LOG_IF(ERROR, observer_list_.size() != 0u)
32 << "ShillClientHelper destroyed with active observers: " 32 << "ShillClientHelper destroyed with active observers: "
33 << observer_list_.size(); 33 << observer_list_.size();
34 } 34 }
35 35
36 void ShillClientHelper::AddPropertyChangedObserver( 36 void ShillClientHelper::AddPropertyChangedObserver(
37 ShillPropertyChangedObserver* observer) { 37 ShillPropertyChangedObserver* observer) {
38 // Excecutes all the pending MonitorPropertyChanged calls.
hashimoto 2013/02/13 05:56:00 nitty-nit: s/Executes/Execute/ Our style guide doe
deymo 2013/02/13 19:18:11 Done.
39 for (std::vector<std::string>::iterator it =
hashimoto 2013/02/13 05:56:00 nit: "for (size_t i = 0; i < interfaces_to_be_moni
deymo 2013/02/13 19:18:11 Done.
40 interfaces_to_be_monitored_.begin();
41 it != interfaces_to_be_monitored_.end(); ++it) {
42 MonitorPropertyChangedInternal(*it);
43 }
44 interfaces_to_be_monitored_.clear();
45
38 observer_list_.AddObserver(observer); 46 observer_list_.AddObserver(observer);
39 } 47 }
40 48
41 void ShillClientHelper::RemovePropertyChangedObserver( 49 void ShillClientHelper::RemovePropertyChangedObserver(
42 ShillPropertyChangedObserver* observer) { 50 ShillPropertyChangedObserver* observer) {
43 observer_list_.RemoveObserver(observer); 51 observer_list_.RemoveObserver(observer);
44 } 52 }
45 53
46 void ShillClientHelper::MonitorPropertyChanged( 54 void ShillClientHelper::MonitorPropertyChanged(
47 const std::string& interface_name) { 55 const std::string& interface_name) {
56 if (observer_list_.size() > 0) {
57 // Effectively monitor the PropertyChanged now.
58 MonitorPropertyChangedInternal(interface_name);
59 } else {
60 // Delay the ConnectToSignal until an observer is added.
61 interfaces_to_be_monitored_.push_back(interface_name);
62 }
63 }
64
65 void ShillClientHelper::MonitorPropertyChangedInternal(
66 const std::string& interface_name) {
48 // We are not using dbus::PropertySet to monitor PropertyChanged signal 67 // We are not using dbus::PropertySet to monitor PropertyChanged signal
49 // because the interface is not "org.freedesktop.DBus.Properties". 68 // because the interface is not "org.freedesktop.DBus.Properties".
50 proxy_->ConnectToSignal(interface_name, 69 proxy_->ConnectToSignal(interface_name,
51 flimflam::kMonitorPropertyChanged, 70 flimflam::kMonitorPropertyChanged,
52 base::Bind(&ShillClientHelper::OnPropertyChanged, 71 base::Bind(&ShillClientHelper::OnPropertyChanged,
53 weak_ptr_factory_.GetWeakPtr()), 72 weak_ptr_factory_.GetWeakPtr()),
54 base::Bind(&ShillClientHelper::OnSignalConnected, 73 base::Bind(&ShillClientHelper::OnSignalConnected,
55 weak_ptr_factory_.GetWeakPtr())); 74 weak_ptr_factory_.GetWeakPtr()));
56 } 75 }
57 76
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (response) { 356 if (response) {
338 // Error message may contain the error message as string. 357 // Error message may contain the error message as string.
339 dbus::MessageReader reader(response); 358 dbus::MessageReader reader(response);
340 error_name = response->GetErrorName(); 359 error_name = response->GetErrorName();
341 reader.PopString(&error_message); 360 reader.PopString(&error_message);
342 } 361 }
343 error_callback.Run(error_name, error_message); 362 error_callback.Run(error_name, error_message);
344 } 363 }
345 364
346 } // namespace chromeos 365 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_client_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698