| 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/login/users/user_manager.h" | 15 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
| 21 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 22 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 23 #include "components/signin/core/browser/signin_client.h" |
| 22 #include "components/signin/core/browser/signin_manager.h" | 24 #include "components/signin/core/browser/signin_manager.h" |
| 23 #include "google_apis/gaia/gaia_auth_util.h" | 25 #include "google_apis/gaia/gaia_auth_util.h" |
| 24 #include "google_apis/gaia/gaia_constants.h" | 26 #include "google_apis/gaia/gaia_constants.h" |
| 25 #include "google_apis/gaia/gaia_urls.h" | 27 #include "google_apis/gaia/gaia_urls.h" |
| 26 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
| 27 | 29 |
| 28 namespace chromeos { | 30 namespace chromeos { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 account_id_fetcher_.reset(); | 214 account_id_fetcher_.reset(); |
| 213 LOG(ERROR) << "Account id fetch failed! response_code=" << response_code; | 215 LOG(ERROR) << "Account id fetch failed! response_code=" << response_code; |
| 214 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); | 216 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); |
| 215 } | 217 } |
| 216 | 218 |
| 217 void OAuth2LoginManager::FetchOAuth2Tokens() { | 219 void OAuth2LoginManager::FetchOAuth2Tokens() { |
| 218 DCHECK(auth_request_context_.get()); | 220 DCHECK(auth_request_context_.get()); |
| 219 // If we have authenticated cookie jar, get OAuth1 token first, then fetch | 221 // If we have authenticated cookie jar, get OAuth1 token first, then fetch |
| 220 // SID/LSID cookies through OAuthLogin call. | 222 // SID/LSID cookies through OAuthLogin call. |
| 221 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { | 223 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { |
| 224 SigninClient* signin_client = |
| 225 ChromeSigninClientFactory::GetForProfile(user_profile_); |
| 226 std::string signin_scoped_device_id = |
| 227 signin_client->GetSigninScopedDeviceId(); |
| 228 |
| 222 oauth2_token_fetcher_.reset( | 229 oauth2_token_fetcher_.reset( |
| 223 new OAuth2TokenFetcher(this, auth_request_context_.get())); | 230 new OAuth2TokenFetcher(this, auth_request_context_.get())); |
| 224 oauth2_token_fetcher_->StartExchangeFromCookies(std::string()); | 231 oauth2_token_fetcher_->StartExchangeFromCookies(std::string(), |
| 232 signin_scoped_device_id); |
| 225 } else if (restore_strategy_ == RESTORE_FROM_AUTH_CODE) { | 233 } else if (restore_strategy_ == RESTORE_FROM_AUTH_CODE) { |
| 226 DCHECK(!auth_code_.empty()); | 234 DCHECK(!auth_code_.empty()); |
| 227 oauth2_token_fetcher_.reset( | 235 oauth2_token_fetcher_.reset( |
| 228 new OAuth2TokenFetcher(this, | 236 new OAuth2TokenFetcher(this, |
| 229 g_browser_process->system_request_context())); | 237 g_browser_process->system_request_context())); |
| 230 oauth2_token_fetcher_->StartExchangeFromAuthCode(auth_code_); | 238 oauth2_token_fetcher_->StartExchangeFromAuthCode(auth_code_); |
| 231 } else { | 239 } else { |
| 232 NOTREACHED(); | 240 NOTREACHED(); |
| 233 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); | 241 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); |
| 234 } | 242 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 FOR_EACH_OBSERVER(Observer, observer_list_, | 403 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 396 OnSessionRestoreStateChanged(user_profile_, state_)); | 404 OnSessionRestoreStateChanged(user_profile_, state_)); |
| 397 } | 405 } |
| 398 | 406 |
| 399 void OAuth2LoginManager::SetSessionRestoreStartForTesting( | 407 void OAuth2LoginManager::SetSessionRestoreStartForTesting( |
| 400 const base::Time& time) { | 408 const base::Time& time) { |
| 401 session_restore_start_ = time; | 409 session_restore_start_ = time; |
| 402 } | 410 } |
| 403 | 411 |
| 404 } // namespace chromeos | 412 } // namespace chromeos |
| OLD | NEW |