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

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

Issue 10949030: This converts the Shill clients to allow propagation of shill errors (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: review changes Created 8 years, 2 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"
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 {
17
18 const char kInvalidResponseErrorName[] = ""; // No error name.
19 const char kInvalidResponseErrorMessage[] = "Invalid response.";
20
21 } // namespace
22
16 ShillClientHelper::ShillClientHelper(dbus::Bus* bus, 23 ShillClientHelper::ShillClientHelper(dbus::Bus* bus,
17 dbus::ObjectProxy* proxy) 24 dbus::ObjectProxy* proxy)
18 : blocking_method_caller_(bus, proxy), 25 : blocking_method_caller_(bus, proxy),
19 proxy_(proxy), 26 proxy_(proxy),
20 weak_ptr_factory_(this) { 27 weak_ptr_factory_(this) {
21 } 28 }
22 29
23 ShillClientHelper::~ShillClientHelper() { 30 ShillClientHelper::~ShillClientHelper() {
24 } 31 }
25 32
(...skipping 29 matching lines...) Expand all
55 62
56 void ShillClientHelper::CallObjectPathMethod( 63 void ShillClientHelper::CallObjectPathMethod(
57 dbus::MethodCall* method_call, 64 dbus::MethodCall* method_call,
58 const ObjectPathDBusMethodCallback& callback) { 65 const ObjectPathDBusMethodCallback& callback) {
59 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 66 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
60 base::Bind(&ShillClientHelper::OnObjectPathMethod, 67 base::Bind(&ShillClientHelper::OnObjectPathMethod,
61 weak_ptr_factory_.GetWeakPtr(), 68 weak_ptr_factory_.GetWeakPtr(),
62 callback)); 69 callback));
63 } 70 }
64 71
72 void ShillClientHelper::CallObjectPathMethodWithErrorCallback(
73 dbus::MethodCall* method_call,
74 const ObjectPathCallback& callback,
75 const ErrorCallback& error_callback) {
76 proxy_->CallMethodWithErrorCallback(
77 method_call,
78 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
79 base::Bind(&ShillClientHelper::OnObjectPathMethodWithoutStatus,
80 weak_ptr_factory_.GetWeakPtr(),
81 callback,
82 error_callback),
83 base::Bind(&ShillClientHelper::OnError,
84 weak_ptr_factory_.GetWeakPtr(),
85 error_callback));
86 }
87
65 void ShillClientHelper::CallDictionaryValueMethod( 88 void ShillClientHelper::CallDictionaryValueMethod(
66 dbus::MethodCall* method_call, 89 dbus::MethodCall* method_call,
67 const DictionaryValueCallback& callback) { 90 const DictionaryValueCallback& callback) {
68 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 91 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
69 base::Bind(&ShillClientHelper::OnDictionaryValueMethod, 92 base::Bind(&ShillClientHelper::OnDictionaryValueMethod,
70 weak_ptr_factory_.GetWeakPtr(), 93 weak_ptr_factory_.GetWeakPtr(),
71 callback)); 94 callback));
72 } 95 }
73 96
74 void ShillClientHelper::CallVoidMethodWithErrorCallback( 97 void ShillClientHelper::CallVoidMethodWithErrorCallback(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 246 }
224 dbus::MessageReader reader(response); 247 dbus::MessageReader reader(response);
225 dbus::ObjectPath result; 248 dbus::ObjectPath result;
226 if (!reader.PopObjectPath(&result)) { 249 if (!reader.PopObjectPath(&result)) {
227 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath()); 250 callback.Run(DBUS_METHOD_CALL_FAILURE, dbus::ObjectPath());
228 return; 251 return;
229 } 252 }
230 callback.Run(DBUS_METHOD_CALL_SUCCESS, result); 253 callback.Run(DBUS_METHOD_CALL_SUCCESS, result);
231 } 254 }
232 255
256 void ShillClientHelper::OnObjectPathMethodWithoutStatus(
257 const ObjectPathCallback& callback,
258 const ErrorCallback& error_callback,
259 dbus::Response* response) {
260 if (!response) {
261 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
262 return;
263 }
264 dbus::MessageReader reader(response);
265 dbus::ObjectPath result;
266 if (!reader.PopObjectPath(&result)) {
267 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
268 return;
269 }
270 callback.Run(result);
271 }
272
233 void ShillClientHelper::OnDictionaryValueMethod( 273 void ShillClientHelper::OnDictionaryValueMethod(
234 const DictionaryValueCallback& callback, 274 const DictionaryValueCallback& callback,
235 dbus::Response* response) { 275 dbus::Response* response) {
236 if (!response) { 276 if (!response) {
237 base::DictionaryValue result; 277 base::DictionaryValue result;
238 callback.Run(DBUS_METHOD_CALL_FAILURE, result); 278 callback.Run(DBUS_METHOD_CALL_FAILURE, result);
239 return; 279 return;
240 } 280 }
241 dbus::MessageReader reader(response); 281 dbus::MessageReader reader(response);
242 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); 282 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
(...skipping 13 matching lines...) Expand all
256 } 296 }
257 297
258 void ShillClientHelper::OnDictionaryValueMethodWithErrorCallback( 298 void ShillClientHelper::OnDictionaryValueMethodWithErrorCallback(
259 const DictionaryValueCallbackWithoutStatus& callback, 299 const DictionaryValueCallbackWithoutStatus& callback,
260 const ErrorCallback& error_callback, 300 const ErrorCallback& error_callback,
261 dbus::Response* response) { 301 dbus::Response* response) {
262 dbus::MessageReader reader(response); 302 dbus::MessageReader reader(response);
263 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); 303 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
264 base::DictionaryValue* result = NULL; 304 base::DictionaryValue* result = NULL;
265 if (!value.get() || !value->GetAsDictionary(&result)) { 305 if (!value.get() || !value->GetAsDictionary(&result)) {
266 const std::string error_name; // No error name. 306 error_callback.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
267 const std::string error_message = "Invalid response.";
268 error_callback.Run(error_name, error_message);
269 return; 307 return;
270 } 308 }
271 callback.Run(*result); 309 callback.Run(*result);
272 } 310 }
273 311
274 void ShillClientHelper::OnError(const ErrorCallback& error_callback, 312 void ShillClientHelper::OnError(const ErrorCallback& error_callback,
275 dbus::ErrorResponse* response) { 313 dbus::ErrorResponse* response) {
276 std::string error_name; 314 std::string error_name;
277 std::string error_message; 315 std::string error_message;
278 if (response) { 316 if (response) {
279 // Error message may contain the error message as string. 317 // Error message may contain the error message as string.
280 dbus::MessageReader reader(response); 318 dbus::MessageReader reader(response);
281 error_name = response->GetErrorName(); 319 error_name = response->GetErrorName();
282 reader.PopString(&error_message); 320 reader.PopString(&error_message);
283 } 321 }
284 error_callback.Run(error_name, error_message); 322 error_callback.Run(error_name, error_message);
285 } 323 }
286 324
287 } // namespace chromeos 325 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698