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

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

Issue 671183002: Revert of Inline sign in extracts gaia id from HTTP header and seeds account tracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 "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/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/signin/account_tracker_service_factory.h"
17 #include "chrome/browser/signin/chrome_signin_client_factory.h" 16 #include "chrome/browser/signin/chrome_signin_client_factory.h"
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 18 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
21 #include "chromeos/chromeos_switches.h" 20 #include "chromeos/chromeos_switches.h"
22 #include "components/signin/core/browser/account_tracker_service.h"
23 #include "components/signin/core/browser/profile_oauth2_token_service.h" 21 #include "components/signin/core/browser/profile_oauth2_token_service.h"
24 #include "components/signin/core/browser/signin_client.h" 22 #include "components/signin/core/browser/signin_client.h"
25 #include "components/signin/core/browser/signin_manager.h" 23 #include "components/signin/core/browser/signin_manager.h"
26 #include "components/user_manager/user_manager.h" 24 #include "components/user_manager/user_manager.h"
27 #include "google_apis/gaia/gaia_auth_util.h" 25 #include "google_apis/gaia/gaia_auth_util.h"
28 #include "google_apis/gaia/gaia_constants.h" 26 #include "google_apis/gaia/gaia_constants.h"
29 #include "google_apis/gaia/gaia_urls.h" 27 #include "google_apis/gaia/gaia_urls.h"
30 #include "net/url_request/url_request_context_getter.h" 28 #include "net/url_request/url_request_context_getter.h"
31 29
32 namespace chromeos { 30 namespace chromeos {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 159
162 const std::string& OAuth2LoginManager::GetPrimaryAccountId() { 160 const std::string& OAuth2LoginManager::GetPrimaryAccountId() {
163 SigninManagerBase* signin_manager = 161 SigninManagerBase* signin_manager =
164 SigninManagerFactory::GetForProfile(user_profile_); 162 SigninManagerFactory::GetForProfile(user_profile_);
165 return signin_manager->GetAuthenticatedAccountId(); 163 return signin_manager->GetAuthenticatedAccountId();
166 } 164 }
167 165
168 void OAuth2LoginManager::StoreOAuth2Token() { 166 void OAuth2LoginManager::StoreOAuth2Token() {
169 const std::string& primary_account_id = GetPrimaryAccountId(); 167 const std::string& primary_account_id = GetPrimaryAccountId();
170 if (primary_account_id.empty()) { 168 if (primary_account_id.empty()) {
171 GetAccountInfoOfRefreshToken(refresh_token_); 169 GetAccountIdOfRefreshToken(refresh_token_);
172 return; 170 return;
173 } 171 }
174 172
175 UpdateCredentials(primary_account_id); 173 OnGetUserEmailResponse(primary_account_id);
176 } 174 }
177 175
178 void OAuth2LoginManager::GetAccountInfoOfRefreshToken( 176 void OAuth2LoginManager::GetAccountIdOfRefreshToken(
179 const std::string& refresh_token) { 177 const std::string& refresh_token) {
180 gaia::OAuthClientInfo client_info; 178 gaia::OAuthClientInfo client_info;
181 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 179 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
182 client_info.client_id = gaia_urls->oauth2_chrome_client_id(); 180 client_info.client_id = gaia_urls->oauth2_chrome_client_id();
183 client_info.client_secret = gaia_urls->oauth2_chrome_client_secret(); 181 client_info.client_secret = gaia_urls->oauth2_chrome_client_secret();
184 182
185 account_info_fetcher_.reset(new gaia::GaiaOAuthClient( 183 account_id_fetcher_.reset(new gaia::GaiaOAuthClient(
186 auth_request_context_.get())); 184 auth_request_context_.get()));
187 account_info_fetcher_->RefreshToken(client_info, refresh_token, 185 account_id_fetcher_->RefreshToken(client_info, refresh_token,
188 std::vector<std::string>(1, kServiceScopeGetUserInfo), kMaxRetries, 186 std::vector<std::string>(1, kServiceScopeGetUserInfo), kMaxRetries,
189 this); 187 this);
190 } 188 }
191 189
192 void OAuth2LoginManager::UpdateCredentials(const std::string& account_id) { 190 void OAuth2LoginManager::OnRefreshTokenResponse(
193 DCHECK(!account_id.empty()); 191 const std::string& access_token,
192 int expires_in_seconds) {
193 account_id_fetcher_->GetUserEmail(access_token, kMaxRetries, this);
194 }
195
196 void OAuth2LoginManager::OnGetUserEmailResponse(
197 const std::string& user_email) {
194 DCHECK(!refresh_token_.empty()); 198 DCHECK(!refresh_token_.empty());
195 // |account_id| is assumed to be already canonicalized if it's an email. 199 account_id_fetcher_.reset();
196 GetTokenService()->UpdateCredentials(account_id, refresh_token_); 200 std::string canonicalized = gaia::CanonicalizeEmail(user_email);
201 GetTokenService()->UpdateCredentials(canonicalized, refresh_token_);
197 202
198 FOR_EACH_OBSERVER(Observer, observer_list_, 203 FOR_EACH_OBSERVER(Observer, observer_list_,
199 OnNewRefreshTokenAvaiable(user_profile_)); 204 OnNewRefreshTokenAvaiable(user_profile_));
200 } 205 }
201 206
202 void OAuth2LoginManager::OnRefreshTokenResponse(
203 const std::string& access_token,
204 int expires_in_seconds) {
205 account_info_fetcher_->GetUserInfo(access_token, kMaxRetries, this);
206 }
207
208 void OAuth2LoginManager::OnGetUserInfoResponse(
209 scoped_ptr<base::DictionaryValue> user_info) {
210 account_info_fetcher_.reset();
211
212 std::string gaia_id;
213 std::string email;
214 user_info->GetString("id", &gaia_id);
215 user_info->GetString("email", &email);
216
217 AccountTrackerService* account_tracker =
218 AccountTrackerServiceFactory::GetForProfile(user_profile_);
219 account_tracker->SeedAccountInfo(gaia_id, email);
220 UpdateCredentials(account_tracker->PickAccountIdForAccount(gaia_id, email));
221 }
222
223 void OAuth2LoginManager::OnOAuthError() { 207 void OAuth2LoginManager::OnOAuthError() {
224 account_info_fetcher_.reset(); 208 account_id_fetcher_.reset();
225 LOG(ERROR) << "Account info fetch failed!"; 209 LOG(ERROR) << "Account id fetch failed!";
226 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); 210 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED);
227 } 211 }
228 212
229 void OAuth2LoginManager::OnNetworkError(int response_code) { 213 void OAuth2LoginManager::OnNetworkError(int response_code) {
230 account_info_fetcher_.reset(); 214 account_id_fetcher_.reset();
231 LOG(ERROR) << "Account info fetch failed! response_code=" << response_code; 215 LOG(ERROR) << "Account id fetch failed! response_code=" << response_code;
232 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); 216 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED);
233 } 217 }
234 218
235 void OAuth2LoginManager::FetchOAuth2Tokens() { 219 void OAuth2LoginManager::FetchOAuth2Tokens() {
236 DCHECK(auth_request_context_.get()); 220 DCHECK(auth_request_context_.get());
237 // 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
238 // SID/LSID cookies through OAuthLogin call. 222 // SID/LSID cookies through OAuthLogin call.
239 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { 223 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) {
240 SigninClient* signin_client = 224 SigninClient* signin_client =
241 ChromeSigninClientFactory::GetForProfile(user_profile_); 225 ChromeSigninClientFactory::GetForProfile(user_profile_);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 FOR_EACH_OBSERVER(Observer, observer_list_, 403 FOR_EACH_OBSERVER(Observer, observer_list_,
420 OnSessionRestoreStateChanged(user_profile_, state_)); 404 OnSessionRestoreStateChanged(user_profile_, state_));
421 } 405 }
422 406
423 void OAuth2LoginManager::SetSessionRestoreStartForTesting( 407 void OAuth2LoginManager::SetSessionRestoreStartForTesting(
424 const base::Time& time) { 408 const base::Time& time) {
425 session_restore_start_ = time; 409 session_restore_start_ = time;
426 } 410 }
427 411
428 } // namespace chromeos 412 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698