diff options
author | sergeyu <sergeyu@chromium.org> | 2015-04-24 17:18:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-25 00:18:25 +0000 |
commit | d9bdcb6c95619e6cb3a4281156573c58f7626a26 (patch) | |
tree | 84cf1bd7964177589cc1f1e024655dbb0ef50042 /remoting/host/setup | |
parent | f79a51f871181b0da7653cfa17d351745bd12994 (diff) | |
download | chromium_src-d9bdcb6c95619e6cb3a4281156573c58f7626a26.zip chromium_src-d9bdcb6c95619e6cb3a4281156573c58f7626a26.tar.gz chromium_src-d9bdcb6c95619e6cb3a4281156573c58f7626a26.tar.bz2 |
Use base::ResetAndReturn() in remoting.
base::ResetAndReturn() makes code shorter and simpler. Also in several
places callbacks were Reset() after Run(), which is dangerous for
callback that are allowed to delete the caller. base::ResetAndReturn()
helps to avoid this issue.
Review URL: https://codereview.chromium.org/1064863004
Cr-Commit-Position: refs/heads/master@{#326940}
Diffstat (limited to 'remoting/host/setup')
-rw-r--r-- | remoting/host/setup/daemon_controller_delegate_mac.mm | 9 | ||||
-rw-r--r-- | remoting/host/setup/host_starter.cc | 25 | ||||
-rw-r--r-- | remoting/host/setup/oauth_client.cc | 5 |
3 files changed, 15 insertions, 24 deletions
diff --git a/remoting/host/setup/daemon_controller_delegate_mac.mm b/remoting/host/setup/daemon_controller_delegate_mac.mm index 2fd7daa..9821f86 100644 --- a/remoting/host/setup/daemon_controller_delegate_mac.mm +++ b/remoting/host/setup/daemon_controller_delegate_mac.mm @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "base/bind.h" +#include "base/callback_helpers.h" #include "base/compiler_specific.h" #include "base/files/file_path.h" #include "base/files/file_util.h" @@ -175,12 +176,10 @@ void DaemonControllerDelegateMac::PreferencePaneCallbackDelegate( return; } - DCHECK(!current_callback_.is_null()); - DaemonController::CompletionCallback done = current_callback_; - current_callback_.Reset(); - done.Run(result); - DeregisterForPreferencePaneNotifications(); + + DCHECK(!current_callback_.is_null()); + base::ResetAndReturn(¤t_callback_).Run(result); } // static diff --git a/remoting/host/setup/host_starter.cc b/remoting/host/setup/host_starter.cc index 127c4a9..5eda05c 100644 --- a/remoting/host/setup/host_starter.cc +++ b/remoting/host/setup/host_starter.cc @@ -5,6 +5,7 @@ #include "remoting/host/setup/host_starter.h" #include "base/bind.h" +#include "base/callback_helpers.h" #include "base/guid.h" #include "base/location.h" #include "base/thread_task_runner_handle.h" @@ -184,9 +185,7 @@ void HostStarter::OnHostStarted(DaemonController::AsyncResult result) { service_client_->UnregisterHost(host_id_, access_token_, this); return; } - CompletionCallback cb = on_done_; - on_done_.Reset(); - cb.Run(START_COMPLETE); + base::ResetAndReturn(&on_done_).Run(START_COMPLETE); } void HostStarter::OnOAuthError() { @@ -195,14 +194,12 @@ void HostStarter::OnOAuthError() { &HostStarter::OnOAuthError, weak_ptr_)); return; } - CompletionCallback cb = on_done_; - on_done_.Reset(); if (unregistering_host_) { LOG(ERROR) << "OAuth error occurred when unregistering host."; - cb.Run(START_ERROR); - } else { - cb.Run(OAUTH_ERROR); } + + base::ResetAndReturn(&on_done_) + .Run(unregistering_host_ ? START_ERROR : OAUTH_ERROR); } void HostStarter::OnNetworkError(int response_code) { @@ -211,14 +208,12 @@ void HostStarter::OnNetworkError(int response_code) { &HostStarter::OnNetworkError, weak_ptr_, response_code)); return; } - CompletionCallback cb = on_done_; - on_done_.Reset(); if (unregistering_host_) { LOG(ERROR) << "Network error occurred when unregistering host."; - cb.Run(START_ERROR); - } else { - cb.Run(NETWORK_ERROR); } + + base::ResetAndReturn(&on_done_) + .Run(unregistering_host_ ? START_ERROR : NETWORK_ERROR); } void HostStarter::OnHostUnregistered() { @@ -227,9 +222,7 @@ void HostStarter::OnHostUnregistered() { &HostStarter::OnHostUnregistered, weak_ptr_)); return; } - CompletionCallback cb = on_done_; - on_done_.Reset(); - cb.Run(START_ERROR); + base::ResetAndReturn(&on_done_).Run(START_ERROR); } } // namespace remoting diff --git a/remoting/host/setup/oauth_client.cc b/remoting/host/setup/oauth_client.cc index d96d360..fae8021 100644 --- a/remoting/host/setup/oauth_client.cc +++ b/remoting/host/setup/oauth_client.cc @@ -4,6 +4,7 @@ #include "remoting/host/setup/oauth_client.h" +#include "base/callback_helpers.h" #include "base/logging.h" namespace { @@ -61,9 +62,7 @@ void OAuthClient::OnRefreshTokenResponse( void OAuthClient::SendResponse(const std::string& user_email, const std::string& refresh_token) { - CompletionCallback on_done = on_done_; - on_done_.Reset(); - on_done.Run(user_email, refresh_token); + base::ResetAndReturn(&on_done_).Run(user_email, refresh_token); // Process the next request in the queue. if (pending_requests_.size()) { |