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

Side by Side Diff: chrome/browser/signin/mutable_profile_oauth2_token_service_delegate.cc

Issue 2939443004: Load credentials on desktop even when there is no authenticated account ID. (Closed)
Patch Set: Unit test Created 3 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/signin/mutable_profile_oauth2_token_service_delegate.h" 5 #include "chrome/browser/signin/mutable_profile_oauth2_token_service_delegate.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 273 }
274 274
275 void MutableProfileOAuth2TokenServiceDelegate::LoadCredentials( 275 void MutableProfileOAuth2TokenServiceDelegate::LoadCredentials(
276 const std::string& primary_account_id) { 276 const std::string& primary_account_id) {
277 if (load_credentials_state_ == LOAD_CREDENTIALS_IN_PROGRESS) { 277 if (load_credentials_state_ == LOAD_CREDENTIALS_IN_PROGRESS) {
278 VLOG(1) << "Load credentials operation already in progress"; 278 VLOG(1) << "Load credentials operation already in progress";
279 return; 279 return;
280 } 280 }
281 281
282 load_credentials_state_ = LOAD_CREDENTIALS_IN_PROGRESS; 282 load_credentials_state_ = LOAD_CREDENTIALS_IN_PROGRESS;
283 if (primary_account_id.empty()) { 283 if (primary_account_id.empty() &&
284 !switches::IsAccountConsistencyDiceEnabled()) {
284 load_credentials_state_ = LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS; 285 load_credentials_state_ = LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS;
285 FireRefreshTokensLoaded(); 286 FireRefreshTokensLoaded();
286 return; 287 return;
287 } 288 }
288 289
289 ValidateAccountId(primary_account_id); 290 if (!primary_account_id.empty())
291 ValidateAccountId(primary_account_id);
290 DCHECK(loading_primary_account_id_.empty()); 292 DCHECK(loading_primary_account_id_.empty());
291 DCHECK_EQ(0, web_data_service_request_); 293 DCHECK_EQ(0, web_data_service_request_);
292 294
293 refresh_tokens_.clear(); 295 refresh_tokens_.clear();
294 296
295 scoped_refptr<TokenWebData> token_web_data = client_->GetDatabase(); 297 scoped_refptr<TokenWebData> token_web_data = client_->GetDatabase();
296 if (!token_web_data) { 298 if (!token_web_data) {
297 // This case only exists in unit tests that do not care about loading 299 // This case only exists in unit tests that do not care about loading
298 // credentials. 300 // credentials.
299 load_credentials_state_ = LOAD_CREDENTIALS_FINISHED_WITH_UNKNOWN_ERRORS; 301 load_credentials_state_ = LOAD_CREDENTIALS_FINISHED_WITH_UNKNOWN_ERRORS;
300 FireRefreshTokensLoaded(); 302 FireRefreshTokensLoaded();
301 return; 303 return;
302 } 304 }
303 305
304 // If the account_id is an email address, then canonicalize it. This 306 if (!primary_account_id.empty()) {
305 // is to support legacy account_ids, and will not be needed after 307 // If the account_id is an email address, then canonicalize it. This
306 // switching to gaia-ids. 308 // is to support legacy account_ids, and will not be needed after
307 if (primary_account_id.find('@') != std::string::npos) { 309 // switching to gaia-ids.
308 loading_primary_account_id_ = gaia::CanonicalizeEmail(primary_account_id); 310 if (primary_account_id.find('@') != std::string::npos) {
309 } else { 311 loading_primary_account_id_ = gaia::CanonicalizeEmail(primary_account_id);
310 loading_primary_account_id_ = primary_account_id; 312 } else {
313 loading_primary_account_id_ = primary_account_id;
314 }
311 } 315 }
312 316
313 web_data_service_request_ = token_web_data->GetAllTokens(this); 317 web_data_service_request_ = token_web_data->GetAllTokens(this);
314 } 318 }
315 319
316 void MutableProfileOAuth2TokenServiceDelegate::OnWebDataServiceRequestDone( 320 void MutableProfileOAuth2TokenServiceDelegate::OnWebDataServiceRequestDone(
317 WebDataServiceBase::Handle handle, 321 WebDataServiceBase::Handle handle,
318 std::unique_ptr<WDTypedResult> result) { 322 std::unique_ptr<WDTypedResult> result) {
319 VLOG(1) << "MutablePO2TS::OnWebDataServiceRequestDone. Result type: " 323 VLOG(1) << "MutablePO2TS::OnWebDataServiceRequestDone. Result type: "
320 << (result.get() == nullptr ? -1 : (int)result->GetType()); 324 << (result.get() == nullptr ? -1 : (int)result->GetType());
(...skipping 15 matching lines...) Expand all
336 load_credentials_state_ = 340 load_credentials_state_ =
337 LoadCredentialsStateFromTokenResult(token_result->GetValue().db_result); 341 LoadCredentialsStateFromTokenResult(token_result->GetValue().db_result);
338 } else { 342 } else {
339 load_credentials_state_ = LOAD_CREDENTIALS_FINISHED_WITH_UNKNOWN_ERRORS; 343 load_credentials_state_ = LOAD_CREDENTIALS_FINISHED_WITH_UNKNOWN_ERRORS;
340 } 344 }
341 FireRefreshTokensLoaded(); 345 FireRefreshTokensLoaded();
342 346
343 // Make sure that we have an entry for |loading_primary_account_id_| in the 347 // Make sure that we have an entry for |loading_primary_account_id_| in the
344 // map. The entry could be missing if there is a corruption in the token DB 348 // map. The entry could be missing if there is a corruption in the token DB
345 // while this profile is connected to an account. 349 // while this profile is connected to an account.
346 DCHECK(!loading_primary_account_id_.empty()); 350 DCHECK(!loading_primary_account_id_.empty() ||
347 if (refresh_tokens_.count(loading_primary_account_id_) == 0) { 351 switches::IsAccountConsistencyDiceEnabled());
352 if (!loading_primary_account_id_.empty() &&
353 refresh_tokens_.count(loading_primary_account_id_) == 0) {
348 refresh_tokens_[loading_primary_account_id_].reset(new AccountStatus( 354 refresh_tokens_[loading_primary_account_id_].reset(new AccountStatus(
349 signin_error_controller_, loading_primary_account_id_, std::string())); 355 signin_error_controller_, loading_primary_account_id_, std::string()));
350 } 356 }
351 357
352 // If we don't have a refresh token for a known account, signal an error. 358 // If we don't have a refresh token for a known account, signal an error.
353 for (auto& token : refresh_tokens_) { 359 for (auto& token : refresh_tokens_) {
354 if (!RefreshTokenIsAvailable(token.first)) { 360 if (!RefreshTokenIsAvailable(token.first)) {
355 UpdateAuthError(token.first, 361 UpdateAuthError(token.first,
356 GoogleServiceAuthError( 362 GoogleServiceAuthError(
357 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 363 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 if (canon_account_id != account_id) { 427 if (canon_account_id != account_id) {
422 ClearPersistedCredentials(account_id); 428 ClearPersistedCredentials(account_id);
423 if (db_tokens.count(ApplyAccountIdPrefix(canon_account_id)) == 0) 429 if (db_tokens.count(ApplyAccountIdPrefix(canon_account_id)) == 0)
424 PersistCredentials(canon_account_id, refresh_token); 430 PersistCredentials(canon_account_id, refresh_token);
425 } 431 }
426 432
427 account_id = canon_account_id; 433 account_id = canon_account_id;
428 } 434 }
429 435
430 // Only load secondary accounts when account consistency is enabled. 436 // Only load secondary accounts when account consistency is enabled.
431 if (switches::IsAccountConsistencyMirrorEnabled() || 437 if (account_id == loading_primary_account_id_ ||
432 account_id == loading_primary_account_id_) { 438 switches::IsAccountConsistencyDiceEnabled() ||
439 switches::IsAccountConsistencyMirrorEnabled()) {
433 refresh_tokens_[account_id].reset(new AccountStatus( 440 refresh_tokens_[account_id].reset(new AccountStatus(
434 signin_error_controller_, account_id, refresh_token)); 441 signin_error_controller_, account_id, refresh_token));
435 FireRefreshTokenAvailable(account_id); 442 FireRefreshTokenAvailable(account_id);
436 } else { 443 } else {
437 RevokeCredentialsOnServer(refresh_token); 444 RevokeCredentialsOnServer(refresh_token);
438 ClearPersistedCredentials(account_id); 445 ClearPersistedCredentials(account_id);
439 FireRefreshTokenRevoked(account_id); 446 FireRefreshTokenRevoked(account_id);
440 } 447 }
441 } 448 }
442 } 449 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 net::NetworkChangeNotifier::ConnectionType type) { 578 net::NetworkChangeNotifier::ConnectionType type) {
572 // If our network has changed, reset the backoff timer so that errors caused 579 // If our network has changed, reset the backoff timer so that errors caused
573 // by a previous lack of network connectivity don't prevent new requests. 580 // by a previous lack of network connectivity don't prevent new requests.
574 backoff_entry_.Reset(); 581 backoff_entry_.Reset();
575 } 582 }
576 583
577 const net::BackoffEntry* 584 const net::BackoffEntry*
578 MutableProfileOAuth2TokenServiceDelegate::BackoffEntry() const { 585 MutableProfileOAuth2TokenServiceDelegate::BackoffEntry() const {
579 return &backoff_entry_; 586 return &backoff_entry_;
580 } 587 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698