Chromium Code Reviews| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 std::string pref_gaia_id = | 65 std::string pref_gaia_id = |
| 66 client_->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId); | 66 client_->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId); |
| 67 | 67 |
| 68 // If kGoogleServicesUserAccountId is empty, then this is either a chromeos | 68 // If kGoogleServicesUserAccountId is empty, then this is either a chromeos |
| 69 // machine or a really old profile on one of the other platforms. However | 69 // machine or a really old profile on one of the other platforms. However |
| 70 // in this case the account tracker should have the gaia_id so fetch it | 70 // in this case the account tracker should have the gaia_id so fetch it |
| 71 // from there. | 71 // from there. |
| 72 if (!pref_account_username.empty() && pref_gaia_id.empty()) { | 72 if (!pref_account_username.empty() && pref_gaia_id.empty()) { |
| 73 AccountTrackerService::AccountInfo info = | 73 AccountTrackerService::AccountInfo info = |
| 74 account_tracker_service_->GetAccountInfo(pref_account_username); | 74 account_tracker_service_->GetAccountInfo(pref_account_username); |
| 75 DCHECK(!info.gaia.empty()); | |
| 76 pref_gaia_id = info.gaia; | 75 pref_gaia_id = info.gaia; |
| 76 | |
| 77 // If |pref_gaia_id| is still null, this means the profile has been in | |
| 78 // an auth error state for some time (since M39). It could also mean | |
| 79 // a profile that has not been used since M33. | |
| 77 } | 80 } |
| 78 | 81 |
| 79 if (!pref_account_username.empty() && !pref_gaia_id.empty()) { | 82 if (!pref_account_username.empty() && !pref_gaia_id.empty()) { |
| 80 account_id = account_tracker_service_->SeedAccountInfo( | 83 account_id = account_tracker_service_->SeedAccountInfo( |
| 81 pref_gaia_id, pref_account_username); | 84 pref_gaia_id, pref_account_username); |
| 85 } else { | |
| 86 // If chrome is still using email as the account id, use the value of the | |
| 87 // old pref directly. Otherwise, there is no way to know what the account | |
| 88 // id should be. The user is essentially signed out. | |
| 89 // TODO(rogerta): may want to show a toast or something. | |
| 90 if (account_tracker_service_->GetMigrationState() == | |
| 91 AccountTrackerService::MIGRATION_NOT_STARTED) { | |
| 92 account_id = pref_account_username; | |
|
Mike Lerman
2015/04/22 13:46:37
The control flow could lead here even if pref_acco
Roger Tawa OOO till Jul 10th
2015/04/22 17:59:29
Yes it could. That happens when the profile is no
| |
| 93 } | |
| 94 } | |
| 82 | 95 |
| 83 // Now remove obsolete preferences. | 96 // Now remove obsolete preferences. |
| 84 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); | 97 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
|
Mike Lerman
2015/04/22 13:46:37
Wouldn't we only want to clear the kGoogleServices
Roger Tawa OOO till Jul 10th
2015/04/22 17:59:28
Moving forward, this pref is obsolete. If we don'
| |
| 85 | 98 |
| 86 // TODO(rogerta): once migration to gaia id is complete, remove | 99 // TODO(rogerta): once migration to gaia id is complete, remove |
| 87 // kGoogleServicesUserAccountId and change all uses of that pref to | 100 // kGoogleServicesUserAccountId and change all uses of that pref to |
| 88 // kGoogleServicesAccountId. | 101 // kGoogleServicesAccountId. |
| 89 } | |
| 90 } | 102 } |
| 91 | 103 |
| 92 if (!account_id.empty()) | 104 if (!account_id.empty()) |
| 93 SetAuthenticatedAccountId(account_id); | 105 SetAuthenticatedAccountId(account_id); |
| 94 } | 106 } |
| 95 | 107 |
| 96 bool SigninManagerBase::IsInitialized() const { return initialized_; } | 108 bool SigninManagerBase::IsInitialized() const { return initialized_; } |
| 97 | 109 |
| 98 bool SigninManagerBase::IsSigninAllowed() const { | 110 bool SigninManagerBase::IsSigninAllowed() const { |
| 99 return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); | 111 return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); |
| 100 } | 112 } |
| 101 | 113 |
| 102 std::string SigninManagerBase::GetAuthenticatedUsername() const { | 114 std::string SigninManagerBase::GetAuthenticatedUsername() const { |
| 103 return account_tracker_service_->GetAccountInfo( | 115 AccountTrackerService::AccountInfo info = |
|
Mike Lerman
2015/04/22 13:46:37
nit: Can this fit on 2 lines?
Roger Tawa OOO till Jul 10th
2015/04/22 17:59:28
Done.
| |
| 104 GetAuthenticatedAccountId()).email; | 116 account_tracker_service_->GetAccountInfo( |
| 117 GetAuthenticatedAccountId()); | |
| 118 | |
| 119 // Until we switch to gaia id as the account id, we'll assume we can use the | |
| 120 // account_id as an email. This DCHECK makes sure this code is not forgotten | |
| 121 // during the migration. | |
| 122 DCHECK(!info.email.empty() || | |
| 123 (account_tracker_service_->GetMigrationState() == | |
| 124 AccountTrackerService::MIGRATION_NOT_STARTED)); | |
| 125 | |
| 126 return info.email.empty() ? GetAuthenticatedAccountId() : info.email; | |
| 105 } | 127 } |
| 106 | 128 |
| 107 const std::string& SigninManagerBase::GetAuthenticatedAccountId() const { | 129 const std::string& SigninManagerBase::GetAuthenticatedAccountId() const { |
| 108 return authenticated_account_id_; | 130 return authenticated_account_id_; |
| 109 } | 131 } |
| 110 | 132 |
| 111 void SigninManagerBase::SetAuthenticatedAccountInfo(const std::string& gaia_id, | 133 void SigninManagerBase::SetAuthenticatedAccountInfo(const std::string& gaia_id, |
| 112 const std::string& email) { | 134 const std::string& email) { |
| 113 std::string account_id = | 135 std::string account_id = |
| 114 account_tracker_service_->SeedAccountInfo(gaia_id, email); | 136 account_tracker_service_->SeedAccountInfo(gaia_id, email); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 131 DCHECK(pref_account_id.empty() || pref_account_id == account_id) | 153 DCHECK(pref_account_id.empty() || pref_account_id == account_id) |
| 132 << "account_id=" << account_id | 154 << "account_id=" << account_id |
| 133 << " pref_account_id=" << pref_account_id; | 155 << " pref_account_id=" << pref_account_id; |
| 134 authenticated_account_id_ = account_id; | 156 authenticated_account_id_ = account_id; |
| 135 client_->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, account_id); | 157 client_->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, account_id); |
| 136 | 158 |
| 137 // This preference is set so that code on I/O thread has access to the | 159 // This preference is set so that code on I/O thread has access to the |
| 138 // Gaia id of the signed in user. | 160 // Gaia id of the signed in user. |
| 139 AccountTrackerService::AccountInfo info = | 161 AccountTrackerService::AccountInfo info = |
| 140 account_tracker_service_->GetAccountInfo(account_id); | 162 account_tracker_service_->GetAccountInfo(account_id); |
| 141 DCHECK(!info.gaia.empty()); | 163 |
| 142 client_->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, | 164 // When this function is called from Initialize(), it's possible for |
| 143 info.gaia); | 165 // |info.gaia| to be empty when migrating from a really old profile. |
| 166 if (!info.gaia.empty()) { | |
| 167 client_->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, | |
| 168 info.gaia); | |
| 169 } | |
| 144 | 170 |
| 145 // Go ahead and update the last signed in account info here as well. Once a | 171 // Go ahead and update the last signed in account info here as well. Once a |
| 146 // user is signed in the two preferences should match. Doing it here as | 172 // user is signed in the two preferences should match. Doing it here as |
| 147 // opposed to on signin allows us to catch the upgrade scenario. | 173 // opposed to on signin allows us to catch the upgrade scenario. |
| 148 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, | 174 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, |
| 149 info.email); | 175 info.email); |
| 150 } | 176 } |
| 151 | 177 |
| 152 bool SigninManagerBase::IsAuthenticated() const { | 178 bool SigninManagerBase::IsAuthenticated() const { |
| 153 return !authenticated_account_id_.empty(); | 179 return !authenticated_account_id_.empty(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 178 signin_diagnostics_observers_.RemoveObserver(observer); | 204 signin_diagnostics_observers_.RemoveObserver(observer); |
| 179 } | 205 } |
| 180 | 206 |
| 181 void SigninManagerBase::NotifyDiagnosticsObservers( | 207 void SigninManagerBase::NotifyDiagnosticsObservers( |
| 182 const TimedSigninStatusField& field, | 208 const TimedSigninStatusField& field, |
| 183 const std::string& value) { | 209 const std::string& value) { |
| 184 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, | 210 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, |
| 185 signin_diagnostics_observers_, | 211 signin_diagnostics_observers_, |
| 186 NotifySigninValueChanged(field, value)); | 212 NotifySigninValueChanged(field, value)); |
| 187 } | 213 } |
| OLD | NEW |