diff options
-rw-r--r-- | chromeos/dbus/flimflam_client_helper.cc | 32 | ||||
-rw-r--r-- | chromeos/dbus/flimflam_client_helper.h | 18 | ||||
-rw-r--r-- | chromeos/dbus/flimflam_service_client.cc | 26 |
3 files changed, 75 insertions, 1 deletions
diff --git a/chromeos/dbus/flimflam_client_helper.cc b/chromeos/dbus/flimflam_client_helper.cc index 89162cb..b54bb94 100644 --- a/chromeos/dbus/flimflam_client_helper.cc +++ b/chromeos/dbus/flimflam_client_helper.cc @@ -84,6 +84,22 @@ void FlimflamClientHelper::CallVoidMethodWithErrorCallback( error_callback)); } +void FlimflamClientHelper::CallDictionaryValueMethodWithErrorCallback( + dbus::MethodCall* method_call, + const DictionaryValueCallbackWithoutStatus& callback, + const ErrorCallback& error_callback) { + proxy_->CallMethodWithErrorCallback( + method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind( + &FlimflamClientHelper::OnDictionaryValueMethodWithErrorCallback, + weak_ptr_factory_.GetWeakPtr(), + callback, + error_callback), + base::Bind(&FlimflamClientHelper::OnError, + weak_ptr_factory_.GetWeakPtr(), + error_callback)); +} + bool FlimflamClientHelper::CallVoidMethodAndBlock( dbus::MethodCall* method_call) { scoped_ptr<dbus::Response> response( @@ -238,6 +254,22 @@ void FlimflamClientHelper::OnVoidMethodWithErrorCallback( callback.Run(); } +void FlimflamClientHelper::OnDictionaryValueMethodWithErrorCallback( + const DictionaryValueCallbackWithoutStatus& callback, + const ErrorCallback& error_callback, + dbus::Response* response) { + dbus::MessageReader reader(response); + scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + base::DictionaryValue* result = NULL; + if (!value.get() || !value->GetAsDictionary(&result)) { + const std::string error_name; // No error name. + const std::string error_message = "Invalid response."; + error_callback.Run(error_name, error_message); + return; + } + callback.Run(*result); +} + void FlimflamClientHelper::OnError(const ErrorCallback& error_callback, dbus::ErrorResponse* response) { std::string error_name; diff --git a/chromeos/dbus/flimflam_client_helper.h b/chromeos/dbus/flimflam_client_helper.h index 859d95e..671f3c2 100644 --- a/chromeos/dbus/flimflam_client_helper.h +++ b/chromeos/dbus/flimflam_client_helper.h @@ -55,6 +55,11 @@ class FlimflamClientHelper { DBusMethodCallStatus call_status, const base::DictionaryValue& result)> DictionaryValueCallback; + // A callback to handle responses for methods with DictionaryValue reuslts. + // This is used by CallDictionaryValueMethodWithErrorCallback. + typedef base::Callback<void(const base::DictionaryValue& result + )> DictionaryValueCallbackWithoutStatus; + // A callback to handle erros for method call. typedef base::Callback<void(const std::string& error_name, const std::string& error_message)> ErrorCallback; @@ -89,6 +94,12 @@ class FlimflamClientHelper { const base::Closure& callback, const ErrorCallback& error_callback); + // Calls a method with a dictionary value result with error callback. + void CallDictionaryValueMethodWithErrorCallback( + dbus::MethodCall* method_call, + const DictionaryValueCallbackWithoutStatus& callback, + const ErrorCallback& error_callback); + // DEPRECATED DO NOT USE: Calls a method without results. bool CallVoidMethodAndBlock(dbus::MethodCall* method_call); @@ -131,6 +142,13 @@ class FlimflamClientHelper { void OnVoidMethodWithErrorCallback(const base::Closure& callback, dbus::Response* response); + // Handles responses for methods with DictionaryValue results. + // Used by CallDictionaryValueMethodWithErrorCallback(). + void OnDictionaryValueMethodWithErrorCallback( + const DictionaryValueCallbackWithoutStatus& callback, + const ErrorCallback& error_callback, + dbus::Response* response); + // Handles errors for method calls. void OnError(const ErrorCallback& error_callback, dbus::ErrorResponse* response); diff --git a/chromeos/dbus/flimflam_service_client.cc b/chromeos/dbus/flimflam_service_client.cc index 64a1528..eafc381 100644 --- a/chromeos/dbus/flimflam_service_client.cc +++ b/chromeos/dbus/flimflam_service_client.cc @@ -18,6 +18,27 @@ namespace chromeos { namespace { +// Error callback for GetProperties. +void OnGetPropertiesError( + const dbus::ObjectPath& service_path, + const FlimflamServiceClient::DictionaryValueCallback& callback, + const std::string& error_name, + const std::string& error_message) { + const std::string log_string = + "Failed to call org.chromium.flimflam.Service.GetProperties for: " + + service_path.value() + ": " + error_name + ": " + error_message; + + // Suppress ERROR log if error name is + // "org.freedesktop.DBus.Error.UnknownMethod". crbug.com/130660 + if (error_name == DBUS_ERROR_UNKNOWN_METHOD) + VLOG(1) << log_string; + else + LOG(ERROR) << log_string; + + base::DictionaryValue empty_dictionary; + callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); +} + // The FlimflamServiceClient implementation. class FlimflamServiceClientImpl : public FlimflamServiceClient { public: @@ -44,7 +65,10 @@ class FlimflamServiceClientImpl : public FlimflamServiceClient { const DictionaryValueCallback& callback) OVERRIDE { dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, flimflam::kGetPropertiesFunction); - GetHelper(service_path)->CallDictionaryValueMethod(&method_call, callback); + GetHelper(service_path)->CallDictionaryValueMethodWithErrorCallback( + &method_call, + base::Bind(callback, DBUS_METHOD_CALL_SUCCESS), + base::Bind(&OnGetPropertiesError, service_path, callback)); } // FlimflamServiceClient override. |