Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" | 5 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 | 67 |
| 68 void OAuth2LoginManager::RemoveObserver( | 68 void OAuth2LoginManager::RemoveObserver( |
| 69 OAuth2LoginManager::Observer* observer) { | 69 OAuth2LoginManager::Observer* observer) { |
| 70 observer_list_.RemoveObserver(observer); | 70 observer_list_.RemoveObserver(observer); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void OAuth2LoginManager::RestoreSession( | 73 void OAuth2LoginManager::RestoreSession( |
| 74 net::URLRequestContextGetter* auth_request_context, | 74 net::URLRequestContextGetter* auth_request_context, |
| 75 SessionRestoreStrategy restore_strategy, | 75 SessionRestoreStrategy restore_strategy, |
| 76 const std::string& oauth2_refresh_token, | 76 const std::string& oauth2_refresh_token, |
| 77 const std::string& auth_code) { | 77 const std::string& oauth2_access_token) { |
| 78 DCHECK(user_profile_); | 78 DCHECK(user_profile_); |
| 79 auth_request_context_ = auth_request_context; | 79 auth_request_context_ = auth_request_context; |
| 80 restore_strategy_ = restore_strategy; | 80 restore_strategy_ = restore_strategy; |
| 81 refresh_token_ = oauth2_refresh_token; | 81 refresh_token_ = oauth2_refresh_token; |
| 82 oauthlogin_access_token_ = std::string(); | 82 oauthlogin_access_token_ = oauth2_access_token; |
| 83 auth_code_ = auth_code; | |
| 84 session_restore_start_ = base::Time::Now(); | 83 session_restore_start_ = base::Time::Now(); |
| 85 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_PREPARING); | 84 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_PREPARING); |
| 86 ContinueSessionRestore(); | 85 ContinueSessionRestore(); |
| 87 } | 86 } |
| 88 | 87 |
| 89 void OAuth2LoginManager::ContinueSessionRestore() { | 88 void OAuth2LoginManager::ContinueSessionRestore() { |
| 90 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR || | 89 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { |
| 91 restore_strategy_ == RESTORE_FROM_AUTH_CODE) { | |
| 92 FetchOAuth2Tokens(); | 90 FetchOAuth2Tokens(); |
| 93 return; | 91 return; |
| 94 } | 92 } |
| 95 | 93 |
| 94 if (restore_strategy_ == RESTORE_FROM_PASSED_OAUTH2_ACCESS_TOKEN) { | |
| 95 GetTokenHandle(); | |
| 96 StoreOAuth2Token(); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 96 // Save passed OAuth2 refresh token. | 100 // Save passed OAuth2 refresh token. |
| 97 if (restore_strategy_ == RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN) { | 101 if (restore_strategy_ == RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN) { |
| 98 DCHECK(!refresh_token_.empty()); | 102 DCHECK(!refresh_token_.empty()); |
| 99 restore_strategy_ = RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; | 103 restore_strategy_ = RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; |
| 100 StoreOAuth2Token(); | 104 StoreOAuth2Token(); |
| 101 return; | 105 return; |
| 102 } | 106 } |
| 103 | 107 |
| 104 DCHECK(restore_strategy_ == RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN); | 108 DCHECK(restore_strategy_ == RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN); |
| 105 RestoreSessionFromSavedTokens(); | 109 RestoreSessionFromSavedTokens(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 | 237 |
| 234 void OAuth2LoginManager::OnNetworkError(int response_code) { | 238 void OAuth2LoginManager::OnNetworkError(int response_code) { |
| 235 account_info_fetcher_.reset(); | 239 account_info_fetcher_.reset(); |
| 236 LOG(ERROR) << "Account info fetch failed! response_code=" << response_code; | 240 LOG(ERROR) << "Account info fetch failed! response_code=" << response_code; |
| 237 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); | 241 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); |
| 238 } | 242 } |
| 239 | 243 |
| 240 void OAuth2LoginManager::FetchOAuth2Tokens() { | 244 void OAuth2LoginManager::FetchOAuth2Tokens() { |
| 241 DCHECK(auth_request_context_.get()); | 245 DCHECK(auth_request_context_.get()); |
| 242 // If we have authenticated cookie jar, get OAuth1 token first, then fetch | 246 // If we have authenticated cookie jar, get OAuth1 token first, then fetch |
| 243 // SID/LSID cookies through OAuthLogin call. | 247 // 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.
| |
| 244 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { | 248 SigninClient* signin_client = |
| 245 SigninClient* signin_client = | 249 ChromeSigninClientFactory::GetForProfile(user_profile_); |
| 246 ChromeSigninClientFactory::GetForProfile(user_profile_); | 250 std::string signin_scoped_device_id = |
| 247 std::string signin_scoped_device_id = | 251 signin_client->GetSigninScopedDeviceId(); |
| 248 signin_client->GetSigninScopedDeviceId(); | |
| 249 | 252 |
| 250 oauth2_token_fetcher_.reset( | 253 oauth2_token_fetcher_.reset( |
| 251 new OAuth2TokenFetcher(this, auth_request_context_.get())); | 254 new OAuth2TokenFetcher(this, auth_request_context_.get())); |
| 252 oauth2_token_fetcher_->StartExchangeFromCookies(std::string(), | 255 oauth2_token_fetcher_->StartExchangeFromCookies(std::string(), |
| 253 signin_scoped_device_id); | 256 signin_scoped_device_id); |
| 254 } else if (restore_strategy_ == RESTORE_FROM_AUTH_CODE) { | |
| 255 DCHECK(!auth_code_.empty()); | |
| 256 oauth2_token_fetcher_.reset( | |
| 257 new OAuth2TokenFetcher(this, | |
| 258 g_browser_process->system_request_context())); | |
| 259 oauth2_token_fetcher_->StartExchangeFromAuthCode(auth_code_); | |
| 260 } else { | |
| 261 NOTREACHED(); | |
| 262 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); | |
| 263 } | |
| 264 } | 257 } |
| 265 | 258 |
| 266 void OAuth2LoginManager::OnOAuth2TokensAvailable( | 259 void OAuth2LoginManager::OnOAuth2TokensAvailable( |
| 267 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { | 260 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { |
| 268 VLOG(1) << "OAuth2 tokens fetched"; | 261 VLOG(1) << "OAuth2 tokens fetched"; |
| 269 DCHECK(refresh_token_.empty()); | 262 DCHECK(refresh_token_.empty()); |
| 270 refresh_token_.assign(oauth2_tokens.refresh_token); | 263 refresh_token_.assign(oauth2_tokens.refresh_token); |
| 271 oauthlogin_access_token_ = oauth2_tokens.access_token; | 264 oauthlogin_access_token_ = oauth2_tokens.access_token; |
| 265 StoreOAuth2Token(); | |
|
xiyuan
2015/04/20 22:02:41
GetTokenHandle() to keep existing behavior?
achuithb
2015/04/21 07:10:21
Done.
| |
| 266 } | |
| 267 | |
| 268 void OAuth2LoginManager::GetTokenHandle() { | |
| 272 if (StartupUtils::IsWebviewSigninEnabled()) { | 269 if (StartupUtils::IsWebviewSigninEnabled()) { |
| 273 auto user = chromeos::ProfileHelper::Get()->GetUserByProfile(user_profile_); | 270 auto user = chromeos::ProfileHelper::Get()->GetUserByProfile(user_profile_); |
| 274 DCHECK(user); | 271 DCHECK(user); |
| 275 if (user) { | 272 if (user) { |
| 276 token_handle_util_.reset( | 273 token_handle_util_.reset( |
| 277 new TokenHandleUtil(user_manager::UserManager::Get())); | 274 new TokenHandleUtil(user_manager::UserManager::Get())); |
| 278 token_handle_util_->GetTokenHandle( | 275 token_handle_util_->GetTokenHandle( |
| 279 user->GetUserID(), oauthlogin_access_token_, | 276 user->GetUserID(), oauthlogin_access_token_, |
| 280 base::Bind(&OAuth2LoginManager::OnTokenHandleComplete, | 277 base::Bind(&OAuth2LoginManager::OnTokenHandleComplete, |
| 281 weak_factory_.GetWeakPtr())); | 278 weak_factory_.GetWeakPtr())); |
| 282 } | 279 } |
| 283 } | 280 } |
| 284 StoreOAuth2Token(); | |
| 285 } | 281 } |
| 286 | 282 |
| 287 void OAuth2LoginManager::OnOAuth2TokensFetchFailed() { | 283 void OAuth2LoginManager::OnOAuth2TokensFetchFailed() { |
| 288 LOG(ERROR) << "OAuth2 tokens fetch failed!"; | 284 LOG(ERROR) << "OAuth2 tokens fetch failed!"; |
| 289 RecordSessionRestoreOutcome(SESSION_RESTORE_TOKEN_FETCH_FAILED, | 285 RecordSessionRestoreOutcome(SESSION_RESTORE_TOKEN_FETCH_FAILED, |
| 290 SESSION_RESTORE_FAILED); | 286 SESSION_RESTORE_FAILED); |
| 291 } | 287 } |
| 292 | 288 |
| 293 void OAuth2LoginManager::VerifySessionCookies() { | 289 void OAuth2LoginManager::VerifySessionCookies() { |
| 294 DCHECK(!login_verifier_.get()); | 290 DCHECK(!login_verifier_.get()); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 base::MessageLoop::current()->DeleteSoon(FROM_HERE, | 439 base::MessageLoop::current()->DeleteSoon(FROM_HERE, |
| 444 token_handle_util_.release()); | 440 token_handle_util_.release()); |
| 445 } | 441 } |
| 446 | 442 |
| 447 void OAuth2LoginManager::SetSessionRestoreStartForTesting( | 443 void OAuth2LoginManager::SetSessionRestoreStartForTesting( |
| 448 const base::Time& time) { | 444 const base::Time& time) { |
| 449 session_restore_start_ = time; | 445 session_restore_start_ = time; |
| 450 } | 446 } |
| 451 | 447 |
| 452 } // namespace chromeos | 448 } // namespace chromeos |
| OLD | NEW |