| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/chromeos/login/oauth2_login_manager.h" | 5 #include "chrome/browser/chromeos/login/oauth2_login_manager.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" | 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 11 #include "chrome/browser/policy/browser_policy_connector.h" | 11 #include "chrome/browser/policy/browser_policy_connector.h" |
| 12 #include "chrome/browser/prefs/pref_registry_syncable.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/signin/token_service.h" | 15 #include "chrome/browser/signin/token_service.h" |
| 15 #include "chrome/browser/signin/token_service_factory.h" | 16 #include "chrome/browser/signin/token_service_factory.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 19 #include "google_apis/gaia/gaia_constants.h" | 20 #include "google_apis/gaia/gaia_constants.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
| 21 | 22 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, | 85 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
| 85 content::Source<TokenService>(token_service)); | 86 content::Source<TokenService>(token_service)); |
| 86 registrar_.Add(this, | 87 registrar_.Add(this, |
| 87 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 88 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| 88 content::Source<TokenService>(token_service)); | 89 content::Source<TokenService>(token_service)); |
| 89 } | 90 } |
| 90 return token_service; | 91 return token_service; |
| 91 } | 92 } |
| 92 | 93 |
| 93 void OAuth2LoginManager::RemoveLegacyTokens() { | 94 void OAuth2LoginManager::RemoveLegacyTokens() { |
| 94 PrefServiceSyncable* prefs = user_profile_->GetPrefs(); | 95 PrefService* prefs = user_profile_->GetPrefs(); |
| 95 prefs->RegisterStringPref(prefs::kOAuth1Token, | 96 // TODO(joi): Registration should only be done up front. |
| 96 "", | 97 scoped_refptr<PrefRegistrySyncable> registry( |
| 97 PrefServiceSyncable::UNSYNCABLE_PREF); | 98 static_cast<PrefRegistrySyncable*>(prefs->DeprecatedGetPrefRegistry())); |
| 98 prefs->RegisterStringPref(prefs::kOAuth1Secret, | 99 registry->RegisterStringPref(prefs::kOAuth1Token, |
| 99 "", | 100 "", |
| 100 PrefServiceSyncable::UNSYNCABLE_PREF); | 101 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 102 registry->RegisterStringPref(prefs::kOAuth1Secret, |
| 103 "", |
| 104 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 101 prefs->ClearPref(prefs::kOAuth1Token); | 105 prefs->ClearPref(prefs::kOAuth1Token); |
| 102 prefs->ClearPref(prefs::kOAuth1Secret); | 106 prefs->ClearPref(prefs::kOAuth1Secret); |
| 103 prefs->UnregisterPreference(prefs::kOAuth1Token); | 107 registry->DeprecatedUnregisterPreference(prefs::kOAuth1Token); |
| 104 prefs->UnregisterPreference(prefs::kOAuth1Secret); | 108 registry->DeprecatedUnregisterPreference(prefs::kOAuth1Secret); |
| 105 } | 109 } |
| 106 | 110 |
| 107 void OAuth2LoginManager::StoreOAuth2Tokens( | 111 void OAuth2LoginManager::StoreOAuth2Tokens( |
| 108 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { | 112 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { |
| 109 TokenService* token_service = SetupTokenService(); | 113 TokenService* token_service = SetupTokenService(); |
| 110 token_service->UpdateCredentialsWithOAuth2(oauth2_tokens); | 114 token_service->UpdateCredentialsWithOAuth2(oauth2_tokens); |
| 111 } | 115 } |
| 112 | 116 |
| 113 void OAuth2LoginManager::LoadAndVerifyOAuth2Tokens() { | 117 void OAuth2LoginManager::LoadAndVerifyOAuth2Tokens() { |
| 114 // If we have no cookies, try to load saved OAuth2 token from TokenService. | 118 // If we have no cookies, try to load saved OAuth2 token from TokenService. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 256 } |
| 253 | 257 |
| 254 void OAuth2LoginManager::StartTokenService( | 258 void OAuth2LoginManager::StartTokenService( |
| 255 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials) { | 259 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials) { |
| 256 TokenService* token_service = SetupTokenService(); | 260 TokenService* token_service = SetupTokenService(); |
| 257 token_service->UpdateCredentials(gaia_credentials); | 261 token_service->UpdateCredentials(gaia_credentials); |
| 258 CompleteAuthentication(); | 262 CompleteAuthentication(); |
| 259 } | 263 } |
| 260 | 264 |
| 261 } // namespace chromeos | 265 } // namespace chromeos |
| OLD | NEW |