| 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> |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 112 std::vector<std::string> GetAccounts() const; |
| 113 |
| 114 // Global error reporting. |
| 111 void ReportAuthError(const GoogleServiceAuthError& error); | 115 void ReportAuthError(const GoogleServiceAuthError& error); |
| 112 GoogleServiceAuthError GetAuthStatusForTest() const; | 116 GoogleServiceAuthError GetAuthStatusForTest() const; |
| 113 | 117 |
| 114 // BrowserContextKeyedAPI implementation. | 118 // BrowserContextKeyedAPI implementation. |
| 115 virtual void Shutdown() OVERRIDE; | 119 virtual void Shutdown() OVERRIDE; |
| 116 static BrowserContextKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); | 120 static BrowserContextKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); |
| 117 | 121 |
| 118 // AccountTracker::Observer implementation: | 122 // AccountTracker::Observer implementation: |
| 119 virtual void OnAccountAdded(const AccountIds& ids) OVERRIDE; | 123 virtual void OnAccountAdded(const AccountIds& ids) OVERRIDE; |
| 120 virtual void OnAccountRemoved(const AccountIds& ids) OVERRIDE; | 124 virtual void OnAccountRemoved(const AccountIds& ids) OVERRIDE; |
| 121 virtual void OnAccountSignInChanged(const AccountIds& ids, | 125 virtual void OnAccountSignInChanged(const AccountIds& ids, |
| 122 bool is_signed_in) OVERRIDE; | 126 bool is_signed_in) OVERRIDE; |
| 123 | 127 |
| 124 void AddShutdownObserver(ShutdownObserver* observer); | 128 void AddShutdownObserver(ShutdownObserver* observer); |
| 125 void RemoveShutdownObserver(ShutdownObserver* observer); | 129 void RemoveShutdownObserver(ShutdownObserver* observer); |
| 126 | 130 |
| 131 void SetAccountStateForTest(AccountIds ids, bool is_signed_in); |
| 132 |
| 127 private: | 133 private: |
| 128 friend class BrowserContextKeyedAPIFactory<IdentityAPI>; | 134 friend class BrowserContextKeyedAPIFactory<IdentityAPI>; |
| 129 | 135 |
| 130 // BrowserContextKeyedAPI implementation. | 136 // BrowserContextKeyedAPI implementation. |
| 131 static const char* service_name() { return "IdentityAPI"; } | 137 static const char* service_name() { return "IdentityAPI"; } |
| 132 static const bool kServiceIsNULLWhileTesting = true; | 138 static const bool kServiceIsNULLWhileTesting = true; |
| 133 | 139 |
| 134 content::BrowserContext* browser_context_; | 140 content::BrowserContext* browser_context_; |
| 135 IdentityMintRequestQueue mint_queue_; | 141 IdentityMintRequestQueue mint_queue_; |
| 136 CachedTokens token_cache_; | 142 CachedTokens token_cache_; |
| 137 AccountTracker account_tracker_; | 143 AccountTracker account_tracker_; |
| 138 ObserverList<ShutdownObserver> shutdown_observer_list_; | 144 ObserverList<ShutdownObserver> shutdown_observer_list_; |
| 139 }; | 145 }; |
| 140 | 146 |
| 141 template <> | 147 template <> |
| 142 void BrowserContextKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); | 148 void BrowserContextKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); |
| 143 | 149 |
| 150 class IdentityGetAccountsFunction : public ChromeUIThreadExtensionFunction { |
| 151 public: |
| 152 DECLARE_EXTENSION_FUNCTION("identity.getAccounts", |
| 153 IDENTITY_GETACCOUNTS); |
| 154 |
| 155 IdentityGetAccountsFunction(); |
| 156 |
| 157 private: |
| 158 virtual ~IdentityGetAccountsFunction(); |
| 159 |
| 160 // UIThreadExtensionFunction implementation. |
| 161 virtual ExtensionFunction::ResponseAction Run() OVERRIDE; |
| 162 }; |
| 163 |
| 144 // identity.getAuthToken fetches an OAuth 2 function for the | 164 // identity.getAuthToken fetches an OAuth 2 function for the |
| 145 // caller. The request has three sub-flows: non-interactive, | 165 // caller. The request has three sub-flows: non-interactive, |
| 146 // interactive, and sign-in. | 166 // interactive, and sign-in. |
| 147 // | 167 // |
| 148 // In the non-interactive flow, getAuthToken requests a token from | 168 // In the non-interactive flow, getAuthToken requests a token from |
| 149 // GAIA. GAIA may respond with a token, an error, or "consent | 169 // GAIA. GAIA may respond with a token, an error, or "consent |
| 150 // required". In the consent required cases, getAuthToken proceeds to | 170 // required". In the consent required cases, getAuthToken proceeds to |
| 151 // the second, interactive phase. | 171 // the second, interactive phase. |
| 152 // | 172 // |
| 153 // The interactive flow presents a scope approval dialog to the | 173 // The interactive flow presents a scope approval dialog to the |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // Helper to initialize final URL prefix. | 330 // Helper to initialize final URL prefix. |
| 311 void InitFinalRedirectURLPrefix(const std::string& extension_id); | 331 void InitFinalRedirectURLPrefix(const std::string& extension_id); |
| 312 | 332 |
| 313 scoped_ptr<WebAuthFlow> auth_flow_; | 333 scoped_ptr<WebAuthFlow> auth_flow_; |
| 314 GURL final_url_prefix_; | 334 GURL final_url_prefix_; |
| 315 }; | 335 }; |
| 316 | 336 |
| 317 } // namespace extensions | 337 } // namespace extensions |
| 318 | 338 |
| 319 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 339 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
| OLD | NEW |