| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/signin/core/browser/signin_manager.h" | 5 #include "components/signin/core/browser/signin_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 password_.assign(password); | 124 password_.assign(password); |
| 125 NotifyDiagnosticsObservers(SIGNIN_TYPE, SigninTypeToString(type)); | 125 NotifyDiagnosticsObservers(SIGNIN_TYPE, SigninTypeToString(type)); |
| 126 return true; | 126 return true; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void SigninManager::StartSignInWithRefreshToken( | 129 void SigninManager::StartSignInWithRefreshToken( |
| 130 const std::string& refresh_token, | 130 const std::string& refresh_token, |
| 131 const std::string& username, | 131 const std::string& username, |
| 132 const std::string& password, | 132 const std::string& password, |
| 133 const OAuthTokenFetchedCallback& callback) { | 133 const OAuthTokenFetchedCallback& callback) { |
| 134 DCHECK(GetAuthenticatedUsername().empty() || | 134 DCHECK(!IsAuthenticated() || |
| 135 gaia::AreEmailsSame(username, GetAuthenticatedUsername())); | 135 gaia::AreEmailsSame(username, GetAuthenticatedUsername())); |
| 136 | 136 |
| 137 if (!PrepareForSignin(SIGNIN_TYPE_WITH_REFRESH_TOKEN, username, password)) | 137 if (!PrepareForSignin(SIGNIN_TYPE_WITH_REFRESH_TOKEN, username, password)) |
| 138 return; | 138 return; |
| 139 | 139 |
| 140 // Store our callback and token. | 140 // Store our callback and token. |
| 141 temp_refresh_token_ = refresh_token; | 141 temp_refresh_token_ = refresh_token; |
| 142 possibly_invalid_username_ = username; | 142 possibly_invalid_username_ = username; |
| 143 | 143 |
| 144 NotifyDiagnosticsObservers(GET_USER_INFO_STATUS, "Successful"); | 144 NotifyDiagnosticsObservers(GET_USER_INFO_STATUS, "Successful"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 171 ClearTransientSigninData(); | 171 ClearTransientSigninData(); |
| 172 | 172 |
| 173 FOR_EACH_OBSERVER(Observer, observer_list_, GoogleSigninFailed(error)); | 173 FOR_EACH_OBSERVER(Observer, observer_list_, GoogleSigninFailed(error)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void SigninManager::SignOut( | 176 void SigninManager::SignOut( |
| 177 signin_metrics::ProfileSignout signout_source_metric) { | 177 signin_metrics::ProfileSignout signout_source_metric) { |
| 178 DCHECK(IsInitialized()); | 178 DCHECK(IsInitialized()); |
| 179 | 179 |
| 180 signin_metrics::LogSignout(signout_source_metric); | 180 signin_metrics::LogSignout(signout_source_metric); |
| 181 if (GetAuthenticatedUsername().empty()) { | 181 if (!IsAuthenticated()) { |
| 182 if (AuthInProgress()) { | 182 if (AuthInProgress()) { |
| 183 // If the user is in the process of signing in, then treat a call to | 183 // If the user is in the process of signing in, then treat a call to |
| 184 // SignOut as a cancellation request. | 184 // SignOut as a cancellation request. |
| 185 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); | 185 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); |
| 186 HandleAuthError(error); | 186 HandleAuthError(error); |
| 187 } else { | 187 } else { |
| 188 // Clean up our transient data and exit if we aren't signed in. | 188 // Clean up our transient data and exit if we aren't signed in. |
| 189 // This avoids a perf regression from clearing out the TokenDB if | 189 // This avoids a perf regression from clearing out the TokenDB if |
| 190 // SignOut() is invoked on startup to clean up any incomplete previous | 190 // SignOut() is invoked on startup to clean up any incomplete previous |
| 191 // signin attempts. | 191 // signin attempts. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 void SigninManager::Shutdown() { | 262 void SigninManager::Shutdown() { |
| 263 if (merge_session_helper_) | 263 if (merge_session_helper_) |
| 264 merge_session_helper_->CancelAll(); | 264 merge_session_helper_->CancelAll(); |
| 265 | 265 |
| 266 local_state_pref_registrar_.RemoveAll(); | 266 local_state_pref_registrar_.RemoveAll(); |
| 267 account_id_helper_.reset(); | 267 account_id_helper_.reset(); |
| 268 SigninManagerBase::Shutdown(); | 268 SigninManagerBase::Shutdown(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void SigninManager::OnGoogleServicesUsernamePatternChanged() { | 271 void SigninManager::OnGoogleServicesUsernamePatternChanged() { |
| 272 if (!GetAuthenticatedUsername().empty() && | 272 if (IsAuthenticated() && |
| 273 !IsAllowedUsername(GetAuthenticatedUsername())) { | 273 !IsAllowedUsername(GetAuthenticatedUsername())) { |
| 274 // Signed in user is invalid according to the current policy so sign | 274 // Signed in user is invalid according to the current policy so sign |
| 275 // the user out. | 275 // the user out. |
| 276 SignOut(signin_metrics::GOOGLE_SERVICE_NAME_PATTERN_CHANGED); | 276 SignOut(signin_metrics::GOOGLE_SERVICE_NAME_PATTERN_CHANGED); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 bool SigninManager::IsSigninAllowed() const { | 280 bool SigninManager::IsSigninAllowed() const { |
| 281 return signin_allowed_.GetValue(); | 281 return signin_allowed_.GetValue(); |
| 282 } | 282 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 void SigninManager::CompletePendingSignin() { | 344 void SigninManager::CompletePendingSignin() { |
| 345 DCHECK(!possibly_invalid_username_.empty()); | 345 DCHECK(!possibly_invalid_username_.empty()); |
| 346 OnSignedIn(possibly_invalid_username_); | 346 OnSignedIn(possibly_invalid_username_); |
| 347 | 347 |
| 348 if (client_->ShouldMergeSigninCredentialsIntoCookieJar()) { | 348 if (client_->ShouldMergeSigninCredentialsIntoCookieJar()) { |
| 349 merge_session_helper_.reset(new MergeSessionHelper( | 349 merge_session_helper_.reset(new MergeSessionHelper( |
| 350 token_service_, client_->GetURLRequestContext(), NULL)); | 350 token_service_, client_->GetURLRequestContext(), NULL)); |
| 351 } | 351 } |
| 352 | 352 |
| 353 DCHECK(!temp_refresh_token_.empty()); | 353 DCHECK(!temp_refresh_token_.empty()); |
| 354 DCHECK(!GetAuthenticatedUsername().empty()); | 354 DCHECK(IsAuthenticated()); |
| 355 token_service_->UpdateCredentials(GetAuthenticatedUsername(), | 355 token_service_->UpdateCredentials(GetAuthenticatedUsername(), |
| 356 temp_refresh_token_); | 356 temp_refresh_token_); |
| 357 temp_refresh_token_.clear(); | 357 temp_refresh_token_.clear(); |
| 358 | 358 |
| 359 if (client_->ShouldMergeSigninCredentialsIntoCookieJar()) | 359 if (client_->ShouldMergeSigninCredentialsIntoCookieJar()) |
| 360 merge_session_helper_->LogIn(GetAuthenticatedUsername()); | 360 merge_session_helper_->LogIn(GetAuthenticatedUsername()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void SigninManager::OnExternalSigninCompleted(const std::string& username) { | 363 void SigninManager::OnExternalSigninCompleted(const std::string& username) { |
| 364 OnSignedIn(username); | 364 OnSignedIn(username); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 382 | 382 |
| 383 password_.clear(); // Don't need it anymore. | 383 password_.clear(); // Don't need it anymore. |
| 384 DisableOneClickSignIn(client_->GetPrefs()); // Don't ever offer again. | 384 DisableOneClickSignIn(client_->GetPrefs()); // Don't ever offer again. |
| 385 } | 385 } |
| 386 | 386 |
| 387 void SigninManager::ProhibitSignout(bool prohibit_signout) { | 387 void SigninManager::ProhibitSignout(bool prohibit_signout) { |
| 388 prohibit_signout_ = prohibit_signout; | 388 prohibit_signout_ = prohibit_signout; |
| 389 } | 389 } |
| 390 | 390 |
| 391 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } | 391 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } |
| OLD | NEW |