Chromium Code Reviews| Index: chrome/browser/sync/signin_manager.cc |
| diff --git a/chrome/browser/sync/signin_manager.cc b/chrome/browser/sync/signin_manager.cc |
| index 6156351c003a86c3fce9c449a658f6e010cd014c..2d433f77f26d1b156a91ddefb29019800332946c 100644 |
| --- a/chrome/browser/sync/signin_manager.cc |
| +++ b/chrome/browser/sync/signin_manager.cc |
| @@ -32,10 +32,14 @@ void SigninManager::RegisterUserPrefs(PrefService* user_prefs) { |
| void SigninManager::Initialize(Profile* profile) { |
| profile_ = profile; |
| - username_ = profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| + if (SyncSetupWizard::IsUsingOAuth()) |
|
akalin
2011/08/10 19:42:01
use SetUsername here?
Rick Campbell
2011/08/11 03:58:23
Done.
|
| + oauth_username_ = |
| + profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
|
Andrew T Wilson (Slow)
2011/08/10 20:54:50
If you don't change this to use SetUsername(), sho
Rick Campbell
2011/08/11 03:58:23
Done, by using SetUsername.
|
| + else |
| + username_ = profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| profile_->GetTokenService()->Initialize( |
| GaiaConstants::kChromeSource, profile_); |
| - if (!username_.empty()) { |
| + if (!username_.empty() || !oauth_username_.empty()) { |
|
akalin
2011/08/10 19:42:01
use GetUsername here?
Rick Campbell
2011/08/11 03:58:23
Done.
|
| profile_->GetTokenService()->LoadTokensFromDB(); |
| } |
| } |
| @@ -59,11 +63,16 @@ void SigninManager::CleanupNotificationRegistration() { |
| // If a username already exists, the user is logged in. |
| const std::string& SigninManager::GetUsername() { |
| + if (SyncSetupWizard::IsUsingOAuth()) |
| + return oauth_username_; |
| return username_; |
| } |
| void SigninManager::SetUsername(const std::string& username) { |
| - username_ = username; |
| + if (SyncSetupWizard::IsUsingOAuth()) |
| + oauth_username_ = username; |
| + else |
| + username_ = username; |
| } |
| // static |
| @@ -77,14 +86,26 @@ void SigninManager::PrepareForSignin() { |
| #endif |
| } |
| +// static |
| +void SigninManager::PrepareForOAuthSignin() { |
| + DCHECK(oauth_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()->AreOAuthCredentialsValid()); |
| +#endif |
| +} |
| + |
| // Users must always sign out before they sign in again. |
| void SigninManager::StartOAuthSignIn() { |
| - PrepareForSignin(); |
| + PrepareForOAuthSignin(); |
| oauth_login_.reset(new GaiaOAuthFetcher(this, |
| profile_->GetRequestContext(), |
| profile_, |
| GaiaConstants::kSyncServiceOAuth)); |
| oauth_login_->StartGetOAuthToken(); |
| + // TODO(rogerta?): Bug 92325: Expand Autologin to include OAuth signin |
| } |
| // Users must always sign out before they sign in again. |
| @@ -143,9 +164,11 @@ void SigninManager::SignOut() { |
| client_login_.reset(); |
| last_result_ = ClientLoginResult(); |
| username_.clear(); |
| + oauth_username_.clear(); |
| password_.clear(); |
| had_two_factor_error_ = false; |
| - profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username_); |
| + profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
| + profile_->GetPrefs()->ClearPref(prefs::kSyncUsingOAuth); |
| profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
| profile_->GetTokenService()->ResetCredentialsInMemory(); |
| profile_->GetTokenService()->EraseTokensFromDB(); |
| @@ -157,12 +180,14 @@ void SigninManager::OnClientLoginSuccess(const ClientLoginResult& result) { |
| client_login_->StartGetUserInfo(result.lsid, kGetInfoEmailKey); |
| } |
| +// NOTE: GetUserInfo is a ClientLogin request similar to OAuth's userinfo |
| void SigninManager::OnGetUserInfoSuccess(const std::string& key, |
| const std::string& value) { |
| DCHECK(key == kGetInfoEmailKey); |
| username_ = value; |
| profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username_); |
| + profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, false); |
| profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
| GoogleServiceSigninSuccessDetails details(username_, password_); |
| @@ -223,17 +248,18 @@ void SigninManager::OnGetOAuthTokenSuccess(const std::string& oauth_token) { |
| } |
| void SigninManager::OnGetOAuthTokenFailure() { |
| - VLOG(1) << "SigninManager::OnGetOAuthTokenFailure"; |
| + LOG(WARNING) << "SigninManager::OnGetOAuthTokenFailure"; |
| } |
| void SigninManager::OnOAuthGetAccessTokenSuccess(const std::string& token, |
| const std::string& secret) { |
| VLOG(1) << "SigninManager::OnOAuthGetAccessTokenSuccess"; |
| + profile_->GetTokenService()->UpdateOAuthCredentials(token, secret); |
| } |
| void SigninManager::OnOAuthGetAccessTokenFailure( |
| const GoogleServiceAuthError& error) { |
| - VLOG(1) << "SigninManager::OnOAuthGetAccessTokenFailure"; |
| + LOG(WARNING) << "SigninManager::OnOAuthGetAccessTokenFailure"; |
| } |
| void SigninManager::OnOAuthWrapBridgeSuccess(const std::string& service_name, |
| @@ -245,15 +271,31 @@ void SigninManager::OnOAuthWrapBridgeSuccess(const std::string& service_name, |
| void SigninManager::OnOAuthWrapBridgeFailure( |
| const std::string& service_scope, |
| const GoogleServiceAuthError& error) { |
| - VLOG(1) << "SigninManager::OnOAuthWrapBridgeFailure"; |
| + LOG(WARNING) << "SigninManager::OnOAuthWrapBridgeFailure"; |
| } |
| +// NOTE: userinfo is an OAuth request similar to ClientLogin's GetUserInfo |
| void SigninManager::OnUserInfoSuccess(const std::string& email) { |
| - VLOG(1) << "SigninManager::OnUserInfoSuccess(\"" << email << "\")"; |
| + VLOG(1) << "Sync signin for " << email << " is complete."; |
|
Roger Tawa OOO till Jul 10th
2011/08/10 19:13:05
Did you forget to change this vlog?
Is there a re
Rick Campbell
2011/08/11 03:58:23
I think that I misunderstood originally. I change
|
| + oauth_username_ = email; |
| + profile_->GetPrefs()->SetString( |
| + prefs::kGoogleServicesUsername, oauth_username_); |
| + profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, true); |
| + profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
| + |
| + DCHECK(password_.empty()); |
| + GoogleServiceSigninSuccessDetails details(oauth_username_, ""); |
| + NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| + Source<Profile>(profile_), |
| + Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| + |
| + DCHECK(profile_->GetTokenService()->AreOAuthCredentialsValid()); |
| + profile_->GetTokenService()->StartFetchingOAuthTokens(); |
| } |
| void SigninManager::OnUserInfoFailure(const GoogleServiceAuthError& error) { |
| - VLOG(1) << "SigninManager::OnUserInfoFailure"; |
| + LOG(WARNING) << "SigninManager::OnUserInfoFailure"; |
| } |
| void SigninManager::Observe(int type, |