Chromium Code Reviews| Index: chrome/browser/chromeos/login/signin/oauth2_login_manager.cc |
| diff --git a/chrome/browser/chromeos/login/signin/oauth2_login_manager.cc b/chrome/browser/chromeos/login/signin/oauth2_login_manager.cc |
| index 61023ea0f62914fb8272be54232c9572b66f259e..f9809b298dff779469c3cf5faaa5a9e82c470396 100644 |
| --- a/chrome/browser/chromeos/login/signin/oauth2_login_manager.cc |
| +++ b/chrome/browser/chromeos/login/signin/oauth2_login_manager.cc |
| @@ -74,25 +74,29 @@ void OAuth2LoginManager::RestoreSession( |
| net::URLRequestContextGetter* auth_request_context, |
| SessionRestoreStrategy restore_strategy, |
| const std::string& oauth2_refresh_token, |
| - const std::string& auth_code) { |
| + const std::string& oauth2_access_token) { |
| DCHECK(user_profile_); |
| auth_request_context_ = auth_request_context; |
| restore_strategy_ = restore_strategy; |
| refresh_token_ = oauth2_refresh_token; |
| - oauthlogin_access_token_ = std::string(); |
| - auth_code_ = auth_code; |
| + oauthlogin_access_token_ = oauth2_access_token; |
| session_restore_start_ = base::Time::Now(); |
| SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_PREPARING); |
| ContinueSessionRestore(); |
| } |
| void OAuth2LoginManager::ContinueSessionRestore() { |
| - if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR || |
| - restore_strategy_ == RESTORE_FROM_AUTH_CODE) { |
| + if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { |
| FetchOAuth2Tokens(); |
| return; |
| } |
| + if (restore_strategy_ == RESTORE_FROM_PASSED_OAUTH2_ACCESS_TOKEN) { |
| + GetTokenHandle(); |
| + StoreOAuth2Token(); |
| + return; |
| + } |
| + |
| // Save passed OAuth2 refresh token. |
| if (restore_strategy_ == RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN) { |
| DCHECK(!refresh_token_.empty()); |
| @@ -241,26 +245,15 @@ void OAuth2LoginManager::FetchOAuth2Tokens() { |
| DCHECK(auth_request_context_.get()); |
| // If we have authenticated cookie jar, get OAuth1 token first, then fetch |
| // SID/LSID cookies through OAuthLogin call. |
|
xiyuan
2015/04/20 22:02:42
nit: DCHECK_EQ(RESTORE_FROM_COOKIE_JAR, restore_st
achuithb
2015/04/21 07:10:21
Done.
|
| - if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { |
| - SigninClient* signin_client = |
| - ChromeSigninClientFactory::GetForProfile(user_profile_); |
| - std::string signin_scoped_device_id = |
| - signin_client->GetSigninScopedDeviceId(); |
| - |
| - oauth2_token_fetcher_.reset( |
| - new OAuth2TokenFetcher(this, auth_request_context_.get())); |
| - oauth2_token_fetcher_->StartExchangeFromCookies(std::string(), |
| - signin_scoped_device_id); |
| - } else if (restore_strategy_ == RESTORE_FROM_AUTH_CODE) { |
| - DCHECK(!auth_code_.empty()); |
| - oauth2_token_fetcher_.reset( |
| - new OAuth2TokenFetcher(this, |
| - g_browser_process->system_request_context())); |
| - oauth2_token_fetcher_->StartExchangeFromAuthCode(auth_code_); |
| - } else { |
| - NOTREACHED(); |
| - SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); |
| - } |
| + SigninClient* signin_client = |
| + ChromeSigninClientFactory::GetForProfile(user_profile_); |
| + std::string signin_scoped_device_id = |
| + signin_client->GetSigninScopedDeviceId(); |
| + |
| + oauth2_token_fetcher_.reset( |
| + new OAuth2TokenFetcher(this, auth_request_context_.get())); |
| + oauth2_token_fetcher_->StartExchangeFromCookies(std::string(), |
| + signin_scoped_device_id); |
| } |
| void OAuth2LoginManager::OnOAuth2TokensAvailable( |
| @@ -269,6 +262,10 @@ void OAuth2LoginManager::OnOAuth2TokensAvailable( |
| DCHECK(refresh_token_.empty()); |
| refresh_token_.assign(oauth2_tokens.refresh_token); |
| oauthlogin_access_token_ = oauth2_tokens.access_token; |
| + StoreOAuth2Token(); |
|
xiyuan
2015/04/20 22:02:41
GetTokenHandle() to keep existing behavior?
achuithb
2015/04/21 07:10:21
Done.
|
| +} |
| + |
| +void OAuth2LoginManager::GetTokenHandle() { |
| if (StartupUtils::IsWebviewSigninEnabled()) { |
| auto user = chromeos::ProfileHelper::Get()->GetUserByProfile(user_profile_); |
| DCHECK(user); |
| @@ -281,7 +278,6 @@ void OAuth2LoginManager::OnOAuth2TokensAvailable( |
| weak_factory_.GetWeakPtr())); |
| } |
| } |
| - StoreOAuth2Token(); |
| } |
| void OAuth2LoginManager::OnOAuth2TokensFetchFailed() { |