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

Reset sync right away if devices size <= 1 #1191

Merged
merged 1 commit into from
Dec 28, 2018
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
19 changes: 13 additions & 6 deletions components/brave_sync/brave_sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,17 @@ void BraveSyncServiceImpl::OnDeleteDevice(const std::string& device_id) {
void BraveSyncServiceImpl::OnResetSync() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

const std::string device_id = sync_prefs_->GetThisDeviceId();

// We have to send delete record and wait for library deleted response then we
// can reset it by ResetInternal()
OnDeleteDevice(device_id);
auto sync_devices = sync_prefs_->GetSyncDevices();
// If there is only one or no devices left, we won't get back resolved sync
// record back.
if (sync_devices->size() <= 1)
ResetSyncInternal();
else {
// We have to send delete record and wait for library deleted response then
// we can reset it by ResetInternal()
const std::string device_id = sync_prefs_->GetThisDeviceId();
OnDeleteDevice(device_id);
}
}

void BraveSyncServiceImpl::GetSettingsAndDevices(
Expand Down Expand Up @@ -479,7 +485,8 @@ void BraveSyncServiceImpl::OnResolvedPreferences(const RecordsList& records) {
record->action == jslib::SyncRecord::Action::A_DELETE &&
actually_merged);
contains_only_one_device = sync_devices->size() < 2 &&
record->action == jslib::SyncRecord::Action::A_DELETE;
record->action == jslib::SyncRecord::Action::A_DELETE &&
actually_merged;
}
} // for each device

Expand Down
12 changes: 2 additions & 10 deletions components/brave_sync/brave_sync_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,21 +483,13 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice) {
EXPECT_TRUE(DevicesContains(devices.get(), "2", "device2"));

using brave_sync::jslib::SyncRecord;
// device 2 => device 1
EXPECT_CALL(*sync_client(), SendSyncRecords).Times(2);
EXPECT_CALL(*sync_client(), SendSyncRecords).Times(1);
sync_service()->OnDeleteDevice("2");

RecordsList resolved_records;
auto resolved_record = SyncRecord::Clone(*records.at(1));
resolved_record->action = jslib::SyncRecord::Action::A_DELETE;
resolved_records.push_back(std::move(resolved_record));
EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1);
sync_service()->OnResolvedPreferences(resolved_records);

resolved_records.clear();
resolved_record = SyncRecord::Clone(*records.at(0));
resolved_record->action = jslib::SyncRecord::Action::A_DELETE;
resolved_records.push_back(std::move(resolved_record));
EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(3);
sync_service()->OnResolvedPreferences(resolved_records);

Expand Down Expand Up @@ -534,7 +526,7 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenSelfDeleted) {
auto resolved_record = SyncRecord::Clone(*records.at(0));
resolved_record->action = jslib::SyncRecord::Action::A_DELETE;
resolved_records.push_back(std::move(resolved_record));
EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(3);
EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(5);
sync_service()->OnResolvedPreferences(resolved_records);

auto devices_final = sync_service()->sync_prefs_->GetSyncDevices();
Expand Down