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

Side by Side Diff: chrome/browser/sync/signin_manager.cc

Issue 8515030: Do not clear tokens from db when the user enters new credentials. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 9 years, 1 month 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/sync/signin_manager.h ('k') | chrome/browser/sync/signin_manager_unittest.cc » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/sync/signin_manager.h" 5 #include "chrome/browser/sync/signin_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/net/gaia/token_service.h" 9 #include "chrome/browser/net/gaia/token_service.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 if (browser_sync::IsUsingOAuth()) 73 if (browser_sync::IsUsingOAuth())
74 oauth_username_ = username; 74 oauth_username_ = username;
75 else 75 else
76 username_ = username; 76 username_ = username;
77 } 77 }
78 78
79 // static 79 // static
80 void SigninManager::PrepareForSignin() { 80 void SigninManager::PrepareForSignin() {
81 DCHECK(!browser_sync::IsUsingOAuth()); 81 DCHECK(!browser_sync::IsUsingOAuth());
82 DCHECK(username_.empty()); 82 DCHECK(username_.empty());
83 #if !defined(OS_CHROMEOS)
84 // The Sign out should clear the token service credentials.
85 // Note: In CHROMEOS we might have valid credentials but still need to
86 // set up 2-factor authentication.
87 DCHECK(!profile_->GetTokenService()->AreCredentialsValid());
88 #endif
89 } 83 }
90 84
91 // static 85 // static
92 void SigninManager::PrepareForOAuthSignin() { 86 void SigninManager::PrepareForOAuthSignin() {
93 DCHECK(browser_sync::IsUsingOAuth()); 87 DCHECK(browser_sync::IsUsingOAuth());
94 DCHECK(oauth_username_.empty()); 88 DCHECK(oauth_username_.empty());
95 #if !defined(OS_CHROMEOS) 89 #if !defined(OS_CHROMEOS)
96 // The Sign out should clear the token service credentials. 90 // The Sign out should clear the token service credentials.
97 // Note: In CHROMEOS we might have valid credentials but still need to 91 // Note: In CHROMEOS we might have valid credentials but still need to
98 // set up 2-factor authentication. 92 // set up 2-factor authentication.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 GaiaConstants::kChromeSource, 147 GaiaConstants::kChromeSource,
154 profile_->GetRequestContext())); 148 profile_->GetRequestContext()));
155 client_login_->StartClientLogin(username_, 149 client_login_->StartClientLogin(username_,
156 access_code, 150 access_code,
157 "", 151 "",
158 std::string(), 152 std::string(),
159 std::string(), 153 std::string(),
160 GaiaAuthFetcher::HostedAccountsNotAllowed); 154 GaiaAuthFetcher::HostedAccountsNotAllowed);
161 } 155 }
162 156
157 void SigninManager::ClearInMemoryData() {
158 if (!profile_)
159 return;
160
161 CleanupNotificationRegistration();
162 client_login_.reset();
163 last_result_ = ClientLoginResult();
164 username_.clear();
165 oauth_username_.clear();
166 password_.clear();
167 had_two_factor_error_ = false;
168 }
169
163 void SigninManager::SignOut() { 170 void SigninManager::SignOut() {
164 if (!profile_) 171 if (!profile_)
165 return; 172 return;
166 173
167 CleanupNotificationRegistration(); 174 ClearInMemoryData();
168
169 client_login_.reset();
170 last_result_ = ClientLoginResult();
171 username_.clear();
172 oauth_username_.clear();
173 password_.clear();
174 had_two_factor_error_ = false;
175 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); 175 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
176 profile_->GetPrefs()->ClearPref(prefs::kSyncUsingOAuth); 176 profile_->GetPrefs()->ClearPref(prefs::kSyncUsingOAuth);
177 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); 177 profile_->GetPrefs()->ScheduleSavePersistentPrefs();
178 profile_->GetTokenService()->ResetCredentialsInMemory(); 178 profile_->GetTokenService()->ResetCredentialsInMemory();
179 profile_->GetTokenService()->EraseTokensFromDB(); 179 profile_->GetTokenService()->EraseTokensFromDB();
180 } 180 }
181 181
182 void SigninManager::OnClientLoginSuccess(const ClientLoginResult& result) { 182 void SigninManager::OnClientLoginSuccess(const ClientLoginResult& result) {
183 DCHECK(!browser_sync::IsUsingOAuth()); 183 DCHECK(!browser_sync::IsUsingOAuth());
184 last_result_ = result; 184 last_result_ = result;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // a second factor error, and we don't sign out if we're dealing with 244 // a second factor error, and we don't sign out if we're dealing with
245 // an invalid access code (again, because the password was valid). 245 // an invalid access code (again, because the password was valid).
246 bool invalid_gaia = error.state() == 246 bool invalid_gaia = error.state() ==
247 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS; 247 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS;
248 if (error.state() == GoogleServiceAuthError::TWO_FACTOR || 248 if (error.state() == GoogleServiceAuthError::TWO_FACTOR ||
249 (had_two_factor_error_ && invalid_gaia)) { 249 (had_two_factor_error_ && invalid_gaia)) {
250 had_two_factor_error_ = true; 250 had_two_factor_error_ = true;
251 return; 251 return;
252 } 252 }
253 253
254 SignOut(); 254 ClearInMemoryData();
255 } 255 }
256 256
257 void SigninManager::OnOAuthGetAccessTokenSuccess(const std::string& token, 257 void SigninManager::OnOAuthGetAccessTokenSuccess(const std::string& token,
258 const std::string& secret) { 258 const std::string& secret) {
259 DCHECK(browser_sync::IsUsingOAuth()); 259 DCHECK(browser_sync::IsUsingOAuth());
260 VLOG(1) << "SigninManager::OnOAuthGetAccessTokenSuccess"; 260 VLOG(1) << "SigninManager::OnOAuthGetAccessTokenSuccess";
261 profile_->GetTokenService()->UpdateOAuthCredentials(token, secret); 261 profile_->GetTokenService()->UpdateOAuthCredentials(token, secret);
262 } 262 }
263 263
264 void SigninManager::OnOAuthGetAccessTokenFailure( 264 void SigninManager::OnOAuthGetAccessTokenFailure(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 profile_->GetRequestContext())); 334 profile_->GetRequestContext()));
335 } 335 }
336 336
337 client_login_->StartMergeSession(tok_details->token()); 337 client_login_->StartMergeSession(tok_details->token());
338 338
339 // We only want to do this once per sign-in. 339 // We only want to do this once per sign-in.
340 CleanupNotificationRegistration(); 340 CleanupNotificationRegistration();
341 } 341 }
342 #endif 342 #endif
343 } 343 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/signin_manager.h ('k') | chrome/browser/sync/signin_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698