Remove weave::Cloud::GetDeviceInfo and OnCloudRequestErrorCallback BUG:24267885 Change-Id: Ic13d0ca757c8ec9c9bde332e430288f1e45e28ba Reviewed-on: https://weave-review.googlesource.com/1217 Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/libweave/include/weave/cloud.h b/libweave/include/weave/cloud.h index d3c9500..0ef4c14 100644 --- a/libweave/include/weave/cloud.h +++ b/libweave/include/weave/cloud.h
@@ -26,21 +26,11 @@ public: using OnRegistrationChangedCallback = base::Callback<void(RegistrationStatus satus)>; - using OnCloudRequestCallback = - base::Callback<void(const base::DictionaryValue& response)>; - using OnCloudRequestErrorCallback = base::Callback<void(const Error* error)>; // Sets callback which is called when registration state is changed. virtual void AddOnRegistrationChangedCallback( const OnRegistrationChangedCallback& callback) = 0; - // Gets the full device description JSON object asynchronously. - // Passes the device info as the first argument to |callback|, or nullptr if - // the device is not registered or in case of communication failure. - virtual void GetDeviceInfo( - const OnCloudRequestCallback& success_callback, - const OnCloudRequestErrorCallback& error_callback) = 0; - // Registers the device. // Returns a device ID on success. virtual std::string RegisterDevice(const std::string& ticket_id,
diff --git a/libweave/src/device_registration_info.cc b/libweave/src/device_registration_info.cc index a011826..1e5566a 100644 --- a/libweave/src/device_registration_info.cc +++ b/libweave/src/device_registration_info.cc
@@ -337,7 +337,7 @@ void DeviceRegistrationInfo::RefreshAccessToken( const base::Closure& success_callback, - const CloudRequestErrorCallback& error_callback) { + const ErrorCallback& error_callback) { LOG(INFO) << "Refreshing access token."; ErrorPtr error; @@ -363,8 +363,7 @@ // one of the copies will be bad. auto shared_success_callback = std::make_shared<base::Closure>(success_callback); - auto shared_error_callback = - std::make_shared<CloudRequestErrorCallback>(error_callback); + auto shared_error_callback = std::make_shared<ErrorCallback>(error_callback); RequestSender sender{http::kPost, GetOAuthURL("token"), http_client_}; sender.SetFormData({ @@ -386,7 +385,7 @@ void DeviceRegistrationInfo::OnRefreshAccessTokenSuccess( const std::shared_ptr<base::Closure>& success_callback, - const std::shared_ptr<CloudRequestErrorCallback>& error_callback, + const std::shared_ptr<ErrorCallback>& error_callback, int id, const HttpClient::Response& response) { VLOG(1) << "Refresh access token request with ID " << id << " completed"; @@ -424,7 +423,7 @@ void DeviceRegistrationInfo::OnRefreshAccessTokenError( const std::shared_ptr<base::Closure>& success_callback, - const std::shared_ptr<CloudRequestErrorCallback>& error_callback, + const std::shared_ptr<ErrorCallback>& error_callback, int id, const Error* error) { VLOG(1) << "Refresh access token request with ID " << id << " failed"; @@ -516,7 +515,7 @@ void DeviceRegistrationInfo::GetDeviceInfo( const CloudRequestCallback& success_callback, - const CloudRequestErrorCallback& error_callback) { + const ErrorCallback& error_callback) { ErrorPtr error; if (!VerifyRegistrationCredentials(&error)) { if (!error_callback.is_null()) @@ -632,7 +631,7 @@ const std::string& url, const base::DictionaryValue* body, const CloudRequestCallback& success_callback, - const CloudRequestErrorCallback& error_callback) { + const ErrorCallback& error_callback) { // We make CloudRequestData shared here because we want to make sure // there is only one instance of success_callback and error_calback since // those may have move-only types and making a copy of the callback with @@ -881,7 +880,7 @@ void DeviceRegistrationInfo::UpdateDeviceResource( const base::Closure& on_success, - const CloudRequestErrorCallback& on_failure) { + const ErrorCallback& on_failure) { queued_resource_update_callbacks_.emplace_back(on_success, on_failure); if (!in_progress_resource_update_callbacks_.empty()) { VLOG(1) << "Another request is already pending."; @@ -1001,9 +1000,8 @@ callback.Run(commands ? *commands : empty); } -void DeviceRegistrationInfo::OnFetchCommandsError( - const CloudRequestErrorCallback& callback, - const Error* error) { +void DeviceRegistrationInfo::OnFetchCommandsError(const ErrorCallback& callback, + const Error* error) { OnFetchCommandsReturned(); callback.Run(error); } @@ -1017,7 +1015,7 @@ void DeviceRegistrationInfo::FetchCommands( const base::Callback<void(const base::ListValue&)>& on_success, - const CloudRequestErrorCallback& on_failure) { + const ErrorCallback& on_failure) { fetch_commands_request_sent_ = true; fetch_commands_request_queued_ = false; DoCloudRequest(
diff --git a/libweave/src/device_registration_info.h b/libweave/src/device_registration_info.h index 752a4e2..ac8e7a7 100644 --- a/libweave/src/device_registration_info.h +++ b/libweave/src/device_registration_info.h
@@ -53,7 +53,6 @@ public: using CloudRequestCallback = base::Callback<void(const base::DictionaryValue& response)>; - using CloudRequestErrorCallback = base::Callback<void(const Error* error)>; DeviceRegistrationInfo(const std::shared_ptr<CommandManager>& command_manager, const std::shared_ptr<StateManager>& state_manager, @@ -67,9 +66,6 @@ // Cloud overrides. void AddOnRegistrationChangedCallback( const OnRegistrationChangedCallback& callback) override; - void GetDeviceInfo( - const OnCloudRequestCallback& success_callback, - const OnCloudRequestErrorCallback& error_callback) override; std::string RegisterDevice(const std::string& ticket_id, ErrorPtr* error) override; void UpdateDeviceInfo(const std::string& name, @@ -85,6 +81,9 @@ const std::string& service_url, ErrorPtr* error) override; + void GetDeviceInfo(const CloudRequestCallback& success_callback, + const ErrorCallback& error_callback); + // Returns the GCD service request URL. If |subpath| is specified, it is // appended to the base URL which is normally // https://www.googleapis.com/clouddevices/v1/". @@ -148,17 +147,17 @@ // Forcibly refreshes the access token. void RefreshAccessToken(const base::Closure& success_callback, - const CloudRequestErrorCallback& error_callback); + const ErrorCallback& error_callback); // Callbacks for RefreshAccessToken(). void OnRefreshAccessTokenSuccess( const std::shared_ptr<base::Closure>& success_callback, - const std::shared_ptr<CloudRequestErrorCallback>& error_callback, + const std::shared_ptr<ErrorCallback>& error_callback, int id, const provider::HttpClient::Response& response); void OnRefreshAccessTokenError( const std::shared_ptr<base::Closure>& success_callback, - const std::shared_ptr<CloudRequestErrorCallback>& error_callback, + const std::shared_ptr<ErrorCallback>& error_callback, int id, const Error* error); @@ -181,7 +180,7 @@ const std::string& url, const base::DictionaryValue* body, const CloudRequestCallback& success_callback, - const CloudRequestErrorCallback& error_callback); + const ErrorCallback& error_callback); // Helper for DoCloudRequest(). struct CloudRequestData { @@ -189,7 +188,7 @@ std::string url; std::string body; CloudRequestCallback success_callback; - CloudRequestErrorCallback error_callback; + ErrorCallback error_callback; }; void SendCloudRequest(const std::shared_ptr<const CloudRequestData>& data); void OnCloudRequestSuccess( @@ -207,7 +206,7 @@ void CheckAccessTokenError(const Error* error); void UpdateDeviceResource(const base::Closure& on_success, - const CloudRequestErrorCallback& on_failure); + const ErrorCallback& on_failure); void StartQueuedUpdateDeviceResource(); // Success/failure callbacks for UpdateDeviceResource(). void OnUpdateDeviceResourceSuccess(const base::DictionaryValue& device_info); @@ -225,13 +224,12 @@ void FetchCommands( const base::Callback<void(const base::ListValue&)>& on_success, - const CloudRequestErrorCallback& on_failure); + const ErrorCallback& on_failure); // Success/failure callbacks for FetchCommands(). void OnFetchCommandsSuccess( const base::Callback<void(const base::ListValue&)>& callback, const base::DictionaryValue& json); - void OnFetchCommandsError(const CloudRequestErrorCallback& callback, - const Error* error); + void OnFetchCommandsError(const ErrorCallback& callback, const Error* error); // Called when FetchCommands completes (with either success or error). // This method reschedules any pending/queued fetch requests. void OnFetchCommandsReturned(); @@ -316,7 +314,7 @@ bool fetch_commands_request_queued_{false}; using ResourceUpdateCallbackList = - std::vector<std::pair<base::Closure, CloudRequestErrorCallback>>; + std::vector<std::pair<base::Closure, ErrorCallback>>; // Success/error callbacks for device resource update request currently in // flight to the cloud server. ResourceUpdateCallbackList in_progress_resource_update_callbacks_;
diff --git a/libweave/src/weave_unittest.cc b/libweave/src/weave_unittest.cc index bcd39e2..8250d8c 100644 --- a/libweave/src/weave_unittest.cc +++ b/libweave/src/weave_unittest.cc
@@ -241,13 +241,6 @@ cloud_ = device_->GetCloud(); ASSERT_TRUE(cloud_); - cloud_->GetDeviceInfo( - base::Bind( - [](const base::DictionaryValue& response) { ADD_FAILURE(); }), - base::Bind([](const Error* error) { - EXPECT_TRUE(error->HasError("gcd", "device_not_registered")); - })); - for (const auto& cb : http_server_changed_cb_) cb.Run(http_server_);