diff options
Diffstat (limited to 'chromium/google_apis/gaia/oauth2_token_service.h')
-rw-r--r-- | chromium/google_apis/gaia/oauth2_token_service.h | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/chromium/google_apis/gaia/oauth2_token_service.h b/chromium/google_apis/gaia/oauth2_token_service.h index 1745315abf4..685b9dbb340 100644 --- a/chromium/google_apis/gaia/oauth2_token_service.h +++ b/chromium/google_apis/gaia/oauth2_token_service.h @@ -26,6 +26,7 @@ class URLRequestContextGetter; } class GoogleServiceAuthError; +class OAuth2AccessTokenFetcher; // Abstract base class for a service that fetches and caches OAuth2 access // tokens. Concrete subclasses should implement GetRefreshToken to return @@ -52,6 +53,9 @@ class GoogleServiceAuthError; // delete the request even once the callback has been invoked. class OAuth2TokenService : public base::NonThreadSafe { public: + // A set of scopes in OAuth2 authentication. + typedef std::set<std::string> ScopeSet; + // Class representing a request that fetches an OAuth2 access token. class Request { public: @@ -65,8 +69,11 @@ class OAuth2TokenService : public base::NonThreadSafe { // which will be called back when the request completes. class Consumer { public: - Consumer(); + Consumer(const std::string& id); virtual ~Consumer(); + + std::string id() const { return id_; } + // |request| is a Request that is started by this consumer and has // completed. virtual void OnGetTokenSuccess(const Request* request, @@ -74,10 +81,12 @@ class OAuth2TokenService : public base::NonThreadSafe { const base::Time& expiration_time) = 0; virtual void OnGetTokenFailure(const Request* request, const GoogleServiceAuthError& error) = 0; + private: + std::string id_; }; - // Classes that want to listen for token availability should implement this - // interface and register with the AddObserver() call. + // Classes that want to listen for refresh token availability should + // implement this interface and register with the AddObserver() call. class Observer { public: // Called whenever a new login-scoped refresh token is available for @@ -91,12 +100,31 @@ class OAuth2TokenService : public base::NonThreadSafe { // Called after all refresh tokens are loaded during OAuth2TokenService // startup. virtual void OnRefreshTokensLoaded() {} + protected: virtual ~Observer() {} }; - // A set of scopes in OAuth2 authentication. - typedef std::set<std::string> ScopeSet; + // Classes that want to monitor status of access token and access token + // request should implement this interface and register with the + // AddDiagnosticsObserver() call. + class DiagnosticsObserver { + public: + // Called when receiving request for access token. + virtual void OnAccessTokenRequested(const std::string& account_id, + const std::string& consumer_id, + const ScopeSet& scopes) = 0; + // Called when access token fetching finished successfully or + // unsuccessfully. |expiration_time| are only valid with + // successful completion. + virtual void OnFetchAccessTokenComplete(const std::string& account_id, + const std::string& consumer_id, + const ScopeSet& scopes, + GoogleServiceAuthError error, + base::Time expiration_time) = 0; + virtual void OnTokenRemoved(const std::string& account_id, + const ScopeSet& scopes) = 0; + }; OAuth2TokenService(); virtual ~OAuth2TokenService(); @@ -105,6 +133,10 @@ class OAuth2TokenService : public base::NonThreadSafe { void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); + // Add or remove observers of this token service. + void AddDiagnosticsObserver(DiagnosticsObserver* observer); + void RemoveDiagnosticsObserver(DiagnosticsObserver* observer); + // Checks in the cache for a valid access token for a specified |account_id| // and |scopes|, and if not found starts a request for an OAuth2 access token // using the OAuth2 refresh token maintained by this instance for that @@ -141,7 +173,7 @@ class OAuth2TokenService : public base::NonThreadSafe { // Returns true if a refresh token exists for |account_id|. If false, calls to // |StartRequest| will result in a Consumer::OnGetTokenFailure callback. - virtual bool RefreshTokenIsAvailable(const std::string& account_id); + virtual bool RefreshTokenIsAvailable(const std::string& account_id) const = 0; // Mark an OAuth2 |access_token| issued for |account_id| and |scopes| as // invalid. This should be done if the token was received from this class, @@ -184,6 +216,8 @@ class OAuth2TokenService : public base::NonThreadSafe { // Overridden from Request: virtual std::string GetAccountId() const OVERRIDE; + std::string GetConsumerId() const; + // Informs |consumer_| that this request is completed. void InformConsumer(const GoogleServiceAuthError& error, const std::string& access_token, @@ -195,10 +229,6 @@ class OAuth2TokenService : public base::NonThreadSafe { Consumer* const consumer_; }; - // Subclasses should return the maintained refresh token for |account_id|. - // If no token is available, return an empty string. - virtual std::string GetRefreshToken(const std::string& account_id) = 0; - // Subclasses can override if they want to report errors to the user. virtual void UpdateAuthError( const std::string& account_id, @@ -232,13 +262,6 @@ class OAuth2TokenService : public base::NonThreadSafe { virtual void FireRefreshTokenRevoked(const std::string& account_id); virtual void FireRefreshTokensLoaded(); - // Creates a request implementation. Can be overriden by derived classes to - // provide additional control of token consumption. |consumer| will outlive - // the created request. - virtual scoped_ptr<RequestImpl> CreateRequest( - const std::string& account_id, - Consumer* consumer); - // Fetches an OAuth token for the specified client/scopes. Virtual so it can // be overridden for tests and for platform-specific behavior on Android. virtual void FetchOAuth2Token(RequestImpl* request, @@ -248,6 +271,16 @@ class OAuth2TokenService : public base::NonThreadSafe { const std::string& client_secret, const ScopeSet& scopes); + // Creates an access token fetcher for the given account id. + // + // Subclasses should override to create an access token fetcher for the given + // |account_id|. This method is only called if subclasses use the default + // implementation of |FetchOAuth2Token|. + virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( + const std::string& account_id, + net::URLRequestContextGetter* getter, + OAuth2AccessTokenConsumer* consumer) = 0; + // Invalidates the |access_token| issued for |account_id|, |client_id| and // |scopes|. Virtual so it can be overriden for tests and for platform- // specifc behavior. @@ -334,10 +367,13 @@ class OAuth2TokenService : public base::NonThreadSafe { // token using these parameters. PendingFetcherMap pending_fetchers_; - // List of observers to notify when token availability changes. + // List of observers to notify when refresh token availability changes. // Makes sure list is empty on destruction. ObserverList<Observer, true> observer_list_; + // List of observers to notify when access token status changes. + ObserverList<DiagnosticsObserver, true> diagnostics_observer_list_; + // Maximum number of retries in fetching an OAuth2 access token. static int max_fetch_retry_num_; |