| 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_base.h" | 5 #include "components/signin/core/browser/signin_manager_base.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // If the user is clearing the token service from the command line, then | 35 // If the user is clearing the token service from the command line, then |
| 36 // clear their login info also (not valid to be logged in without any | 36 // clear their login info also (not valid to be logged in without any |
| 37 // tokens). | 37 // tokens). |
| 38 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 38 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 39 if (cmd_line->HasSwitch(switches::kClearTokenService)) | 39 if (cmd_line->HasSwitch(switches::kClearTokenService)) |
| 40 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); | 40 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
| 41 | 41 |
| 42 std::string user = | 42 std::string user = |
| 43 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 43 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| 44 if (!user.empty()) { | 44 if (!user.empty()) |
| 45 #if defined(OS_IOS) | |
| 46 // Prior to M38, Chrome on iOS did not normalize the email before setting | |
| 47 // it in SigninManager. |AccountReconcilor| expects the authenticated email | |
| 48 // to be normalized as it used as an account identifier and is compared | |
| 49 // to the accounts available in the cookies. | |
| 50 user = gaia::CanonicalizeEmail(gaia::SanitizeEmail(user)); | |
| 51 #endif | |
| 52 SetAuthenticatedUsername(user); | 45 SetAuthenticatedUsername(user); |
| 53 } | |
| 54 } | 46 } |
| 55 | 47 |
| 56 bool SigninManagerBase::IsInitialized() const { return initialized_; } | 48 bool SigninManagerBase::IsInitialized() const { return initialized_; } |
| 57 | 49 |
| 58 bool SigninManagerBase::IsSigninAllowed() const { | 50 bool SigninManagerBase::IsSigninAllowed() const { |
| 59 return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); | 51 return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); |
| 60 } | 52 } |
| 61 | 53 |
| 62 const std::string& SigninManagerBase::GetAuthenticatedUsername() const { | 54 std::string SigninManagerBase::GetAuthenticatedUsername() const { |
| 63 return authenticated_username_; | 55 return authenticated_username_; |
| 64 } | 56 } |
| 65 | 57 |
| 66 const std::string& SigninManagerBase::GetAuthenticatedAccountId() const { | 58 std::string SigninManagerBase::GetAuthenticatedAccountId() const { |
| 67 return GetAuthenticatedUsername(); | 59 return authenticated_account_id_; |
| 68 } | 60 } |
| 69 | 61 |
| 70 void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) { | 62 void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) { |
| 71 if (!authenticated_username_.empty()) { | 63 if (!authenticated_username_.empty()) { |
| 72 DLOG_IF(ERROR, !gaia::AreEmailsSame(username, authenticated_username_)) | 64 DLOG_IF(ERROR, !gaia::AreEmailsSame(username, authenticated_username_)) |
| 73 << "Tried to change the authenticated username to something different: " | 65 << "Tried to change the authenticated username to something different: " |
| 74 << "Current: " << authenticated_username_ << ", New: " << username; | 66 << "Current: " << authenticated_username_ << ", New: " << username; |
| 75 | 67 |
| 76 #if defined(OS_IOS) | 68 #if defined(OS_IOS) |
| 77 // Prior to M26, chrome on iOS did not normalize the email before setting | 69 // Prior to M26, chrome on iOS did not normalize the email before setting |
| 78 // it in SigninManager. If the emails are the same as given by | 70 // it in SigninManager. If the emails are the same as given by |
| 79 // gaia::AreEmailsSame() but not the same as given by std::string::op==(), | 71 // gaia::AreEmailsSame() but not the same as given by std::string::op==(), |
| 80 // make sure to set the authenticated name below. | 72 // make sure to set the authenticated name below. |
| 81 if (!gaia::AreEmailsSame(username, authenticated_username_) || | 73 if (!gaia::AreEmailsSame(username, authenticated_username_) || |
| 82 username == authenticated_username_) { | 74 username == authenticated_username_) { |
| 83 return; | 75 return; |
| 84 } | 76 } |
| 85 #else | 77 #else |
| 86 return; | 78 return; |
| 87 #endif | 79 #endif |
| 88 } | 80 } |
| 89 std::string pref_username = | 81 std::string pref_username = |
| 90 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 82 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| 91 DCHECK(pref_username.empty() || gaia::AreEmailsSame(username, pref_username)) | 83 DCHECK(pref_username.empty() || gaia::AreEmailsSame(username, pref_username)) |
| 92 << "username: " << username << "; pref_username: " << pref_username; | 84 << "username: " << username << "; pref_username: " << pref_username; |
| 93 authenticated_username_ = username; | 85 authenticated_username_ = username; |
| 86 authenticated_account_id_ = |
| 87 gaia::CanonicalizeEmail(gaia::SanitizeEmail(GetAuthenticatedUsername())); |
| 94 client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); | 88 client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); |
| 95 NotifyDiagnosticsObservers(USERNAME, username); | 89 NotifyDiagnosticsObservers(USERNAME, username); |
| 96 | 90 |
| 97 // Go ahead and update the last signed in username here as well. Once a | 91 // Go ahead and update the last signed in username here as well. Once a |
| 98 // user is signed in the two preferences should match. Doing it here as | 92 // user is signed in the two preferences should match. Doing it here as |
| 99 // opposed to on signin allows us to catch the upgrade scenario. | 93 // opposed to on signin allows us to catch the upgrade scenario. |
| 100 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username); | 94 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username); |
| 101 } | 95 } |
| 102 | 96 |
| 103 void SigninManagerBase::clear_authenticated_username() { | 97 void SigninManagerBase::ClearAuthenticatedUsername() { |
| 104 authenticated_username_.clear(); | 98 authenticated_username_.clear(); |
| 99 authenticated_account_id_.clear(); |
| 105 } | 100 } |
| 106 | 101 |
| 107 bool SigninManagerBase::IsAuthenticated() const { | 102 bool SigninManagerBase::IsAuthenticated() const { |
| 108 return !GetAuthenticatedAccountId().empty(); | 103 return !authenticated_account_id_.empty(); |
| 109 } | 104 } |
| 110 | 105 |
| 111 bool SigninManagerBase::AuthInProgress() const { | 106 bool SigninManagerBase::AuthInProgress() const { |
| 112 // SigninManagerBase never kicks off auth processes itself. | 107 // SigninManagerBase never kicks off auth processes itself. |
| 113 return false; | 108 return false; |
| 114 } | 109 } |
| 115 | 110 |
| 116 void SigninManagerBase::Shutdown() {} | 111 void SigninManagerBase::Shutdown() {} |
| 117 | 112 |
| 118 void SigninManagerBase::AddObserver(Observer* observer) { | 113 void SigninManagerBase::AddObserver(Observer* observer) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 141 NotifySigninValueChanged(field, value)); | 136 NotifySigninValueChanged(field, value)); |
| 142 } | 137 } |
| 143 | 138 |
| 144 void SigninManagerBase::NotifyDiagnosticsObservers( | 139 void SigninManagerBase::NotifyDiagnosticsObservers( |
| 145 const TimedSigninStatusField& field, | 140 const TimedSigninStatusField& field, |
| 146 const std::string& value) { | 141 const std::string& value) { |
| 147 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 142 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
| 148 signin_diagnostics_observers_, | 143 signin_diagnostics_observers_, |
| 149 NotifySigninValueChanged(field, value)); | 144 NotifySigninValueChanged(field, value)); |
| 150 } | 145 } |
| OLD | NEW |