Chromium Code Reviews| 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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 if (cmd_line->HasSwitch(switches::kSetToken)) { | 93 if (cmd_line->HasSwitch(switches::kSetToken)) { |
| 94 std::string value = cmd_line->GetSwitchValueASCII(switches::kSetToken); | 94 std::string value = cmd_line->GetSwitchValueASCII(switches::kSetToken); |
| 95 int separator = value.find(':'); | 95 int separator = value.find(':'); |
| 96 std::string service = value.substr(0, separator); | 96 std::string service = value.substr(0, separator); |
| 97 std::string token = value.substr(separator + 1); | 97 std::string token = value.substr(separator + 1); |
| 98 token_map_[service] = token; | 98 token_map_[service] = token; |
| 99 SaveAuthTokenToDB(service, token); | 99 SaveAuthTokenToDB(service, token); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 // TODO(petewil) We should refactor the token_service so it does not both | |
| 104 // store tokens and fetch them. Move the key-value storage out of | |
| 105 // token_service, and leave the token fetching in token_service. | |
| 106 | |
| 107 void TokenService::AddAuthTokenManually(const std::string& service, | |
|
Andrew T Wilson (Slow)
2013/03/01 17:50:54
I think we should keep this code as it's the prima
Pete Williamson
2013/03/04 18:32:53
Done.
| |
| 108 const std::string& auth_token) { | |
| 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 110 VLOG(1) << "Got an authorization token for " << service; | |
| 111 token_map_[service] = auth_token; | |
| 112 FireTokenAvailableNotification(service, auth_token); | |
| 113 SaveAuthTokenToDB(service, auth_token); | |
| 114 | |
| 115 // We don't ever want to fetch OAuth2 tokens from LSO service token in case | |
| 116 // when ChromeOS is in forced OAuth2 use mode. OAuth2 token should only | |
| 117 // arrive into token service exclusively through UpdateCredentialsWithOAuth2. | |
| 118 #if !defined(OS_CHROMEOS) | |
| 119 // If we got ClientLogin token for "lso" service, and we don't already have | |
| 120 // OAuth2 tokens, start fetching OAuth2 login scoped token pair. | |
| 121 if (service == GaiaConstants::kLSOService && !HasOAuthLoginToken()) { | |
| 122 int index = GetServiceIndex(service); | |
| 123 CHECK_GE(index, 0); | |
| 124 fetchers_[index]->StartLsoForOAuthLoginTokenExchange(auth_token); | |
| 125 } | |
| 126 #endif | |
| 127 } | |
| 128 | |
| 129 | |
| 130 void TokenService::ResetCredentialsInMemory() { | 103 void TokenService::ResetCredentialsInMemory() { |
| 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 132 | 105 |
| 133 // Terminate any running fetchers. Callbacks will not return. | 106 // Terminate any running fetchers. Callbacks will not return. |
| 134 for (size_t i = 0; i < arraysize(kServices); ++i) { | 107 for (size_t i = 0; i < arraysize(kServices); ++i) { |
| 135 fetchers_[i].reset(); | 108 fetchers_[i].reset(); |
| 136 } | 109 } |
| 137 | 110 |
| 138 // Cancel pending loads. Callbacks will not return. | 111 // Cancel pending loads. Callbacks will not return. |
| 139 if (token_loading_query_) { | 112 if (token_loading_query_) { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 void TokenService::IssueAuthTokenForTest(const std::string& service, | 299 void TokenService::IssueAuthTokenForTest(const std::string& service, |
| 327 const std::string& auth_token) { | 300 const std::string& auth_token) { |
| 328 token_map_[service] = auth_token; | 301 token_map_[service] = auth_token; |
| 329 FireTokenAvailableNotification(service, auth_token); | 302 FireTokenAvailableNotification(service, auth_token); |
| 330 } | 303 } |
| 331 | 304 |
| 332 void TokenService::OnIssueAuthTokenSuccess(const std::string& service, | 305 void TokenService::OnIssueAuthTokenSuccess(const std::string& service, |
| 333 const std::string& auth_token) { | 306 const std::string& auth_token) { |
| 334 FOR_DIAGNOSTICS_OBSERVERS( | 307 FOR_DIAGNOSTICS_OBSERVERS( |
| 335 NotifyTokenReceivedSuccess(service, auth_token, true)); | 308 NotifyTokenReceivedSuccess(service, auth_token, true)); |
| 336 AddAuthTokenManually(service, auth_token); | 309 |
| 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 311 VLOG(1) << "Got an authorization token for " << service; | |
| 312 token_map_[service] = auth_token; | |
| 313 FireTokenAvailableNotification(service, auth_token); | |
| 314 SaveAuthTokenToDB(service, auth_token); | |
| 315 | |
| 316 // We don't ever want to fetch OAuth2 tokens from LSO service token in case | |
| 317 // when ChromeOS is in forced OAuth2 use mode. OAuth2 token should only | |
| 318 // arrive into token service exclusively through UpdateCredentialsWithOAuth2. | |
| 319 #if !defined(OS_CHROMEOS) | |
| 320 // If we got ClientLogin token for "lso" service, and we don't already have | |
| 321 // OAuth2 tokens, start fetching OAuth2 login scoped token pair. | |
| 322 if (service == GaiaConstants::kLSOService && !HasOAuthLoginToken()) { | |
| 323 int index = GetServiceIndex(service); | |
| 324 CHECK_GE(index, 0); | |
| 325 fetchers_[index]->StartLsoForOAuthLoginTokenExchange(auth_token); | |
| 326 } | |
| 327 #endif | |
| 337 } | 328 } |
| 338 | 329 |
| 339 void TokenService::OnIssueAuthTokenFailure(const std::string& service, | 330 void TokenService::OnIssueAuthTokenFailure(const std::string& service, |
| 340 const GoogleServiceAuthError& error) { | 331 const GoogleServiceAuthError& error) { |
| 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 342 LOG(WARNING) << "Auth token issuing failed for service:" << service | 333 LOG(WARNING) << "Auth token issuing failed for service:" << service |
| 343 << ", error: " << error.ToString(); | 334 << ", error: " << error.ToString(); |
| 344 FOR_DIAGNOSTICS_OBSERVERS( | 335 FOR_DIAGNOSTICS_OBSERVERS( |
| 345 NotifyTokenReceivedFailure(service, error.ToString())); | 336 NotifyTokenReceivedFailure(service, error.ToString())); |
| 346 FireTokenRequestFailedNotification(service, error); | 337 FireTokenRequestFailedNotification(service, error); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 DCHECK(NULL == fetchers_[i].get()); | 404 DCHECK(NULL == fetchers_[i].get()); |
| 414 } | 405 } |
| 415 | 406 |
| 416 for (size_t i = 0; i < arraysize(kServices); i++) { | 407 for (size_t i = 0; i < arraysize(kServices); i++) { |
| 417 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kServices[i]); | 408 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kServices[i]); |
| 418 } | 409 } |
| 419 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, | 410 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, |
| 420 GaiaConstants::kGaiaOAuth2LoginRefreshToken); | 411 GaiaConstants::kGaiaOAuth2LoginRefreshToken); |
| 421 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, | 412 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, |
| 422 GaiaConstants::kGaiaOAuth2LoginAccessToken); | 413 GaiaConstants::kGaiaOAuth2LoginAccessToken); |
| 423 // TODO(petewil): Remove next line when we refactor key-value | |
| 424 // storage out of token_service. | |
| 425 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, | |
| 426 GaiaConstants::kObfuscatedGaiaId); | |
| 427 | 414 |
| 428 if (credentials_.lsid.empty() && credentials_.sid.empty()) { | 415 if (credentials_.lsid.empty() && credentials_.sid.empty()) { |
| 429 // Look for GAIA SID and LSID tokens. If we have both, and the current | 416 // Look for GAIA SID and LSID tokens. If we have both, and the current |
| 430 // crendentials are empty, update the credentials. | 417 // crendentials are empty, update the credentials. |
| 431 std::string lsid; | 418 std::string lsid; |
| 432 std::string sid; | 419 std::string sid; |
| 433 | 420 |
| 434 if (db_tokens.count(GaiaConstants::kGaiaLsid) > 0) | 421 if (db_tokens.count(GaiaConstants::kGaiaLsid) > 0) |
| 435 lsid = db_tokens.find(GaiaConstants::kGaiaLsid)->second; | 422 lsid = db_tokens.find(GaiaConstants::kGaiaLsid)->second; |
| 436 | 423 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 | 467 |
| 481 void TokenService::AddSigninDiagnosticsObserver( | 468 void TokenService::AddSigninDiagnosticsObserver( |
| 482 SigninDiagnosticsObserver* observer) { | 469 SigninDiagnosticsObserver* observer) { |
| 483 signin_diagnostics_observers_.AddObserver(observer); | 470 signin_diagnostics_observers_.AddObserver(observer); |
| 484 } | 471 } |
| 485 | 472 |
| 486 void TokenService::RemoveSigninDiagnosticsObserver( | 473 void TokenService::RemoveSigninDiagnosticsObserver( |
| 487 SigninDiagnosticsObserver* observer) { | 474 SigninDiagnosticsObserver* observer) { |
| 488 signin_diagnostics_observers_.RemoveObserver(observer); | 475 signin_diagnostics_observers_.RemoveObserver(observer); |
| 489 } | 476 } |
| OLD | NEW |