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..1efa97dcdbe4999799b0f6b5113e16614090b69f 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()) |
| + oauth_username_ = |
| + profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| + else |
| + username_ = profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| profile_->GetTokenService()->Initialize( |
| GaiaConstants::kChromeSource, profile_); |
| - if (!username_.empty()) { |
| + if (!username_.empty() || !oauth_username_.empty()) { |
| 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,12 @@ 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()->SetString( |
| + prefs::kGoogleServicesUsername, GetUsername()); |
|
Roger Tawa OOO till Jul 10th
2011/08/10 18:10:43
won't GetUsername() always return an empty string?
Rick Campbell
2011/08/10 18:55:16
Done. Changing this and the next one to ClearPref
|
| + profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, false); |
| profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
| profile_->GetTokenService()->ResetCredentialsInMemory(); |
| profile_->GetTokenService()->EraseTokensFromDB(); |
| @@ -157,12 +181,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 +249,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 +272,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 << "\")"; |
|
Roger Tawa OOO till Jul 10th
2011/08/10 18:10:43
should this VLOG also be changed?
Rick Campbell
2011/08/10 18:55:16
Done.
|
| + 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, |