Index: chrome/browser/sync/signin_manager.cc |
diff --git a/chrome/browser/sync/signin_manager.cc b/chrome/browser/sync/signin_manager.cc |
index 1feb5fc9b8e3ebd8183d4f8a534e317df42bf9e2..c170f3edd46749d390e62dd45568d1816126daf2 100644 |
--- a/chrome/browser/sync/signin_manager.cc |
+++ b/chrome/browser/sync/signin_manager.cc |
@@ -18,6 +18,13 @@ |
const char kGetInfoEmailKey[] = "email"; |
+namespace { |
+bool IsUsingOAuth() { |
+ return CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableSyncOAuth); |
+} |
+} |
akalin
2011/08/11 18:03:37
} // namespace
Rick Campbell
2011/08/11 21:04:08
Moved IsUsingOAuth() to util/
|
+ |
SigninManager::SigninManager() |
: profile_(NULL), had_two_factor_error_(false) {} |
@@ -35,10 +42,10 @@ void SigninManager::RegisterUserPrefs(PrefService* user_prefs) { |
void SigninManager::Initialize(Profile* profile) { |
profile_ = profile; |
- username_ = profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
+ SetUsername(profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); |
profile_->GetTokenService()->Initialize( |
GaiaConstants::kChromeSource, profile_); |
- if (!username_.empty()) { |
+ if (!GetUsername().empty()) { |
profile_->GetTokenService()->LoadTokensFromDB(); |
} |
} |
@@ -62,11 +69,16 @@ void SigninManager::CleanupNotificationRegistration() { |
// If a username already exists, the user is logged in. |
const std::string& SigninManager::GetUsername() { |
+ if (IsUsingOAuth()) |
akalin
2011/08/11 18:03:37
Consider:
return IsUsingOAuth() ? oauth_username_
Rick Campbell
2011/08/11 21:04:08
Done.
|
+ return oauth_username_; |
return username_; |
} |
void SigninManager::SetUsername(const std::string& username) { |
- username_ = username; |
+ if (IsUsingOAuth()) |
akalin
2011/08/11 18:03:37
Consider:
(IsUsingOAuth() ? oauth_username_ : use
Rick Campbell
2011/08/11 21:04:08
As we discussed out-of-band, I'm going to leave th
|
+ oauth_username_ = username; |
+ else |
+ username_ = username; |
} |
// static |
@@ -80,14 +92,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. |
@@ -146,9 +170,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(); |
@@ -160,12 +186,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_); |
@@ -226,17 +254,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, |
@@ -248,15 +277,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."; |
akalin
2011/08/11 18:03:37
DCHECK(IsUsingOAuth()) ?
Rick Campbell
2011/08/11 21:04:08
Done. Added similar DCHECKs for SigninManager::On
|
+ 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, |