Index: remoting/host/setup/oauth_client.cc |
diff --git a/remoting/host/setup/oauth_client.cc b/remoting/host/setup/oauth_client.cc |
index 684ab2c2d84e4cdc99b3424bdf5a62a7d0a5196d..fae80219c8ae7de4315aee57da3594e0ca89dda2 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 { |
@@ -23,13 +24,16 @@ OAuthClient::~OAuthClient() { |
void OAuthClient::GetCredentialsFromAuthCode( |
const gaia::OAuthClientInfo& oauth_client_info, |
const std::string& auth_code, |
+ bool need_user_email, |
CompletionCallback on_done) { |
if (!on_done_.is_null()) { |
- pending_requests_.push(Request(oauth_client_info, auth_code, on_done)); |
+ pending_requests_.push( |
+ Request(oauth_client_info, auth_code, need_user_email, on_done)); |
return; |
} |
+ need_user_email_ = need_user_email; |
on_done_ = on_done; |
// Map the authorization code to refresh and access tokens. |
gaia_oauth_client_.GetTokensFromAuthCode(oauth_client_info, auth_code, |
@@ -41,8 +45,12 @@ void OAuthClient::OnGetTokensResponse( |
const std::string& access_token, |
int expires_in_seconds) { |
refresh_token_ = refresh_token; |
- // Get the email corresponding to the access token. |
- gaia_oauth_client_.GetUserEmail(access_token, kMaxGaiaRetries, this); |
+ if (need_user_email_) { |
+ // Get the email corresponding to the access token. |
+ gaia_oauth_client_.GetUserEmail(access_token, kMaxGaiaRetries, this); |
+ } else { |
+ SendResponse("", refresh_token_); |
+ } |
} |
void OAuthClient::OnRefreshTokenResponse( |
@@ -54,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()) { |
@@ -64,7 +70,10 @@ void OAuthClient::SendResponse(const std::string& user_email, |
pending_requests_.pop(); |
// GetCredentialsFromAuthCode is asynchronous, so it's safe to call it here. |
GetCredentialsFromAuthCode( |
- request.oauth_client_info, request.auth_code, request.on_done); |
+ request.oauth_client_info, |
+ request.auth_code, |
+ request.need_user_email, |
+ request.on_done); |
} |
} |
@@ -83,9 +92,11 @@ void OAuthClient::OnNetworkError(int response_code) { |
OAuthClient::Request::Request( |
const gaia::OAuthClientInfo& oauth_client_info, |
const std::string& auth_code, |
+ bool need_user_email, |
CompletionCallback on_done) { |
this->oauth_client_info = oauth_client_info; |
this->auth_code = auth_code; |
+ this->need_user_email = need_user_email; |
this->on_done = on_done; |
} |