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 |
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 Loading... |
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 if (restore_strategy_ != RESTORE_FROM_COOKIE_JAR) { |
| 241 NOTREACHED(); |
| 242 SetSessionRestoreState(SESSION_RESTORE_FAILED); |
| 243 return; |
| 244 } |
| 245 |
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. |
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; |
272 if (StartupUtils::IsWebviewSigninEnabled()) { | 265 if (StartupUtils::IsWebviewSigninEnabled()) { |
273 auto user = chromeos::ProfileHelper::Get()->GetUserByProfile(user_profile_); | 266 auto user = chromeos::ProfileHelper::Get()->GetUserByProfile(user_profile_); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 base::MessageLoop::current()->DeleteSoon(FROM_HERE, | 436 base::MessageLoop::current()->DeleteSoon(FROM_HERE, |
444 token_handle_util_.release()); | 437 token_handle_util_.release()); |
445 } | 438 } |
446 | 439 |
447 void OAuth2LoginManager::SetSessionRestoreStartForTesting( | 440 void OAuth2LoginManager::SetSessionRestoreStartForTesting( |
448 const base::Time& time) { | 441 const base::Time& time) { |
449 session_restore_start_ = time; | 442 session_restore_start_ = time; |
450 } | 443 } |
451 | 444 |
452 } // namespace chromeos | 445 } // namespace chromeos |
OLD | NEW |