OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 44 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
45 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" | 45 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" |
46 #include "chrome/browser/webdata/web_data_service.h" | 46 #include "chrome/browser/webdata/web_data_service.h" |
47 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 47 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
48 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 48 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
49 #include "chrome/common/net/gaia/google_service_auth_error.h" | 49 #include "chrome/common/net/gaia/google_service_auth_error.h" |
50 #include "content/public/browser/notification_observer.h" | 50 #include "content/public/browser/notification_observer.h" |
51 #include "content/public/browser/notification_registrar.h" | 51 #include "content/public/browser/notification_registrar.h" |
52 | 52 |
53 class Profile; | 53 class Profile; |
54 class TokenServiceTest; | |
54 | 55 |
55 namespace net { | 56 namespace net { |
56 class URLRequestContextGetter; | 57 class URLRequestContextGetter; |
57 } | 58 } |
58 | 59 |
59 // The TokenService is a Profile member, so all calls are expected | 60 // The TokenService is a Profile member, so all calls are expected |
60 // from the UI thread. | 61 // from the UI thread. |
61 class TokenService : public GaiaAuthConsumer, | 62 class TokenService : public GaiaAuthConsumer, |
62 public GaiaOAuthConsumer, | 63 public GaiaOAuthConsumer, |
63 public WebDataServiceConsumer, | 64 public WebDataServiceConsumer, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 // Results come back via event channel. Services can also poll before events | 148 // Results come back via event channel. Services can also poll before events |
148 // are issued. | 149 // are issued. |
149 void StartFetchingTokens(); | 150 void StartFetchingTokens(); |
150 // Fetch tokens for only those services for which we are missing tokens. | 151 // Fetch tokens for only those services for which we are missing tokens. |
151 // This can happen when new services are added in new Chrome versions and the | 152 // This can happen when new services are added in new Chrome versions and the |
152 // user is already logged in. | 153 // user is already logged in. |
153 void StartFetchingMissingTokens(); | 154 void StartFetchingMissingTokens(); |
154 void StartFetchingOAuthTokens(); | 155 void StartFetchingOAuthTokens(); |
155 virtual bool HasTokenForService(const char* service) const; | 156 virtual bool HasTokenForService(const char* service) const; |
156 const std::string& GetTokenForService(const char* const service) const; | 157 const std::string& GetTokenForService(const char* const service) const; |
158 virtual bool HasOAuthLoginToken() const; | |
Rick Campbell
2011/11/28 22:51:07
I think that these should not be singled out for s
Munjal (Google)
2011/11/28 23:41:14
These methods are more like OAuth1 methods and les
| |
159 const std::string& GetOAuth2LoginRefreshToken() const; | |
160 const std::string& GetOAuth2LoginAccessToken() const; | |
157 | 161 |
158 // For tests only. Doesn't save to the WebDB. | 162 // For tests only. Doesn't save to the WebDB. |
159 void IssueAuthTokenForTest(const std::string& service, | 163 void IssueAuthTokenForTest(const std::string& service, |
160 const std::string& auth_token); | 164 const std::string& auth_token); |
161 | 165 |
162 // GaiaAuthConsumer implementation. | 166 // GaiaAuthConsumer implementation. |
163 virtual void OnIssueAuthTokenSuccess(const std::string& service, | 167 virtual void OnIssueAuthTokenSuccess(const std::string& service, |
164 const std::string& auth_token) OVERRIDE; | 168 const std::string& auth_token) OVERRIDE; |
165 virtual void OnIssueAuthTokenFailure( | 169 virtual void OnIssueAuthTokenFailure( |
166 const std::string& service, | 170 const std::string& service, |
167 const GoogleServiceAuthError& error) OVERRIDE; | 171 const GoogleServiceAuthError& error) OVERRIDE; |
172 virtual void OnOAuthLoginTokenSuccess(const std::string& refresh_token, | |
173 const std::string& access_token, | |
174 int expires_in_secs) OVERRIDE; | |
175 virtual void OnOAuthLoginTokenFailure(const GoogleServiceAuthError& error) | |
176 OVERRIDE; | |
168 | 177 |
169 // GaiaOAuthConsumer implementation. | 178 // GaiaOAuthConsumer implementation. |
170 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token, | 179 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token, |
171 const std::string& secret) OVERRIDE; | 180 const std::string& secret) OVERRIDE; |
172 virtual void OnOAuthGetAccessTokenFailure( | 181 virtual void OnOAuthGetAccessTokenFailure( |
173 const GoogleServiceAuthError& error) OVERRIDE; | 182 const GoogleServiceAuthError& error) OVERRIDE; |
174 | 183 |
175 virtual void OnOAuthWrapBridgeSuccess(const std::string& service_scope, | 184 virtual void OnOAuthWrapBridgeSuccess(const std::string& service_scope, |
176 const std::string& token, | 185 const std::string& token, |
177 const std::string& expires_in) OVERRIDE; | 186 const std::string& expires_in) OVERRIDE; |
(...skipping 12 matching lines...) Expand all Loading... | |
190 const content::NotificationDetails& details) OVERRIDE; | 199 const content::NotificationDetails& details) OVERRIDE; |
191 | 200 |
192 private: | 201 private: |
193 | 202 |
194 void FireTokenAvailableNotification(const std::string& service, | 203 void FireTokenAvailableNotification(const std::string& service, |
195 const std::string& auth_token); | 204 const std::string& auth_token); |
196 | 205 |
197 void FireTokenRequestFailedNotification(const std::string& service, | 206 void FireTokenRequestFailedNotification(const std::string& service, |
198 const GoogleServiceAuthError& error); | 207 const GoogleServiceAuthError& error); |
199 | 208 |
200 void LoadTokensIntoMemory(const std::map<std::string, std::string>& in_toks, | 209 void LoadTokensIntoMemory( |
201 std::map<std::string, std::string>* out_toks); | 210 const std::map<std::string, std::string>& db_tokens, |
211 std::map<std::string, std::string>* in_memory_tokens); | |
212 void LoadSingleTokenIntoMemory( | |
213 const std::map<std::string, std::string>& db_tokens, | |
214 std::map<std::string, std::string>* in_memory_tokens, | |
215 const std::string& service); | |
202 | 216 |
203 void SaveAuthTokenToDB(const std::string& service, | 217 void SaveAuthTokenToDB(const std::string& service, |
204 const std::string& auth_token); | 218 const std::string& auth_token); |
205 | 219 |
220 // Returns the index of the given service. | |
221 static int GetServiceIndex(const std::string& service); | |
222 | |
206 // The profile with which this instance was initialized, or NULL. | 223 // The profile with which this instance was initialized, or NULL. |
207 Profile* profile_; | 224 Profile* profile_; |
208 | 225 |
209 // Web data service to access tokens from. | 226 // Web data service to access tokens from. |
210 scoped_refptr<WebDataService> web_data_service_; | 227 scoped_refptr<WebDataService> web_data_service_; |
211 // Getter to use for fetchers. | 228 // Getter to use for fetchers. |
212 scoped_refptr<net::URLRequestContextGetter> getter_; | 229 scoped_refptr<net::URLRequestContextGetter> getter_; |
213 // Request handle to load Gaia tokens from DB. | 230 // Request handle to load Gaia tokens from DB. |
214 WebDataService::Handle token_loading_query_; | 231 WebDataService::Handle token_loading_query_; |
215 | 232 |
(...skipping 29 matching lines...) Expand all Loading... | |
245 static const char* kOAuthServices[kNumOAuthServices]; | 262 static const char* kOAuthServices[kNumOAuthServices]; |
246 // A bunch of fetchers suitable for OAuth token issuing. We don't care about | 263 // A bunch of fetchers suitable for OAuth token issuing. We don't care about |
247 // the ordering, nor do we care which is for which service. | 264 // the ordering, nor do we care which is for which service. |
248 scoped_ptr<GaiaOAuthFetcher> oauth_fetchers_[kNumOAuthServices]; | 265 scoped_ptr<GaiaOAuthFetcher> oauth_fetchers_[kNumOAuthServices]; |
249 | 266 |
250 // Map from service to token. | 267 // Map from service to token. |
251 std::map<std::string, std::string> token_map_; | 268 std::map<std::string, std::string> token_map_; |
252 | 269 |
253 content::NotificationRegistrar registrar_; | 270 content::NotificationRegistrar registrar_; |
254 | 271 |
272 friend class TokenServiceTest; | |
255 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryBasic); | 273 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryBasic); |
256 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryAdvanced); | 274 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryAdvanced); |
257 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, FullIntegrationNewServicesAdded); | 275 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, FullIntegrationNewServicesAdded); |
258 | 276 |
259 DISALLOW_COPY_AND_ASSIGN(TokenService); | 277 DISALLOW_COPY_AND_ASSIGN(TokenService); |
260 }; | 278 }; |
261 | 279 |
262 #endif // CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_H_ | 280 #endif // CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_H_ |
OLD | NEW |