| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 restore_strategy_ = RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; | 89 restore_strategy_ = RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; |
| 90 StoreOAuth2Token(); | 90 StoreOAuth2Token(); |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 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 // Just return if there is a pending TokenService::LoadCredentials call. |
| 100 // Session restore continues in OnRefreshTokenAvailable when the call |
| 101 // finishes. |
| 102 if (pending_token_service_load_) |
| 103 return; |
| 104 |
| 99 ProfileOAuth2TokenService* token_service = GetTokenService(); | 105 ProfileOAuth2TokenService* token_service = GetTokenService(); |
| 100 const std::string& primary_account_id = GetPrimaryAccountId(); | 106 const std::string& primary_account_id = GetPrimaryAccountId(); |
| 101 if (token_service->RefreshTokenIsAvailable(primary_account_id)) { | 107 if (token_service->RefreshTokenIsAvailable(primary_account_id)) { |
| 102 VLOG(1) << "OAuth2 refresh token is already loaded."; | 108 VLOG(1) << "OAuth2 refresh token is already loaded."; |
| 103 FireRefreshTokensLoaded(); | 109 FireRefreshTokensLoaded(); |
| 104 VerifySessionCookies(); | 110 VerifySessionCookies(); |
| 105 } else { | 111 } else { |
| 106 VLOG(1) << "Loading OAuth2 refresh token from database."; | 112 VLOG(1) << "Loading OAuth2 refresh token from database."; |
| 107 | 113 |
| 108 // Flag user with unknown token status in case there are no saved tokens | 114 // Flag user with unknown token status in case there are no saved tokens |
| 109 // and OnRefreshTokenAvailable is not called. Flagging it here would | 115 // and OnRefreshTokenAvailable is not called. Flagging it here would |
| 110 // cause user to go through Gaia in next login to obtain a new refresh | 116 // cause user to go through Gaia in next login to obtain a new refresh |
| 111 // token. | 117 // token. |
| 112 user_manager::UserManager::Get()->SaveUserOAuthStatus( | 118 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
| 113 AccountId::FromUserEmail(primary_account_id), | 119 AccountId::FromUserEmail(primary_account_id), |
| 114 user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); | 120 user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); |
| 115 | 121 |
| 122 pending_token_service_load_ = true; |
| 116 token_service->LoadCredentials(primary_account_id); | 123 token_service->LoadCredentials(primary_account_id); |
| 117 } | 124 } |
| 118 } | 125 } |
| 119 | 126 |
| 120 void OAuth2LoginManager::Stop() { | 127 void OAuth2LoginManager::Stop() { |
| 121 oauth2_token_fetcher_.reset(); | 128 oauth2_token_fetcher_.reset(); |
| 122 login_verifier_.reset(); | 129 login_verifier_.reset(); |
| 123 } | 130 } |
| 124 | 131 |
| 125 bool OAuth2LoginManager::SessionRestoreIsRunning() const { | 132 bool OAuth2LoginManager::SessionRestoreIsRunning() const { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 146 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { | 153 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { |
| 147 VLOG(1) << "Logged in as supervised user, skip token validation."; | 154 VLOG(1) << "Logged in as supervised user, skip token validation."; |
| 148 return; | 155 return; |
| 149 } | 156 } |
| 150 // Only restore session cookies for the primary account in the profile. | 157 // Only restore session cookies for the primary account in the profile. |
| 151 if (GetPrimaryAccountId() == user_email) { | 158 if (GetPrimaryAccountId() == user_email) { |
| 152 // Token is loaded. Undo the flagging before token loading. | 159 // Token is loaded. Undo the flagging before token loading. |
| 153 user_manager::UserManager::Get()->SaveUserOAuthStatus( | 160 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
| 154 AccountId::FromUserEmail(user_email), | 161 AccountId::FromUserEmail(user_email), |
| 155 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | 162 user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
| 163 |
| 164 pending_token_service_load_ = false; |
| 156 VerifySessionCookies(); | 165 VerifySessionCookies(); |
| 157 } | 166 } |
| 158 } | 167 } |
| 159 | 168 |
| 160 ProfileOAuth2TokenService* OAuth2LoginManager::GetTokenService() { | 169 ProfileOAuth2TokenService* OAuth2LoginManager::GetTokenService() { |
| 161 return ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_); | 170 return ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_); |
| 162 } | 171 } |
| 163 | 172 |
| 164 const std::string& OAuth2LoginManager::GetPrimaryAccountId() { | 173 const std::string& OAuth2LoginManager::GetPrimaryAccountId() { |
| 165 SigninManagerBase* signin_manager = | 174 SigninManagerBase* signin_manager = |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 for (auto& observer : observer_list_) | 428 for (auto& observer : observer_list_) |
| 420 observer.OnSessionRestoreStateChanged(user_profile_, state_); | 429 observer.OnSessionRestoreStateChanged(user_profile_, state_); |
| 421 } | 430 } |
| 422 | 431 |
| 423 void OAuth2LoginManager::SetSessionRestoreStartForTesting( | 432 void OAuth2LoginManager::SetSessionRestoreStartForTesting( |
| 424 const base::Time& time) { | 433 const base::Time& time) { |
| 425 session_restore_start_ = time; | 434 session_restore_start_ = time; |
| 426 } | 435 } |
| 427 | 436 |
| 428 } // namespace chromeos | 437 } // namespace chromeos |
| OLD | NEW |