Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: chrome/browser/chromeos/login/signin/oauth2_login_manager.cc

Issue 1097663003: Fetch OAuth2 tokens prior to profile creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: set up default networks Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
96 // Save passed OAuth2 refresh token. 94 // Save passed OAuth2 refresh token.
97 if (restore_strategy_ == RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN) { 95 if (restore_strategy_ == RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN) {
98 DCHECK(!refresh_token_.empty()); 96 DCHECK(!refresh_token_.empty());
99 restore_strategy_ = RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; 97 restore_strategy_ = RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN;
100 StoreOAuth2Token(); 98 StoreOAuth2Token();
101 return; 99 return;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 230 }
233 231
234 void OAuth2LoginManager::OnNetworkError(int response_code) { 232 void OAuth2LoginManager::OnNetworkError(int response_code) {
235 account_info_fetcher_.reset(); 233 account_info_fetcher_.reset();
236 LOG(ERROR) << "Account info fetch failed! response_code=" << response_code; 234 LOG(ERROR) << "Account info fetch failed! response_code=" << response_code;
237 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); 235 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED);
238 } 236 }
239 237
240 void OAuth2LoginManager::FetchOAuth2Tokens() { 238 void OAuth2LoginManager::FetchOAuth2Tokens() {
241 DCHECK(auth_request_context_.get()); 239 DCHECK(auth_request_context_.get());
240 DCHECK_EQ(RESTORE_FROM_COOKIE_JAR, restore_strategy_);
241
242 // If we have authenticated cookie jar, get OAuth1 token first, then fetch 242 // If we have authenticated cookie jar, get OAuth1 token first, then fetch
243 // SID/LSID cookies through OAuthLogin call. 243 // SID/LSID cookies through OAuthLogin call.
244 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { 244 SigninClient* signin_client =
245 SigninClient* signin_client = 245 ChromeSigninClientFactory::GetForProfile(user_profile_);
246 ChromeSigninClientFactory::GetForProfile(user_profile_); 246 std::string signin_scoped_device_id =
247 std::string signin_scoped_device_id = 247 signin_client->GetSigninScopedDeviceId();
248 signin_client->GetSigninScopedDeviceId();
249 248
250 oauth2_token_fetcher_.reset( 249 oauth2_token_fetcher_.reset(
251 new OAuth2TokenFetcher(this, auth_request_context_.get())); 250 new OAuth2TokenFetcher(this, auth_request_context_.get()));
252 oauth2_token_fetcher_->StartExchangeFromCookies(std::string(), 251 oauth2_token_fetcher_->StartExchangeFromCookies(std::string(),
253 signin_scoped_device_id); 252 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);
Nikita (slow) 2015/04/23 10:59:25 I suggest keeping this code as a safety net when F
achuithb 2015/04/23 22:11:16 Done.
263 }
264 } 253 }
265 254
266 void OAuth2LoginManager::OnOAuth2TokensAvailable( 255 void OAuth2LoginManager::OnOAuth2TokensAvailable(
267 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { 256 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) {
268 VLOG(1) << "OAuth2 tokens fetched"; 257 VLOG(1) << "OAuth2 tokens fetched";
269 DCHECK(refresh_token_.empty()); 258 DCHECK(refresh_token_.empty());
270 refresh_token_.assign(oauth2_tokens.refresh_token); 259 refresh_token_.assign(oauth2_tokens.refresh_token);
271 oauthlogin_access_token_ = oauth2_tokens.access_token; 260 oauthlogin_access_token_ = oauth2_tokens.access_token;
272 if (StartupUtils::IsWebviewSigninEnabled()) { 261 if (StartupUtils::IsWebviewSigninEnabled()) {
273 auto user = chromeos::ProfileHelper::Get()->GetUserByProfile(user_profile_); 262 auto user = chromeos::ProfileHelper::Get()->GetUserByProfile(user_profile_);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 base::MessageLoop::current()->DeleteSoon(FROM_HERE, 432 base::MessageLoop::current()->DeleteSoon(FROM_HERE,
444 token_handle_util_.release()); 433 token_handle_util_.release());
445 } 434 }
446 435
447 void OAuth2LoginManager::SetSessionRestoreStartForTesting( 436 void OAuth2LoginManager::SetSessionRestoreStartForTesting(
448 const base::Time& time) { 437 const base::Time& time) {
449 session_restore_start_ = time; 438 session_restore_start_ = time;
450 } 439 }
451 440
452 } // namespace chromeos 441 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698