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

Side by Side Diff: google_apis/gaia/oauth2_token_service.cc

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

Powered by Google App Engine
This is Rietveld 408576698