| 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/flimflam_client_helper.h" | 5 #include "chromeos/dbus/flimflam_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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 void FlimflamClientHelper::CallDictionaryValueMethod( | 64 void FlimflamClientHelper::CallDictionaryValueMethod( |
| 65 dbus::MethodCall* method_call, | 65 dbus::MethodCall* method_call, |
| 66 const DictionaryValueCallback& callback) { | 66 const DictionaryValueCallback& callback) { |
| 67 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 67 proxy_->CallMethod(method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 68 base::Bind(&FlimflamClientHelper::OnDictionaryValueMethod, | 68 base::Bind(&FlimflamClientHelper::OnDictionaryValueMethod, |
| 69 weak_ptr_factory_.GetWeakPtr(), | 69 weak_ptr_factory_.GetWeakPtr(), |
| 70 callback)); | 70 callback)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void FlimflamClientHelper::CallVoidMethodWithErrorCallback( |
| 74 dbus::MethodCall* method_call, |
| 75 const base::Closure& callback, |
| 76 const ErrorCallback& error_callback) { |
| 77 proxy_->CallMethodWithErrorCallback( |
| 78 method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 79 base::Bind(&FlimflamClientHelper::OnVoidMethodWithErrorCallback, |
| 80 weak_ptr_factory_.GetWeakPtr(), |
| 81 callback), |
| 82 base::Bind(&FlimflamClientHelper::OnError, |
| 83 weak_ptr_factory_.GetWeakPtr(), |
| 84 error_callback)); |
| 85 } |
| 86 |
| 73 bool FlimflamClientHelper::CallVoidMethodAndBlock( | 87 bool FlimflamClientHelper::CallVoidMethodAndBlock( |
| 74 dbus::MethodCall* method_call) { | 88 dbus::MethodCall* method_call) { |
| 75 scoped_ptr<dbus::Response> response( | 89 scoped_ptr<dbus::Response> response( |
| 76 blocking_method_caller_.CallMethodAndBlock(method_call)); | 90 blocking_method_caller_.CallMethodAndBlock(method_call)); |
| 77 if (!response.get()) | 91 if (!response.get()) |
| 78 return false; | 92 return false; |
| 79 return true; | 93 return true; |
| 80 } | 94 } |
| 81 | 95 |
| 82 dbus::ObjectPath FlimflamClientHelper::CallObjectPathMethodAndBlock( | 96 dbus::ObjectPath FlimflamClientHelper::CallObjectPathMethodAndBlock( |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); | 225 scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); |
| 212 base::DictionaryValue* result = NULL; | 226 base::DictionaryValue* result = NULL; |
| 213 if (!value.get() || !value->GetAsDictionary(&result)) { | 227 if (!value.get() || !value->GetAsDictionary(&result)) { |
| 214 base::DictionaryValue result; | 228 base::DictionaryValue result; |
| 215 callback.Run(DBUS_METHOD_CALL_FAILURE, result); | 229 callback.Run(DBUS_METHOD_CALL_FAILURE, result); |
| 216 return; | 230 return; |
| 217 } | 231 } |
| 218 callback.Run(DBUS_METHOD_CALL_SUCCESS, *result); | 232 callback.Run(DBUS_METHOD_CALL_SUCCESS, *result); |
| 219 } | 233 } |
| 220 | 234 |
| 235 void FlimflamClientHelper::OnVoidMethodWithErrorCallback( |
| 236 const base::Closure& callback, |
| 237 dbus::Response* response) { |
| 238 callback.Run(); |
| 239 } |
| 240 |
| 241 void FlimflamClientHelper::OnError(const ErrorCallback& error_callback, |
| 242 dbus::ErrorResponse* response) { |
| 243 std::string error_name; |
| 244 std::string error_message; |
| 245 if (response) { |
| 246 // Error message may contain the error message as string. |
| 247 dbus::MessageReader reader(response); |
| 248 error_name = response->GetErrorName(); |
| 249 reader.PopString(&error_message); |
| 250 } |
| 251 error_callback.Run(error_name, error_message); |
| 252 } |
| 253 |
| 221 } // namespace chromeos | 254 } // namespace chromeos |
| OLD | NEW |