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

Unified Diff: chromeos/dbus/shill_client_helper.cc

Issue 12220025: Shill: ShillServiceClient destroys ShillClientHelpers when they are not need. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Delay in the ConnectToSignal call introduced. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/shill_client_helper.h ('k') | chromeos/dbus/shill_service_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/shill_client_helper.cc
diff --git a/chromeos/dbus/shill_client_helper.cc b/chromeos/dbus/shill_client_helper.cc
index c83bfe0b9d3530f1c9f859eeba37beb225e625d7..c66659c3499955d7d40e7854b1d806c4c764e6be 100644
--- a/chromeos/dbus/shill_client_helper.cc
+++ b/chromeos/dbus/shill_client_helper.cc
@@ -24,6 +24,7 @@ ShillClientHelper::ShillClientHelper(dbus::Bus* bus,
dbus::ObjectProxy* proxy)
: blocking_method_caller_(bus, proxy),
proxy_(proxy),
+ in_progress_calls_(0),
weak_ptr_factory_(this) {
}
@@ -33,8 +34,23 @@ ShillClientHelper::~ShillClientHelper() {
<< observer_list_.size();
}
+bool ShillClientHelper::IsObserved() const {
+ return observer_list_.size() > 0;
+}
+
+bool ShillClientHelper::IsWaitingResponse() const {
+ return in_progress_calls_ > 0;
+}
+
void ShillClientHelper::AddPropertyChangedObserver(
ShillPropertyChangedObserver* observer) {
+ // Excecutes all the pending MonitorPropertyChanged calls.
+ for (std::vector<std::string>::iterator it = monitored_interfaces_.begin();
+ it != monitored_interfaces_.end(); ++it) {
+ MonitorPropertyChangedInternal(*it);
+ }
+ monitored_interfaces_.clear();
+
observer_list_.AddObserver(observer);
}
@@ -45,6 +61,16 @@ void ShillClientHelper::RemovePropertyChangedObserver(
void ShillClientHelper::MonitorPropertyChanged(
const std::string& interface_name) {
+ if (observer_list_.size() > 0)
+ // Effectively monitor the PropertyChanged now.
+ MonitorPropertyChangedInternal(interface_name);
+ else
+ // Delay the ConnectToSignal until an observer is added.
+ monitored_interfaces_.push_back(interface_name);
+}
+
+void ShillClientHelper::MonitorPropertyChangedInternal(
+ const std::string& interface_name) {
// We are not using dbus::PropertySet to monitor PropertyChanged signal
// because the interface is not "org.freedesktop.DBus.Properties".
proxy_->ConnectToSignal(interface_name,
@@ -58,6 +84,7 @@ void ShillClientHelper::MonitorPropertyChanged(
void ShillClientHelper::CallVoidMethod(
dbus::MethodCall* method_call,
const VoidDBusMethodCallback& callback) {
+ ++in_progress_calls_;
proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&ShillClientHelper::OnVoidMethod,
weak_ptr_factory_.GetWeakPtr(),
@@ -67,6 +94,7 @@ void ShillClientHelper::CallVoidMethod(
void ShillClientHelper::CallObjectPathMethod(
dbus::MethodCall* method_call,
const ObjectPathDBusMethodCallback& callback) {
+ ++in_progress_calls_;
proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&ShillClientHelper::OnObjectPathMethod,
weak_ptr_factory_.GetWeakPtr(),
@@ -77,6 +105,7 @@ void ShillClientHelper::CallObjectPathMethodWithErrorCallback(
dbus::MethodCall* method_call,
const ObjectPathCallback& callback,
const ErrorCallback& error_callback) {
+ ++in_progress_calls_;
proxy_->CallMethodWithErrorCallback(
method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
@@ -92,6 +121,7 @@ void ShillClientHelper::CallObjectPathMethodWithErrorCallback(
void ShillClientHelper::CallDictionaryValueMethod(
dbus::MethodCall* method_call,
const DictionaryValueCallback& callback) {
+ ++in_progress_calls_;
proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&ShillClientHelper::OnDictionaryValueMethod,
weak_ptr_factory_.GetWeakPtr(),
@@ -102,6 +132,7 @@ void ShillClientHelper::CallVoidMethodWithErrorCallback(
dbus::MethodCall* method_call,
const base::Closure& callback,
const ErrorCallback& error_callback) {
+ ++in_progress_calls_;
proxy_->CallMethodWithErrorCallback(
method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&ShillClientHelper::OnVoidMethodWithErrorCallback,
@@ -116,6 +147,7 @@ void ShillClientHelper::CallDictionaryValueMethodWithErrorCallback(
dbus::MethodCall* method_call,
const DictionaryValueCallbackWithoutStatus& callback,
const ErrorCallback& error_callback) {
+ ++in_progress_calls_;
proxy_->CallMethodWithErrorCallback(
method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(
@@ -132,6 +164,7 @@ void ShillClientHelper::CallListValueMethodWithErrorCallback(
dbus::MethodCall* method_call,
const ListValueCallback& callback,
const ErrorCallback& error_callback) {
+ ++in_progress_calls_;
proxy_->CallMethodWithErrorCallback(
method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(
@@ -237,6 +270,7 @@ void ShillClientHelper::OnPropertyChanged(dbus::Signal* signal) {
void ShillClientHelper::OnVoidMethod(const VoidDBusMethodCallback& callback,
dbus::Response* response) {
+ --in_progress_calls_;
if (!response) {
callback.Run(DBUS_METHOD_CALL_FAILURE);
return;
@@ -247,6 +281,7 @@ void ShillClientHelper::OnVoidMethod(const VoidDBusMethodCallback& callback,
void ShillClientHelper::OnObjectPathMethod(
const ObjectPathDBusMethodCallback& callback,
dbus::Response* response) {
+ --in_progress_calls_;
if (!response) {
callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath());
return;
@@ -264,6 +299,7 @@ void ShillClientHelper::OnObjectPathMethodWithoutStatus(
const ObjectPathCallback& callback,
const ErrorCallback& error_callback,
dbus::Response* response) {
+ --in_progress_calls_;
if (!response) {
error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
return;
@@ -280,6 +316,7 @@ void ShillClientHelper::OnObjectPathMethodWithoutStatus(
void ShillClientHelper::OnDictionaryValueMethod(
const DictionaryValueCallback& callback,
dbus::Response* response) {
+ --in_progress_calls_;
if (!response) {
base::DictionaryValue result;
callback.Run(DBUS_METHOD_CALL_FAILURE, result);
@@ -299,6 +336,7 @@ void ShillClientHelper::OnDictionaryValueMethod(
void ShillClientHelper::OnVoidMethodWithErrorCallback(
const base::Closure& callback,
dbus::Response* response) {
+ --in_progress_calls_;
callback.Run();
}
@@ -306,6 +344,7 @@ void ShillClientHelper::OnDictionaryValueMethodWithErrorCallback(
const DictionaryValueCallbackWithoutStatus& callback,
const ErrorCallback& error_callback,
dbus::Response* response) {
+ --in_progress_calls_;
dbus::MessageReader reader(response);
scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
base::DictionaryValue* result = NULL;
@@ -320,6 +359,7 @@ void ShillClientHelper::OnListValueMethodWithErrorCallback(
const ListValueCallback& callback,
const ErrorCallback& error_callback,
dbus::Response* response) {
+ --in_progress_calls_;
dbus::MessageReader reader(response);
scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
base::ListValue* result = NULL;
@@ -332,6 +372,7 @@ void ShillClientHelper::OnListValueMethodWithErrorCallback(
void ShillClientHelper::OnError(const ErrorCallback& error_callback,
dbus::ErrorResponse* response) {
+ --in_progress_calls_;
std::string error_name;
std::string error_message;
if (response) {
« no previous file with comments | « chromeos/dbus/shill_client_helper.h ('k') | chromeos/dbus/shill_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698