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 23 matching lines...) Expand all Loading... |
34 class GoogleServiceAuthError; | 34 class GoogleServiceAuthError; |
35 class MockGetAuthTokenFunction; | 35 class MockGetAuthTokenFunction; |
36 | 36 |
37 namespace content { | 37 namespace content { |
38 class BrowserContext; | 38 class BrowserContext; |
39 } | 39 } |
40 | 40 |
41 namespace extensions { | 41 namespace extensions { |
42 | 42 |
43 class GetAuthTokenFunctionTest; | 43 class GetAuthTokenFunctionTest; |
| 44 class IdentityGetAuthTokenFunction; |
44 class MockGetAuthTokenFunction; | 45 class MockGetAuthTokenFunction; |
45 | 46 |
46 class IdentityTokenCacheValue { | 47 class IdentityTokenCacheValue { |
47 public: | 48 public: |
48 IdentityTokenCacheValue(); | 49 IdentityTokenCacheValue(); |
49 explicit IdentityTokenCacheValue(const IssueAdviceInfo& issue_advice); | 50 explicit IdentityTokenCacheValue(const IssueAdviceInfo& issue_advice); |
50 IdentityTokenCacheValue(const std::string& token, | 51 IdentityTokenCacheValue(const std::string& token, |
51 base::TimeDelta time_to_live); | 52 base::TimeDelta time_to_live); |
52 IdentityTokenCacheValue(const IdentityTokenCacheValue& other); | 53 IdentityTokenCacheValue(const IdentityTokenCacheValue& other); |
53 ~IdentityTokenCacheValue(); | 54 ~IdentityTokenCacheValue(); |
(...skipping 18 matching lines...) Expand all Loading... |
72 IssueAdviceInfo issue_advice_; | 73 IssueAdviceInfo issue_advice_; |
73 std::string token_; | 74 std::string token_; |
74 base::Time expiration_time_; | 75 base::Time expiration_time_; |
75 }; | 76 }; |
76 | 77 |
77 class IdentityAPI : public BrowserContextKeyedAPI, | 78 class IdentityAPI : public BrowserContextKeyedAPI, |
78 public gaia::AccountTracker::Observer { | 79 public gaia::AccountTracker::Observer { |
79 public: | 80 public: |
80 typedef std::map<ExtensionTokenKey, IdentityTokenCacheValue> CachedTokens; | 81 typedef std::map<ExtensionTokenKey, IdentityTokenCacheValue> CachedTokens; |
81 | 82 |
82 class ShutdownObserver { | |
83 public: | |
84 virtual void OnShutdown() = 0; | |
85 }; | |
86 | |
87 explicit IdentityAPI(content::BrowserContext* context); | 83 explicit IdentityAPI(content::BrowserContext* context); |
88 ~IdentityAPI() override; | 84 ~IdentityAPI() override; |
89 | 85 |
90 // Request serialization queue for getAuthToken. | 86 // Request serialization queue for getAuthToken. |
91 IdentityMintRequestQueue* mint_queue(); | 87 IdentityMintRequestQueue* mint_queue(); |
92 | 88 |
93 // Token cache | 89 // Token cache |
94 void SetCachedToken(const ExtensionTokenKey& key, | 90 void SetCachedToken(const ExtensionTokenKey& key, |
95 const IdentityTokenCacheValue& token_data); | 91 const IdentityTokenCacheValue& token_data); |
96 void EraseCachedToken(const std::string& extension_id, | 92 void EraseCachedToken(const std::string& extension_id, |
(...skipping 10 matching lines...) Expand all Loading... |
107 // BrowserContextKeyedAPI implementation. | 103 // BrowserContextKeyedAPI implementation. |
108 void Shutdown() override; | 104 void Shutdown() override; |
109 static BrowserContextKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); | 105 static BrowserContextKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); |
110 | 106 |
111 // gaia::AccountTracker::Observer implementation: | 107 // gaia::AccountTracker::Observer implementation: |
112 void OnAccountAdded(const gaia::AccountIds& ids) override; | 108 void OnAccountAdded(const gaia::AccountIds& ids) override; |
113 void OnAccountRemoved(const gaia::AccountIds& ids) override; | 109 void OnAccountRemoved(const gaia::AccountIds& ids) override; |
114 void OnAccountSignInChanged(const gaia::AccountIds& ids, | 110 void OnAccountSignInChanged(const gaia::AccountIds& ids, |
115 bool is_signed_in) override; | 111 bool is_signed_in) override; |
116 | 112 |
117 void AddShutdownObserver(ShutdownObserver* observer); | 113 void SetAccountStateForTest(gaia::AccountIds ids, bool is_signed_in); |
118 void RemoveShutdownObserver(ShutdownObserver* observer); | |
119 | 114 |
120 void SetAccountStateForTest(gaia::AccountIds ids, bool is_signed_in); | 115 void set_get_auth_token_function( |
| 116 IdentityGetAuthTokenFunction* get_auth_token_function) { |
| 117 get_auth_token_function_ = get_auth_token_function; |
| 118 } |
121 | 119 |
122 private: | 120 private: |
123 friend class BrowserContextKeyedAPIFactory<IdentityAPI>; | 121 friend class BrowserContextKeyedAPIFactory<IdentityAPI>; |
124 | 122 |
125 // BrowserContextKeyedAPI implementation. | 123 // BrowserContextKeyedAPI implementation. |
126 static const char* service_name() { return "IdentityAPI"; } | 124 static const char* service_name() { return "IdentityAPI"; } |
127 static const bool kServiceIsNULLWhileTesting = true; | 125 static const bool kServiceIsNULLWhileTesting = true; |
128 | 126 |
129 content::BrowserContext* browser_context_; | 127 content::BrowserContext* browser_context_; |
130 IdentityMintRequestQueue mint_queue_; | 128 IdentityMintRequestQueue mint_queue_; |
131 CachedTokens token_cache_; | 129 CachedTokens token_cache_; |
132 ProfileIdentityProvider profile_identity_provider_; | 130 ProfileIdentityProvider profile_identity_provider_; |
133 gaia::AccountTracker account_tracker_; | 131 gaia::AccountTracker account_tracker_; |
134 base::ObserverList<ShutdownObserver> shutdown_observer_list_; | 132 |
| 133 // May be null. |
| 134 IdentityGetAuthTokenFunction* get_auth_token_function_; |
135 }; | 135 }; |
136 | 136 |
137 template <> | 137 template <> |
138 void BrowserContextKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); | 138 void BrowserContextKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); |
139 | 139 |
140 class IdentityGetAccountsFunction : public ChromeUIThreadExtensionFunction { | 140 class IdentityGetAccountsFunction : public ChromeUIThreadExtensionFunction { |
141 public: | 141 public: |
142 DECLARE_EXTENSION_FUNCTION("identity.getAccounts", | 142 DECLARE_EXTENSION_FUNCTION("identity.getAccounts", |
143 IDENTITY_GETACCOUNTS); | 143 IDENTITY_GETACCOUNTS); |
144 | 144 |
(...skipping 21 matching lines...) Expand all Loading... |
166 // | 166 // |
167 // In some cases we need to display a sign-in dialog. Normally the | 167 // In some cases we need to display a sign-in dialog. Normally the |
168 // profile will be signed in already, but if it turns out we need a | 168 // profile will be signed in already, but if it turns out we need a |
169 // new login token, there is a sign-in flow. If that flow completes | 169 // new login token, there is a sign-in flow. If that flow completes |
170 // successfully, getAuthToken proceeds to the non-interactive flow. | 170 // successfully, getAuthToken proceeds to the non-interactive flow. |
171 class IdentityGetAuthTokenFunction : public ChromeAsyncExtensionFunction, | 171 class IdentityGetAuthTokenFunction : public ChromeAsyncExtensionFunction, |
172 public GaiaWebAuthFlow::Delegate, | 172 public GaiaWebAuthFlow::Delegate, |
173 public IdentityMintRequestQueue::Request, | 173 public IdentityMintRequestQueue::Request, |
174 public OAuth2MintTokenFlow::Delegate, | 174 public OAuth2MintTokenFlow::Delegate, |
175 public IdentitySigninFlow::Delegate, | 175 public IdentitySigninFlow::Delegate, |
176 public OAuth2TokenService::Consumer, | 176 public OAuth2TokenService::Consumer { |
177 public IdentityAPI::ShutdownObserver { | |
178 public: | 177 public: |
179 DECLARE_EXTENSION_FUNCTION("identity.getAuthToken", | 178 DECLARE_EXTENSION_FUNCTION("identity.getAuthToken", |
180 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN); | 179 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN); |
181 | 180 |
182 IdentityGetAuthTokenFunction(); | 181 IdentityGetAuthTokenFunction(); |
183 | 182 |
184 const ExtensionTokenKey* GetExtensionTokenKeyForTest() { | 183 const ExtensionTokenKey* GetExtensionTokenKeyForTest() { |
185 return token_key_.get(); | 184 return token_key_.get(); |
186 } | 185 } |
187 | 186 |
| 187 void Shutdown(); |
| 188 |
188 protected: | 189 protected: |
189 ~IdentityGetAuthTokenFunction() override; | 190 ~IdentityGetAuthTokenFunction() override; |
190 | 191 |
191 // IdentitySigninFlow::Delegate implementation: | 192 // IdentitySigninFlow::Delegate implementation: |
192 void SigninSuccess() override; | 193 void SigninSuccess() override; |
193 void SigninFailed() override; | 194 void SigninFailed() override; |
194 | 195 |
195 // GaiaWebAuthFlow::Delegate implementation: | 196 // GaiaWebAuthFlow::Delegate implementation: |
196 void OnGaiaFlowFailure(GaiaWebAuthFlow::Failure failure, | 197 void OnGaiaFlowFailure(GaiaWebAuthFlow::Failure failure, |
197 GoogleServiceAuthError service_error, | 198 GoogleServiceAuthError service_error, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 244 |
244 // IdentityMintRequestQueue::Request implementation: | 245 // IdentityMintRequestQueue::Request implementation: |
245 void StartMintToken(IdentityMintRequestQueue::MintType type) override; | 246 void StartMintToken(IdentityMintRequestQueue::MintType type) override; |
246 | 247 |
247 // OAuth2MintTokenFlow::Delegate implementation: | 248 // OAuth2MintTokenFlow::Delegate implementation: |
248 void OnMintTokenSuccess(const std::string& access_token, | 249 void OnMintTokenSuccess(const std::string& access_token, |
249 int time_to_live) override; | 250 int time_to_live) override; |
250 void OnMintTokenFailure(const GoogleServiceAuthError& error) override; | 251 void OnMintTokenFailure(const GoogleServiceAuthError& error) override; |
251 void OnIssueAdviceSuccess(const IssueAdviceInfo& issue_advice) override; | 252 void OnIssueAdviceSuccess(const IssueAdviceInfo& issue_advice) override; |
252 | 253 |
253 // IdentityAPI::ShutdownObserver implementation: | |
254 void OnShutdown() override; | |
255 | |
256 #if defined(OS_CHROMEOS) | 254 #if defined(OS_CHROMEOS) |
257 // Starts a login access token request for device robot account. This method | 255 // Starts a login access token request for device robot account. This method |
258 // will be called only in Chrome OS for: | 256 // will be called only in Chrome OS for: |
259 // 1. Enterprise kiosk mode. | 257 // 1. Enterprise kiosk mode. |
260 // 2. Whitelisted first party apps in public session. | 258 // 2. Whitelisted first party apps in public session. |
261 virtual void StartDeviceLoginAccessTokenRequest(); | 259 virtual void StartDeviceLoginAccessTokenRequest(); |
262 | 260 |
263 bool IsOriginWhitelistedInPublicSession(); | 261 bool IsOriginWhitelistedInPublicSession(); |
264 #endif | 262 #endif |
265 | 263 |
(...skipping 22 matching lines...) Expand all Loading... |
288 // When launched in interactive mode, and if there is no existing grant, | 286 // When launched in interactive mode, and if there is no existing grant, |
289 // a permissions prompt will be popped up to the user. | 287 // a permissions prompt will be popped up to the user. |
290 IssueAdviceInfo issue_advice_; | 288 IssueAdviceInfo issue_advice_; |
291 std::unique_ptr<GaiaWebAuthFlow> gaia_web_auth_flow_; | 289 std::unique_ptr<GaiaWebAuthFlow> gaia_web_auth_flow_; |
292 std::unique_ptr<IdentitySigninFlow> signin_flow_; | 290 std::unique_ptr<IdentitySigninFlow> signin_flow_; |
293 }; | 291 }; |
294 | 292 |
295 } // namespace extensions | 293 } // namespace extensions |
296 | 294 |
297 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 295 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
OLD | NEW |