OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| 6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| 7 |
| 8 #include "base/observer_list.h" |
| 9 #include "google_apis/gaia/gaia_auth_util.h" |
| 10 #include "google_apis/gaia/oauth2_token_service.h" |
| 11 |
| 12 namespace net { |
| 13 class URLRequestContextGetter; |
| 14 } |
| 15 |
| 16 class SigninClient; |
| 17 |
| 18 // Abstract base class to fetch and maintain refresh tokens from various |
| 19 // entities. Concrete subclasses should implement RefreshTokenIsAvailable and |
| 20 // CreateAccessTokenFetcher properly. |
| 21 class OAuth2TokenServiceDelegate { |
| 22 public: |
| 23 OAuth2TokenServiceDelegate(); |
| 24 virtual ~OAuth2TokenServiceDelegate(); |
| 25 |
| 26 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| 27 const std::string& account_id, |
| 28 net::URLRequestContextGetter* getter, |
| 29 OAuth2AccessTokenConsumer* consumer) = 0; |
| 30 |
| 31 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const = 0; |
| 32 virtual void UpdateAuthError(const std::string& account_id, |
| 33 const GoogleServiceAuthError& error){}; |
| 34 |
| 35 virtual std::vector<std::string> GetAccounts(); |
| 36 virtual void RevokeAllCredentials(){}; |
| 37 |
| 38 virtual void InvalidateAccessToken(const std::string& account_id, |
| 39 const std::string& client_id, |
| 40 const std::set<std::string>& scopes, |
| 41 const std::string& access_token) {} |
| 42 |
| 43 virtual void Shutdown() {} |
| 44 virtual void LoadCredentials(const std::string& primary_account_id) {} |
| 45 virtual void UpdateCredentials(const std::string& account_id, |
| 46 const std::string& refresh_token) {} |
| 47 virtual void RevokeCredentials(const std::string& account_id) {} |
| 48 virtual net::URLRequestContextGetter* GetRequestContext() const; |
| 49 |
| 50 void ValidateAccountId(const std::string& account_id) const; |
| 51 |
| 52 // Add or remove observers of this token service. |
| 53 void AddObserver(OAuth2TokenService::Observer* observer); |
| 54 void RemoveObserver(OAuth2TokenService::Observer* observer); |
| 55 |
| 56 protected: |
| 57 // Called by subclasses to notify observers. |
| 58 virtual void FireRefreshTokenAvailable(const std::string& account_id); |
| 59 virtual void FireRefreshTokenRevoked(const std::string& account_id); |
| 60 virtual void FireRefreshTokensLoaded(); |
| 61 |
| 62 // Helper class to scope batch changes. |
| 63 class ScopedBatchChange { |
| 64 public: |
| 65 explicit ScopedBatchChange(OAuth2TokenServiceDelegate* delegate); |
| 66 ~ScopedBatchChange(); |
| 67 |
| 68 private: |
| 69 OAuth2TokenServiceDelegate* delegate_; // Weak. |
| 70 DISALLOW_COPY_AND_ASSIGN(ScopedBatchChange); |
| 71 }; |
| 72 |
| 73 private: |
| 74 // List of observers to notify when refresh token availability changes. |
| 75 // Makes sure list is empty on destruction. |
| 76 base::ObserverList<OAuth2TokenService::Observer, true> observer_list_; |
| 77 |
| 78 void StartBatchChanges(); |
| 79 void EndBatchChanges(); |
| 80 |
| 81 // The depth of batch changes. |
| 82 int batch_change_depth_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegate); |
| 85 }; |
| 86 |
| 87 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
OLD | NEW |