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 #include "chrome/browser/signin/token_service.h" | 5 #include "chrome/browser/signin/token_service.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
117 credentials_ = credentials; | 117 credentials_ = credentials; |
118 | 118 |
119 SaveAuthTokenToDB(GaiaConstants::kGaiaLsid, credentials.lsid); | 119 SaveAuthTokenToDB(GaiaConstants::kGaiaLsid, credentials.lsid); |
120 SaveAuthTokenToDB(GaiaConstants::kGaiaSid, credentials.sid); | 120 SaveAuthTokenToDB(GaiaConstants::kGaiaSid, credentials.sid); |
121 | 121 |
122 // Cancel any currently running requests. | 122 // Cancel any currently running requests. |
123 for (size_t i = 0; i < arraysize(kServices); i++) { | 123 for (size_t i = 0; i < arraysize(kServices); i++) { |
124 fetchers_[i].reset(); | 124 fetchers_[i].reset(); |
125 } | 125 } |
| 126 |
| 127 // Notify the CredentialCacheService that a new lsid and sid are available. |
| 128 FireCredentialsUpdatedNotification(credentials.lsid, credentials.sid); |
126 } | 129 } |
127 | 130 |
128 void TokenService::UpdateCredentialsWithOAuth2( | 131 void TokenService::UpdateCredentialsWithOAuth2( |
129 const GaiaAuthConsumer::ClientOAuthResult& credentials) { | 132 const GaiaAuthConsumer::ClientOAuthResult& credentials) { |
130 // Will be implemented once the ClientOAuth signin is complete. Not called | 133 // Will be implemented once the ClientOAuth signin is complete. Not called |
131 // yet by any code. | 134 // yet by any code. |
132 NOTREACHED(); | 135 NOTREACHED(); |
133 } | 136 } |
134 | 137 |
135 | 138 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 const std::string& TokenService::GetOAuth2LoginAccessToken() const { | 222 const std::string& TokenService::GetOAuth2LoginAccessToken() const { |
220 return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginAccessToken); | 223 return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginAccessToken); |
221 } | 224 } |
222 | 225 |
223 // static | 226 // static |
224 void TokenService::GetServiceNamesForTesting(std::vector<std::string>* names) { | 227 void TokenService::GetServiceNamesForTesting(std::vector<std::string>* names) { |
225 names->resize(arraysize(kServices)); | 228 names->resize(arraysize(kServices)); |
226 std::copy(kServices, kServices + arraysize(kServices), names->begin()); | 229 std::copy(kServices, kServices + arraysize(kServices), names->begin()); |
227 } | 230 } |
228 | 231 |
| 232 void TokenService::FireCredentialsUpdatedNotification( |
| 233 const std::string& lsid, |
| 234 const std::string& sid) { |
| 235 CredentialsUpdatedDetails details(lsid, sid); |
| 236 content::NotificationService::current()->Notify( |
| 237 chrome::NOTIFICATION_TOKEN_SERVICE_CREDENTIALS_UPDATED, |
| 238 content::Source<TokenService>(this), |
| 239 content::Details<const CredentialsUpdatedDetails>(&details)); |
| 240 } |
| 241 |
229 // Note that this can fire twice or more for any given service. | 242 // Note that this can fire twice or more for any given service. |
230 // It can fire once from the DB read, and then once from the initial | 243 // It can fire once from the DB read, and then once from the initial |
231 // fetcher. Future fetches can cause more notification firings. | 244 // fetcher. Future fetches can cause more notification firings. |
232 // The DB read will not however fire a notification if the fetcher | 245 // The DB read will not however fire a notification if the fetcher |
233 // returned first. So it's always safe to use the latest notification. | 246 // returned first. So it's always safe to use the latest notification. |
234 void TokenService::FireTokenAvailableNotification( | 247 void TokenService::FireTokenAvailableNotification( |
235 const std::string& service, | 248 const std::string& service, |
236 const std::string& auth_token) { | 249 const std::string& auth_token) { |
237 | 250 |
238 TokenAvailableDetails details(service, auth_token); | 251 TokenAvailableDetails details(service, auth_token); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 } | 401 } |
389 | 402 |
390 void TokenService::Observe(int type, | 403 void TokenService::Observe(int type, |
391 const content::NotificationSource& source, | 404 const content::NotificationSource& source, |
392 const content::NotificationDetails& details) { | 405 const content::NotificationDetails& details) { |
393 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); | 406 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); |
394 TokenAvailableDetails* tok_details = | 407 TokenAvailableDetails* tok_details = |
395 content::Details<TokenAvailableDetails>(details).ptr(); | 408 content::Details<TokenAvailableDetails>(details).ptr(); |
396 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); | 409 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); |
397 } | 410 } |
OLD | NEW |