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

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

Issue 606083002: patch from issue 473153002 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix saml Created 6 years, 2 months 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 "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"
16 #include "chrome/browser/signin/chrome_signin_client_factory.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"
22 #include "components/signin/core/browser/account_tracker_service.h"
21 #include "components/signin/core/browser/profile_oauth2_token_service.h" 23 #include "components/signin/core/browser/profile_oauth2_token_service.h"
22 #include "components/signin/core/browser/signin_client.h" 24 #include "components/signin/core/browser/signin_client.h"
23 #include "components/signin/core/browser/signin_manager.h" 25 #include "components/signin/core/browser/signin_manager.h"
24 #include "components/user_manager/user_manager.h" 26 #include "components/user_manager/user_manager.h"
25 #include "google_apis/gaia/gaia_auth_util.h" 27 #include "google_apis/gaia/gaia_auth_util.h"
26 #include "google_apis/gaia/gaia_constants.h" 28 #include "google_apis/gaia/gaia_constants.h"
27 #include "google_apis/gaia/gaia_urls.h" 29 #include "google_apis/gaia/gaia_urls.h"
28 #include "net/url_request/url_request_context_getter.h" 30 #include "net/url_request/url_request_context_getter.h"
29 31
30 namespace chromeos { 32 namespace chromeos {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 161
160 const std::string& OAuth2LoginManager::GetPrimaryAccountId() { 162 const std::string& OAuth2LoginManager::GetPrimaryAccountId() {
161 SigninManagerBase* signin_manager = 163 SigninManagerBase* signin_manager =
162 SigninManagerFactory::GetForProfile(user_profile_); 164 SigninManagerFactory::GetForProfile(user_profile_);
163 return signin_manager->GetAuthenticatedAccountId(); 165 return signin_manager->GetAuthenticatedAccountId();
164 } 166 }
165 167
166 void OAuth2LoginManager::StoreOAuth2Token() { 168 void OAuth2LoginManager::StoreOAuth2Token() {
167 const std::string& primary_account_id = GetPrimaryAccountId(); 169 const std::string& primary_account_id = GetPrimaryAccountId();
168 if (primary_account_id.empty()) { 170 if (primary_account_id.empty()) {
169 GetAccountIdOfRefreshToken(refresh_token_); 171 GetAccountInfoOfRefreshToken(refresh_token_);
170 return; 172 return;
171 } 173 }
172 174
173 OnGetUserEmailResponse(primary_account_id); 175 UpdateCredentials(primary_account_id);
174 } 176 }
175 177
176 void OAuth2LoginManager::GetAccountIdOfRefreshToken( 178 void OAuth2LoginManager::GetAccountInfoOfRefreshToken(
177 const std::string& refresh_token) { 179 const std::string& refresh_token) {
178 gaia::OAuthClientInfo client_info; 180 gaia::OAuthClientInfo client_info;
179 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 181 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
180 client_info.client_id = gaia_urls->oauth2_chrome_client_id(); 182 client_info.client_id = gaia_urls->oauth2_chrome_client_id();
181 client_info.client_secret = gaia_urls->oauth2_chrome_client_secret(); 183 client_info.client_secret = gaia_urls->oauth2_chrome_client_secret();
182 184
183 account_id_fetcher_.reset(new gaia::GaiaOAuthClient( 185 account_info_fetcher_.reset(new gaia::GaiaOAuthClient(
184 auth_request_context_.get())); 186 auth_request_context_.get()));
185 account_id_fetcher_->RefreshToken(client_info, refresh_token, 187 account_info_fetcher_->RefreshToken(client_info, refresh_token,
186 std::vector<std::string>(1, kServiceScopeGetUserInfo), kMaxRetries, 188 std::vector<std::string>(1, kServiceScopeGetUserInfo), kMaxRetries,
187 this); 189 this);
188 } 190 }
189 191
190 void OAuth2LoginManager::OnRefreshTokenResponse( 192 void OAuth2LoginManager::UpdateCredentials(const std::string& account_id) {
191 const std::string& access_token, 193 DCHECK(!account_id.empty());
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) {
198 DCHECK(!refresh_token_.empty()); 194 DCHECK(!refresh_token_.empty());
199 account_id_fetcher_.reset(); 195 // TODO(rogerta): why canonicalize? Seems like this creates problems.
200 std::string canonicalized = gaia::CanonicalizeEmail(user_email); 196 std::string canonicalized = gaia::CanonicalizeEmail(account_id);
201 GetTokenService()->UpdateCredentials(canonicalized, refresh_token_); 197 GetTokenService()->UpdateCredentials(canonicalized, refresh_token_);
202 198
203 FOR_EACH_OBSERVER(Observer, observer_list_, 199 FOR_EACH_OBSERVER(Observer, observer_list_,
204 OnNewRefreshTokenAvaiable(user_profile_)); 200 OnNewRefreshTokenAvaiable(user_profile_));
205 } 201 }
206 202
203 void OAuth2LoginManager::OnRefreshTokenResponse(
204 const std::string& access_token,
205 int expires_in_seconds) {
206 account_info_fetcher_->GetUserInfo(access_token, kMaxRetries, this);
207 }
208
209 void OAuth2LoginManager::OnGetUserInfoResponse(
210 scoped_ptr<base::DictionaryValue> user_info) {
211 account_info_fetcher_.reset();
212
213 std::string account_id = GetPrimaryAccountId();
214 std::string gaia_id;
215 std::string email;
216 if (user_info->GetString("id", &gaia_id) &&
217 user_info->GetString("email", &email)) {
218 AccountTrackerService* account_tracker =
219 AccountTrackerServiceFactory::GetForProfile(user_profile_);
220 account_tracker->SeedAccountInfo(account_id, gaia_id, email);
221 }
222
223 UpdateCredentials(account_id);
224 }
225
207 void OAuth2LoginManager::OnOAuthError() { 226 void OAuth2LoginManager::OnOAuthError() {
208 account_id_fetcher_.reset(); 227 account_info_fetcher_.reset();
209 LOG(ERROR) << "Account id fetch failed!"; 228 LOG(ERROR) << "Account info fetch failed!";
210 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); 229 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED);
211 } 230 }
212 231
213 void OAuth2LoginManager::OnNetworkError(int response_code) { 232 void OAuth2LoginManager::OnNetworkError(int response_code) {
214 account_id_fetcher_.reset(); 233 account_info_fetcher_.reset();
215 LOG(ERROR) << "Account id fetch failed! response_code=" << response_code; 234 LOG(ERROR) << "Account info fetch failed! response_code=" << response_code;
216 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED); 235 SetSessionRestoreState(OAuth2LoginManager::SESSION_RESTORE_FAILED);
217 } 236 }
218 237
219 void OAuth2LoginManager::FetchOAuth2Tokens() { 238 void OAuth2LoginManager::FetchOAuth2Tokens() {
220 DCHECK(auth_request_context_.get()); 239 DCHECK(auth_request_context_.get());
221 // If we have authenticated cookie jar, get OAuth1 token first, then fetch 240 // If we have authenticated cookie jar, get OAuth1 token first, then fetch
222 // SID/LSID cookies through OAuthLogin call. 241 // SID/LSID cookies through OAuthLogin call.
223 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) { 242 if (restore_strategy_ == RESTORE_FROM_COOKIE_JAR) {
224 SigninClient* signin_client = 243 SigninClient* signin_client =
225 ChromeSigninClientFactory::GetForProfile(user_profile_); 244 ChromeSigninClientFactory::GetForProfile(user_profile_);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 FOR_EACH_OBSERVER(Observer, observer_list_, 422 FOR_EACH_OBSERVER(Observer, observer_list_,
404 OnSessionRestoreStateChanged(user_profile_, state_)); 423 OnSessionRestoreStateChanged(user_profile_, state_));
405 } 424 }
406 425
407 void OAuth2LoginManager::SetSessionRestoreStartForTesting( 426 void OAuth2LoginManager::SetSessionRestoreStartForTesting(
408 const base::Time& time) { 427 const base::Time& time) {
409 session_restore_start_ = time; 428 session_restore_start_ = time;
410 } 429 }
411 430
412 } // namespace chromeos 431 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698