Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Side by Side Diff: chrome/browser/signin/token_service.cc

Issue 11991002: Merge 176800 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1364/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/signin/token_service.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // store tokens and fetch them. Move the key-value storage out of 96 // store tokens and fetch them. Move the key-value storage out of
97 // token_service, and leave the token fetching in token_service. 97 // token_service, and leave the token fetching in token_service.
98 98
99 void TokenService::AddAuthTokenManually(const std::string& service, 99 void TokenService::AddAuthTokenManually(const std::string& service,
100 const std::string& auth_token) { 100 const std::string& auth_token) {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
102 VLOG(1) << "Got an authorization token for " << service; 102 VLOG(1) << "Got an authorization token for " << service;
103 token_map_[service] = auth_token; 103 token_map_[service] = auth_token;
104 FireTokenAvailableNotification(service, auth_token); 104 FireTokenAvailableNotification(service, auth_token);
105 SaveAuthTokenToDB(service, auth_token); 105 SaveAuthTokenToDB(service, auth_token);
106
107 #if defined(OS_CHROMEOS)
108 // We don't ever want to fetch OAuth2 tokens from LSO service token in case
109 // when ChromeOS is in forced OAuth2 use mode. OAuth2 token should only
110 // arrive into token service exclusively through UpdateCredentialsWithOAuth2.
111 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceOAuth1))
112 return;
113 #endif
114
106 // If we got ClientLogin token for "lso" service, and we don't already have 115 // If we got ClientLogin token for "lso" service, and we don't already have
107 // OAuth2 tokens, start fetching OAuth2 login scoped token pair. 116 // OAuth2 tokens, start fetching OAuth2 login scoped token pair.
108 if (service == GaiaConstants::kLSOService && !HasOAuthLoginToken()) { 117 if (service == GaiaConstants::kLSOService && !HasOAuthLoginToken()) {
109 int index = GetServiceIndex(service); 118 int index = GetServiceIndex(service);
110 CHECK_GE(index, 0); 119 CHECK_GE(index, 0);
111 fetchers_[index]->StartLsoForOAuthLoginTokenExchange(auth_token); 120 fetchers_[index]->StartLsoForOAuthLoginTokenExchange(auth_token);
112 } 121 }
113 } 122 }
114 123
115 124
(...skipping 24 matching lines...) Expand all
140 SaveAuthTokenToDB(GaiaConstants::kGaiaLsid, credentials.lsid); 149 SaveAuthTokenToDB(GaiaConstants::kGaiaLsid, credentials.lsid);
141 SaveAuthTokenToDB(GaiaConstants::kGaiaSid, credentials.sid); 150 SaveAuthTokenToDB(GaiaConstants::kGaiaSid, credentials.sid);
142 151
143 // Cancel any currently running requests. 152 // Cancel any currently running requests.
144 for (size_t i = 0; i < arraysize(kServices); i++) { 153 for (size_t i = 0; i < arraysize(kServices); i++) {
145 fetchers_[i].reset(); 154 fetchers_[i].reset();
146 } 155 }
147 } 156 }
148 157
149 void TokenService::UpdateCredentialsWithOAuth2( 158 void TokenService::UpdateCredentialsWithOAuth2(
150 const GaiaAuthConsumer::ClientOAuthResult& credentials) { 159 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) {
151 // Will be implemented once the ClientOAuth signin is complete. Not called 160 SaveOAuth2Credentials(oauth2_tokens);
152 // yet by any code.
153 NOTREACHED();
154 } 161 }
155 162
156 void TokenService::LoadTokensFromDB() { 163 void TokenService::LoadTokensFromDB() {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
158 if (web_data_service_.get()) 165 if (web_data_service_.get())
159 token_loading_query_ = web_data_service_->GetAllTokens(this); 166 token_loading_query_ = web_data_service_->GetAllTokens(this);
160 } 167 }
161 168
162 void TokenService::SaveAuthTokenToDB(const std::string& service, 169 void TokenService::SaveAuthTokenToDB(const std::string& service,
163 const std::string& auth_token) { 170 const std::string& auth_token) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // Note map[key] is not const. 232 // Note map[key] is not const.
226 return (*token_map_.find(service)).second; 233 return (*token_map_.find(service)).second;
227 } 234 }
228 return EmptyString(); 235 return EmptyString();
229 } 236 }
230 237
231 bool TokenService::HasOAuthLoginToken() const { 238 bool TokenService::HasOAuthLoginToken() const {
232 return HasTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken); 239 return HasTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken);
233 } 240 }
234 241
242 bool TokenService::HasOAuthLoginAccessToken() const {
243 return HasTokenForService(GaiaConstants::kGaiaOAuth2LoginAccessToken);
244 }
245
235 const std::string& TokenService::GetOAuth2LoginRefreshToken() const { 246 const std::string& TokenService::GetOAuth2LoginRefreshToken() const {
236 return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken); 247 return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken);
237 } 248 }
238 249
239 const std::string& TokenService::GetOAuth2LoginAccessToken() const { 250 const std::string& TokenService::GetOAuth2LoginAccessToken() const {
240 return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginAccessToken); 251 return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginAccessToken);
241 } 252 }
242 253
243 // static 254 // static
244 void TokenService::GetServiceNamesForTesting(std::vector<std::string>* names) { 255 void TokenService::GetServiceNamesForTesting(std::vector<std::string>* names) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 const GoogleServiceAuthError& error) { 316 const GoogleServiceAuthError& error) {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
307 LOG(WARNING) << "Auth token issuing failed for service:" << service 318 LOG(WARNING) << "Auth token issuing failed for service:" << service
308 << ", error: " << error.ToString(); 319 << ", error: " << error.ToString();
309 FireTokenRequestFailedNotification(service, error); 320 FireTokenRequestFailedNotification(service, error);
310 } 321 }
311 322
312 void TokenService::OnClientOAuthSuccess(const ClientOAuthResult& result) { 323 void TokenService::OnClientOAuthSuccess(const ClientOAuthResult& result) {
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
314 VLOG(1) << "Got OAuth2 login token pair"; 325 VLOG(1) << "Got OAuth2 login token pair";
326 SaveOAuth2Credentials(result);
327 }
328
329 void TokenService::SaveOAuth2Credentials(const ClientOAuthResult& result) {
315 token_map_[GaiaConstants::kGaiaOAuth2LoginRefreshToken] = 330 token_map_[GaiaConstants::kGaiaOAuth2LoginRefreshToken] =
316 result.refresh_token; 331 result.refresh_token;
317 token_map_[GaiaConstants::kGaiaOAuth2LoginAccessToken] = result.access_token; 332 token_map_[GaiaConstants::kGaiaOAuth2LoginAccessToken] = result.access_token;
333 // Save refresh token only since access token is transient anyway.
318 SaveAuthTokenToDB(GaiaConstants::kGaiaOAuth2LoginRefreshToken, 334 SaveAuthTokenToDB(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
319 result.refresh_token); 335 result.refresh_token);
320 SaveAuthTokenToDB(GaiaConstants::kGaiaOAuth2LoginAccessToken,
321 result.access_token);
322 // We don't save expiration information for now. 336 // We don't save expiration information for now.
323 337
324 FireTokenAvailableNotification(GaiaConstants::kGaiaOAuth2LoginRefreshToken, 338 FireTokenAvailableNotification(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
325 result.refresh_token); 339 result.refresh_token);
326 } 340 }
327 341
328 void TokenService::OnClientOAuthFailure( 342 void TokenService::OnClientOAuthFailure(
329 const GoogleServiceAuthError& error) { 343 const GoogleServiceAuthError& error) {
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
331 LOG(WARNING) << "OAuth2 login token pair fetch failed: " << error.ToString(); 345 LOG(WARNING) << "OAuth2 login token pair fetch failed: " << error.ToString();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 if (!in_memory_tokens->count(service) && db_tokens.count(service)) { 428 if (!in_memory_tokens->count(service) && db_tokens.count(service)) {
415 std::string db_token = db_tokens.find(service)->second; 429 std::string db_token = db_tokens.find(service)->second;
416 if (!db_token.empty()) { 430 if (!db_token.empty()) {
417 VLOG(1) << "Loading " << service << " token from DB: " << db_token; 431 VLOG(1) << "Loading " << service << " token from DB: " << db_token;
418 (*in_memory_tokens)[service] = db_token; 432 (*in_memory_tokens)[service] = db_token;
419 FireTokenAvailableNotification(service, db_token); 433 FireTokenAvailableNotification(service, db_token);
420 // Failures are only for network errors. 434 // Failures are only for network errors.
421 } 435 }
422 } 436 }
423 } 437 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/token_service.h ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698