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

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

Issue 2422843003: Remove usage of FOR_EACH_OBSERVER macro in google_apis (Closed)
Patch Set: Created 4 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 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 <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 const ScopeSet& scopes, 476 const ScopeSet& scopes,
477 Consumer* consumer) { 477 Consumer* consumer) {
478 DCHECK(CalledOnValidThread()); 478 DCHECK(CalledOnValidThread());
479 479
480 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 480 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
481 // fixed. 481 // fixed.
482 tracked_objects::ScopedTracker tracking_profile1( 482 tracked_objects::ScopedTracker tracking_profile1(
483 FROM_HERE_WITH_EXPLICIT_FUNCTION( 483 FROM_HERE_WITH_EXPLICIT_FUNCTION(
484 "422460 OAuth2TokenService::StartRequestForClientWithContext 1")); 484 "422460 OAuth2TokenService::StartRequestForClientWithContext 1"));
485 std::unique_ptr<RequestImpl> request(new RequestImpl(account_id, consumer)); 485 std::unique_ptr<RequestImpl> request(new RequestImpl(account_id, consumer));
486 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, 486 for (auto& observer : diagnostics_observer_list_)
487 OnAccessTokenRequested(account_id, 487 observer.OnAccessTokenRequested(account_id, consumer->id(), scopes);
488 consumer->id(),
489 scopes));
490 488
491 if (!RefreshTokenIsAvailable(account_id)) { 489 if (!RefreshTokenIsAvailable(account_id)) {
492 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 490 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460
493 // is fixed. 491 // is fixed.
494 tracked_objects::ScopedTracker tracking_profile2( 492 tracked_objects::ScopedTracker tracking_profile2(
495 FROM_HERE_WITH_EXPLICIT_FUNCTION( 493 FROM_HERE_WITH_EXPLICIT_FUNCTION(
496 "422460 OAuth2TokenService::StartRequestForClientWithContext 2")); 494 "422460 OAuth2TokenService::StartRequestForClientWithContext 2"));
497 495
498 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 496 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
499 497
500 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, 498 for (auto& observer : diagnostics_observer_list_) {
501 OnFetchAccessTokenComplete( 499 observer.OnFetchAccessTokenComplete(account_id, consumer->id(), scopes,
502 account_id, consumer->id(), scopes, error, 500 error, base::Time());
503 base::Time())); 501 }
504 502
505 base::ThreadTaskRunnerHandle::Get()->PostTask( 503 base::ThreadTaskRunnerHandle::Get()->PostTask(
506 FROM_HERE, 504 FROM_HERE,
507 base::Bind(&RequestImpl::InformConsumer, request->AsWeakPtr(), error, 505 base::Bind(&RequestImpl::InformConsumer, request->AsWeakPtr(), error,
508 std::string(), base::Time())); 506 std::string(), base::Time()));
509 return std::move(request); 507 return std::move(request);
510 } 508 }
511 509
512 RequestParameters request_parameters(client_id, 510 RequestParameters request_parameters(client_id,
513 account_id, 511 account_id,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 OAuth2AccessTokenConsumer* consumer) { 569 OAuth2AccessTokenConsumer* consumer) {
572 return delegate_->CreateAccessTokenFetcher(account_id, getter, consumer); 570 return delegate_->CreateAccessTokenFetcher(account_id, getter, consumer);
573 } 571 }
574 572
575 void OAuth2TokenService::StartCacheLookupRequest( 573 void OAuth2TokenService::StartCacheLookupRequest(
576 RequestImpl* request, 574 RequestImpl* request,
577 const OAuth2TokenService::RequestParameters& request_parameters, 575 const OAuth2TokenService::RequestParameters& request_parameters,
578 OAuth2TokenService::Consumer* consumer) { 576 OAuth2TokenService::Consumer* consumer) {
579 CHECK(HasCacheEntry(request_parameters)); 577 CHECK(HasCacheEntry(request_parameters));
580 const CacheEntry* cache_entry = GetCacheEntry(request_parameters); 578 const CacheEntry* cache_entry = GetCacheEntry(request_parameters);
581 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, 579 for (auto& observer : diagnostics_observer_list_) {
582 OnFetchAccessTokenComplete( 580 observer.OnFetchAccessTokenComplete(
583 request_parameters.account_id, 581 request_parameters.account_id, consumer->id(),
584 consumer->id(), 582 request_parameters.scopes, GoogleServiceAuthError::AuthErrorNone(),
585 request_parameters.scopes, 583 cache_entry->expiration_date);
586 GoogleServiceAuthError::AuthErrorNone(), 584 }
587 cache_entry->expiration_date));
588 base::ThreadTaskRunnerHandle::Get()->PostTask( 585 base::ThreadTaskRunnerHandle::Get()->PostTask(
589 FROM_HERE, 586 FROM_HERE,
590 base::Bind(&RequestImpl::InformConsumer, request->AsWeakPtr(), 587 base::Bind(&RequestImpl::InformConsumer, request->AsWeakPtr(),
591 GoogleServiceAuthError(GoogleServiceAuthError::NONE), 588 GoogleServiceAuthError(GoogleServiceAuthError::NONE),
592 cache_entry->access_token, cache_entry->expiration_date)); 589 cache_entry->access_token, cache_entry->expiration_date));
593 } 590 }
594 591
595 std::vector<std::string> OAuth2TokenService::GetAccounts() const { 592 std::vector<std::string> OAuth2TokenService::GetAccounts() const {
596 return delegate_->GetAccounts(); 593 return delegate_->GetAccounts();
597 } 594 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 RequestParameters request_param(fetcher->GetClientId(), 671 RequestParameters request_param(fetcher->GetClientId(),
675 fetcher->GetAccountId(), 672 fetcher->GetAccountId(),
676 fetcher->GetScopeSet()); 673 fetcher->GetScopeSet());
677 674
678 const OAuth2TokenService::CacheEntry* entry = GetCacheEntry(request_param); 675 const OAuth2TokenService::CacheEntry* entry = GetCacheEntry(request_param);
679 const std::vector<base::WeakPtr<RequestImpl> >& requests = 676 const std::vector<base::WeakPtr<RequestImpl> >& requests =
680 fetcher->waiting_requests(); 677 fetcher->waiting_requests();
681 for (size_t i = 0; i < requests.size(); ++i) { 678 for (size_t i = 0; i < requests.size(); ++i) {
682 const RequestImpl* req = requests[i].get(); 679 const RequestImpl* req = requests[i].get();
683 if (req) { 680 if (req) {
684 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, 681 for (auto& observer : diagnostics_observer_list_) {
685 OnFetchAccessTokenComplete( 682 observer.OnFetchAccessTokenComplete(
686 req->GetAccountId(), req->GetConsumerId(), 683 req->GetAccountId(), req->GetConsumerId(), fetcher->GetScopeSet(),
687 fetcher->GetScopeSet(), fetcher->error(), 684 fetcher->error(), entry ? entry->expiration_date : base::Time());
688 entry ? entry->expiration_date : base::Time())); 685 }
689 } 686 }
690 } 687 }
691 688
692 auto iter = pending_fetchers_.find(request_param); 689 auto iter = pending_fetchers_.find(request_param);
693 DCHECK(iter != pending_fetchers_.end()); 690 DCHECK(iter != pending_fetchers_.end());
694 DCHECK_EQ(fetcher, iter->second.get()); 691 DCHECK_EQ(fetcher, iter->second.get());
695 692
696 // The Fetcher deletes itself. 693 // The Fetcher deletes itself.
697 iter->second.release(); 694 iter->second.release();
698 pending_fetchers_.erase(iter); 695 pending_fetchers_.erase(iter);
(...skipping 18 matching lines...) Expand all
717 return &token_iterator->second; 714 return &token_iterator->second;
718 } 715 }
719 716
720 bool OAuth2TokenService::RemoveCacheEntry( 717 bool OAuth2TokenService::RemoveCacheEntry(
721 const RequestParameters& request_parameters, 718 const RequestParameters& request_parameters,
722 const std::string& token_to_remove) { 719 const std::string& token_to_remove) {
723 DCHECK(CalledOnValidThread()); 720 DCHECK(CalledOnValidThread());
724 TokenCache::iterator token_iterator = token_cache_.find(request_parameters); 721 TokenCache::iterator token_iterator = token_cache_.find(request_parameters);
725 if (token_iterator != token_cache_.end() && 722 if (token_iterator != token_cache_.end() &&
726 token_iterator->second.access_token == token_to_remove) { 723 token_iterator->second.access_token == token_to_remove) {
727 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, 724 for (auto& observer : diagnostics_observer_list_) {
728 OnTokenRemoved(request_parameters.account_id, 725 observer.OnTokenRemoved(request_parameters.account_id,
729 request_parameters.scopes)); 726 request_parameters.scopes);
727 }
730 token_cache_.erase(token_iterator); 728 token_cache_.erase(token_iterator);
731 return true; 729 return true;
732 } 730 }
733 return false; 731 return false;
734 } 732 }
735 void OAuth2TokenService::UpdateAuthError(const std::string& account_id, 733 void OAuth2TokenService::UpdateAuthError(const std::string& account_id,
736 const GoogleServiceAuthError& error) { 734 const GoogleServiceAuthError& error) {
737 delegate_->UpdateAuthError(account_id, error); 735 delegate_->UpdateAuthError(account_id, error);
738 } 736 }
739 737
740 void OAuth2TokenService::RegisterCacheEntry( 738 void OAuth2TokenService::RegisterCacheEntry(
741 const std::string& client_id, 739 const std::string& client_id,
742 const std::string& account_id, 740 const std::string& account_id,
743 const OAuth2TokenService::ScopeSet& scopes, 741 const OAuth2TokenService::ScopeSet& scopes,
744 const std::string& access_token, 742 const std::string& access_token,
745 const base::Time& expiration_date) { 743 const base::Time& expiration_date) {
746 DCHECK(CalledOnValidThread()); 744 DCHECK(CalledOnValidThread());
747 745
748 CacheEntry& token = token_cache_[RequestParameters(client_id, 746 CacheEntry& token = token_cache_[RequestParameters(client_id,
749 account_id, 747 account_id,
750 scopes)]; 748 scopes)];
751 token.access_token = access_token; 749 token.access_token = access_token;
752 token.expiration_date = expiration_date; 750 token.expiration_date = expiration_date;
753 } 751 }
754 752
755 void OAuth2TokenService::ClearCache() { 753 void OAuth2TokenService::ClearCache() {
756 DCHECK(CalledOnValidThread()); 754 DCHECK(CalledOnValidThread());
757 for (TokenCache::iterator iter = token_cache_.begin(); 755 for (TokenCache::iterator iter = token_cache_.begin();
758 iter != token_cache_.end(); ++iter) { 756 iter != token_cache_.end(); ++iter) {
759 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, 757 for (auto& observer : diagnostics_observer_list_)
760 OnTokenRemoved(iter->first.account_id, 758 observer.OnTokenRemoved(iter->first.account_id, iter->first.scopes);
761 iter->first.scopes));
762 } 759 }
763 760
764 token_cache_.clear(); 761 token_cache_.clear();
765 } 762 }
766 763
767 void OAuth2TokenService::ClearCacheForAccount(const std::string& account_id) { 764 void OAuth2TokenService::ClearCacheForAccount(const std::string& account_id) {
768 DCHECK(CalledOnValidThread()); 765 DCHECK(CalledOnValidThread());
769 for (TokenCache::iterator iter = token_cache_.begin(); 766 for (TokenCache::iterator iter = token_cache_.begin();
770 iter != token_cache_.end(); 767 iter != token_cache_.end();
771 /* iter incremented in body */) { 768 /* iter incremented in body */) {
772 if (iter->first.account_id == account_id) { 769 if (iter->first.account_id == account_id) {
773 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, 770 for (auto& observer : diagnostics_observer_list_)
774 OnTokenRemoved(account_id, iter->first.scopes)); 771 observer.OnTokenRemoved(account_id, iter->first.scopes);
775 token_cache_.erase(iter++); 772 token_cache_.erase(iter++);
776 } else { 773 } else {
777 ++iter; 774 ++iter;
778 } 775 }
779 } 776 }
780 } 777 }
781 778
782 void OAuth2TokenService::CancelAllRequests() { 779 void OAuth2TokenService::CancelAllRequests() {
783 std::vector<Fetcher*> fetchers_to_cancel; 780 std::vector<Fetcher*> fetchers_to_cancel;
784 for (auto iter = pending_fetchers_.begin(); iter != pending_fetchers_.end(); 781 for (auto iter = pending_fetchers_.begin(); iter != pending_fetchers_.end();
(...skipping 30 matching lines...) Expand all
815 812
816 size_t OAuth2TokenService::GetNumPendingRequestsForTesting( 813 size_t OAuth2TokenService::GetNumPendingRequestsForTesting(
817 const std::string& client_id, 814 const std::string& client_id,
818 const std::string& account_id, 815 const std::string& account_id,
819 const ScopeSet& scopes) const { 816 const ScopeSet& scopes) const {
820 auto iter = pending_fetchers_.find( 817 auto iter = pending_fetchers_.find(
821 OAuth2TokenService::RequestParameters(client_id, account_id, scopes)); 818 OAuth2TokenService::RequestParameters(client_id, account_id, scopes));
822 return iter == pending_fetchers_.end() ? 819 return iter == pending_fetchers_.end() ?
823 0 : iter->second->GetWaitingRequestCount(); 820 0 : iter->second->GetWaitingRequestCount();
824 } 821 }
OLDNEW
« no previous file with comments | « google_apis/gaia/identity_provider.cc ('k') | google_apis/gaia/oauth2_token_service_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698