OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "google_apis/gaia/oauth2_token_service.h" | 5 #include "google_apis/gaia/oauth2_token_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
18 #include "google_apis/gaia/gaia_urls.h" | 18 #include "google_apis/gaia/gaia_urls.h" |
19 #include "google_apis/gaia/google_service_auth_error.h" | 19 #include "google_apis/gaia/google_service_auth_error.h" |
20 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" | 20 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" |
| 21 #include "google_apis/gaia/oauth2_token_service_delegate.h" |
21 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
22 | 23 |
23 int OAuth2TokenService::max_fetch_retry_num_ = 5; | 24 int OAuth2TokenService::max_fetch_retry_num_ = 5; |
24 | 25 |
25 OAuth2TokenService::RequestParameters::RequestParameters( | 26 OAuth2TokenService::RequestParameters::RequestParameters( |
26 const std::string& client_id, | 27 const std::string& client_id, |
27 const std::string& account_id, | 28 const std::string& account_id, |
28 const ScopeSet& scopes) | 29 const ScopeSet& scopes) |
29 : client_id(client_id), | 30 : client_id(client_id), |
30 account_id(account_id), | 31 account_id(account_id), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 const GoogleServiceAuthError& error, | 73 const GoogleServiceAuthError& error, |
73 const std::string& access_token, | 74 const std::string& access_token, |
74 const base::Time& expiration_date) { | 75 const base::Time& expiration_date) { |
75 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
76 if (error.state() == GoogleServiceAuthError::NONE) | 77 if (error.state() == GoogleServiceAuthError::NONE) |
77 consumer_->OnGetTokenSuccess(this, access_token, expiration_date); | 78 consumer_->OnGetTokenSuccess(this, access_token, expiration_date); |
78 else | 79 else |
79 consumer_->OnGetTokenFailure(this, error); | 80 consumer_->OnGetTokenFailure(this, error); |
80 } | 81 } |
81 | 82 |
82 OAuth2TokenService::ScopedBatchChange::ScopedBatchChange( | |
83 OAuth2TokenService* token_service) : token_service_(token_service) { | |
84 DCHECK(token_service_); | |
85 token_service_->StartBatchChanges(); | |
86 } | |
87 | |
88 OAuth2TokenService::ScopedBatchChange::~ScopedBatchChange() { | |
89 token_service_->EndBatchChanges(); | |
90 } | |
91 | |
92 // Class that fetches an OAuth2 access token for a given account id and set of | 83 // Class that fetches an OAuth2 access token for a given account id and set of |
93 // scopes. | 84 // scopes. |
94 // | 85 // |
95 // It aims to meet OAuth2TokenService's requirements on token fetching. Retry | 86 // It aims to meet OAuth2TokenService's requirements on token fetching. Retry |
96 // mechanism is used to handle failures. | 87 // mechanism is used to handle failures. |
97 // | 88 // |
98 // To use this class, call CreateAndStart() to create and start a Fetcher. | 89 // To use this class, call CreateAndStart() to create and start a Fetcher. |
99 // | 90 // |
100 // The Fetcher will call back the service by calling | 91 // The Fetcher will call back the service by calling |
101 // OAuth2TokenService::OnFetchComplete() when it completes fetching, if it is | 92 // OAuth2TokenService::OnFetchComplete() when it completes fetching, if it is |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 376 |
386 OAuth2TokenService::Request::~Request() { | 377 OAuth2TokenService::Request::~Request() { |
387 } | 378 } |
388 | 379 |
389 OAuth2TokenService::Consumer::Consumer(const std::string& id) | 380 OAuth2TokenService::Consumer::Consumer(const std::string& id) |
390 : id_(id) {} | 381 : id_(id) {} |
391 | 382 |
392 OAuth2TokenService::Consumer::~Consumer() { | 383 OAuth2TokenService::Consumer::~Consumer() { |
393 } | 384 } |
394 | 385 |
395 OAuth2TokenService::OAuth2TokenService() : batch_change_depth_(0) { | 386 OAuth2TokenService::OAuth2TokenService(OAuth2TokenServiceDelegate* delegate) |
| 387 : delegate_(delegate) { |
| 388 DCHECK(delegate_); |
396 } | 389 } |
397 | 390 |
398 OAuth2TokenService::~OAuth2TokenService() { | 391 OAuth2TokenService::~OAuth2TokenService() { |
399 // Release all the pending fetchers. | 392 // Release all the pending fetchers. |
400 STLDeleteContainerPairSecondPointers( | 393 STLDeleteContainerPairSecondPointers( |
401 pending_fetchers_.begin(), pending_fetchers_.end()); | 394 pending_fetchers_.begin(), pending_fetchers_.end()); |
402 } | 395 } |
403 | 396 |
| 397 OAuth2TokenServiceDelegate* OAuth2TokenService::GetDelegate() { |
| 398 return delegate_.get(); |
| 399 } |
| 400 |
404 void OAuth2TokenService::AddObserver(Observer* observer) { | 401 void OAuth2TokenService::AddObserver(Observer* observer) { |
405 observer_list_.AddObserver(observer); | 402 delegate_->AddObserver(observer); |
406 } | 403 } |
407 | 404 |
408 void OAuth2TokenService::RemoveObserver(Observer* observer) { | 405 void OAuth2TokenService::RemoveObserver(Observer* observer) { |
409 observer_list_.RemoveObserver(observer); | 406 delegate_->RemoveObserver(observer); |
410 } | 407 } |
411 | 408 |
412 void OAuth2TokenService::AddDiagnosticsObserver(DiagnosticsObserver* observer) { | 409 void OAuth2TokenService::AddDiagnosticsObserver(DiagnosticsObserver* observer) { |
413 diagnostics_observer_list_.AddObserver(observer); | 410 diagnostics_observer_list_.AddObserver(observer); |
414 } | 411 } |
415 | 412 |
416 void OAuth2TokenService::RemoveDiagnosticsObserver( | 413 void OAuth2TokenService::RemoveDiagnosticsObserver( |
417 DiagnosticsObserver* observer) { | 414 DiagnosticsObserver* observer) { |
418 diagnostics_observer_list_.RemoveObserver(observer); | 415 diagnostics_observer_list_.RemoveObserver(observer); |
419 } | 416 } |
420 | 417 |
421 std::vector<std::string> OAuth2TokenService::GetAccounts() { | |
422 return std::vector<std::string>(); | |
423 } | |
424 | |
425 scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( | 418 scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( |
426 const std::string& account_id, | 419 const std::string& account_id, |
427 const OAuth2TokenService::ScopeSet& scopes, | 420 const OAuth2TokenService::ScopeSet& scopes, |
428 OAuth2TokenService::Consumer* consumer) { | 421 OAuth2TokenService::Consumer* consumer) { |
429 return StartRequestForClientWithContext( | 422 return StartRequestForClientWithContext( |
430 account_id, | 423 account_id, |
431 GetRequestContext(), | 424 GetRequestContext(), |
432 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 425 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
433 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), | 426 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), |
434 scopes, | 427 scopes, |
435 consumer); | 428 consumer); |
436 } | 429 } |
437 | 430 |
438 scoped_ptr<OAuth2TokenService::Request> | 431 scoped_ptr<OAuth2TokenService::Request> |
439 OAuth2TokenService::StartRequestForClient( | 432 OAuth2TokenService::StartRequestForClient( |
440 const std::string& account_id, | 433 const std::string& account_id, |
441 const std::string& client_id, | 434 const std::string& client_id, |
442 const std::string& client_secret, | 435 const std::string& client_secret, |
443 const OAuth2TokenService::ScopeSet& scopes, | 436 const OAuth2TokenService::ScopeSet& scopes, |
444 OAuth2TokenService::Consumer* consumer) { | 437 OAuth2TokenService::Consumer* consumer) { |
445 return StartRequestForClientWithContext( | 438 return StartRequestForClientWithContext( |
446 account_id, | 439 account_id, |
447 GetRequestContext(), | 440 GetRequestContext(), |
448 client_id, | 441 client_id, |
449 client_secret, | 442 client_secret, |
450 scopes, | 443 scopes, |
451 consumer); | 444 consumer); |
452 } | 445 } |
453 | 446 |
| 447 net::URLRequestContextGetter* OAuth2TokenService::GetRequestContext() const { |
| 448 return delegate_->GetRequestContext(); |
| 449 } |
| 450 |
454 scoped_ptr<OAuth2TokenService::Request> | 451 scoped_ptr<OAuth2TokenService::Request> |
455 OAuth2TokenService::StartRequestWithContext( | 452 OAuth2TokenService::StartRequestWithContext( |
456 const std::string& account_id, | 453 const std::string& account_id, |
457 net::URLRequestContextGetter* getter, | 454 net::URLRequestContextGetter* getter, |
458 const ScopeSet& scopes, | 455 const ScopeSet& scopes, |
459 Consumer* consumer) { | 456 Consumer* consumer) { |
460 return StartRequestForClientWithContext( | 457 return StartRequestForClientWithContext( |
461 account_id, | 458 account_id, |
462 getter, | 459 getter, |
463 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 460 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
(...skipping 10 matching lines...) Expand all Loading... |
474 const std::string& client_secret, | 471 const std::string& client_secret, |
475 const ScopeSet& scopes, | 472 const ScopeSet& scopes, |
476 Consumer* consumer) { | 473 Consumer* consumer) { |
477 DCHECK(CalledOnValidThread()); | 474 DCHECK(CalledOnValidThread()); |
478 | 475 |
479 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 476 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
480 // fixed. | 477 // fixed. |
481 tracked_objects::ScopedTracker tracking_profile1( | 478 tracked_objects::ScopedTracker tracking_profile1( |
482 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 479 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
483 "422460 OAuth2TokenService::StartRequestForClientWithContext 1")); | 480 "422460 OAuth2TokenService::StartRequestForClientWithContext 1")); |
484 | |
485 scoped_ptr<RequestImpl> request(new RequestImpl(account_id, consumer)); | 481 scoped_ptr<RequestImpl> request(new RequestImpl(account_id, consumer)); |
486 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, | 482 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, |
487 OnAccessTokenRequested(account_id, | 483 OnAccessTokenRequested(account_id, |
488 consumer->id(), | 484 consumer->id(), |
489 scopes)); | 485 scopes)); |
490 | 486 |
491 if (!RefreshTokenIsAvailable(account_id)) { | 487 if (!RefreshTokenIsAvailable(account_id)) { |
492 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 | 488 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
493 // is fixed. | 489 // is fixed. |
494 tracked_objects::ScopedTracker tracking_profile2( | 490 tracked_objects::ScopedTracker tracking_profile2( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 pending_fetchers_[request_parameters] = | 557 pending_fetchers_[request_parameters] = |
562 Fetcher::CreateAndStart(this, | 558 Fetcher::CreateAndStart(this, |
563 account_id, | 559 account_id, |
564 getter, | 560 getter, |
565 client_id, | 561 client_id, |
566 client_secret, | 562 client_secret, |
567 scopes, | 563 scopes, |
568 request->AsWeakPtr()); | 564 request->AsWeakPtr()); |
569 } | 565 } |
570 | 566 |
| 567 OAuth2AccessTokenFetcher* OAuth2TokenService::CreateAccessTokenFetcher( |
| 568 const std::string& account_id, |
| 569 net::URLRequestContextGetter* getter, |
| 570 OAuth2AccessTokenConsumer* consumer) { |
| 571 return delegate_->CreateAccessTokenFetcher(account_id, getter, consumer); |
| 572 } |
| 573 |
571 void OAuth2TokenService::StartCacheLookupRequest( | 574 void OAuth2TokenService::StartCacheLookupRequest( |
572 RequestImpl* request, | 575 RequestImpl* request, |
573 const OAuth2TokenService::RequestParameters& request_parameters, | 576 const OAuth2TokenService::RequestParameters& request_parameters, |
574 OAuth2TokenService::Consumer* consumer) { | 577 OAuth2TokenService::Consumer* consumer) { |
575 CHECK(HasCacheEntry(request_parameters)); | 578 CHECK(HasCacheEntry(request_parameters)); |
576 const CacheEntry* cache_entry = GetCacheEntry(request_parameters); | 579 const CacheEntry* cache_entry = GetCacheEntry(request_parameters); |
577 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, | 580 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, |
578 OnFetchAccessTokenComplete( | 581 OnFetchAccessTokenComplete( |
579 request_parameters.account_id, | 582 request_parameters.account_id, |
580 consumer->id(), | 583 consumer->id(), |
581 request_parameters.scopes, | 584 request_parameters.scopes, |
582 GoogleServiceAuthError::AuthErrorNone(), | 585 GoogleServiceAuthError::AuthErrorNone(), |
583 cache_entry->expiration_date)); | 586 cache_entry->expiration_date)); |
584 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 587 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
585 &RequestImpl::InformConsumer, | 588 &RequestImpl::InformConsumer, |
586 request->AsWeakPtr(), | 589 request->AsWeakPtr(), |
587 GoogleServiceAuthError(GoogleServiceAuthError::NONE), | 590 GoogleServiceAuthError(GoogleServiceAuthError::NONE), |
588 cache_entry->access_token, | 591 cache_entry->access_token, |
589 cache_entry->expiration_date)); | 592 cache_entry->expiration_date)); |
590 } | 593 } |
591 | 594 |
592 void OAuth2TokenService::InvalidateToken(const std::string& account_id, | 595 std::vector<std::string> OAuth2TokenService::GetAccounts() const { |
593 const ScopeSet& scopes, | 596 return delegate_->GetAccounts(); |
594 const std::string& access_token) { | |
595 InvalidateOAuth2Token(account_id, | |
596 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | |
597 scopes, | |
598 access_token); | |
599 } | 597 } |
600 | 598 |
601 void OAuth2TokenService::InvalidateTokenForClient( | 599 bool OAuth2TokenService::RefreshTokenIsAvailable( |
| 600 const std::string& account_id) const { |
| 601 return delegate_->RefreshTokenIsAvailable(account_id); |
| 602 } |
| 603 |
| 604 void OAuth2TokenService::RevokeAllCredentials() { |
| 605 CancelAllRequests(); |
| 606 ClearCache(); |
| 607 delegate_->RevokeAllCredentials(); |
| 608 } |
| 609 |
| 610 void OAuth2TokenService::InvalidateAccessToken( |
| 611 const std::string& account_id, |
| 612 const ScopeSet& scopes, |
| 613 const std::string& access_token) { |
| 614 InvalidateAccessTokenImpl(account_id, |
| 615 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
| 616 scopes, access_token); |
| 617 } |
| 618 |
| 619 void OAuth2TokenService::InvalidateAccessTokenForClient( |
602 const std::string& account_id, | 620 const std::string& account_id, |
603 const std::string& client_id, | 621 const std::string& client_id, |
604 const ScopeSet& scopes, | 622 const ScopeSet& scopes, |
605 const std::string& access_token) { | 623 const std::string& access_token) { |
606 InvalidateOAuth2Token(account_id, client_id, scopes, access_token); | 624 InvalidateAccessTokenImpl(account_id, client_id, scopes, access_token); |
607 } | 625 } |
608 | 626 |
609 void OAuth2TokenService::InvalidateOAuth2Token( | 627 void OAuth2TokenService::InvalidateAccessTokenImpl( |
610 const std::string& account_id, | 628 const std::string& account_id, |
611 const std::string& client_id, | 629 const std::string& client_id, |
612 const ScopeSet& scopes, | 630 const ScopeSet& scopes, |
613 const std::string& access_token) { | 631 const std::string& access_token) { |
614 DCHECK(CalledOnValidThread()); | 632 DCHECK(CalledOnValidThread()); |
615 RemoveCacheEntry( | 633 RemoveCacheEntry( |
616 RequestParameters(client_id, | 634 RequestParameters(client_id, |
617 account_id, | 635 account_id, |
618 scopes), | 636 scopes), |
619 access_token); | 637 access_token); |
| 638 delegate_->InvalidateAccessToken(account_id, client_id, scopes, access_token); |
620 } | 639 } |
621 | 640 |
622 void OAuth2TokenService::OnFetchComplete(Fetcher* fetcher) { | 641 void OAuth2TokenService::OnFetchComplete(Fetcher* fetcher) { |
623 DCHECK(CalledOnValidThread()); | 642 DCHECK(CalledOnValidThread()); |
624 | 643 |
625 // Update the auth error state so auth errors are appropriately communicated | 644 // Update the auth error state so auth errors are appropriately communicated |
626 // to the user. | 645 // to the user. |
627 UpdateAuthError(fetcher->GetAccountId(), fetcher->error()); | 646 UpdateAuthError(fetcher->GetAccountId(), fetcher->error()); |
628 | 647 |
629 // Note |fetcher| is recorded in |pending_fetcher_| mapped to its refresh | 648 // Note |fetcher| is recorded in |pending_fetcher_| mapped to its refresh |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 if (token_iterator != token_cache_.end() && | 723 if (token_iterator != token_cache_.end() && |
705 token_iterator->second.access_token == token_to_remove) { | 724 token_iterator->second.access_token == token_to_remove) { |
706 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, | 725 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, |
707 OnTokenRemoved(request_parameters.account_id, | 726 OnTokenRemoved(request_parameters.account_id, |
708 request_parameters.scopes)); | 727 request_parameters.scopes)); |
709 token_cache_.erase(token_iterator); | 728 token_cache_.erase(token_iterator); |
710 return true; | 729 return true; |
711 } | 730 } |
712 return false; | 731 return false; |
713 } | 732 } |
| 733 void OAuth2TokenService::UpdateAuthError(const std::string& account_id, |
| 734 const GoogleServiceAuthError& error) { |
| 735 delegate_->UpdateAuthError(account_id, error); |
| 736 } |
714 | 737 |
715 void OAuth2TokenService::RegisterCacheEntry( | 738 void OAuth2TokenService::RegisterCacheEntry( |
716 const std::string& client_id, | 739 const std::string& client_id, |
717 const std::string& account_id, | 740 const std::string& account_id, |
718 const OAuth2TokenService::ScopeSet& scopes, | 741 const OAuth2TokenService::ScopeSet& scopes, |
719 const std::string& access_token, | 742 const std::string& access_token, |
720 const base::Time& expiration_date) { | 743 const base::Time& expiration_date) { |
721 DCHECK(CalledOnValidThread()); | 744 DCHECK(CalledOnValidThread()); |
722 | 745 |
723 CacheEntry& token = token_cache_[RequestParameters(client_id, | 746 CacheEntry& token = token_cache_[RequestParameters(client_id, |
724 account_id, | 747 account_id, |
725 scopes)]; | 748 scopes)]; |
726 token.access_token = access_token; | 749 token.access_token = access_token; |
727 token.expiration_date = expiration_date; | 750 token.expiration_date = expiration_date; |
728 } | 751 } |
729 | 752 |
730 void OAuth2TokenService::UpdateAuthError( | |
731 const std::string& account_id, | |
732 const GoogleServiceAuthError& error) { | |
733 // Default implementation does nothing. | |
734 } | |
735 | |
736 void OAuth2TokenService::ClearCache() { | 753 void OAuth2TokenService::ClearCache() { |
737 DCHECK(CalledOnValidThread()); | 754 DCHECK(CalledOnValidThread()); |
738 for (TokenCache::iterator iter = token_cache_.begin(); | 755 for (TokenCache::iterator iter = token_cache_.begin(); |
739 iter != token_cache_.end(); ++iter) { | 756 iter != token_cache_.end(); ++iter) { |
740 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, | 757 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, |
741 OnTokenRemoved(iter->first.account_id, | 758 OnTokenRemoved(iter->first.account_id, |
742 iter->first.scopes)); | 759 iter->first.scopes)); |
743 } | 760 } |
744 | 761 |
745 token_cache_.clear(); | 762 token_cache_.clear(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 void OAuth2TokenService::CancelFetchers( | 804 void OAuth2TokenService::CancelFetchers( |
788 std::vector<Fetcher*> fetchers_to_cancel) { | 805 std::vector<Fetcher*> fetchers_to_cancel) { |
789 for (std::vector<OAuth2TokenService::Fetcher*>::iterator iter = | 806 for (std::vector<OAuth2TokenService::Fetcher*>::iterator iter = |
790 fetchers_to_cancel.begin(); | 807 fetchers_to_cancel.begin(); |
791 iter != fetchers_to_cancel.end(); | 808 iter != fetchers_to_cancel.end(); |
792 ++iter) { | 809 ++iter) { |
793 (*iter)->Cancel(); | 810 (*iter)->Cancel(); |
794 } | 811 } |
795 } | 812 } |
796 | 813 |
797 void OAuth2TokenService::FireRefreshTokenAvailable( | |
798 const std::string& account_id) { | |
799 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | |
800 // fixed. | |
801 tracked_objects::ScopedTracker tracking_profile( | |
802 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
803 "422460 OAuth2TokenService::FireRefreshTokenAvailable")); | |
804 | |
805 FOR_EACH_OBSERVER(Observer, observer_list_, | |
806 OnRefreshTokenAvailable(account_id)); | |
807 } | |
808 | |
809 void OAuth2TokenService::FireRefreshTokenRevoked( | |
810 const std::string& account_id) { | |
811 FOR_EACH_OBSERVER(Observer, observer_list_, | |
812 OnRefreshTokenRevoked(account_id)); | |
813 } | |
814 | |
815 void OAuth2TokenService::FireRefreshTokensLoaded() { | |
816 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | |
817 // fixed. | |
818 tracked_objects::ScopedTracker tracking_profile( | |
819 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
820 "422460 OAuth2TokenService::FireRefreshTokensLoaded")); | |
821 | |
822 FOR_EACH_OBSERVER(Observer, observer_list_, OnRefreshTokensLoaded()); | |
823 } | |
824 | |
825 void OAuth2TokenService::StartBatchChanges() { | |
826 ++batch_change_depth_; | |
827 if (batch_change_depth_ == 1) | |
828 FOR_EACH_OBSERVER(Observer, observer_list_, OnStartBatchChanges()); | |
829 } | |
830 | |
831 void OAuth2TokenService::EndBatchChanges() { | |
832 --batch_change_depth_; | |
833 DCHECK_LE(0, batch_change_depth_); | |
834 if (batch_change_depth_ == 0) | |
835 FOR_EACH_OBSERVER(Observer, observer_list_, OnEndBatchChanges()); | |
836 } | |
837 | |
838 int OAuth2TokenService::cache_size_for_testing() const { | |
839 return token_cache_.size(); | |
840 } | |
841 | |
842 void OAuth2TokenService::set_max_authorization_token_fetch_retries_for_testing( | 814 void OAuth2TokenService::set_max_authorization_token_fetch_retries_for_testing( |
843 int max_retries) { | 815 int max_retries) { |
844 DCHECK(CalledOnValidThread()); | 816 DCHECK(CalledOnValidThread()); |
845 max_fetch_retry_num_ = max_retries; | 817 max_fetch_retry_num_ = max_retries; |
846 } | 818 } |
847 | 819 |
848 size_t OAuth2TokenService::GetNumPendingRequestsForTesting( | 820 size_t OAuth2TokenService::GetNumPendingRequestsForTesting( |
849 const std::string& client_id, | 821 const std::string& client_id, |
850 const std::string& account_id, | 822 const std::string& account_id, |
851 const ScopeSet& scopes) const { | 823 const ScopeSet& scopes) const { |
852 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( | 824 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( |
853 OAuth2TokenService::RequestParameters( | 825 OAuth2TokenService::RequestParameters( |
854 client_id, | 826 client_id, |
855 account_id, | 827 account_id, |
856 scopes)); | 828 scopes)); |
857 return iter == pending_fetchers_.end() ? | 829 return iter == pending_fetchers_.end() ? |
858 0 : iter->second->GetWaitingRequestCount(); | 830 0 : iter->second->GetWaitingRequestCount(); |
859 } | 831 } |
OLD | NEW |