Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync fix bookmarks object id duplication #4710

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions browser/profiles/brave_bookmark_model_loaded_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ void BraveBookmarkModelLoadedObserver::BookmarkModelLoaded(
#endif
profile_->GetPrefs()->SetBoolean(kOtherBookmarksMigrated, true);
}

#if BUILDFLAG(ENABLE_BRAVE_SYNC)
BraveProfileSyncServiceImpl::AddNonClonedBookmarkKeys(model);
#endif

BookmarkModelLoadedObserver::BookmarkModelLoaded(model, ids_reassigned);
}
11 changes: 11 additions & 0 deletions components/brave_sync/brave_profile_sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,17 @@ void BraveProfileSyncServiceImpl::OnSyncReadyBookmarksModelLoaded() {
}
}

// static
void BraveProfileSyncServiceImpl::AddNonClonedBookmarkKeys(
BookmarkModel* model) {
DCHECK(model);
DCHECK(model->loaded());
model->AddNonClonedKey("object_id");
model->AddNonClonedKey("order");
model->AddNonClonedKey("sync_timestamp");
model->AddNonClonedKey("version");
}

syncer::ModelTypeSet BraveProfileSyncServiceImpl::GetPreferredDataTypes()
const {
// Force DEVICE_INFO type to have nudge cycle each time to fetch
Expand Down
2 changes: 2 additions & 0 deletions components/brave_sync/brave_profile_sync_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class BraveProfileSyncServiceImpl
BraveSyncClient* GetBraveSyncClient() override;
#endif

static void AddNonClonedBookmarkKeys(BookmarkModel* model);

bool IsBraveSyncEnabled() const override;

syncer::ModelTypeSet GetPreferredDataTypes() const override;
Expand Down
31 changes: 31 additions & 0 deletions components/brave_sync/brave_sync_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1600,3 +1600,34 @@ TEST_F(BraveSyncServiceTest, CheckOtherBookmarkChildRecord) {
sync_service()->CheckOtherBookmarkChildRecord(record_a1.get());
EXPECT_EQ(record_a1->GetBookmark().parentFolderObjectId, object_id_iter1);
}

TEST_F(BraveSyncServiceTest, AddNonClonedBookmarkKeys) {
sync_service()->AddNonClonedBookmarkKeys(model());
const bookmarks::BookmarkNode* bookmark_a1 =
model()->AddURL(model()->other_node(), 0, base::ASCIIToUTF16("A1"),
GURL("https://a1.com"));

AsMutable(bookmark_a1)->SetMetaInfo("object_id", "object_id_value");
AsMutable(bookmark_a1)->SetMetaInfo("order", "order_value");
AsMutable(bookmark_a1)->SetMetaInfo("sync_timestamp", "sync_timestamp_value");
AsMutable(bookmark_a1)->SetMetaInfo("version", "version_value");

model()->Copy(bookmark_a1, model()->other_node(), 1);

const bookmarks::BookmarkNode* bookmark_copy =
model()->other_node()->children().at(1).get();

std::string meta_object_id;
EXPECT_FALSE(bookmark_copy->GetMetaInfo("object_id", &meta_object_id));
EXPECT_TRUE(meta_object_id.empty());
std::string meta_order;
EXPECT_FALSE(bookmark_copy->GetMetaInfo("order", &meta_order));
EXPECT_TRUE(meta_order.empty());
std::string meta_sync_timestamp;
EXPECT_FALSE(
bookmark_copy->GetMetaInfo("sync_timestamp", &meta_sync_timestamp));
EXPECT_TRUE(meta_sync_timestamp.empty());
std::string meta_version;
EXPECT_FALSE(bookmark_copy->GetMetaInfo("version", &meta_version));
EXPECT_TRUE(meta_version.empty());
}