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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #define CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_H_ | 45 #define CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_H_ |
46 | 46 |
47 #include <map> | 47 #include <map> |
48 #include <string> | 48 #include <string> |
49 #include <vector> | 49 #include <vector> |
50 | 50 |
51 #include "base/gtest_prod_util.h" | 51 #include "base/gtest_prod_util.h" |
52 #include "base/memory/scoped_ptr.h" | 52 #include "base/memory/scoped_ptr.h" |
53 #include "base/observer_list.h" | 53 #include "base/observer_list.h" |
54 #include "chrome/browser/signin/signin_internals_util.h" | 54 #include "chrome/browser/signin/signin_internals_util.h" |
55 #include "chrome/browser/webdata/web_data_service.h" | |
56 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 55 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 56 #include "components/webdata/common/web_data_service_base.h" |
| 57 #include "components/webdata/common/web_data_service_consumer.h" |
57 #include "google_apis/gaia/gaia_auth_consumer.h" | 58 #include "google_apis/gaia/gaia_auth_consumer.h" |
58 #include "google_apis/gaia/gaia_auth_fetcher.h" | 59 #include "google_apis/gaia/gaia_auth_fetcher.h" |
59 #include "google_apis/gaia/google_service_auth_error.h" | 60 #include "google_apis/gaia/google_service_auth_error.h" |
60 | 61 |
61 class Profile; | 62 class Profile; |
62 class TokenServiceTest; | 63 class TokenServiceTest; |
| 64 class TokenWebData; |
63 | 65 |
64 namespace net { | 66 namespace net { |
65 class URLRequestContextGetter; | 67 class URLRequestContextGetter; |
66 } | 68 } |
67 | 69 |
68 // The TokenService is a Profile member, so all calls are expected | 70 // The TokenService is a Profile member, so all calls are expected |
69 // from the UI thread. | 71 // from the UI thread. |
70 class TokenService : public GaiaAuthConsumer, | 72 class TokenService : public GaiaAuthConsumer, |
71 public BrowserContextKeyedService, | 73 public BrowserContextKeyedService, |
72 public WebDataServiceConsumer { | 74 public WebDataServiceConsumer { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 const std::string& auth_token) OVERRIDE; | 183 const std::string& auth_token) OVERRIDE; |
182 virtual void OnIssueAuthTokenFailure( | 184 virtual void OnIssueAuthTokenFailure( |
183 const std::string& service, | 185 const std::string& service, |
184 const GoogleServiceAuthError& error) OVERRIDE; | 186 const GoogleServiceAuthError& error) OVERRIDE; |
185 virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) OVERRIDE; | 187 virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) OVERRIDE; |
186 virtual void OnClientOAuthFailure( | 188 virtual void OnClientOAuthFailure( |
187 const GoogleServiceAuthError& error) OVERRIDE; | 189 const GoogleServiceAuthError& error) OVERRIDE; |
188 | 190 |
189 // WebDataServiceConsumer implementation. | 191 // WebDataServiceConsumer implementation. |
190 virtual void OnWebDataServiceRequestDone( | 192 virtual void OnWebDataServiceRequestDone( |
191 WebDataService::Handle h, | 193 WebDataServiceBase::Handle h, |
192 const WDTypedResult* result) OVERRIDE; | 194 const WDTypedResult* result) OVERRIDE; |
193 | 195 |
194 // Gets the list of all service names for which tokens will be retrieved. | 196 // Gets the list of all service names for which tokens will be retrieved. |
195 static void GetServiceNames(std::vector<std::string>* names); | 197 static void GetServiceNames(std::vector<std::string>* names); |
196 | 198 |
197 protected: | 199 protected: |
198 // Saves OAuth2 credentials. | 200 // Saves OAuth2 credentials. |
199 void SaveOAuth2Credentials(const ClientOAuthResult& result); | 201 void SaveOAuth2Credentials(const ClientOAuthResult& result); |
200 | 202 |
201 void set_tokens_loaded(bool loaded) { | 203 void set_tokens_loaded(bool loaded) { |
(...skipping 18 matching lines...) Expand all Loading... |
220 void SaveAuthTokenToDB(const std::string& service, | 222 void SaveAuthTokenToDB(const std::string& service, |
221 const std::string& auth_token); | 223 const std::string& auth_token); |
222 | 224 |
223 // Returns the index of the given service. | 225 // Returns the index of the given service. |
224 static int GetServiceIndex(const std::string& service); | 226 static int GetServiceIndex(const std::string& service); |
225 | 227 |
226 // The profile with which this instance was initialized, or NULL. | 228 // The profile with which this instance was initialized, or NULL. |
227 Profile* profile_; | 229 Profile* profile_; |
228 | 230 |
229 // Web data service to access tokens from. | 231 // Web data service to access tokens from. |
230 scoped_refptr<WebDataService> web_data_service_; | 232 scoped_refptr<TokenWebData> token_web_data_; |
231 // Getter to use for fetchers. | 233 // Getter to use for fetchers. |
232 scoped_refptr<net::URLRequestContextGetter> getter_; | 234 scoped_refptr<net::URLRequestContextGetter> getter_; |
233 // Request handle to load Gaia tokens from DB. | 235 // Request handle to load Gaia tokens from DB. |
234 WebDataService::Handle token_loading_query_; | 236 WebDataServiceBase::Handle token_loading_query_; |
235 // True if token loading has completed (regardless of success). | 237 // True if token loading has completed (regardless of success). |
236 bool tokens_loaded_; | 238 bool tokens_loaded_; |
237 | 239 |
238 // Gaia request source for Gaia accounting. | 240 // Gaia request source for Gaia accounting. |
239 std::string source_; | 241 std::string source_; |
240 // Credentials from ClientLogin for Issuing auth tokens. | 242 // Credentials from ClientLogin for Issuing auth tokens. |
241 GaiaAuthConsumer::ClientLoginResult credentials_; | 243 GaiaAuthConsumer::ClientLoginResult credentials_; |
242 | 244 |
243 // A bunch of fetchers suitable for ClientLogin token issuing. We don't care | 245 // A bunch of fetchers suitable for ClientLogin token issuing. We don't care |
244 // about the ordering, nor do we care which is for which service. The | 246 // about the ordering, nor do we care which is for which service. The |
(...skipping 11 matching lines...) Expand all Loading... |
256 | 258 |
257 friend class TokenServiceTest; | 259 friend class TokenServiceTest; |
258 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryBasic); | 260 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryBasic); |
259 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryAdvanced); | 261 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryAdvanced); |
260 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, FullIntegrationNewServicesAdded); | 262 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, FullIntegrationNewServicesAdded); |
261 | 263 |
262 DISALLOW_COPY_AND_ASSIGN(TokenService); | 264 DISALLOW_COPY_AND_ASSIGN(TokenService); |
263 }; | 265 }; |
264 | 266 |
265 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_H_ | 267 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_H_ |
OLD | NEW |