| 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/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 14 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
| 14 #include "chrome/common/net/gaia/gaia_constants.h" | 15 #include "chrome/common/net/gaia/gaia_constants.h" |
| 16 #include "chrome/common/pref_names.h" |
| 15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 19 | 21 |
| 20 using content::BrowserThread; | 22 using content::BrowserThread; |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 // List of services that are capable of ClientLogin-based authentication. | 26 // List of services that are capable of ClientLogin-based authentication. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 61 } |
| 60 DCHECK(!profile_); | 62 DCHECK(!profile_); |
| 61 profile_ = profile; | 63 profile_ = profile; |
| 62 getter_ = profile->GetRequestContext(); | 64 getter_ = profile->GetRequestContext(); |
| 63 // Since the user can create a bookmark in incognito, sync may be running. | 65 // Since the user can create a bookmark in incognito, sync may be running. |
| 64 // Thus we have to go for explicit access. | 66 // Thus we have to go for explicit access. |
| 65 web_data_service_ = profile->GetWebDataService(Profile::EXPLICIT_ACCESS); | 67 web_data_service_ = profile->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 66 source_ = std::string(source); | 68 source_ = std::string(source); |
| 67 | 69 |
| 68 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 70 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 69 // Allow the token service to be cleared from the command line. | 71 // Allow the token service to be cleared from the command line. We rely on |
| 72 // SigninManager::Initialize() being called to clear out the |
| 73 // kGoogleServicesUsername pref before we call EraseTokensFromDB() as |
| 74 // otherwise the system would be in an invalid state. |
| 70 if (cmd_line->HasSwitch(switches::kClearTokenService)) | 75 if (cmd_line->HasSwitch(switches::kClearTokenService)) |
| 71 EraseTokensFromDB(); | 76 EraseTokensFromDB(); |
| 72 | 77 |
| 73 // Allow a token to be injected from the command line. | 78 // Allow a token to be injected from the command line. |
| 74 if (cmd_line->HasSwitch(switches::kSetToken)) { | 79 if (cmd_line->HasSwitch(switches::kSetToken)) { |
| 75 std::string value = cmd_line->GetSwitchValueASCII(switches::kSetToken); | 80 std::string value = cmd_line->GetSwitchValueASCII(switches::kSetToken); |
| 76 int separator = value.find(':'); | 81 int separator = value.find(':'); |
| 77 std::string service = value.substr(0, separator); | 82 std::string service = value.substr(0, separator); |
| 78 std::string token = value.substr(separator + 1); | 83 std::string token = value.substr(separator + 1); |
| 79 token_map_[service] = token; | 84 token_map_[service] = token; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 131 |
| 127 void TokenService::SaveAuthTokenToDB(const std::string& service, | 132 void TokenService::SaveAuthTokenToDB(const std::string& service, |
| 128 const std::string& auth_token) { | 133 const std::string& auth_token) { |
| 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 130 if (web_data_service_.get()) | 135 if (web_data_service_.get()) |
| 131 web_data_service_->SetTokenForService(service, auth_token); | 136 web_data_service_->SetTokenForService(service, auth_token); |
| 132 } | 137 } |
| 133 | 138 |
| 134 void TokenService::EraseTokensFromDB() { | 139 void TokenService::EraseTokensFromDB() { |
| 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 141 // Try to track down http://crbug.com/121755 - we should never clear the |
| 142 // token DB while we're still logged in. |
| 143 if (profile_) { |
| 144 std::string user = profile_->GetPrefs()->GetString( |
| 145 prefs::kGoogleServicesUsername); |
| 146 CHECK(user.empty()); |
| 147 } |
| 136 if (web_data_service_.get()) | 148 if (web_data_service_.get()) |
| 137 web_data_service_->RemoveAllTokens(); | 149 web_data_service_->RemoveAllTokens(); |
| 138 } | 150 } |
| 139 | 151 |
| 140 bool TokenService::TokensLoadedFromDB() const { | 152 bool TokenService::TokensLoadedFromDB() const { |
| 141 return tokens_loaded_; | 153 return tokens_loaded_; |
| 142 } | 154 } |
| 143 | 155 |
| 144 // static | 156 // static |
| 145 int TokenService::GetServiceIndex(const std::string& service) { | 157 int TokenService::GetServiceIndex(const std::string& service) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 373 } |
| 362 | 374 |
| 363 void TokenService::Observe(int type, | 375 void TokenService::Observe(int type, |
| 364 const content::NotificationSource& source, | 376 const content::NotificationSource& source, |
| 365 const content::NotificationDetails& details) { | 377 const content::NotificationDetails& details) { |
| 366 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); | 378 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); |
| 367 TokenAvailableDetails* tok_details = | 379 TokenAvailableDetails* tok_details = |
| 368 content::Details<TokenAvailableDetails>(details).ptr(); | 380 content::Details<TokenAvailableDetails>(details).ptr(); |
| 369 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); | 381 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); |
| 370 } | 382 } |
| OLD | NEW |