Commit a2301dea authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[PSS] Fix a broken invariant aroung !is_stopping_and_clearing_

This CL fixes a broken invariant that is_stopping_and_clearing is false
whenever StopAndClear() gets called. This does not have to be true and
this CL treats this special case without talking to UserSettings.

Bug: 928216
Change-Id: I4d6d9cf471d4327035f29d06635f340bfb707861
Reviewed-on: https://chromium-review.googlesource.com/c/1452002
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Auto-Submit: Jan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629155}
parent 38df1661
......@@ -1908,12 +1908,25 @@ bool ProfileSyncService::IsSyncAllowedByFlag() {
void ProfileSyncService::StopAndClear() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!is_stopping_and_clearing_);
// This can happen if the user had disabled sync before and is now setting up
// sync again but hits the "Cancel" button on the confirmation dialog.
// TODO(crbug.com/906034): Maybe we can streamline the defaults and the
// behavior on setting up sync so that either this whole early return goes
// away or it treats all "Cancel the confirmation" cases?
if (!user_settings_->IsSyncRequested()) {
StopImpl(CLEAR_DATA);
return;
}
// We need to remember that clearing of data is needed when sync will be
// stopped. This flag is cleared in OnSyncRequestedPrefChange() where sync
// gets stopped.
// gets stopped. This happens synchronously when |user_settings_| get changed
// below.
DCHECK(!is_stopping_and_clearing_);
is_stopping_and_clearing_ = true;
user_settings_->SetSyncRequested(false);
DCHECK(!is_stopping_and_clearing_);
}
void ProfileSyncService::ReconfigureDatatypeManager(
......
......@@ -951,6 +951,28 @@ TEST_F(ProfileSyncServiceWithStandaloneTransportTest, ClearDataOnSignOut) {
EXPECT_TRUE(local_device_info_provider()->GetLocalDeviceInfo());
}
TEST_F(ProfileSyncServiceWithStandaloneTransportTest, CancelSyncAfterSignOut) {
SignIn();
CreateService(ProfileSyncService::AUTO_START);
InitializeForNthSync();
ASSERT_EQ(syncer::SyncService::TransportState::ACTIVE,
service()->GetTransportState());
base::Time last_synced_time = service()->GetLastSyncedTime();
ASSERT_LT(base::Time::Now() - last_synced_time,
base::TimeDelta::FromMinutes(1));
// Disable sync.
service()->StopAndClear();
EXPECT_FALSE(service()->IsSyncFeatureEnabled());
// Calling StopAndClear while already stopped should not crash. This may
// (under some circumstances) happen when the user enables sync again but hits
// the cancel button at the end of the process.
ASSERT_FALSE(service()->GetUserSettings()->IsSyncRequested());
service()->StopAndClear();
EXPECT_FALSE(service()->IsSyncFeatureEnabled());
}
// Verify that credential errors get returned from GetAuthError().
TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) {
// This test needs to manually send access tokens (or errors), so 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