| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 void SigninManager::InitTokenService() { | 98 void SigninManager::InitTokenService() { |
| 99 if (token_service_ && IsAuthenticated()) | 99 if (token_service_ && IsAuthenticated()) |
| 100 token_service_->LoadCredentials(GetAuthenticatedAccountId()); | 100 token_service_->LoadCredentials(GetAuthenticatedAccountId()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 std::string SigninManager::SigninTypeToString(SigninManager::SigninType type) { | 103 std::string SigninManager::SigninTypeToString(SigninManager::SigninType type) { |
| 104 switch (type) { | 104 switch (type) { |
| 105 case SIGNIN_TYPE_NONE: | 105 case SIGNIN_TYPE_NONE: |
| 106 return "No Signin"; | 106 return "No Signin"; |
| 107 case SIGNIN_TYPE_WITH_REFRESH_TOKEN: | 107 case SIGNIN_TYPE_WITH_REFRESH_TOKEN: |
| 108 return "Signin with refresh token"; | 108 return "With refresh token"; |
| 109 } | 109 } |
| 110 | 110 |
| 111 NOTREACHED(); | 111 NOTREACHED(); |
| 112 return std::string(); | 112 return std::string(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool SigninManager::PrepareForSignin(SigninType type, | 115 bool SigninManager::PrepareForSignin(SigninType type, |
| 116 const std::string& username, | 116 const std::string& username, |
| 117 const std::string& password) { | 117 const std::string& password) { |
| 118 DCHECK(possibly_invalid_username_.empty() || | 118 DCHECK(possibly_invalid_username_.empty() || |
| (...skipping 11 matching lines...) Expand all Loading... |
| 130 // 2) trying to refresh credentials for an existing username. If it is 2, we | 130 // 2) trying to refresh credentials for an existing username. If it is 2, we |
| 131 // need to try again, but take care to leave state around tracking that the | 131 // need to try again, but take care to leave state around tracking that the |
| 132 // user has successfully signed in once before with this username, so that on | 132 // user has successfully signed in once before with this username, so that on |
| 133 // restart we don't think sync setup has never completed. | 133 // restart we don't think sync setup has never completed. |
| 134 ClearTransientSigninData(); | 134 ClearTransientSigninData(); |
| 135 type_ = type; | 135 type_ = type; |
| 136 possibly_invalid_username_.assign(username); | 136 possibly_invalid_username_.assign(username); |
| 137 password_.assign(password); | 137 password_.assign(password); |
| 138 signin_manager_signed_in_ = false; | 138 signin_manager_signed_in_ = false; |
| 139 user_info_fetched_by_account_tracker_ = false; | 139 user_info_fetched_by_account_tracker_ = false; |
| 140 NotifyDiagnosticsObservers(SIGNIN_TYPE, SigninTypeToString(type)); | 140 NotifyDiagnosticsObservers(SIGNIN_STARTED, SigninTypeToString(type)); |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void SigninManager::StartSignInWithRefreshToken( | 144 void SigninManager::StartSignInWithRefreshToken( |
| 145 const std::string& refresh_token, | 145 const std::string& refresh_token, |
| 146 const std::string& username, | 146 const std::string& username, |
| 147 const std::string& password, | 147 const std::string& password, |
| 148 const OAuthTokenFetchedCallback& callback) { | 148 const OAuthTokenFetchedCallback& callback) { |
| 149 DCHECK(!IsAuthenticated() || | 149 DCHECK(!IsAuthenticated() || |
| 150 gaia::AreEmailsSame(username, GetAuthenticatedUsername())); | 150 gaia::AreEmailsSame(username, GetAuthenticatedUsername())); |
| 151 | 151 |
| 152 if (!PrepareForSignin(SIGNIN_TYPE_WITH_REFRESH_TOKEN, username, password)) | 152 if (!PrepareForSignin(SIGNIN_TYPE_WITH_REFRESH_TOKEN, username, password)) |
| 153 return; | 153 return; |
| 154 | 154 |
| 155 // Store our callback and token. | 155 // Store our callback and token. |
| 156 temp_refresh_token_ = refresh_token; | 156 temp_refresh_token_ = refresh_token; |
| 157 possibly_invalid_username_ = username; | 157 possibly_invalid_username_ = username; |
| 158 | 158 |
| 159 NotifyDiagnosticsObservers(GET_USER_INFO_STATUS, "Successful"); | |
| 160 | |
| 161 if (!callback.is_null() && !temp_refresh_token_.empty()) { | 159 if (!callback.is_null() && !temp_refresh_token_.empty()) { |
| 162 callback.Run(temp_refresh_token_); | 160 callback.Run(temp_refresh_token_); |
| 163 } else { | 161 } else { |
| 164 // No oauth token or callback, so just complete our pending signin. | 162 // No oauth token or callback, so just complete our pending signin. |
| 165 CompletePendingSignin(); | 163 CompletePendingSignin(); |
| 166 } | 164 } |
| 167 } | 165 } |
| 168 | 166 |
| 169 void SigninManager::CopyCredentialsFrom(const SigninManager& source) { | 167 void SigninManager::CopyCredentialsFrom(const SigninManager& source) { |
| 170 DCHECK_NE(this, &source); | 168 DCHECK_NE(this, &source); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 const std::string username = GetAuthenticatedUsername(); | 220 const std::string username = GetAuthenticatedUsername(); |
| 223 const base::Time signin_time = | 221 const base::Time signin_time = |
| 224 base::Time::FromInternalValue( | 222 base::Time::FromInternalValue( |
| 225 client_->GetPrefs()->GetInt64(prefs::kSignedInTime)); | 223 client_->GetPrefs()->GetInt64(prefs::kSignedInTime)); |
| 226 ClearAuthenticatedUsername(); | 224 ClearAuthenticatedUsername(); |
| 227 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesHostedDomain); | 225 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesHostedDomain); |
| 228 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); | 226 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
| 229 client_->GetPrefs()->ClearPref(prefs::kSignedInTime); | 227 client_->GetPrefs()->ClearPref(prefs::kSignedInTime); |
| 230 client_->OnSignedOut(); | 228 client_->OnSignedOut(); |
| 231 | 229 |
| 232 // Erase (now) stale information from AboutSigninInternals. | |
| 233 NotifyDiagnosticsObservers(USERNAME, ""); | |
| 234 | |
| 235 // Determine the duration the user was logged in and log that to UMA. | 230 // Determine the duration the user was logged in and log that to UMA. |
| 236 if (!signin_time.is_null()) { | 231 if (!signin_time.is_null()) { |
| 237 base::TimeDelta signed_in_duration = base::Time::Now() - signin_time; | 232 base::TimeDelta signed_in_duration = base::Time::Now() - signin_time; |
| 238 UMA_HISTOGRAM_COUNTS("Signin.SignedInDurationBeforeSignout", | 233 UMA_HISTOGRAM_COUNTS("Signin.SignedInDurationBeforeSignout", |
| 239 signed_in_duration.InMinutes()); | 234 signed_in_duration.InMinutes()); |
| 240 } | 235 } |
| 241 | 236 |
| 242 // Revoke all tokens before sending signed_out notification, because there | 237 // Revoke all tokens before sending signed_out notification, because there |
| 243 // may be components that don't listen for token service events when the | 238 // may be components that don't listen for token service events when the |
| 244 // profile is not connected to an account. | 239 // profile is not connected to an account. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 } | 377 } |
| 383 | 378 |
| 384 merge_session_helper_.reset(new MergeSessionHelper( | 379 merge_session_helper_.reset(new MergeSessionHelper( |
| 385 token_service_, GaiaConstants::kChromeSource, | 380 token_service_, GaiaConstants::kChromeSource, |
| 386 client_->GetURLRequestContext(), this)); | 381 client_->GetURLRequestContext(), this)); |
| 387 | 382 |
| 388 merge_session_helper_->LogIn(GetAuthenticatedAccountId()); | 383 merge_session_helper_->LogIn(GetAuthenticatedAccountId()); |
| 389 } | 384 } |
| 390 | 385 |
| 391 void SigninManager::CompletePendingSignin() { | 386 void SigninManager::CompletePendingSignin() { |
| 387 NotifyDiagnosticsObservers(SIGNIN_COMPLETED, "Successful"); |
| 388 |
| 392 DCHECK(!possibly_invalid_username_.empty()); | 389 DCHECK(!possibly_invalid_username_.empty()); |
| 393 OnSignedIn(possibly_invalid_username_); | 390 OnSignedIn(possibly_invalid_username_); |
| 394 | 391 |
| 395 DCHECK(!temp_refresh_token_.empty()); | 392 DCHECK(!temp_refresh_token_.empty()); |
| 396 DCHECK(IsAuthenticated()); | 393 DCHECK(IsAuthenticated()); |
| 397 token_service_->UpdateCredentials(GetAuthenticatedAccountId(), | 394 token_service_->UpdateCredentials(GetAuthenticatedAccountId(), |
| 398 temp_refresh_token_); | 395 temp_refresh_token_); |
| 399 temp_refresh_token_.clear(); | 396 temp_refresh_token_.clear(); |
| 400 | 397 |
| 401 MergeSigninCredentialIntoCookieJar(); | 398 MergeSigninCredentialIntoCookieJar(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 void SigninManager::OnAccountUpdateFailed(const std::string& account_id) { | 447 void SigninManager::OnAccountUpdateFailed(const std::string& account_id) { |
| 451 user_info_fetched_by_account_tracker_ = true; | 448 user_info_fetched_by_account_tracker_ = true; |
| 452 PostSignedIn(); | 449 PostSignedIn(); |
| 453 } | 450 } |
| 454 | 451 |
| 455 void SigninManager::ProhibitSignout(bool prohibit_signout) { | 452 void SigninManager::ProhibitSignout(bool prohibit_signout) { |
| 456 prohibit_signout_ = prohibit_signout; | 453 prohibit_signout_ = prohibit_signout; |
| 457 } | 454 } |
| 458 | 455 |
| 459 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } | 456 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } |
| OLD | NEW |