| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The TokenService will supply authentication tokens for any service that | 5 // The TokenService will supply authentication tokens for any service that |
| 6 // needs it, such as sync. Whenever the user logs in, a controller watching | 6 // needs it, such as sync. Whenever the user logs in, a controller watching |
| 7 // the token service is expected either to call ClientLogin to derive a new | 7 // the token service is expected either to call ClientLogin to derive a new |
| 8 // SID and LSID, or to use GAIA OAuth requests to derive an OAuth1 access | 8 // SID and LSID, or to use GAIA OAuth requests to derive an OAuth1 access |
| 9 // token for the OAuthLogin scope. Whenever such credentials are available, | 9 // token for the OAuthLogin scope. Whenever such credentials are available, |
| 10 // the TokenService should be updated with new credentials. The controller | 10 // the TokenService should be updated with new credentials. The controller |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 // Clear all DB stored tokens for the current profile. Tokens may still be | 137 // Clear all DB stored tokens for the current profile. Tokens may still be |
| 138 // available in memory. If a DB load is pending it may still be serviced. | 138 // available in memory. If a DB load is pending it may still be serviced. |
| 139 void EraseTokensFromDB(); | 139 void EraseTokensFromDB(); |
| 140 | 140 |
| 141 // Returns true if tokens have been loaded from the DB. Set when | 141 // Returns true if tokens have been loaded from the DB. Set when |
| 142 // LoadTokensFromDB() completes, unset when ResetCredentialsInMemory() is | 142 // LoadTokensFromDB() completes, unset when ResetCredentialsInMemory() is |
| 143 // called. | 143 // called. |
| 144 bool TokensLoadedFromDB() const; | 144 bool TokensLoadedFromDB() const; |
| 145 | 145 |
| 146 // Returns true if the token service has all credentials needed to fetch | 146 // Returns true if the token service has either GAIA credentials or OAuth2 |
| 147 // tokens. | 147 // tokens needed to fetch other service tokens. |
| 148 virtual bool AreCredentialsValid() const; | 148 virtual bool AreCredentialsValid() const; |
| 149 | 149 |
| 150 // Tokens will be fetched for all services(sync, talk) in the background. | 150 // Tokens will be fetched for all services(sync, talk) in the background. |
| 151 // Results come back via event channel. Services can also poll before events | 151 // Results come back via event channel. Services can also poll before events |
| 152 // are issued. | 152 // are issued. |
| 153 void StartFetchingTokens(); | 153 void StartFetchingTokens(); |
| 154 virtual bool HasTokenForService(const char* service) const; | 154 virtual bool HasTokenForService(const char* service) const; |
| 155 const std::string& GetTokenForService(const char* const service) const; | 155 const std::string& GetTokenForService(const char* const service) const; |
| 156 | 156 |
| 157 // OAuth login token is an all-powerful token that allows creating OAuth2 | 157 // OAuth login token is an all-powerful token that allows creating OAuth2 |
| 158 // tokens for any other scope (i.e. down-scoping). | 158 // tokens for any other scope (i.e. down-scoping). |
| 159 // Typical use is to create an OAuth2 token for appropriate scope and then | 159 // Typical use is to create an OAuth2 token for appropriate scope and then |
| 160 // use that token to call a Google API. | 160 // use that token to call a Google API. |
| 161 virtual bool HasOAuthLoginToken() const; | 161 virtual bool HasOAuthLoginToken() const; |
| 162 virtual bool HasOAuthLoginAccessToken() const; |
| 162 virtual const std::string& GetOAuth2LoginRefreshToken() const; | 163 virtual const std::string& GetOAuth2LoginRefreshToken() const; |
| 163 const std::string& GetOAuth2LoginAccessToken() const; | 164 const std::string& GetOAuth2LoginAccessToken() const; |
| 164 | 165 |
| 165 // For tests only. Doesn't save to the WebDB. | 166 // For tests only. Doesn't save to the WebDB. |
| 166 void IssueAuthTokenForTest(const std::string& service, | 167 void IssueAuthTokenForTest(const std::string& service, |
| 167 const std::string& auth_token); | 168 const std::string& auth_token); |
| 168 | 169 |
| 169 // GaiaAuthConsumer implementation. | 170 // GaiaAuthConsumer implementation. |
| 170 virtual void OnIssueAuthTokenSuccess(const std::string& service, | 171 virtual void OnIssueAuthTokenSuccess(const std::string& service, |
| 171 const std::string& auth_token) OVERRIDE; | 172 const std::string& auth_token) OVERRIDE; |
| 172 virtual void OnIssueAuthTokenFailure( | 173 virtual void OnIssueAuthTokenFailure( |
| 173 const std::string& service, | 174 const std::string& service, |
| 174 const GoogleServiceAuthError& error) OVERRIDE; | 175 const GoogleServiceAuthError& error) OVERRIDE; |
| 175 virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) OVERRIDE; | 176 virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) OVERRIDE; |
| 176 virtual void OnClientOAuthFailure( | 177 virtual void OnClientOAuthFailure( |
| 177 const GoogleServiceAuthError& error) OVERRIDE; | 178 const GoogleServiceAuthError& error) OVERRIDE; |
| 178 | 179 |
| 179 // WebDataServiceConsumer implementation. | 180 // WebDataServiceConsumer implementation. |
| 180 virtual void OnWebDataServiceRequestDone( | 181 virtual void OnWebDataServiceRequestDone( |
| 181 WebDataService::Handle h, | 182 WebDataService::Handle h, |
| 182 const WDTypedResult* result) OVERRIDE; | 183 const WDTypedResult* result) OVERRIDE; |
| 183 | 184 |
| 184 protected: | 185 protected: |
| 186 // Saves OAuth2 credentials. |
| 187 void SaveOAuth2Credentials(const ClientOAuthResult& result); |
| 188 |
| 185 void set_tokens_loaded(bool loaded) { | 189 void set_tokens_loaded(bool loaded) { |
| 186 tokens_loaded_ = loaded; | 190 tokens_loaded_ = loaded; |
| 187 } | 191 } |
| 188 | 192 |
| 189 private: | 193 private: |
| 190 | 194 |
| 191 // Gets the list of all service names for which tokens will be retrieved. | 195 // Gets the list of all service names for which tokens will be retrieved. |
| 192 // This method is meant only for tests. | 196 // This method is meant only for tests. |
| 193 static void GetServiceNamesForTesting(std::vector<std::string>* names); | 197 static void GetServiceNamesForTesting(std::vector<std::string>* names); |
| 194 | 198 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 245 |
| 242 friend class TokenServiceTest; | 246 friend class TokenServiceTest; |
| 243 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryBasic); | 247 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryBasic); |
| 244 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryAdvanced); | 248 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryAdvanced); |
| 245 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, FullIntegrationNewServicesAdded); | 249 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, FullIntegrationNewServicesAdded); |
| 246 | 250 |
| 247 DISALLOW_COPY_AND_ASSIGN(TokenService); | 251 DISALLOW_COPY_AND_ASSIGN(TokenService); |
| 248 }; | 252 }; |
| 249 | 253 |
| 250 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_H_ | 254 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_H_ |
| OLD | NEW |