| 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 "components/signin/ios/browser/profile_oauth2_token_service_ios.h" | 5 #include "components/signin/ios/browser/profile_oauth2_token_service_ios.h" |
| 6 | 6 |
| 7 #include <Foundation/Foundation.h> | 7 #include <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 } | 446 } |
| 447 accounts_[account_id]->SetLastAuthError(error); | 447 accounts_[account_id]->SetLastAuthError(error); |
| 448 } | 448 } |
| 449 | 449 |
| 450 // Clear the authentication error state and notify all observers that a new | 450 // Clear the authentication error state and notify all observers that a new |
| 451 // refresh token is available so that they request new access tokens. | 451 // refresh token is available so that they request new access tokens. |
| 452 void ProfileOAuth2TokenServiceIOS::AddOrUpdateAccount( | 452 void ProfileOAuth2TokenServiceIOS::AddOrUpdateAccount( |
| 453 const std::string& account_id) { | 453 const std::string& account_id) { |
| 454 DCHECK(thread_checker_.CalledOnValidThread()); | 454 DCHECK(thread_checker_.CalledOnValidThread()); |
| 455 DCHECK(!account_id.empty()); | 455 DCHECK(!account_id.empty()); |
| 456 DCHECK(!use_legacy_token_service_); |
| 456 | 457 |
| 457 bool account_present = accounts_.count(account_id) > 0; | 458 bool account_present = accounts_.count(account_id) > 0; |
| 458 if (account_present && accounts_[account_id]->GetAuthStatus().state() == | 459 if (account_present && accounts_[account_id]->GetAuthStatus().state() == |
| 459 GoogleServiceAuthError::NONE) { | 460 GoogleServiceAuthError::NONE) { |
| 460 // No need to update the account if it is already a known account and if | 461 // No need to update the account if it is already a known account and if |
| 461 // there is no auth error. | 462 // there is no auth error. |
| 462 return; | 463 return; |
| 463 } | 464 } |
| 464 | 465 |
| 465 if (account_present) { | 466 if (account_present) { |
| 466 CancelRequestsForAccount(account_id); | 467 CancelRequestsForAccount(account_id); |
| 467 ClearCacheForAccount(account_id); | 468 ClearCacheForAccount(account_id); |
| 468 } else { | 469 } else { |
| 469 accounts_[account_id].reset(new AccountInfo(this, account_id)); | 470 accounts_[account_id].reset(new AccountInfo(this, account_id)); |
| 470 } | 471 } |
| 471 UpdateAuthError(account_id, GoogleServiceAuthError::AuthErrorNone()); | 472 UpdateAuthError(account_id, GoogleServiceAuthError::AuthErrorNone()); |
| 472 FireRefreshTokenAvailable(account_id); | 473 FireRefreshTokenAvailable(account_id); |
| 473 } | 474 } |
| 474 | 475 |
| 475 void ProfileOAuth2TokenServiceIOS::RemoveAccount( | 476 void ProfileOAuth2TokenServiceIOS::RemoveAccount( |
| 476 const std::string& account_id) { | 477 const std::string& account_id) { |
| 477 DCHECK(thread_checker_.CalledOnValidThread()); | 478 DCHECK(thread_checker_.CalledOnValidThread()); |
| 478 DCHECK(!account_id.empty()); | 479 DCHECK(!account_id.empty()); |
| 480 DCHECK(!use_legacy_token_service_); |
| 479 | 481 |
| 480 if (accounts_.count(account_id) > 0) { | 482 if (accounts_.count(account_id) > 0) { |
| 481 CancelRequestsForAccount(account_id); | 483 CancelRequestsForAccount(account_id); |
| 482 ClearCacheForAccount(account_id); | 484 ClearCacheForAccount(account_id); |
| 483 accounts_.erase(account_id); | 485 accounts_.erase(account_id); |
| 484 FireRefreshTokenRevoked(account_id); | 486 FireRefreshTokenRevoked(account_id); |
| 485 } | 487 } |
| 486 } | 488 } |
| 487 | 489 |
| 488 void ProfileOAuth2TokenServiceIOS::StartUsingSharedAuthentication() { | 490 void ProfileOAuth2TokenServiceIOS::StartUsingSharedAuthentication() { |
| 489 if (!use_legacy_token_service_) | 491 if (!use_legacy_token_service_) |
| 490 return; | 492 return; |
| 491 MutableProfileOAuth2TokenService::RevokeAllCredentials(); | 493 MutableProfileOAuth2TokenService::RevokeAllCredentials(); |
| 492 use_legacy_token_service_ = false; | 494 use_legacy_token_service_ = false; |
| 493 } | 495 } |
| 494 | 496 |
| 495 void ProfileOAuth2TokenServiceIOS::SetUseLegacyTokenServiceForTesting( | 497 void ProfileOAuth2TokenServiceIOS::SetUseLegacyTokenServiceForTesting( |
| 496 bool use_legacy_token_service) { | 498 bool use_legacy_token_service) { |
| 497 use_legacy_token_service_ = use_legacy_token_service; | 499 use_legacy_token_service_ = use_legacy_token_service; |
| 498 } | 500 } |
| OLD | NEW |