Commit 2b0e2397 authored by James Cook's avatar James Cook Committed by Commit Bot

chromeos: Only set primary account for new user logins

Today the code sets a primary account on every login. This should not
be necessary, but there is a comment saying it is done to ensure
the google service username is set. That code dates back to 2012 and
was apparently added for migration to a new pref. All users should be
migrated by now.

Remove the comment and only SetPrimaryAccount() for new logins.
Add CHECKs that a primary account exists for existing logins.

No behavior changes are expected.

See comments on this code review for details:
https://chromium-review.googlesource.com/c/chromium/src/+/2001018

Bug: none
Change-Id: I61e68c38a52a16b11508fb75fe0df8c9391645fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006261
Commit-Queue: James Cook <jamescook@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Auto-Submit: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732676}
parent 6e6da4ff
......@@ -1415,16 +1415,18 @@ void UserSessionManager::InitProfilePreferences(
// already present in |AccountManager|.
// 2. Make sure that IdentityManager has been notified about it.
base::Optional<AccountInfo> maybe_account_info =
base::Optional<AccountInfo> account_info =
identity_manager
->FindExtendedAccountInfoForAccountWithRefreshTokenByGaiaId(
gaia_id);
DCHECK(maybe_account_info.has_value());
// Make sure that the google service username is properly set (we do this
// on every sign in, not just the first login, to deal with existing
// profiles that might not have it set yet).
identity_manager->GetPrimaryAccountMutator()->SetPrimaryAccount(
maybe_account_info->account_id);
DCHECK(account_info.has_value());
if (user_manager->IsCurrentUserNew() || profile->IsNewProfile()) {
identity_manager->GetPrimaryAccountMutator()->SetPrimaryAccount(
account_info->account_id);
} else {
CHECK(identity_manager->HasPrimaryAccount());
CHECK_EQ(identity_manager->GetPrimaryAccountInfo().gaia, gaia_id);
}
} else {
// Make sure that the google service username is properly set (we do this
// on every sign in, not just the first login, to deal with existing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment