Commit cfadda1d authored by lipalani@chromium.org's avatar lipalani@chromium.org

When the user enters new credentials to sync we clear the data from db as well...

When the user enters new credentials to sync we clear the data from db as well as in memory. However if at this state the user restarts the browser sync will not initialize the next time thinking that user has not setup sync.

This fix prevents the data from being cleared from db. So on restart we can still initialize sync and display auth error.

BUG=103861
TEST=manual by running the repro, sync_integration_tests.exe and unit_tests.exe


Review URL: http://codereview.chromium.org/8515030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109744 0039d316-1c4b-4281-b951-d872f2087c98
parent 11cccb1c
...@@ -1073,7 +1073,7 @@ void ProfileSyncService::OnUserSubmittedAuth( ...@@ -1073,7 +1073,7 @@ void ProfileSyncService::OnUserSubmittedAuth(
} }
if (!signin_->GetUsername().empty()) { if (!signin_->GetUsername().empty()) {
signin_->SignOut(); signin_->ClearInMemoryData();
} }
// The user has submitted credentials, which indicates they don't // The user has submitted credentials, which indicates they don't
......
...@@ -80,12 +80,6 @@ void SigninManager::SetUsername(const std::string& username) { ...@@ -80,12 +80,6 @@ void SigninManager::SetUsername(const std::string& username) {
void SigninManager::PrepareForSignin() { void SigninManager::PrepareForSignin() {
DCHECK(!browser_sync::IsUsingOAuth()); DCHECK(!browser_sync::IsUsingOAuth());
DCHECK(username_.empty()); DCHECK(username_.empty());
#if !defined(OS_CHROMEOS)
// The Sign out should clear the token service credentials.
// Note: In CHROMEOS we might have valid credentials but still need to
// set up 2-factor authentication.
DCHECK(!profile_->GetTokenService()->AreCredentialsValid());
#endif
} }
// static // static
...@@ -160,18 +154,24 @@ void SigninManager::ProvideSecondFactorAccessCode( ...@@ -160,18 +154,24 @@ void SigninManager::ProvideSecondFactorAccessCode(
GaiaAuthFetcher::HostedAccountsNotAllowed); GaiaAuthFetcher::HostedAccountsNotAllowed);
} }
void SigninManager::SignOut() { void SigninManager::ClearInMemoryData() {
if (!profile_) if (!profile_)
return; return;
CleanupNotificationRegistration(); CleanupNotificationRegistration();
client_login_.reset(); client_login_.reset();
last_result_ = ClientLoginResult(); last_result_ = ClientLoginResult();
username_.clear(); username_.clear();
oauth_username_.clear(); oauth_username_.clear();
password_.clear(); password_.clear();
had_two_factor_error_ = false; had_two_factor_error_ = false;
}
void SigninManager::SignOut() {
if (!profile_)
return;
ClearInMemoryData();
profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
profile_->GetPrefs()->ClearPref(prefs::kSyncUsingOAuth); profile_->GetPrefs()->ClearPref(prefs::kSyncUsingOAuth);
profile_->GetPrefs()->ScheduleSavePersistentPrefs(); profile_->GetPrefs()->ScheduleSavePersistentPrefs();
...@@ -251,7 +251,7 @@ void SigninManager::OnClientLoginFailure(const GoogleServiceAuthError& error) { ...@@ -251,7 +251,7 @@ void SigninManager::OnClientLoginFailure(const GoogleServiceAuthError& error) {
return; return;
} }
SignOut(); ClearInMemoryData();
} }
void SigninManager::OnOAuthGetAccessTokenSuccess(const std::string& token, void SigninManager::OnOAuthGetAccessTokenSuccess(const std::string& token,
......
...@@ -81,6 +81,11 @@ class SigninManager : public GaiaAuthConsumer, ...@@ -81,6 +81,11 @@ class SigninManager : public GaiaAuthConsumer,
// associated with the user, and canceling all auth in progress. // associated with the user, and canceling all auth in progress.
void SignOut(); void SignOut();
// Called when a new request to re-authenticate a user is in progress.
// Will clear in memory data but leaves the db as such so when the browser
// restarts we can use the old token(which might throw a password error).
void ClearInMemoryData();
// GaiaAuthConsumer // GaiaAuthConsumer
virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE; virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE;
virtual void OnClientLoginFailure(const GoogleServiceAuthError& error) virtual void OnClientLoginFailure(const GoogleServiceAuthError& error)
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/net/gaia/token_service.h"
#include "chrome/browser/net/gaia/token_service_unittest.h" #include "chrome/browser/net/gaia/token_service_unittest.h"
#include "chrome/browser/password_manager/encryptor.h" #include "chrome/browser/password_manager/encryptor.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/sync/util/oauth.h" #include "chrome/browser/sync/util/oauth.h"
#include "chrome/browser/webdata/web_data_service.h" #include "chrome/browser/webdata/web_data_service.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "chrome/common/net/gaia/gaia_urls.h" #include "chrome/common/net/gaia/gaia_urls.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/test/test_url_fetcher_factory.h" #include "content/test/test_url_fetcher_factory.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
...@@ -112,6 +114,39 @@ TEST_F(SigninManagerTest, SignInClientLogin) { ...@@ -112,6 +114,39 @@ TEST_F(SigninManagerTest, SignInClientLogin) {
EXPECT_EQ("user@gmail.com", manager_->GetUsername()); EXPECT_EQ("user@gmail.com", manager_->GetUsername());
} }
TEST_F(SigninManagerTest, ClearInMemoryData) {
browser_sync::SetIsUsingOAuthForTest(false);
manager_->Initialize(profile_.get());
EXPECT_TRUE(manager_->GetUsername().empty());
manager_->StartSignIn("username", "password", "", "");
EXPECT_FALSE(manager_->GetUsername().empty());
SimulateValidResponseClientLogin();
// Should go into token service and stop.
EXPECT_EQ(1U, google_login_success_.size());
EXPECT_EQ(0U, google_login_failure_.size());
EXPECT_EQ("user@gmail.com", manager_->GetUsername());
// Now clear the in memory data.
manager_->ClearInMemoryData();
EXPECT_TRUE(manager_->GetUsername().empty());
// Ensure preferences are not modified.
EXPECT_FALSE(
profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty());
// On reset it should be regenerated.
manager_.reset(new SigninManager());
manager_->Initialize(profile_.get());
// Now make sure we have the right user name.
EXPECT_EQ("user@gmail.com", manager_->GetUsername());
}
// NOTE: OAuth's "StartOAuthSignIn" is called before collecting credentials // NOTE: OAuth's "StartOAuthSignIn" is called before collecting credentials
// from the user. See also SigninManagerTest::SignInClientLogin. // from the user. See also SigninManagerTest::SignInClientLogin.
TEST_F(SigninManagerTest, SignInOAuth) { TEST_F(SigninManagerTest, SignInOAuth) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment