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

Side by Side Diff: chrome/browser/extensions/api/identity/identity_api.cc

Issue 166053003: Move ProfileKeyedAPI implementations to take BrowserContext in the constructor (part 2). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: | Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/identity/identity_api.h" 5 #include "chrome/browser/extensions/api/identity/identity_api.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const char kPageLoadFailure[] = "Authorization page could not be loaded."; 58 const char kPageLoadFailure[] = "Authorization page could not be loaded.";
59 59
60 const int kCachedIssueAdviceTTLSeconds = 1; 60 const int kCachedIssueAdviceTTLSeconds = 1;
61 } // namespace identity_constants 61 } // namespace identity_constants
62 62
63 namespace { 63 namespace {
64 64
65 static const char kChromiumDomainRedirectUrlPattern[] = 65 static const char kChromiumDomainRedirectUrlPattern[] =
66 "https://%s.chromiumapp.org/"; 66 "https://%s.chromiumapp.org/";
67 67
68 std::string GetPrimaryAccountId(Profile* profile) { 68 std::string GetPrimaryAccountId(content::BrowserContext* context) {
69 SigninManagerBase* signin_manager = 69 SigninManagerBase* signin_manager =
70 SigninManagerFactory::GetForProfile(profile); 70 SigninManagerFactory::GetForProfile(Profile::FromBrowserContext(context));
71 return signin_manager->GetAuthenticatedAccountId(); 71 return signin_manager->GetAuthenticatedAccountId();
72 } 72 }
73 73
74 } // namespace 74 } // namespace
75 75
76 namespace identity = api::identity; 76 namespace identity = api::identity;
77 77
78 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction() 78 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction()
79 : OAuth2TokenService::Consumer("extensions_identity_api"), 79 : OAuth2TokenService::Consumer("extensions_identity_api"),
80 should_prompt_for_scopes_(false), 80 should_prompt_for_scopes_(false),
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 670
671 bool IdentityTokenCacheValue::is_expired() const { 671 bool IdentityTokenCacheValue::is_expired() const {
672 return status_ == CACHE_STATUS_NOTFOUND || 672 return status_ == CACHE_STATUS_NOTFOUND ||
673 expiration_time_ < base::Time::Now(); 673 expiration_time_ < base::Time::Now();
674 } 674 }
675 675
676 const base::Time& IdentityTokenCacheValue::expiration_time() const { 676 const base::Time& IdentityTokenCacheValue::expiration_time() const {
677 return expiration_time_; 677 return expiration_time_;
678 } 678 }
679 679
680 IdentityAPI::IdentityAPI(Profile* profile) 680 IdentityAPI::IdentityAPI(content::BrowserContext* context)
681 : profile_(profile), 681 : browser_context_(context),
682 account_tracker_(profile) { 682 account_tracker_(Profile::FromBrowserContext(context)) {
683 account_tracker_.AddObserver(this); 683 account_tracker_.AddObserver(this);
684 } 684 }
685 685
686 IdentityAPI::~IdentityAPI() {} 686 IdentityAPI::~IdentityAPI() {}
687 687
688 IdentityMintRequestQueue* IdentityAPI::mint_queue() { 688 IdentityMintRequestQueue* IdentityAPI::mint_queue() {
689 return &mint_queue_; 689 return &mint_queue_;
690 } 690 }
691 691
692 void IdentityAPI::SetCachedToken(const ExtensionTokenKey& key, 692 void IdentityAPI::SetCachedToken(const ExtensionTokenKey& key,
(...skipping 25 matching lines...) Expand all
718 const IdentityTokenCacheValue& IdentityAPI::GetCachedToken( 718 const IdentityTokenCacheValue& IdentityAPI::GetCachedToken(
719 const ExtensionTokenKey& key) { 719 const ExtensionTokenKey& key) {
720 return token_cache_[key]; 720 return token_cache_[key];
721 } 721 }
722 722
723 const IdentityAPI::CachedTokens& IdentityAPI::GetAllCachedTokens() { 723 const IdentityAPI::CachedTokens& IdentityAPI::GetAllCachedTokens() {
724 return token_cache_; 724 return token_cache_;
725 } 725 }
726 726
727 void IdentityAPI::ReportAuthError(const GoogleServiceAuthError& error) { 727 void IdentityAPI::ReportAuthError(const GoogleServiceAuthError& error) {
728 account_tracker_.ReportAuthError(GetPrimaryAccountId(profile_), error); 728 account_tracker_.ReportAuthError(GetPrimaryAccountId(browser_context_),
729 error);
729 } 730 }
730 731
731 void IdentityAPI::Shutdown() { 732 void IdentityAPI::Shutdown() {
732 account_tracker_.RemoveObserver(this); 733 account_tracker_.RemoveObserver(this);
733 account_tracker_.Shutdown(); 734 account_tracker_.Shutdown();
734 } 735 }
735 736
736 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> > 737 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> >
737 g_factory = LAZY_INSTANCE_INITIALIZER; 738 g_factory = LAZY_INSTANCE_INITIALIZER;
738 739
739 // static 740 // static
740 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() { 741 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() {
741 return g_factory.Pointer(); 742 return g_factory.Pointer();
742 } 743 }
743 744
744 void IdentityAPI::OnAccountAdded(const AccountIds& ids) {} 745 void IdentityAPI::OnAccountAdded(const AccountIds& ids) {}
745 746
746 void IdentityAPI::OnAccountRemoved(const AccountIds& ids) {} 747 void IdentityAPI::OnAccountRemoved(const AccountIds& ids) {}
747 748
748 void IdentityAPI::OnAccountSignInChanged(const AccountIds& ids, 749 void IdentityAPI::OnAccountSignInChanged(const AccountIds& ids,
749 bool is_signed_in) { 750 bool is_signed_in) {
750 api::identity::AccountInfo account_info; 751 api::identity::AccountInfo account_info;
751 account_info.id = ids.gaia; 752 account_info.id = ids.gaia;
752 753
753 scoped_ptr<base::ListValue> args = 754 scoped_ptr<base::ListValue> args =
754 api::identity::OnSignInChanged::Create(account_info, is_signed_in); 755 api::identity::OnSignInChanged::Create(account_info, is_signed_in);
755 scoped_ptr<Event> event(new Event( 756 scoped_ptr<Event> event(new Event(api::identity::OnSignInChanged::kEventName,
756 api::identity::OnSignInChanged::kEventName, args.Pass(), profile_)); 757 args.Pass(),
758 browser_context_));
757 759
758 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); 760 ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent(
761 event.Pass());
759 } 762 }
760 763
761 template <> 764 template <>
762 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies() { 765 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies() {
763 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 766 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
764 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 767 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
765 } 768 }
766 769
767 } // namespace extensions 770 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698