Chromium Code Reviews| Index: components/signin/core/browser/signin_manager_base.cc |
| diff --git a/components/signin/core/browser/signin_manager_base.cc b/components/signin/core/browser/signin_manager_base.cc |
| index 08cdc6ba44d7c28e491fa71a53738c4e8b0c1718..b059ece7d9a56f2c89586799b6d67dad2aeae9c2 100644 |
| --- a/components/signin/core/browser/signin_manager_base.cc |
| +++ b/components/signin/core/browser/signin_manager_base.cc |
| @@ -23,8 +23,16 @@ |
| using namespace signin_internals_util; |
| -SigninManagerBase::SigninManagerBase(SigninClient* client) |
| - : client_(client), initialized_(false), weak_pointer_factory_(this) {} |
| +SigninManagerBase::SigninManagerBase( |
| + SigninClient* client, |
| + AccountTrackerService* account_tracker_service) |
| + : client_(client), |
| + account_tracker_service_(account_tracker_service), |
| + initialized_(false), |
| + weak_pointer_factory_(this) { |
| + DCHECK(client_); |
| + DCHECK(account_tracker_service_); |
| +} |
| SigninManagerBase::~SigninManagerBase() {} |
| @@ -37,13 +45,45 @@ void SigninManagerBase::Initialize(PrefService* local_state) { |
| // clear their login info also (not valid to be logged in without any |
| // tokens). |
| base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| - if (cmd_line->HasSwitch(switches::kClearTokenService)) |
| + if (cmd_line->HasSwitch(switches::kClearTokenService)) { |
| + client_->GetPrefs()->ClearPref(prefs::kGoogleServicesAccountId); |
| client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
| + client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUserAccountId); |
|
Mike Lerman
2015/04/08 14:45:27
Also clear prefs::kGoogleServicesUserAccountId?
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
Already done. Did you mean some other pref?
Mike Lerman
2015/04/08 20:49:28
I did, I meeant kGoogleServicesLastAccountId.
Roger Tawa OOO till Jul 10th
2015/04/09 15:59:47
Good question. The *Last* prefs are for rememberi
|
| + } |
| + |
| + std::string account_id = |
| + client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId); |
| + |
| + // Handle backward compatibility: if kGoogleServicesAccountId is empty, but |
| + // kGoogleServicesUsername is not, then this is an old profile that needs to |
|
Mike Lerman
2015/04/08 14:45:27
comment nit: There's no "profile" within component
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
I think I'll it as is. I'm not sure "user" or "br
|
| + // be updated. kGoogleServicesUserAccountId should not be empty, and contains |
| + // the gaia_id. Use both properties to prime the account tracker before |
| + // proceeding. |
| + if (account_id.empty()) { |
| + std::string pref_account_username = |
| + client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| + std::string pref_gaia_id = |
| + client_->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId); |
| + DCHECK(pref_account_username.empty() || !pref_gaia_id.empty()); |
|
Mike Lerman
2015/04/08 14:45:27
Is this supposed to read !pref_account_username.em
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
I'm trying to DCHECK that if I have a username, th
|
| + if (!pref_account_username.empty() && !pref_gaia_id.empty()) { |
| + account_tracker_service_->SeedAccountInfo( |
|
Mike Lerman
2015/04/08 14:45:27
Should lines 69-72 instead be:
account_id = SetAut
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
I did it this way because this is the "upgrade" ca
|
| + pref_gaia_id, pref_account_username); |
| + |
| + account_id = pref_account_username; |
| + client_->GetPrefs()->SetString(prefs::kGoogleServicesLastAccountId, |
| + account_id); |
| + |
| + // Now remove obsolete preferences. |
| + client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
| + |
| + // TODO(rogerta): once migration to gaia id is complete, remove |
| + // kGoogleServicesUserAccountId and change all uses of that pref to |
| + // kGoogleServicesAccountId. |
| + } |
| + } |
| - std::string user = |
| - client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| - if (!user.empty()) |
| - SetAuthenticatedUsername(user); |
| + if (!account_id.empty()) |
| + SetAuthenticatedAccountId(account_id); |
| } |
| bool SigninManagerBase::IsInitialized() const { return initialized_; } |
| @@ -52,64 +92,66 @@ bool SigninManagerBase::IsSigninAllowed() const { |
| return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); |
| } |
| -const std::string& SigninManagerBase::GetAuthenticatedUsername() const { |
| - return authenticated_username_; |
| +std::string SigninManagerBase::GetAuthenticatedUsername() const { |
| + return account_tracker_service_->GetAccountInfo( |
|
Mike Lerman
2015/04/08 14:45:27
Hmm. Should this method be deleted, and users of t
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
It could, but there is just so much code that assu
|
| + GetAuthenticatedAccountId()).email; |
| } |
| const std::string& SigninManagerBase::GetAuthenticatedAccountId() const { |
| return authenticated_account_id_; |
| } |
| -void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) { |
| - DCHECK(!username.empty()); |
| - if (!authenticated_username_.empty()) { |
| - DLOG_IF(ERROR, !gaia::AreEmailsSame(username, authenticated_username_)) |
| - << "Tried to change the authenticated username to something different: " |
| - << "Current: " << authenticated_username_ << ", New: " << username; |
| - |
| -#if defined(OS_IOS) |
| - // Prior to M26, chrome on iOS did not normalize the email before setting |
| - // it in SigninManager. If the emails are the same as given by |
| - // gaia::AreEmailsSame() but not the same as given by std::string::op==(), |
| - // make sure to set the authenticated name below. |
| - if (!gaia::AreEmailsSame(username, authenticated_username_) || |
| - username == authenticated_username_) { |
| - return; |
| - } |
| -#else |
| +void SigninManagerBase::SetAuthenticatedAccountInfo(const std::string& gaia_id, |
| + const std::string& email) { |
| + std::string account_id = |
|
Mike Lerman
2015/04/08 14:45:27
Can this be a const std::string&?
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
SeedAccountInfo returns an AccountInfo by value.
|
| + account_tracker_service_->SeedAccountInfo(gaia_id, email); |
| + SetAuthenticatedAccountId(account_id); |
| +} |
| + |
| +void SigninManagerBase::SetAuthenticatedAccountId( |
| + const std::string& account_id) { |
| + DCHECK(!account_id.empty()); |
| + if (!authenticated_account_id_.empty()) { |
| + DLOG_IF(ERROR, account_id != authenticated_account_id_) |
| + << "Tried to change the authenticated id to something different: " |
| + << "Current: " << authenticated_account_id_ << ", New: " << account_id; |
| return; |
| -#endif |
| } |
| - std::string pref_username = |
| - client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| - DCHECK(pref_username.empty() || gaia::AreEmailsSame(username, pref_username)) |
| - << "username: " << username << "; pref_username: " << pref_username; |
| - authenticated_username_ = username; |
| - |
| - // TODO(rogerta): remove this DCHECK when migration work is started. |
| - DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, |
| - AccountTrackerService::GetMigrationState(client_->GetPrefs())); |
| - authenticated_account_id_ = |
| - AccountTrackerService::PickAccountIdForAccount(client_->GetPrefs(), |
| - username, |
| - username); |
| - client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); |
| - |
| - // Go ahead and update the last signed in username here as well. Once a |
| + |
| + std::string pref_account_id = |
| + client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId); |
| + |
| + DCHECK(pref_account_id.empty() || pref_account_id == account_id) |
| + << "account_id=" << account_id |
| + << " pref_account_id=" << pref_account_id; |
| + authenticated_account_id_ = account_id; |
| + client_->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, account_id); |
| + |
| + // This preference is set so that code on I/O thread has access to the |
| + // Gaia id of the signed in user. |
| + AccountTrackerService::AccountInfo info = |
| + account_tracker_service_->GetAccountInfo(account_id); |
| + DCHECK(!info.gaia.empty()); |
| + client_->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, |
| + info.gaia); |
| + |
| + // Go ahead and update the last signed in account info here as well. Once a |
| // user is signed in the two preferences should match. Doing it here as |
| // opposed to on signin allows us to catch the upgrade scenario. |
| - client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username); |
| -} |
| - |
| -void SigninManagerBase::ClearAuthenticatedUsername() { |
| - authenticated_username_.clear(); |
| - authenticated_account_id_.clear(); |
| + client_->GetPrefs()->SetString(prefs::kGoogleServicesLastAccountId, |
|
Mike Lerman
2015/04/08 14:45:27
Umm -you never seem to read the kGoogleServicesLas
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
kGoogleServicesLastUsername was used to know the i
Mike Lerman
2015/04/08 20:49:28
Since we'll be keeping kGoogleServicesLastUsername
Roger Tawa OOO till Jul 10th
2015/04/09 15:59:47
Done.
|
| + account_id); |
| + client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, |
|
Mike Lerman
2015/04/08 14:45:27
You never seem to read the kGoogleServicesLastUser
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
Used in inline_login_handler_impl.cc:405
|
| + info.email); |
| } |
| bool SigninManagerBase::IsAuthenticated() const { |
| return !authenticated_account_id_.empty(); |
| } |
| +void SigninManagerBase::clear_authenticated_user() { |
| + authenticated_account_id_.clear(); |
|
Mike Lerman
2015/04/08 14:45:27
Should this also clear the kGoogleServicesAccountI
Roger Tawa OOO till Jul 10th
2015/04/08 20:24:21
I don't think so.
Mike Lerman
2015/04/08 20:49:28
Then should the implementation of the hacker-style
Roger Tawa OOO till Jul 10th
2015/04/09 15:59:47
Done.
|
| +} |
| + |
| bool SigninManagerBase::AuthInProgress() const { |
| // SigninManagerBase never kicks off auth processes itself. |
| return false; |