Commit 3c43db3e authored by Marc Treib's avatar Marc Treib Committed by Chromium LUCI CQ

ProfileSyncService: Only call ClearPrimaryAccount if there is one

ClearPrimaryAccount is somewhat misnamed: It doesn't actually remove the
account, it only clears the sync-consented bit, so the account will
change from ConsentLevel::kSync to ConsentLevel::kNotRequired.

If the primary account doesn't have sync consent to begin with (i.e.
it's a Sync-the-transport user), then ClearPrimaryAccount should be a
no-op. However, currently it still records metrics, and it notifies
identity observers (even though nothing actually changed).

This CL is a quick-fix for that issue, until ClearPrimaryAccount is
actually fixed/redesigned.

Bug: 1155042
Change-Id: Icc711cbd8eb118fd3d1b2ff28b2f74df4d8cde65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566947
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833205}
parent 8fadec12
...@@ -1045,13 +1045,18 @@ void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { ...@@ -1045,13 +1045,18 @@ void ProfileSyncService::OnActionableError(const SyncProtocolError& error) {
// the next browser startup. // the next browser startup.
StopAndClear(); StopAndClear();
#if !BUILDFLAG(IS_CHROMEOS_ASH) #if !BUILDFLAG(IS_CHROMEOS_ASH)
// On every platform except ChromeOS, sign out the user after a dashboard // On every platform except ChromeOS, revoke the Sync consent in
// clear. // IdentityManager after a dashboard clear.
if (!IsLocalSyncEnabled()) { if (!IsLocalSyncEnabled() &&
identity_manager_->HasPrimaryAccount(signin::ConsentLevel::kSync)) {
auto* account_mutator = identity_manager_->GetPrimaryAccountMutator(); auto* account_mutator = identity_manager_->GetPrimaryAccountMutator();
// GetPrimaryAccountMutator() returns nullptr on ChromeOS only. // GetPrimaryAccountMutator() returns nullptr on ChromeOS only.
DCHECK(account_mutator); DCHECK(account_mutator);
// Note that this method is misnamed: It will not actually remove the
// primary account, it will just clear the Sync consent bit (i.e. the
// account will change from ConsentLevel::kSync to
// ConsentLevel::kNotRequired)
account_mutator->ClearPrimaryAccount( account_mutator->ClearPrimaryAccount(
signin::PrimaryAccountMutator::ClearAccountsAction::kDefault, signin::PrimaryAccountMutator::ClearAccountsAction::kDefault,
signin_metrics::SERVER_FORCED_DISABLE, signin_metrics::SERVER_FORCED_DISABLE,
......
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