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

Unified Diff: chrome/browser/signin/oauth2_token_service.h

Issue 22581003: Handling of multiple concurrent requests from different clients in OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/signin/oauth2_token_service.h
diff --git a/chrome/browser/signin/oauth2_token_service.h b/chrome/browser/signin/oauth2_token_service.h
index d63fbdf33861520b8b40c8d575c62e7770795636..3213c9627ce407e05a60cd43940c086d10e200f5 100644
--- a/chrome/browser/signin/oauth2_token_service.h
+++ b/chrome/browser/signin/oauth2_token_service.h
@@ -119,8 +119,12 @@ class OAuth2TokenService {
// This method does the same as |StartRequest| except it uses |client_id| and
// |client_secret| to identify OAuth client app instead of using
- // Chrome's default values.
+ // Chrome's default values. |request_origin| is used to differentiate where
+ // request originates from. It's expected to be empty for requests from
+ // the internal chrome services while we will use webapp id for their
+ // requests.
virtual scoped_ptr<Request> StartRequestForClient(
+ const std::string& request_origin,
const std::string& client_id,
const std::string& client_secret,
const ScopeSet& scopes,
@@ -150,6 +154,17 @@ class OAuth2TokenService {
void set_max_authorization_token_fetch_retries_for_testing(int max_retries);
protected:
+ struct ClientScopeSet {
+ ClientScopeSet(const std::string& request_origin,
+ const std::string& client_id,
+ const ScopeSet& scopes);
+ bool operator<(const ClientScopeSet& set) const;
+
+ std::string request_origin;
+ std::string client_id;
+ ScopeSet scopes;
+ };
+
// Implements a cancelable |OAuth2TokenService::Request|, which should be
// operated on the UI thread.
// TODO(davidroche): move this out of header file.
@@ -180,19 +195,22 @@ class OAuth2TokenService {
// Add a new entry to the cache.
// Subclasses can override if there are implementation-specific reasons
// that an access token should ever not be cached.
- virtual void RegisterCacheEntry(const std::string& refresh_token,
+ virtual void RegisterCacheEntry(const std::string& request_origin,
+ const std::string& client_id,
+ const std::string& refresh_token,
const ScopeSet& scopes,
const std::string& access_token,
const base::Time& expiration_date);
// Returns true if GetCacheEntry would return a valid cache entry for the
// given scopes.
- bool HasCacheEntry(const ScopeSet& scopes);
+ bool HasCacheEntry(const ClientScopeSet& client_scopes);
// Posts a task to fire the Consumer callback with the cached token. Must
// Must only be called if HasCacheEntry() returns true.
- scoped_ptr<Request> StartCacheLookupRequest(const ScopeSet& scopes,
- Consumer* consumer);
+ scoped_ptr<Request> StartCacheLookupRequest(
+ const ClientScopeSet& client_scopes,
+ Consumer* consumer);
// Clears the internal token cache.
void ClearCache();
@@ -211,6 +229,27 @@ class OAuth2TokenService {
void FireRefreshTokensCleared();
private:
+
+ // The parameters used to fetch an OAuth2 access token.
+ struct FetchParameters {
+ FetchParameters(const std::string& request_origin,
+ const std::string& client_id,
+ const std::string& refresh_token,
+ const ScopeSet& scopes);
+ bool operator<(const FetchParameters& params) const;
+
+ // Request origin identifier. It's empty for internal chrome services
+ // requests but the requests originating from webapps should be identified
+ // by their originating extension_id.
+ std::string request_origin;
+ // OAuth2 client id.
+ std::string client_id;
+ // Refresh token used for minting access tokens within this request.
+ std::string refresh_token;
+ // URL scopes for the requested access token.
+ ScopeSet scopes;
+ };
+
// Derived classes must provide a request context used for fetching access
// tokens with the |StartRequest| method.
virtual net::URLRequestContextGetter* GetRequestContext() = 0;
@@ -231,6 +270,7 @@ class OAuth2TokenService {
// client app instead of using Chrome's default values.
scoped_ptr<Request> StartRequestForClientWithContext(
net::URLRequestContextGetter* getter,
+ const std::string& request_origin,
const std::string& client_id,
const std::string& client_secret,
const ScopeSet& scopes,
@@ -238,14 +278,14 @@ class OAuth2TokenService {
// Returns a currently valid OAuth2 access token for the given set of scopes,
// or NULL if none have been cached. Note the user of this method should
- // ensure no entry with the same |scopes| is added before the usage of the
- // returned entry is done.
- const CacheEntry* GetCacheEntry(const ScopeSet& scopes);
+ // ensure no entry with the same |client_scopes| is added before the usage of
+ // the returned entry is done.
+ const CacheEntry* GetCacheEntry(const ClientScopeSet& client_scopes);
// Removes an access token for the given set of scopes from the cache.
// Returns true if the entry was removed, otherwise false.
- bool RemoveCacheEntry(const OAuth2TokenService::ScopeSet& scopes,
+ bool RemoveCacheEntry(const ClientScopeSet& client_scopes,
const std::string& token_to_remove);
@@ -256,12 +296,9 @@ class OAuth2TokenService {
void CancelFetchers(std::vector<Fetcher*> fetchers_to_cancel);
// The cache of currently valid tokens.
- typedef std::map<ScopeSet, CacheEntry> TokenCache;
+ typedef std::map<ClientScopeSet, CacheEntry> TokenCache;
TokenCache token_cache_;
- // The parameters (refresh token and scope set) used to fetch an OAuth2 access
- // token.
- typedef std::pair<std::string, ScopeSet> FetchParameters;
// A map from fetch parameters to a fetcher that is fetching an OAuth2 access
// token using these parameters.
std::map<FetchParameters, Fetcher*> pending_fetchers_;

Powered by Google App Engine
This is Rietveld 408576698