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

Fix sync resend (uplift to 0.66.x) #2967

Merged
merged 1 commit into from
Jul 22, 2019
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
2 changes: 1 addition & 1 deletion components/brave_sync/brave_sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ BraveSyncServiceImpl::BraveSyncServiceImpl(Profile* profile) :
sync_client_.get(),
sync_prefs_.get())),
timer_(std::make_unique<base::RepeatingTimer>()),
unsynced_send_interval_(base::TimeDelta::FromMinutes(10)) {
unsynced_send_interval_(base::TimeDelta::FromMinutes(60)) {
// Moniter syncs prefs required in GetSettingsAndDevices
profile_pref_change_registrar_.Init(profile->GetPrefs());
profile_pref_change_registrar_.Add(
Expand Down
9 changes: 4 additions & 5 deletions components/brave_sync/client/bookmark_change_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ void UpdateNode(bookmarks::BookmarkModel* model,
model->SetNodeMetaInfo(node, "object_id", record->objectId);
model->SetNodeMetaInfo(node, "order", bookmark.order);

// updating the sync_timestamp marks this record as synced
model->SetNodeMetaInfo(node,
"sync_timestamp",
std::to_string(record->syncTimestamp.ToJsTime()));

if (pending_node_root && node->parent() == pending_node_root) {
model->SetNodeMetaInfo(node, "parent_object_id",
bookmark.parentFolderObjectId);
Expand Down Expand Up @@ -782,6 +777,10 @@ void BookmarkChangeProcessor::GetAllSyncData(
auto* node = FindByObjectId(bookmark_model_, record->objectId);
if (node) {
resolved_record->second = BookmarkNodeToSyncBookmark(node);
// Update "sync_timestamp"
bookmark_model_->SetNodeMetaInfo(node,
"sync_timestamp",
std::to_string(record->syncTimestamp.ToJsTime()));
}

records_and_existing_objects->push_back(std::move(resolved_record));
Expand Down
63 changes: 63 additions & 0 deletions components/brave_sync/client/bookmark_change_processor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1403,3 +1403,66 @@ TEST_F(BraveBookmarkChangeProcessorTest, ApplyOrder) {
node_a->GetMetaInfo("order", &order);
EXPECT_EQ(order, new_order);
}

namespace {

const bookmarks::BookmarkNode* GetSingleNodeByUrl(
bookmarks::BookmarkModel* model, const std::string& url) {
std::vector<const bookmarks::BookmarkNode*> nodes;
model->GetNodesByURL(GURL(url), &nodes);
size_t nodes_size = nodes.size();
CHECK_EQ(nodes_size, 1u);
const bookmarks::BookmarkNode* node = nodes.at(0);
return node;
}

} // namespace

TEST_F(BraveBookmarkChangeProcessorTest, SyncTimestampMetaUpdateWay) {
// Should update "sync_timestamp":
// "get-existing-objects" => model => "resolve-sync-records"
// (GetAllSyncData)
//
// Should not update "sync_timestamp":
// "resolved-sync-records" => model
// (ApplyChangesFromSyncModel)

change_processor()->Start();

RecordsList records;
const char* record_b_object_id =
"222, 222, 37, 61, 199, 11, 166, 234, "
"214, 197, 45, 215, 241, 206, 219, 130";
records.push_back(SimpleBookmarkSyncRecord(
SyncRecord::Action::A_CREATE,
record_b_object_id,
"https://b.com/",
"B.com - title",
"1.1.1.2", ""));

change_processor()->ApplyChangesFromSyncModel(records);

std::string node_b_sync_timestamp;
GetSingleNodeByUrl(model(), "https://b.com/")->GetMetaInfo(
"sync_timestamp", &node_b_sync_timestamp);
EXPECT_EQ(node_b_sync_timestamp, "");

RecordsList records_to_resolve;
records_to_resolve.push_back(SimpleBookmarkSyncRecord(
SyncRecord::Action::A_UPDATE,
record_b_object_id,
"https://b.com/",
"B.com - title - modified",
"1.1.1.2", ""));
auto timestamp_resolve = base::Time::Now();
records_to_resolve.at(0)->syncTimestamp = timestamp_resolve;

brave_sync::SyncRecordAndExistingList records_and_existing_objects;
change_processor()->GetAllSyncData(records_to_resolve,
&records_and_existing_objects);
GetSingleNodeByUrl(model(), "https://b.com/")->GetMetaInfo(
"sync_timestamp", &node_b_sync_timestamp);

EXPECT_EQ(node_b_sync_timestamp,
std::to_string(timestamp_resolve.ToJsTime()));
}