Chromium Code Reviews| Index: google_apis/gaia/oauth2_token_service_delegate.h |
| diff --git a/google_apis/gaia/oauth2_token_service_delegate.h b/google_apis/gaia/oauth2_token_service_delegate.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..66457afc71a38fa529a7e440d7f76dfb5039f021 |
| --- /dev/null |
| +++ b/google_apis/gaia/oauth2_token_service_delegate.h |
| @@ -0,0 +1,95 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| +#define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| + |
| +#include "base/observer_list.h" |
| +#include "google_apis/gaia/gaia_auth_util.h" |
| +#include "google_apis/gaia/oauth2_token_service.h" |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +class SigninClient; |
| + |
| +// ProfileOAuth2TokenServiceDelegate provides an alternative to |
| +// ProfileOAuth2TokenService. It allows token to be fetched from other external |
| +// entity such as a OS level accounts database. |
| +class OAuth2TokenServiceDelegate { |
| + public: |
| + OAuth2TokenServiceDelegate(); |
| + virtual ~OAuth2TokenServiceDelegate(); |
| + |
| + virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| + const std::string& account_id, |
| + net::URLRequestContextGetter* getter, |
| + OAuth2AccessTokenConsumer* consumer) = 0; |
| + |
| + virtual bool RefreshTokenIsAvailable(const std::string& account_id) const = 0; |
| + virtual std::string GetRefreshToken(const std::string& account_id) const = 0; |
|
Roger Tawa OOO till Jul 10th
2015/05/24 21:13:19
GetRefreshToken() should not be exposed here. On
gogerald1
2015/05/25 21:10:58
That's because we need to know whether the updated
Roger Tawa OOO till Jul 10th
2015/05/28 14:54:43
See other comments, but by having the token servic
|
| + virtual void UpdateAuthError(const std::string& account_id, |
| + const GoogleServiceAuthError& error) = 0; |
| + |
| + virtual std::vector<std::string> GetAccounts() = 0; |
| + virtual void RevokeAllCredentials() = 0; |
| + |
| + virtual void InvalidateOAuth2Token(const std::string& account_id, |
| + const std::string& client_id, |
| + const std::set<std::string>& scopes, |
| + const std::string& access_token) = 0; |
| + |
| + virtual void Shutdown() {} |
| + virtual void LoadCredentials(const std::string& primary_account_id) {} |
| + virtual void UpdateCredentials(const std::string& account_id, |
| + const std::string& refresh_token) {} |
| + virtual void RevokeCredentials(const std::string& account_id) {} |
| + virtual net::URLRequestContextGetter* GetRequestContext() const; |
| + |
| + void ValidateAccountId(const std::string& account_id) const { |
| + DCHECK(!account_id.empty()); |
| + |
| + // If the account is given as an email, make sure its a canonical email. |
| + // Note that some tests don't use email strings as account id, and after |
| + // the gaia id migration it won't be an email. So only check for |
| + // canonicalization if the account_id is suspected to be an email. |
| + if (account_id.find('@') != std::string::npos) |
| + DCHECK_EQ(gaia::CanonicalizeEmail(account_id), account_id); |
| + } |
| + |
| + // Add or remove observers of this token service. |
| + void AddObserver(OAuth2TokenService::Observer* observer); |
| + void RemoveObserver(OAuth2TokenService::Observer* observer); |
| + |
| + protected: |
| + // Called by subclasses to notify observers. |
| + virtual void FireRefreshTokenAvailable(const std::string& account_id); |
| + virtual void FireRefreshTokenRevoked(const std::string& account_id); |
| + virtual void FireRefreshTokensLoaded(); |
| + |
| + // Helper class to scope batch changes. |
| + class ScopedBatchChange { |
| + public: |
| + explicit ScopedBatchChange(OAuth2TokenServiceDelegate* delegate); |
| + ~ScopedBatchChange(); |
| + |
| + private: |
| + OAuth2TokenServiceDelegate* delegate_; // Weak. |
| + DISALLOW_COPY_AND_ASSIGN(ScopedBatchChange); |
| + }; |
| + |
| + private: |
| + // List of observers to notify when refresh token availability changes. |
| + // Makes sure list is empty on destruction. |
| + ObserverList<OAuth2TokenService::Observer, true> observer_list_; |
| + |
| + void StartBatchChanges(); |
| + void EndBatchChanges(); |
| + |
| + // The depth of batch changes. |
| + int batch_change_depth_; |
| +}; |
| + |
| +#endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |