| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/signin/signin_manager.h" | 5 #include "chrome/browser/signin/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/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 token_service); | 61 token_service); |
| 62 } | 62 } |
| 63 #endif | 63 #endif |
| 64 } | 64 } |
| 65 | 65 |
| 66 const std::string& SigninManager::GetAuthenticatedUsername() { | 66 const std::string& SigninManager::GetAuthenticatedUsername() { |
| 67 return authenticated_username_; | 67 return authenticated_username_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SigninManager::SetAuthenticatedUsername(const std::string& username) { | 70 void SigninManager::SetAuthenticatedUsername(const std::string& username) { |
| 71 DCHECK(authenticated_username_.empty() || | 71 if (!authenticated_username_.empty()) { |
| 72 username == authenticated_username_); | 72 DLOG_IF(ERROR, username != authenticated_username_) << |
| 73 "Tried to change the authenticated username to something different: " << |
| 74 "Current: " << authenticated_username_ << ", New: " << username; |
| 75 return; |
| 76 } |
| 73 authenticated_username_ = username; | 77 authenticated_username_ = username; |
| 74 // TODO(tim): We could go further in ensuring kGoogleServicesUsername and | 78 // TODO(tim): We could go further in ensuring kGoogleServicesUsername and |
| 75 // authenticated_username_ are consistent once established (e.g. remove | 79 // authenticated_username_ are consistent once established (e.g. remove |
| 76 // authenticated_username_ altogether). Bug 107160. | 80 // authenticated_username_ altogether). Bug 107160. |
| 77 } | 81 } |
| 78 | 82 |
| 79 void SigninManager::PrepareForSignin() { | 83 void SigninManager::PrepareForSignin() { |
| 80 DCHECK(!browser_sync::IsUsingOAuth()); | 84 DCHECK(!browser_sync::IsUsingOAuth()); |
| 81 DCHECK(possibly_invalid_username_.empty()); | 85 DCHECK(possibly_invalid_username_.empty()); |
| 82 // This attempt is either 1) the user trying to establish initial sync, or | 86 // This attempt is either 1) the user trying to establish initial sync, or |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); | 189 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
| 186 profile_->GetPrefs()->ClearPref(prefs::kSyncUsingOAuth); | 190 profile_->GetPrefs()->ClearPref(prefs::kSyncUsingOAuth); |
| 187 profile_->GetTokenService()->ResetCredentialsInMemory(); | 191 profile_->GetTokenService()->ResetCredentialsInMemory(); |
| 188 profile_->GetTokenService()->EraseTokensFromDB(); | 192 profile_->GetTokenService()->EraseTokensFromDB(); |
| 189 } | 193 } |
| 190 | 194 |
| 191 const GoogleServiceAuthError& SigninManager::GetLoginAuthError() const { | 195 const GoogleServiceAuthError& SigninManager::GetLoginAuthError() const { |
| 192 return last_login_auth_error_; | 196 return last_login_auth_error_; |
| 193 } | 197 } |
| 194 | 198 |
| 199 bool SigninManager::AuthInProgress() const { |
| 200 return !possibly_invalid_username_.empty(); |
| 201 } |
| 202 |
| 195 void SigninManager::OnClientLoginSuccess(const ClientLoginResult& result) { | 203 void SigninManager::OnClientLoginSuccess(const ClientLoginResult& result) { |
| 196 DCHECK(!browser_sync::IsUsingOAuth()); | 204 DCHECK(!browser_sync::IsUsingOAuth()); |
| 197 last_result_ = result; | 205 last_result_ = result; |
| 198 // Make a request for the canonical email address. | 206 // Make a request for the canonical email address. |
| 199 client_login_->StartGetUserInfo(result.lsid, kGetInfoEmailKey); | 207 client_login_->StartGetUserInfo(result.lsid, kGetInfoEmailKey); |
| 200 } | 208 } |
| 201 | 209 |
| 202 // NOTE: GetUserInfo is a ClientLogin request similar to OAuth's userinfo | 210 // NOTE: GetUserInfo is a ClientLogin request similar to OAuth's userinfo |
| 203 void SigninManager::OnGetUserInfoSuccess(const std::string& key, | 211 void SigninManager::OnGetUserInfoSuccess(const std::string& key, |
| 204 const std::string& value) { | 212 const std::string& value) { |
| 205 DCHECK(!browser_sync::IsUsingOAuth()); | 213 DCHECK(!browser_sync::IsUsingOAuth()); |
| 206 DCHECK(key == kGetInfoEmailKey); | 214 DCHECK(key == kGetInfoEmailKey); |
| 207 DCHECK(authenticated_username_.empty() || authenticated_username_ == value); | |
| 208 | |
| 209 last_login_auth_error_ = GoogleServiceAuthError::None(); | 215 last_login_auth_error_ = GoogleServiceAuthError::None(); |
| 210 authenticated_username_ = value; | 216 SetAuthenticatedUsername(value); |
| 211 possibly_invalid_username_.clear(); | 217 possibly_invalid_username_.clear(); |
| 212 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 218 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| 213 authenticated_username_); | 219 authenticated_username_); |
| 214 profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, false); | 220 profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, false); |
| 215 | 221 |
| 216 GoogleServiceSigninSuccessDetails details(authenticated_username_, | 222 GoogleServiceSigninSuccessDetails details(authenticated_username_, |
| 217 password_); | 223 password_); |
| 218 content::NotificationService::current()->Notify( | 224 content::NotificationService::current()->Notify( |
| 219 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 225 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 220 content::Source<Profile>(profile_), | 226 content::Source<Profile>(profile_), |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 profile_->GetRequestContext())); | 361 profile_->GetRequestContext())); |
| 356 } | 362 } |
| 357 | 363 |
| 358 client_login_->StartMergeSession(tok_details->token()); | 364 client_login_->StartMergeSession(tok_details->token()); |
| 359 | 365 |
| 360 // We only want to do this once per sign-in. | 366 // We only want to do this once per sign-in. |
| 361 CleanupNotificationRegistration(); | 367 CleanupNotificationRegistration(); |
| 362 } | 368 } |
| 363 #endif | 369 #endif |
| 364 } | 370 } |
| OLD | NEW |