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

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

Issue 24293002: Revert 224179 "Track active references in ShillClientHelper" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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
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/callback_helpers.h"
9 #include "base/values.h" 8 #include "base/values.h"
10 #include "dbus/message.h" 9 #include "dbus/message.h"
11 #include "dbus/object_proxy.h" 10 #include "dbus/object_proxy.h"
12 #include "dbus/values_util.h" 11 #include "dbus/values_util.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 12 #include "third_party/cros_system_api/dbus/service_constants.h"
14 13
15 namespace chromeos { 14 namespace chromeos {
16 15
17 // Class to hold onto a reference to a ShillClientHelper. This calss
18 // is owned by callbacks and released once the callback completes.
19 // Note: Only success callbacks hold the reference. If an error callback is
20 // invoked instead, the success callback will still be destroyed and the
21 // RefHolder with it, once the callback chain completes.
22 class ShillClientHelper::RefHolder {
23 public:
24 explicit RefHolder(base::WeakPtr<ShillClientHelper> helper)
25 : helper_(helper) {
26 helper_->AddRef();
27 }
28 ~RefHolder() {
29 if (helper_)
30 helper_->Release();
31 }
32
33 private:
34 base::WeakPtr<ShillClientHelper> helper_;
35 };
36
37 namespace { 16 namespace {
38 17
39 const char kInvalidResponseErrorName[] = ""; // No error name. 18 const char kInvalidResponseErrorName[] = ""; // No error name.
40 const char kInvalidResponseErrorMessage[] = "Invalid response."; 19 const char kInvalidResponseErrorMessage[] = "Invalid response.";
41 20
42 // Note: here and below, |ref_holder| is unused in the function body. It only
43 // exists so that it will be destroyed (and the reference released) with the
44 // Callback object once completed.
45 void OnBooleanMethodWithErrorCallback( 21 void OnBooleanMethodWithErrorCallback(
46 ShillClientHelper::RefHolder* ref_holder,
47 const ShillClientHelper::BooleanCallback& callback, 22 const ShillClientHelper::BooleanCallback& callback,
48 const ShillClientHelper::ErrorCallback& error_callback, 23 const ShillClientHelper::ErrorCallback& error_callback,
49 dbus::Response* response) { 24 dbus::Response* response) {
50 if (!response) { 25 if (!response) {
51 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); 26 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
52 return; 27 return;
53 } 28 }
54 dbus::MessageReader reader(response); 29 dbus::MessageReader reader(response);
55 bool result; 30 bool result;
56 if (!reader.PopBool(&result)) { 31 if (!reader.PopBool(&result)) {
57 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); 32 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
58 return; 33 return;
59 } 34 }
60 callback.Run(result); 35 callback.Run(result);
61 } 36 }
62 37
63 void OnStringMethodWithErrorCallback( 38 void OnStringMethodWithErrorCallback(
64 ShillClientHelper::RefHolder* ref_holder,
65 const ShillClientHelper::StringCallback& callback, 39 const ShillClientHelper::StringCallback& callback,
66 const ShillClientHelper::ErrorCallback& error_callback, 40 const ShillClientHelper::ErrorCallback& error_callback,
67 dbus::Response* response) { 41 dbus::Response* response) {
68 if (!response) { 42 if (!response) {
69 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); 43 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
70 return; 44 return;
71 } 45 }
72 dbus::MessageReader reader(response); 46 dbus::MessageReader reader(response);
73 std::string result; 47 std::string result;
74 if (!reader.PopString(&result)) { 48 if (!reader.PopString(&result)) {
75 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); 49 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
76 return; 50 return;
77 } 51 }
78 callback.Run(result); 52 callback.Run(result);
79 } 53 }
80 54
81 // Handles responses for methods without results. 55 // Handles responses for methods without results.
82 void OnVoidMethod(ShillClientHelper::RefHolder* ref_holder, 56 void OnVoidMethod(const VoidDBusMethodCallback& callback,
83 const VoidDBusMethodCallback& callback,
84 dbus::Response* response) { 57 dbus::Response* response) {
85 if (!response) { 58 if (!response) {
86 callback.Run(DBUS_METHOD_CALL_FAILURE); 59 callback.Run(DBUS_METHOD_CALL_FAILURE);
87 return; 60 return;
88 } 61 }
89 callback.Run(DBUS_METHOD_CALL_SUCCESS); 62 callback.Run(DBUS_METHOD_CALL_SUCCESS);
90 } 63 }
91 64
92 // Handles responses for methods with ObjectPath results. 65 // Handles responses for methods with ObjectPath results.
93 void OnObjectPathMethod( 66 void OnObjectPathMethod(
94 ShillClientHelper::RefHolder* ref_holder,
95 const ObjectPathDBusMethodCallback& callback, 67 const ObjectPathDBusMethodCallback& callback,
96 dbus::Response* response) { 68 dbus::Response* response) {
97 if (!response) { 69 if (!response) {
98 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); 70 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath());
99 return; 71 return;
100 } 72 }
101 dbus::MessageReader reader(response); 73 dbus::MessageReader reader(response);
102 dbus::ObjectPath result; 74 dbus::ObjectPath result;
103 if (!reader.PopObjectPath(&result)) { 75 if (!reader.PopObjectPath(&result)) {
104 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); 76 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath());
105 return; 77 return;
106 } 78 }
107 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); 79 callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
108 } 80 }
109 81
110 // Handles responses for methods with ObjectPath results and no status. 82 // Handles responses for methods with ObjectPath results and no status.
111 void OnObjectPathMethodWithoutStatus( 83 void OnObjectPathMethodWithoutStatus(
112 ShillClientHelper::RefHolder* ref_holder,
113 const ObjectPathCallback& callback, 84 const ObjectPathCallback& callback,
114 const ShillClientHelper::ErrorCallback& error_callback, 85 const ShillClientHelper::ErrorCallback& error_callback,
115 dbus::Response* response) { 86 dbus::Response* response) {
116 if (!response) { 87 if (!response) {
117 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); 88 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
118 return; 89 return;
119 } 90 }
120 dbus::MessageReader reader(response); 91 dbus::MessageReader reader(response);
121 dbus::ObjectPath result; 92 dbus::ObjectPath result;
122 if (!reader.PopObjectPath(&result)) { 93 if (!reader.PopObjectPath(&result)) {
123 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); 94 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
124 return; 95 return;
125 } 96 }
126 callback.Run(result); 97 callback.Run(result);
127 } 98 }
128 99
129 // Handles responses for methods with DictionaryValue results. 100 // Handles responses for methods with DictionaryValue results.
130 void OnDictionaryValueMethod( 101 void OnDictionaryValueMethod(
131 ShillClientHelper::RefHolder* ref_holder,
132 const ShillClientHelper::DictionaryValueCallback& callback, 102 const ShillClientHelper::DictionaryValueCallback& callback,
133 dbus::Response* response) { 103 dbus::Response* response) {
134 if (!response) { 104 if (!response) {
135 base::DictionaryValue result; 105 base::DictionaryValue result;
136 callback.Run(DBUS_METHOD_CALL_FAILURE, result); 106 callback.Run(DBUS_METHOD_CALL_FAILURE, result);
137 return; 107 return;
138 } 108 }
139 dbus::MessageReader reader(response); 109 dbus::MessageReader reader(response);
140 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); 110 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
141 base::DictionaryValue* result = NULL; 111 base::DictionaryValue* result = NULL;
142 if (!value.get() || !value->GetAsDictionary(&result)) { 112 if (!value.get() || !value->GetAsDictionary(&result)) {
143 base::DictionaryValue result; 113 base::DictionaryValue result;
144 callback.Run(DBUS_METHOD_CALL_FAILURE, result); 114 callback.Run(DBUS_METHOD_CALL_FAILURE, result);
145 return; 115 return;
146 } 116 }
147 callback.Run(DBUS_METHOD_CALL_SUCCESS, *result); 117 callback.Run(DBUS_METHOD_CALL_SUCCESS, *result);
148 } 118 }
149 119
150 // Handles responses for methods without results. 120 // Handles responses for methods without results.
151 void OnVoidMethodWithErrorCallback( 121 void OnVoidMethodWithErrorCallback(
152 ShillClientHelper::RefHolder* ref_holder,
153 const base::Closure& callback, 122 const base::Closure& callback,
154 dbus::Response* response) { 123 dbus::Response* response) {
155 callback.Run(); 124 callback.Run();
156 } 125 }
157 126
158 // Handles responses for methods with DictionaryValue results. 127 // Handles responses for methods with DictionaryValue results.
159 // Used by CallDictionaryValueMethodWithErrorCallback(). 128 // Used by CallDictionaryValueMethodWithErrorCallback().
160 void OnDictionaryValueMethodWithErrorCallback( 129 void OnDictionaryValueMethodWithErrorCallback(
161 ShillClientHelper::RefHolder* ref_holder,
162 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback, 130 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback,
163 const ShillClientHelper::ErrorCallback& error_callback, 131 const ShillClientHelper::ErrorCallback& error_callback,
164 dbus::Response* response) { 132 dbus::Response* response) {
165 dbus::MessageReader reader(response); 133 dbus::MessageReader reader(response);
166 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); 134 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
167 base::DictionaryValue* result = NULL; 135 base::DictionaryValue* result = NULL;
168 if (!value.get() || !value->GetAsDictionary(&result)) { 136 if (!value.get() || !value->GetAsDictionary(&result)) {
169 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); 137 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
170 return; 138 return;
171 } 139 }
172 callback.Run(*result); 140 callback.Run(*result);
173 } 141 }
174 142
175 // Handles responses for methods with ListValue results. 143 // Handles responses for methods with ListValue results.
176 void OnListValueMethodWithErrorCallback( 144 void OnListValueMethodWithErrorCallback(
177 ShillClientHelper::RefHolder* ref_holder,
178 const ShillClientHelper::ListValueCallback& callback, 145 const ShillClientHelper::ListValueCallback& callback,
179 const ShillClientHelper::ErrorCallback& error_callback, 146 const ShillClientHelper::ErrorCallback& error_callback,
180 dbus::Response* response) { 147 dbus::Response* response) {
181 dbus::MessageReader reader(response); 148 dbus::MessageReader reader(response);
182 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); 149 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
183 base::ListValue* result = NULL; 150 base::ListValue* result = NULL;
184 if (!value.get() || !value->GetAsList(&result)) { 151 if (!value.get() || !value->GetAsList(&result)) {
185 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); 152 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
186 return; 153 return;
187 } 154 }
188 callback.Run(*result); 155 callback.Run(*result);
189 } 156 }
190 157
191 // Handles running appropriate error callbacks. 158 // Handles running appropriate error callbacks.
192 void OnError(const ShillClientHelper::ErrorCallback& error_callback, 159 void OnError(const ShillClientHelper::ErrorCallback& error_callback,
193 dbus::ErrorResponse* response) { 160 dbus::ErrorResponse* response) {
194 std::string error_name; 161 std::string error_name;
195 std::string error_message; 162 std::string error_message;
196 if (response) { 163 if (response) {
197 // Error message may contain the error message as string. 164 // Error message may contain the error message as string.
198 dbus::MessageReader reader(response); 165 dbus::MessageReader reader(response);
199 error_name = response->GetErrorName(); 166 error_name = response->GetErrorName();
200 reader.PopString(&error_message); 167 reader.PopString(&error_message);
201 } 168 }
202 error_callback.Run(error_name, error_message); 169 error_callback.Run(error_name, error_message);
203 } 170 }
204 171
205 } // namespace 172 } // namespace
206 173
207 ShillClientHelper::ShillClientHelper(dbus::ObjectProxy* proxy) 174 ShillClientHelper::ShillClientHelper(dbus::Bus* bus,
175 dbus::ObjectProxy* proxy)
208 : proxy_(proxy), 176 : proxy_(proxy),
209 active_refs_(0),
210 weak_ptr_factory_(this) { 177 weak_ptr_factory_(this) {
211 } 178 }
212 179
213 ShillClientHelper::~ShillClientHelper() { 180 ShillClientHelper::~ShillClientHelper() {
214 LOG_IF(ERROR, observer_list_.might_have_observers()) 181 LOG_IF(ERROR, observer_list_.might_have_observers())
215 << "ShillClientHelper destroyed with active observers"; 182 << "ShillClientHelper destroyed with active observers";
216 } 183 }
217 184
218 void ShillClientHelper::SetReleasedCallback(ReleasedCallback callback) {
219 CHECK(released_callback_.is_null());
220 released_callback_ = callback;
221 }
222
223 void ShillClientHelper::AddPropertyChangedObserver( 185 void ShillClientHelper::AddPropertyChangedObserver(
224 ShillPropertyChangedObserver* observer) { 186 ShillPropertyChangedObserver* observer) {
225 if (observer_list_.HasObserver(observer))
226 return;
227 AddRef();
228 // Excecute all the pending MonitorPropertyChanged calls. 187 // Excecute all the pending MonitorPropertyChanged calls.
229 for (size_t i = 0; i < interfaces_to_be_monitored_.size(); ++i) { 188 for (size_t i = 0; i < interfaces_to_be_monitored_.size(); ++i) {
230 MonitorPropertyChangedInternal(interfaces_to_be_monitored_[i]); 189 MonitorPropertyChangedInternal(interfaces_to_be_monitored_[i]);
231 } 190 }
232 interfaces_to_be_monitored_.clear(); 191 interfaces_to_be_monitored_.clear();
233 192
234 observer_list_.AddObserver(observer); 193 observer_list_.AddObserver(observer);
235 } 194 }
236 195
237 void ShillClientHelper::RemovePropertyChangedObserver( 196 void ShillClientHelper::RemovePropertyChangedObserver(
238 ShillPropertyChangedObserver* observer) { 197 ShillPropertyChangedObserver* observer) {
239 if (!observer_list_.HasObserver(observer))
240 return;
241 observer_list_.RemoveObserver(observer); 198 observer_list_.RemoveObserver(observer);
242 Release();
243 } 199 }
244 200
245 void ShillClientHelper::MonitorPropertyChanged( 201 void ShillClientHelper::MonitorPropertyChanged(
246 const std::string& interface_name) { 202 const std::string& interface_name) {
247 if (observer_list_.might_have_observers()) { 203 if (observer_list_.might_have_observers()) {
248 // Effectively monitor the PropertyChanged now. 204 // Effectively monitor the PropertyChanged now.
249 MonitorPropertyChangedInternal(interface_name); 205 MonitorPropertyChangedInternal(interface_name);
250 } else { 206 } else {
251 // Delay the ConnectToSignal until an observer is added. 207 // Delay the ConnectToSignal until an observer is added.
252 interfaces_to_be_monitored_.push_back(interface_name); 208 interfaces_to_be_monitored_.push_back(interface_name);
253 } 209 }
254 } 210 }
255 211
256 void ShillClientHelper::MonitorPropertyChangedInternal( 212 void ShillClientHelper::MonitorPropertyChangedInternal(
257 const std::string& interface_name) { 213 const std::string& interface_name) {
258 // We are not using dbus::PropertySet to monitor PropertyChanged signal 214 // We are not using dbus::PropertySet to monitor PropertyChanged signal
259 // because the interface is not "org.freedesktop.DBus.Properties". 215 // because the interface is not "org.freedesktop.DBus.Properties".
260 proxy_->ConnectToSignal(interface_name, 216 proxy_->ConnectToSignal(interface_name,
261 flimflam::kMonitorPropertyChanged, 217 flimflam::kMonitorPropertyChanged,
262 base::Bind(&ShillClientHelper::OnPropertyChanged, 218 base::Bind(&ShillClientHelper::OnPropertyChanged,
263 weak_ptr_factory_.GetWeakPtr()), 219 weak_ptr_factory_.GetWeakPtr()),
264 base::Bind(&ShillClientHelper::OnSignalConnected, 220 base::Bind(&ShillClientHelper::OnSignalConnected,
265 weak_ptr_factory_.GetWeakPtr())); 221 weak_ptr_factory_.GetWeakPtr()));
266 } 222 }
267 223
268 void ShillClientHelper::CallVoidMethod( 224 void ShillClientHelper::CallVoidMethod(
269 dbus::MethodCall* method_call, 225 dbus::MethodCall* method_call,
270 const VoidDBusMethodCallback& callback) { 226 const VoidDBusMethodCallback& callback) {
271 DCHECK(!callback.is_null()); 227 DCHECK(!callback.is_null());
272 proxy_->CallMethod( 228 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
273 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 229 base::Bind(&OnVoidMethod,
274 base::Bind(&OnVoidMethod, 230 callback));
275 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())),
276 callback));
277 } 231 }
278 232
279 void ShillClientHelper::CallObjectPathMethod( 233 void ShillClientHelper::CallObjectPathMethod(
280 dbus::MethodCall* method_call, 234 dbus::MethodCall* method_call,
281 const ObjectPathDBusMethodCallback& callback) { 235 const ObjectPathDBusMethodCallback& callback) {
282 DCHECK(!callback.is_null()); 236 DCHECK(!callback.is_null());
283 proxy_->CallMethod( 237 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
284 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 238 base::Bind(&OnObjectPathMethod,
285 base::Bind(&OnObjectPathMethod, 239 callback));
286 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())),
287 callback));
288 } 240 }
289 241
290 void ShillClientHelper::CallObjectPathMethodWithErrorCallback( 242 void ShillClientHelper::CallObjectPathMethodWithErrorCallback(
291 dbus::MethodCall* method_call, 243 dbus::MethodCall* method_call,
292 const ObjectPathCallback& callback, 244 const ObjectPathCallback& callback,
293 const ErrorCallback& error_callback) { 245 const ErrorCallback& error_callback) {
294 DCHECK(!callback.is_null()); 246 DCHECK(!callback.is_null());
295 DCHECK(!error_callback.is_null()); 247 DCHECK(!error_callback.is_null());
296 proxy_->CallMethodWithErrorCallback( 248 proxy_->CallMethodWithErrorCallback(
297 method_call, 249 method_call,
298 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 250 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
299 base::Bind(&OnObjectPathMethodWithoutStatus, 251 base::Bind(&OnObjectPathMethodWithoutStatus,
300 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())),
301 callback, 252 callback,
302 error_callback), 253 error_callback),
303 base::Bind(&OnError, 254 base::Bind(&OnError,
304 error_callback)); 255 error_callback));
305 } 256 }
306 257
307 void ShillClientHelper::CallDictionaryValueMethod( 258 void ShillClientHelper::CallDictionaryValueMethod(
308 dbus::MethodCall* method_call, 259 dbus::MethodCall* method_call,
309 const DictionaryValueCallback& callback) { 260 const DictionaryValueCallback& callback) {
310 DCHECK(!callback.is_null()); 261 DCHECK(!callback.is_null());
311 proxy_->CallMethod( 262 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
312 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 263 base::Bind(&OnDictionaryValueMethod,
313 base::Bind(&OnDictionaryValueMethod, 264 callback));
314 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())),
315 callback));
316 } 265 }
317 266
318 void ShillClientHelper::CallVoidMethodWithErrorCallback( 267 void ShillClientHelper::CallVoidMethodWithErrorCallback(
319 dbus::MethodCall* method_call, 268 dbus::MethodCall* method_call,
320 const base::Closure& callback, 269 const base::Closure& callback,
321 const ErrorCallback& error_callback) { 270 const ErrorCallback& error_callback) {
322 DCHECK(!callback.is_null()); 271 DCHECK(!callback.is_null());
323 DCHECK(!error_callback.is_null()); 272 DCHECK(!error_callback.is_null());
324 proxy_->CallMethodWithErrorCallback( 273 proxy_->CallMethodWithErrorCallback(
325 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 274 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
326 base::Bind(&OnVoidMethodWithErrorCallback, 275 base::Bind(&OnVoidMethodWithErrorCallback,
327 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())),
328 callback), 276 callback),
329 base::Bind(&OnError, 277 base::Bind(&OnError,
330 error_callback)); 278 error_callback));
331 } 279 }
332 280
333 void ShillClientHelper::CallBooleanMethodWithErrorCallback( 281 void ShillClientHelper::CallBooleanMethodWithErrorCallback(
334 dbus::MethodCall* method_call, 282 dbus::MethodCall* method_call,
335 const BooleanCallback& callback, 283 const BooleanCallback& callback,
336 const ErrorCallback& error_callback) { 284 const ErrorCallback& error_callback) {
337 DCHECK(!callback.is_null()); 285 DCHECK(!callback.is_null());
338 DCHECK(!error_callback.is_null()); 286 DCHECK(!error_callback.is_null());
339 proxy_->CallMethodWithErrorCallback( 287 proxy_->CallMethodWithErrorCallback(
340 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 288 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
341 base::Bind(&OnBooleanMethodWithErrorCallback, 289 base::Bind(&OnBooleanMethodWithErrorCallback,
342 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())),
343 callback, 290 callback,
344 error_callback), 291 error_callback),
345 base::Bind(&OnError, 292 base::Bind(&OnError,
346 error_callback)); 293 error_callback));
347 } 294 }
348 295
349 void ShillClientHelper::CallStringMethodWithErrorCallback( 296 void ShillClientHelper::CallStringMethodWithErrorCallback(
350 dbus::MethodCall* method_call, 297 dbus::MethodCall* method_call,
351 const StringCallback& callback, 298 const StringCallback& callback,
352 const ErrorCallback& error_callback) { 299 const ErrorCallback& error_callback) {
353 DCHECK(!callback.is_null()); 300 DCHECK(!callback.is_null());
354 DCHECK(!error_callback.is_null()); 301 DCHECK(!error_callback.is_null());
355 proxy_->CallMethodWithErrorCallback( 302 proxy_->CallMethodWithErrorCallback(
356 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 303 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
357 base::Bind(&OnStringMethodWithErrorCallback, 304 base::Bind(&OnStringMethodWithErrorCallback,
358 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())),
359 callback, 305 callback,
360 error_callback), 306 error_callback),
361 base::Bind(&OnError, 307 base::Bind(&OnError,
362 error_callback)); 308 error_callback));
363 } 309 }
364 310
365 void ShillClientHelper::CallDictionaryValueMethodWithErrorCallback( 311 void ShillClientHelper::CallDictionaryValueMethodWithErrorCallback(
366 dbus::MethodCall* method_call, 312 dbus::MethodCall* method_call,
367 const DictionaryValueCallbackWithoutStatus& callback, 313 const DictionaryValueCallbackWithoutStatus& callback,
368 const ErrorCallback& error_callback) { 314 const ErrorCallback& error_callback) {
369 DCHECK(!callback.is_null()); 315 DCHECK(!callback.is_null());
370 DCHECK(!error_callback.is_null()); 316 DCHECK(!error_callback.is_null());
371 proxy_->CallMethodWithErrorCallback( 317 proxy_->CallMethodWithErrorCallback(
372 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 318 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
373 base::Bind(&OnDictionaryValueMethodWithErrorCallback, 319 base::Bind(
374 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())), 320 &OnDictionaryValueMethodWithErrorCallback,
375 callback, 321 callback,
376 error_callback), 322 error_callback),
377 base::Bind(&OnError, 323 base::Bind(&OnError,
378 error_callback)); 324 error_callback));
379 } 325 }
380 326
381 void ShillClientHelper::CallListValueMethodWithErrorCallback( 327 void ShillClientHelper::CallListValueMethodWithErrorCallback(
382 dbus::MethodCall* method_call, 328 dbus::MethodCall* method_call,
383 const ListValueCallback& callback, 329 const ListValueCallback& callback,
384 const ErrorCallback& error_callback) { 330 const ErrorCallback& error_callback) {
385 DCHECK(!callback.is_null()); 331 DCHECK(!callback.is_null());
386 DCHECK(!error_callback.is_null()); 332 DCHECK(!error_callback.is_null());
387 proxy_->CallMethodWithErrorCallback( 333 proxy_->CallMethodWithErrorCallback(
388 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 334 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
389 base::Bind(&OnListValueMethodWithErrorCallback, 335 base::Bind(
390 base::Owned(new RefHolder(weak_ptr_factory_.GetWeakPtr())), 336 &OnListValueMethodWithErrorCallback,
391 callback, 337 callback,
392 error_callback), 338 error_callback),
393 base::Bind(&OnError, 339 base::Bind(&OnError,
394 error_callback)); 340 error_callback));
395 } 341 }
396 342
397 // static 343 // static
398 void ShillClientHelper::AppendValueDataAsVariant(dbus::MessageWriter* writer, 344 void ShillClientHelper::AppendValueDataAsVariant(dbus::MessageWriter* writer,
399 const base::Value& value) { 345 const base::Value& value) {
400 // Support basic types and string-to-string dictionary. 346 // Support basic types and string-to-string dictionary.
401 switch (value.GetType()) { 347 switch (value.GetType()) {
402 case base::Value::TYPE_DICTIONARY: { 348 case base::Value::TYPE_DICTIONARY: {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 it.Advance()) { 413 it.Advance()) {
468 dbus::MessageWriter entry_writer(NULL); 414 dbus::MessageWriter entry_writer(NULL);
469 array_writer.OpenDictEntry(&entry_writer); 415 array_writer.OpenDictEntry(&entry_writer);
470 entry_writer.AppendString(it.key()); 416 entry_writer.AppendString(it.key());
471 ShillClientHelper::AppendValueDataAsVariant(&entry_writer, it.value()); 417 ShillClientHelper::AppendValueDataAsVariant(&entry_writer, it.value());
472 array_writer.CloseContainer(&entry_writer); 418 array_writer.CloseContainer(&entry_writer);
473 } 419 }
474 writer->CloseContainer(&array_writer); 420 writer->CloseContainer(&array_writer);
475 } 421 }
476 422
477 void ShillClientHelper::AddRef() {
478 ++active_refs_;
479 }
480
481 void ShillClientHelper::Release() {
482 --active_refs_;
483 if (active_refs_ == 0 && !released_callback_.is_null())
484 base::ResetAndReturn(&released_callback_).Run(this); // May delete this
485 }
486
487 void ShillClientHelper::OnSignalConnected(const std::string& interface, 423 void ShillClientHelper::OnSignalConnected(const std::string& interface,
488 const std::string& signal, 424 const std::string& signal,
489 bool success) { 425 bool success) {
490 LOG_IF(ERROR, !success) << "Connect to " << interface << " " << signal 426 LOG_IF(ERROR, !success) << "Connect to " << interface << " " << signal
491 << " failed."; 427 << " failed.";
492 } 428 }
493 429
494 void ShillClientHelper::OnPropertyChanged(dbus::Signal* signal) { 430 void ShillClientHelper::OnPropertyChanged(dbus::Signal* signal) {
495 if (!observer_list_.might_have_observers()) 431 if (!observer_list_.might_have_observers())
496 return; 432 return;
497 433
498 dbus::MessageReader reader(signal); 434 dbus::MessageReader reader(signal);
499 std::string name; 435 std::string name;
500 if (!reader.PopString(&name)) 436 if (!reader.PopString(&name))
501 return; 437 return;
502 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); 438 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
503 if (!value.get()) 439 if (!value.get())
504 return; 440 return;
505 441
506 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, observer_list_, 442 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, observer_list_,
507 OnPropertyChanged(name, *value)); 443 OnPropertyChanged(name, *value));
508 } 444 }
509 445
446
510 } // namespace chromeos 447 } // namespace chromeos
OLDNEW
« no previous file with comments | « trunk/src/chromeos/dbus/shill_client_helper.h ('k') | trunk/src/chromeos/dbus/shill_device_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698