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

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

Issue 99173004: Identity API: add multi-account support to token cache and request queues (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 #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 "chrome/browser/extensions/api/identity/account_tracker.h" 16 #include "chrome/browser/extensions/api/identity/account_tracker.h"
17 #include "chrome/browser/extensions/api/identity/extension_token_key.h"
17 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h" 18 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h"
18 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h" 19 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h"
19 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h" 20 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h"
20 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" 21 #include "chrome/browser/extensions/api/identity/web_auth_flow.h"
21 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" 22 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
22 #include "chrome/browser/extensions/chrome_extension_function.h" 23 #include "chrome/browser/extensions/chrome_extension_function.h"
23 #include "chrome/browser/signin/signin_global_error.h" 24 #include "chrome/browser/signin/signin_global_error.h"
24 #include "google_apis/gaia/oauth2_mint_token_flow.h" 25 #include "google_apis/gaia/oauth2_mint_token_flow.h"
25 #include "google_apis/gaia/oauth2_token_service.h" 26 #include "google_apis/gaia/oauth2_token_service.h"
26 27
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 std::string MapOAuth2ErrorToDescription(const std::string& error); 163 std::string MapOAuth2ErrorToDescription(const std::string& error);
163 164
164 std::string GetOAuth2ClientId() const; 165 std::string GetOAuth2ClientId() const;
165 166
166 bool should_prompt_for_scopes_; 167 bool should_prompt_for_scopes_;
167 IdentityMintRequestQueue::MintType mint_token_flow_type_; 168 IdentityMintRequestQueue::MintType mint_token_flow_type_;
168 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_; 169 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_;
169 OAuth2MintTokenFlow::Mode gaia_mint_token_mode_; 170 OAuth2MintTokenFlow::Mode gaia_mint_token_mode_;
170 bool should_prompt_for_signin_; 171 bool should_prompt_for_signin_;
171 172
173 scoped_ptr<ExtensionTokenKey> token_key_;
172 std::string oauth2_client_id_; 174 std::string oauth2_client_id_;
173 // When launched in interactive mode, and if there is no existing grant, 175 // When launched in interactive mode, and if there is no existing grant,
174 // a permissions prompt will be popped up to the user. 176 // a permissions prompt will be popped up to the user.
175 IssueAdviceInfo issue_advice_; 177 IssueAdviceInfo issue_advice_;
176 scoped_ptr<GaiaWebAuthFlow> gaia_web_auth_flow_; 178 scoped_ptr<GaiaWebAuthFlow> gaia_web_auth_flow_;
177 scoped_ptr<IdentitySigninFlow> signin_flow_; 179 scoped_ptr<IdentitySigninFlow> signin_flow_;
178 scoped_ptr<OAuth2TokenService::Request> login_token_request_; 180 scoped_ptr<OAuth2TokenService::Request> login_token_request_;
179 }; 181 };
180 182
181 class IdentityRemoveCachedAuthTokenFunction 183 class IdentityRemoveCachedAuthTokenFunction
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 247
246 CacheValueStatus status_; 248 CacheValueStatus status_;
247 IssueAdviceInfo issue_advice_; 249 IssueAdviceInfo issue_advice_;
248 std::string token_; 250 std::string token_;
249 base::Time expiration_time_; 251 base::Time expiration_time_;
250 }; 252 };
251 253
252 class IdentityAPI : public ProfileKeyedAPI, 254 class IdentityAPI : public ProfileKeyedAPI,
253 public AccountTracker::Observer { 255 public AccountTracker::Observer {
254 public: 256 public:
255 struct TokenCacheKey { 257 typedef std::map<ExtensionTokenKey, IdentityTokenCacheValue> CachedTokens;
256 TokenCacheKey(const std::string& extension_id,
257 const std::set<std::string> scopes);
258 ~TokenCacheKey();
259 bool operator<(const TokenCacheKey& rhs) const;
260 std::string extension_id;
261 std::set<std::string> scopes;
262 };
263
264 typedef std::map<TokenCacheKey, IdentityTokenCacheValue> CachedTokens;
265 258
266 explicit IdentityAPI(Profile* profile); 259 explicit IdentityAPI(Profile* profile);
267 virtual ~IdentityAPI(); 260 virtual ~IdentityAPI();
268 261
269 // Request serialization queue for getAuthToken. 262 // Request serialization queue for getAuthToken.
270 IdentityMintRequestQueue* mint_queue(); 263 IdentityMintRequestQueue* mint_queue();
271 264
272 // Token cache 265 // Token cache
273 void SetCachedToken(const std::string& extension_id, 266 void SetCachedToken(const ExtensionTokenKey& key,
274 const std::vector<std::string> scopes,
275 const IdentityTokenCacheValue& token_data); 267 const IdentityTokenCacheValue& token_data);
276 void EraseCachedToken(const std::string& extension_id, 268 void EraseCachedToken(const std::string& extension_id,
277 const std::string& token); 269 const std::string& token);
278 void EraseAllCachedTokens(); 270 void EraseAllCachedTokens();
279 const IdentityTokenCacheValue& GetCachedToken( 271 const IdentityTokenCacheValue& GetCachedToken(const ExtensionTokenKey& key);
280 const std::string& extension_id, const std::vector<std::string> scopes);
281 272
282 const CachedTokens& GetAllCachedTokens(); 273 const CachedTokens& GetAllCachedTokens();
283 274
284 void ReportAuthError(const GoogleServiceAuthError& error); 275 void ReportAuthError(const GoogleServiceAuthError& error);
285 276
286 // ProfileKeyedAPI implementation. 277 // ProfileKeyedAPI implementation.
287 virtual void Shutdown() OVERRIDE; 278 virtual void Shutdown() OVERRIDE;
288 static ProfileKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); 279 static ProfileKeyedAPIFactory<IdentityAPI>* GetFactoryInstance();
289 280
290 // AccountTracker::Observer implementation: 281 // AccountTracker::Observer implementation:
(...skipping 16 matching lines...) Expand all
307 CachedTokens token_cache_; 298 CachedTokens token_cache_;
308 AccountTracker account_tracker_; 299 AccountTracker account_tracker_;
309 }; 300 };
310 301
311 template <> 302 template <>
312 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); 303 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies();
313 304
314 } // namespace extensions 305 } // namespace extensions
315 306
316 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 307 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698