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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 TokenRequestFailedDetails(const std::string& service, | 87 TokenRequestFailedDetails(const std::string& service, |
88 const GoogleServiceAuthError& error) | 88 const GoogleServiceAuthError& error) |
89 : service_(service), error_(error) {} | 89 : service_(service), error_(error) {} |
90 const std::string& service() const { return service_; } | 90 const std::string& service() const { return service_; } |
91 const GoogleServiceAuthError& error() const { return error_; } | 91 const GoogleServiceAuthError& error() const { return error_; } |
92 private: | 92 private: |
93 std::string service_; | 93 std::string service_; |
94 GoogleServiceAuthError error_; | 94 GoogleServiceAuthError error_; |
95 }; | 95 }; |
96 | 96 |
| 97 class CredentialsUpdatedDetails { |
| 98 public: |
| 99 CredentialsUpdatedDetails(const std::string& lsid, |
| 100 const std::string& sid) |
| 101 : lsid_(lsid), sid_(sid) {} |
| 102 const std::string& lsid() const { return lsid_; } |
| 103 const std::string& sid() const { return sid_; } |
| 104 private: |
| 105 std::string lsid_; |
| 106 std::string sid_; |
| 107 }; |
| 108 |
97 // Initialize this token service with a request source | 109 // Initialize this token service with a request source |
98 // (usually from a GaiaAuthConsumer constant), and the profile. | 110 // (usually from a GaiaAuthConsumer constant), and the profile. |
99 // Typically you'd then update the credentials. | 111 // Typically you'd then update the credentials. |
100 void Initialize(const char* const source, Profile* profile); | 112 void Initialize(const char* const source, Profile* profile); |
101 | 113 |
102 // Used to determine whether Initialize() has been called. | 114 // Used to determine whether Initialize() has been called. |
103 bool Initialized() const { return !source_.empty(); } | 115 bool Initialized() const { return !source_.empty(); } |
104 | 116 |
105 // Update ClientLogin credentials in the token service. | 117 // Update ClientLogin credentials in the token service. |
106 // Afterwards you can StartFetchingTokens. | 118 // Afterwards you can StartFetchingTokens. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 virtual void Observe(int type, | 187 virtual void Observe(int type, |
176 const content::NotificationSource& source, | 188 const content::NotificationSource& source, |
177 const content::NotificationDetails& details) OVERRIDE; | 189 const content::NotificationDetails& details) OVERRIDE; |
178 | 190 |
179 private: | 191 private: |
180 | 192 |
181 // Gets the list of all service names for which tokens will be retrieved. | 193 // Gets the list of all service names for which tokens will be retrieved. |
182 // This method is meant only for tests. | 194 // This method is meant only for tests. |
183 static void GetServiceNamesForTesting(std::vector<std::string>* names); | 195 static void GetServiceNamesForTesting(std::vector<std::string>* names); |
184 | 196 |
| 197 void FireCredentialsUpdatedNotification(const std::string& lsid, |
| 198 const std::string& sid); |
| 199 |
185 void FireTokenAvailableNotification(const std::string& service, | 200 void FireTokenAvailableNotification(const std::string& service, |
186 const std::string& auth_token); | 201 const std::string& auth_token); |
187 | 202 |
188 void FireTokenRequestFailedNotification(const std::string& service, | 203 void FireTokenRequestFailedNotification(const std::string& service, |
189 const GoogleServiceAuthError& error); | 204 const GoogleServiceAuthError& error); |
190 | 205 |
191 void LoadTokensIntoMemory( | 206 void LoadTokensIntoMemory( |
192 const std::map<std::string, std::string>& db_tokens, | 207 const std::map<std::string, std::string>& db_tokens, |
193 std::map<std::string, std::string>* in_memory_tokens); | 208 std::map<std::string, std::string>* in_memory_tokens); |
194 void LoadSingleTokenIntoMemory( | 209 void LoadSingleTokenIntoMemory( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 248 |
234 friend class TokenServiceTest; | 249 friend class TokenServiceTest; |
235 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryBasic); | 250 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryBasic); |
236 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryAdvanced); | 251 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, LoadTokensIntoMemoryAdvanced); |
237 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, FullIntegrationNewServicesAdded); | 252 FRIEND_TEST_ALL_PREFIXES(TokenServiceTest, FullIntegrationNewServicesAdded); |
238 | 253 |
239 DISALLOW_COPY_AND_ASSIGN(TokenService); | 254 DISALLOW_COPY_AND_ASSIGN(TokenService); |
240 }; | 255 }; |
241 | 256 |
242 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_H_ | 257 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_H_ |
OLD | NEW |