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 #include "chrome/browser/net/gaia/token_service.h" | 5 #include "chrome/browser/net/gaia/token_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 12 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
13 #include "chrome/common/net/gaia/gaia_constants.h" | 13 #include "chrome/common/net/gaia/gaia_constants.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
17 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
18 | 18 |
19 using content::BrowserThread; | 19 using content::BrowserThread; |
20 | 20 |
21 // Unfortunately kNumServices must be defined in the .h. | 21 // Unfortunately kNumServices must be defined in the .h. |
22 // TODO(chron): Sync doesn't use the TalkToken anymore so we can stop | 22 // TODO(chron): Sync doesn't use the TalkToken anymore so we can stop |
23 // requesting it. | 23 // requesting it. |
24 const char* TokenService::kServices[] = { | 24 const char* TokenService::kServices[] = { |
25 GaiaConstants::kPicasaService, | 25 GaiaConstants::kPicasaService, |
26 GaiaConstants::kGaiaService, | 26 GaiaConstants::kGaiaService, |
27 GaiaConstants::kSyncService, | 27 GaiaConstants::kSyncService, |
28 GaiaConstants::kTalkService, | 28 GaiaConstants::kTalkService, |
29 GaiaConstants::kDeviceManagementService, | 29 GaiaConstants::kDeviceManagementService, |
30 GaiaConstants::kCWSService, | |
31 GaiaConstants::kLSOService, | 30 GaiaConstants::kLSOService, |
32 }; | 31 }; |
33 | 32 |
34 const char* kUnusedServiceScope = "unused-service-scope"; | 33 const char* kUnusedServiceScope = "unused-service-scope"; |
35 | 34 |
36 // Unfortunately kNumOAuthServices must be defined in the .h. | 35 // Unfortunately kNumOAuthServices must be defined in the .h. |
37 // For OAuth, Chrome uses the OAuth2 service scope as the service name. | 36 // For OAuth, Chrome uses the OAuth2 service scope as the service name. |
38 const char* TokenService::kOAuthServices[] = { | 37 const char* TokenService::kOAuthServices[] = { |
39 GaiaConstants::kSyncServiceOAuth, | 38 GaiaConstants::kSyncServiceOAuth, |
40 }; | 39 }; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
198 DCHECK(AreCredentialsValid()); | 197 DCHECK(AreCredentialsValid()); |
199 for (int i = 0; i < kNumServices; i++) { | 198 for (int i = 0; i < kNumServices; i++) { |
200 fetchers_[i].reset(new GaiaAuthFetcher(this, source_, getter_)); | 199 fetchers_[i].reset(new GaiaAuthFetcher(this, source_, getter_)); |
201 fetchers_[i]->StartIssueAuthToken(credentials_.sid, | 200 fetchers_[i]->StartIssueAuthToken(credentials_.sid, |
202 credentials_.lsid, | 201 credentials_.lsid, |
203 kServices[i]); | 202 kServices[i]); |
204 } | 203 } |
205 } | 204 } |
206 | 205 |
207 void TokenService::StartFetchingMissingTokens() { | |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
209 DCHECK(AreCredentialsValid()); | |
210 for (int i = 0; i < kNumServices; i++) { | |
211 // if token exists for a service, skip for that service. | |
212 if (HasTokenForService(kServices[i])) | |
213 continue; | |
214 | |
215 fetchers_[i].reset(new GaiaAuthFetcher(this, source_, getter_)); | |
216 fetchers_[i]->StartIssueAuthToken(credentials_.sid, | |
217 credentials_.lsid, | |
218 kServices[i]); | |
219 } | |
220 } | |
221 | |
222 void TokenService::StartFetchingOAuthTokens() { | 206 void TokenService::StartFetchingOAuthTokens() { |
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
224 DCHECK(HasOAuthCredentials()); | 208 DCHECK(HasOAuthCredentials()); |
225 for (int i = 0; i < kNumOAuthServices; i++) { | 209 for (int i = 0; i < kNumOAuthServices; i++) { |
226 oauth_fetchers_[i].reset( | 210 oauth_fetchers_[i].reset( |
227 new GaiaOAuthFetcher(this, getter_, profile_, kUnusedServiceScope)); | 211 new GaiaOAuthFetcher(this, getter_, profile_, kUnusedServiceScope)); |
228 oauth_fetchers_[i]->StartOAuthWrapBridge(oauth_token_, | 212 oauth_fetchers_[i]->StartOAuthWrapBridge(oauth_token_, |
229 oauth_secret_, | 213 oauth_secret_, |
230 GaiaConstants::kGaiaOAuthDuration, | 214 GaiaConstants::kGaiaOAuthDuration, |
231 kOAuthServices[i]); | 215 kOAuthServices[i]); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 458 } |
475 | 459 |
476 void TokenService::Observe(int type, | 460 void TokenService::Observe(int type, |
477 const content::NotificationSource& source, | 461 const content::NotificationSource& source, |
478 const content::NotificationDetails& details) { | 462 const content::NotificationDetails& details) { |
479 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); | 463 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); |
480 TokenAvailableDetails* tok_details = | 464 TokenAvailableDetails* tok_details = |
481 content::Details<TokenAvailableDetails>(details).ptr(); | 465 content::Details<TokenAvailableDetails>(details).ptr(); |
482 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); | 466 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); |
483 } | 467 } |
OLD | NEW |