Commit 30eedfbd authored by Rushan Suleymanov's avatar Rushan Suleymanov Committed by Commit Bot

[Sync] Untrack sharing message entities when sync is stopped

Currently if sync is turned off (but keeps metadata) the sharing message
bridge will invoke a callback but continue sending messages after sync
is turned on.

In this patch the bridge stops tracking of entities when sync is turned
off in all cases.

Bug: 1060169
Change-Id: Id5ba8305b3e492cd99d2f4929911ac521972f98d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095104
Commit-Queue: Rushan Suleymanov <rushans@google.com>
Reviewed-by: default avatarvitaliii <vitaliii@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748884}
parent ff571471
...@@ -198,8 +198,7 @@ void SharingMessageBridgeImpl::ApplyStopSyncChanges( ...@@ -198,8 +198,7 @@ void SharingMessageBridgeImpl::ApplyStopSyncChanges(
sync_disabled_error_message.set_error_code( sync_disabled_error_message.set_error_code(
sync_pb::SharingMessageCommitError::SYNC_TURNED_OFF); sync_pb::SharingMessageCommitError::SYNC_TURNED_OFF);
for (auto& cth_and_callback : commit_callbacks_) { for (auto& cth_and_callback : commit_callbacks_) {
// We do not need to untrack data here because the change processor will change_processor()->UntrackEntityForClientTagHash(cth_and_callback.first);
// remove all entities anyway.
cth_and_callback.second->Run(sync_disabled_error_message); cth_and_callback.second->Run(sync_disabled_error_message);
} }
commit_callbacks_.clear(); commit_callbacks_.clear();
......
...@@ -224,4 +224,56 @@ IN_PROC_BROWSER_TEST_F(SingleClientSharingMessageSyncTest, ...@@ -224,4 +224,56 @@ IN_PROC_BROWSER_TEST_F(SingleClientSharingMessageSyncTest,
std::make_unique<SharingMessageSpecifics>(specifics), callback.Get()); std::make_unique<SharingMessageSpecifics>(specifics), callback.Get());
} }
IN_PROC_BROWSER_TEST_F(SingleClientSharingMessageSyncTest,
ShouldCleanPendingMessagesAfterSyncPaused) {
base::MockOnceCallback<void(const sync_pb::SharingMessageCommitError&)>
callback;
EXPECT_CALL(
callback,
Run(HasErrorCode(sync_pb::SharingMessageCommitError::SYNC_TURNED_OFF)));
ASSERT_TRUE(SetupSync());
SharingMessageBridge* sharing_message_bridge =
SharingMessageBridgeFactory::GetForBrowserContext(GetProfile(0));
SharingMessageSpecifics specifics;
specifics.set_payload("payload");
sharing_message_bridge->SendSharingMessage(
std::make_unique<SharingMessageSpecifics>(specifics), callback.Get());
GetClient(0)->StopSyncServiceWithoutClearingData();
GetClient(0)->StartSyncService();
ASSERT_TRUE(NextCycleIterationChecker(GetSyncService(0)).Wait());
EXPECT_TRUE(GetFakeServer()
->GetSyncEntitiesByModelType(syncer::SHARING_MESSAGE)
.empty());
}
IN_PROC_BROWSER_TEST_F(SingleClientSharingMessageSyncTest,
ShouldCleanPendingMessagesAfterSyncTurnedOff) {
base::MockOnceCallback<void(const sync_pb::SharingMessageCommitError&)>
callback;
EXPECT_CALL(
callback,
Run(HasErrorCode(sync_pb::SharingMessageCommitError::SYNC_TURNED_OFF)));
ASSERT_TRUE(SetupSync());
SharingMessageBridge* sharing_message_bridge =
SharingMessageBridgeFactory::GetForBrowserContext(GetProfile(0));
SharingMessageSpecifics specifics;
specifics.set_payload("payload");
sharing_message_bridge->SendSharingMessage(
std::make_unique<SharingMessageSpecifics>(specifics), callback.Get());
GetClient(0)->StopSyncServiceAndClearData();
GetClient(0)->StartSyncService();
ASSERT_TRUE(NextCycleIterationChecker(GetSyncService(0)).Wait());
EXPECT_TRUE(GetFakeServer()
->GetSyncEntitiesByModelType(syncer::SHARING_MESSAGE)
.empty());
}
} // namespace } // namespace
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