-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/browser/resources/settings/brave_sync_page/brave_sync_page.js b/browser/resources/settings/brave_sync_page/brave_sync_page.js
index 1d64d114374d..3c14c6327c6f 100644
--- a/browser/resources/settings/brave_sync_page/brave_sync_page.js
+++ b/browser/resources/settings/brave_sync_page/brave_sync_page.js
@@ -1,29 +1,96 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
- (function() {
- 'use strict';
+/**
+ * 'settings-brave-sync-page' is the settings page containing brave's
+ * custom sync.
+ */
+Polymer({
+ is: 'settings-brave-sync-page',
- /**
- * 'settings-brave-sync-page' is the settings page containing brave's
- * custom sync.
- */
- Polymer({
- is: 'settings-brave-sync-page',
+ behaviors: [
+ I18nBehavior,
+ WebUIListenerBehavior,
+ ],
- properties: {},
+ properties: {
+ /**
+ * The current sync status, supplied by SyncBrowserProxy.
+ * @type {?settings.SyncStatus}
+ */
+ syncStatus_: Object,
+ syncLabel_: {
+ type: String,
+ computed: 'computeSyncLabel_(syncStatus_.firstSetupInProgress)'
+ },
+ },
- /** @private {?settings.DefaultBraveSyncBrowserProxy} */
- browserProxy_: null,
+ /** @private {?settings.SyncBrowserProxy} */
+ browserProxy_: null,
+ /** @private */
+ braveBrowserProxy_: null,
- /** @override */
- created: function() {
- this.browserProxy_ = settings.DefaultBraveSyncBrowserProxyImpl.getInstance();
- },
+ /** @override */
+ created: function() {
+ this.browserProxy_ = settings.SyncBrowserProxyImpl.getInstance();
+ this.braveBrowserProxy_ = settings.BraveSyncBrowserProxy.getInstance();
+ },
- /** @override */
- ready: function() {
- },
- });
- })();
+ /** @private */
+ computeSyncLabel_() {
+ const isAlreadySetup = this.syncStatus_ !== undefined &&
+ !this.syncStatus_.firstSetupInProgress;
+ const key = isAlreadySetup ? 'braveSyncManageActionLabel' : 'braveSyncSetupActionLabel';
+ return I18nBehavior.i18n(key);
+ },
+
+ /** @override */
+ attached: function() {
+ const onSyncStatus = this.handleSyncStatus_.bind(this)
+ this.browserProxy_.getSyncStatus().then(onSyncStatus);
+ this.addWebUIListener('sync-status-changed',onSyncStatus);
+ this.addWebUIListener(
+ 'sync-prefs-changed', this.handleSyncPrefsChanged_.bind(this));
+ },
+
+ /** @private */
+ onSyncTap_: function() {
+ // Users can go to sync subpage regardless of sync status.
+ const router = settings.Router.getInstance();
+ router.navigateTo(router.getRoutes().BRAVE_SYNC_SETUP);
+ },
+
+ /**
+ * Handler for when the sync state is pushed from the browser.
+ * @param {?settings.SyncStatus} syncStatus
+ * @private
+ */
+ handleSyncStatus_: function(syncStatus) {
+ console.debug('Sync Status Update', syncStatus)
+ this.syncStatus_ = syncStatus;
+ },
+
+ /**
+ * Handler for when the sync preferences are updated.
+ * @private
+ */
+ handleSyncPrefsChanged_: async function(syncPrefs) {
+ // Enforce encryption
+ if (this.syncStatus_ && !this.syncStatus_.firstSetupInProgress) {
+ if (!syncPrefs.encryptAllData) {
+ const syncCode = await this.braveBrowserProxy_.getSyncCode()
+ syncPrefs.encryptAllData = true;
+ syncPrefs.setNewPassphrase = true;
+ syncPrefs.passphrase = syncCode;
+ await this.browserProxy_.setSyncEncryption(syncPrefs)
+ } else if (syncPrefs.passphraseRequired) {
+ const syncCode = await this.braveBrowserProxy_.getSyncCode()
+ syncPrefs.setNewPassphrase = false;
+ syncPrefs.passphrase = syncCode;
+ await this.browserProxy_.setSyncEncryption(syncPrefs)
+ }
+ }
+ },
+});
diff --git a/browser/resources/settings/brave_sync_page/brave_sync_setup.html b/browser/resources/settings/brave_sync_page/brave_sync_setup.html
new file mode 100644
index 000000000000..d663567d23ea
--- /dev/null
+++ b/browser/resources/settings/brave_sync_page/brave_sync_setup.html
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
$i18n{braveSyncSetupTitle}
+
$i18n{braveSyncSetupSubtitle}
+
+
+
+
+ $i18n{braveSyncStartNewChain}
+
+
+ $i18n{braveSyncEnterCode}
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/browser/resources/settings/brave_sync_page/brave_sync_setup.js b/browser/resources/settings/brave_sync_page/brave_sync_setup.js
new file mode 100644
index 000000000000..71d1495508fd
--- /dev/null
+++ b/browser/resources/settings/brave_sync_page/brave_sync_setup.js
@@ -0,0 +1,81 @@
+// Copyright (c) 2020 The Brave Authors. All rights reserved.
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// you can obtain one at http://mozilla.org/MPL/2.0/.
+
+/**
+ * @fileoverview
+ * 'brave-sync-setup' is the UI for starting or joining a sync chain
+ * settings.
+ */
+Polymer({
+ is: 'settings-brave-sync-setup',
+
+ properties: {
+ syncCode: {
+ type: String,
+ notify: true
+ },
+ /**
+ * Sync code dialog type. Can only have 1 at a time, so use a single property.
+ * 'qr' | 'words' | 'input' | 'choose' | null
+ * @private
+ */
+ syncCodeDialogType_: String,
+ isSubmittingSyncCode_: {
+ type: Boolean,
+ value: false,
+ },
+ isGettingSyncCode_: {
+ type: Boolean,
+ value: false,
+ },
+ isInvalidSyncCode_: {
+ type: Boolean,
+ value: false,
+ }
+ },
+
+ /** @private {?settings.BraveSyncBrowserProxy} */
+ syncBrowserProxy_: null,
+
+ created: function() {
+ this.syncBrowserProxy_ = settings.BraveSyncBrowserProxy.getInstance();
+ },
+
+ handleStartSyncChain_: async function () {
+ this.isGettingSyncCode_ = true
+ const syncCode = await this.syncBrowserProxy_.getSyncCode()
+ this.isGettingSyncCode_ = false
+ this.syncCode = syncCode;
+ this.syncCodeDialogType_ = 'choose'
+ },
+
+ handleJoinSyncChain_: function () {
+ this.syncCode = undefined
+ this.syncCodeDialogType_ = 'input'
+ },
+
+ handleSyncCodeDialogDone_: function (e) {
+ this.submitSyncCode_()
+ },
+
+ submitSyncCode_: async function () {
+ this.isSubmittingSyncCode_ = true
+ const syncCodeToSubmit = this.syncCode || ''
+ let success = false
+ try {
+ success = await this.syncBrowserProxy_.setSyncCode(syncCodeToSubmit)
+ } catch (e) {
+ console.error("Error setting sync code")
+ success = false
+ }
+ this.isSubmittingSyncCode_ = false
+ if (!success) {
+ this.isInvalidSyncCode_ = true
+ } else {
+ this.syncCodeDialogType_ = undefined
+ this.fire('setup-success')
+ }
+ },
+});
diff --git a/browser/resources/settings/brave_sync_page/brave_sync_subpage.html b/browser/resources/settings/brave_sync_page/brave_sync_subpage.html
new file mode 100644
index 000000000000..dde7424d1f35
--- /dev/null
+++ b/browser/resources/settings/brave_sync_page/brave_sync_subpage.html
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $i18n{syncDisabledByAdministrator}
+
+
+
+
+
+
+
+
+
+
+ $i18n{syncLoading}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/browser/resources/settings/brave_sync_page/brave_sync_subpage.js b/browser/resources/settings/brave_sync_page/brave_sync_subpage.js
new file mode 100644
index 000000000000..8bae0e7ff08d
--- /dev/null
+++ b/browser/resources/settings/brave_sync_page/brave_sync_subpage.js
@@ -0,0 +1,245 @@
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+(function() {
+
+/**
+ * @fileoverview
+ * 'settings-sync-page' is the settings page containing sync settings.
+ */
+Polymer({
+ is: 'settings-brave-sync-subpage',
+
+ behaviors: [
+ settings.RouteObserverBehavior,
+ ],
+
+ properties: {
+ /** @private */
+ pages_: {
+ type: Object,
+ value: settings.PageStatus,
+ readOnly: true,
+ },
+
+ /**
+ * Current page status
+ * 'configure' | 'setup' | 'spinner'
+ * @private
+ */
+ pageStatus_: {
+ type: String,
+ value: 'configure',
+ },
+
+ /**
+ * The current sync preferences, supplied by SyncBrowserProxy.
+ * @type {settings.SyncPrefs|undefined}
+ */
+ syncPrefs: {
+ type: Object,
+ },
+
+ /** @type {settings.SyncStatus} */
+ syncStatus: {
+ type: Object,
+ },
+
+ /** @private */
+ syncDisabledByAdmin_: {
+ type: Boolean,
+ value: false,
+ computed: 'computeSyncDisabledByAdmin_(syncStatus.managed)',
+ },
+
+ /** @private */
+ syncSectionDisabled_: {
+ type: Boolean,
+ value: false,
+ computed: 'computeSyncSectionDisabled_(' +
+ 'syncStatus.disabled, ' +
+ 'syncStatus.hasError, syncStatus.statusAction, ' +
+ 'syncPrefs.trustedVaultKeysRequired)',
+ },
+ },
+
+ observers: [
+ 'updatePageStatus_(syncStatus.*)'
+ ],
+
+ /** @private {?settings.SyncBrowserProxy} */
+ browserProxy_: null,
+
+ /**
+ * The beforeunload callback is used to show the 'Leave site' dialog. This
+ * makes sure that the user has the chance to go back and confirm the sync
+ * opt-in before leaving.
+ *
+ * This property is non-null if the user is currently navigated on the sync
+ * settings route.
+ *
+ * @private {?Function}
+ */
+ beforeunloadCallback_: null,
+
+ /**
+ * The unload callback is used to cancel the sync setup when the user hits
+ * the browser back button after arriving on the page.
+ * Note: Cases like closing the tab or reloading don't need to be handled,
+ * because they are already caught in |PeopleHandler::~PeopleHandler|
+ * from the C++ code.
+ *
+ * @private {?Function}
+ */
+ unloadCallback_: null,
+
+ /**
+ * Whether the user completed setup successfully.
+ * @private {boolean}
+ */
+ setupSuccessful_: false,
+
+ /** @override */
+ created: function() {
+ this.browserProxy_ = settings.SyncBrowserProxyImpl.getInstance();
+ },
+
+ /** @override */
+ attached: function() {
+ const router = settings.Router.getInstance();
+ if (router.getCurrentRoute() == router.getRoutes().BRAVE_SYNC_SETUP) {
+ this.onNavigateToPage_();
+ }
+ },
+
+ /** @override */
+ detached: function() {
+ const router = settings.Router.getInstance();
+ if (router.getRoutes().BRAVE_SYNC_SETUP.contains(router.getCurrentRoute())) {
+ this.onNavigateAwayFromPage_();
+ }
+
+ if (this.beforeunloadCallback_) {
+ window.removeEventListener('beforeunload', this.beforeunloadCallback_);
+ this.beforeunloadCallback_ = null;
+ }
+ if (this.unloadCallback_) {
+ window.removeEventListener('unload', this.unloadCallback_);
+ this.unloadCallback_ = null;
+ }
+ },
+
+ updatePageStatus_: function () {
+ const isFirstSetup = this.syncStatus && this.syncStatus.firstSetupInProgress
+ this.pageStatus_ = isFirstSetup ? 'setup' : 'configure'
+ },
+
+ /**
+ * @return {boolean}
+ * @private
+ */
+ computeSyncSectionDisabled_: function() {
+ return this.syncStatus !== undefined &&
+ (!!this.syncStatus.disabled ||
+ (!!this.syncStatus.hasError &&
+ this.syncStatus.statusAction !==
+ settings.StatusAction.ENTER_PASSPHRASE &&
+ this.syncStatus.statusAction !==
+ settings.StatusAction.RETRIEVE_TRUSTED_VAULT_KEYS));
+ },
+
+ /**
+ * @return {boolean}
+ * @private
+ */
+ computeSyncDisabledByAdmin_() {
+ return this.syncStatus != undefined && !!this.syncStatus.managed;
+ },
+
+ /** @protected */
+ currentRouteChanged: function() {
+ const router = settings.Router.getInstance();
+ if (router.getCurrentRoute() == router.getRoutes().BRAVE_SYNC_SETUP) {
+ this.onNavigateToPage_();
+ return;
+ }
+
+ if (router.getRoutes().BRAVE_SYNC_SETUP.contains(router.getCurrentRoute())) {
+ return;
+ }
+
+ this.onNavigateAwayFromPage_();
+ },
+
+ /**
+ * @param {!settings.PageStatus} expectedPageStatus
+ * @return {boolean}
+ * @private
+ */
+ isStatus_: function(expectedPageStatus) {
+ return expectedPageStatus == this.pageStatus_;
+ },
+
+ /** @private */
+ onNavigateToPage_: function() {
+ const router = settings.Router.getInstance();
+ assert(router.getCurrentRoute() == router.getRoutes().BRAVE_SYNC_SETUP);
+ if (this.beforeunloadCallback_) {
+ return;
+ }
+
+ // Triggers push of prefs to our handler
+ this.browserProxy_.didNavigateToSyncPage();
+
+ this.beforeunloadCallback_ = event => {
+ // When the user tries to leave the sync setup, show the 'Leave site'
+ // dialog.
+ if (this.syncStatus && this.syncStatus.firstSetupInProgress) {
+ event.preventDefault();
+ event.returnValue = '';
+
+ chrome.metricsPrivate.recordUserAction(
+ 'Signin_Signin_AbortAdvancedSyncSettings');
+ }
+ };
+ window.addEventListener('beforeunload', this.beforeunloadCallback_);
+
+ this.unloadCallback_ = this.onNavigateAwayFromPage_.bind(this);
+ window.addEventListener('unload', this.unloadCallback_);
+ },
+
+ /** @private */
+ onNavigateAwayFromPage_: function() {
+ if (!this.beforeunloadCallback_) {
+ return;
+ }
+
+ this.browserProxy_.didNavigateAwayFromSyncPage(!this.setupSuccessful_);
+
+ window.removeEventListener('beforeunload', this.beforeunloadCallback_);
+ this.beforeunloadCallback_ = null;
+
+ if (this.unloadCallback_) {
+ window.removeEventListener('unload', this.unloadCallback_);
+ this.unloadCallback_ = null;
+ }
+ },
+
+ /**
+ * Called when setup is complete and sync code is set
+ * @private
+ */
+ onSetupSuccess_: function() {
+ this.setupSuccessful_ = true
+ // This navigation causes the firstSetupInProgress flag to be marked as false
+ // via `didNavigateAwayFromSyncPage`.
+ const router = settings.Router.getInstance();
+ if (router.getCurrentRoute() == router.getRoutes().BRAVE_SYNC_SETUP) {
+ router.navigateTo(router.getRoutes().BRAVE_SYNC);
+ }
+ },
+});
+
+})();
diff --git a/components/brave_sync/ui/components/images/sync_computer.svg b/browser/resources/settings/brave_sync_page/device_computer.svg
similarity index 100%
rename from components/brave_sync/ui/components/images/sync_computer.svg
rename to browser/resources/settings/brave_sync_page/device_computer.svg
diff --git a/components/brave_sync/ui/components/images/sync_devices.svg b/browser/resources/settings/brave_sync_page/device_mobile.svg
similarity index 100%
rename from components/brave_sync/ui/components/images/sync_devices.svg
rename to browser/resources/settings/brave_sync_page/device_mobile.svg
diff --git a/components/brave_sync/ui/components/images/start_icon.svg b/browser/resources/settings/brave_sync_page/start_icon.svg
similarity index 100%
rename from components/brave_sync/ui/components/images/start_icon.svg
rename to browser/resources/settings/brave_sync_page/start_icon.svg
diff --git a/browser/resources/settings/settings_resources.grd b/browser/resources/settings/settings_resources.grd
index 14cf2862c82c..9aea96177f9c 100644
--- a/browser/resources/settings/settings_resources.grd
+++ b/browser/resources/settings/settings_resources.grd
@@ -43,10 +43,21 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn
index 45cbeb701afb..da09c004b7a5 100644
--- a/browser/ui/BUILD.gn
+++ b/browser/ui/BUILD.gn
@@ -1,7 +1,6 @@
import("//brave/browser/translate/buildflags/buildflags.gni")
import("//brave/build/config.gni")
import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
-import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/speedreader/buildflags.gni")
@@ -43,13 +42,6 @@ source_set("ui") {
"webui/brave_webui_source.h",
]
- if (enable_brave_sync) {
- sources += [
- "webui/sync/sync_ui.cc",
- "webui/sync/sync_ui.h",
- ]
- }
-
if (!is_android) {
sources += [
"bookmark/brave_bookmark_tab_helper.cc",
@@ -94,6 +86,8 @@ source_set("ui") {
"webui/settings/brave_import_data_handler.h",
"webui/settings/brave_privacy_handler.cc",
"webui/settings/brave_privacy_handler.h",
+ "webui/settings/brave_sync_handler.cc",
+ "webui/settings/brave_sync_handler.h",
"webui/settings/default_brave_shields_handler.cc",
"webui/settings/default_brave_shields_handler.h",
]
@@ -204,7 +198,6 @@ source_set("ui") {
"//brave/components/brave_rewards/browser",
"//brave/components/brave_rewards/resources",
"//brave/components/brave_shields/browser",
- "//brave/components/brave_sync/buildflags:buildflags",
"//brave/components/brave_wallet/browser/buildflags:buildflags",
"//brave/components/brave_wayback_machine:buildflags",
"//brave/components/brave_welcome_ui:generated_resources",
@@ -239,15 +232,6 @@ source_set("ui") {
]
}
- if (enable_brave_sync) {
- deps += [
- "//brave/components/brave_sync",
- "//brave/components/brave_sync:generated_resources",
- "//brave/components/brave_sync:static_resources",
- "//components/sync/driver:driver",
- ]
- }
-
if (enable_brave_wayback_machine) {
deps += [ "//brave/components/brave_wayback_machine" ]
@@ -260,6 +244,8 @@ source_set("ui") {
deps += [
"//brave/app:brave_generated_resources_grit",
"//brave/browser:version_info",
+ "//brave/components/brave_sync",
+ "//components/sync_device_info",
"//third_party/blink/public/common",
]
}
diff --git a/browser/ui/brave_browser_command_controller.cc b/browser/ui/brave_browser_command_controller.cc
index 41f089e87baf..6b9ff1c8ae1e 100644
--- a/browser/ui/brave_browser_command_controller.cc
+++ b/browser/ui/brave_browser_command_controller.cc
@@ -14,7 +14,6 @@
#include "brave/browser/ui/browser_commands.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
-#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profile.h"
@@ -23,10 +22,6 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/prefs/pref_service.h"
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-#include "components/sync/driver/sync_driver_switches.h"
-#endif
-
namespace {
bool IsBraveCommands(int id) {
@@ -102,7 +97,7 @@ bool BraveBrowserCommandController::UpdateCommandEnabled(int id, bool state) {
}
void BraveBrowserCommandController::InitBraveCommandState() {
- // Sync & Rewards pages doesn't work on tor(guest) session.
+ // Rewards pages doesn't work on tor(guest) session.
// They also doesn't work on private window but they are redirected
// to normal window in this case.
const bool is_guest_session = browser_->profile()->IsGuestSession();
@@ -112,10 +107,6 @@ void BraveBrowserCommandController::InitBraveCommandState() {
#endif
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
UpdateCommandForBraveWallet();
-#endif
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- if (switches::IsSyncAllowedByFlag())
- UpdateCommandForBraveSync();
#endif
}
UpdateCommandForBraveAdblock();
@@ -150,10 +141,6 @@ void BraveBrowserCommandController::UpdateCommandForTor() {
}
#endif
-void BraveBrowserCommandController::UpdateCommandForBraveSync() {
- UpdateCommandEnabled(IDC_SHOW_BRAVE_SYNC, true);
-}
-
void BraveBrowserCommandController::UpdateCommandForBraveWallet() {
UpdateCommandEnabled(IDC_SHOW_BRAVE_WALLET, true);
}
@@ -200,9 +187,6 @@ bool BraveBrowserCommandController::ExecuteBraveCommandWithDisposition(
case IDC_NEW_TOR_CONNECTION_FOR_SITE:
brave::NewTorConnectionForSite(browser_);
break;
- case IDC_SHOW_BRAVE_SYNC:
- brave::ShowBraveSync(browser_);
- break;
case IDC_SHOW_BRAVE_WALLET:
brave::ShowBraveWallet(browser_);
break;
diff --git a/browser/ui/brave_browser_command_controller_browsertest.cc b/browser/ui/brave_browser_command_controller_browsertest.cc
index aaeeaf2766f3..8ce47efcea59 100644
--- a/browser/ui/brave_browser_command_controller_browsertest.cc
+++ b/browser/ui/brave_browser_command_controller_browsertest.cc
@@ -10,7 +10,6 @@
#include "brave/browser/ui/brave_browser_command_controller.h"
#include "brave/browser/ui/browser_commands.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
-#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -19,7 +18,6 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/in_process_browser_test.h"
-#include "components/sync/driver/sync_driver_switches.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
@@ -53,15 +51,6 @@ IN_PROC_BROWSER_TEST_F(BraveBrowserCommandControllerTest,
command_controller->IsCommandEnabled(IDC_NEW_OFFTHERECORD_WINDOW_TOR));
#endif
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- if (switches::IsSyncAllowedByFlag())
- EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
- else
- EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
-#else
- EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
-#endif
-
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_WALLET));
#else
@@ -89,13 +78,6 @@ IN_PROC_BROWSER_TEST_F(BraveBrowserCommandControllerTest,
command_controller->IsCommandEnabled(IDC_NEW_OFFTHERECORD_WINDOW_TOR));
#endif
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- if (switches::IsSyncAllowedByFlag())
- EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
- else
- EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
-#endif
-
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_WALLET));
#endif
@@ -136,10 +118,6 @@ IN_PROC_BROWSER_TEST_F(BraveBrowserCommandControllerTest,
command_controller->IsCommandEnabled(IDC_NEW_OFFTHERECORD_WINDOW_TOR));
#endif
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
-#endif
-
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_WALLET));
#endif
@@ -177,13 +155,6 @@ IN_PROC_BROWSER_TEST_F(BraveBrowserCommandControllerTest,
command_controller->IsCommandEnabled(IDC_NEW_OFFTHERECORD_WINDOW_TOR));
#endif
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- if (switches::IsSyncAllowedByFlag())
- EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
- else
- EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
-#endif
-
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_WALLET));
#endif
diff --git a/browser/ui/brave_pages.cc b/browser/ui/brave_pages.cc
index 4c0ad3777d58..648b40b3ecf0 100644
--- a/browser/ui/brave_pages.cc
+++ b/browser/ui/brave_pages.cc
@@ -8,7 +8,9 @@
#include "brave/browser/webcompat_reporter/webcompat_reporter_dialog.h"
#include "brave/common/webui_url_constants.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/singleton_tabs.h"
+#include "chrome/common/webui_url_constants.h"
#include "url/gurl.h"
namespace brave {
@@ -25,6 +27,13 @@ void ShowBraveAdblock(Browser* browser) {
GetSingletonTabNavigateParams(browser, GURL(kBraveUIAdblockURL)));
}
+void ShowSync(Browser* browser) {
+ auto url = chrome::GetSettingsUrl(chrome::kSyncSetupSubPage);
+ ShowSingletonTabOverwritingNTP(
+ browser,
+ GetSingletonTabNavigateParams(browser, url));
+}
+
void ShowWebcompatReporter(Browser* browser) {
content::WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
@@ -34,12 +43,6 @@ void ShowWebcompatReporter(Browser* browser) {
OpenWebcompatReporterDialog(web_contents);
}
-void ShowBraveSync(Browser* browser) {
- ShowSingletonTabOverwritingNTP(
- browser,
- GetSingletonTabNavigateParams(browser, GURL(kBraveUISyncURL)));
-}
-
void ShowBraveWallet(Browser* browser) {
ShowSingletonTabOverwritingNTP(
browser,
diff --git a/browser/ui/brave_pages.h b/browser/ui/brave_pages.h
index 4a5f499bb186..854fb187bbd2 100644
--- a/browser/ui/brave_pages.h
+++ b/browser/ui/brave_pages.h
@@ -13,9 +13,9 @@ namespace brave {
void ShowBraveAdblock(Browser* browser);
void ShowWebcompatReporter(Browser* browser);
void ShowBraveRewards(Browser* browser);
-void ShowBraveSync(Browser* browser);
void ShowBraveWallet(Browser* browser);
void ShowExtensionSettings(Browser* browser);
+void ShowSync(Browser* browser);
} // namespace brave
diff --git a/browser/ui/toolbar/brave_app_menu_model.cc b/browser/ui/toolbar/brave_app_menu_model.cc
index b8376bed7c15..3963bf234687 100644
--- a/browser/ui/toolbar/brave_app_menu_model.cc
+++ b/browser/ui/toolbar/brave_app_menu_model.cc
@@ -76,13 +76,6 @@ void BraveAppMenuModel::InsertBraveMenuItems() {
IDS_SHOW_BRAVE_WALLET);
}
- // Insert sync menu
- if (IsCommandIdEnabled(IDC_SHOW_BRAVE_SYNC)) {
- InsertItemWithStringIdAt(GetIndexOfBraveSyncItem(),
- IDC_SHOW_BRAVE_SYNC,
- IDS_SHOW_BRAVE_SYNC);
- }
-
// Insert adblock menu at last. Assumed this is always enabled.
DCHECK(IsCommandIdEnabled(IDC_SHOW_BRAVE_ADBLOCK));
InsertItemWithStringIdAt(GetIndexOfBraveAdBlockItem(),
@@ -110,10 +103,6 @@ void BraveAppMenuModel::InsertBraveMenuItems() {
int BraveAppMenuModel::GetIndexOfBraveAdBlockItem() const {
// Insert as a last item in second section.
int adblock_item_index = -1;
- adblock_item_index = GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC);
- if (adblock_item_index != -1)
- return adblock_item_index + 1;
-
adblock_item_index = GetIndexOfCommandId(IDC_MANAGE_EXTENSIONS);
if (adblock_item_index != -1)
return adblock_item_index + 1;
@@ -143,20 +132,3 @@ int BraveAppMenuModel::GetIndexOfBraveRewardsItem() const {
DCHECK_NE(-1, rewards_index) << "No download item";
return rewards_index;
}
-
-int BraveAppMenuModel::GetIndexOfBraveSyncItem() const {
- // Insert sync menu under extensions menu. If extensions menu is not
- // available, check above items.
- int sync_index = -1;
- sync_index = GetIndexOfCommandId(IDC_MANAGE_EXTENSIONS);
- if (sync_index != -1)
- return sync_index + 1;
-
- sync_index = GetIndexOfCommandId(IDC_SHOW_BRAVE_WALLET);
- if (sync_index != -1)
- return sync_index + 1;
-
- sync_index = GetIndexOfCommandId(IDC_SHOW_DOWNLOADS);
- DCHECK_NE(-1, sync_index) << "No download item";
- return sync_index + 1;
-}
diff --git a/browser/ui/toolbar/brave_app_menu_model_browsertest.cc b/browser/ui/toolbar/brave_app_menu_model_browsertest.cc
index 2eb93b8e80bf..749dbcb18f56 100644
--- a/browser/ui/toolbar/brave_app_menu_model_browsertest.cc
+++ b/browser/ui/toolbar/brave_app_menu_model_browsertest.cc
@@ -13,7 +13,6 @@
#include "brave/browser/ui/brave_browser_command_controller.h"
#include "brave/browser/ui/browser_commands.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
-#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -23,7 +22,6 @@
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/test/base/in_process_browser_test.h"
-#include "components/sync/driver/sync_driver_switches.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
@@ -78,9 +76,6 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) {
IDC_SHOW_BRAVE_WALLET,
#endif
IDC_MANAGE_EXTENSIONS,
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- IDC_SHOW_BRAVE_SYNC,
-#endif
IDC_SHOW_BRAVE_ADBLOCK,
IDC_ADD_NEW_PROFILE,
IDC_OPEN_GUEST_PROFILE,
@@ -89,16 +84,6 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) {
std::vector
commands_disabled_for_normal_profile = {
IDC_NEW_TOR_CONNECTION_FOR_SITE,
};
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- if (!switches::IsSyncAllowedByFlag()) {
- commands_in_order_for_normal_profile.erase(
- std::remove(commands_in_order_for_normal_profile.begin(),
- commands_in_order_for_normal_profile.end(),
- IDC_SHOW_BRAVE_SYNC),
- commands_in_order_for_normal_profile.end());
- commands_disabled_for_normal_profile.push_back(IDC_SHOW_BRAVE_SYNC);
- }
-#endif
CheckCommandsAreInOrderInMenuModel(browser(),
commands_in_order_for_normal_profile);
CheckCommandsAreDisabledInMenuModel(browser(),
@@ -121,9 +106,6 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) {
IDC_SHOW_BRAVE_WALLET,
#endif
IDC_MANAGE_EXTENSIONS,
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- IDC_SHOW_BRAVE_SYNC,
-#endif
IDC_SHOW_BRAVE_ADBLOCK,
IDC_ADD_NEW_PROFILE,
IDC_OPEN_GUEST_PROFILE,
@@ -133,16 +115,6 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) {
IDC_NEW_TOR_CONNECTION_FOR_SITE,
IDC_RECENT_TABS_MENU,
};
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- if (!switches::IsSyncAllowedByFlag()) {
- commands_in_order_for_private_profile.erase(
- std::remove(commands_in_order_for_private_profile.begin(),
- commands_in_order_for_private_profile.end(),
- IDC_SHOW_BRAVE_SYNC),
- commands_in_order_for_private_profile.end());
- commands_disabled_for_private_profile.push_back(IDC_SHOW_BRAVE_SYNC);
- }
-#endif
CheckCommandsAreInOrderInMenuModel(private_browser,
commands_in_order_for_private_profile);
CheckCommandsAreDisabledInMenuModel(private_browser,
@@ -187,9 +159,6 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) {
IDC_SHOW_BRAVE_WALLET,
#endif
IDC_MANAGE_EXTENSIONS,
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- IDC_SHOW_BRAVE_SYNC,
-#endif
IDC_ADD_NEW_PROFILE,
IDC_OPEN_GUEST_PROFILE,
};
@@ -224,9 +193,6 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) {
IDC_SHOW_DOWNLOADS,
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
IDC_SHOW_BRAVE_WALLET,
-#endif
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- IDC_SHOW_BRAVE_SYNC,
#endif
IDC_SHOW_BRAVE_ADBLOCK,
IDC_ADD_NEW_PROFILE,
@@ -236,16 +202,6 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) {
std::vector commands_disabled_for_tor_profile = {
IDC_RECENT_TABS_MENU,
};
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- if (!switches::IsSyncAllowedByFlag()) {
- commands_in_order_for_tor_profile.erase(
- std::remove(commands_in_order_for_tor_profile.begin(),
- commands_in_order_for_tor_profile.end(),
- IDC_SHOW_BRAVE_SYNC),
- commands_in_order_for_tor_profile.end());
- commands_disabled_for_tor_profile.push_back(IDC_SHOW_BRAVE_SYNC);
- }
-#endif
CheckCommandsAreInOrderInMenuModel(tor_browser,
commands_in_order_for_tor_profile);
CheckCommandsAreDisabledInMenuModel(tor_browser,
diff --git a/browser/ui/webui/brave_settings_ui.cc b/browser/ui/webui/brave_settings_ui.cc
index 3aebf56f51e9..56935a2ab85e 100644
--- a/browser/ui/webui/brave_settings_ui.cc
+++ b/browser/ui/webui/brave_settings_ui.cc
@@ -17,6 +17,7 @@
#include "brave/browser/ui/webui/settings/brave_appearance_handler.h"
#include "brave/browser/ui/webui/settings/brave_default_extensions_handler.h"
#include "brave/browser/ui/webui/settings/brave_privacy_handler.h"
+#include "brave/browser/ui/webui/settings/brave_sync_handler.h"
#include "brave/browser/ui/webui/settings/default_brave_shields_handler.h"
#include "brave/browser/version_info.h"
#include "brave/components/brave_sync/buildflags/buildflags.h"
@@ -44,6 +45,7 @@ BraveSettingsUI::BraveSettingsUI(content::WebUI* web_ui,
web_ui->AddMessageHandler(std::make_unique());
web_ui->AddMessageHandler(std::make_unique());
web_ui->AddMessageHandler(std::make_unique());
+ web_ui->AddMessageHandler(std::make_unique());
#if BUILDFLAG(ENABLE_SPARKLE)
// Use sparkle's relaunch api for browser relaunch on update.
web_ui->AddMessageHandler(std::make_unique());
diff --git a/browser/ui/webui/brave_web_ui_controller_factory.cc b/browser/ui/webui/brave_web_ui_controller_factory.cc
index 2c3eaff8b52b..1f0adf5dfd4d 100644
--- a/browser/ui/webui/brave_web_ui_controller_factory.cc
+++ b/browser/ui/webui/brave_web_ui_controller_factory.cc
@@ -16,7 +16,6 @@
#include "brave/common/pref_names.h"
#include "brave/common/webui_url_constants.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
-#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
@@ -38,11 +37,6 @@
#include "brave/browser/ui/webui/brave_wallet_ui.h"
#endif
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-#include "brave/browser/ui/webui/sync/sync_ui.h"
-#include "components/sync/driver/sync_driver_switches.h"
-#endif
-
using content::WebUI;
using content::WebUIController;
@@ -70,11 +64,6 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) {
} else if (host == kWalletHost) {
return new BraveWalletUI(web_ui, url.host());
#endif // BUILDFLAG(BRAVE_WALLET_ENABLED)
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- } else if (host == kBraveUISyncHost &&
- switches::IsSyncAllowedByFlag()) {
- return new SyncUI(web_ui, url.host());
-#endif // BUILDFLAG(ENABLE_BRAVE_SYNC)
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
} else if (host == kRewardsPageHost) {
return new BraveRewardsPageUI(web_ui, url.host());
@@ -114,10 +103,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
#endif
url.host_piece() == kWelcomeHost ||
url.host_piece() == chrome::kChromeUIWelcomeURL ||
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- (url.host_piece() == kBraveUISyncHost &&
- switches::IsSyncAllowedByFlag()) ||
-#endif
url.host_piece() == chrome::kChromeUINewTabHost ||
url.host_piece() == chrome::kChromeUISettingsHost) {
return &NewWebUI;
diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc
index 51899d6277e3..aff5d8cb5f2b 100644
--- a/browser/ui/webui/brave_webui_source.cc
+++ b/browser/ui/webui/brave_webui_source.cc
@@ -697,81 +697,6 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "tapNetworkLink", IDS_BRAVE_UI_TAP_NETWORK_LINK },
{ "tapNetworkDisclaimer", IDS_BRAVE_UI_TAP_NETWORK_DISCLAIMER },
}
- }, {
- std::string("sync"), {
- // Shared strings
- { "remove", IDS_BRAVE_SYNC_SHARED_REMOVE_PARTIAL },
- { "copied", IDS_BRAVE_SYNC_SHARED_COPIED_TEXT },
- { "wordCount", IDS_BRAVE_SYNC_SHARED_WORD_COUNT_TEXT },
- { "ok", IDS_BRAVE_SYNC_SHARED_OK_BUTTON },
- { "cancel", IDS_BRAVE_SYNC_SHARED_CANCEL_BUTTON },
- { "cancelDeviceSyncing", IDS_BRAVE_SYNC_SHARED_CANCEL_SYNCING_TITLE },
- { "cancelDeviceSyncingButton", IDS_BRAVE_SYNC_SHARED_CANCEL_SYNCING_BUTTON }, // NOLINT
- { "thisSyncChain", IDS_BRAVE_SYNC_SHARED_FROM_THIS_CHAIN_PARTIAL },
- { "lookingForDevice", IDS_BRAVE_SYNC_SCAN_CODE_LOOKING_FOR_DEVICE_BUTTON }, // NOLINT
- { "viewSyncCode", IDS_BRAVE_SYNC_ENABLED_VIEW_CODE_BUTTON },
- // Enabled Content
- { "braveSync", IDS_BRAVE_SYNC_ENABLED_BRAVE_TITLE },
- { "syncChainDevices", IDS_BRAVE_SYNC_ENABLED_DEVICES_CHAIN_TITLE },
- { "deviceName", IDS_BRAVE_SYNC_ENABLED_TABLE_DEVICE_NAME_TITLE },
- { "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 },
- { "settingsTitle", IDS_BRAVE_SYNC_ENABLED_SETTINGS_TITLE },
- { "settingsDescription", IDS_BRAVE_SYNC_ENABLED_SETTINGS_DESCRIPTION },
- { "settings", IDS_BRAVE_SYNC_ENABLED_TABLE_SETTINGS },
- { "bookmarks", IDS_BRAVE_SYNC_ENABLED_BOOKMARKS_LABEL },
- { "savedSiteSettings", IDS_BRAVE_SYNC_ENABLED_SITE_SETTINGS_LABEL },
- { "browsingHistory", IDS_BRAVE_SYNC_ENABLED_HISTORY_LABEL },
- { "leaveSyncChain", IDS_BRAVE_SYNC_ENABLED_LEAVE_CHAIN_BUTTON },
- // Disabled Content
- { "syncTitle", IDS_BRAVE_SYNC_DISABLED_DESCRIPTION },
- { "syncDescription", IDS_BRAVE_SYNC_DISABLED_NEW_CHAIN_DESCRIPTION },
- { "startSyncChain", IDS_BRAVE_SYNC_DISABLED_START_NEW_CHAIN_BUTTON },
- { "enterSyncChainCode", IDS_BRAVE_SYNC_DISABLED_ENTER_CODE_BUTTON },
- // [modal] Enter Sync Code
- { "enterSyncCode", IDS_BRAVE_SYNC_ENTER_CODE_TITLE },
- { "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_THIS_DEVICE_DESCRIPTION }, // NOLINT
- { "joinSyncChain", IDS_BRAVE_SYNC_REMOVE_THIS_DEVICE_JOIN_CHAIN_INSTRUCTIONS }, // NOLINT
- // [modal] Remove Other Device
- { "otherDeviceRemovalDescription", IDS_BRAVE_SYNC_REMOVE_OTHER_DEVICE_DESCRIPTION }, // NOLINT
- // [modal] Reset Sync
- { "warning", IDS_BRAVE_SYNC_RESET_WARNING_TITLE },
- { "removing", IDS_BRAVE_SYNC_RESET_REMOVING_PARTIAL },
- { "deleteSyncChain", IDS_BRAVE_SYNC_RESET_DELETE_CHAIN_PARTIAL },
- { "deleteSyncDescription", IDS_BRAVE_SYNC_RESET_REMOVAL_INSTRUCTIONS },
- { "startSyncChainHowTo", IDS_BRAVE_SYNC_RESET_START_NEW_INSTRUCTIONS },
- { "areYouSure", IDS_BRAVE_SYNC_RESET_ARE_YOU_SURE_TITLE },
- // [modal] Scan Code
- { "scanThisCode", IDS_BRAVE_SYNC_SCAN_CODE_TITLE },
- { "scanThisCodeHowToPartial1", IDS_BRAVE_SYNC_SCAN_CODE_DESCRIPTION_PARTIAL_1 }, // NOLINT
- { "scanThisCodeHowToPartial2", IDS_BRAVE_SYNC_SCAN_CODE_DESCRIPTION_PARTIAL_2 }, // NOLINT
- { "scanThisCodeHowToPartial3", IDS_BRAVE_SYNC_SCAN_CODE_DESCRIPTION_PARTIAL_3 }, // NOLINT
- // [modal] View Code
- { "chainCode", IDS_BRAVE_SYNC_VIEW_CODE_TITLE },
- { "chainCodeDescriptionPartial1", IDS_BRAVE_SYNC_VIEW_CODE_DESCRIPTION_PARTIAL_1 }, // NOLINT
- { "chainCodeDescriptionPartial2", IDS_BRAVE_SYNC_VIEW_CODE_DESCRIPTION_PARTIAL_2 }, // NOLINT
- { "chainCodeDescriptionPartial3", IDS_BRAVE_SYNC_VIEW_CODE_DESCRIPTION_PARTIAL_3 }, // NOLINT
- { "useCameraInstead", IDS_BRAVE_SYNC_VIEW_CODE_USE_CAMERA_BUTTON },
- { "qrCode", IDS_BRAVE_SYNC_VIEW_CODE_QR_CODE },
- // [modal] Choose Device Type
- { "letsSync", IDS_BRAVE_SYNC_CHOOSE_DEVICE_TITLE },
- { "chooseDeviceType", IDS_BRAVE_SYNC_CHOOSE_DEVICE_DESCRIPTION },
- { "phoneTablet", IDS_BRAVE_SYNC_CHOOSE_DEVICE_MOBILE_TITLE },
- { "computer", IDS_BRAVE_SYNC_CHOOSE_DEVICE_COMPUTER_TITLE },
- // errors
- { "errorWrongCodeTitle", IDS_BRAVE_SYNC_ERROR_WRONG_CODE_TITLE },
- { "errorWrongCodeDescription", IDS_BRAVE_SYNC_ERROR_WRONG_CODE_DESCRIPTION }, // NOLINT
- { "errorMissingDeviceNameTitle", IDS_BRAVE_SYNC_ERROR_MISSING_DEVICE_NAME_TITLE }, // NOLINT
- { "errorMissingCodeTitle", IDS_BRAVE_SYNC_ERROR_MISSING_SYNC_CODE_TITLE }, // NOLINT
- { "errorSyncInitFailedTitle", IDS_BRAVE_SYNC_ERROR_INIT_FAILED_TITLE },
- { "errorSyncInitFailedDescription", IDS_BRAVE_SYNC_ERROR_INIT_FAILED_DESCRIPTION }, // NOLINT
- { "errorSyncRequiresCorrectTimeTitle", IDS_BRAVE_SYNC_REQUIRES_CORRECT_TIME_TITLE }, // NOLINT
- { "errorSyncRequiresCorrectTimeDescription", IDS_BRAVE_SYNC_REQUIRES_CORRECT_TIME_DESCRIPTION }, // NOLINT
- }
}, {
std::string("adblock"), {
{ "additionalFiltersTitle", IDS_ADBLOCK_ADDITIONAL_FILTERS_TITLE },
diff --git a/browser/ui/webui/settings/brave_sync_handler.cc b/browser/ui/webui/settings/brave_sync_handler.cc
new file mode 100644
index 000000000000..d2f0593f774e
--- /dev/null
+++ b/browser/ui/webui/settings/brave_sync_handler.cc
@@ -0,0 +1,217 @@
+// Copyright (c) 2020 The Brave Authors. All rights reserved.
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// you can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include "brave/browser/ui/webui/settings/brave_sync_handler.h"
+
+#include
+#include
+#include
+
+#include "base/bind.h"
+#include "base/containers/span.h"
+#include "base/strings/string_number_conversions.h"
+#include "brave/components/brave_sync/brave_sync_prefs.h"
+#include "brave/components/brave_sync/crypto/crypto.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync/device_info_sync_service_factory.h"
+#include "chrome/browser/sync/profile_sync_service_factory.h"
+#include "components/sync/driver/sync_service.h"
+#include "components/sync/driver/sync_user_settings.h"
+#include "components/sync_device_info/device_info_sync_service.h"
+#include "components/sync_device_info/device_info_tracker.h"
+#include "components/sync_device_info/local_device_info_provider.h"
+#include "content/public/browser/web_ui.h"
+
+namespace {
+
+std::string StrFromUint8Array(const std::vector& arr) {
+ std::string result;
+ for (size_t i = 0; i < arr.size(); ++i) {
+ result += base::NumberToString(static_cast(arr.at(i)));
+ if (i != arr.size() - 1) {
+ result += ", ";
+ }
+ }
+ return result;
+}
+
+} // namespace
+
+BraveSyncHandler::BraveSyncHandler() { }
+BraveSyncHandler::~BraveSyncHandler() { }
+
+void BraveSyncHandler::RegisterMessages() {
+ profile_ = Profile::FromWebUI(web_ui());
+ web_ui()->RegisterMessageCallback(
+ "SyncGetDeviceList",
+ base::BindRepeating(&BraveSyncHandler::HandleGetDeviceList,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "SyncSetupSetSyncCode",
+ base::BindRepeating(&BraveSyncHandler::HandleSetSyncCode,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "SyncSetupGetSyncCode",
+ base::BindRepeating(&BraveSyncHandler::HandleGetSyncCode,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "SyncGetQRCode",
+ base::BindRepeating(&BraveSyncHandler::HandleGetQRCode,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "SyncSetupReset", base::BindRepeating(&BraveSyncHandler::HandleReset,
+ base::Unretained(this)));
+}
+
+void BraveSyncHandler::OnJavascriptAllowed() {
+ syncer::DeviceInfoTracker* tracker =
+ DeviceInfoSyncServiceFactory::GetForProfile(profile_)
+ ->GetDeviceInfoTracker();
+ DCHECK(tracker);
+ if (tracker)
+ device_info_tracker_observer_.Add(tracker);
+}
+
+void BraveSyncHandler::OnJavascriptDisallowed() {
+ device_info_tracker_observer_.RemoveAll();
+}
+
+void BraveSyncHandler::OnDeviceInfoChange() {
+ if (IsJavascriptAllowed())
+ FireWebUIListener("device-info-changed", GetSyncDeviceList());
+}
+
+void BraveSyncHandler::HandleGetDeviceList(const base::ListValue* args) {
+ AllowJavascript();
+ const auto& list = args->GetList();
+ CHECK_EQ(1U, list.size());
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+
+ ResolveJavascriptCallback(*callback_id, GetSyncDeviceList());
+}
+
+void BraveSyncHandler::HandleGetSyncCode(const base::ListValue* args) {
+ AllowJavascript();
+
+ CHECK_EQ(1U, args->GetSize());
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+
+ brave_sync::Prefs brave_sync_prefs(profile_->GetPrefs());
+ std::string sync_code = brave_sync_prefs.GetSeed();
+ if (sync_code.empty()) {
+ std::vector seed = brave_sync::crypto::GetSeed();
+ sync_code = brave_sync::crypto::PassphraseFromBytes32(seed);
+ }
+
+ ResolveJavascriptCallback(*callback_id, base::Value(sync_code));
+}
+
+void BraveSyncHandler::HandleGetQRCode(const base::ListValue* args) {
+ AllowJavascript();
+ CHECK_EQ(2U, args->GetSize());
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+ const base::Value* sync_code;
+ CHECK(args->Get(1, &sync_code));
+
+ std::vector seed;
+ if (!brave_sync::crypto::PassphraseToBytes32(sync_code->GetString(), &seed)) {
+ LOG(ERROR) << "invalid sync code";
+ ResolveJavascriptCallback(*callback_id, base::Value(false));
+ return;
+ }
+
+ std::string seed_serialized = StrFromUint8Array(seed);
+
+ // TODO(petemill): Use QRCodeGenerator
+ // const char* input_data_string = sync_code.c_str();
+ // auto input_data = base::span(
+ // reinterpret_cast(input_data_string),
+ // strlen(input_data_string));
+ // // Generate QR code data
+ // uint8_t qr_data_buf[QRCode::kInputBytes];
+ // QRCodeGenerator generator;
+ // base::span code =
+ // generator.Generate(input_data);
+ ResolveJavascriptCallback(*callback_id, base::Value(seed_serialized));
+ // ResolveJavascriptCallback(*callback_id, base::Value(false));
+}
+
+void BraveSyncHandler::HandleSetSyncCode(const base::ListValue* args) {
+ AllowJavascript();
+ CHECK_EQ(2U, args->GetSize());
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+ const base::Value* sync_code;
+ CHECK(args->Get(1, &sync_code));
+
+ if (sync_code->GetString().empty()) {
+ LOG(ERROR) << "No sync code parameter provided!";
+ RejectJavascriptCallback(*callback_id, base::Value(false));
+ return;
+ }
+
+ std::vector seed;
+ if (!brave_sync::crypto::PassphraseToBytes32(sync_code->GetString(), &seed)) {
+ LOG(ERROR) << "invalid sync code";
+ RejectJavascriptCallback(*callback_id, base::Value(false));
+ return;
+ }
+ brave_sync::Prefs brave_sync_prefs(profile_->GetPrefs());
+ if (!brave_sync_prefs.SetSeed(sync_code->GetString())) {
+ ResolveJavascriptCallback(*callback_id, base::Value(false));
+ return;
+ }
+ ResolveJavascriptCallback(*callback_id, base::Value(true));
+}
+
+void BraveSyncHandler::HandleReset(const base::ListValue* args) {
+ AllowJavascript();
+ CHECK_EQ(1U, args->GetSize());
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+
+ auto* sync_service = GetSyncService();
+ if (sync_service) {
+ sync_service->GetUserSettings()->SetSyncRequested(false);
+ sync_service->StopAndClear();
+ }
+ brave_sync::Prefs brave_sync_prefs(profile_->GetPrefs());
+ brave_sync_prefs.Clear();
+
+ // Sync prefs will be clear in ProfileSyncService::StopImpl
+ ResolveJavascriptCallback(*callback_id, base::Value());
+}
+
+syncer::SyncService* BraveSyncHandler::GetSyncService() const {
+ return ProfileSyncServiceFactory::IsSyncAllowed(profile_)
+ ? ProfileSyncServiceFactory::GetForProfile(profile_)
+ : nullptr;
+}
+
+base::Value BraveSyncHandler::GetSyncDeviceList() {
+ AllowJavascript();
+ auto* device_info_service =
+ DeviceInfoSyncServiceFactory::GetForProfile(profile_);
+ syncer::DeviceInfoTracker* tracker =
+ device_info_service->GetDeviceInfoTracker();
+ DCHECK(tracker);
+ const syncer::DeviceInfo* local_device_info = device_info_service
+ ->GetLocalDeviceInfoProvider()->GetLocalDeviceInfo();
+
+ base::Value device_list(base::Value::Type::LIST);
+
+ for (const auto& device : tracker->GetAllDeviceInfo()) {
+ auto device_value = base::Value::FromUniquePtrValue(device->ToValue());
+ bool is_current_device = local_device_info
+ ? local_device_info->guid() == device->guid()
+ : false;
+ device_value.SetBoolKey("isCurrentDevice", is_current_device);
+ device_list.Append(std::move(device_value));
+ }
+ return device_list;
+}
diff --git a/browser/ui/webui/settings/brave_sync_handler.h b/browser/ui/webui/settings/brave_sync_handler.h
new file mode 100644
index 000000000000..922896df1942
--- /dev/null
+++ b/browser/ui/webui/settings/brave_sync_handler.h
@@ -0,0 +1,53 @@
+// Copyright (c) 2020 The Brave Authors. All rights reserved.
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// you can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_SYNC_HANDLER_H_
+#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_SYNC_HANDLER_H_
+
+#include "base/scoped_observer.h"
+#include "base/values.h"
+#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
+#include "components/sync_device_info/device_info_tracker.h"
+
+namespace syncer {
+class SyncService;
+}
+class Profile;
+
+class BraveSyncHandler : public settings::SettingsPageUIHandler,
+ public syncer::DeviceInfoTracker::Observer {
+ public:
+ BraveSyncHandler();
+ ~BraveSyncHandler() override;
+
+ // syncer::DeviceInfoTracker::Observer
+ void OnDeviceInfoChange() override;
+
+ private:
+ // SettingsPageUIHandler overrides:
+ void RegisterMessages() override;
+ void OnJavascriptAllowed() override;
+ void OnJavascriptDisallowed() override;
+
+ // Custom message handlers:
+ void HandleGetDeviceList(const base::ListValue* args);
+ void HandleGetSyncCode(const base::ListValue* args);
+ void HandleSetSyncCode(const base::ListValue* args);
+ void HandleGetQRCode(const base::ListValue* args);
+ void HandleReset(const base::ListValue* args);
+
+ base::Value GetSyncDeviceList();
+ syncer::SyncService* GetSyncService() const;
+
+ Profile* profile_ = nullptr;
+
+ // Manages observer lifetimes.
+ ScopedObserver
+ device_info_tracker_observer_{this};
+
+ DISALLOW_COPY_AND_ASSIGN(BraveSyncHandler);
+};
+
+#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_SYNC_HANDLER_H_
diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc
deleted file mode 100644
index 53aa0ad1680c..000000000000
--- a/browser/ui/webui/sync/sync_ui.cc
+++ /dev/null
@@ -1,273 +0,0 @@
-/* Copyright 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "brave/browser/ui/webui/sync/sync_ui.h"
-
-#include
-#include
-
-#include "base/bind.h"
-#include "base/memory/weak_ptr.h"
-#include "brave/common/webui_url_constants.h"
-#include "brave/components/brave_sync/brave_sync_service.h"
-#include "brave/components/brave_sync/brave_sync_service_observer.h"
-#include "brave/components/brave_sync/grit/brave_sync_generated_map.h"
-#include "brave/components/brave_sync/grit/brave_sync_resources.h"
-#include "brave/components/brave_sync/public/brave_profile_sync_service.h"
-#include "brave/components/brave_sync/settings.h"
-#include "brave/components/brave_sync/sync_devices.h"
-#include "brave/components/brave_sync/values_conv.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/profile_sync_service_factory.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/web_ui_message_handler.h"
-
-using content::WebUIMessageHandler;
-
-namespace {
-
-// The handler for Javascript messages for Brave about: pages
-class SyncUIDOMHandler : public WebUIMessageHandler,
- public brave_sync::BraveSyncServiceObserver {
- public:
- SyncUIDOMHandler();
- ~SyncUIDOMHandler() override;
-
- void Init();
-
- // WebUIMessageHandler implementation.
- void RegisterMessages() override;
-
- private:
- void SetupSyncHaveCode(const base::ListValue* args);
- void SetupSyncNewToSync(const base::ListValue* args);
- void PageLoaded(const base::ListValue* args);
- void NeedSyncWords(const base::ListValue* args);
- void NeedSyncQRcode(const base::ListValue* args);
- void SyncBookmarks(const base::ListValue* args);
- void SyncBrowsingHistory(const base::ListValue* args);
- void SyncSavedSiteSettings(const base::ListValue* args);
- void DeleteDevice(const base::ListValue* args);
- void ResetSync(const base::ListValue* args);
-
- void OnSyncSetupError(brave_sync::BraveSyncService* sync_service,
- const std::string& error) override;
- void OnSyncStateChanged(brave_sync::BraveSyncService *sync_service) override;
- void OnHaveSyncWords(brave_sync::BraveSyncService *sync_service,
- const std::string& sync_words) override;
-
- // this should grab actual data from controller and update the page
- void LoadSyncSettingsView();
-
- // Move to observer
- void GetSettingsAndDevicesComplete(
- std::unique_ptr settings,
- std::unique_ptr devices);
-
- brave_sync::BraveSyncService* sync_service_ = nullptr; // NOT OWNED
-
- base::WeakPtrFactory weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(SyncUIDOMHandler);
-};
-
-SyncUIDOMHandler::SyncUIDOMHandler() : weak_ptr_factory_(this) {}
-
-SyncUIDOMHandler::~SyncUIDOMHandler() {
- if (sync_service_)
- sync_service_->RemoveObserver(this);
-}
-
-void SyncUIDOMHandler::RegisterMessages() {
- this->web_ui()->RegisterMessageCallback("setupSyncHaveCode",
- base::Bind(&SyncUIDOMHandler::SetupSyncHaveCode,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("setupSyncNewToSync",
- base::Bind(&SyncUIDOMHandler::SetupSyncNewToSync,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("pageLoaded",
- base::Bind(&SyncUIDOMHandler::PageLoaded,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("needSyncWords",
- base::Bind(&SyncUIDOMHandler::NeedSyncWords,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("needSyncQRcode",
- base::Bind(&SyncUIDOMHandler::NeedSyncQRcode,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("syncBookmarks",
- base::Bind(&SyncUIDOMHandler::SyncBookmarks,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("syncBrowsingHistory",
- base::Bind(&SyncUIDOMHandler::SyncBrowsingHistory,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("syncSavedSiteSettings",
- base::Bind(&SyncUIDOMHandler::SyncSavedSiteSettings,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("deleteDevice",
- base::Bind(&SyncUIDOMHandler::DeleteDevice,
- base::Unretained(this)));
-
- this->web_ui()->RegisterMessageCallback("resetSync",
- base::Bind(&SyncUIDOMHandler::ResetSync,
- base::Unretained(this)));
-}
-
-void SyncUIDOMHandler::Init() {
- Profile* profile = Profile::FromWebUI(web_ui());
- auto* profile_sync_service =
- static_cast(
- ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile(
- profile));
-
- sync_service_ = profile_sync_service->GetSyncService();
- if (sync_service_)
- sync_service_->AddObserver(this);
-}
-
-void SyncUIDOMHandler::SetupSyncHaveCode(const base::ListValue* args) {
- DCHECK(sync_service_);
- std::string sync_words, device_name;
- if (!args->GetString(0, &sync_words) || !args->GetString(1, &device_name))
- // TODO(bridiver) - does this need to report an error?
- return;
-
- sync_service_->OnSetupSyncHaveCode(sync_words, device_name);
-}
-
-void SyncUIDOMHandler::SetupSyncNewToSync(const base::ListValue* args) {
- DCHECK(sync_service_);
- std::string sync_words, device_name;
- if (!args->GetString(0, &device_name))
- // TODO(bridiver) - does this need to report an error?
- return;
-
- sync_service_->OnSetupSyncNewToSync(device_name);
-}
-
-void SyncUIDOMHandler::PageLoaded(const base::ListValue* args) {
- DCHECK(sync_service_);
- LoadSyncSettingsView();
-}
-
-void SyncUIDOMHandler::NeedSyncWords(const base::ListValue* args) {
- DCHECK(sync_service_);
- sync_service_->GetSyncWords();
-}
-
-void SyncUIDOMHandler::NeedSyncQRcode(const base::ListValue* args) {
- DCHECK(sync_service_);
- std::string seed = sync_service_->GetSeed();
- web_ui()->CallJavascriptFunctionUnsafe(
- "sync_ui_exports.haveSeedForQrCode", base::Value(seed));
-}
-
-void SyncUIDOMHandler::SyncBookmarks(const base::ListValue* args) {
- DCHECK(sync_service_);
- bool new_value;
- if (!args->GetBoolean(0, &new_value))
- // TODO(bridiver) - does this need to report an error?
- return;
-
- sync_service_->OnSetSyncBookmarks(new_value);
-}
-
-void SyncUIDOMHandler::SyncBrowsingHistory(const base::ListValue* args) {
- DCHECK(sync_service_);
- bool new_value;
- if (!args->GetBoolean(0, &new_value))
- // TODO(bridiver) - does this need to report an error?
- return;
-
- sync_service_->OnSetSyncBrowsingHistory(new_value);
-}
-
-void SyncUIDOMHandler::SyncSavedSiteSettings(const base::ListValue* args) {
- DCHECK(sync_service_);
- bool new_value;
- if (!args->GetBoolean(0, &new_value))
- // TODO(bridiver) - does this need to report an error?
- return;
-
- sync_service_->OnSetSyncSavedSiteSettings(new_value);
-}
-
-void SyncUIDOMHandler::DeleteDevice(const base::ListValue* args) {
- DCHECK(sync_service_);
- std::string device_id_v2;
- if (!args->GetString(0, &device_id_v2)) {
- DCHECK(false) << "[Brave Sync] could not get device id v2";
- return;
- }
-
- sync_service_->OnDeleteDevice(device_id_v2);
-}
-
-void SyncUIDOMHandler::ResetSync(const base::ListValue* args) {
- DCHECK(sync_service_);
- sync_service_->OnResetSync();
-}
-
-void SyncUIDOMHandler::OnSyncSetupError(
- brave_sync::BraveSyncService* sync_service,
- const std::string& error) {
-
- web_ui()->CallJavascriptFunctionUnsafe(
- "sync_ui_exports.syncSetupError", base::Value(error));
-}
-
-void SyncUIDOMHandler::OnSyncStateChanged(
- brave_sync::BraveSyncService *sync_service) {
- LoadSyncSettingsView();
-}
-
-void SyncUIDOMHandler::LoadSyncSettingsView() {
- sync_service_->GetSettingsAndDevices(
- base::Bind(&SyncUIDOMHandler::GetSettingsAndDevicesComplete,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void SyncUIDOMHandler::GetSettingsAndDevicesComplete(
- std::unique_ptr settings,
- std::unique_ptr devices) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-
- std::unique_ptr bv_devices = devices->ToValueArrOnly();
- std::unique_ptr bv_settings =
- brave_sync::BraveSyncSettingsToValue(settings.get());
- web_ui()->CallJavascriptFunctionUnsafe(
- "sync_ui_exports.showSettings", *bv_settings, *bv_devices);
-}
-
-void SyncUIDOMHandler::OnHaveSyncWords(
- brave_sync::BraveSyncService *sync_service,
- const std::string& sync_words) {
- web_ui()->CallJavascriptFunctionUnsafe(
- "sync_ui_exports.haveSyncWords", base::Value(sync_words));
-}
-
-} // namespace
-
-SyncUI::SyncUI(content::WebUI* web_ui, const std::string& name)
- : BasicUI(web_ui, name,
- kBraveSyncGenerated,
- kBraveSyncGeneratedSize,
- Profile::FromWebUI(web_ui)->IsOffTheRecord() ?
- IDR_BRAVE_SYNC_DISABLED_HTML : IDR_BRAVE_SYNC_HTML) {
- auto handler_owner = std::make_unique();
- SyncUIDOMHandler* handler = handler_owner.get();
- web_ui->AddMessageHandler(std::move(handler_owner));
- handler->Init();
-}
-
-SyncUI::~SyncUI() {
-}
diff --git a/browser/ui/webui/sync/sync_ui.h b/browser/ui/webui/sync/sync_ui.h
deleted file mode 100644
index 47e02bd058dd..000000000000
--- a/browser/ui/webui/sync/sync_ui.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_BROWSER_UI_WEBUI_SYNC_I_SYNC_UI_H_
-#define BRAVE_BROWSER_UI_WEBUI_SYNC_I_SYNC_UI_H_
-
-#include
-
-#include "brave/browser/ui/webui/basic_ui.h"
-
-class SyncUI : public BasicUI {
-public:
- SyncUI(content::WebUI* web_ui, const std::string& host);
- ~SyncUI() override;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(SyncUI);
-};
-
-#endif //BRAVE_BROWSER_UI_WEBUI_SYNC_I_SYNC_UI_H_
diff --git a/build/config/brave_build.gni b/build/config/brave_build.gni
index 6fec95b80c76..fcb2fc2f721b 100644
--- a/build/config/brave_build.gni
+++ b/build/config/brave_build.gni
@@ -4,5 +4,6 @@
import("//brave/brave_repack_locales.gni")
import("//brave/build/config/compiler.gni")
import("//brave/build/features.gni")
+import("//brave/components/sync/driver/sources.gni")
import("//brave/net/sources.gni")
import("//brave/third_party/blink/renderer/includes.gni")
diff --git a/build/features.gni b/build/features.gni
index a85ec90fa669..e5202e2c48a1 100644
--- a/build/features.gni
+++ b/build/features.gni
@@ -1,8 +1,17 @@
declare_args() {
brave_chromium_build = true
brave_branding_path_component = ""
+
+ brave_services_key = ""
}
if (brave_chromium_build && !is_ios) {
brave_branding_path_component = "brave"
}
+
+brave_service_key_defines = []
+if (brave_services_key != "") {
+ brave_service_key_defines += [ "BRAVE_SERVICES_KEY=\"$brave_services_key\"" ]
+} else {
+ brave_service_key_defines += [ "BRAVE_SERVICES_KEY=\"dummytoken\"" ]
+}
diff --git a/chromium_src/chrome/browser/about_flags.cc b/chromium_src/chrome/browser/about_flags.cc
index f4060d48a334..8e98f10a2e22 100644
--- a/chromium_src/chrome/browser/about_flags.cc
+++ b/chromium_src/chrome/browser/about_flags.cc
@@ -9,7 +9,7 @@
#include "brave/common/brave_features.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_shields/common/features.h"
-#include "brave/components/brave_sync/features.h"
+#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/ntp_background_images/browser/features.h"
#include "brave/components/speedreader/buildflags.h"
#include "chrome/browser/profiles/profile.h"
@@ -17,7 +17,6 @@
#include "components/prefs/pref_service.h"
using brave_shields::features::kBraveAdblockCosmeticFiltering;
-using brave_sync::features::kBraveSync;
using ntp_background_images::features::kBraveNTPBrandedWallpaper;
using ntp_background_images::features::kBraveNTPBrandedWallpaperDemo;
using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
@@ -35,6 +34,18 @@ using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
#define SPEEDREADER_FEATURE_ENTRIES
#endif
+#if BUILDFLAG(ENABLE_BRAVE_SYNC)
+#include "brave/components/brave_sync/features.h"
+
+#define BRAVE_SYNC_FEATURE_ENTRIES \
+ {"brave-sync-v2", \
+ flag_descriptions::kBraveSyncName, \
+ flag_descriptions::kBraveSyncDescription, kOsDesktop, \
+ FEATURE_VALUE_TYPE(brave_sync::features::kBraveSync)},
+#else
+#define BRAVE_SYNC_FEATURE_ENTRIES
+#endif
+
#define BRAVE_FEATURE_ENTRIES \
{"use-dev-updater-url", \
flag_descriptions::kUseDevUpdaterUrlName, \
@@ -53,10 +64,7 @@ using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
flag_descriptions::kBraveAdblockCosmeticFilteringDescription, kOsAll, \
FEATURE_VALUE_TYPE(kBraveAdblockCosmeticFiltering)}, \
SPEEDREADER_FEATURE_ENTRIES \
- {"brave-sync", \
- flag_descriptions::kBraveSyncName, \
- flag_descriptions::kBraveSyncDescription, kOsDesktop, \
- FEATURE_VALUE_TYPE(kBraveSync)}, \
+ BRAVE_SYNC_FEATURE_ENTRIES \
{"brave-super-referral", \
flag_descriptions::kBraveSuperReferralName, \
flag_descriptions::kBraveSuperReferralDescription, \
diff --git a/chromium_src/chrome/browser/autocomplete/autocomplete_classifier_factory.cc b/chromium_src/chrome/browser/autocomplete/autocomplete_classifier_factory.cc
index 25b589e00e6a..a0140ae6c9a7 100644
--- a/chromium_src/chrome/browser/autocomplete/autocomplete_classifier_factory.cc
+++ b/chromium_src/chrome/browser/autocomplete/autocomplete_classifier_factory.cc
@@ -3,13 +3,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "brave/browser/autocomplete/brave_autocomplete_provider_client.h"
#include "brave/browser/autocomplete/brave_autocomplete_scheme_classifier.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
-#define ChromeAutocompleteProviderClient BraveAutocompleteProviderClient
#define ChromeAutocompleteSchemeClassifier BraveAutocompleteSchemeClassifier
#include "../../../../../chrome/browser/autocomplete/autocomplete_classifier_factory.cc"
#undef ChromeAutocompleteSchemeClassifier
-#undef ChromeAutocompleteProviderClient
diff --git a/chromium_src/chrome/browser/browser_about_handler.cc b/chromium_src/chrome/browser/browser_about_handler.cc
index 054f10cf9864..3615484687fa 100644
--- a/chromium_src/chrome/browser/browser_about_handler.cc
+++ b/chromium_src/chrome/browser/browser_about_handler.cc
@@ -14,13 +14,6 @@ bool FixupBrowserAboutURL(GURL* url,
content::BrowserContext* browser_context) {
bool result = FixupBrowserAboutURL_ChromiumImpl(url, browser_context);
- // redirect sync-internals
- if (url->host() == chrome::kChromeUISyncInternalsHost) {
- GURL::Replacements replacements;
- replacements.SetHostStr(chrome::kChromeUISyncHost);
- *url = url->ReplaceComponents(replacements);
- }
-
if (url->SchemeIs(kBraveUIScheme)) {
GURL::Replacements replacements;
replacements.SetSchemeStr(content::kChromeUIScheme);
diff --git a/chromium_src/chrome/browser/extensions/component_extensions_whitelist/whitelist.cc b/chromium_src/chrome/browser/extensions/component_extensions_whitelist/whitelist.cc
index cb73fc8268f5..29c8310dd570 100644
--- a/chromium_src/chrome/browser/extensions/component_extensions_whitelist/whitelist.cc
+++ b/chromium_src/chrome/browser/extensions/component_extensions_whitelist/whitelist.cc
@@ -12,7 +12,6 @@
#include "brave/components/brave_extension/grit/brave_extension.h"
#include "components/grit/brave_components_resources.h"
#include "brave/components/brave_rewards/resources/extension/grit/brave_rewards_extension_resources.h"
-#include "brave/components/brave_sync/grit/brave_sync_resources.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h"
namespace extensions {
@@ -21,7 +20,6 @@ namespace extensions {
const char* const kAllowed[] = {
brave_extension_id,
brave_rewards_extension_id,
- brave_sync_extension_id,
ethereum_remote_client_extension_id,
brave_webtorrent_extension_id
};
@@ -39,7 +37,6 @@ namespace extensions {
// Please keep the list in alphabetical order.
case IDR_BRAVE_EXTENSION:
case IDR_BRAVE_REWARDS:
- case IDR_BRAVE_SYNC_EXTENSION:
case IDR_BRAVE_WEBTORRENT:
return true;
}
diff --git a/chromium_src/chrome/browser/flag_descriptions.cc b/chromium_src/chrome/browser/flag_descriptions.cc
index ce60f2cc86ed..acf59816882b 100644
--- a/chromium_src/chrome/browser/flag_descriptions.cc
+++ b/chromium_src/chrome/browser/flag_descriptions.cc
@@ -27,8 +27,10 @@ const char kBraveAdblockCosmeticFilteringDescription[] =
const char kBraveSpeedreaderName[] = "Enable SpeedReader";
const char kBraveSpeedreaderDescription[] =
"Enables faster loading of simplified article-style web pages.";
-const char kBraveSyncName[] = "Enable Brave Sync";
-const char kBraveSyncDescription[] = "Brave Sync is disabled by default";
+const char kBraveSyncName[] = "Enable Brave Sync v2";
+const char kBraveSyncDescription[] =
+ "Brave Sync v2 integrates with chromium sync engine with Brave specific "
+ "authentication flow and enforce client side encryption";
const char kBraveSuperReferralName[] = "Enable Brave Super Referral";
const char kBraveSuperReferralDescription[] =
"Use custom theme for Brave Super Referral";
diff --git a/chromium_src/chrome/browser/prefs/browser_prefs.cc b/chromium_src/chrome/browser/prefs/browser_prefs.cc
index e999301ce056..227e2996dcc9 100644
--- a/chromium_src/chrome/browser/prefs/browser_prefs.cc
+++ b/chromium_src/chrome/browser/prefs/browser_prefs.cc
@@ -45,8 +45,7 @@ void MigrateObsoleteProfilePrefs(Profile* profile) {
// Added 11/2019.
MigrateWidevinePrefs(profile);
#endif
- // Added 11/2019.
- MigrateBraveSyncPrefs(profile->GetPrefs());
+ brave_sync::MigrateBraveSyncPrefs(profile->GetPrefs());
// Added 12/2019.
dark_mode::MigrateBraveDarkModePrefs(profile);
diff --git a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc
index 58063bc00024..bd93c36ea817 100644
--- a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc
+++ b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc
@@ -4,12 +4,12 @@
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
-#include "brave/browser/autocomplete/brave_autocomplete_provider_client.h"
#include "brave/browser/autocomplete/brave_autocomplete_scheme_classifier.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/browser/translate/buildflags/buildflags.h"
#include "brave/browser/renderer_context_menu/brave_spelling_options_submenu_observer.h"
+#include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
@@ -28,7 +28,7 @@ GURL GetSelectionNavigationURL(Profile* profile, const base::string16& text) {
AutocompleteMatch match;
AutocompleteClassifier classifier(
std::make_unique(
- std::make_unique(profile),
+ std::make_unique(profile),
AutocompleteClassifier::DefaultOmniboxProviders()),
std::make_unique(profile));
classifier.Classify(text, false, false,
diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc
deleted file mode 100644
index 3c5a62c9e770..000000000000
--- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "components/sync/driver/profile_sync_service.h"
-#include "brave/components/brave_sync/buildflags/buildflags.h"
-
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-#include "brave/components/brave_sync/brave_profile_sync_service_impl.h"
-using brave_sync::BraveProfileSyncServiceImpl;
-#endif
-
-class Profile;
-
-namespace {
-
-std::unique_ptr BraveBuildServiceInstanceFor(
- Profile* profile,
- syncer::ProfileSyncService::InitParams init_params) {
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- return std::make_unique(profile,
- std::move(init_params));
-#else
- return std::make_unique(std::move(init_params));
-#endif
-}
-
-} // namespace
-
-#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" // NOLINT
diff --git a/chromium_src/chrome/browser/ui/browser_navigator.cc b/chromium_src/chrome/browser/ui/browser_navigator.cc
index eb73964aafe0..e204555dcf86 100644
--- a/chromium_src/chrome/browser/ui/browser_navigator.cc
+++ b/chromium_src/chrome/browser/ui/browser_navigator.cc
@@ -55,7 +55,6 @@ void MaybeHandleInParent(NavigateParams* params, bool allow_in_incognito) {
bool IsHostAllowedInIncognitoBraveImpl(const base::StringPiece& host) {
if (host == kWalletHost ||
host == kRewardsPageHost ||
- host == kBraveUISyncHost ||
host == chrome::kChromeUISyncInternalsHost) {
return false;
}
diff --git a/chromium_src/chrome/browser/ui/chrome_pages.cc b/chromium_src/chrome/browser/ui/chrome_pages.cc
new file mode 100644
index 000000000000..27f1d1cceb39
--- /dev/null
+++ b/chromium_src/chrome/browser/ui/chrome_pages.cc
@@ -0,0 +1,25 @@
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// It has caller in the same file
+#define BRAVE_GET_SETTINGS_URL \
+GURL GetSettingsUrl_ChromiumImpl(const std::string& sub_page) {
+// BRAVE_GET_SETTINGS_URL
+
+#include "../../../../../chrome/browser/ui/chrome_pages.cc"
+
+#undef BRAVE_GET_SETTINGS_URL
+
+#include "brave/common/webui_url_constants.h"
+
+namespace chrome {
+
+GURL GetSettingsUrl(const std::string& sub_page) {
+ if (sub_page == chrome::kSyncSetupSubPage)
+ return chrome::GetSettingsUrl(kBraveSyncSetupPath);
+ return GetSettingsUrl_ChromiumImpl(sub_page);
+}
+
+} // namespace chrome
diff --git a/chromium_src/chrome/browser/ui/omnibox/chrome_omnibox_client.cc b/chromium_src/chrome/browser/ui/omnibox/chrome_omnibox_client.cc
deleted file mode 100644
index 37b498b88d50..000000000000
--- a/chromium_src/chrome/browser/ui/omnibox/chrome_omnibox_client.cc
+++ /dev/null
@@ -1,10 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "brave/browser/autocomplete/brave_autocomplete_provider_client.h"
-
-#define ChromeAutocompleteProviderClient BraveAutocompleteProviderClient
-#include "../../../../../../chrome/browser/ui/omnibox/chrome_omnibox_client.cc"
-#undef ChromeAutocompleteProviderClient
-
diff --git a/chromium_src/chrome/browser/ui/passwords/manage_passwords_view_utils.cc b/chromium_src/chrome/browser/ui/passwords/manage_passwords_view_utils.cc
new file mode 100644
index 000000000000..5dfda7198518
--- /dev/null
+++ b/chromium_src/chrome/browser/ui/passwords/manage_passwords_view_utils.cc
@@ -0,0 +1,12 @@
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#define ShouldManagePasswordsinGooglePasswordManager \
+ ShouldManagePasswordsinGooglePasswordManager_ChromiumImpl
+#include "../../../../../../chrome/browser/ui/passwords/manage_passwords_view_utils.cc"
+#undef ShouldManagePasswordsinGooglePasswordManager
+bool ShouldManagePasswordsinGooglePasswordManager(Profile* profile) {
+ return false;
+}
diff --git a/chromium_src/chrome/browser/ui/webui/settings/people_handler.cc b/chromium_src/chrome/browser/ui/webui/settings/people_handler.cc
new file mode 100644
index 000000000000..1bcd6c8ace59
--- /dev/null
+++ b/chromium_src/chrome/browser/ui/webui/settings/people_handler.cc
@@ -0,0 +1,15 @@
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// IsSetupInProgress isn't accurate in brave sync flow especially for the first
+// time setup, we rely on it to display setup dialog
+#define BRAVE_GET_SYNC_STATUS_DICTIONARY \
+ sync_status->SetBoolean( \
+ "firstSetupInProgress", \
+ service && !disallowed_by_policy && \
+ !service->GetUserSettings()->IsFirstSetupComplete());
+
+#include "../../../../../../../chrome/browser/ui/webui/settings/people_handler.cc"
+#undef BRAVE_GET_SYNC_STATUS_DICTIONARY
diff --git a/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc b/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
index 0cad859ad228..901a12d5bf06 100644
--- a/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
+++ b/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
@@ -145,8 +145,82 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_WEBRTC_POLICY_DISABLE_NON_PROXIED_UDP},
{"braveSync",
IDS_SETTINGS_BRAVE_SYNC_TITLE},
- {"braveSyncLabel",
- IDS_SETTINGS_BRAVE_SYNC_LINK_LABEL},
+ {"braveSyncSetupActionLabel",
+ IDS_SETTINGS_BRAVE_SYNC_SETUP_ACTION_LABEL},
+ {"braveSyncSetupTitle",
+ IDS_SETTINGS_BRAVE_SYNC_SETUP_TITLE},
+ {"braveSyncSetupSubtitle",
+ IDS_SETTINGS_BRAVE_SYNC_SETUP_SUBTITLE},
+ {"braveSyncManageActionLabel",
+ IDS_SETTINGS_BRAVE_SYNC_MANAGE_ACTION_LABEL},
+ {"braveSyncWordCount",
+ IDS_SETTINGS_BRAVE_SYNC_WORD_COUNT},
+ {"braveSyncCopied",
+ IDS_SETTINGS_BRAVE_SYNC_COPIED_TEXT},
+ {"braveSyncManagerTitle",
+ IDS_SETTINGS_BRAVE_SYNC_MANAGER_TITLE},
+ {"braveSyncSettingsTitle",
+ IDS_SETTINGS_BRAVE_SYNC_SETTINGS_TITLE},
+ {"braveSyncSettingsSubtitle",
+ IDS_SETTINGS_BRAVE_SYNC_SETTINGS_SUBTITLE},
+ {"braveSyncDeviceListTitle",
+ IDS_SETTINGS_BRAVE_SYNC_DEVICE_LIST_TITLE},
+ {"braveSyncDeviceListSubtitle",
+ IDS_SETTINGS_BRAVE_SYNC_DEVICE_LIST_SUBTITLE},
+ {"braveSyncDeviceListNameColumn",
+ IDS_SETTINGS_BRAVE_SYNC_DEVICE_LIST_NAME_COLUMN},
+ {"braveSyncDeviceListNameThisDevice",
+ IDS_SETTINGS_BRAVE_SYNC_DEVICE_LIST_NAME_THIS_DEVICE},
+ {"braveSyncDeviceListLastActiveColumn",
+ IDS_SETTINGS_BRAVE_SYNC_DEVICE_LIST_LAST_ACTIVE_COLUMN},
+ {"braveSyncSetupTitle",
+ IDS_BRAVE_SYNC_SETUP_TITLE},
+ {"braveSyncSetupDesc",
+ IDS_BRAVE_SYNC_SETUP_DESCRIPTION},
+ {"braveSyncStartNewChain",
+ IDS_BRAVE_SYNC_START_NEW_CHAIN_BUTTON},
+ {"braveSyncEnterCode",
+ IDS_BRAVE_SYNC_ENTER_CODE_BUTTON},
+ {"braveSyncChooseDeviceMobileTitle",
+ IDS_BRAVE_SYNC_CHOOSE_DEVICE_MOBILE_TITLE},
+ {"braveSyncChooseDeviceComputerTitle",
+ IDS_BRAVE_SYNC_CHOOSE_DEVICE_COMPUTER_TITLE},
+ {"braveSyncScanCodeTitle",
+ IDS_BRAVE_SYNC_SCAN_CODE_TITLE},
+ {"braveSyncScanCodeDesc1",
+ IDS_BRAVE_SYNC_SCAN_CODE_DESCRIPTION_PARTIAL_1},
+ {"braveSyncScanCodeDesc2",
+ IDS_BRAVE_SYNC_SCAN_CODE_DESCRIPTION_PARTIAL_2},
+ {"braveSyncScanCodeDesc3",
+ IDS_BRAVE_SYNC_SCAN_CODE_DESCRIPTION_PARTIAL_3},
+ {"braveSyncViewCodeTitle",
+ IDS_BRAVE_SYNC_VIEW_CODE_TITLE},
+ {"braveSyncViewCodeDesc1",
+ IDS_BRAVE_SYNC_VIEW_CODE_DESCRIPTION_PARTIAL_1},
+ {"braveSyncViewCodeDesc2",
+ IDS_BRAVE_SYNC_VIEW_CODE_DESCRIPTION_PARTIAL_2},
+ {"braveSyncViewCodeDesc3",
+ IDS_BRAVE_SYNC_VIEW_CODE_DESCRIPTION_PARTIAL_3},
+ {"braveSyncViewCodeQRCodeButton",
+ IDS_BRAVE_SYNC_VIEW_CODE_QR_CODE_BUTTON},
+ {"braveSyncEnterCodeTitle",
+ IDS_BRAVE_SYNC_ENTER_CODE_TITLE},
+ {"braveSyncEnterCodeDesc",
+ IDS_BRAVE_SYNC_ENTER_CODE_DESCRIPTION},
+ {"braveSyncViewCodeButton",
+ IDS_BRAVE_SYNC_VIEW_CODE_BUTTON},
+ {"braveSyncAddDevice",
+ IDS_BRAVE_SYNC_ADD_DEVICE_BUTTON},
+ {"braveSyncChooseDeviceTitle",
+ IDS_BRAVE_SYNC_CHOOSE_DEVICE_TITLE},
+ {"braveSyncChooseDeviceDesc",
+ IDS_BRAVE_SYNC_CHOOSE_DEVICE_DESCRIPTION},
+ {"braveSyncInvalidSyncCodeTitle",
+ IDS_BRAVE_SYNC_INVALID_SYNC_CODE_TITLE},
+ {"braveSyncResetButton",
+ IDS_BRAVE_SYNC_RESET_BUTTON},
+ {"braveSyncResetConfirmation",
+ IDS_BRAVE_SYNC_RESET_CONFIRMATION},
{"braveHelpTips",
IDS_SETTINGS_HELP_TIPS},
{"braveHelpTipsWaybackMachineLabel",
diff --git a/chromium_src/components/autofill/core/browser/autofill_experiments.cc b/chromium_src/components/autofill/core/browser/autofill_experiments.cc
index 991f0632a691..1b8958467d58 100644
--- a/chromium_src/components/autofill/core/browser/autofill_experiments.cc
+++ b/chromium_src/components/autofill/core/browser/autofill_experiments.cc
@@ -14,6 +14,7 @@ class SyncService;
namespace autofill {
class LogManager;
+class PersonalDataManager;
bool IsCreditCardUploadEnabled(const PrefService* pref_service,
const syncer::SyncService* sync_service,
const std::string& user_email,
@@ -21,8 +22,17 @@ bool IsCreditCardUploadEnabled(const PrefService* pref_service,
LogManager* log_manager) {
return false;
}
+bool IsCreditCardMigrationEnabled(PersonalDataManager* personal_data_manager,
+ PrefService* pref_service,
+ syncer::SyncService* sync_service,
+ bool is_test_mode,
+ LogManager* log_manager) {
+ return false;
+}
} // namespace autofill
#define IsCreditCardUploadEnabled IsCreditCardUploadEnabled_ChromiumImpl
+#define IsCreditCardMigrationEnabled IsCreditCardMigrationEnabled_ChromiumImpl
#include "../../../../../../components/autofill/core/browser/autofill_experiments.cc"
#undef IsCreditCardUploadEnabled
+#undef IsCreditCardMigrationEnabled
diff --git a/chromium_src/components/bookmarks/browser/bookmark_model.cc b/chromium_src/components/bookmarks/browser/bookmark_model.cc
index 6b946ed15c49..d6f360ef0fad 100644
--- a/chromium_src/components/bookmarks/browser/bookmark_model.cc
+++ b/chromium_src/components/bookmarks/browser/bookmark_model.cc
@@ -5,6 +5,8 @@
#include "../../../../../components/bookmarks/browser/bookmark_model.cc"
+#include "ui/base/models/tree_node_iterator.h"
+
namespace bookmarks {
// Move bookmarks under "Other Bookmarks" folder from
@@ -15,11 +17,11 @@ void BraveMigrateOtherNodeFolder(BookmarkModel* model) {
// Model must be loaded at this point
if (!model->bookmark_bar_node()->children().size())
return;
- const bookmarks::BookmarkNode* possible_other_node_folder =
- model->bookmark_bar_node()->children().back().get();
+ const BookmarkNode* possible_other_node_folder =
+ model->bookmark_bar_node()->children().back().get();
if (possible_other_node_folder->is_folder() &&
(possible_other_node_folder->GetTitledUrlNodeTitle() ==
- model->other_node()->GetTitledUrlNodeTitle())) {
+ model->other_node()->GetTitledUrlNodeTitle())) {
size_t children_size = possible_other_node_folder->children().size();
for (size_t i = 0; i < children_size; ++i) {
model->Move(possible_other_node_folder->children().front().get(),
@@ -29,4 +31,35 @@ void BraveMigrateOtherNodeFolder(BookmarkModel* model) {
}
}
+void BraveClearSyncV1MetaInfo(BookmarkModel* model) {
+ CHECK(model);
+ CHECK(model->loaded());
+ model->BeginExtensiveChanges();
+ ui::TreeNodeIterator iterator(model->root_node());
+ while (iterator.has_next()) {
+ const BookmarkNode* node = iterator.Next();
+ // Permanent node cannot trigger BookmarkModelObserver and we stored meta
+ // info in it
+ if (model->is_permanent_node(node)) {
+ const_cast(node)->SetMetaInfoMap(
+ BookmarkNode::MetaInfoMap());
+ }
+
+ model->DeleteNodeMetaInfo(node, "object_id");
+ model->DeleteNodeMetaInfo(node, "order");
+ model->DeleteNodeMetaInfo(node, "parent_object_id");
+ model->DeleteNodeMetaInfo(node, "position_in_parent");
+ model->DeleteNodeMetaInfo(node, "sync_timestamp");
+ model->DeleteNodeMetaInfo(node, "version");
+
+ // These might exist if user uses v1 since the very beginning when we
+ // integrates with chromium sync
+ model->DeleteNodeMetaInfo(node, "originator_cache_guid");
+ model->DeleteNodeMetaInfo(node, "originator_client_item_id");
+ model->DeleteNodeMetaInfo(node, "mtime");
+ model->DeleteNodeMetaInfo(node, "ctime");
+ }
+ model->EndExtensiveChanges();
+}
+
} // namespace bookmarks
diff --git a/chromium_src/components/bookmarks/browser/bookmark_model.h b/chromium_src/components/bookmarks/browser/bookmark_model.h
index 0e927ae602cb..0084520ba030 100644
--- a/chromium_src/components/bookmarks/browser/bookmark_model.h
+++ b/chromium_src/components/bookmarks/browser/bookmark_model.h
@@ -16,6 +16,7 @@ class BraveSyncServiceTestDelayedLoadModel;
namespace bookmarks {
void BraveMigrateOtherNodeFolder(BookmarkModel* model);
+void BraveClearSyncV1MetaInfo(BookmarkModel* model);
} // namespace bookmarks
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_
diff --git a/chromium_src/components/bookmarks/browser/bookmark_model_unittest.cc b/chromium_src/components/bookmarks/browser/bookmark_model_unittest.cc
index afce42c2569a..f3a3a774c519 100644
--- a/chromium_src/components/bookmarks/browser/bookmark_model_unittest.cc
+++ b/chromium_src/components/bookmarks/browser/bookmark_model_unittest.cc
@@ -56,8 +56,8 @@ TEST_F(BookmarkModelTest, BraveMigrateOtherNodeFolderNotExist) {
BraveMigrateOtherNodeFolder(model_.get());
ASSERT_EQ(model_->other_node()->children().size(), 0u);
- const BookmarkNode* folder =
- model_->AddFolder(model_->bookmark_bar_node(), 0, ASCIIToUTF16("Other B"));
+ const BookmarkNode* folder = model_->AddFolder(model_->bookmark_bar_node(), 0,
+ ASCIIToUTF16("Other B"));
model_->AddURL(folder, 0, ASCIIToUTF16("B1"), GURL("https://B1.com"));
BraveMigrateOtherNodeFolder(model_.get());
ASSERT_EQ(model_->bookmark_bar_node()->children().size(), 1u);
@@ -71,4 +71,65 @@ TEST_F(BookmarkModelTest, BraveMigrateOtherNodeFolderNotExist) {
ASSERT_EQ(model_->other_node()->children().size(), 0u);
}
+TEST_F(BookmarkModelTest, BraveClearSyncV1MetaInfo_PermanentNodes) {
+ AsMutable(model_->bookmark_bar_node())->SetMetaInfo("order", "1.0.1");
+ AsMutable(model_->other_node())->SetMetaInfo("order", "1.0.2");
+
+ BraveClearSyncV1MetaInfo(model_.get());
+
+ ASSERT_EQ(model_->bookmark_bar_node()->GetMetaInfoMap(), nullptr);
+ ASSERT_EQ(model_->other_node()->GetMetaInfoMap(), nullptr);
+}
+
+TEST_F(BookmarkModelTest, BraveClearSyncV1MetaInfo) {
+ BookmarkNode::MetaInfoMap meta_info_map;
+ meta_info_map["object_id"] = "object_id_value";
+ meta_info_map["order"] = "order_value";
+ meta_info_map["parent_object_id"] = "parent_object_id_value";
+ meta_info_map["position_in_parent"] = "position_in_parent_value";
+ meta_info_map["sync_timestamp"] = "sync_timestamp_value";
+ meta_info_map["version"] = "version_value";
+ meta_info_map["originator_cache_guid"] = "originator_cache_guid_value";
+ meta_info_map["originator_client_item_id"] =
+ "originator_client_item_id_value";
+ meta_info_map["mtime"] = "mtime_value";
+ meta_info_map["ctime"] = "ctime_value";
+
+ // -- Bookmarks
+ // |-- A
+ // | |--A1.com
+ // |-- C1.com (The only node contains non related meta info)
+ // -- Other Bookmarks
+ // |-- B
+ // | |--B1.com
+ const BookmarkNode* folder_A = model_->AddFolder(
+ model_->bookmark_bar_node(), 0, ASCIIToUTF16("A"), &meta_info_map);
+ const BookmarkNode* bookmark_A1 = model_->AddURL(
+ folder_A, 0, ASCIIToUTF16("A1"), GURL("https://A1.com"), &meta_info_map);
+ const BookmarkNode* bookmark_C1 = model_->AddURL(
+ folder_A, 1, ASCIIToUTF16("C1"), GURL("https://C1.com"), &meta_info_map);
+ model_->SetNodeMetaInfo(bookmark_C1, "brave_meta", "brave_meta_value");
+ const BookmarkNode* folder_B = model_->AddFolder(
+ model_->other_node(), 0, ASCIIToUTF16("B"), &meta_info_map);
+ const BookmarkNode* bookmark_B1 = model_->AddURL(
+ folder_A, 0, ASCIIToUTF16("B1"), GURL("https://B1.com"), &meta_info_map);
+ ASSERT_NE(folder_A->GetMetaInfoMap(), nullptr);
+ ASSERT_NE(bookmark_A1->GetMetaInfoMap(), nullptr);
+ ASSERT_NE(bookmark_C1->GetMetaInfoMap(), nullptr);
+ ASSERT_NE(folder_B->GetMetaInfoMap(), nullptr);
+ ASSERT_NE(bookmark_B1->GetMetaInfoMap(), nullptr);
+
+ BraveClearSyncV1MetaInfo(model_.get());
+
+ ASSERT_EQ(folder_A->GetMetaInfoMap(), nullptr);
+ ASSERT_EQ(bookmark_A1->GetMetaInfoMap(), nullptr);
+ ASSERT_NE(bookmark_C1->GetMetaInfoMap(), nullptr);
+ ASSERT_EQ(folder_B->GetMetaInfoMap(), nullptr);
+ ASSERT_EQ(bookmark_B1->GetMetaInfoMap(), nullptr);
+
+ std::string brave_meta;
+ ASSERT_TRUE(bookmark_C1->GetMetaInfo("brave_meta", &brave_meta));
+ ASSERT_EQ(brave_meta, "brave_meta_value");
+}
+
} // namespace bookmarks
diff --git a/chromium_src/components/infobars/core/infobar_delegate.h b/chromium_src/components/infobars/core/infobar_delegate.h
index ae0126b8fae0..5541d2cdc841 100644
--- a/chromium_src/components/infobars/core/infobar_delegate.h
+++ b/chromium_src/components/infobars/core/infobar_delegate.h
@@ -9,7 +9,8 @@
#define BRAVE_INFOBAR_DELEGATE_IDENTIFIERS \
BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE = 500, \
CRYPTO_WALLETS_INFOBAR_DELEGATE = 501, \
- WAYBACK_MACHINE_INFOBAR_DELEGATE = 502,
+ WAYBACK_MACHINE_INFOBAR_DELEGATE = 502, \
+ SYNC_V2_MIGRATE_INFOBAR_DELEGATE = 503,
#include "../../../../../components/infobars/core/infobar_delegate.h"
diff --git a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc
deleted file mode 100644
index 3dd9346e6a27..000000000000
--- a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include
-
-#include "brave/components/brave_sync/buildflags/buildflags.h"
-#include "components/sync/driver/glue/sync_engine_impl.h"
-#include "components/sync/engine/sync_engine_host.h"
-
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-#include "base/memory/weak_ptr.h"
-#include "brave/components/brave_sync/jslib_messages.h"
-#include "brave/components/brave_sync/public/brave_profile_sync_service.h"
-
-using brave_sync::BraveProfileSyncService;
-using brave_sync::GetRecordsCallback;
-using brave_sync::RecordsList;
-#endif
-
-namespace syncer {
-
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-SyncEngineHost* BraveGetSyncEngineHost(SyncEngineImpl* sync_engine) {
- return sync_engine->host_;
-}
-
-void OnNudgeSyncCycleOnOwnerThread(base::WeakPtr sync_engine,
- brave_sync::RecordsListPtr records_list) {
- if (sync_engine.get())
- static_cast(
- BraveGetSyncEngineHost(sync_engine.get()))
- ->OnNudgeSyncCycle(std::move(records_list));
-}
-
-void OnNudgeSyncCycle(WeakHandle sync_engine_impl,
- brave_sync::RecordsListPtr records_list) {
- sync_engine_impl.Call(FROM_HERE, &OnNudgeSyncCycleOnOwnerThread,
- base::Passed(&records_list));
-}
-
-void OnPollSyncCycleOnOwnerThread(base::WeakPtr sync_engine,
- GetRecordsCallback cb,
- base::WaitableEvent* wevent) {
- if (sync_engine.get())
- static_cast(
- BraveGetSyncEngineHost(sync_engine.get()))
- ->OnPollSyncCycle(std::move(cb), wevent);
-}
-
-void OnPollSyncCycle(WeakHandle sync_engine_impl,
- GetRecordsCallback cb,
- base::WaitableEvent* wevent) {
- sync_engine_impl.Call(FROM_HERE, &OnPollSyncCycleOnOwnerThread,
- base::Passed(&cb), wevent);
-}
-#endif
-
-void BraveInit(WeakHandle sync_engine_impl,
- SyncManager::InitArgs* args) {
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- DCHECK(args);
- args->nudge_sync_cycle_delegate_function =
- base::BindRepeating(&OnNudgeSyncCycle, sync_engine_impl);
- args->poll_sync_cycle_delegate_function =
- base::BindRepeating(&OnPollSyncCycle, sync_engine_impl);
-#endif
-}
-
-} // namespace syncer
-
-#define BRAVE_SYNC_ENGINE_BACKEND_DO_INITIALIZE BraveInit(host_, &args);
-
-#include "../../../../../../components/sync/driver/glue/sync_engine_backend.cc" // NOLINT
diff --git a/chromium_src/components/sync/driver/glue/sync_engine_impl.h b/chromium_src/components/sync/driver/glue/sync_engine_impl.h
deleted file mode 100644
index 98a3c9aa9129..000000000000
--- a/chromium_src/components/sync/driver/glue/sync_engine_impl.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_IMPL_H_
-#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_IMPL_H_
-
-#define BRAVE_SYNC_ENGINE_IMPL_H \
- friend SyncEngineHost* BraveGetSyncEngineHost(SyncEngineImpl*);
-
-#include "../../../../../../components/sync/driver/glue/sync_engine_impl.h" // NOLINT
-#undef BRAVE_SYNC_ENGINE_IMPL_H
-#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_IMPL_H_
diff --git a/chromium_src/components/sync/driver/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc
index 5b995a855e87..3294af74afa3 100644
--- a/chromium_src/components/sync/driver/profile_sync_service.cc
+++ b/chromium_src/components/sync/driver/profile_sync_service.cc
@@ -1,81 +1,49 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "brave/chromium_src/components/sync/driver/profile_sync_service.h"
+#include "brave/components/brave_sync/brave_sync_prefs.h"
+#include "components/prefs/pref_service.h"
+
+#include "brave/components/sync/driver/brave_sync_auth_manager.h"
+
+#define BRAVE_PROFILE_SYNC_SERVICE \
+ brave_sync_prefs_change_registrar_.Init(sync_client_->GetPrefService()); \
+ brave_sync_prefs_change_registrar_.Add( \
+ brave_sync::Prefs::GetSeedPath(), \
+ base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, \
+ base::Unretained(this))); \
+ brave_sync::Prefs brave_sync_prefs(sync_client_->GetPrefService()); \
+ auth_manager_->DeriveSigningKeys(brave_sync_prefs.GetSeed()); \
+ if (!brave_sync_prefs.IsSyncV1Migrated()) { \
+ StopImpl(CLEAR_DATA); \
+ brave_sync_prefs.SetSyncV1Migrated(true); \
+ }
-#include
+#define BRAVE_D_PROFILE_SYNC_SERVICE \
+ brave_sync_prefs_change_registrar_.RemoveAll();
-#include "brave/components/brave_sync/buildflags/buildflags.h"
+#define SyncAuthManager BraveSyncAuthManager
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-#include "base/bind.h"
-#include "base/memory/weak_ptr.h"
-#include "brave/components/brave_sync/jslib_messages.h"
-#include "brave/components/brave_sync/public/brave_profile_sync_service.h"
-#include "chrome/browser/sync/chrome_sync_client.h"
-#include "content/public/browser/browser_thread.h"
+#include "../../../../../components/sync/driver/profile_sync_service.cc"
-using brave_sync::BraveProfileSyncService;
-#endif
+#undef BRAVE_PROFILE_SYNC_SERVICE
+#undef BRAVE_D_PROFILE_SYNC_SERVICE
+#undef SyncAuthManager
namespace syncer {
-
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-const int64_t kBraveDefaultPollIntervalSeconds = 60;
-
-bool IsBraveSyncEnabled(ProfileSyncService* profile_sync_service) {
- return static_cast(profile_sync_service)
- ->IsBraveSyncEnabled();
-}
-
-void OnNudgeSyncCycle(base::WeakPtr profile_sync_service,
- brave_sync::RecordsListPtr records_list) {
- if (profile_sync_service.get()) {
- static_cast(profile_sync_service.get())
- ->OnNudgeSyncCycle(std::move(records_list));
- }
-}
-
-void OnPollSyncCycle(base::WeakPtr profile_sync_service,
- brave_sync::GetRecordsCallback cb,
- base::WaitableEvent* wevent) {
- if (profile_sync_service.get()) {
- static_cast(profile_sync_service.get())
- ->OnPollSyncCycle(std::move(cb), wevent);
+void ProfileSyncService::OnBraveSyncPrefsChanged(const std::string& path) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ if (path == brave_sync::Prefs::GetSeedPath()) {
+ brave_sync::Prefs brave_sync_prefs(sync_client_->GetPrefService());
+ const std::string seed = brave_sync_prefs.GetSeed();
+ if (!seed.empty()) {
+ auth_manager_->DeriveSigningKeys(seed);
+ } else {
+ VLOG(1) << "Brave sync seed cleared";
+ auth_manager_->ResetKeys();
+ }
}
}
-#endif
-
-void BraveInit(base::WeakPtr profile_sync_service,
- SyncPrefs* sync_prefs,
- syncer::SyncEngine::InitParams* params) {
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
- DCHECK(params);
- params->nudge_sync_cycle_delegate_function =
- base::BindRepeating(&OnNudgeSyncCycle, profile_sync_service);
- params->poll_sync_cycle_delegate_function =
- base::BindRepeating(&OnPollSyncCycle, profile_sync_service);
-
- sync_prefs->SetPollInterval(
- base::TimeDelta::FromSeconds(syncer::kBraveDefaultPollIntervalSeconds));
-#endif
-}
-
} // namespace syncer
-
-// avoid redefining IsSyncFeatureEnabled in header
-#include "components/sync/driver/sync_service.h"
-// For use_transport_only_mode
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-#define IsSyncFeatureEnabled() IsBraveSyncEnabled(this)
-#endif
-#define BRAVE_PROFILE_SYNC_SERVICE_START_UP_SLOW_ENGINE_COMPONENTS \
- BraveInit(sync_enabled_weak_factory_.GetWeakPtr(), &sync_prefs_, ¶ms);
-
-#include "../../../../components/sync/driver/profile_sync_service.cc" // NOLINT
-#undef BRAVE_PROFILE_SYNC_SERVICE_START_UP_SLOW_ENGINE_COMPONENTS
-#if BUILDFLAG(ENABLE_BRAVE_SYNC)
-#undef IsSyncFeatureEnabled
-#endif
diff --git a/chromium_src/components/sync/driver/profile_sync_service.h b/chromium_src/components/sync/driver/profile_sync_service.h
index e516f8872b60..a7f0d9d209cc 100644
--- a/chromium_src/components/sync/driver/profile_sync_service.h
+++ b/chromium_src/components/sync/driver/profile_sync_service.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -6,14 +6,24 @@
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_
#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_
-namespace brave_sync {
-class BraveProfileSyncServiceImpl;
-} // namespace brave_sync
+#include "components/prefs/pref_change_registrar.h"
+// Header guard to prevent Initialize from getting overriden in it
+// ============================================================================
+#include "components/sync/base/sync_prefs.h"
+#include "components/sync/driver/sync_service_crypto.h"
+// ============================================================================
-#define BRAVE_PROFILE_SYNC_SERVICE_H \
- friend class brave_sync::BraveProfileSyncServiceImpl;
+
+#define BRAVE_PROFILE_SYNC_SERVICE_H_ \
+ private: \
+ PrefChangeRegistrar brave_sync_prefs_change_registrar_;
+
+#define Initialize \
+ OnBraveSyncPrefsChanged(const std::string& path); \
+ void Initialize
#include "../../../../../components/sync/driver/profile_sync_service.h"
-#undef BRAVE_PROFILE_SYNC_SERVICE_H
+#undef BRAVE_PROFILE_SYNC_SERVICE_H_
+#undef Initialize
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_
diff --git a/chromium_src/components/sync/driver/sync_auth_manager.h b/chromium_src/components/sync/driver/sync_auth_manager.h
new file mode 100644
index 000000000000..82fa997ebecc
--- /dev/null
+++ b/chromium_src/components/sync/driver/sync_auth_manager.h
@@ -0,0 +1,27 @@
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_SYNC_AUTH_MANAGER_H_
+#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_SYNC_AUTH_MANAGER_H_
+
+namespace syncer {
+class BraveSyncAuthManager;
+} // namespace syncer
+
+// Header guard to prevent DetermineAccountToUse from getting overriden in it
+#include "components/sync/driver/sync_auth_util.h"
+
+#define RequestAccessToken virtual RequestAccessToken
+#define DetermineAccountToUse \
+ DetermineAccountToUse_Unused() { return SyncAccountInfo(); } \
+ friend BraveSyncAuthManager; \
+ virtual SyncAccountInfo DetermineAccountToUse
+
+#include "../../../../../components/sync/driver/sync_auth_manager.h"
+
+#undef BRAVE_SYNC_AUTH_MANAGER_H_
+#undef RequestAccessToken
+#undef DetermineAccountToUse
+#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_SYNC_AUTH_MANAGER_H_
diff --git a/chromium_src/components/sync/driver/sync_stopped_reporter.cc b/chromium_src/components/sync/driver/sync_stopped_reporter.cc
new file mode 100644
index 000000000000..d9ccbf00ed0d
--- /dev/null
+++ b/chromium_src/components/sync/driver/sync_stopped_reporter.cc
@@ -0,0 +1,13 @@
+/* Copyright (c) 2020 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#define BRAVE_REPORT_SYNC_STOPPED \
+ std::string headers; \
+ headers = "Authorization: Bearer " + access_token; \
+ resource_request->headers.AddHeadersFromString(headers.c_str());
+
+#include "../../../../../components/sync/driver/sync_stopped_reporter.cc"
+
+#undef BRAVE_REPORT_SYNC_STOPPED
diff --git a/chromium_src/components/sync/engine/sync_engine.h b/chromium_src/components/sync/engine/sync_engine.h
deleted file mode 100644
index 2b27b9836498..000000000000
--- a/chromium_src/components/sync/engine/sync_engine.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_SYNC_ENGINE_H_
-#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_SYNC_ENGINE_H_
-
-#include "brave/components/brave_sync/jslib_messages_fwd.h"
-
-#define BRAVE_SYNC_ENGINE_INIT_PARAMS_H \
- brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; \
- brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function;
-
-#include "../../../../../components/sync/engine/sync_engine.h"
-#undef BRAVE_SYNC_ENGINE_INIT_PARAMS_H
-
-#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_SYNC_ENGINE_H_
diff --git a/chromium_src/components/sync/engine/sync_manager.h b/chromium_src/components/sync/engine/sync_manager.h
deleted file mode 100644
index cd0a9e821e36..000000000000
--- a/chromium_src/components/sync/engine/sync_manager.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_SYNC_MANAGER_H_
-#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_SYNC_MANAGER_H_
-
-#include "brave/components/brave_sync/jslib_messages_fwd.h"
-
-namespace syncer {
-class Syncer;
-} // namespace syncer
-
-#define BRAVE_SYNC_MANAGER_INIT_ARGS_H \
- brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; \
- brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function;
-
-#include "../../../../../components/sync/engine/sync_manager.h"
-#undef BRAVE_SYNC_MANAGER_INIT_ARGS_H
-
-#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_SYNC_MANAGER_H_
diff --git a/chromium_src/components/sync/engine_impl/commit.cc b/chromium_src/components/sync/engine_impl/commit.cc
deleted file mode 100644
index 19ed5eb726d5..000000000000
--- a/chromium_src/components/sync/engine_impl/commit.cc
+++ /dev/null
@@ -1,193 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-namespace sync_pb {
-class ClientToServerMessage;
-class ClientToServerResponse;
-} // namespace sync_pb
-
-namespace syncer {
-class SyncCycle;
-class SyncerError;
-namespace {
-
-SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message,
- sync_pb::ClientToServerResponse* response,
- SyncCycle* cycle);
-}
-
-} // namespace syncer
-
-#define BRAVE_COMMIT_POST_AND_PROCESS_RESPONSE \
- PostBraveCommit(&message_, &response, cycle);
-
-#include "../../../../../components/sync/engine_impl/commit.cc" // NOLINT
-#undef BRAVE_COMMIT_POST_AND_PROCESS_RESPONSE
-
-#include "base/base64.h"
-#include "brave/components/brave_sync/jslib_const.h"
-#include "brave/components/brave_sync/jslib_messages.h"
-#include "brave/components/brave_sync/jslib_messages_fwd.h"
-#include "brave/components/brave_sync/tools.h"
-#include "components/sync/base/time.h"
-#include "components/sync/base/unique_position.h"
-
-namespace syncer {
-namespace {
-using brave_sync::jslib::MetaInfo;
-using brave_sync::jslib::SyncRecord;
-// from components/sync_bookmarks/bookmark_model_merger.cc
-const char kOtherBookmarksTag[] = "other_bookmarks";
-
-void CreateSuccessfulCommitResponse(
- const sync_pb::SyncEntity& entity,
- sync_pb::CommitResponse::EntryResponse* response,
- const std::string& new_object_id) {
- response->set_response_type(sync_pb::CommitResponse::SUCCESS);
- response->set_non_unique_name(entity.name());
- response->set_version(entity.version() + 1);
- response->set_parent_id_string(entity.parent_id_string());
-
- if (new_object_id.empty())
- response->set_id_string(entity.id_string());
- else
- response->set_id_string(new_object_id);
-}
-
-std::unique_ptr CreateOtherBookmarksRecord(SyncRecord* child) {
- auto record = std::make_unique();
- record->objectData = brave_sync::jslib_const::SyncObjectData_BOOKMARK;
- auto bookmark = std::make_unique();
- bookmark->site.title = brave_sync::tools::kOtherNodeName;
- bookmark->site.customTitle = brave_sync::tools::kOtherNodeName;
- // Special order reserved for "Other Bookmarks" folder, it only has effect on
- // mobile. On desktop, it is used to distinguish "Other Bookmarks" from normal
- // same name folder
- bookmark->order = brave_sync::tools::kOtherNodeOrder;
- bookmark->site.creationTime = child->GetBookmark().site.creationTime;
- bookmark->isFolder = true;
-
- DCHECK(child->has_bookmark());
- record->objectId = child->GetBookmark().parentFolderObjectId;
- record->action = brave_sync::jslib::SyncRecord::Action::A_CREATE;
- record->syncTimestamp = child->syncTimestamp;
- record->SetBookmark(std::move(bookmark));
-
- return record;
-}
-
-brave_sync::RecordsListPtr ConvertCommitsToBraveRecords(
- sync_pb::ClientToServerMessage* message,
- sync_pb::ClientToServerResponse* response) {
- brave_sync::RecordsListPtr record_list =
- std::make_unique();
- const sync_pb::CommitMessage& commit_message = message->commit();
- const std::string cache_guid = commit_message.cache_guid();
- bool other_bookmarks_record_created = false;
- for (int i = 0; i < commit_message.entries_size(); ++i) {
- sync_pb::SyncEntity entity = commit_message.entries(i);
- std::string new_object_id;
- if (entity.specifics().has_bookmark()) {
- const sync_pb::BookmarkSpecifics& bm_specifics =
- entity.specifics().bookmark();
-
- auto record = std::make_unique();
- record->objectData = brave_sync::jslib_const::SyncObjectData_BOOKMARK;
-
- auto bookmark = std::make_unique();
- bookmark->site.location = bm_specifics.url();
- bookmark->site.title = bm_specifics.legacy_canonicalized_title();
- bookmark->site.customTitle = bm_specifics.legacy_canonicalized_title();
- // bookmark->site.lastAccessedTime - ignored
- bookmark->site.creationTime =
- ProtoTimeToTime(bm_specifics.creation_time_us());
- bookmark->site.favicon = bm_specifics.icon_url();
- bookmark->isFolder = entity.folder();
- // only matters for direct children of permanent nodes
- bookmark->hideInToolbar = entity.parent_id_string() == kOtherBookmarksTag;
-
- bool skip_record = false;
- for (int i = 0; i < bm_specifics.meta_info_size(); ++i) {
- if (bm_specifics.meta_info(i).key() == "order") {
- bookmark->order = bm_specifics.meta_info(i).value();
- } else if (bm_specifics.meta_info(i).key() == "object_id") {
- new_object_id = bm_specifics.meta_info(i).value();
- } else if (bm_specifics.meta_info(i).key() == "parent_object_id") {
- bookmark->parentFolderObjectId = bm_specifics.meta_info(i).value();
- } else if (bm_specifics.meta_info(i).key() == "sync_timestamp") {
- record->syncTimestamp = base::Time::FromJsTime(
- std::stod(bm_specifics.meta_info(i).value()));
- } else if (bm_specifics.meta_info(i).key() == "last_send_time" &&
- entity.version() == 0) {
- // Upgrade from legacy code, we need to prevent sending duplicate
- // records which are already on sync chain
- skip_record = true;
- }
- }
-
- int64_t version = entity.version();
- if (entity.version() == 0) {
- record->objectId = new_object_id;
- record->action = brave_sync::jslib::SyncRecord::Action::A_CREATE;
- } else {
- record->objectId = entity.id_string();
- if (entity.deleted())
- record->action = brave_sync::jslib::SyncRecord::Action::A_DELETE;
- else
- record->action = brave_sync::jslib::SyncRecord::Action::A_UPDATE;
- }
-
- if (entity.deleted() && entity.version() == 0 &&
- record->objectId.empty()) {
- // This is for recover profile after crash with duplicated object ids
- // When doing delete of duplicated bookmark, pretend it has a new
- // object id to got through nudge/pull cycle
- // We are ok, if other devices would get this record, because they have
- // nothing to delete in fact
- record->objectId = brave_sync::tools::GenerateObjectId();
- record->action = brave_sync::jslib::SyncRecord::Action::A_DELETE;
- }
-
- DCHECK(!record->objectId.empty());
-
- MetaInfo metaInfo;
-
- metaInfo.key = "version";
- metaInfo.value = std::to_string(version);
- bookmark->metaInfo.push_back(metaInfo);
-
- metaInfo.key = "position_in_parent";
- metaInfo.value = std::to_string(entity.position_in_parent());
- bookmark->metaInfo.push_back(metaInfo);
-
- record->SetBookmark(std::move(bookmark));
-
- if (!other_bookmarks_record_created &&
- entity.parent_id_string() == kOtherBookmarksTag) {
- record_list->push_back(CreateOtherBookmarksRecord(record.get()));
- other_bookmarks_record_created = true;
- }
- if (!skip_record)
- record_list->push_back(std::move(record));
- }
- sync_pb::CommitResponse_EntryResponse* entry_response =
- response->mutable_commit()->add_entryresponse();
- CreateSuccessfulCommitResponse(entity, entry_response, new_object_id);
- }
- return record_list;
-}
-
-SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message,
- sync_pb::ClientToServerResponse* response,
- SyncCycle* cycle) {
- brave_sync::RecordsListPtr records_list =
- ConvertCommitsToBraveRecords(message, response);
- cycle->delegate()->OnNudgeSyncCycle(std::move(records_list));
-
- return SyncerError(SyncerError::SYNCER_OK);
-}
-
-} // namespace
-} // namespace syncer
diff --git a/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h b/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h
deleted file mode 100644
index 2437341a63cc..000000000000
--- a/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
-#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
-
-#include "brave/components/brave_sync/jslib_messages_fwd.h"
-
-#define BRAVE_SYNC_CYCLE_DELEGATE_H \
- virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) {} \
- virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, \
- base::WaitableEvent* wevent) {}
-
-#include "../../../../../../components/sync/engine_impl/cycle/sync_cycle.h"
-#undef BRAVE_SYNC_CYCLE_DELEGATE_H
-
-#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc
deleted file mode 100644
index 7a2849c757f9..000000000000
--- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc
+++ /dev/null
@@ -1,260 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "components/sync/engine_impl/get_updates_processor.h"
-
-#include
-#include
-#include
-#include
-
-namespace syncer {
-namespace {
-SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*,
- ModelTypeSet*,
- std::unique_ptr);
-} // namespace
-} // namespace syncer
-
-#include "../../../../../components/sync/engine_impl/get_updates_processor.cc" // NOLINT
-#include "base/base64.h"
-#include "base/guid.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/time/time.h"
-#include "brave/components/brave_sync/jslib_messages.h"
-#include "components/sync/base/hash_util.h"
-#include "components/sync/base/system_encryptor.h"
-#include "components/sync/base/time.h"
-#include "components/sync/engine_impl/loopback_server/loopback_server_entity.h"
-#include "components/sync/syncable/directory_cryptographer.h"
-#include "components/sync/syncable/syncable_proto_util.h"
-#include "url/gurl.h"
-
-namespace syncer {
-namespace {
-
-using brave_sync::jslib::Bookmark;
-using brave_sync::jslib::SyncRecord;
-using syncable::Id;
-static const char kBookmarkBarFolderServerTag[] = "bookmark_bar";
-static const char kBookmarkBarFolderName[] = "Bookmark Bar";
-static const char kOtherBookmarksFolderServerTag[] = "other_bookmarks";
-static const char kOtherBookmarksFolderName[] = "Other Bookmarks";
-static const char kSyncedBookmarksFolderServerTag[] = "synced_bookmarks";
-static const char kSyncedBookmarksFolderName[] = "Synced Bookmarks";
-// The parent tag for children of the root entity. Entities with this parent are
-// referred to as top level enities.
-static const char kRootParentTag[] = "0";
-
-void AddBookmarkSpecifics(sync_pb::EntitySpecifics* specifics,
- const SyncRecord* record) {
- DCHECK(specifics);
- auto bookmark = record->GetBookmark();
- sync_pb::BookmarkSpecifics* bm_specifics = specifics->mutable_bookmark();
- bm_specifics->set_url(bookmark.site.location);
-
- bm_specifics->set_legacy_canonicalized_title(
- bookmark.site.TryGetNonEmptyTitle());
- bm_specifics->set_creation_time_us(
- TimeToProtoTime(bookmark.site.creationTime));
- // base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds());
- sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info();
- meta_info->set_key("order");
- meta_info->set_value(bookmark.order);
- // For GetExistingObjects lookup
- meta_info = bm_specifics->add_meta_info();
- meta_info->set_key("object_id");
- meta_info->set_value(record->objectId);
- meta_info = bm_specifics->add_meta_info();
- meta_info->set_key("parent_object_id");
- meta_info->set_value(bookmark.parentFolderObjectId);
- meta_info = bm_specifics->add_meta_info();
- meta_info->set_key("sync_timestamp");
- meta_info->set_value(std::to_string(record->syncTimestamp.ToJsTime()));
-}
-
-void ExtractBookmarkMeta(sync_pb::SyncEntity* entity,
- sync_pb::EntitySpecifics* specifics,
- const Bookmark& bookmark) {
- sync_pb::BookmarkSpecifics* bm_specifics = specifics->mutable_bookmark();
- for (const auto& metaInfo : bookmark.metaInfo) {
- // version need to be incremented
- if (metaInfo.key != "version") {
- sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info();
- meta_info->set_key(metaInfo.key);
- meta_info->set_value(metaInfo.value);
- }
- if (metaInfo.key == "version") {
- int64_t version;
- bool result = base::StringToInt64(metaInfo.value, &version);
- DCHECK(result);
- entity->set_version(++version);
- sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info();
- meta_info->set_key(metaInfo.key);
- meta_info->set_value(std::to_string(version));
- } else if (metaInfo.key == "position_in_parent") {
- int64_t position_in_parent;
- bool result = base::StringToInt64(metaInfo.value, &position_in_parent);
- DCHECK(result);
- entity->set_position_in_parent(position_in_parent);
- }
- }
- DCHECK(entity->has_version());
-}
-
-void MigrateFromLegacySync(sync_pb::SyncEntity* entity) {
- if (!entity->has_position_in_parent()) {
- entity->set_position_in_parent(0);
- }
-}
-
-void AddRootForType(sync_pb::SyncEntity* entity, ModelType type) {
- DCHECK(entity);
- sync_pb::EntitySpecifics specifics;
- AddDefaultFieldValue(type, &specifics);
- std::string server_tag = ModelTypeToRootTag(type);
- std::string name = syncer::ModelTypeToString(type);
- std::string id = LoopbackServerEntity::GetTopLevelId(type);
- entity->set_server_defined_unique_tag(server_tag);
- entity->set_id_string(id);
- entity->set_parent_id_string(kRootParentTag);
- entity->set_name(name);
- entity->set_version(1);
- entity->set_folder(true);
- entity->mutable_specifics()->CopyFrom(specifics);
-}
-
-void AddPermanentNode(sync_pb::SyncEntity* entity,
- const std::string& name,
- const std::string& tag) {
- DCHECK(entity);
- sync_pb::EntitySpecifics specifics;
- AddDefaultFieldValue(BOOKMARKS, &specifics);
- std::string parent = ModelTypeToRootTag(BOOKMARKS);
- std::string id = tag;
- std::string parent_id = LoopbackServerEntity::CreateId(BOOKMARKS, parent);
- entity->set_server_defined_unique_tag(tag);
- entity->set_id_string(id);
- entity->set_parent_id_string(parent_id);
- entity->set_name(name);
- entity->set_folder(true);
- entity->set_version(1);
- entity->mutable_specifics()->CopyFrom(specifics);
-}
-
-void AddBookmarkNode(sync_pb::SyncEntity* entity, const SyncRecord* record) {
- DCHECK(entity);
- DCHECK(record);
- DCHECK(record->has_bookmark());
- DCHECK(!record->objectId.empty());
-
- auto bookmark_record = record->GetBookmark();
-
- sync_pb::EntitySpecifics specifics;
- AddDefaultFieldValue(BOOKMARKS, &specifics);
- entity->set_id_string(record->objectId);
- if (!bookmark_record.parentFolderObjectId.empty()) {
- // parentFolderObjectId is used for mobile to treat "Other Bookmarks" as
- // normal folder
- if (bookmark_record.hideInToolbar)
- entity->set_parent_id_string(std::string(kOtherBookmarksFolderServerTag));
- else
- entity->set_parent_id_string(bookmark_record.parentFolderObjectId);
- } else {
- entity->set_parent_id_string(std::string(kBookmarkBarFolderServerTag));
- }
- entity->set_non_unique_name(bookmark_record.site.TryGetNonEmptyTitle());
- entity->set_folder(bookmark_record.isFolder);
-
- ExtractBookmarkMeta(entity, &specifics, bookmark_record);
-
- MigrateFromLegacySync(entity);
-
- if (record->action == SyncRecord::Action::A_DELETE)
- entity->set_deleted(true);
- else
- AddBookmarkSpecifics(&specifics, record);
- entity->mutable_specifics()->CopyFrom(specifics);
-}
-
-void ConstructUpdateResponse(sync_pb::GetUpdatesResponse* gu_response,
- ModelTypeSet* request_types,
- std::unique_ptr records) {
- DCHECK(gu_response);
- DCHECK(request_types);
- for (ModelType type : *request_types) {
- sync_pb::DataTypeProgressMarker* marker =
- gu_response->add_new_progress_marker();
- marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(type));
- marker->set_token("token");
- if (type == BOOKMARKS) {
- google::protobuf::RepeatedPtrField entities;
- AddRootForType(entities.Add(), BOOKMARKS);
- AddPermanentNode(entities.Add(), kBookmarkBarFolderName,
- kBookmarkBarFolderServerTag);
- AddPermanentNode(entities.Add(), kOtherBookmarksFolderName,
- kOtherBookmarksFolderServerTag);
- // required since 84f01c4c006cf89941138f3591db129a5b3cde54
- AddPermanentNode(entities.Add(), kSyncedBookmarksFolderName,
- kSyncedBookmarksFolderServerTag);
- if (records) {
- for (const auto& record : *records.get()) {
- AddBookmarkNode(entities.Add(), record.get());
- }
- }
- std::copy(entities.begin(), entities.end(),
- RepeatedPtrFieldBackInserter(gu_response->mutable_entries()));
- } else if (type == NIGORI) {
- google::protobuf::RepeatedPtrField entities;
- sync_pb::EntitySpecifics specifics;
- AddDefaultFieldValue(NIGORI, &specifics);
- sync_pb::SyncEntity* entity = entities.Add();
- AddRootForType(entity, NIGORI);
- sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
- nigori->set_encrypt_everything(false);
- nigori->set_encrypt_bookmarks(false);
- syncer::DirectoryCryptographer cryptographer;
- KeyParams params = {KeyDerivationParams::CreateForPbkdf2(), "foobar"};
- syncer::KeyDerivationMethod method = params.derivation_params.method();
- bool add_key_result = cryptographer.AddKey(params);
- DCHECK(add_key_result);
- bool get_keys_result =
- cryptographer.GetKeys(nigori->mutable_encryption_keybag());
- DCHECK(get_keys_result);
- nigori->set_keybag_is_frozen(true);
- nigori->set_keystore_migration_time(1U);
- nigori->set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE);
- nigori->set_custom_passphrase_key_derivation_method(
- EnumKeyDerivationMethodToProto(method));
- entity->mutable_specifics()->CopyFrom(specifics);
-
- std::copy(entities.begin(), entities.end(),
- RepeatedPtrFieldBackInserter(gu_response->mutable_entries()));
- }
- }
- gu_response->set_changes_remaining(0);
- gu_response->add_encryption_keys("dummy_encryption_key");
-}
-
-SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse* update_response,
- ModelTypeSet* request_types,
- std::unique_ptr records) {
- DCHECK(update_response);
- DCHECK(request_types);
- sync_pb::GetUpdatesResponse* gu_response = new sync_pb::GetUpdatesResponse();
- ConstructUpdateResponse(gu_response, request_types, std::move(records));
- update_response->set_allocated_get_updates(gu_response);
- return SyncerError(SyncerError::SYNCER_OK);
-}
-
-} // namespace
-
-void GetUpdatesProcessor::AddBraveRecords(
- std::unique_ptr records) {
- brave_records_ = std::move(records);
-}
-
-} // namespace syncer
diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.h b/chromium_src/components/sync/engine_impl/get_updates_processor.h
deleted file mode 100644
index e70f42654ad1..000000000000
--- a/chromium_src/components/sync/engine_impl/get_updates_processor.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_GET_UPDATES_PROCESSOR_H_
-#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_GET_UPDATES_PROCESSOR_H_
-
-#include "brave/components/brave_sync/jslib_messages_fwd.h"
-
-namespace syncer {
-using brave_sync::RecordsList;
-} // namespace syncer
-
-#define BRAVE_GET_UPDATES_PROCESSOR_H \
- public: \
- void AddBraveRecords(std::unique_ptr records); \
- \
- private: \
- std::unique_ptr brave_records_;
-
-#include "../../../../../components/sync/engine_impl/get_updates_processor.h"
-#undef BRAVE_GET_UPDATES_PROCESSOR_H
-
-#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_GET_UPDATES_PROCESSOR_H_
diff --git a/chromium_src/components/sync/engine_impl/process_updates_util.cc b/chromium_src/components/sync/engine_impl/process_updates_util.cc
deleted file mode 100644
index d6fc2f67e126..000000000000
--- a/chromium_src/components/sync/engine_impl/process_updates_util.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-// TODO(darkdh): investigate the records flow causing object id not applied to
-// local entry in CommitResponse
-
-#define BRAVE_PROCESS_UPDATE \
- DCHECK(false) << "Brave object id " << server_id \
- << " is not applied to local id " << local_id; \
- return;
-
-#include "../../../../../components/sync/engine_impl/process_updates_util.cc" // NOLINT
-#undef BRAVE_PROCESS_UPDATE
diff --git a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc
deleted file mode 100644
index 3c3fafb9487f..000000000000
--- a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "components/sync/engine_impl/sync_scheduler_impl.h"
-
-#define BRAVE_SYNC_MANAGER_IMPL_INIT \
- static_cast(scheduler_.get()) \
- ->nudge_sync_cycle_delegate_function_ = \
- args->nudge_sync_cycle_delegate_function; \
- static_cast(scheduler_.get()) \
- ->poll_sync_cycle_delegate_function_ = \
- args->poll_sync_cycle_delegate_function;
-
-#include "../../../../../components/sync/engine_impl/sync_manager_impl.cc" // NOLINT
-#undef BRAVE_SYNC_MANAGER_IMPL_INIT
diff --git a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc
deleted file mode 100644
index beab44e2497a..000000000000
--- a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "components/sync/engine_impl/sync_scheduler_impl.h"
-
-#include "brave/components/brave_sync/jslib_messages.h"
-
-namespace syncer {
-
-void SyncSchedulerImpl::OnNudgeSyncCycle(
- brave_sync::RecordsListPtr records_list) {
- DCHECK(nudge_sync_cycle_delegate_function_);
- nudge_sync_cycle_delegate_function_.Run(std::move(records_list));
-}
-
-void SyncSchedulerImpl::OnPollSyncCycle(brave_sync::GetRecordsCallback cb,
- base::WaitableEvent* wevent) {
- DCHECK(poll_sync_cycle_delegate_function_);
- poll_sync_cycle_delegate_function_.Run(std::move(cb), wevent);
-}
-
-} // namespace syncer
-
-#define BRAVE_SYNC_SCHEDULER_IMPL_TRY_SYNC_CYCLE_JOB \
- SyncCycle cycle(cycle_context_, this); \
- if (mode_ != CONFIGURATION_MODE) { \
- syncer_->DownloadBraveRecords(&cycle); \
- }
-
-#include "../../../../../components/sync/engine_impl/sync_scheduler_impl.cc" // NOLINT
diff --git a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.h b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.h
deleted file mode 100644
index 8870a48224bf..000000000000
--- a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_
-#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_
-
-#include "brave/components/brave_sync/jslib_messages_fwd.h"
-
-#define BRAVE_SYNC_SCHEDULER_IMPL_H_ \
- void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; \
- void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, \
- base::WaitableEvent* wevent) override; \
- \
- private: \
- friend class SyncManagerImpl; \
- brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function_; \
- brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function_;
-
-#include "../../../../../components/sync/engine_impl/sync_scheduler_impl.h"
-#undef BRAVE_SYNC_SCHEDULER_IMPL_H_
-
-#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_
diff --git a/chromium_src/components/sync/engine_impl/syncer.cc b/chromium_src/components/sync/engine_impl/syncer.cc
deleted file mode 100644
index e6a97e0ac362..000000000000
--- a/chromium_src/components/sync/engine_impl/syncer.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "brave/chromium_src/components/sync/engine_impl/syncer.h"
-
-#include
-#include
-
-#include "base/bind.h"
-
-#include "../../../../../components/sync/engine_impl/syncer.cc" // NOLINT
-
-namespace syncer {
-
-using brave_sync::GetRecordsCallback;
-using brave_sync::RecordsList;
-
-void Syncer::OnGetRecords(std::unique_ptr records) {
- brave_records_ = std::move(records);
-}
-
-void Syncer::DownloadBraveRecords(SyncCycle* cycle) {
- // syncer will be alive as long as sync is enabled
- brave_records_.reset();
- brave_sync::GetRecordsCallback on_get_records =
- base::BindOnce(&Syncer::OnGetRecords, base::Unretained(this));
- base::WaitableEvent wevent;
- cycle->delegate()->OnPollSyncCycle(std::move(on_get_records), &wevent);
- wevent.Wait();
-}
-
-} // namespace syncer
diff --git a/chromium_src/components/sync/engine_impl/syncer.h b/chromium_src/components/sync/engine_impl/syncer.h
deleted file mode 100644
index e0170fe93c2d..000000000000
--- a/chromium_src/components/sync/engine_impl/syncer.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_
-#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_
-
-#include "brave/components/brave_sync/jslib_messages.h"
-#include "brave/components/brave_sync/jslib_messages_fwd.h"
-
-#define BRAVE_SYNCER_H \
- public: \
- void DownloadBraveRecords(SyncCycle* cycle); \
- \
- private: \
- void OnGetRecords(std::unique_ptr records); \
- std::unique_ptr brave_records_;
-
-#include "../../../../../components/sync/engine_impl/syncer.h"
-#undef BRAVE_SYNCER_H
-
-#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_
diff --git a/chromium_src/components/sync/syncable/write_transaction.cc b/chromium_src/components/sync/syncable/write_transaction.cc
deleted file mode 100644
index 77492bb22fa5..000000000000
--- a/chromium_src/components/sync/syncable/write_transaction.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#define BRAVE_WRITE_TRANSACTION if (close_transaction_)
-#include "../../../../components/sync/syncable/write_transaction.cc" // NOLINT
-#undef BRAVE_WRITE_TRANSACTION
-
-namespace syncer {
-
-WriteTransaction::WriteTransaction(const base::Location& from_here,
- UserShare* share,
- syncable::WriteTransaction* syncable_wr_tr)
- : BaseTransaction(share), transaction_(syncable_wr_tr) {
- close_transaction_ = false;
-}
-
-} // namespace syncer
diff --git a/chromium_src/components/sync/syncable/write_transaction.h b/chromium_src/components/sync/syncable/write_transaction.h
deleted file mode 100644
index b96064e243a2..000000000000
--- a/chromium_src/components/sync/syncable/write_transaction.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SYNCABLE_WRITE_TRANSACTION_H_
-#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SYNCABLE_WRITE_TRANSACTION_H_
-
-#define BRAVE_WRITE_TRANSACTION_H_ \
- WriteTransaction(const base::Location& from_here, UserShare* share, \
- syncable::WriteTransaction* syncable_wr_tr); \
- \
- private: \
- bool close_transaction_ = true;
-
-#include "../../../../../components/sync/syncable/write_transaction.h"
-#undef BRAVE_WRITE_TRANSACTION_H_
-
-#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SYNCABLE_WRITE_TRANSACTION_H_
diff --git a/chromium_src/components/sync_bookmarks/bookmark_model_type_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_model_type_processor.cc
deleted file mode 100644
index 2a2febe25d39..000000000000
--- a/chromium_src/components/sync_bookmarks/bookmark_model_type_processor.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Copyright 2020 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "components/sync_bookmarks/bookmark_model_observer_impl.h"
-
-#include
-
-namespace sync_bookmarks {
-
-class BraveBookmarkModelObserverImpl : public BookmarkModelObserverImpl {
- public:
- // |bookmark_tracker_| must not be null and must outlive this object.
- BraveBookmarkModelObserverImpl(
- const base::RepeatingClosure& nudge_for_commit_closure,
- base::OnceClosure on_bookmark_model_being_deleted_closure,
- SyncedBookmarkTracker* bookmark_tracker)
- : BookmarkModelObserverImpl(
- nudge_for_commit_closure,
- std::move(on_bookmark_model_being_deleted_closure),
- bookmark_tracker) {}
- ~BraveBookmarkModelObserverImpl() override = default;
-
- // BookmarkModelObserver:
- void BookmarkMetaInfoChanged(bookmarks::BookmarkModel* model,
- const bookmarks::BookmarkNode* node) override {}
- void BookmarkNodeFaviconChanged(
- bookmarks::BookmarkModel* model,
- const bookmarks::BookmarkNode* node) override {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BraveBookmarkModelObserverImpl);
-};
-
-} // namespace sync_bookmarks
-
-#define BookmarkModelObserverImpl BraveBookmarkModelObserverImpl
-#include "../../../../components/sync_bookmarks/bookmark_model_type_processor.cc"
-#undef BookmarkModelObserverImpl
diff --git a/chromium_src/components/sync_bookmarks/bookmark_remote_updates_handler.cc b/chromium_src/components/sync_bookmarks/bookmark_remote_updates_handler.cc
deleted file mode 100644
index 153358b7b5b3..000000000000
--- a/chromium_src/components/sync_bookmarks/bookmark_remote_updates_handler.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Copyright 2020 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "brave/components/brave_sync/syncer_helper.h"
-
-#define BRAVE_APPLY_REMOTE_UPDATE true ? brave_sync::GetIndex(new_parent, node):
-
-#define BRAVE_PROCESS_CREATE_1 \
- std::string order; \
- std::string object_id; \
- for (int i = 0; i < update_entity.specifics.bookmark().meta_info_size(); \
- ++i) { \
- if (update_entity.specifics.bookmark().meta_info(i).key() == "order") { \
- order = update_entity.specifics.bookmark().meta_info(i).value(); \
- } else if (update_entity.specifics.bookmark().meta_info(i).key() == \
- "object_id") { \
- object_id = update_entity.specifics.bookmark().meta_info(i).value(); \
- } \
- }
-
-#define BRAVE_PROCESS_CREATE_2 \
- true ? brave_sync::GetIndex(parent_node, order, object_id):
-#include "../../../../components/sync_bookmarks/bookmark_remote_updates_handler.cc"
-#undef BRAVE_APPLY_REMOTE_UPDATE
-#undef BRAVE_PROCESS_CREATE_1
-#undef BRAVE_PROCESS_CREATE_2
diff --git a/chromium_src/components/sync_bookmarks/bookmark_specifics_conversions.cc b/chromium_src/components/sync_bookmarks/bookmark_specifics_conversions.cc
deleted file mode 100644
index 0dfcaf66d748..000000000000
--- a/chromium_src/components/sync_bookmarks/bookmark_specifics_conversions.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Copyright 2020 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "components/sync_bookmarks/bookmark_specifics_conversions.h"
-
-#include "brave/components/brave_sync/syncer_helper.h"
-#define CreateSpecificsFromBookmarkNode \
- CreateSpecificsFromBookmarkNodeChromiumImpl
-#include "../../../../components/sync_bookmarks/bookmark_specifics_conversions.cc"
-#undef CreateSpecificsFromBookmarkNode
-
-namespace sync_bookmarks {
-
-sync_pb::EntitySpecifics CreateSpecificsFromBookmarkNode(
- const bookmarks::BookmarkNode* node,
- bookmarks::BookmarkModel* model,
- bool force_favicon_load,
- bool include_guid) {
- brave_sync::AddBraveMetaInfo(node);
- return CreateSpecificsFromBookmarkNodeChromiumImpl(
- node, model, force_favicon_load, include_guid);
-}
-
-} // namespace sync_bookmarks
diff --git a/chromium_src/net/tools/transport_security_state_generator/input_file_parsers.cc b/chromium_src/net/tools/transport_security_state_generator/input_file_parsers.cc
index 54206e2eb848..dd9c1e43e7b6 100644
--- a/chromium_src/net/tools/transport_security_state_generator/input_file_parsers.cc
+++ b/chromium_src/net/tools/transport_security_state_generator/input_file_parsers.cc
@@ -311,8 +311,12 @@ bool ParseJSON(base::StringPiece json,
// Brave
{ "name": "download.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "laptop-updates.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
+ // TODO(darkdh): remove sync v1 endpoints when Android migrates to v2
{ "name": "sync.brave.com", "mode": "force-https", "policy": "custom", "pins": "brave"},
{ "name": "sync-staging.brave.com", "policy": "custom", "mode": "force-https", "pins": "brave"},
+ { "name": "sync-v2.brave.com", "policy": "custom", "mode": "force-https", "pins": "brave"},
+ { "name": "sync-v2.bravesoftware.com", "policy": "custom", "mode": "force-https", "pins": "brave"},
+ { "name": "sync-v2.brave.software", "policy": "custom", "mode": "force-https", "pins": "brave"},
{ "name": "p3a.brave.com", "policy": "custom", "mode": "force-https", "pins": "brave"},
{ "name": "p3a.bravesoftware.com", "policy": "custom", "mode": "force-https", "pins": "brave"},
{ "name": "p3a-dev.bravesoftware.com", "policy": "custom", "mode": "force-https", "pins": "brave"},
diff --git a/common/extensions/api/BUILD.gn b/common/extensions/api/BUILD.gn
index f47663be92f0..454ee67ad8d5 100644
--- a/common/extensions/api/BUILD.gn
+++ b/common/extensions/api/BUILD.gn
@@ -1,5 +1,4 @@
import("//brave/components/binance/browser/buildflags/buildflags.gni")
-import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
import("//brave/components/brave_together/buildflags/buildflags.gni")
import("//tools/grit/grit_rule.gni")
@@ -62,10 +61,6 @@ brave_extensions_api_schema_sources = [
"rewards_notifications.json",
]
-if (enable_brave_sync) {
- brave_extensions_api_schema_sources += [ "brave_sync.json" ]
-}
-
if (brave_wallet_enabled) {
brave_extensions_api_schema_sources += [ "brave_wallet.json" ]
}
diff --git a/common/extensions/api/brave_sync.json b/common/extensions/api/brave_sync.json
deleted file mode 100644
index 9a582f180c6d..000000000000
--- a/common/extensions/api/brave_sync.json
+++ /dev/null
@@ -1,450 +0,0 @@
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-[
- {
- "namespace": "braveSync",
- "description": "Use the chrome.braveSync
API to provide the interaction .",
- "compiler_options": {
- "implemented_in": "brave/browser/extensions/api/brave_sync_api.h"
- },
- "types": [
- {
- "id": "Bytes",
- "type": "array", "items": {"type": "integer", "minimum": 0, "maximum" : 255 }
- },
- {
- "id": "Config",
- "type": "object",
- "description": "Config passed to got-init-data",
- "properties": {
- "apiVersion" : {
- "type": "string",
- "description": "version of API"
- },
- "serverUrl" : {
- "type": "string",
- "description": "url of the server"
- },
- "debug" : {
- "type": "boolean",
- "description": "whether sync lib produces debug messages"
- }
- }
- },
- {
- "id": "Site",
- "type": "object",
- "description": "Represents site entity",
- "properties": {
- "location" : {"type" : "string", "description" : "url of site"},
- "title" : {"type" : "string", "description" : "title of site"},
- "customTitle" : {"type" : "string", "description" : "custom title of site"},
- "lastAccessedTime" : {"type" : "number", "description" : "last accessed time"},
- "creationTime" : {"type" : "number", "description" : "creation time"},
- "favicon" : {"type" : "string", "description" : "url of favicon"}
- }
- },
- {
- "id": "MetaInfo",
- "type": "object",
- "description": "Represents metaInfo entity",
- "properties": {
- "key" : {"type" : "string", "description" : "key of meta info"},
- "value" : {"type" : "string", "description" : "value of meta info"}
- }
- },
- {
- "id": "Bookmark",
- "type": "object",
- "description": "Represents bookmark entity",
- "properties": {
- "site" : {"$ref" : "Site"},
- "isFolder" : {"type": "boolean"},
- "parentFolderObjectId" : {"type" : "binary", "optional": true},
- "parentFolderObjectIdStr" : {"type" : "string", "optional": true},
- "fields" : { "type": "array", "items": {"type": "string" }, "optional": true },
- "hideInToolbar" : {"type": "boolean", "optional": true},
- "order" : {"type": "string", "optional": true},
- "metaInfo" : { "type": "array", "items": {"$ref" : "MetaInfo" }, "optional": true }
- }
- },
- {
- "id": "SiteSetting",
- "type": "object",
- "description": "Represents site settings",
- "properties": {
- "hostPattern" : {"type": "string"},
- "zoomLevel" : {"type": "number", "optional": true},
- "shieldsUp" : {"type": "boolean", "optional": true},
- "adControl" : {"type": "string", "optional": true},
- "cookieControl" : {"type": "string", "optional": true},
- "safeBrowsing" : {"type": "boolean", "optional": true},
- "noScript" : {"type": "boolean", "optional": true},
- "httpsEverywhere" : {"type": "boolean", "optional": true},
- "fingerprintingProtection" : {"type": "boolean", "optional": true},
- "ledgerPayments" : {"type": "boolean", "optional": true},
- "ledgerPaymentsShown" : {"type": "boolean", "optional": true},
- "fields" : { "type": "array", "items": {"type": "string" }, "optional": true }
- }
- },
- {
- "id": "Device",
- "type": "object",
- "description": "Represents sync device",
- "properties": {
- "name" : {"type": "string"},
- "deviceIdV2" : {"type": "string"}
- }
- },
- {
- "id": "SyncRecord",
- "type": "object",
- "description": "Record representing sync entity",
- "properties": {
- "action" : {
- "type": "integer",
- "description": "action code"
- },
- "deviceId" : {
- "type": "binary",
- "description": "device id"
- },
- "objectId" : {
- "type": "binary",
- "description": "object id"
- },
- // "deviceIdStr", "objectIdStr" and "parentFolderObjectIdStr" are
- // workaround because js lib uses UInt8Array type for ids,
- // and there is no appropriate conversion
- "deviceIdStr" : {
- "type": "string",
- "description": "device id",
- "optional": true
- },
- "objectIdStr" : {
- "type": "string",
- "description": "object id",
- "optional": true
- },
- "objectData": {
- "type": "string",
- "description": "may be bookmark|device|historySite|siteSetting"
- },
- "syncTimestamp": {
- "type": "number",
- "description": "time when record was synced",
- "optional": true
- },
- "bookmark" : {
- "$ref": "Bookmark",
- "optional": true,
- "description": "bookmark info"
- },
- "historySite" : {
- "$ref": "Site",
- "optional": true,
- "description": "history info"
- },
- "siteSetting" : {
- "$ref": "SiteSetting",
- "optional": true,
- "description": "site setting"
- },
- "device" : {
- "$ref": "Device",
- "optional": true,
- "description": "synced device info"
- }
- },
- "oneOf": [
- { "required": [ "bookmark"] },
- { "required": [ "history_site"] },
- { "required": [ "site_setting"] },
- { "required": [ "device"] }
- ]
- },
- {
- "id": "RecordAndExistingObject",
- "type": "object",
- "description": "represents pair of sync record and sync record with existing object",
- "properties": {
- "serverRecord" : {
- "$ref": "SyncRecord",
- "description": "original sync record"
- },
- "localRecord" : {
- "$ref": "SyncRecord",
- "description": "existing sync record",
- "optional": true
- }
- }
- }
- ],
- "events": [
- {
- "name": "onGotInitData",
- "type": "function",
- "description": "Browser sends init data to sync js",
- "parameters": [
- {
- "$ref": "Bytes",
- "name": "seed",
- "optional": true
- },
- {
- "$ref": "Bytes",
- "name": "device_id",
- "optional": true
- },
- {
- "$ref": "Config",
- "name": "config"
- },
- {
- "type": "string",
- "name": "device_id_v2",
- "optional": true
- }
- ]
- },
- {
- "name": "onFetchSyncRecords",
- "type": "function",
- "description": "sent to fetch sync records after a given start time from the sync server",
- "parameters": [
- {
- "type": "array", "items": {"type": "string"},
- "name": "categoryNames"
- },
- {
- "type": "number",
- "name": "startAt"
- },
- {
- "type": "number",
- "name": "maxRecords"
- }
- ]
- },
- {
- "name": "onResolveSyncRecords",
- "type": "function",
- "description": "Browser sends resolve records.",
- "parameters": [
- {
- "type": "string",
- "name": "categoryName"
- },
- {
- "type": "array", "items": {"$ref": "RecordAndExistingObject"},
- "name": "recordsAndExistingObjects"
- }
- ]
- },
- {
- "name": "onSendSyncRecords",
- "type": "function",
- "description": "Browser sends this to the js sync library with the data that needs to be synced.",
- "parameters": [
- {
- "type": "string",
- "name": "categoryName"
- },
- {
- "type": "array", "items": {"$ref": "SyncRecord"},
- "name": "records"
- }
- ]
- },
- {
- "name": "onSendGetBookmarksBaseOrder",
- "type": "function",
- "description": "Browser sends this to get base bookmarks order for the particular device.",
- "parameters": [
- {
- "type": "string",
- "name": "deviceId"
- },
- {
- "type": "string",
- "name": "platform"
- }
- ]
- },
- {
- "name": "sendCompact",
- "type": "function",
- "description": "Browser sends this to compact records of a category",
- "parameters": [
- {
- "type": "string",
- "name": "categoryName"
- }
- ]
- },
- {
- "name": "onLoadClient",
- "type": "function",
- "description": "Browser informs extension page to load js sync library.",
- "parameters": []
- }
- ],
- "functions": [
- {
- "name": "extensionInitialized",
- "type": "function",
- "description": "Notifies extension has registered all listeners",
- "parameters": []
- },
- {
- "name": "getInitData",
- "type": "function",
- "description": "Emits the version of sync that is currently running",
- "parameters": [
- {
- "type": "string",
- "name": "syncVersion"
- },
- {
- "type": "function",
- "name": "callback",
- "optional": true,
- "parameters": [
- {
- "name": "callback_arg1",
- "type": "integer"
- }
- ]
- }
- ]
- },
- {
- "name": "syncSetupError",
- "type": "function",
- "description": "Indicates that a fatal error occurred during sync setup, meaning that sync is not running",
- "parameters": [
- {
- "type": "string",
- "name": "error"
- }
- ]
- },
- {
- "name": "syncDebug",
- "type": "function",
- "description": "Used for debugging in environments where the webview console output is not easily accessible",
- "parameters": [
- {
- "type": "string",
- "name": "message"
- }
- ]
- },
- {
- "name": "syncReady",
- "type": "function",
- "description": "Sent when sync has finished initialization",
- "parameters": []
- },
- {
- "name": "saveInitData",
- "type": "function",
- "description": "Browser must save values in persistent storage if non-empty",
- "parameters": [
- {
- "type": "binary",
- "name": "seed",
- "optional": true
- },
- {
- "type": "binary",
- "name": "device_id",
- "optional": true
- },
- {
- "type": "string",
- "name": "device_id_v2",
- "optional": true
- }
- ]
- },
- {
- "name": "getExistingObjects",
- "type": "function",
- "description": "Browser should resolve this records and answer with `resolve-sync-records`",
- "parameters": [
- {
- "type": "string",
- "name": "category_name"
- },
- {
- "type": "array", "items": {"$ref": "SyncRecord"},
- "name": "records"
- },
- {
- "type": "number",
- "name": "last_record_timestamp"
- },
- {
- "type": "boolean",
- "name": "is_truncated"
- }
- ]
- },
- {
- "name": "resolvedSyncRecords",
- "type": "function",
- "description": "Browser must update its local values with the resolved sync records",
- "parameters": [
- {
- "type": "string",
- "name": "category_name"
- },
- {
- "type": "array", "items": {"$ref": "SyncRecord"},
- "name": "records"
- }
- ]
- },
- {
- "name": "saveBookmarksBaseOrder",
- "type": "function",
- "description": "Browser must save bookmarks base order",
- "parameters": [
- {
- "type": "string",
- "name": "order"
- }
- ]
- },
- {
- "name": "onCompactComplete",
- "type": "function",
- "description": "Notify browser that compaction for category is done",
- "parameters": [
- {
- "type": "string",
- "name": "category_name"
- }
- ]
- },
- {
- "name": "onRecordsSent",
- "type": "function",
- "description": "Notify browser that records are successfully uploaded",
- "parameters": [
- {
- "type": "string",
- "name": "category_name"
- },
- {
- "type": "array", "items": {"$ref": "SyncRecord"},
- "name": "records"
- }
- ]
- }
- ]
- }
-]
diff --git a/common/extensions/extension_constants.cc b/common/extensions/extension_constants.cc
index d1a3fb1c9387..6cca76cbfd70 100644
--- a/common/extensions/extension_constants.cc
+++ b/common/extensions/extension_constants.cc
@@ -10,7 +10,6 @@ const char brave_rewards_extension_id[] = "jidkidbbcafjabdphckchenhfomhnfma";
const char brave_webtorrent_extension_id[] = "lgjmpdmojkpocjcopdikifhejkkjglho";
const char hangouts_extension_id[] = "nkeimhogjdpnpccoofpliimaahmaaome";
const char widevine_extension_id[] = "oimompecagnajdejgnnjijobebaeigek";
-const char brave_sync_extension_id[] = "nomlkjnggnifocmealianaaiobmebgil";
const char crl_set_extension_id[] = "hfnkpimlhhgieaddgfemjhofmfblmnib";
const char ethereum_remote_client_extension_id[] =
diff --git a/common/extensions/extension_constants.h b/common/extensions/extension_constants.h
index 2e1ab11f07db..3b097de9d75f 100644
--- a/common/extensions/extension_constants.h
+++ b/common/extensions/extension_constants.h
@@ -11,7 +11,6 @@ extern const char brave_rewards_extension_id[];
extern const char brave_webtorrent_extension_id[];
extern const char hangouts_extension_id[];
extern const char widevine_extension_id[];
-extern const char brave_sync_extension_id[];
extern const char crl_set_extension_id[];
extern const char ethereum_remote_client_extension_id[];
diff --git a/common/extensions/whitelist.cc b/common/extensions/whitelist.cc
index 76e6dc2c4b29..0f8196704238 100644
--- a/common/extensions/whitelist.cc
+++ b/common/extensions/whitelist.cc
@@ -16,7 +16,6 @@
const std::vector kVettedExtensions{
brave_extension_id,
brave_rewards_extension_id,
- brave_sync_extension_id,
brave_webtorrent_extension_id,
crl_set_extension_id,
ethereum_remote_client_extension_id,
diff --git a/common/network_constants.cc b/common/network_constants.cc
index 84a5de06ecc2..2f83cd867173 100644
--- a/common/network_constants.cc
+++ b/common/network_constants.cc
@@ -61,6 +61,7 @@ const char kCookieHeader[] = "Cookie";
const char kRefererHeader[] = "Referer";
const char kUserAgentHeader[] = "User-Agent";
const char kBravePartnerHeader[] = "X-Brave-Partner";
+const char kBraveServicesKeyHeader[] = "BraveServiceKey";
const char kBittorrentMimeType[] = "application/x-bittorrent";
const char kOctetStreamMimeType[] = "application/octet-stream";
diff --git a/common/network_constants.h b/common/network_constants.h
index c542c375ea65..e3a30e0e1f28 100644
--- a/common/network_constants.h
+++ b/common/network_constants.h
@@ -42,6 +42,7 @@ extern const char kCookieHeader[];
extern const char kRefererHeader[];
extern const char kUserAgentHeader[];
extern const char kBravePartnerHeader[];
+extern const char kBraveServicesKeyHeader[];
extern const char kBittorrentMimeType[];
extern const char kOctetStreamMimeType[];
diff --git a/common/webui_url_constants.cc b/common/webui_url_constants.cc
index 7d59940e76b6..049e3967841d 100644
--- a/common/webui_url_constants.cc
+++ b/common/webui_url_constants.cc
@@ -14,13 +14,12 @@ const char kWelcomeHost[] = "welcome";
const char kWelcomeJS[] = "brave_welcome.js";
const char kTipHost[] = "tip";
const char kBraveNewTabJS[] = "brave_new_tab.js";
-const char kBraveUISyncHost[] = "sync";
-const char kBraveSyncJS[] = "brave_sync.js";
const char kBraveUIRewardsURL[] = "chrome://rewards/";
const char kBraveUIAdblockURL[] = "chrome://adblock/";
const char kBraveUIWebcompatReporterURL[] = "chrome://webcompat/";
const char kBraveUITipURL[] = "chrome://tip/";
-const char kBraveUISyncURL[] = "chrome://sync/";
const char kBraveUIWalletURL[] = "chrome://wallet/";
const char kExtensionSettingsURL[] = "brave://settings/extensions";
const char kWalletHost[] = "wallet";
+const char kBraveSyncPath[] = "braveSync";
+const char kBraveSyncSetupPath[] = "braveSync/setup";
diff --git a/common/webui_url_constants.h b/common/webui_url_constants.h
index 4df5724784fe..a6487b757619 100644
--- a/common/webui_url_constants.h
+++ b/common/webui_url_constants.h
@@ -15,17 +15,16 @@ extern const char kWelcomeHost[];
extern const char kWelcomeJS[];
extern const char kTipHost[];
extern const char kBraveNewTabJS[];
-extern const char kBraveUISyncHost[];
-extern const char kBraveSyncJS[];
extern const char kBraveUIRewardsURL[];
extern const char kBraveUIAdblockURL[];
extern const char kBraveUIWebcompatReporterURL[];
extern const char kBraveUITipHost[];
extern const char kBraveUITipURL[];
-extern const char kBraveUISyncURL[];
extern const char kBraveUIWalletURL[];
extern const char kBraveUIWalletURL[];
extern const char kExtensionSettingsURL[];
extern const char kWalletHost[];
+extern const char kBraveSyncPath[];
+extern const char kBraveSyncSetupPath[];
#endif // BRAVE_COMMON_WEBUI_URL_CONSTANTS_H_
diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn
index 8cb90e479992..8cc6ad9361c1 100644
--- a/components/brave_sync/BUILD.gn
+++ b/components/brave_sync/BUILD.gn
@@ -14,78 +14,6 @@ config("brave_sync_config") {
]
}
-if (enable_brave_sync) {
- source_set("js_sync_lib_impl") {
- sources = [
- "brave_profile_sync_service_impl.cc",
- "brave_profile_sync_service_impl.h",
- "client/brave_sync_client.h",
- "client/brave_sync_client_impl.cc",
- "client/brave_sync_client_impl.h",
- "client/client_data.cc",
- "client/client_data.h",
- "client/client_ext_impl_data.cc",
- "client/client_ext_impl_data.h",
- ]
-
- configs += [ ":brave_sync_config" ]
- deps = [
- ":core",
- ":crypto",
- ":jslib_messages",
- ":prefs",
- ":public",
- ":static_resources",
- "//base",
- "//brave/common:common",
- "//chrome/common",
- "//components/bookmarks/browser",
- "//components/bookmarks/common",
- "//components/keyed_service/content",
- "//components/keyed_service/core",
- "//components/pref_registry",
- "//components/prefs",
- "//components/signin/public/identity_manager",
- "//components/sync:rest_of_sync",
- "//components/sync/driver:driver",
- "//content/public/browser",
- "//extensions/browser",
- "//net",
- "//services/network/public/cpp",
- "//ui/base",
- ]
- }
-}
-
-source_set("jslib_messages") {
- sources = [
- "jslib_const.cc",
- "jslib_const.h",
- "jslib_messages.cc",
- "jslib_messages.h",
- "jslib_messages_fwd.h",
- ]
-
- deps = [
- "//base",
- ]
-}
-
-source_set("prefs") {
- sources = [
- "brave_sync_prefs.cc",
- "brave_sync_prefs.h",
- "settings.cc",
- "settings.h",
- "sync_devices.cc",
- "sync_devices.h",
- ]
-
- deps = [
- "//components/prefs",
- ]
-}
-
source_set("crypto") {
sources = [
"crypto/crypto.cc",
@@ -93,6 +21,7 @@ source_set("crypto") {
]
deps = [
+ "//base",
"//brave/vendor/bat-native-tweetnacl:tweetnacl",
"//brave/vendor/bip39wally-core-native:bip39wally-core",
"//crypto",
@@ -112,121 +41,46 @@ source_set("features") {
deps = [
"//base",
+ "buildflags",
]
}
-source_set("public") {
+source_set("network_time_helper") {
sources = [
- "public/brave_profile_sync_service.h",
+ "network_time_helper.cc",
+ "network_time_helper.h",
]
deps = [
- ":core",
- "buildflags",
+ "//base",
+ "//components/network_time",
]
}
-source_set("core") {
+source_set("prefs") {
sources = [
- "bookmark_order_util.cc",
- "bookmark_order_util.h",
- "brave_sync_service.cc",
- "brave_sync_service.h",
- "syncer_helper.cc",
- "syncer_helper.h",
- "tools.cc",
- "tools.h",
- "values_conv.cc",
- "values_conv.h",
+ "brave_sync_prefs.cc",
+ "brave_sync_prefs.h",
]
deps = [
- ":crypto",
- ":features",
- ":jslib_messages",
- ":prefs",
"//base",
- "//components/bookmarks/browser",
- "//crypto",
- "//extensions/buildflags",
+ "//components/os_crypt",
+ "//components/prefs",
+ "//components/pref_registry",
]
}
source_set("brave_sync") {
sources = [
- "brave_sync_service_observer.h",
]
deps = [
- ":core",
+ ":crypto",
+ ":features",
+ ":network_time_helper",
+ ":prefs",
"buildflags",
"//base",
]
-
- if (enable_brave_sync) {
- deps += [ ":js_sync_lib_impl" ]
- }
-}
-
-pack_web_resources("generated_resources") {
- resource_name = "brave_sync"
- output_dir = "$root_gen_dir/brave/components/brave_sync"
- deps = [
- "ui",
- ]
-}
-
-grit("static_resources") {
- source = "resources.grd"
- outputs = [
- "grit/brave_sync_resources_map.cc",
- "grit/brave_sync_resources_map.h",
- "grit/brave_sync_resources.h",
- "brave_sync_static.pak",
- ]
-
- deps = []
-
- grit_flags = [
- "-E",
- "root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
- ]
-
- # fix paths so we don't have to do this
- resource_ids = ""
-
- output_dir = "$root_gen_dir/brave/components/brave_sync"
-}
-
-repack("resources") {
- deps = [
- ":generated_resources",
- ":static_resources",
- ]
-
- sources = [
- "$root_gen_dir/brave/components/brave_sync/brave_sync_generated.pak",
- "$root_gen_dir/brave/components/brave_sync/brave_sync_static.pak",
- ]
-
- output = "$root_gen_dir/brave/components/brave_sync/brave_sync_resources.pak"
-}
-
-if (enable_brave_sync) {
- source_set("testutil") {
- testonly = true
-
- deps = [
- ":brave_sync",
- "//base",
- "//chrome/test:test_support",
- "//content/public/browser",
- "//testing/gtest",
- ]
-
- sources = [
- "test_util.cc",
- "test_util.h",
- ]
- }
}
diff --git a/components/brave_sync/bookmark_order_util.cc b/components/brave_sync/bookmark_order_util.cc
deleted file mode 100644
index 30fa629f9c88..000000000000
--- a/components/brave_sync/bookmark_order_util.cc
+++ /dev/null
@@ -1,176 +0,0 @@
-/* Copyright 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "brave/components/brave_sync/bookmark_order_util.h"
-
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-
-namespace brave_sync {
-
-namespace {
-
-bool CompareOrder(const std::vector& vec_left,
- const std::vector& vec_right) {
- // Use C++ stdlib
- return std::lexicographical_compare(vec_left.begin(), vec_left.end(),
- vec_right.begin(), vec_right.end());
-}
-
-} // namespace
-
-std::vector OrderToIntVect(const std::string& s) {
- std::vector vec_s = SplitString(
- s,
- ".",
- base::WhitespaceHandling::TRIM_WHITESPACE,
- base::SplitResult::SPLIT_WANT_NONEMPTY);
- std::vector vec_int;
- vec_int.reserve(vec_s.size());
- for (size_t i = 0; i < vec_s.size(); ++i) {
- int output = 0;
- bool b = base::StringToInt(vec_s[i], &output);
- CHECK(b);
- CHECK_GE(output, 0);
- vec_int.emplace_back(output);
- }
- return vec_int;
-}
-
-std::string ToOrderString(const std::vector& vec_int) {
- std::string ret;
- for (size_t i = 0; i < vec_int.size(); ++i) {
- if (vec_int[i] < 0) {
- return "";
- }
- ret += std::to_string(vec_int[i]);
- if (i != vec_int.size() - 1) {
- ret += ".";
- }
- }
- return ret;
-}
-
-bool CompareOrder(const std::string& left, const std::string& right) {
- // Return: true if left < right
- // Split each and compare as int vectors
- std::vector vec_left = OrderToIntVect(left);
- std::vector vec_right = OrderToIntVect(right);
-
- return CompareOrder(vec_left, vec_right);
-}
-
-namespace {
-
-std::string GetNextOrderFromPrevOrder(std::vector* vec_prev) {
- DCHECK_GT(vec_prev->size(), 2u);
- int last_number = vec_prev->at(vec_prev->size() - 1);
- DCHECK_GT(last_number, 0);
- if (last_number <= 0) {
- return "";
- } else {
- vec_prev->at(vec_prev->size() - 1)++;
- return ToOrderString(*vec_prev);
- }
-}
-
-std::string GetPrevOrderFromNextOrder(std::vector* vec_next) {
- DCHECK_GT(vec_next->size(), 2u);
- int last_number = vec_next->at(vec_next->size() - 1);
- DCHECK_GT(last_number, 0);
- vec_next->resize(vec_next->size() - 1);
- if (last_number <= 0) {
- return "";
- } else if (last_number == 1) {
- return ToOrderString(*vec_next) + ".0.1";
- } else {
- vec_next->push_back(last_number - 1);
- return ToOrderString(*vec_next);
- }
-}
-
-} // namespace
-
-// Inspired by https://github.com/brave/sync/blob/staging/client/bookmarkUtil.js
-std::string GetOrder(const std::string& prev,
- const std::string& next,
- const std::string& parent) {
- if (prev.empty() && next.empty()) {
- DCHECK(!parent.empty());
- return parent + ".1";
- } else if (!prev.empty() && next.empty()) {
- std::vector vec_prev = OrderToIntVect(prev);
- DCHECK_GT(vec_prev.size(), 2u);
- // Just increase the last number, as we don't have next
- return GetNextOrderFromPrevOrder(&vec_prev);
- } else if (prev.empty() && !next.empty()) {
- std::vector vec_next = OrderToIntVect(next);
- DCHECK_GT(vec_next.size(), 2u);
- // Just decrease the last number or substitute with 0.1,
- // as we don't have prev
- return GetPrevOrderFromNextOrder(&vec_next);
- } else {
- DCHECK(!prev.empty() && !next.empty());
- std::vector vec_prev = OrderToIntVect(prev);
- DCHECK_GT(vec_prev.size(), 2u);
- std::vector vec_next = OrderToIntVect(next);
- DCHECK_GT(vec_next.size(), 2u);
- DCHECK(CompareOrder(prev, next));
-
- // Assume prev looks as a.b.c.d
- // result candidates are:
- // a.b.c.(d+1)
- // a.b.c.d.1
- // a.b.c.d.0.1
- // a.b.c.d.0.0.1
- // ...
- // each of them is greater than prev
-
- // Length of result in worse case can be one segment longer
- // than length of next
- // And result should be < next
-
- std::vector vec_result;
- vec_result = vec_prev;
- vec_result[vec_result.size() - 1]++;
-
- // Case a.b.c.(d+1)
- DCHECK(CompareOrder(vec_prev, vec_result));
- if (CompareOrder(vec_result, vec_next)) {
- return ToOrderString(vec_result);
- }
-
- vec_result = vec_prev;
- vec_result.push_back(1);
- // Case a.b.c.d.1
- DCHECK(CompareOrder(vec_prev, vec_result));
- if (CompareOrder(vec_result, vec_next)) {
- return ToOrderString(vec_result);
- }
-
- size_t insert_at = vec_prev.size();
- size_t try_until_size = vec_next.size() + 1;
- // Cases a.b.c.d.0....0.1
- while (vec_result.size() < try_until_size) {
- vec_result.insert(vec_result.begin() + insert_at, 0);
- DCHECK(CompareOrder(vec_prev, vec_result));
- if (CompareOrder(vec_result, vec_next)) {
- return ToOrderString(vec_result);
- }
- }
-
- NOTREACHED() << "[BraveSync] " << __func__ << " prev=" << prev
- << " next=" << next << " terminated with "
- << ToOrderString(vec_result);
- }
-
- NOTREACHED() << "[BraveSync] " << __func__
- << " condition is not handled prev.empty()=" << prev.empty()
- << " next.empty()=" << next.empty();
-
- return "";
-}
-
-} // namespace brave_sync
diff --git a/components/brave_sync/bookmark_order_util.h b/components/brave_sync/bookmark_order_util.h
deleted file mode 100644
index 6a9d9504f695..000000000000
--- a/components/brave_sync/bookmark_order_util.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Copyright 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_COMPONENTS_BRAVE_SYNC_BOOKMARK_ORDER_UTIL_H_
-#define BRAVE_COMPONENTS_BRAVE_SYNC_BOOKMARK_ORDER_UTIL_H_
-
-#include
-#include
-
-namespace brave_sync {
-
- std::vector OrderToIntVect(const std::string& s);
- std::string ToOrderString(const std::vector& vec_int);
- bool CompareOrder(const std::string& left, const std::string& right);
- std::string GetOrder(const std::string& prev,
- const std::string& next,
- const std::string& parent);
-
- } // namespace brave_sync
-
-#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BOOKMARK_ORDER_UTIL_H_
diff --git a/components/brave_sync/bookmark_order_util_unittest.cc b/components/brave_sync/bookmark_order_util_unittest.cc
deleted file mode 100644
index 98a911177262..000000000000
--- a/components/brave_sync/bookmark_order_util_unittest.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "brave/components/brave_sync/bookmark_order_util.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace brave_sync {
-
-TEST(BookmarkOrderUtilTest, OrderToIntVect_EmptyString) {
- std::vector result = OrderToIntVect("");
- EXPECT_TRUE(result.empty());
-}
-
-TEST(BookmarkOrderUtilTest, OrderToIntVect_SingleValue) {
- std::vector result = OrderToIntVect("1");
- ASSERT_EQ(result.size(), 1u);
- EXPECT_EQ(result.at(0), 1);
-}
-
-TEST(BookmarkOrderUtilTest, OrderToIntVect_TypicalValue) {
- std::vector result = OrderToIntVect("1.7.4");
- ASSERT_EQ(result.size(), 3u);
- EXPECT_EQ(result.at(0), 1);
- EXPECT_EQ(result.at(1), 7);
- EXPECT_EQ(result.at(2), 4);
-}
-
-TEST(BookmarkOrderUtilTest, OrderToIntVect_WrongValue) {
- std::vector result = OrderToIntVect("..");
- EXPECT_TRUE(result.empty());
-}
-
-TEST(BookmarkOrderUtilTest, OrderToIntVect_SemiWrongValue) {
- std::vector result = OrderToIntVect(".5.");
- ASSERT_EQ(result.size(), 1u);
- EXPECT_EQ(result.at(0), 5);
-}
-
-TEST(BookmarkOrderUtilTest, ToOrderString) {
- EXPECT_EQ(ToOrderString({}), "");
- EXPECT_EQ(ToOrderString({1}), "1");
- EXPECT_EQ(ToOrderString({1, 2, 3}), "1.2.3");
- EXPECT_EQ(ToOrderString({-1, 2, 3}), "");
-}
-
-TEST(BookmarkOrderUtilTest, CompareOrder) {
- EXPECT_FALSE(CompareOrder("", ""));
- EXPECT_TRUE(CompareOrder("1", "2"));
- EXPECT_TRUE(CompareOrder("1", "1.1"));
- EXPECT_TRUE(CompareOrder("1.1", "2.234.1"));
- EXPECT_TRUE(CompareOrder("2.234.1", "63.17.1.45.2"));
-
- EXPECT_FALSE(CompareOrder("2", "1"));
- EXPECT_TRUE(CompareOrder("2", "11"));
- EXPECT_FALSE(CompareOrder("11", "2"));
-
- EXPECT_TRUE(CompareOrder("1.7.0.1", "1.7.1"));
- EXPECT_TRUE(CompareOrder("1.7.0.1", "1.7.0.2"));
- EXPECT_FALSE(CompareOrder("1.7.0.2", "1.7.0.1"));
-
- EXPECT_TRUE(CompareOrder("2.0.8", "2.0.8.0.1"));
- EXPECT_TRUE(CompareOrder("2.0.8.0.1", "2.0.8.1"));
-
- EXPECT_TRUE(CompareOrder("2.0.8", "2.0.8.0.0.1"));
- EXPECT_TRUE(CompareOrder("2.0.8.0.0.1", "2.0.8.0.1"));
-
- EXPECT_TRUE(CompareOrder("2.0.8.10", "2.0.8.10.1"));
- EXPECT_TRUE(CompareOrder("2.0.8.10.1", "2.0.8.11.1"));
-
- EXPECT_TRUE(CompareOrder("2.0.0.1", "2.0.1"));
-
- EXPECT_TRUE(CompareOrder("2.5.6.3", "2.5.7.8.2"));
- EXPECT_TRUE(CompareOrder("2.5.6.3", "2.5.6.4"));
- EXPECT_TRUE(CompareOrder("2.5.6.4", "2.5.7.8.2"));
-
- EXPECT_TRUE(CompareOrder("2.0.8.10", "2.0.8.11"));
- EXPECT_TRUE(CompareOrder("2.0.8.11", "2.0.8.11.1"));
-}
-
-TEST(BookmarkOrderUtilTest, GetOrder) {
- // Ported from
- // https://github.com/brave/sync/blob/staging/test/client/bookmarkUtil.js
- EXPECT_EQ(GetOrder("", "2.0.1", ""), "2.0.0.1");
-
- EXPECT_EQ(GetOrder("", "2.0.9", ""), "2.0.8");
- EXPECT_EQ(GetOrder("2.0.8", "", ""), "2.0.9");
- EXPECT_EQ(GetOrder("2.0.8", "2.0.9", ""), "2.0.8.1");
-
- EXPECT_EQ(GetOrder("2.0.8", "2.0.8.1", ""), "2.0.8.0.1");
- EXPECT_EQ(GetOrder("2.0.8", "2.0.8.0.1", ""), "2.0.8.0.0.1");
- EXPECT_EQ(GetOrder("2.0.8", "2.0.8.0.0.1", ""), "2.0.8.0.0.0.1");
-
- EXPECT_EQ(GetOrder("2.0.8.1", "2.0.9", ""), "2.0.8.2");
- EXPECT_EQ(GetOrder("2.0.8.1", "2.0.10", ""), "2.0.8.2");
- EXPECT_EQ(GetOrder("2.0.8.10", "2.0.8.15", ""), "2.0.8.11");
-
- EXPECT_EQ(GetOrder("2.0.8.10", "2.0.8.15.1", ""), "2.0.8.11");
- EXPECT_EQ(GetOrder("2.0.8.10", "2.0.8.11.1", ""), "2.0.8.11");
-
- EXPECT_EQ(GetOrder("2.0.8.11", "2.0.8.11.1", ""), "2.0.8.11.0.1");
-
- EXPECT_EQ(GetOrder("2.0.8.10.0.1", "2.0.8.15.1", ""), "2.0.8.10.0.2");
- EXPECT_EQ(GetOrder("", "", "2.0.9"), "2.0.9.1");
-
- EXPECT_EQ(GetOrder("2.5.6.3", "2.5.7.8.2", ""), "2.5.6.4");
- EXPECT_EQ(GetOrder("2.5.6.35", "2.5.7.8.2", ""), "2.5.6.36");
-
- EXPECT_EQ(GetOrder("1.1.1.2", "1.1.1.2.1", ""), "1.1.1.2.0.1");
- EXPECT_EQ(GetOrder("1.1.1.2.1", "1.1.1.3", ""), "1.1.1.2.2");
-}
-
-} // namespace brave_sync
diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc
deleted file mode 100644
index 70a8ede7b1f3..000000000000
--- a/components/brave_sync/brave_profile_sync_service_impl.cc
+++ /dev/null
@@ -1,1425 +0,0 @@
-/* Copyright 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "brave/components/brave_sync/brave_profile_sync_service_impl.h"
-
-#include
-#include