| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ | 5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| 6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ | 6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "google_apis/gaia/gaia_auth_util.h" | 10 #include "google_apis/gaia/gaia_auth_util.h" |
| 11 #include "google_apis/gaia/oauth2_token_service.h" | 11 #include "google_apis/gaia/oauth2_token_service.h" |
| 12 #include "net/base/backoff_entry.h" | 12 #include "net/base/backoff_entry.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 class URLRequestContextGetter; | 15 class URLRequestContextGetter; |
| 16 } | 16 } |
| 17 | 17 |
| 18 // Abstract base class to fetch and maintain refresh tokens from various | 18 // Abstract base class to fetch and maintain refresh tokens from various |
| 19 // entities. Concrete subclasses should implement RefreshTokenIsAvailable and | 19 // entities. Concrete subclasses should implement RefreshTokenIsAvailable and |
| 20 // CreateAccessTokenFetcher properly. | 20 // CreateAccessTokenFetcher properly. |
| 21 class OAuth2TokenServiceDelegate { | 21 class OAuth2TokenServiceDelegate { |
| 22 public: | 22 public: |
| 23 enum LoadCredentialsState { |
| 24 LOAD_CREDENTIALS_UNKNOWN, |
| 25 LOAD_CREDENTIALS_NOT_STARTED, |
| 26 LOAD_CREDENTIALS_IN_PROGRESS, |
| 27 LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS, |
| 28 LOAD_CREDENTIALS_FINISHED_WITH_DB_ERRORS, |
| 29 LOAD_CREDENTIALS_FINISHED_WITH_DECRYPT_ERRORS, |
| 30 LOAD_CREDENTIALS_FINISHED_WITH_UNKNOWN_ERRORS, |
| 31 }; |
| 32 |
| 23 OAuth2TokenServiceDelegate(); | 33 OAuth2TokenServiceDelegate(); |
| 24 virtual ~OAuth2TokenServiceDelegate(); | 34 virtual ~OAuth2TokenServiceDelegate(); |
| 25 | 35 |
| 26 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 36 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| 27 const std::string& account_id, | 37 const std::string& account_id, |
| 28 net::URLRequestContextGetter* getter, | 38 net::URLRequestContextGetter* getter, |
| 29 OAuth2AccessTokenConsumer* consumer) = 0; | 39 OAuth2AccessTokenConsumer* consumer) = 0; |
| 30 | 40 |
| 31 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const = 0; | 41 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const = 0; |
| 32 virtual bool RefreshTokenHasError(const std::string& account_id) const; | 42 virtual bool RefreshTokenHasError(const std::string& account_id) const; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 51 bool ValidateAccountId(const std::string& account_id) const; | 61 bool ValidateAccountId(const std::string& account_id) const; |
| 52 | 62 |
| 53 // Add or remove observers of this token service. | 63 // Add or remove observers of this token service. |
| 54 void AddObserver(OAuth2TokenService::Observer* observer); | 64 void AddObserver(OAuth2TokenService::Observer* observer); |
| 55 void RemoveObserver(OAuth2TokenService::Observer* observer); | 65 void RemoveObserver(OAuth2TokenService::Observer* observer); |
| 56 | 66 |
| 57 // Returns a pointer to its instance of net::BackoffEntry if it has one, or | 67 // Returns a pointer to its instance of net::BackoffEntry if it has one, or |
| 58 // a nullptr otherwise. | 68 // a nullptr otherwise. |
| 59 virtual const net::BackoffEntry* BackoffEntry() const; | 69 virtual const net::BackoffEntry* BackoffEntry() const; |
| 60 | 70 |
| 71 // Diagnostic methods |
| 72 |
| 73 // Returns the state of the load credentials operation. |
| 74 virtual LoadCredentialsState GetLoadCredentialsState() const; |
| 75 |
| 61 protected: | 76 protected: |
| 62 // Called by subclasses to notify observers. | 77 // Called by subclasses to notify observers. |
| 63 virtual void FireRefreshTokenAvailable(const std::string& account_id); | 78 virtual void FireRefreshTokenAvailable(const std::string& account_id); |
| 64 virtual void FireRefreshTokenRevoked(const std::string& account_id); | 79 virtual void FireRefreshTokenRevoked(const std::string& account_id); |
| 65 virtual void FireRefreshTokensLoaded(); | 80 virtual void FireRefreshTokensLoaded(); |
| 66 | 81 |
| 67 // Helper class to scope batch changes. | 82 // Helper class to scope batch changes. |
| 68 class ScopedBatchChange { | 83 class ScopedBatchChange { |
| 69 public: | 84 public: |
| 70 explicit ScopedBatchChange(OAuth2TokenServiceDelegate* delegate); | 85 explicit ScopedBatchChange(OAuth2TokenServiceDelegate* delegate); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 89 void StartBatchChanges(); | 104 void StartBatchChanges(); |
| 90 void EndBatchChanges(); | 105 void EndBatchChanges(); |
| 91 | 106 |
| 92 // The depth of batch changes. | 107 // The depth of batch changes. |
| 93 int batch_change_depth_; | 108 int batch_change_depth_; |
| 94 | 109 |
| 95 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegate); | 110 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegate); |
| 96 }; | 111 }; |
| 97 | 112 |
| 98 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ | 113 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_DELEGATE_H_ |
| OLD | NEW |