OLD | NEW |
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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 return status_ == CACHE_STATUS_NOTFOUND || | 659 return status_ == CACHE_STATUS_NOTFOUND || |
660 expiration_time_ < base::Time::Now(); | 660 expiration_time_ < base::Time::Now(); |
661 } | 661 } |
662 | 662 |
663 const base::Time& IdentityTokenCacheValue::expiration_time() const { | 663 const base::Time& IdentityTokenCacheValue::expiration_time() const { |
664 return expiration_time_; | 664 return expiration_time_; |
665 } | 665 } |
666 | 666 |
667 IdentityAPI::IdentityAPI(Profile* profile) | 667 IdentityAPI::IdentityAPI(Profile* profile) |
668 : profile_(profile), | 668 : profile_(profile), |
669 error_(GoogleServiceAuthError::NONE) { | 669 error_(GoogleServiceAuthError::NONE), |
670 SigninGlobalError::GetForProfile(profile_)->AddProvider(this); | 670 initialized_(false) { |
671 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->AddObserver(this); | |
672 } | 671 } |
673 | 672 |
674 IdentityAPI::~IdentityAPI() { | 673 IdentityAPI::~IdentityAPI() { |
675 } | 674 } |
676 | 675 |
| 676 void IdentityAPI::Initialize() { |
| 677 SigninGlobalError::GetForProfile(profile_)->AddProvider(this); |
| 678 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->AddObserver(this); |
| 679 |
| 680 initialized_ = true; |
| 681 } |
| 682 |
677 IdentityMintRequestQueue* IdentityAPI::mint_queue() { | 683 IdentityMintRequestQueue* IdentityAPI::mint_queue() { |
678 return &mint_queue_; | 684 return &mint_queue_; |
679 } | 685 } |
680 | 686 |
681 void IdentityAPI::SetCachedToken(const std::string& extension_id, | 687 void IdentityAPI::SetCachedToken(const std::string& extension_id, |
682 const std::vector<std::string> scopes, | 688 const std::vector<std::string> scopes, |
683 const IdentityTokenCacheValue& token_data) { | 689 const IdentityTokenCacheValue& token_data) { |
684 std::set<std::string> scopeset(scopes.begin(), scopes.end()); | 690 std::set<std::string> scopeset(scopes.begin(), scopes.end()); |
685 TokenCacheKey key(extension_id, scopeset); | 691 TokenCacheKey key(extension_id, scopeset); |
686 | 692 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 const IdentityAPI::CachedTokens& IdentityAPI::GetAllCachedTokens() { | 724 const IdentityAPI::CachedTokens& IdentityAPI::GetAllCachedTokens() { |
719 return token_cache_; | 725 return token_cache_; |
720 } | 726 } |
721 | 727 |
722 void IdentityAPI::ReportAuthError(const GoogleServiceAuthError& error) { | 728 void IdentityAPI::ReportAuthError(const GoogleServiceAuthError& error) { |
723 error_ = error; | 729 error_ = error; |
724 SigninGlobalError::GetForProfile(profile_)->AuthStatusChanged(); | 730 SigninGlobalError::GetForProfile(profile_)->AuthStatusChanged(); |
725 } | 731 } |
726 | 732 |
727 void IdentityAPI::Shutdown() { | 733 void IdentityAPI::Shutdown() { |
| 734 if (!initialized_) |
| 735 return; |
| 736 |
728 SigninGlobalError::GetForProfile(profile_)->RemoveProvider(this); | 737 SigninGlobalError::GetForProfile(profile_)->RemoveProvider(this); |
729 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 738 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
730 RemoveObserver(this); | 739 RemoveObserver(this); |
| 740 |
| 741 initialized_ = false; |
731 } | 742 } |
732 | 743 |
733 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> > | 744 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> > |
734 g_factory = LAZY_INSTANCE_INITIALIZER; | 745 g_factory = LAZY_INSTANCE_INITIALIZER; |
735 | 746 |
736 // static | 747 // static |
737 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() { | 748 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() { |
738 return &g_factory.Get(); | 749 return &g_factory.Get(); |
739 } | 750 } |
740 | 751 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 const IdentityAPI::TokenCacheKey& rhs) const { | 783 const IdentityAPI::TokenCacheKey& rhs) const { |
773 if (extension_id < rhs.extension_id) | 784 if (extension_id < rhs.extension_id) |
774 return true; | 785 return true; |
775 else if (rhs.extension_id < extension_id) | 786 else if (rhs.extension_id < extension_id) |
776 return false; | 787 return false; |
777 | 788 |
778 return scopes < rhs.scopes; | 789 return scopes < rhs.scopes; |
779 } | 790 } |
780 | 791 |
781 } // namespace extensions | 792 } // namespace extensions |
OLD | NEW |