Commit 2524138f authored by Rushan Suleymanov's avatar Rushan Suleymanov Committed by Commit Bot

[Sync] Fix metadata with tracked unsyncable bookmark node.

This patch introduces check for unsyncable nodes while loading metadata
from the disk and throws away metadata if unsyncable node is tracked.

Bug: 1093024
Change-Id: Ib07c8999670b5831a3955d26734bf6704eb6232b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238826
Commit-Queue: Rushan Suleymanov <rushans@google.com>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776907}
parent 55331da0
......@@ -608,6 +608,9 @@ SyncedBookmarkTracker::InitEntitiesFromModelAndMetadata(
while (iterator.has_next()) {
const bookmarks::BookmarkNode* node = iterator.Next();
if (!model->client()->CanSyncNode(node)) {
if (bookmark_node_to_entities_map_.count(node) != 0) {
return CorruptionReason::TRACKED_MANAGED_NODE;
}
continue;
}
if (bookmark_node_to_entities_map_.count(node) == 0) {
......
......@@ -297,7 +297,9 @@ class SyncedBookmarkTracker {
UNTRACKED_BOOKMARK = 8,
BOOKMARK_GUID_MISMATCH = 9,
DUPLICATED_CLIENT_TAG_HASH = 10,
kMaxValue = DUPLICATED_CLIENT_TAG_HASH
TRACKED_MANAGED_NODE = 11,
kMaxValue = TRACKED_MANAGED_NODE
};
SyncedBookmarkTracker(sync_pb::ModelTypeState model_type_state,
......
......@@ -47,7 +47,9 @@ enum class ExpectedCorruptionReason {
UNTRACKED_BOOKMARK = 8,
BOOKMARK_GUID_MISMATCH = 9,
DUPLICATED_CLIENT_TAG_HASH = 10,
kMaxValue = DUPLICATED_CLIENT_TAG_HASH
TRACKED_MANAGED_NODE = 11,
kMaxValue = TRACKED_MANAGED_NODE
};
sync_pb::EntitySpecifics GenerateSpecifics(const std::string& title,
......@@ -743,6 +745,41 @@ TEST(SyncedBookmarkTrackerTest,
/*count=*/1);
}
TEST(SyncedBookmarkTrackerTest,
ShouldNotMatchModelAndMetadataIfUnsyncableNodeIsTracked) {
// Add a managed node with an arbitrary id 100.
const int64_t kManagedNodeId = 100;
auto owned_managed_node = std::make_unique<bookmarks::BookmarkPermanentNode>(
kManagedNodeId, bookmarks::BookmarkNode::FOLDER);
auto client = std::make_unique<bookmarks::TestBookmarkClient>();
bookmarks::BookmarkNode* managed_node = client->EnableManagedNode();
std::unique_ptr<bookmarks::BookmarkModel> model =
bookmarks::TestBookmarkClient::CreateModelWithClient(std::move(client));
// The model should contain the managed node now.
ASSERT_THAT(GetBookmarkNodeByID(model.get(), kManagedNodeId),
Eq(managed_node));
// Add entries for all the permanent nodes. TestBookmarkClient creates all the
// 3 permanent nodes.
sync_pb::BookmarkModelMetadata model_metadata =
CreateMetadataForPermanentNodes(model.get());
// Add unsyncable node to metadata.
*model_metadata.add_bookmarks_metadata() =
CreateNodeMetadata(managed_node->id(),
/*server_id=*/"server_id");
base::HistogramTester histogram_tester;
EXPECT_THAT(SyncedBookmarkTracker::CreateFromBookmarkModelAndMetadata(
model.get(), std::move(model_metadata)),
IsNull());
histogram_tester.ExpectUniqueSample(
"Sync.BookmarksModelMetadataCorruptionReason",
/*sample=*/ExpectedCorruptionReason::TRACKED_MANAGED_NODE, /*count=*/1);
}
TEST(SyncedBookmarkTrackerTest,
ShouldMatchModelAndMetadataDespiteGuidMismatch) {
base::test::ScopedFeatureList override_features;
......
......@@ -66180,6 +66180,7 @@ would be helpful to identify which type is being sent.
<int value="8" label="Bookmark in model is missing sync metadata"/>
<int value="9" label="Client tag hash does not match bookmark GUID"/>
<int value="10" label="Duplicate client tag hashes exist"/>
<int value="11" label="Managed bookmark has sync metadata"/>
</enum>
<enum name="SyncBookmarkModelSyncState">
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