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

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: 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
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.
39 for (std::vector<std::string>::iterator it = monitored_interfaces_.begin();
40 it != monitored_interfaces_.end(); ++it) {
41 MonitorPropertyChangedInternal(*it);
42 }
43 monitored_interfaces_.clear();
44
38 observer_list_.AddObserver(observer); 45 observer_list_.AddObserver(observer);
39 } 46 }
40 47
41 void ShillClientHelper::RemovePropertyChangedObserver( 48 void ShillClientHelper::RemovePropertyChangedObserver(
42 ShillPropertyChangedObserver* observer) { 49 ShillPropertyChangedObserver* observer) {
43 observer_list_.RemoveObserver(observer); 50 observer_list_.RemoveObserver(observer);
44 } 51 }
45 52
46 void ShillClientHelper::MonitorPropertyChanged( 53 void ShillClientHelper::MonitorPropertyChanged(
47 const std::string& interface_name) { 54 const std::string& interface_name) {
55 if (observer_list_.size() > 0)
hashimoto 2013/02/13 04:01:31 nit: if-statement without curly braces are not all
deymo 2013/02/13 05:41:07 Done.
56 // Effectively monitor the PropertyChanged now.
57 MonitorPropertyChangedInternal(interface_name);
58 else
59 // Delay the ConnectToSignal until an observer is added.
60 monitored_interfaces_.push_back(interface_name);
61 }
62
63 void ShillClientHelper::MonitorPropertyChangedInternal(
64 const std::string& interface_name) {
48 // We are not using dbus::PropertySet to monitor PropertyChanged signal 65 // We are not using dbus::PropertySet to monitor PropertyChanged signal
49 // because the interface is not "org.freedesktop.DBus.Properties". 66 // because the interface is not "org.freedesktop.DBus.Properties".
50 proxy_->ConnectToSignal(interface_name, 67 proxy_->ConnectToSignal(interface_name,
51 flimflam::kMonitorPropertyChanged, 68 flimflam::kMonitorPropertyChanged,
52 base::Bind(&ShillClientHelper::OnPropertyChanged, 69 base::Bind(&ShillClientHelper::OnPropertyChanged,
53 weak_ptr_factory_.GetWeakPtr()), 70 weak_ptr_factory_.GetWeakPtr()),
54 base::Bind(&ShillClientHelper::OnSignalConnected, 71 base::Bind(&ShillClientHelper::OnSignalConnected,
55 weak_ptr_factory_.GetWeakPtr())); 72 weak_ptr_factory_.GetWeakPtr()));
56 } 73 }
57 74
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (response) { 354 if (response) {
338 // Error message may contain the error message as string. 355 // Error message may contain the error message as string.
339 dbus::MessageReader reader(response); 356 dbus::MessageReader reader(response);
340 error_name = response->GetErrorName(); 357 error_name = response->GetErrorName();
341 reader.PopString(&error_message); 358 reader.PopString(&error_message);
342 } 359 }
343 error_callback.Run(error_name, error_message); 360 error_callback.Run(error_name, error_message);
344 } 361 }
345 362
346 } // namespace chromeos 363 } // namespace chromeos
OLDNEW
« chromeos/dbus/shill_client_helper.h ('K') | « chromeos/dbus/shill_client_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698