| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // Initializes this token service with the profile. | 52 // Initializes this token service with the profile. |
| 53 virtual void Initialize(Profile* profile); | 53 virtual void Initialize(Profile* profile); |
| 54 | 54 |
| 55 // BrowserContextKeyedService implementation. | 55 // BrowserContextKeyedService implementation. |
| 56 virtual void Shutdown() OVERRIDE; | 56 virtual void Shutdown() OVERRIDE; |
| 57 | 57 |
| 58 // SigninGlobalError::AuthStatusProvider implementation. | 58 // SigninGlobalError::AuthStatusProvider implementation. |
| 59 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE; | 59 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE; |
| 60 | 60 |
| 61 // Takes injected TokenService for testing. | 61 // Takes injected TokenService for testing. |
| 62 bool ShouldCacheForRefreshToken(TokenService *token_service, | 62 bool ShouldCacheForRefreshToken(const std::string& refresh_token); |
| 63 const std::string& refresh_token); | 63 |
| 64 // Gets an account id of the primary account related to the profile. |
| 65 std::string GetPrimaryAccountId(); |
| 66 |
| 67 // Lists account IDs of all accounts with a refresh token. |
| 68 virtual std::vector<std::string> GetAccounts() OVERRIDE; |
| 64 | 69 |
| 65 // Updates a |refresh_token| for an |account_id|. Credentials are persisted, | 70 // Updates a |refresh_token| for an |account_id|. Credentials are persisted, |
| 66 // and avialable through |LoadCredentials| after service is restarted. | 71 // and avialable through |LoadCredentials| after service is restarted. |
| 67 void UpdateCredentials(const std::string& account_id, | 72 void UpdateCredentials(const std::string& account_id, |
| 68 const std::string& refresh_token); | 73 const std::string& refresh_token); |
| 69 | 74 |
| 70 // Revokes credentials related to |account_id|. | 75 // Revokes credentials related to |account_id|. |
| 71 void RevokeCredentials(const std::string& account_id); | 76 void RevokeCredentials(const std::string& account_id); |
| 72 | 77 |
| 73 // Revokes all credentials handled by the object. | 78 // Revokes all credentials handled by the object. |
| 74 void RevokeAllCredentials(); | 79 void RevokeAllCredentials(); |
| 75 | 80 |
| 76 SigninGlobalError* signin_global_error() { | 81 SigninGlobalError* signin_global_error() { |
| 77 return signin_global_error_.get(); | 82 return signin_global_error_.get(); |
| 78 } | 83 } |
| 79 | 84 |
| 80 const SigninGlobalError* signin_global_error() const { | 85 const SigninGlobalError* signin_global_error() const { |
| 81 return signin_global_error_.get(); | 86 return signin_global_error_.get(); |
| 82 } | 87 } |
| 83 | 88 |
| 84 Profile* profile() const { return profile_; } | 89 Profile* profile() const { return profile_; } |
| 85 | 90 |
| 86 protected: | 91 protected: |
| 87 friend class ProfileOAuth2TokenServiceFactory; | 92 friend class ProfileOAuth2TokenServiceFactory; |
| 88 ProfileOAuth2TokenService(); | 93 ProfileOAuth2TokenService(); |
| 89 virtual ~ProfileOAuth2TokenService(); | 94 virtual ~ProfileOAuth2TokenService(); |
| 90 | 95 |
| 91 // OAuth2TokenService overrides. | 96 // OAuth2TokenService overrides. |
| 92 virtual std::string GetRefreshToken() OVERRIDE; | 97 virtual std::string GetRefreshToken(const std::string& account_id) OVERRIDE; |
| 93 | 98 |
| 94 // OAuth2TokenService implementation. | 99 // OAuth2TokenService implementation. |
| 95 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | 100 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; |
| 96 | 101 |
| 97 // Updates the internal cache of the result from the most-recently-completed | 102 // Updates the internal cache of the result from the most-recently-completed |
| 98 // auth request (used for reporting errors to the user). | 103 // auth request (used for reporting errors to the user). |
| 99 virtual void UpdateAuthError(const GoogleServiceAuthError& error) OVERRIDE; | 104 virtual void UpdateAuthError( |
| 105 const std::string& account_id, |
| 106 const GoogleServiceAuthError& error) OVERRIDE; |
| 100 | 107 |
| 101 // Overridden to not cache tokens if the TokenService refresh token | 108 // Overridden to not cache tokens if the TokenService refresh token |
| 102 // changes while a token fetch is in-flight. If the user logs out and | 109 // changes while a token fetch is in-flight. If the user logs out and |
| 103 // logs back in with a different account, then any in-flight token | 110 // logs back in with a different account, then any in-flight token |
| 104 // fetches will be for the old account's refresh token. Therefore | 111 // fetches will be for the old account's refresh token. Therefore |
| 105 // when they come back, they shouldn't be cached. | 112 // when they come back, they shouldn't be cached. |
| 106 virtual void RegisterCacheEntry(const std::string& client_id, | 113 virtual void RegisterCacheEntry(const std::string& client_id, |
| 107 const std::string& refresh_token, | 114 const std::string& refresh_token, |
| 108 const ScopeSet& scopes, | 115 const ScopeSet& scopes, |
| 109 const std::string& access_token, | 116 const std::string& access_token, |
| 110 const base::Time& expiration_date) OVERRIDE; | 117 const base::Time& expiration_date) OVERRIDE; |
| 111 | 118 |
| 119 // Method responsible for persistence of credentials. Enables overriding for |
| 120 // testing purposes, or other cases, when accessing the DB is not desired. |
| 121 virtual void PersistCredentials(const std::string& account_id, |
| 122 const std::string& refresh_token); |
| 123 |
| 124 // Method responsible for clearing persisted credentials. Enables overriding |
| 125 // for testing purposes, or other cases, when accessing the DB is not desired. |
| 126 virtual void ClearPersistedCredentials(const std::string& account_id); |
| 127 |
| 112 private: | 128 private: |
| 113 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, | 129 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, |
| 114 StaleRefreshTokensNotCached); | 130 StaleRefreshTokensNotCached); |
| 115 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, | 131 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, |
| 116 TokenServiceUpdateClearsCache); | 132 TokenServiceUpdateClearsCache); |
| 117 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, | 133 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, |
| 118 PersistenceDBUpgrade); | 134 PersistenceDBUpgrade); |
| 119 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, | 135 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, |
| 120 PersistenceLoadCredentials); | 136 PersistenceLoadCredentials); |
| 121 | 137 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // The auth status from the most-recently-completed request. | 170 // The auth status from the most-recently-completed request. |
| 155 GoogleServiceAuthError last_auth_error_; | 171 GoogleServiceAuthError last_auth_error_; |
| 156 | 172 |
| 157 // Registrar for notifications from the TokenService. | 173 // Registrar for notifications from the TokenService. |
| 158 content::NotificationRegistrar registrar_; | 174 content::NotificationRegistrar registrar_; |
| 159 | 175 |
| 160 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService); | 176 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService); |
| 161 }; | 177 }; |
| 162 | 178 |
| 163 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 179 #endif // CHROME_BROWSER_SIGNIN_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |