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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 | 55 |
56 void ShillClientHelper::CallObjectPathMethod( | 56 void ShillClientHelper::CallObjectPathMethod( |
57 dbus::MethodCall* method_call, | 57 dbus::MethodCall* method_call, |
58 const ObjectPathDBusMethodCallback& callback) { | 58 const ObjectPathDBusMethodCallback& callback) { |
59 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 59 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
60 base::Bind(&ShillClientHelper::OnObjectPathMethod, | 60 base::Bind(&ShillClientHelper::OnObjectPathMethod, |
61 weak_ptr_factory_.GetWeakPtr(), | 61 weak_ptr_factory_.GetWeakPtr(), |
62 callback)); | 62 callback)); |
63 } | 63 } |
64 | 64 |
65 void ShillClientHelper::CallObjectPathMethodWithErrorCallback( | |
66 dbus::MethodCall* method_call, | |
67 const ObjectPathCallbackWithoutStatus& callback, | |
68 const ErrorCallback& error_callback) { | |
69 proxy_->CallMethodWithErrorCallback( | |
70 method_call, | |
71 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
72 base::Bind(&ShillClientHelper::OnObjectPathMethodWithoutStatus, | |
73 weak_ptr_factory_.GetWeakPtr(), | |
74 callback), | |
75 base::Bind(&ShillClientHelper::OnError, | |
76 weak_ptr_factory_.GetWeakPtr(), | |
77 error_callback)); | |
78 } | |
79 | |
65 void ShillClientHelper::CallDictionaryValueMethod( | 80 void ShillClientHelper::CallDictionaryValueMethod( |
66 dbus::MethodCall* method_call, | 81 dbus::MethodCall* method_call, |
67 const DictionaryValueCallback& callback) { | 82 const DictionaryValueCallback& callback) { |
68 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 83 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
69 base::Bind(&ShillClientHelper::OnDictionaryValueMethod, | 84 base::Bind(&ShillClientHelper::OnDictionaryValueMethod, |
70 weak_ptr_factory_.GetWeakPtr(), | 85 weak_ptr_factory_.GetWeakPtr(), |
71 callback)); | 86 callback)); |
72 } | 87 } |
73 | 88 |
74 void ShillClientHelper::CallVoidMethodWithErrorCallback( | 89 void ShillClientHelper::CallVoidMethodWithErrorCallback( |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 } | 238 } |
224 dbus::MessageReader reader(response); | 239 dbus::MessageReader reader(response); |
225 dbus::ObjectPath result; | 240 dbus::ObjectPath result; |
226 if (!reader.PopObjectPath(&result)) { | 241 if (!reader.PopObjectPath(&result)) { |
227 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); | 242 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); |
228 return; | 243 return; |
229 } | 244 } |
230 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); | 245 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); |
231 } | 246 } |
232 | 247 |
248 void ShillClientHelper::OnObjectPathMethodWithoutStatus( | |
249 const ObjectPathCallbackWithoutStatus& callback, | |
250 dbus::Response* response) { | |
251 if (!response) { | |
252 callback.Run(dbus::ObjectPath()); | |
hashimoto
2012/09/24 02:28:56
Please run ErrorCallback on error cases. (see OnDi
Greg Spencer (Chromium)
2012/09/24 21:50:54
Done.
| |
253 return; | |
254 } | |
255 dbus::MessageReader reader(response); | |
256 dbus::ObjectPath result; | |
257 if (!reader.PopObjectPath(&result)) { | |
258 callback.Run(dbus::ObjectPath()); | |
hashimoto
2012/09/24 02:28:56
ditto.
Greg Spencer (Chromium)
2012/09/24 21:50:54
Done.
| |
259 return; | |
260 } | |
261 callback.Run(result); | |
262 } | |
263 | |
233 void ShillClientHelper::OnDictionaryValueMethod( | 264 void ShillClientHelper::OnDictionaryValueMethod( |
234 const DictionaryValueCallback& callback, | 265 const DictionaryValueCallback& callback, |
235 dbus::Response* response) { | 266 dbus::Response* response) { |
236 if (!response) { | 267 if (!response) { |
237 base::DictionaryValue result; | 268 base::DictionaryValue result; |
238 callback.Run(DBUS_METHOD_CALL_FAILURE, result); | 269 callback.Run(DBUS_METHOD_CALL_FAILURE, result); |
239 return; | 270 return; |
240 } | 271 } |
241 dbus::MessageReader reader(response); | 272 dbus::MessageReader reader(response); |
242 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); | 273 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 if (response) { | 309 if (response) { |
279 // Error message may contain the error message as string. | 310 // Error message may contain the error message as string. |
280 dbus::MessageReader reader(response); | 311 dbus::MessageReader reader(response); |
281 error_name = response->GetErrorName(); | 312 error_name = response->GetErrorName(); |
282 reader.PopString(&error_message); | 313 reader.PopString(&error_message); |
283 } | 314 } |
284 error_callback.Run(error_name, error_message); | 315 error_callback.Run(error_name, error_message); |
285 } | 316 } |
286 | 317 |
287 } // namespace chromeos | 318 } // namespace chromeos |
OLD | NEW |