| 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_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 if (token_service_) | 47 if (token_service_) |
| 48 token_service_->LoadCredentials(GetAuthenticatedAccountId()); | 48 token_service_->LoadCredentials(GetAuthenticatedAccountId()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 std::string SigninManager::SigninTypeToString(SigninManager::SigninType type) { | 51 std::string SigninManager::SigninTypeToString(SigninManager::SigninType type) { |
| 52 switch (type) { | 52 switch (type) { |
| 53 case SIGNIN_TYPE_NONE: | 53 case SIGNIN_TYPE_NONE: |
| 54 return "No Signin"; | 54 return "No Signin"; |
| 55 case SIGNIN_TYPE_WITH_REFRESH_TOKEN: | 55 case SIGNIN_TYPE_WITH_REFRESH_TOKEN: |
| 56 return "With refresh token"; | 56 return "With refresh token"; |
| 57 case SIGNIN_TYPE_WITHOUT_REFRESH_TOKEN: |
| 58 return "Without refresh token"; |
| 57 } | 59 } |
| 58 | 60 |
| 59 NOTREACHED(); | 61 NOTREACHED(); |
| 60 return std::string(); | 62 return std::string(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 bool SigninManager::PrepareForSignin(SigninType type, | 65 bool SigninManager::PrepareForSignin(SigninType type, |
| 64 const std::string& gaia_id, | 66 const std::string& gaia_id, |
| 65 const std::string& username, | 67 const std::string& username, |
| 66 const std::string& password) { | 68 const std::string& password) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 94 return true; | 96 return true; |
| 95 } | 97 } |
| 96 | 98 |
| 97 void SigninManager::StartSignInWithRefreshToken( | 99 void SigninManager::StartSignInWithRefreshToken( |
| 98 const std::string& refresh_token, | 100 const std::string& refresh_token, |
| 99 const std::string& gaia_id, | 101 const std::string& gaia_id, |
| 100 const std::string& username, | 102 const std::string& username, |
| 101 const std::string& password, | 103 const std::string& password, |
| 102 const OAuthTokenFetchedCallback& callback) { | 104 const OAuthTokenFetchedCallback& callback) { |
| 103 DCHECK(!IsAuthenticated()); | 105 DCHECK(!IsAuthenticated()); |
| 104 | 106 SigninType signin_type = refresh_token.empty() |
| 105 if (!PrepareForSignin(SIGNIN_TYPE_WITH_REFRESH_TOKEN, gaia_id, username, | 107 ? SIGNIN_TYPE_WITHOUT_REFRESH_TOKEN |
| 106 password)) { | 108 : SIGNIN_TYPE_WITH_REFRESH_TOKEN; |
| 109 if (!PrepareForSignin(signin_type, gaia_id, username, password)) { |
| 107 return; | 110 return; |
| 108 } | 111 } |
| 109 | 112 |
| 110 // Store our token. | 113 // Store the refresh token. |
| 111 temp_refresh_token_ = refresh_token; | 114 temp_refresh_token_ = refresh_token; |
| 112 | 115 |
| 113 if (!callback.is_null() && !temp_refresh_token_.empty()) { | 116 if (!callback.is_null()) { |
| 117 // Callback present, let the caller complete the pending sign-in. |
| 114 callback.Run(temp_refresh_token_); | 118 callback.Run(temp_refresh_token_); |
| 115 } else { | 119 } else { |
| 116 // No oauth token or callback, so just complete our pending signin. | 120 // No callback, so just complete the pending signin. |
| 117 CompletePendingSignin(); | 121 CompletePendingSignin(); |
| 118 } | 122 } |
| 119 } | 123 } |
| 120 | 124 |
| 121 void SigninManager::CopyCredentialsFrom(const SigninManager& source) { | 125 void SigninManager::CopyCredentialsFrom(const SigninManager& source) { |
| 122 DCHECK_NE(this, &source); | 126 DCHECK_NE(this, &source); |
| 123 possibly_invalid_account_id_ = source.possibly_invalid_account_id_; | 127 possibly_invalid_account_id_ = source.possibly_invalid_account_id_; |
| 124 possibly_invalid_gaia_id_ = source.possibly_invalid_gaia_id_; | 128 possibly_invalid_gaia_id_ = source.possibly_invalid_gaia_id_; |
| 125 possibly_invalid_email_ = source.possibly_invalid_email_; | 129 possibly_invalid_email_ = source.possibly_invalid_email_; |
| 126 temp_refresh_token_ = source.temp_refresh_token_; | 130 temp_refresh_token_ = source.temp_refresh_token_; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 347 |
| 344 cookie_manager_service_->AddAccountToCookie(GetAuthenticatedAccountId(), | 348 cookie_manager_service_->AddAccountToCookie(GetAuthenticatedAccountId(), |
| 345 "ChromiumSigninManager"); | 349 "ChromiumSigninManager"); |
| 346 } | 350 } |
| 347 | 351 |
| 348 void SigninManager::CompletePendingSignin() { | 352 void SigninManager::CompletePendingSignin() { |
| 349 NotifyDiagnosticsObservers(SIGNIN_COMPLETED, "Successful"); | 353 NotifyDiagnosticsObservers(SIGNIN_COMPLETED, "Successful"); |
| 350 DCHECK(!possibly_invalid_account_id_.empty()); | 354 DCHECK(!possibly_invalid_account_id_.empty()); |
| 351 OnSignedIn(); | 355 OnSignedIn(); |
| 352 | 356 |
| 353 DCHECK(!temp_refresh_token_.empty()); | |
| 354 DCHECK(IsAuthenticated()); | 357 DCHECK(IsAuthenticated()); |
| 355 | 358 |
| 356 std::string account_id = GetAuthenticatedAccountId(); | 359 if (!temp_refresh_token_.empty()) { |
| 357 token_service_->UpdateCredentials(account_id, temp_refresh_token_); | 360 std::string account_id = GetAuthenticatedAccountId(); |
| 358 temp_refresh_token_.clear(); | 361 token_service_->UpdateCredentials(account_id, temp_refresh_token_); |
| 359 | 362 temp_refresh_token_.clear(); |
| 363 } |
| 360 MergeSigninCredentialIntoCookieJar(); | 364 MergeSigninCredentialIntoCookieJar(); |
| 361 } | 365 } |
| 362 | 366 |
| 363 void SigninManager::OnExternalSigninCompleted(const std::string& username) { | 367 void SigninManager::OnExternalSigninCompleted(const std::string& username) { |
| 364 AccountInfo info = | 368 AccountInfo info = |
| 365 account_tracker_service()->FindAccountInfoByEmail(username); | 369 account_tracker_service()->FindAccountInfoByEmail(username); |
| 366 DCHECK(!info.gaia.empty()); | 370 DCHECK(!info.gaia.empty()); |
| 367 DCHECK(!info.email.empty()); | 371 DCHECK(!info.email.empty()); |
| 368 possibly_invalid_account_id_ = info.account_id; | 372 possibly_invalid_account_id_ = info.account_id; |
| 369 possibly_invalid_gaia_id_ = info.gaia; | 373 possibly_invalid_gaia_id_ = info.gaia; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 account_tracker_service()->SetMigrationDone(); | 432 account_tracker_service()->SetMigrationDone(); |
| 429 token_service_->RemoveObserver(this); | 433 token_service_->RemoveObserver(this); |
| 430 } | 434 } |
| 431 } | 435 } |
| 432 | 436 |
| 433 void SigninManager::ProhibitSignout(bool prohibit_signout) { | 437 void SigninManager::ProhibitSignout(bool prohibit_signout) { |
| 434 prohibit_signout_ = prohibit_signout; | 438 prohibit_signout_ = prohibit_signout; |
| 435 } | 439 } |
| 436 | 440 |
| 437 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } | 441 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } |
| OLD | NEW |