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, | 103 void TokenService::AddAuthTokenManually(const std::string& service, |
108 const std::string& auth_token) { | 104 const std::string& auth_token) { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
110 VLOG(1) << "Got an authorization token for " << service; | 106 VLOG(1) << "Got an authorization token for " << service; |
111 token_map_[service] = auth_token; | 107 token_map_[service] = auth_token; |
112 FireTokenAvailableNotification(service, auth_token); | 108 FireTokenAvailableNotification(service, auth_token); |
113 SaveAuthTokenToDB(service, auth_token); | 109 SaveAuthTokenToDB(service, auth_token); |
114 | 110 |
115 // We don't ever want to fetch OAuth2 tokens from LSO service token in case | 111 // 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 | 112 // when ChromeOS is in forced OAuth2 use mode. OAuth2 token should only |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // tokens from the DB into memory. | 394 // tokens from the DB into memory. |
399 for (size_t i = 0; i < arraysize(kServices); ++i) { | 395 for (size_t i = 0; i < arraysize(kServices); ++i) { |
400 DCHECK(NULL == fetchers_[i].get()); | 396 DCHECK(NULL == fetchers_[i].get()); |
401 } | 397 } |
402 | 398 |
403 for (size_t i = 0; i < arraysize(kServices); i++) { | 399 for (size_t i = 0; i < arraysize(kServices); i++) { |
404 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kServices[i]); | 400 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kServices[i]); |
405 } | 401 } |
406 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, | 402 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, |
407 GaiaConstants::kGaiaOAuth2LoginRefreshToken); | 403 GaiaConstants::kGaiaOAuth2LoginRefreshToken); |
408 // TODO(petewil): Remove next line when we refactor key-value | |
409 // storage out of token_service - http://crbug.com/177125. | |
410 LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, | |
411 GaiaConstants::kObfuscatedGaiaId); | |
412 | 404 |
413 if (credentials_.lsid.empty() && credentials_.sid.empty()) { | 405 if (credentials_.lsid.empty() && credentials_.sid.empty()) { |
414 // Look for GAIA SID and LSID tokens. If we have both, and the current | 406 // Look for GAIA SID and LSID tokens. If we have both, and the current |
415 // crendentials are empty, update the credentials. | 407 // crendentials are empty, update the credentials. |
416 std::string lsid; | 408 std::string lsid; |
417 std::string sid; | 409 std::string sid; |
418 | 410 |
419 if (db_tokens.count(GaiaConstants::kGaiaLsid) > 0) | 411 if (db_tokens.count(GaiaConstants::kGaiaLsid) > 0) |
420 lsid = db_tokens.find(GaiaConstants::kGaiaLsid)->second; | 412 lsid = db_tokens.find(GaiaConstants::kGaiaLsid)->second; |
421 | 413 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 457 |
466 void TokenService::AddSigninDiagnosticsObserver( | 458 void TokenService::AddSigninDiagnosticsObserver( |
467 SigninDiagnosticsObserver* observer) { | 459 SigninDiagnosticsObserver* observer) { |
468 signin_diagnostics_observers_.AddObserver(observer); | 460 signin_diagnostics_observers_.AddObserver(observer); |
469 } | 461 } |
470 | 462 |
471 void TokenService::RemoveSigninDiagnosticsObserver( | 463 void TokenService::RemoveSigninDiagnosticsObserver( |
472 SigninDiagnosticsObserver* observer) { | 464 SigninDiagnosticsObserver* observer) { |
473 signin_diagnostics_observers_.RemoveObserver(observer); | 465 signin_diagnostics_observers_.RemoveObserver(observer); |
474 } | 466 } |
OLD | NEW |