| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 DCHECK(restore_strategy_ == RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN); | 94 DCHECK(restore_strategy_ == RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN); |
| 95 RestoreSessionFromSavedTokens(); | 95 RestoreSessionFromSavedTokens(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void OAuth2LoginManager::RestoreSessionFromSavedTokens() { | 98 void OAuth2LoginManager::RestoreSessionFromSavedTokens() { |
| 99 ProfileOAuth2TokenService* token_service = GetTokenService(); | 99 ProfileOAuth2TokenService* token_service = GetTokenService(); |
| 100 const std::string& primary_account_id = GetPrimaryAccountId(); | 100 const std::string& primary_account_id = GetPrimaryAccountId(); |
| 101 if (token_service->RefreshTokenIsAvailable(primary_account_id)) { | 101 if (token_service->RefreshTokenIsAvailable(primary_account_id)) { |
| 102 VLOG(1) << "OAuth2 refresh token is already loaded."; | 102 VLOG(1) << "OAuth2 refresh token is already loaded."; |
| 103 FireRefreshTokensLoaded(); |
| 103 VerifySessionCookies(); | 104 VerifySessionCookies(); |
| 104 } else { | 105 } else { |
| 105 VLOG(1) << "Loading OAuth2 refresh token from database."; | 106 VLOG(1) << "Loading OAuth2 refresh token from database."; |
| 106 | 107 |
| 107 // Flag user with unknown token status in case there are no saved tokens | 108 // Flag user with unknown token status in case there are no saved tokens |
| 108 // and OnRefreshTokenAvailable is not called. Flagging it here would | 109 // and OnRefreshTokenAvailable is not called. Flagging it here would |
| 109 // cause user to go through Gaia in next login to obtain a new refresh | 110 // cause user to go through Gaia in next login to obtain a new refresh |
| 110 // token. | 111 // token. |
| 111 user_manager::UserManager::Get()->SaveUserOAuthStatus( | 112 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
| 112 AccountId::FromUserEmail(primary_account_id), | 113 AccountId::FromUserEmail(primary_account_id), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 account_info_fetcher_->RefreshToken(client_info, refresh_token, | 189 account_info_fetcher_->RefreshToken(client_info, refresh_token, |
| 189 std::vector<std::string>(1, kServiceScopeGetUserInfo), kMaxRetries, | 190 std::vector<std::string>(1, kServiceScopeGetUserInfo), kMaxRetries, |
| 190 this); | 191 this); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void OAuth2LoginManager::UpdateCredentials(const std::string& account_id) { | 194 void OAuth2LoginManager::UpdateCredentials(const std::string& account_id) { |
| 194 DCHECK(!account_id.empty()); | 195 DCHECK(!account_id.empty()); |
| 195 DCHECK(!refresh_token_.empty()); | 196 DCHECK(!refresh_token_.empty()); |
| 196 // |account_id| is assumed to be already canonicalized if it's an email. | 197 // |account_id| is assumed to be already canonicalized if it's an email. |
| 197 GetTokenService()->UpdateCredentials(account_id, refresh_token_); | 198 GetTokenService()->UpdateCredentials(account_id, refresh_token_); |
| 199 FireRefreshTokensLoaded(); |
| 198 | 200 |
| 199 FOR_EACH_OBSERVER(Observer, observer_list_, | 201 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 200 OnNewRefreshTokenAvaiable(user_profile_)); | 202 OnNewRefreshTokenAvaiable(user_profile_)); |
| 201 } | 203 } |
| 202 | 204 |
| 205 void OAuth2LoginManager::FireRefreshTokensLoaded() { |
| 206 // TODO(570218): Figure out the right way to plumb this. |
| 207 GetTokenService()->LoadCredentials(std::string()); |
| 208 } |
| 209 |
| 203 void OAuth2LoginManager::OnRefreshTokenResponse( | 210 void OAuth2LoginManager::OnRefreshTokenResponse( |
| 204 const std::string& access_token, | 211 const std::string& access_token, |
| 205 int expires_in_seconds) { | 212 int expires_in_seconds) { |
| 206 account_info_fetcher_->GetUserInfo(access_token, kMaxRetries, this); | 213 account_info_fetcher_->GetUserInfo(access_token, kMaxRetries, this); |
| 207 } | 214 } |
| 208 | 215 |
| 209 void OAuth2LoginManager::OnGetUserInfoResponse( | 216 void OAuth2LoginManager::OnGetUserInfoResponse( |
| 210 scoped_ptr<base::DictionaryValue> user_info) { | 217 scoped_ptr<base::DictionaryValue> user_info) { |
| 211 account_info_fetcher_.reset(); | 218 account_info_fetcher_.reset(); |
| 212 | 219 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 FOR_EACH_OBSERVER(Observer, observer_list_, | 419 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 413 OnSessionRestoreStateChanged(user_profile_, state_)); | 420 OnSessionRestoreStateChanged(user_profile_, state_)); |
| 414 } | 421 } |
| 415 | 422 |
| 416 void OAuth2LoginManager::SetSessionRestoreStartForTesting( | 423 void OAuth2LoginManager::SetSessionRestoreStartForTesting( |
| 417 const base::Time& time) { | 424 const base::Time& time) { |
| 418 session_restore_start_ = time; | 425 session_restore_start_ = time; |
| 419 } | 426 } |
| 420 | 427 |
| 421 } // namespace chromeos | 428 } // namespace chromeos |
| OLD | NEW |