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

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

Issue 1425093004: Revert of This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Created 5 years, 1 month 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"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/signin/account_tracker_service_factory.h" 13 #include "chrome/browser/signin/account_tracker_service_factory.h"
14 #include "chrome/browser/signin/chrome_signin_client_factory.h" 14 #include "chrome/browser/signin/chrome_signin_client_factory.h"
15 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" 15 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chromeos/chromeos_switches.h" 18 #include "chromeos/chromeos_switches.h"
19 #include "components/signin/core/account_id/account_id.h"
20 #include "components/signin/core/browser/account_tracker_service.h" 19 #include "components/signin/core/browser/account_tracker_service.h"
21 #include "components/signin/core/browser/profile_oauth2_token_service.h" 20 #include "components/signin/core/browser/profile_oauth2_token_service.h"
22 #include "components/signin/core/browser/signin_client.h" 21 #include "components/signin/core/browser/signin_client.h"
23 #include "components/signin/core/browser/signin_manager.h" 22 #include "components/signin/core/browser/signin_manager.h"
24 #include "components/user_manager/user.h" 23 #include "components/user_manager/user.h"
25 #include "components/user_manager/user_manager.h" 24 #include "components/user_manager/user_manager.h"
26 #include "google_apis/gaia/gaia_auth_util.h" 25 #include "google_apis/gaia/gaia_auth_util.h"
27 #include "google_apis/gaia/gaia_urls.h" 26 #include "google_apis/gaia/gaia_urls.h"
28 27
29 namespace chromeos { 28 namespace chromeos {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 VLOG(1) << "OAuth2 refresh token is already loaded."; 101 VLOG(1) << "OAuth2 refresh token is already loaded.";
103 VerifySessionCookies(); 102 VerifySessionCookies();
104 } else { 103 } else {
105 VLOG(1) << "Loading OAuth2 refresh token from database."; 104 VLOG(1) << "Loading OAuth2 refresh token from database.";
106 105
107 // Flag user with unknown token status in case there are no saved tokens 106 // Flag user with unknown token status in case there are no saved tokens
108 // and OnRefreshTokenAvailable is not called. Flagging it here would 107 // and OnRefreshTokenAvailable is not called. Flagging it here would
109 // cause user to go through Gaia in next login to obtain a new refresh 108 // cause user to go through Gaia in next login to obtain a new refresh
110 // token. 109 // token.
111 user_manager::UserManager::Get()->SaveUserOAuthStatus( 110 user_manager::UserManager::Get()->SaveUserOAuthStatus(
112 AccountId::FromUserEmail(primary_account_id), 111 primary_account_id, user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN);
113 user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN);
114 112
115 token_service->LoadCredentials(primary_account_id); 113 token_service->LoadCredentials(primary_account_id);
116 } 114 }
117 } 115 }
118 116
119 void OAuth2LoginManager::Stop() { 117 void OAuth2LoginManager::Stop() {
120 oauth2_token_fetcher_.reset(); 118 oauth2_token_fetcher_.reset();
121 login_verifier_.reset(); 119 login_verifier_.reset();
122 } 120 }
123 121
124 bool OAuth2LoginManager::SessionRestoreIsRunning() const { 122 bool OAuth2LoginManager::SessionRestoreIsRunning() const {
125 return state_ == SESSION_RESTORE_PREPARING || 123 return state_ == SESSION_RESTORE_PREPARING ||
126 state_ == SESSION_RESTORE_IN_PROGRESS; 124 state_ == SESSION_RESTORE_IN_PROGRESS;
127 } 125 }
128 126
129 bool OAuth2LoginManager::ShouldBlockTabLoading() const { 127 bool OAuth2LoginManager::ShouldBlockTabLoading() const {
130 return SessionRestoreIsRunning(); 128 return SessionRestoreIsRunning();
131 } 129 }
132 130
133 void OAuth2LoginManager::OnRefreshTokenAvailable( 131 void OAuth2LoginManager::OnRefreshTokenAvailable(
134 const std::string& user_email) { 132 const std::string& account_id) {
135 VLOG(1) << "OnRefreshTokenAvailable"; 133 VLOG(1) << "OnRefreshTokenAvailable";
136 134
137 if (state_ == SESSION_RESTORE_NOT_STARTED) 135 if (state_ == SESSION_RESTORE_NOT_STARTED)
138 return; 136 return;
139 137
140 // TODO(fgorski): Once ProfileOAuth2TokenService supports multi-login, make 138 // TODO(fgorski): Once ProfileOAuth2TokenService supports multi-login, make
141 // sure to restore session cookies in the context of the correct user_email. 139 // sure to restore session cookies in the context of the correct account_id.
142 140
143 // Do not validate tokens for supervised users, as they don't actually have 141 // Do not validate tokens for supervised users, as they don't actually have
144 // oauth2 token. 142 // oauth2 token.
145 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { 143 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
146 VLOG(1) << "Logged in as supervised user, skip token validation."; 144 VLOG(1) << "Logged in as supervised user, skip token validation.";
147 return; 145 return;
148 } 146 }
149 // Only restore session cookies for the primary account in the profile. 147 // Only restore session cookies for the primary account in the profile.
150 if (GetPrimaryAccountId() == user_email) { 148 if (GetPrimaryAccountId() == account_id) {
151 // Token is loaded. Undo the flagging before token loading. 149 // Token is loaded. Undo the flagging before token loading.
152 user_manager::UserManager::Get()->SaveUserOAuthStatus( 150 user_manager::UserManager::Get()->SaveUserOAuthStatus(
153 AccountId::FromUserEmail(user_email), 151 account_id, user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
154 user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
155 VerifySessionCookies(); 152 VerifySessionCookies();
156 } 153 }
157 } 154 }
158 155
159 ProfileOAuth2TokenService* OAuth2LoginManager::GetTokenService() { 156 ProfileOAuth2TokenService* OAuth2LoginManager::GetTokenService() {
160 return ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_); 157 return ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_);
161 } 158 }
162 159
163 const std::string& OAuth2LoginManager::GetPrimaryAccountId() { 160 const std::string& OAuth2LoginManager::GetPrimaryAccountId() {
164 SigninManagerBase* signin_manager = 161 SigninManagerBase* signin_manager =
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 FOR_EACH_OBSERVER(Observer, observer_list_, 409 FOR_EACH_OBSERVER(Observer, observer_list_,
413 OnSessionRestoreStateChanged(user_profile_, state_)); 410 OnSessionRestoreStateChanged(user_profile_, state_));
414 } 411 }
415 412
416 void OAuth2LoginManager::SetSessionRestoreStartForTesting( 413 void OAuth2LoginManager::SetSessionRestoreStartForTesting(
417 const base::Time& time) { 414 const base::Time& time) {
418 session_restore_start_ = time; 415 session_restore_start_ = time;
419 } 416 }
420 417
421 } // namespace chromeos 418 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698