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

Apply device id v2 #4159

Merged
merged 10 commits into from Dec 30, 2019

Delete and create new device record to apply device id v2

  • Loading branch information
darkdh authored and bridiver committed Dec 3, 2019
commit fd6988064ea38a8e26041e649de8e2be213f1330
2 DEPS
@@ -15,7 +15,7 @@ deps = {
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@13bb40a215248cfbdd87d0a6b425c8397402e9e6",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@e3742ba3e8942eea9e4755d91532491871bd3116",
"vendor/bat-native-tweetnacl": "https://github.com/brave-intl/bat-native-tweetnacl.git@800f9d40b7409239ff192e0be634764e747c7a75",
"components/brave_sync/extension/brave-sync": "https://github.com/brave/sync.git@77af1794c25d79bbb64b70bfcea0a0effd611798",
"components/brave_sync/extension/brave-sync": "https://github.com/brave/sync.git@f6a25c1fb62ef5c16e7cf7e2ff41e909a2123f5a",
"vendor/bat-native-usermodel": "https://github.com/brave-intl/bat-native-usermodel.git@45e32155af9897dbe1d5534dd36697ec4728bb75",
"vendor/challenge_bypass_ristretto_ffi": "https://github.com/brave-intl/challenge-bypass-ristretto-ffi.git@c396fb4eb9e9bf63b89ae5a0ec0b5f201d43c7c5",
}
@@ -412,8 +412,8 @@ void BraveProfileSyncServiceImpl::OnGetInitData(
}

std::string device_id_v2;
if (!brave_sync_prefs_->GetDeviceIdV2().empty()) {
device_id_v2 = brave_sync_prefs_->GetDeviceIdV2();
if (!brave_sync_prefs_->GetThisDeviceIdV2().empty()) {
device_id_v2 = brave_sync_prefs_->GetThisDeviceIdV2();
VLOG(1) << "[Brave Sync] Init device id_v2 from prefs: " << device_id_v2;
} else {
VLOG(1) << "[Brave Sync] Init empty device id_v2";
@@ -449,9 +449,10 @@ void BraveProfileSyncServiceImpl::OnSaveInitData(

brave_sync_prefs_->SetSeed(seed_str);
brave_sync_prefs_->SetThisDeviceId(device_id_str);
if (!brave_sync_initializing_ && brave_sync_prefs_->GetDeviceIdV2().empty())
if (!brave_sync_initializing_ &&
brave_sync_prefs_->GetThisDeviceIdV2().empty())
send_device_id_v2_update_ = true;
brave_sync_prefs_->SetDeviceIdV2(device_id_v2);
brave_sync_prefs_->SetThisDeviceIdV2(device_id_v2);

brave_sync_initializing_ = false;
}
@@ -875,7 +876,7 @@ 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();
std::string device_id_v2 = brave_sync_prefs_->GetThisDeviceIdV2();
CHECK(!device_id.empty());

SendDeviceSyncRecord(SyncRecord::Action::A_CREATE, device_name, device_id,
@@ -887,7 +888,7 @@ void BraveProfileSyncServiceImpl::SendUpdateDevice() {

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();
std::string device_id_v2 = brave_sync_prefs_->GetThisDeviceIdV2();
auto sync_devices = brave_sync_prefs_->GetSyncDevices();
// TODO(darkdh): need to get device by object id
const SyncDevice* device = sync_devices->GetByDeviceId(device_id);
@@ -915,7 +916,7 @@ void BraveProfileSyncServiceImpl::SendDeviceSyncRecord(

void BraveProfileSyncServiceImpl::OnResolvedPreferences(
const RecordsList& records) {
const std::string this_device_id = brave_sync_prefs_->GetThisDeviceId();
const std::string this_device_id_v2 = brave_sync_prefs_->GetThisDeviceIdV2();
bool this_device_deleted = false;

auto sync_devices = brave_sync_prefs_->GetSyncDevices();
@@ -931,7 +932,7 @@ void BraveProfileSyncServiceImpl::OnResolvedPreferences(
record->action, &actually_merged);
this_device_deleted =
this_device_deleted ||
(record->deviceId == this_device_id &&
(device.deviceIdV2 == this_device_id_v2 &&
record->action == SyncRecord::Action::A_DELETE && actually_merged);
}
} // for each device
@@ -987,7 +988,9 @@ void BraveProfileSyncServiceImpl::OnPollSyncCycle(GetRecordsCallback cb,
this_device_created_time_ = base::Time::Now();
}
if (send_device_id_v2_update_) {
SendUpdateDevice();
// SendUpdateDevice();
OnDeleteDevice(brave_sync_prefs_->GetThisDeviceId());
SendCreateDevice();
send_device_id_v2_update_ = false;
}

@@ -90,11 +90,11 @@ void Prefs::SetThisDeviceId(const std::string& device_id) {
pref_service_->SetString(kSyncDeviceId, device_id);
}

std::string Prefs::GetDeviceIdV2() const {
std::string Prefs::GetThisDeviceIdV2() const {
return pref_service_->GetString(kSyncDeviceIdV2);
}

void Prefs::SetDeviceIdV2(const std::string& device_id_v2) {
void Prefs::SetThisDeviceIdV2(const std::string& device_id_v2) {
DCHECK(!device_id_v2.empty());
pref_service_->SetString(kSyncDeviceIdV2, device_id_v2);
}
@@ -152,7 +152,7 @@ std::unique_ptr<brave_sync::Settings> Prefs::GetBraveSyncSettings() const {

settings->this_device_name_ = GetThisDeviceName();
settings->this_device_id_ = GetThisDeviceId();
settings->this_device_id_v2_ = GetDeviceIdV2();
settings->this_device_id_v2_ = GetThisDeviceIdV2();
settings->sync_this_device_ = GetSyncEnabled();
settings->sync_bookmarks_ = GetSyncBookmarksEnabled();
settings->sync_settings_ = GetSyncSiteSettingsEnabled();
@@ -83,8 +83,8 @@ class Prefs {
void SetSeed(const std::string& seed);
std::string GetThisDeviceId() const;
void SetThisDeviceId(const std::string& device_id);
std::string GetDeviceIdV2() const;
void SetDeviceIdV2(const std::string& device_id_v2);
std::string GetThisDeviceIdV2() const;
void SetThisDeviceIdV2(const std::string& device_id_v2);
std::string GetThisDeviceName() const;
void SetThisDeviceName(const std::string& device_name);
std::string GetBookmarksBaseOrder();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.