OLD | NEW |
---|---|
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" |
11 #include "dbus/values_util.h" | 11 #include "dbus/values_util.h" |
12 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
13 | 13 |
14 namespace chromeos { | 14 namespace chromeos { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 const char kInvalidResponseErrorName[] = ""; // No error name. | 18 const char kInvalidResponseErrorName[] = ""; // No error name. |
19 const char kInvalidResponseErrorMessage[] = "Invalid response."; | 19 const char kInvalidResponseErrorMessage[] = "Invalid response."; |
20 | 20 |
21 class HelperRelease { | |
hashimoto
2013/09/17 03:28:53
nit: "Helper" here sounds ambiguous, does it mean
stevenjb
2013/09/17 21:03:17
-> ShillClientHelperAutoRelease
| |
22 public: | |
23 HelperRelease(base::WeakPtr<ShillClientHelper> helper) | |
24 : helper_(helper) { | |
25 } | |
26 ~HelperRelease() { | |
27 if (helper_) | |
28 helper_->Release(); | |
29 } | |
30 private: | |
31 base::WeakPtr<ShillClientHelper> helper_; | |
32 }; | |
33 | |
21 void OnBooleanMethodWithErrorCallback( | 34 void OnBooleanMethodWithErrorCallback( |
35 base::WeakPtr<ShillClientHelper> helper, | |
22 const ShillClientHelper::BooleanCallback& callback, | 36 const ShillClientHelper::BooleanCallback& callback, |
23 const ShillClientHelper::ErrorCallback& error_callback, | 37 const ShillClientHelper::ErrorCallback& error_callback, |
24 dbus::Response* response) { | 38 dbus::Response* response) { |
39 HelperRelease release(helper); | |
hashimoto
2013/09/17 03:28:53
I'm a bit worried about manually adding HelperRele
stevenjb
2013/09/17 21:03:17
I initially considered that approach but decided a
| |
25 if (!response) { | 40 if (!response) { |
26 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); | 41 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); |
27 return; | 42 return; |
28 } | 43 } |
29 dbus::MessageReader reader(response); | 44 dbus::MessageReader reader(response); |
30 bool result; | 45 bool result; |
31 if (!reader.PopBool(&result)) { | 46 if (!reader.PopBool(&result)) { |
32 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); | 47 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); |
33 return; | 48 return; |
34 } | 49 } |
35 callback.Run(result); | |
36 } | 50 } |
37 | 51 |
38 void OnStringMethodWithErrorCallback( | 52 void OnStringMethodWithErrorCallback( |
53 base::WeakPtr<ShillClientHelper> helper, | |
39 const ShillClientHelper::StringCallback& callback, | 54 const ShillClientHelper::StringCallback& callback, |
40 const ShillClientHelper::ErrorCallback& error_callback, | 55 const ShillClientHelper::ErrorCallback& error_callback, |
41 dbus::Response* response) { | 56 dbus::Response* response) { |
57 HelperRelease release(helper); | |
42 if (!response) { | 58 if (!response) { |
43 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); | 59 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); |
44 return; | 60 return; |
45 } | 61 } |
46 dbus::MessageReader reader(response); | 62 dbus::MessageReader reader(response); |
47 std::string result; | 63 std::string result; |
48 if (!reader.PopString(&result)) { | 64 if (!reader.PopString(&result)) { |
49 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); | 65 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); |
50 return; | 66 return; |
51 } | 67 } |
52 callback.Run(result); | 68 callback.Run(result); |
53 } | 69 } |
54 | 70 |
55 // Handles responses for methods without results. | 71 // Handles responses for methods without results. |
56 void OnVoidMethod(const VoidDBusMethodCallback& callback, | 72 void OnVoidMethod(base::WeakPtr<ShillClientHelper> helper, |
73 const VoidDBusMethodCallback& callback, | |
57 dbus::Response* response) { | 74 dbus::Response* response) { |
75 HelperRelease release(helper); | |
58 if (!response) { | 76 if (!response) { |
59 callback.Run(DBUS_METHOD_CALL_FAILURE); | 77 callback.Run(DBUS_METHOD_CALL_FAILURE); |
60 return; | 78 return; |
61 } | 79 } |
62 callback.Run(DBUS_METHOD_CALL_SUCCESS); | 80 callback.Run(DBUS_METHOD_CALL_SUCCESS); |
63 } | 81 } |
64 | 82 |
65 // Handles responses for methods with ObjectPath results. | 83 // Handles responses for methods with ObjectPath results. |
66 void OnObjectPathMethod( | 84 void OnObjectPathMethod( |
85 base::WeakPtr<ShillClientHelper> helper, | |
67 const ObjectPathDBusMethodCallback& callback, | 86 const ObjectPathDBusMethodCallback& callback, |
68 dbus::Response* response) { | 87 dbus::Response* response) { |
88 HelperRelease release(helper); | |
69 if (!response) { | 89 if (!response) { |
70 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); | 90 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); |
71 return; | 91 return; |
72 } | 92 } |
73 dbus::MessageReader reader(response); | 93 dbus::MessageReader reader(response); |
74 dbus::ObjectPath result; | 94 dbus::ObjectPath result; |
75 if (!reader.PopObjectPath(&result)) { | 95 if (!reader.PopObjectPath(&result)) { |
76 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); | 96 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); |
77 return; | 97 return; |
78 } | 98 } |
79 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); | 99 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); |
80 } | 100 } |
81 | 101 |
82 // Handles responses for methods with ObjectPath results and no status. | 102 // Handles responses for methods with ObjectPath results and no status. |
83 void OnObjectPathMethodWithoutStatus( | 103 void OnObjectPathMethodWithoutStatus( |
104 base::WeakPtr<ShillClientHelper> helper, | |
84 const ObjectPathCallback& callback, | 105 const ObjectPathCallback& callback, |
85 const ShillClientHelper::ErrorCallback& error_callback, | 106 const ShillClientHelper::ErrorCallback& error_callback, |
86 dbus::Response* response) { | 107 dbus::Response* response) { |
108 HelperRelease release(helper); | |
87 if (!response) { | 109 if (!response) { |
88 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); | 110 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); |
89 return; | 111 return; |
90 } | 112 } |
91 dbus::MessageReader reader(response); | 113 dbus::MessageReader reader(response); |
92 dbus::ObjectPath result; | 114 dbus::ObjectPath result; |
93 if (!reader.PopObjectPath(&result)) { | 115 if (!reader.PopObjectPath(&result)) { |
94 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); | 116 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); |
95 return; | 117 return; |
96 } | 118 } |
97 callback.Run(result); | 119 callback.Run(result); |
98 } | 120 } |
99 | 121 |
100 // Handles responses for methods with DictionaryValue results. | 122 // Handles responses for methods with DictionaryValue results. |
101 void OnDictionaryValueMethod( | 123 void OnDictionaryValueMethod( |
124 base::WeakPtr<ShillClientHelper> helper, | |
102 const ShillClientHelper::DictionaryValueCallback& callback, | 125 const ShillClientHelper::DictionaryValueCallback& callback, |
103 dbus::Response* response) { | 126 dbus::Response* response) { |
127 HelperRelease release(helper); | |
104 if (!response) { | 128 if (!response) { |
105 base::DictionaryValue result; | 129 base::DictionaryValue result; |
106 callback.Run(DBUS_METHOD_CALL_FAILURE, result); | 130 callback.Run(DBUS_METHOD_CALL_FAILURE, result); |
107 return; | 131 return; |
108 } | 132 } |
109 dbus::MessageReader reader(response); | 133 dbus::MessageReader reader(response); |
110 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); | 134 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); |
111 base::DictionaryValue* result = NULL; | 135 base::DictionaryValue* result = NULL; |
112 if (!value.get() || !value->GetAsDictionary(&result)) { | 136 if (!value.get() || !value->GetAsDictionary(&result)) { |
113 base::DictionaryValue result; | 137 base::DictionaryValue result; |
114 callback.Run(DBUS_METHOD_CALL_FAILURE, result); | 138 callback.Run(DBUS_METHOD_CALL_FAILURE, result); |
115 return; | 139 return; |
116 } | 140 } |
117 callback.Run(DBUS_METHOD_CALL_SUCCESS, *result); | 141 callback.Run(DBUS_METHOD_CALL_SUCCESS, *result); |
118 } | 142 } |
119 | 143 |
120 // Handles responses for methods without results. | 144 // Handles responses for methods without results. |
121 void OnVoidMethodWithErrorCallback( | 145 void OnVoidMethodWithErrorCallback( |
146 base::WeakPtr<ShillClientHelper> helper, | |
122 const base::Closure& callback, | 147 const base::Closure& callback, |
123 dbus::Response* response) { | 148 dbus::Response* response) { |
149 HelperRelease release(helper); | |
124 callback.Run(); | 150 callback.Run(); |
125 } | 151 } |
126 | 152 |
127 // Handles responses for methods with DictionaryValue results. | 153 // Handles responses for methods with DictionaryValue results. |
128 // Used by CallDictionaryValueMethodWithErrorCallback(). | 154 // Used by CallDictionaryValueMethodWithErrorCallback(). |
129 void OnDictionaryValueMethodWithErrorCallback( | 155 void OnDictionaryValueMethodWithErrorCallback( |
156 base::WeakPtr<ShillClientHelper> helper, | |
130 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback, | 157 const ShillClientHelper::DictionaryValueCallbackWithoutStatus& callback, |
131 const ShillClientHelper::ErrorCallback& error_callback, | 158 const ShillClientHelper::ErrorCallback& error_callback, |
132 dbus::Response* response) { | 159 dbus::Response* response) { |
160 HelperRelease release(helper); | |
133 dbus::MessageReader reader(response); | 161 dbus::MessageReader reader(response); |
134 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); | 162 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); |
135 base::DictionaryValue* result = NULL; | 163 base::DictionaryValue* result = NULL; |
136 if (!value.get() || !value->GetAsDictionary(&result)) { | 164 if (!value.get() || !value->GetAsDictionary(&result)) { |
137 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); | 165 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); |
138 return; | 166 return; |
139 } | 167 } |
140 callback.Run(*result); | 168 callback.Run(*result); |
141 } | 169 } |
142 | 170 |
143 // Handles responses for methods with ListValue results. | 171 // Handles responses for methods with ListValue results. |
144 void OnListValueMethodWithErrorCallback( | 172 void OnListValueMethodWithErrorCallback( |
173 base::WeakPtr<ShillClientHelper> helper, | |
145 const ShillClientHelper::ListValueCallback& callback, | 174 const ShillClientHelper::ListValueCallback& callback, |
146 const ShillClientHelper::ErrorCallback& error_callback, | 175 const ShillClientHelper::ErrorCallback& error_callback, |
147 dbus::Response* response) { | 176 dbus::Response* response) { |
177 HelperRelease release(helper); | |
148 dbus::MessageReader reader(response); | 178 dbus::MessageReader reader(response); |
149 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); | 179 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); |
150 base::ListValue* result = NULL; | 180 base::ListValue* result = NULL; |
151 if (!value.get() || !value->GetAsList(&result)) { | 181 if (!value.get() || !value->GetAsList(&result)) { |
152 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); | 182 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage); |
153 return; | 183 return; |
154 } | 184 } |
155 callback.Run(*result); | 185 callback.Run(*result); |
156 } | 186 } |
157 | 187 |
158 // Handles running appropriate error callbacks. | 188 // Handles running appropriate error callbacks. |
159 void OnError(const ShillClientHelper::ErrorCallback& error_callback, | 189 void OnError(base::WeakPtr<ShillClientHelper> helper, |
190 const ShillClientHelper::ErrorCallback& error_callback, | |
160 dbus::ErrorResponse* response) { | 191 dbus::ErrorResponse* response) { |
192 HelperRelease release(helper); | |
161 std::string error_name; | 193 std::string error_name; |
162 std::string error_message; | 194 std::string error_message; |
163 if (response) { | 195 if (response) { |
164 // Error message may contain the error message as string. | 196 // Error message may contain the error message as string. |
165 dbus::MessageReader reader(response); | 197 dbus::MessageReader reader(response); |
166 error_name = response->GetErrorName(); | 198 error_name = response->GetErrorName(); |
167 reader.PopString(&error_message); | 199 reader.PopString(&error_message); |
168 } | 200 } |
169 error_callback.Run(error_name, error_message); | 201 error_callback.Run(error_name, error_message); |
170 } | 202 } |
171 | 203 |
172 } // namespace | 204 } // namespace |
173 | 205 |
174 ShillClientHelper::ShillClientHelper(dbus::Bus* bus, | 206 ShillClientHelper::ShillClientHelper(dbus::ObjectProxy* proxy) |
175 dbus::ObjectProxy* proxy) | |
176 : proxy_(proxy), | 207 : proxy_(proxy), |
208 owner_(NULL), | |
209 active_refs_(0), | |
177 weak_ptr_factory_(this) { | 210 weak_ptr_factory_(this) { |
178 } | 211 } |
179 | 212 |
180 ShillClientHelper::~ShillClientHelper() { | 213 ShillClientHelper::~ShillClientHelper() { |
181 LOG_IF(ERROR, observer_list_.might_have_observers()) | 214 LOG_IF(ERROR, observer_list_.might_have_observers()) |
182 << "ShillClientHelper destroyed with active observers"; | 215 << "ShillClientHelper destroyed with active observers"; |
183 } | 216 } |
184 | 217 |
218 void ShillClientHelper::SetOwner(Owner* owner) { | |
219 CHECK(!owner_); | |
220 owner_ = owner; | |
221 } | |
222 | |
223 void ShillClientHelper::AddRef() { | |
224 ++active_refs_; | |
225 } | |
226 | |
227 void ShillClientHelper::Release() { | |
228 --active_refs_; | |
229 if (active_refs_ == 0 && owner_) | |
230 owner_->NotifyReleased(this); // May delete this | |
231 } | |
232 | |
185 void ShillClientHelper::AddPropertyChangedObserver( | 233 void ShillClientHelper::AddPropertyChangedObserver( |
186 ShillPropertyChangedObserver* observer) { | 234 ShillPropertyChangedObserver* observer) { |
235 AddRef(); | |
187 // Excecute all the pending MonitorPropertyChanged calls. | 236 // Excecute all the pending MonitorPropertyChanged calls. |
188 for (size_t i = 0; i < interfaces_to_be_monitored_.size(); ++i) { | 237 for (size_t i = 0; i < interfaces_to_be_monitored_.size(); ++i) { |
189 MonitorPropertyChangedInternal(interfaces_to_be_monitored_[i]); | 238 MonitorPropertyChangedInternal(interfaces_to_be_monitored_[i]); |
190 } | 239 } |
191 interfaces_to_be_monitored_.clear(); | 240 interfaces_to_be_monitored_.clear(); |
192 | 241 |
193 observer_list_.AddObserver(observer); | 242 observer_list_.AddObserver(observer); |
194 } | 243 } |
195 | 244 |
196 void ShillClientHelper::RemovePropertyChangedObserver( | 245 void ShillClientHelper::RemovePropertyChangedObserver( |
197 ShillPropertyChangedObserver* observer) { | 246 ShillPropertyChangedObserver* observer) { |
198 observer_list_.RemoveObserver(observer); | 247 observer_list_.RemoveObserver(observer); |
248 Release(); | |
199 } | 249 } |
200 | 250 |
201 void ShillClientHelper::MonitorPropertyChanged( | 251 void ShillClientHelper::MonitorPropertyChanged( |
202 const std::string& interface_name) { | 252 const std::string& interface_name) { |
203 if (observer_list_.might_have_observers()) { | 253 if (observer_list_.might_have_observers()) { |
204 // Effectively monitor the PropertyChanged now. | 254 // Effectively monitor the PropertyChanged now. |
205 MonitorPropertyChangedInternal(interface_name); | 255 MonitorPropertyChangedInternal(interface_name); |
206 } else { | 256 } else { |
207 // Delay the ConnectToSignal until an observer is added. | 257 // Delay the ConnectToSignal until an observer is added. |
208 interfaces_to_be_monitored_.push_back(interface_name); | 258 interfaces_to_be_monitored_.push_back(interface_name); |
209 } | 259 } |
210 } | 260 } |
211 | 261 |
212 void ShillClientHelper::MonitorPropertyChangedInternal( | 262 void ShillClientHelper::MonitorPropertyChangedInternal( |
213 const std::string& interface_name) { | 263 const std::string& interface_name) { |
214 // We are not using dbus::PropertySet to monitor PropertyChanged signal | 264 // We are not using dbus::PropertySet to monitor PropertyChanged signal |
215 // because the interface is not "org.freedesktop.DBus.Properties". | 265 // because the interface is not "org.freedesktop.DBus.Properties". |
216 proxy_->ConnectToSignal(interface_name, | 266 proxy_->ConnectToSignal(interface_name, |
217 flimflam::kMonitorPropertyChanged, | 267 flimflam::kMonitorPropertyChanged, |
218 base::Bind(&ShillClientHelper::OnPropertyChanged, | 268 base::Bind(&ShillClientHelper::OnPropertyChanged, |
219 weak_ptr_factory_.GetWeakPtr()), | 269 weak_ptr_factory_.GetWeakPtr()), |
220 base::Bind(&ShillClientHelper::OnSignalConnected, | 270 base::Bind(&ShillClientHelper::OnSignalConnected, |
221 weak_ptr_factory_.GetWeakPtr())); | 271 weak_ptr_factory_.GetWeakPtr())); |
222 } | 272 } |
223 | 273 |
224 void ShillClientHelper::CallVoidMethod( | 274 void ShillClientHelper::CallVoidMethod( |
225 dbus::MethodCall* method_call, | 275 dbus::MethodCall* method_call, |
226 const VoidDBusMethodCallback& callback) { | 276 const VoidDBusMethodCallback& callback) { |
227 DCHECK(!callback.is_null()); | 277 DCHECK(!callback.is_null()); |
278 AddRef(); | |
228 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 279 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
229 base::Bind(&OnVoidMethod, | 280 base::Bind(&OnVoidMethod, |
281 weak_ptr_factory_.GetWeakPtr(), | |
230 callback)); | 282 callback)); |
231 } | 283 } |
232 | 284 |
233 void ShillClientHelper::CallObjectPathMethod( | 285 void ShillClientHelper::CallObjectPathMethod( |
234 dbus::MethodCall* method_call, | 286 dbus::MethodCall* method_call, |
235 const ObjectPathDBusMethodCallback& callback) { | 287 const ObjectPathDBusMethodCallback& callback) { |
236 DCHECK(!callback.is_null()); | 288 DCHECK(!callback.is_null()); |
289 AddRef(); | |
237 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 290 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
238 base::Bind(&OnObjectPathMethod, | 291 base::Bind(&OnObjectPathMethod, |
292 weak_ptr_factory_.GetWeakPtr(), | |
239 callback)); | 293 callback)); |
240 } | 294 } |
241 | 295 |
242 void ShillClientHelper::CallObjectPathMethodWithErrorCallback( | 296 void ShillClientHelper::CallObjectPathMethodWithErrorCallback( |
243 dbus::MethodCall* method_call, | 297 dbus::MethodCall* method_call, |
244 const ObjectPathCallback& callback, | 298 const ObjectPathCallback& callback, |
245 const ErrorCallback& error_callback) { | 299 const ErrorCallback& error_callback) { |
246 DCHECK(!callback.is_null()); | 300 DCHECK(!callback.is_null()); |
247 DCHECK(!error_callback.is_null()); | 301 DCHECK(!error_callback.is_null()); |
302 AddRef(); | |
248 proxy_->CallMethodWithErrorCallback( | 303 proxy_->CallMethodWithErrorCallback( |
249 method_call, | 304 method_call, |
250 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 305 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
251 base::Bind(&OnObjectPathMethodWithoutStatus, | 306 base::Bind(&OnObjectPathMethodWithoutStatus, |
307 weak_ptr_factory_.GetWeakPtr(), | |
252 callback, | 308 callback, |
253 error_callback), | 309 error_callback), |
254 base::Bind(&OnError, | 310 base::Bind(&OnError, |
311 weak_ptr_factory_.GetWeakPtr(), | |
255 error_callback)); | 312 error_callback)); |
256 } | 313 } |
257 | 314 |
258 void ShillClientHelper::CallDictionaryValueMethod( | 315 void ShillClientHelper::CallDictionaryValueMethod( |
259 dbus::MethodCall* method_call, | 316 dbus::MethodCall* method_call, |
260 const DictionaryValueCallback& callback) { | 317 const DictionaryValueCallback& callback) { |
261 DCHECK(!callback.is_null()); | 318 DCHECK(!callback.is_null()); |
319 AddRef(); | |
262 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 320 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
263 base::Bind(&OnDictionaryValueMethod, | 321 base::Bind(&OnDictionaryValueMethod, |
322 weak_ptr_factory_.GetWeakPtr(), | |
264 callback)); | 323 callback)); |
265 } | 324 } |
266 | 325 |
267 void ShillClientHelper::CallVoidMethodWithErrorCallback( | 326 void ShillClientHelper::CallVoidMethodWithErrorCallback( |
268 dbus::MethodCall* method_call, | 327 dbus::MethodCall* method_call, |
269 const base::Closure& callback, | 328 const base::Closure& callback, |
270 const ErrorCallback& error_callback) { | 329 const ErrorCallback& error_callback) { |
271 DCHECK(!callback.is_null()); | 330 DCHECK(!callback.is_null()); |
272 DCHECK(!error_callback.is_null()); | 331 DCHECK(!error_callback.is_null()); |
332 AddRef(); | |
273 proxy_->CallMethodWithErrorCallback( | 333 proxy_->CallMethodWithErrorCallback( |
274 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 334 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
275 base::Bind(&OnVoidMethodWithErrorCallback, | 335 base::Bind(&OnVoidMethodWithErrorCallback, |
336 weak_ptr_factory_.GetWeakPtr(), | |
276 callback), | 337 callback), |
277 base::Bind(&OnError, | 338 base::Bind(&OnError, |
339 weak_ptr_factory_.GetWeakPtr(), | |
278 error_callback)); | 340 error_callback)); |
279 } | 341 } |
280 | 342 |
281 void ShillClientHelper::CallBooleanMethodWithErrorCallback( | 343 void ShillClientHelper::CallBooleanMethodWithErrorCallback( |
282 dbus::MethodCall* method_call, | 344 dbus::MethodCall* method_call, |
283 const BooleanCallback& callback, | 345 const BooleanCallback& callback, |
284 const ErrorCallback& error_callback) { | 346 const ErrorCallback& error_callback) { |
285 DCHECK(!callback.is_null()); | 347 DCHECK(!callback.is_null()); |
286 DCHECK(!error_callback.is_null()); | 348 DCHECK(!error_callback.is_null()); |
349 AddRef(); | |
287 proxy_->CallMethodWithErrorCallback( | 350 proxy_->CallMethodWithErrorCallback( |
288 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 351 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
289 base::Bind(&OnBooleanMethodWithErrorCallback, | 352 base::Bind(&OnBooleanMethodWithErrorCallback, |
353 weak_ptr_factory_.GetWeakPtr(), | |
290 callback, | 354 callback, |
291 error_callback), | 355 error_callback), |
292 base::Bind(&OnError, | 356 base::Bind(&OnError, |
357 weak_ptr_factory_.GetWeakPtr(), | |
293 error_callback)); | 358 error_callback)); |
294 } | 359 } |
295 | 360 |
296 void ShillClientHelper::CallStringMethodWithErrorCallback( | 361 void ShillClientHelper::CallStringMethodWithErrorCallback( |
297 dbus::MethodCall* method_call, | 362 dbus::MethodCall* method_call, |
298 const StringCallback& callback, | 363 const StringCallback& callback, |
299 const ErrorCallback& error_callback) { | 364 const ErrorCallback& error_callback) { |
300 DCHECK(!callback.is_null()); | 365 DCHECK(!callback.is_null()); |
301 DCHECK(!error_callback.is_null()); | 366 DCHECK(!error_callback.is_null()); |
367 AddRef(); | |
302 proxy_->CallMethodWithErrorCallback( | 368 proxy_->CallMethodWithErrorCallback( |
303 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 369 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
304 base::Bind(&OnStringMethodWithErrorCallback, | 370 base::Bind(&OnStringMethodWithErrorCallback, |
371 weak_ptr_factory_.GetWeakPtr(), | |
305 callback, | 372 callback, |
306 error_callback), | 373 error_callback), |
307 base::Bind(&OnError, | 374 base::Bind(&OnError, |
375 weak_ptr_factory_.GetWeakPtr(), | |
308 error_callback)); | 376 error_callback)); |
309 } | 377 } |
310 | 378 |
311 void ShillClientHelper::CallDictionaryValueMethodWithErrorCallback( | 379 void ShillClientHelper::CallDictionaryValueMethodWithErrorCallback( |
312 dbus::MethodCall* method_call, | 380 dbus::MethodCall* method_call, |
313 const DictionaryValueCallbackWithoutStatus& callback, | 381 const DictionaryValueCallbackWithoutStatus& callback, |
314 const ErrorCallback& error_callback) { | 382 const ErrorCallback& error_callback) { |
315 DCHECK(!callback.is_null()); | 383 DCHECK(!callback.is_null()); |
316 DCHECK(!error_callback.is_null()); | 384 DCHECK(!error_callback.is_null()); |
385 AddRef(); | |
317 proxy_->CallMethodWithErrorCallback( | 386 proxy_->CallMethodWithErrorCallback( |
318 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 387 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
319 base::Bind( | 388 base::Bind( |
320 &OnDictionaryValueMethodWithErrorCallback, | 389 &OnDictionaryValueMethodWithErrorCallback, |
390 weak_ptr_factory_.GetWeakPtr(), | |
321 callback, | 391 callback, |
322 error_callback), | 392 error_callback), |
323 base::Bind(&OnError, | 393 base::Bind(&OnError, |
394 weak_ptr_factory_.GetWeakPtr(), | |
324 error_callback)); | 395 error_callback)); |
325 } | 396 } |
326 | 397 |
327 void ShillClientHelper::CallListValueMethodWithErrorCallback( | 398 void ShillClientHelper::CallListValueMethodWithErrorCallback( |
328 dbus::MethodCall* method_call, | 399 dbus::MethodCall* method_call, |
329 const ListValueCallback& callback, | 400 const ListValueCallback& callback, |
330 const ErrorCallback& error_callback) { | 401 const ErrorCallback& error_callback) { |
331 DCHECK(!callback.is_null()); | 402 DCHECK(!callback.is_null()); |
332 DCHECK(!error_callback.is_null()); | 403 DCHECK(!error_callback.is_null()); |
404 AddRef(); | |
333 proxy_->CallMethodWithErrorCallback( | 405 proxy_->CallMethodWithErrorCallback( |
334 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 406 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
335 base::Bind( | 407 base::Bind( |
336 &OnListValueMethodWithErrorCallback, | 408 &OnListValueMethodWithErrorCallback, |
409 weak_ptr_factory_.GetWeakPtr(), | |
337 callback, | 410 callback, |
338 error_callback), | 411 error_callback), |
339 base::Bind(&OnError, | 412 base::Bind(&OnError, |
413 weak_ptr_factory_.GetWeakPtr(), | |
340 error_callback)); | 414 error_callback)); |
341 } | 415 } |
342 | 416 |
343 // static | 417 // static |
344 void ShillClientHelper::AppendValueDataAsVariant(dbus::MessageWriter* writer, | 418 void ShillClientHelper::AppendValueDataAsVariant(dbus::MessageWriter* writer, |
345 const base::Value& value) { | 419 const base::Value& value) { |
346 // Support basic types and string-to-string dictionary. | 420 // Support basic types and string-to-string dictionary. |
347 switch (value.GetType()) { | 421 switch (value.GetType()) { |
348 case base::Value::TYPE_DICTIONARY: { | 422 case base::Value::TYPE_DICTIONARY: { |
349 const base::DictionaryValue* dictionary = NULL; | 423 const base::DictionaryValue* dictionary = NULL; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); | 512 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); |
439 if (!value.get()) | 513 if (!value.get()) |
440 return; | 514 return; |
441 | 515 |
442 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, observer_list_, | 516 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, observer_list_, |
443 OnPropertyChanged(name, *value)); | 517 OnPropertyChanged(name, *value)); |
444 } | 518 } |
445 | 519 |
446 | 520 |
447 } // namespace chromeos | 521 } // namespace chromeos |
OLD | NEW |