| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "chrome/browser/extensions/api/identity/account_tracker.h" | |
| 18 #include "chrome/browser/extensions/api/identity/extension_token_key.h" | 17 #include "chrome/browser/extensions/api/identity/extension_token_key.h" |
| 19 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h" | 18 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h" |
| 20 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h" | 19 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h" |
| 21 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h" | 20 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h" |
| 22 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" | 21 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" |
| 23 #include "chrome/browser/extensions/chrome_extension_function.h" | 22 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 24 #include "chrome/browser/signin/signin_global_error.h" | 23 #include "chrome/browser/signin/profile_identity_provider.h" |
| 25 #include "extensions/browser/browser_context_keyed_api_factory.h" | 24 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 25 #include "google_apis/gaia/account_tracker.h" |
| 26 #include "google_apis/gaia/oauth2_mint_token_flow.h" | 26 #include "google_apis/gaia/oauth2_mint_token_flow.h" |
| 27 #include "google_apis/gaia/oauth2_token_service.h" | 27 #include "google_apis/gaia/oauth2_token_service.h" |
| 28 | 28 |
| 29 class GoogleServiceAuthError; | 29 class GoogleServiceAuthError; |
| 30 class MockGetAuthTokenFunction; | 30 class MockGetAuthTokenFunction; |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 class BrowserContext; | 33 class BrowserContext; |
| 34 } | 34 } |
| 35 | 35 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 private: | 76 private: |
| 77 bool is_expired() const; | 77 bool is_expired() const; |
| 78 | 78 |
| 79 CacheValueStatus status_; | 79 CacheValueStatus status_; |
| 80 IssueAdviceInfo issue_advice_; | 80 IssueAdviceInfo issue_advice_; |
| 81 std::string token_; | 81 std::string token_; |
| 82 base::Time expiration_time_; | 82 base::Time expiration_time_; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 class IdentityAPI : public BrowserContextKeyedAPI, | 85 class IdentityAPI : public BrowserContextKeyedAPI, |
| 86 public AccountTracker::Observer { | 86 public gaia::AccountTracker::Observer { |
| 87 public: | 87 public: |
| 88 typedef std::map<ExtensionTokenKey, IdentityTokenCacheValue> CachedTokens; | 88 typedef std::map<ExtensionTokenKey, IdentityTokenCacheValue> CachedTokens; |
| 89 | 89 |
| 90 class ShutdownObserver { | 90 class ShutdownObserver { |
| 91 public: | 91 public: |
| 92 virtual void OnShutdown() = 0; | 92 virtual void OnShutdown() = 0; |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 explicit IdentityAPI(content::BrowserContext* context); | 95 explicit IdentityAPI(content::BrowserContext* context); |
| 96 virtual ~IdentityAPI(); | 96 virtual ~IdentityAPI(); |
| 97 | 97 |
| 98 // Request serialization queue for getAuthToken. | 98 // Request serialization queue for getAuthToken. |
| 99 IdentityMintRequestQueue* mint_queue(); | 99 IdentityMintRequestQueue* mint_queue(); |
| 100 | 100 |
| 101 // Token cache | 101 // Token cache |
| 102 void SetCachedToken(const ExtensionTokenKey& key, | 102 void SetCachedToken(const ExtensionTokenKey& key, |
| 103 const IdentityTokenCacheValue& token_data); | 103 const IdentityTokenCacheValue& token_data); |
| 104 void EraseCachedToken(const std::string& extension_id, | 104 void EraseCachedToken(const std::string& extension_id, |
| 105 const std::string& token); | 105 const std::string& token); |
| 106 void EraseAllCachedTokens(); | 106 void EraseAllCachedTokens(); |
| 107 const IdentityTokenCacheValue& GetCachedToken(const ExtensionTokenKey& key); | 107 const IdentityTokenCacheValue& GetCachedToken(const ExtensionTokenKey& key); |
| 108 | 108 |
| 109 const CachedTokens& GetAllCachedTokens(); | 109 const CachedTokens& GetAllCachedTokens(); |
| 110 | 110 |
| 111 // Account queries. | 111 // Account queries. |
| 112 std::vector<std::string> GetAccounts() const; | 112 std::vector<std::string> GetAccounts() const; |
| 113 std::string FindAccountKeyByGaiaId(const std::string& gaia_id); | 113 std::string FindAccountKeyByGaiaId(const std::string& gaia_id); |
| 114 | 114 |
| 115 // Global error reporting. | |
| 116 void ReportAuthError(const GoogleServiceAuthError& error); | |
| 117 GoogleServiceAuthError GetAuthStatusForTest() const; | |
| 118 | |
| 119 // BrowserContextKeyedAPI implementation. | 115 // BrowserContextKeyedAPI implementation. |
| 120 virtual void Shutdown() OVERRIDE; | 116 virtual void Shutdown() OVERRIDE; |
| 121 static BrowserContextKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); | 117 static BrowserContextKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); |
| 122 | 118 |
| 123 // AccountTracker::Observer implementation: | 119 // gaia::AccountTracker::Observer implementation: |
| 124 virtual void OnAccountAdded(const AccountIds& ids) OVERRIDE; | 120 virtual void OnAccountAdded(const gaia::AccountIds& ids) OVERRIDE; |
| 125 virtual void OnAccountRemoved(const AccountIds& ids) OVERRIDE; | 121 virtual void OnAccountRemoved(const gaia::AccountIds& ids) OVERRIDE; |
| 126 virtual void OnAccountSignInChanged(const AccountIds& ids, | 122 virtual void OnAccountSignInChanged(const gaia::AccountIds& ids, |
| 127 bool is_signed_in) OVERRIDE; | 123 bool is_signed_in) OVERRIDE; |
| 128 | 124 |
| 129 void AddShutdownObserver(ShutdownObserver* observer); | 125 void AddShutdownObserver(ShutdownObserver* observer); |
| 130 void RemoveShutdownObserver(ShutdownObserver* observer); | 126 void RemoveShutdownObserver(ShutdownObserver* observer); |
| 131 | 127 |
| 132 void SetAccountStateForTest(AccountIds ids, bool is_signed_in); | 128 void SetAccountStateForTest(gaia::AccountIds ids, bool is_signed_in); |
| 133 | 129 |
| 134 private: | 130 private: |
| 135 friend class BrowserContextKeyedAPIFactory<IdentityAPI>; | 131 friend class BrowserContextKeyedAPIFactory<IdentityAPI>; |
| 136 | 132 |
| 137 // BrowserContextKeyedAPI implementation. | 133 // BrowserContextKeyedAPI implementation. |
| 138 static const char* service_name() { return "IdentityAPI"; } | 134 static const char* service_name() { return "IdentityAPI"; } |
| 139 static const bool kServiceIsNULLWhileTesting = true; | 135 static const bool kServiceIsNULLWhileTesting = true; |
| 140 | 136 |
| 141 content::BrowserContext* browser_context_; | 137 content::BrowserContext* browser_context_; |
| 142 IdentityMintRequestQueue mint_queue_; | 138 IdentityMintRequestQueue mint_queue_; |
| 143 CachedTokens token_cache_; | 139 CachedTokens token_cache_; |
| 144 AccountTracker account_tracker_; | 140 ProfileIdentityProvider profile_identity_provider_; |
| 141 gaia::AccountTracker account_tracker_; |
| 145 ObserverList<ShutdownObserver> shutdown_observer_list_; | 142 ObserverList<ShutdownObserver> shutdown_observer_list_; |
| 146 }; | 143 }; |
| 147 | 144 |
| 148 template <> | 145 template <> |
| 149 void BrowserContextKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); | 146 void BrowserContextKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); |
| 150 | 147 |
| 151 class IdentityGetAccountsFunction : public ChromeUIThreadExtensionFunction { | 148 class IdentityGetAccountsFunction : public ChromeUIThreadExtensionFunction { |
| 152 public: | 149 public: |
| 153 DECLARE_EXTENSION_FUNCTION("identity.getAccounts", | 150 DECLARE_EXTENSION_FUNCTION("identity.getAccounts", |
| 154 IDENTITY_GETACCOUNTS); | 151 IDENTITY_GETACCOUNTS); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // Helper to initialize final URL prefix. | 344 // Helper to initialize final URL prefix. |
| 348 void InitFinalRedirectURLPrefix(const std::string& extension_id); | 345 void InitFinalRedirectURLPrefix(const std::string& extension_id); |
| 349 | 346 |
| 350 scoped_ptr<WebAuthFlow> auth_flow_; | 347 scoped_ptr<WebAuthFlow> auth_flow_; |
| 351 GURL final_url_prefix_; | 348 GURL final_url_prefix_; |
| 352 }; | 349 }; |
| 353 | 350 |
| 354 } // namespace extensions | 351 } // namespace extensions |
| 355 | 352 |
| 356 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 353 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
| OLD | NEW |