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
Apply device id v2 #4159
Merged
+576
−211
Merged
Apply device id v2 #4159
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6805ec2
deviceIdV2 and extra SAVE_INIT_DATA for migration
darkdh fd69880
Delete and create new device record to apply device id v2
darkdh 3382a50
Save this device object id for future update
darkdh 8e9e192
Propagate device id v2 for existing devices and delete device by devi…
darkdh de60324
fix sync unittest and lint
darkdh 6d76b38
Add test for device id v2 migration
darkdh f5ba9dd
bump deps for https://github.com/brave/sync/pull/362
bridiver a5c94c1
convert sync endpoint to gn config
bridiver 474c06f
always point to production for now
bridiver 33adbef
Bump brave-sync commit to production(master branch)
darkdh File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
deviceIdV2 and extra SAVE_INIT_DATA for migration
- Loading branch information
| @@ -81,7 +81,8 @@ std::string GetDeviceName() { | ||
| RecordsListPtr CreateDeviceRecord(const std::string& device_name, | ||
| const std::string& object_id, | ||
| const SyncRecord::Action& action, | ||
| const std::string& device_id) { | ||
| const std::string& device_id, | ||
| const std::string& device_id_v2) { | ||
| RecordsListPtr records = std::make_unique<RecordsList>(); | ||
|
|
||
| SyncRecordPtr record = std::make_unique<SyncRecord>(); | ||
| @@ -93,6 +94,7 @@ RecordsListPtr CreateDeviceRecord(const std::string& device_name, | ||
|
|
||
| std::unique_ptr<Device> device = std::make_unique<Device>(); | ||
| device->name = device_name; | ||
| device->deviceIdV2 = device_id_v2; | ||
| record->SetDevice(std::move(device)); | ||
|
|
||
| records->emplace_back(std::move(record)); | ||
| @@ -157,6 +159,7 @@ SyncRecordPtr PrepareResolvedDevice(SyncDevice* device, | ||
| std::unique_ptr<jslib::Device> device_record = | ||
| std::make_unique<jslib::Device>(); | ||
| device_record->name = device->name_; | ||
| device_record->deviceIdV2 = device->device_id_v2_; | ||
| record->SetDevice(std::move(device_record)); | ||
| return record; | ||
| } | ||
| @@ -287,9 +290,10 @@ void BraveProfileSyncServiceImpl::OnDeleteDevice(const std::string& device_id) { | ||
| const SyncDevice* device = sync_devices->GetByDeviceId(device_id); | ||
| if (device) { | ||
| const std::string device_name = device->name_; | ||
| const std::string device_id_v2 = device->device_id_v2_; | ||
| const std::string object_id = device->object_id_; | ||
| SendDeviceSyncRecord(SyncRecord::Action::A_DELETE, device_name, device_id, | ||
| object_id); | ||
| device_id_v2, object_id); | ||
| if (device_id == brave_sync_prefs_->GetThisDeviceId()) { | ||
| // Mark state we have sent DELETE for own device and we are going to | ||
| // call ResetSyncInternal() at OnRecordsSent after ensuring we had made | ||
| @@ -407,6 +411,14 @@ void BraveProfileSyncServiceImpl::OnGetInitData( | ||
| VLOG(1) << "[Brave Sync] Init empty device id"; | ||
| } | ||
|
|
||
| std::string device_id_v2; | ||
| if (!brave_sync_prefs_->GetDeviceIdV2().empty()) { | ||
| device_id_v2 = brave_sync_prefs_->GetDeviceIdV2(); | ||
| VLOG(1) << "[Brave Sync] Init device id_v2 from prefs: " << device_id_v2; | ||
| } else { | ||
| VLOG(1) << "[Brave Sync] Init empty device id_v2"; | ||
| } | ||
|
|
||
| DCHECK(!sync_version.empty()); | ||
| // TODO(bridiver) - this seems broken because using the version we get back | ||
| // from the server (currently v1.4.2) causes things to break. What is the | ||
| @@ -415,20 +427,19 @@ void BraveProfileSyncServiceImpl::OnGetInitData( | ||
|
|
||
| client_data::Config config; | ||
| config.api_version = brave_sync_prefs_->GetApiVersion(); | ||
| config.server_url = "https://sync.brave.com"; | ||
| config.server_url = "https://sync-staging.brave.com"; | ||
darkdh
Author
Member
|
||
| config.debug = true; | ||
| brave_sync_client_->SendGotInitData(seed, device_id, config); | ||
| brave_sync_client_->SendGotInitData(seed, device_id, config, device_id_v2); | ||
| } | ||
|
|
||
| void BraveProfileSyncServiceImpl::OnSaveInitData(const Uint8Array& seed, | ||
| const Uint8Array& device_id) { | ||
| void BraveProfileSyncServiceImpl::OnSaveInitData( | ||
| const Uint8Array& seed, const Uint8Array& device_id, | ||
| const std::string& device_id_v2) { | ||
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||
| DCHECK(!brave_sync_ready_); | ||
| // If we are here and brave_sync_initializing_ is false, we have came | ||
| // not from OnSetupSyncNewToSync or OnSetupSyncHaveCode. | ||
| // One case is we put wrong code words and then restarted before cleared | ||
| // kSyncEnabled pref. This should not happen. | ||
| DCHECK(brave_sync_initializing_); | ||
| // OnSaveInitData will not only be triggered by OnSetupSyncNewToSync or | ||
| // OnSetupSyncHaveCode, we use it to migrate device which doesn't have | ||
| // deviceIdV2 | ||
|
|
||
| std::string seed_str = StrFromUint8Array(seed); | ||
| std::string device_id_str = StrFromUint8Array(device_id); | ||
| @@ -438,6 +449,9 @@ void BraveProfileSyncServiceImpl::OnSaveInitData(const Uint8Array& seed, | ||
|
|
||
| brave_sync_prefs_->SetSeed(seed_str); | ||
| brave_sync_prefs_->SetThisDeviceId(device_id_str); | ||
| if (!brave_sync_initializing_ && brave_sync_prefs_->GetDeviceIdV2().empty()) | ||
| send_device_id_v2_update_ = true; | ||
| brave_sync_prefs_->SetDeviceIdV2(device_id_v2); | ||
|
|
||
| brave_sync_initializing_ = false; | ||
| } | ||
| @@ -861,21 +875,41 @@ void BraveProfileSyncServiceImpl::SendCreateDevice() { | ||
| std::string device_name = brave_sync_prefs_->GetThisDeviceName(); | ||
| std::string object_id = tools::GenerateObjectId(); | ||
| std::string device_id = brave_sync_prefs_->GetThisDeviceId(); | ||
| std::string device_id_v2 = brave_sync_prefs_->GetDeviceIdV2(); | ||
| CHECK(!device_id.empty()); | ||
|
|
||
| SendDeviceSyncRecord(SyncRecord::Action::A_CREATE, device_name, device_id, | ||
| object_id); | ||
| device_id_v2, object_id); | ||
| } | ||
|
|
||
| void BraveProfileSyncServiceImpl::SendUpdateDevice() { | ||
| DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | ||
|
|
||
| std::string device_id = brave_sync_prefs_->GetThisDeviceId(); | ||
| std::string device_name = brave_sync_prefs_->GetThisDeviceName(); | ||
| std::string device_id_v2 = brave_sync_prefs_->GetDeviceIdV2(); | ||
| auto sync_devices = brave_sync_prefs_->GetSyncDevices(); | ||
| // TODO(darkdh): need to get device by object id | ||
| const SyncDevice* device = sync_devices->GetByDeviceId(device_id); | ||
| if (device) { | ||
| std::string object_id = device->object_id_; | ||
|
|
||
| SendDeviceSyncRecord(SyncRecord::Action::A_UPDATE, device_name, device_id, | ||
| device_id_v2, object_id); | ||
| } | ||
| } | ||
|
|
||
| void BraveProfileSyncServiceImpl::SendDeviceSyncRecord( | ||
| const int action, | ||
| const std::string& device_name, | ||
| const std::string& device_id, | ||
| const std::string& device_id_v2, | ||
| const std::string& object_id) { | ||
| DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | ||
| RecordsListPtr records = | ||
| CreateDeviceRecord(device_name, object_id, | ||
| static_cast<SyncRecord::Action>(action), device_id); | ||
| static_cast<SyncRecord::Action>(action), device_id, | ||
| device_id_v2); | ||
| SendSyncRecords(SyncRecordType_PREFERENCES, std::move(records)); | ||
| } | ||
|
|
||
| @@ -889,9 +923,11 @@ void BraveProfileSyncServiceImpl::OnResolvedPreferences( | ||
| DCHECK(record->has_device() || record->has_sitesetting()); | ||
| if (record->has_device()) { | ||
| bool actually_merged = false; | ||
| auto& device = record->GetDevice(); | ||
| sync_devices->Merge( | ||
| SyncDevice(record->GetDevice().name, record->objectId, | ||
| record->deviceId, record->syncTimestamp.ToJsTime()), | ||
| record->deviceId, device.deviceIdV2, | ||
| record->syncTimestamp.ToJsTime()), | ||
| record->action, &actually_merged); | ||
| this_device_deleted = | ||
| this_device_deleted || | ||
| @@ -950,6 +986,10 @@ void BraveProfileSyncServiceImpl::OnPollSyncCycle(GetRecordsCallback cb, | ||
| SendCreateDevice(); | ||
| this_device_created_time_ = base::Time::Now(); | ||
| } | ||
| if (send_device_id_v2_update_) { | ||
| SendUpdateDevice(); | ||
| send_device_id_v2_update_ = false; | ||
| } | ||
|
|
||
| FetchDevices(); | ||
|
|
||
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
should this point to staging?