From 9ee5bcb147d65c85ddb8b45aef29e8acd3797ebc Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 14 Dec 2018 10:45:45 -0800 Subject: [PATCH] Use thisDeviceId to identify "This Device" --- browser/ui/webui/brave_webui_source.cc | 6 +++--- components/brave_sync/brave_sync_prefs.cc | 1 + components/brave_sync/brave_sync_service_unittest.cc | 1 + components/brave_sync/settings.h | 1 + components/brave_sync/ui/components/enabledContent.tsx | 3 +-- components/brave_sync/ui/reducers/sync_reducer.ts | 3 ++- components/brave_sync/ui/storage.ts | 1 + components/brave_sync/values_conv.cc | 1 + components/definitions/sync.d.ts | 2 ++ components/resources/brave_components_strings.grd | 6 +++--- 10 files changed, 16 insertions(+), 9 deletions(-) diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index f38f27d64806..1b05461f8304 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -444,7 +444,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, content::WebUIDataSource* { "braveSync", IDS_BRAVE_SYNC_ENABLED_BRAVE_TITLE }, { "syncChainDevices", IDS_BRAVE_SYNC_ENABLED_DEVICES_CHAIN_TITLE }, { "deviceName", IDS_BRAVE_SYNC_ENABLED_TABLE_DEVICE_NAME_TITLE }, - { "mainDevice", IDS_BRAVE_SYNC_ENABLED_TABLE_MAIN_DEVICE_TEXT }, + { "thisDevice", IDS_BRAVE_SYNC_ENABLED_TABLE_THIS_DEVICE_TEXT }, { "addedOn", IDS_BRAVE_SYNC_ENABLED_TABLE_ADDED_ON_TITLE }, { "addDevice", IDS_BRAVE_SYNC_ENABLED_ADD_DEVICE_BUTTON }, { "viewSyncCode", IDS_BRAVE_SYNC_ENABLED_VIEW_CODE_BUTTON }, @@ -464,8 +464,8 @@ void CustomizeWebUIHTMLSource(const std::string &name, content::WebUIDataSource* { "enterSyncCodeDescription", IDS_BRAVE_SYNC_ENTER_CODE_DESCRIPTION }, { "confirmCode", IDS_BRAVE_SYNC_ENTER_CODE_CONFIRM_CODE_BUTTON }, // [modal] Remove Main Device - { "thisDeviceRemovalDescription", IDS_BRAVE_SYNC_REMOVE_MAIN_DEVICE_DESCRIPTION }, - { "joinSyncChain", IDS_BRAVE_SYNC_REMOVE_MAIN_DEVICE_JOIN_CHAIN_INSTRUCTIONS }, + { "thisDeviceRemovalDescription", IDS_BRAVE_SYNC_REMOVE_THIS_DEVICE_DESCRIPTION }, + { "joinSyncChain", IDS_BRAVE_SYNC_REMOVE_THIS_DEVICE_JOIN_CHAIN_INSTRUCTIONS }, // [modal] Remove Other Device { "otherDeviceRemovalDescription", IDS_BRAVE_SYNC_REMOVE_OTHER_DEVICE_DESCRIPTION }, // [modal] Reset Sync diff --git a/components/brave_sync/brave_sync_prefs.cc b/components/brave_sync/brave_sync_prefs.cc index 8c4f4d490f1b..589a103a68b0 100644 --- a/components/brave_sync/brave_sync_prefs.cc +++ b/components/brave_sync/brave_sync_prefs.cc @@ -97,6 +97,7 @@ std::unique_ptr Prefs::GetBraveSyncSettings() const { auto settings = std::make_unique(); settings->this_device_name_ = GetThisDeviceName(); + settings->this_device_id_ = GetThisDeviceId(); settings->sync_this_device_ = GetSyncEnabled(); settings->sync_bookmarks_ = GetSyncBookmarksEnabled(); settings->sync_settings_ = GetSyncSiteSettingsEnabled(); diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 903edb645593..3a0f9a99fa6a 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -317,6 +317,7 @@ TEST_F(BraveSyncServiceTest, GetSettingsAndDevices) { [](std::unique_ptr settings, std::unique_ptr devices) { EXPECT_TRUE(settings->this_device_name_.empty()); + EXPECT_TRUE(settings->this_device_id_.empty()); EXPECT_FALSE(settings->sync_configured_); EXPECT_FALSE(settings->sync_this_device_); EXPECT_FALSE(settings->sync_bookmarks_); diff --git a/components/brave_sync/settings.h b/components/brave_sync/settings.h index 0566bb2c46d8..1b08903a4294 100644 --- a/components/brave_sync/settings.h +++ b/components/brave_sync/settings.h @@ -13,6 +13,7 @@ class Settings { public: Settings(); std::string this_device_name_; + std::string this_device_id_; bool sync_this_device_; bool sync_bookmarks_; bool sync_settings_; diff --git a/components/brave_sync/ui/components/enabledContent.tsx b/components/brave_sync/ui/components/enabledContent.tsx index 358b511cd090..b79af12f442d 100644 --- a/components/brave_sync/ui/components/enabledContent.tsx +++ b/components/brave_sync/ui/components/enabledContent.tsx @@ -81,7 +81,7 @@ export default class SyncEnabledContent extends React.PureComponent - {device.name} {Number(device.id) === 0 ? getLocale('mainDevice') : null } + {device.name} {device.id === this.props.syncData.thisDeviceId ? getLocale('thisDevice') : null } }, { content: device.lastActive }, @@ -90,7 +90,6 @@ export default class SyncEnabledContent extends React.PureComponent × diff --git a/components/brave_sync/ui/reducers/sync_reducer.ts b/components/brave_sync/ui/reducers/sync_reducer.ts index a3a74374a4d2..70418c33d947 100644 --- a/components/brave_sync/ui/reducers/sync_reducer.ts +++ b/components/brave_sync/ui/reducers/sync_reducer.ts @@ -39,6 +39,7 @@ const syncReducer: Reducer = (state: Sync.State | undefi devices: [ ...devices ], isSyncConfigured: payload.settings.sync_configured, thisDeviceName: payload.settings.this_device_name, + thisDeviceId: payload.settings.this_device_id, syncBookmarks: payload.settings.sync_bookmarks, syncSavedSiteSettings: payload.settings.sync_settings, syncBrowsingHistory: payload.settings.sync_history @@ -87,7 +88,7 @@ const syncReducer: Reducer = (state: Sync.State | undefi } // if the device removed is the this device, reset sync - if (payload.deviceName === state.thisDeviceName && payload.id === 0) { + if (payload.id === state.thisDeviceId) { state = { ...storage.defaultState } chrome.send('resetSync') break diff --git a/components/brave_sync/ui/storage.ts b/components/brave_sync/ui/storage.ts index ae482f72e968..b2ce25ff15f2 100644 --- a/components/brave_sync/ui/storage.ts +++ b/components/brave_sync/ui/storage.ts @@ -9,6 +9,7 @@ const keyName = 'sync-data_t' export const defaultState = { thisDeviceName: '', + thisDeviceId: '', devices: [], isSyncConfigured: false, seedQRImageSource: '', diff --git a/components/brave_sync/values_conv.cc b/components/brave_sync/values_conv.cc index ce07a2f2354d..3635e27fe8df 100644 --- a/components/brave_sync/values_conv.cc +++ b/components/brave_sync/values_conv.cc @@ -23,6 +23,7 @@ std::unique_ptr BraveSyncSettingsToValue(brave_sync::Settings *brave_sync auto result = std::make_unique(Value::Type::DICTIONARY); result->SetKey("this_device_name", Value(brave_sync_settings->this_device_name_)); + result->SetKey("this_device_id", Value(brave_sync_settings->this_device_id_)); result->SetKey("sync_this_device", Value(brave_sync_settings->sync_this_device_)); result->SetKey("sync_bookmarks", Value(brave_sync_settings->sync_bookmarks_)); result->SetKey("sync_settings", Value(brave_sync_settings->sync_settings_)); diff --git a/components/definitions/sync.d.ts b/components/definitions/sync.d.ts index 9afbeaf01a26..c60a137eb346 100644 --- a/components/definitions/sync.d.ts +++ b/components/definitions/sync.d.ts @@ -16,6 +16,7 @@ declare namespace Sync { device_id: number last_active: number } + export interface Devices { name: string id: number @@ -32,6 +33,7 @@ export type SetupErrorType = export interface State { thisDeviceName: string + thisDeviceId: string devices: Devices[] isSyncConfigured: boolean seedQRImageSource: string diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index 38ff2c5c963d..531a6e3fd7a0 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -449,7 +449,7 @@ Brave Sync Devices in your sync chain device name - (This Device) + (This Device) added on add device view sync code @@ -469,8 +469,8 @@ Go to Brave Settings > Sync > Display sync code Confirm Sync Code - Local device data will remain intact on all devices. Other devices in this sync chain will remain synced. - To join a sync chain again, choose “Enter a sync chain code”. + Local device data will remain intact on all devices. Other devices in this sync chain will remain synced. + To join a sync chain again, choose “Enter a sync chain code”. Note: Removing this device from this sync chain does not clear previously synced data from the device.