From c423779d9484740bb8c66abc6258bf0c2d83ecf0 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 26 Feb 2019 15:01:06 -0800 Subject: [PATCH 01/73] Make browser_sync::ProfileSyncService a brave_sync::SyncMessageHandler subclass of syncer::SyncClient should own brave_sync::BraveSyncClient* and implement GetBraveSyncClient Update brave sync extension api Suppress BraveSyncServiceImpl create sync chain Start sync engine based on brave_sync enabled Dispatch OnPollSyncCycle and OnNudgeSyncCycle from sync thread to UI thread Avoid use_transport_only_mode and put poll/nudge delegate into syncer fake sync_pb::GetUpdateResponse Adding BookmarksSpecifics Put back Device record & overrides short/long poll interval Add GetRecords callback to PollSyncCycleDelegate Fix OnGetRecords callback triggered on the wrong thread Apply real records from sync chain Get rid of sync event observer for nudge/poll delegate also partial brave commit builder Complete brave commit & update (CREATE, DELETE, partial UPDATE) Add MetaInfo to Bookmark protobuf --- browser/brave_profile_prefs.cc | 4 + ...browser_context_keyed_service_factories.cc | 2 - browser/extensions/api/brave_sync_api.cc | 60 +- browser/profiles/brave_profile_manager.cc | 3 - browser/ui/webui/sync/sync_ui.cc | 9 +- .../chrome/browser/sync/chrome_sync_client.cc | 10 + .../browser_sync/profile_sync_service.cc | 818 ++++++++++++++++++ .../browser_sync/profile_sync_service.h | 15 + .../driver/glue/sync_backend_host_core.cc | 35 + .../sync/driver/glue/sync_backend_host_core.h | 6 + .../driver/glue/sync_backend_host_impl.cc | 30 + .../sync/driver/glue/sync_backend_host_impl.h | 6 + .../components/sync/driver/sync_client.h | 5 + .../components/sync/engine/sync_engine.h | 2 + .../components/sync/engine/sync_manager.h | 5 + .../components/sync/engine_impl/commit.cc | 165 ++++ .../sync/engine_impl/cycle/sync_cycle.h | 2 + .../sync/engine_impl/get_updates_processor.cc | 218 +++++ .../sync/engine_impl/get_updates_processor.h | 5 + .../sync/engine_impl/sync_manager_impl.cc | 12 + .../sync/engine_impl/sync_scheduler_impl.cc | 33 + .../components/sync/engine_impl/syncer.cc | 26 + .../components/sync/engine_impl/syncer.h | 6 + .../bookmark_change_processor.cc | 108 +++ .../bookmark_local_changes_builder.cc | 116 +++ common/extensions/api/brave_sync.json | 12 +- components/brave_sync/BUILD.gn | 5 +- components/brave_sync/brave_sync_prefs.cc | 21 + components/brave_sync/brave_sync_prefs.h | 6 + components/brave_sync/brave_sync_service.h | 7 +- .../brave_sync/brave_sync_service_impl.cc | 5 +- .../brave_sync/brave_sync_service_impl.h | 4 +- .../brave_sync/client/brave_sync_client.h | 4 +- .../client/brave_sync_client_impl.cc | 22 +- .../client/brave_sync_client_impl.h | 3 +- .../brave_sync/client/client_ext_impl_data.cc | 36 + components/brave_sync/jslib_messages.cc | 19 + components/brave_sync/jslib_messages.h | 13 + components/brave_sync/jslib_messages_fwd.h | 12 + ...e-browser-sync-chrome_sync_client.cc.patch | 14 + ...me-browser-sync-chrome_sync_client.h.patch | 21 + ...browser_sync-profile_sync_service.cc.patch | 84 ++ ...-browser_sync-profile_sync_service.h.patch | 122 +++ ...ync-driver-data_type_manager_impl.cc.patch | 14 + ...river-glue-sync_backend_host_core.cc.patch | 32 + ...driver-glue-sync_backend_host_core.h.patch | 24 + ...river-glue-sync_backend_host_impl.cc.patch | 15 + ...driver-glue-sync_backend_host_impl.h.patch | 27 + ...components-sync-driver-sync_client.h.patch | 13 + ...components-sync-engine-sync_engine.h.patch | 24 + ...omponents-sync-engine-sync_manager.h.patch | 14 + ...omponents-sync-engine_impl-commit.cc.patch | 16 + ...-sync-engine_impl-cycle-sync_cycle.h.patch | 15 + ...engine_impl-get_updates_processor.cc.patch | 33 + ...-engine_impl-get_updates_processor.h.patch | 22 + ...ync-engine_impl-sync_manager_impl.cc.patch | 13 + ...sync-engine_impl-sync_manager_impl.h.patch | 13 + ...ts-sync-engine_impl-sync_scheduler.h.patch | 14 + ...c-engine_impl-sync_scheduler_impl.cc.patch | 12 + ...nc-engine_impl-sync_scheduler_impl.h.patch | 34 + ...omponents-sync-engine_impl-syncer.cc.patch | 28 + ...components-sync-engine_impl-syncer.h.patch | 36 + ...okmarks-bookmark_change_processor.cc.patch | 40 + ...ks-bookmark_local_changes_builder.cc.patch | 12 + 64 files changed, 2501 insertions(+), 61 deletions(-) create mode 100644 chromium_src/chrome/browser/sync/chrome_sync_client.cc create mode 100644 chromium_src/components/browser_sync/profile_sync_service.cc create mode 100644 chromium_src/components/browser_sync/profile_sync_service.h create mode 100644 chromium_src/components/sync/driver/glue/sync_backend_host_core.cc create mode 100644 chromium_src/components/sync/driver/glue/sync_backend_host_core.h create mode 100644 chromium_src/components/sync/driver/glue/sync_backend_host_impl.cc create mode 100644 chromium_src/components/sync/driver/glue/sync_backend_host_impl.h create mode 100644 chromium_src/components/sync/driver/sync_client.h create mode 100644 chromium_src/components/sync/engine/sync_engine.h create mode 100644 chromium_src/components/sync/engine/sync_manager.h create mode 100644 chromium_src/components/sync/engine_impl/commit.cc create mode 100644 chromium_src/components/sync/engine_impl/cycle/sync_cycle.h create mode 100644 chromium_src/components/sync/engine_impl/get_updates_processor.cc create mode 100644 chromium_src/components/sync/engine_impl/get_updates_processor.h create mode 100644 chromium_src/components/sync/engine_impl/sync_manager_impl.cc create mode 100644 chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc create mode 100644 chromium_src/components/sync/engine_impl/syncer.cc create mode 100644 chromium_src/components/sync/engine_impl/syncer.h create mode 100644 chromium_src/components/sync_bookmarks/bookmark_change_processor.cc create mode 100644 chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc create mode 100644 patches/chrome-browser-sync-chrome_sync_client.cc.patch create mode 100644 patches/chrome-browser-sync-chrome_sync_client.h.patch create mode 100644 patches/components-browser_sync-profile_sync_service.cc.patch create mode 100644 patches/components-browser_sync-profile_sync_service.h.patch create mode 100644 patches/components-sync-driver-data_type_manager_impl.cc.patch create mode 100644 patches/components-sync-driver-glue-sync_backend_host_core.cc.patch create mode 100644 patches/components-sync-driver-glue-sync_backend_host_core.h.patch create mode 100644 patches/components-sync-driver-glue-sync_backend_host_impl.cc.patch create mode 100644 patches/components-sync-driver-glue-sync_backend_host_impl.h.patch create mode 100644 patches/components-sync-driver-sync_client.h.patch create mode 100644 patches/components-sync-engine-sync_engine.h.patch create mode 100644 patches/components-sync-engine-sync_manager.h.patch create mode 100644 patches/components-sync-engine_impl-commit.cc.patch create mode 100644 patches/components-sync-engine_impl-cycle-sync_cycle.h.patch create mode 100644 patches/components-sync-engine_impl-get_updates_processor.cc.patch create mode 100644 patches/components-sync-engine_impl-get_updates_processor.h.patch create mode 100644 patches/components-sync-engine_impl-sync_manager_impl.cc.patch create mode 100644 patches/components-sync-engine_impl-sync_manager_impl.h.patch create mode 100644 patches/components-sync-engine_impl-sync_scheduler.h.patch create mode 100644 patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch create mode 100644 patches/components-sync-engine_impl-sync_scheduler_impl.h.patch create mode 100644 patches/components-sync-engine_impl-syncer.cc.patch create mode 100644 patches/components-sync-engine_impl-syncer.h.patch create mode 100644 patches/components-sync_bookmarks-bookmark_change_processor.cc.patch create mode 100644 patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index b011b7c4d518..6c9024a326bf 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -8,6 +8,7 @@ #include "brave/common/pref_names.h" #include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h" #include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" +#include "brave/components/brave_sync/brave_sync_prefs.h" #include "chrome/browser/net/prediction_options.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/common/pref_names.h" @@ -44,6 +45,9 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterBooleanPref(kLocationBarIsWide, false); registry->RegisterBooleanPref(kHideBraveRewardsButton, false); + //TODO(darkdh): merge into upstream SyncPrefs + brave_sync::prefs::Prefs::RegisterProfilePrefs(registry); + registry->RegisterBooleanPref(kWidevineOptedIn, false); registry->RegisterBooleanPref(kAskWidevineInstall, true); #if BUILDFLAG(BUNDLE_WIDEVINE_CDM) diff --git a/browser/browser_context_keyed_service_factories.cc b/browser/browser_context_keyed_service_factories.cc index 14266d66fc7c..7defe1ab9701 100644 --- a/browser/browser_context_keyed_service_factories.cc +++ b/browser/browser_context_keyed_service_factories.cc @@ -12,7 +12,6 @@ #include "brave/browser/tor/tor_profile_service_factory.h" #include "brave/components/brave_ads/browser/ads_service_factory.h" #include "brave/components/brave_rewards/browser/rewards_service_factory.h" -#include "brave/components/brave_sync/brave_sync_service_factory.h" namespace brave { @@ -21,7 +20,6 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() { brave_rewards::RewardsServiceFactory::GetInstance(); brave_shields::AdBlockPrefServiceFactory::GetInstance(); brave_shields::CookiePrefServiceFactory::GetInstance(); - brave_sync::BraveSyncServiceFactory::GetInstance(); greaselion::GreaselionServiceFactory::GetInstance(); TorProfileServiceFactory::GetInstance(); SearchEngineProviderServiceFactory::GetInstance(); diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index da656c73f435..e0f2133120b1 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -11,15 +11,14 @@ #include "brave/common/extensions/api/brave_sync.h" #include "brave/components/brave_sync/client/brave_sync_client.h" -#include "brave/components/brave_sync/brave_sync_service.h" -#include "brave/components/brave_sync/brave_sync_service_factory.h" #include "brave/components/brave_sync/client/client_ext_impl_data.h" #include "brave/components/brave_sync/values_conv.h" #include "brave/components/brave_sync/jslib_messages.h" #include "chrome/browser/profiles/profile.h" +#include "components/browser_sync/profile_sync_service.h" +#include "chrome/browser/sync/profile_sync_service_factory.h" -using ::brave_sync::BraveSyncService; -using ::brave_sync::BraveSyncServiceFactory; +using browser_sync::ProfileSyncService; using content::BrowserContext; namespace extensions { @@ -27,8 +26,8 @@ namespace api { namespace { -BraveSyncService* GetBraveSyncService(BrowserContext* browser_context) { - return BraveSyncServiceFactory::GetForProfile( +ProfileSyncService* GetProfileSyncService(BrowserContext* browser_context) { + return ProfileSyncServiceFactory::GetForProfile( Profile::FromBrowserContext(browser_context)); } @@ -38,10 +37,9 @@ ExtensionFunction::ResponseAction BraveSyncGetInitDataFunction::Run() { brave_sync::GetInitData::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler()->OnGetInitData( - params->sync_version); + sync_service->OnGetInitData(params->sync_version); return RespondNow(NoArguments()); } @@ -51,9 +49,9 @@ ExtensionFunction::ResponseAction BraveSyncSyncSetupErrorFunction::Run() { brave_sync::SyncSetupError::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler()->OnSyncSetupError( + sync_service->OnSyncSetupError( params->error); return RespondNow(NoArguments()); @@ -64,9 +62,9 @@ ExtensionFunction::ResponseAction BraveSyncSyncDebugFunction::Run() { brave_sync::SyncDebug::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler()->OnSyncDebug( + sync_service->OnSyncDebug( params->message); return RespondNow(NoArguments()); @@ -77,9 +75,9 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { brave_sync::SaveInitData::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler()->OnSaveInitData( + sync_service->OnSaveInitData( params->seed ? *params->seed : std::vector(), params->device_id ? *params->device_id : std::vector()); @@ -87,9 +85,9 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { } ExtensionFunction::ResponseAction BraveSyncSyncReadyFunction::Run() { - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler()->OnSyncReady(); + sync_service->OnSyncReady(); return RespondNow(NoArguments()); } @@ -102,9 +100,9 @@ ExtensionFunction::ResponseAction BraveSyncGetExistingObjectsFunction::Run() { auto records = std::make_unique>(); ::brave_sync::ConvertSyncRecords(params->records, *records.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler()->OnGetExistingObjects( + sync_service->OnGetExistingObjects( params->category_name, std::move(records), base::Time::FromJsTime(params->last_record_timestamp), @@ -121,9 +119,9 @@ ExtensionFunction::ResponseAction BraveSyncResolvedSyncRecordsFunction::Run() { auto records = std::make_unique>(); ::brave_sync::ConvertSyncRecords(params->records, *records.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler()->OnResolvedSyncRecords( + sync_service->OnResolvedSyncRecords( params->category_name, std::move(records)); @@ -136,10 +134,10 @@ BraveSyncSaveBookmarksBaseOrderFunction::Run() { brave_sync::SaveBookmarksBaseOrder::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler() - ->OnSaveBookmarksBaseOrder(params->order); + sync_service->OnSaveBookmarksBaseOrder( + params->order); return RespondNow(NoArguments()); } @@ -149,10 +147,9 @@ ExtensionFunction::ResponseAction BraveSyncSaveBookmarkOrderFunction::Run() { brave_sync::SaveBookmarkOrder::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler()->OnSaveBookmarkOrder( - params->object_id, params->order); + sync_service->OnSaveBookmarkOrder(params->object_id, params->order); return RespondNow(NoArguments()); } @@ -162,19 +159,18 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() { brave_sync::SyncWordsPrepared::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->sync_message_handler() - ->OnSyncWordsPrepared(params->words); + sync_service->OnSyncWordsPrepared(params->words); return RespondNow(NoArguments()); } ExtensionFunction::ResponseAction BraveSyncExtensionInitializedFunction::Run() { // Also inform sync client extension started - BraveSyncService* sync_service = GetBraveSyncService(browser_context()); + ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetSyncClient()->OnExtensionInitialized(); + sync_service->GetBraveSyncClient()->OnExtensionInitialized(); return RespondNow(NoArguments()); } diff --git a/browser/profiles/brave_profile_manager.cc b/browser/profiles/brave_profile_manager.cc index 1efbb726bc29..98358a0c5ca4 100644 --- a/browser/profiles/brave_profile_manager.cc +++ b/browser/profiles/brave_profile_manager.cc @@ -92,9 +92,6 @@ std::string BraveProfileManager::GetLastUsedProfileName() { void BraveProfileManager::DoFinalInitForServices(Profile* profile, bool go_off_the_record) { ProfileManager::DoFinalInitForServices(profile, go_off_the_record); - // BraveSyncService need to be created when profile initialized, otherwise - // it will only be constructed only when we open chrome:/sync/ - brave_sync::BraveSyncServiceFactory::GetForProfile(profile); brave_ads::AdsServiceFactory::GetForProfile(profile); brave_rewards::RewardsServiceFactory::GetForProfile(profile); content::URLDataSource::Add(profile, diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index 16b98c6a67c2..cd16f5a0f9d4 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -7,7 +7,6 @@ #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_factory.h" #include "brave/components/brave_sync/brave_sync_service_observer.h" #include "brave/components/brave_sync/grit/brave_sync_resources.h" #include "brave/components/brave_sync/grit/brave_sync_generated_map.h" @@ -15,6 +14,8 @@ #include "brave/components/brave_sync/settings.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 "components/browser_sync/profile_sync_service.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_ui_message_handler.h" @@ -60,7 +61,7 @@ class SyncUIDOMHandler : public WebUIMessageHandler, std::unique_ptr settings, std::unique_ptr devices); - brave_sync::BraveSyncService *sync_service_ = nullptr; // NOT OWNED + brave_sync::BraveSyncService* sync_service_ = nullptr; // NOT OWNED base::WeakPtrFactory weak_ptr_factory_; @@ -118,7 +119,9 @@ void SyncUIDOMHandler::RegisterMessages() { void SyncUIDOMHandler::Init() { Profile* profile = Profile::FromWebUI(web_ui()); - sync_service_ = brave_sync::BraveSyncServiceFactory::GetForProfile(profile); + sync_service_ = + static_cast( + ProfileSyncServiceFactory::GetForProfile(profile)); if (sync_service_) sync_service_->AddObserver(this); } diff --git a/chromium_src/chrome/browser/sync/chrome_sync_client.cc b/chromium_src/chrome/browser/sync/chrome_sync_client.cc new file mode 100644 index 000000000000..1822dc85b0d8 --- /dev/null +++ b/chromium_src/chrome/browser/sync/chrome_sync_client.cc @@ -0,0 +1,10 @@ +#include "brave/components/brave_sync/client/brave_sync_client_impl.h" +#include "../../../../../chrome/browser/sync/chrome_sync_client.cc" + +namespace browser_sync { + +brave_sync::BraveSyncClient* ChromeSyncClient::GetBraveSyncClient() { + return brave_sync_client_.get(); +} + +} // namespace browser_sync diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/browser_sync/profile_sync_service.cc new file mode 100644 index 000000000000..4a14a7984c29 --- /dev/null +++ b/chromium_src/components/browser_sync/profile_sync_service.cc @@ -0,0 +1,818 @@ +#include "components/signin/core/browser/account_info.h" +#include "components/sync/engine/sync_credentials.h" +namespace browser_sync { +namespace { +syncer::SyncCredentials GetDummyCredentials(); +AccountInfo GetDummyAccountInfo(); +} +} +namespace syncer { +const int64_t kBraveDefaultShortPollIntervalSeconds = 60; +const int64_t kBraveDefaultLongPollIntervalSeconds = 90; +} +#include "../../../../components/browser_sync/profile_sync_service.cc" + +#include "base/bind.h" +#include "base/strings/utf_string_conversions.h" +#include "brave/components/brave_sync/brave_sync_prefs.h" +#include "brave/components/brave_sync/brave_sync_service_observer.h" +#include "brave/components/brave_sync/jslib_const.h" +#include "brave/components/brave_sync/jslib_messages.h" +#include "brave/components/brave_sync/settings.h" +#include "brave/components/brave_sync/sync_devices.h" +#include "brave/components/brave_sync/tools.h" +#include "brave/components/brave_sync/values_conv.h" +#include "components/bookmarks/browser/bookmark_model.h" +#include "components/sync/engine_impl/syncer.h" +#include "content/public/browser/browser_thread.h" +#include "net/base/network_interfaces.h" +#include "ui/base/models/tree_node_iterator.h" + +namespace browser_sync { + +using brave_sync::GetRecordsCallback; +using brave_sync::jslib::Device; +using brave_sync::jslib::SyncRecord; +using brave_sync::jslib_const::kHistorySites; +using brave_sync::jslib_const::kBookmarks; +using brave_sync::jslib_const::kPreferences; +using brave_sync::jslib_const::SyncObjectData_DEVICE; +using brave_sync::jslib_const::SyncRecordType_PREFERENCES; +using brave_sync::RecordsList; +using brave_sync::RecordsListPtr; +using brave_sync::StrFromUint8Array; +using brave_sync::SyncDevice; +using brave_sync::SyncRecordAndExisting; +using brave_sync::SyncRecordAndExistingList; +using brave_sync::SyncRecordPtr; +using brave_sync::tools::IsTimeEmpty; +using brave_sync::Uint8Array; +using brave_sync::Uint8ArrayFromString; + +namespace { + +void NotifyLogMessage(const std::string& message) { + DLOG(INFO) << message; +} + +std::string GetDeviceName() { + std::string hostname = net::GetHostName(); + if (hostname.empty()) { +#if defined(OS_MACOSX) + hostname = std::string("Mac Desktop"); +#elif defined(OS_LINUX) + hostname = std::string("Linux Desktop"); +#elif defined(OS_WIN) + hostname = std::string("Windows Desktop"); +#endif + } + return hostname; +} + +syncer::SyncCredentials GetDummyCredentials() { + syncer::SyncCredentials credentials; + credentials.account_id = "dummy_account_id"; + credentials.email = "dummy_email"; + credentials.sync_token = "dummy_access_token"; + return credentials; +} + +AccountInfo GetDummyAccountInfo() { + AccountInfo account_info; + account_info.account_id = "dummy_account_id"; + return account_info; +} + +RecordsListPtr CreateDeviceCreationRecordExtension( + const std::string& deviceName, + const std::string& objectId, + const SyncRecord::Action &action, + const std::string& deviceId) { + RecordsListPtr records = std::make_unique(); + + SyncRecordPtr record = std::make_unique(); + + record->action = action; + record->deviceId = deviceId; + record->objectId = objectId; + record->objectData = SyncObjectData_DEVICE; // "device" + + std::unique_ptr device = std::make_unique(); + device->name = deviceName; + record->SetDevice(std::move(device)); + + records->emplace_back(std::move(record)); + + return records; +} + +const bookmarks::BookmarkNode* FindByObjectId(bookmarks::BookmarkModel* model, + const std::string& object_id) { + ui::TreeNodeIterator + iterator(model->root_node()); + while (iterator.has_next()) { + const bookmarks::BookmarkNode* node = iterator.Next(); + std::string node_object_id; + node->GetMetaInfo("object_id", &node_object_id); + + if (!node_object_id.empty() && object_id == node_object_id) + return node; + } + return nullptr; +} + +void GetPrevObjectId(const bookmarks::BookmarkNode* parent, + int index, + std::string* prev_object_id) { + DCHECK_GE(index, 0); + auto* prev_node = index == 0 ? + nullptr : + parent->GetChild(index - 1); + + if (prev_node) + prev_node->GetMetaInfo("object_id", prev_object_id); +} + +void GetOrder(const bookmarks::BookmarkNode* parent, + int index, + std::string* prev_order, + std::string* next_order, + std::string* parent_order) { + DCHECK_GE(index, 0); + auto* prev_node = index == 0 ? + nullptr : + parent->GetChild(index - 1); + auto* next_node = index == parent->child_count() - 1 ? + nullptr : + parent->GetChild(index + 1); + + if (prev_node) + prev_node->GetMetaInfo("order", prev_order); + + if (next_node) + next_node->GetMetaInfo("order", next_order); + + parent->GetMetaInfo("order", parent_order); +} + +std::unique_ptr BookmarkNodeToSyncBookmark( + bookmarks::BookmarkModel* model, + brave_sync::prefs::Prefs* brave_sync_prefs, + const bookmarks::BookmarkNode* node, + const SyncRecord::Action& action) { + if (node->is_permanent_node() || !node->parent()) + return std::unique_ptr(); + + auto record = std::make_unique(); + record->deviceId = brave_sync_prefs->GetThisDeviceId(); + record->objectData = brave_sync::jslib_const::SyncObjectData_BOOKMARK; + + auto bookmark = std::make_unique(); + bookmark->site.location = node->url().spec(); + bookmark->site.title = base::UTF16ToUTF8(node->GetTitledUrlNodeTitle()); + bookmark->site.customTitle = base::UTF16ToUTF8(node->GetTitle()); + // bookmark->site.lastAccessedTime - ignored + bookmark->site.creationTime = node->date_added(); + bookmark->site.favicon = node->icon_url() ? node->icon_url()->spec() : ""; + // Url may have type OTHER_NODE if it is in Deleted Bookmarks + bookmark->isFolder = (node->type() != bookmarks::BookmarkNode::URL && + node->type() != bookmarks::BookmarkNode::OTHER_NODE); + bookmark->hideInToolbar = + node->parent() != model->bookmark_bar_node(); + + std::string object_id; + node->GetMetaInfo("object_id", &object_id); + record->objectId = object_id; + + std::string parent_object_id; + node->parent()->GetMetaInfo("object_id", &parent_object_id); + bookmark->parentFolderObjectId = parent_object_id; + + std::string order; + node->GetMetaInfo("order", &order); + bookmark->order = order; + + int index = node->parent()->GetIndexOf(node); + std::string prev_object_id; + GetPrevObjectId(node->parent(), index, &prev_object_id); + bookmark->prevObjectId = prev_object_id; + + std::string prev_order, next_order, parent_order; + GetOrder(node->parent(), index, &prev_order, &next_order, &parent_order); + if (parent_order.empty() && node->parent()->is_permanent_node()) { + if (node->parent() == model->bookmark_bar_node()) + parent_order = + brave_sync_prefs->GetBookmarksBaseOrder() + '0'; + else + // TODO(darkdh): put this to 1 when old code fix the order + parent_order = + brave_sync_prefs->GetBookmarksBaseOrder() + '0'; + } + bookmark->prevOrder = prev_order; + bookmark->nextOrder = next_order; + bookmark->parentOrder = parent_order; + + std::string sync_timestamp; + node->GetMetaInfo("sync_timestamp", &sync_timestamp); + DCHECK(!sync_timestamp.empty()); + + record->syncTimestamp = base::Time::FromJsTime(std::stod(sync_timestamp)); + + record->action = brave_sync::jslib::SyncRecord::Action::A_UPDATE; + + record->SetBookmark(std::move(bookmark)); + + return record; +} + +void CreateResolveList( + const std::vector>& records, + SyncRecordAndExistingList* records_and_existing_objects, + bookmarks::BookmarkModel* model, + brave_sync::prefs::Prefs* brave_sync_prefs) { + for (const auto& record : records) { + auto resolved_record = std::make_unique(); + resolved_record->first = SyncRecord::Clone(*record); + auto* node = FindByObjectId(model, record->objectId); + if (node) { + resolved_record->second = BookmarkNodeToSyncBookmark(model, + brave_sync_prefs, + node, + record->action); + } + + records_and_existing_objects->push_back(std::move(resolved_record)); + } +} + +} // namespace + +void ProfileSyncService::OnSetupSyncHaveCode(const std::string& sync_words, + const std::string& device_name) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + if (sync_words.empty()) { + OnSyncSetupError("ERR_SYNC_WRONG_WORDS"); + return; + } + + if (brave_sync_initializing_) { + NotifyLogMessage("currently initializing"); + return; + } + + if (brave_sync_configured_) { + NotifyLogMessage("already configured"); + return; + } + + if (device_name.empty()) + brave_sync_prefs_->SetThisDeviceName(GetDeviceName()); + else + brave_sync_prefs_->SetThisDeviceName(device_name); + brave_sync_initializing_ = true; + + brave_sync_prefs_->SetSyncEnabled(true); + brave_sync_words_ = sync_words; +} + +void ProfileSyncService::OnSetupSyncNewToSync( + const std::string& device_name) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + if (brave_sync_initializing_) { + NotifyLogMessage("currently initializing"); + return; + } + + if (brave_sync_configured_) { + NotifyLogMessage("already configured"); + return; + } + + brave_sync_words_.clear(); // If the previous attempt was connect to sync chain + // and failed to receive save-init-data + if (device_name.empty()) + brave_sync_prefs_->SetThisDeviceName(GetDeviceName()); + else + brave_sync_prefs_->SetThisDeviceName(device_name); + + brave_sync_initializing_ = true; + + brave_sync_prefs_->SetSyncEnabled(true); +} + +void ProfileSyncService::OnDeleteDevice(const std::string& device_id) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + auto sync_devices = brave_sync_prefs_->GetSyncDevices(); + + const SyncDevice *device = sync_devices->GetByDeviceId(device_id); + if (device) { + const std::string device_name = device->name_; + const std::string object_id = device->object_id_; + SendDeviceSyncRecord( + SyncRecord::Action::A_DELETE, device_name, device_id, object_id); + } +} + +void ProfileSyncService::OnResetSync() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + auto sync_devices = brave_sync_prefs_->GetSyncDevices(); + + if (sync_devices->size() == 0) { + // Fail safe option + VLOG(2) << "[Sync] " << __func__ << " unexpected zero device size"; + ResetSyncInternal(); + } else { + // We have to send delete record and wait for library deleted response then + // we can reset it by ResetInternal() + const std::string device_id = brave_sync_prefs_->GetThisDeviceId(); + OnDeleteDevice(device_id); + } +} + +void ProfileSyncService::GetSettingsAndDevices( + const GetSettingsAndDevicesCallback& callback) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + auto settings = brave_sync_prefs_->GetBraveSyncSettings(); + auto devices = brave_sync_prefs_->GetSyncDevices(); + callback.Run(std::move(settings), std::move(devices)); +} + +void ProfileSyncService::GetSyncWords() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + // Ask sync client + std::string seed = brave_sync_prefs_->GetSeed(); + GetBraveSyncClient()->NeedSyncWords(seed); +} + +std::string ProfileSyncService::GetSeed() { + return brave_sync_prefs_->GetSeed(); +} + +void ProfileSyncService::OnSetSyncEnabled(const bool sync_this_device) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + brave_sync_prefs_->SetSyncEnabled(true); +} + +void ProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + // POC so only do bookmarks + syncer::ModelTypeSet type_set = user_settings_->GetChosenDataTypes(); + if (sync_bookmarks) + type_set.Put(syncer::BOOKMARKS); + else + type_set.Remove(syncer::BOOKMARKS); + user_settings_->SetChosenDataTypes(false, type_set); + brave_sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); +} + +void ProfileSyncService::OnSetSyncBrowsingHistory( + const bool sync_browsing_history) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); +#if 0 + brave_sync_prefs_->SetSyncHistoryEnabled(sync_browsing_history); +#endif +} + +void ProfileSyncService::OnSetSyncSavedSiteSettings( + const bool sync_saved_site_settings) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); +#if 0 + brave_sync_prefs_->SetSyncSiteSettingsEnabled(sync_saved_site_settings); +#endif +} + +void ProfileSyncService::BackgroundSyncStarted(bool startup) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); +#if 0 + if (startup) + bookmark_change_processor_->Start(); + + StartLoop(); +#endif +} + +void ProfileSyncService::BackgroundSyncStopped(bool shutdown) { +#if 0 + if (shutdown) + Shutdown(); + else + StopLoop(); +#endif +} + +void ProfileSyncService::OnSyncDebug(const std::string& message) { + NotifyLogMessage(message); +} + +void ProfileSyncService::OnSyncSetupError(const std::string& error) { + if (brave_sync_initializing_) { + brave_sync_prefs_->Clear(); + brave_sync_initializing_ = false; + } + NotifySyncSetupError(error); +} + +void ProfileSyncService::OnGetInitData(const std::string& sync_version) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + Uint8Array seed; + if (!brave_sync_words_.empty()) { + VLOG(1) << "[Brave Sync] Init from sync words"; + } else if (!brave_sync_prefs_->GetSeed().empty()) { + seed = Uint8ArrayFromString(brave_sync_prefs_->GetSeed()); + VLOG(1) << "[Brave Sync] Init from prefs"; + } else { + VLOG(1) << "[Brave Sync] Init new chain"; + } + + Uint8Array device_id; + if (!brave_sync_prefs_->GetThisDeviceId().empty()) { + device_id = Uint8ArrayFromString(brave_sync_prefs_->GetThisDeviceId()); + VLOG(1) << "[Brave Sync] Init device id from prefs: " << + StrFromUint8Array(device_id); + } else { + VLOG(1) << "[Brave Sync] Init empty device id"; + } + + DCHECK(!sync_version.empty()); + // TODO(bridiver) - this seems broken because using the version we get back + // from the server (currently v1.4.2) causes things to break. What is the + // the point of having this value? + brave_sync_prefs_->SetApiVersion("0"); + + brave_sync::client_data::Config config; + config.api_version = brave_sync_prefs_->GetApiVersion(); + config.server_url = "https://sync.brave.com"; + config.debug = true; + GetBraveSyncClient()->SendGotInitData(seed, device_id, config, brave_sync_words_); +} + +void ProfileSyncService::OnSaveInitData(const Uint8Array& seed, + const Uint8Array& device_id) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + DCHECK(!brave_sync_initialized_); + // If we are here and brave_sync_initializing_ is false, we have came + // not from OnSetupSyncNewToSync or OnSetupSyncHaveCode. + // One case is we put wrong code words and then restarted before cleared + // kSyncEnabled pref. This should not happen. + DCHECK(brave_sync_initializing_); + + std::string seed_str = StrFromUint8Array(seed); + std::string device_id_str = StrFromUint8Array(device_id); + + std::string prev_seed_str = brave_sync_prefs_->GetPrevSeed(); + + brave_sync_words_.clear(); + DCHECK(!seed_str.empty()); + + if (prev_seed_str == seed_str) { // reconnecting to previous sync chain + brave_sync_prefs_->SetPrevSeed(std::string()); + } else if (!prev_seed_str.empty()) { // connect/create to new sync chain + // bookmark_change_processor_->Reset(true); + brave_sync_prefs_->SetPrevSeed(std::string()); + } else { + // This is not required, because when there is no previous seed, bookmarks + // should not have a metadata. However, this is done by intention, to be + // a remedy for cases when sync had been reset and prev_seed_str had been + // cleared when it shouldn't (brave-browser#3188). + // bookmark_change_processor_->Reset(true); + } + + brave_sync_prefs_->SetSeed(seed_str); + brave_sync_prefs_->SetThisDeviceId(device_id_str); + + brave_sync_configured_ = true; + + user_settings_->SetChosenDataTypes(false, syncer::ModelTypeSet()); + OnSetSyncBookmarks(true); + + brave_sync_initializing_ = false; +} + +void ProfileSyncService::OnSyncReady() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + const std::string bookmarks_base_order = brave_sync_prefs_->GetBookmarksBaseOrder(); + if (bookmarks_base_order.empty()) { + std::string platform = brave_sync::tools::GetPlatformName(); + GetBraveSyncClient()->SendGetBookmarksBaseOrder(brave_sync_prefs_->GetThisDeviceId(), + platform); + // OnSyncReady will be called by OnSaveBookmarksBaseOrder + return; + } + + DCHECK(false == brave_sync_initialized_); + brave_sync_initialized_ = true; + + user_settings_->SetSyncRequested(true); +} + +void ProfileSyncService::OnGetExistingObjects( + const std::string& category_name, + std::unique_ptr records, + const base::Time &last_record_time_stamp, + const bool is_truncated) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + // TODO(bridiver) - what do we do with is_truncated ? + // It appears to be ignored in b-l + if (!IsTimeEmpty(last_record_time_stamp)) { + brave_sync_prefs_->SetLatestRecordTime(last_record_time_stamp); + } + + if (category_name == kBookmarks) { + auto records_and_existing_objects = + std::make_unique(); + CreateResolveList( + *records.get(), records_and_existing_objects.get(), + sync_client_->GetBookmarkModel(), + brave_sync_prefs_.get()); + GetBraveSyncClient()->SendResolveSyncRecords( + category_name, std::move(records_and_existing_objects)); + } +} + +void ProfileSyncService::OnResolvedSyncRecords( + const std::string& category_name, + std::unique_ptr records) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + if (category_name == brave_sync::jslib_const::kPreferences) { + OnResolvedPreferences(*records.get()); + } else if (category_name == kBookmarks) { + // Send records to syncer + if (get_record_cb_) + engine_->DispatchGetRecordsCallback(get_record_cb_, std::move(records)); + if (wevent_) { + wevent_->Signal(); + wevent_ = nullptr; + } + } else if (category_name == kHistorySites) { + NOTIMPLEMENTED(); + } +} + +void ProfileSyncService::OnDeletedSyncUser() { + NOTIMPLEMENTED(); +} + +void ProfileSyncService::OnDeleteSyncSiteSettings() { + NOTIMPLEMENTED(); +} + +void ProfileSyncService::OnSaveBookmarksBaseOrder(const std::string& order) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + DCHECK(!order.empty()); + brave_sync_prefs_->SetBookmarksBaseOrder(order); + OnSyncReady(); +} + +void ProfileSyncService::OnSyncWordsPrepared(const std::string& words) { + NotifyHaveSyncWords(words); +} + +void ProfileSyncService::NotifySyncSetupError(const std::string& error) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + for (auto& observer : brave_sync::BraveSyncService::observers_) + observer.OnSyncSetupError(this, error); +} + +void ProfileSyncService::NotifySyncStateChanged() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + for (auto& observer : brave_sync::BraveSyncService::observers_) + observer.OnSyncStateChanged(this); +} + +void ProfileSyncService::NotifyHaveSyncWords( + const std::string& sync_words) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + for (auto& observer : brave_sync::BraveSyncService::observers_) + observer.OnHaveSyncWords(this, sync_words); +} + +void ProfileSyncService::ResetSyncInternal() { + brave_sync_prefs_->SetPrevSeed(brave_sync_prefs_->GetSeed()); + + brave_sync_prefs_->Clear(); + + brave_sync_configured_ = false; + brave_sync_initialized_ = false; + + brave_sync_prefs_->SetSyncEnabled(false); +} + +void ProfileSyncService::FetchSyncRecords(const bool bookmarks, + const bool history, + const bool preferences, + int max_records) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK(bookmarks || history || preferences); + if (!(bookmarks || history || preferences)) { + return; + } + + std::vector category_names; + if (history) { + category_names.push_back(kHistorySites); // "HISTORY_SITES"; + } + if (bookmarks) { + category_names.push_back(kBookmarks); // "BOOKMARKS"; + } + if (preferences) { + category_names.push_back(kPreferences); // "PREFERENCES"; + } + + brave_sync_prefs_->SetLastFetchTime(base::Time::Now()); + + base::Time start_at_time = brave_sync_prefs_->GetLatestRecordTime(); + GetBraveSyncClient()->SendFetchSyncRecords( + category_names, + start_at_time, + max_records); +} + +void ProfileSyncService::SendCreateDevice() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + + std::string device_name = brave_sync_prefs_->GetThisDeviceName(); + std::string object_id = brave_sync::tools::GenerateObjectId(); + std::string device_id = brave_sync_prefs_->GetThisDeviceId(); + CHECK(!device_id.empty()); + + SendDeviceSyncRecord( + SyncRecord::Action::A_CREATE, + device_name, + device_id, + object_id); +} + +void ProfileSyncService::SendDeviceSyncRecord( + const int action, + const std::string& device_name, + const std::string& device_id, + const std::string& object_id) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + RecordsListPtr records = CreateDeviceCreationRecordExtension( + device_name, + object_id, + static_cast(action), + device_id); + GetBraveSyncClient()->SendSyncRecords( + SyncRecordType_PREFERENCES, *records); +} + +brave_sync::BraveSyncClient* ProfileSyncService::GetBraveSyncClient() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + return sync_client_->GetBraveSyncClient(); +} + +void ProfileSyncService::OnResolvedPreferences(const RecordsList& records) { + const std::string this_device_id = brave_sync_prefs_->GetThisDeviceId(); + bool this_device_deleted = false; + bool contains_only_one_device = false; + + auto sync_devices = brave_sync_prefs_->GetSyncDevices(); + for (const auto &record : records) { + DCHECK(record->has_device() || record->has_sitesetting()); + if (record->has_device()) { + bool actually_merged = false; + sync_devices->Merge( + SyncDevice(record->GetDevice().name, + record->objectId, + record->deviceId, + record->syncTimestamp.ToJsTime()), + record->action, + &actually_merged); + this_device_deleted = this_device_deleted || + (record->deviceId == this_device_id && + record->action == SyncRecord::Action::A_DELETE && + actually_merged); + contains_only_one_device = sync_devices->size() < 2 && + record->action == SyncRecord::Action::A_DELETE && + actually_merged; + } + } // for each device + + brave_sync_prefs_->SetSyncDevices(*sync_devices); + + if (this_device_deleted) { + ResetSyncInternal(); + } else if (contains_only_one_device) { + // We see amount of devices had been decreased to 1 and it is not this + // device had been deleted. So call OnResetSync which will send DELETE + // record for this device + OnResetSync(); + } +} + +void ProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { + if (pref == brave_sync::prefs::kSyncEnabled) { + GetBraveSyncClient()->OnSyncEnabledChanged(); + if (!brave_sync_prefs_->GetSyncEnabled()) + brave_sync_initialized_ = false; + } + NotifySyncStateChanged(); +} + +bool ProfileSyncService::IsBraveSyncEnabled() const{ + return brave_sync_prefs_->GetSyncEnabled(); +} + +void ProfileSyncService::BraveSyncSetup() { + brave_sync_words_ = std::string(); + brave_sync_prefs_ = + std::make_unique(sync_client_->GetPrefService()); + sync_client_->GetBraveSyncClient()->set_sync_message_handler(this); + + // Moniter syncs prefs required in GetSettingsAndDevices + brave_pref_change_registrar_.Init(sync_client_->GetPrefService()); + brave_pref_change_registrar_.Add( + brave_sync::prefs::kSyncEnabled, + base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + brave_sync::prefs::kSyncDeviceName, + base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + brave_sync::prefs::kSyncDeviceList, + base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + brave_sync::prefs::kSyncBookmarksEnabled, + base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + brave_sync::prefs::kSyncSiteSettingsEnabled, + base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + brave_sync::prefs::kSyncHistoryEnabled, + base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + + if (!brave_sync_prefs_->GetSeed().empty() && + !brave_sync_prefs_->GetThisDeviceName().empty()) { + brave_sync_configured_ = true; + } +} + +void ProfileSyncService::BraveEngineParamsInit( + syncer::SyncEngine::InitParams* params) { + DCHECK(params); + params->nudge_sync_cycle_delegate_function = + base::BindRepeating(&ProfileSyncService::OnNudgeSyncCycle, + sync_enabled_weak_factory_.GetWeakPtr()); + params->poll_sync_cycle_delegate_function = + base::BindRepeating(&ProfileSyncService::OnPollSyncCycle, + sync_enabled_weak_factory_.GetWeakPtr()); +} + +void ProfileSyncService::OnNudgeSyncCycle( + brave_sync::RecordsListPtr records) { + LOG(ERROR) << __func__; + for (auto& record : *records) { + record->deviceId = brave_sync_prefs_->GetThisDeviceId(); + if (record->has_bookmark()) { + auto* bookmark = record->mutable_bookmark(); + if (bookmark->parentOrder.empty() && + bookmark->parentFolderObjectId.empty()) { + // bookmark toolbar + if (!bookmark->hideInToolbar) + bookmark->parentOrder = + brave_sync_prefs_->GetBookmarksBaseOrder() + '0'; + // other bookmarks + else + // TODO(darkdh): put this to 1 when old code fix the order + bookmark->parentOrder = + brave_sync_prefs_->GetBookmarksBaseOrder() + '0'; + } + } + } + if (!records->empty()) + GetBraveSyncClient()->SendSyncRecords( + brave_sync::jslib_const::SyncRecordType_BOOKMARKS, *records); + GetBraveSyncClient()->ClearOrderMap(); +} + +void ProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, + base::WaitableEvent* wevent) { + LOG(ERROR) << __func__; + + if (IsTimeEmpty(brave_sync_prefs_->GetLastFetchTime())) + SendCreateDevice(); + GetBraveSyncClient()->SendFetchSyncDevices(); + + if (!brave_sync_initialized_) { + wevent->Signal(); + return; + } + + get_record_cb_ = cb; + wevent_ = wevent; + + const bool bookmarks = brave_sync_prefs_->GetSyncBookmarksEnabled(); + const bool history = brave_sync_prefs_->GetSyncHistoryEnabled(); + const bool preferences = brave_sync_prefs_->GetSyncSiteSettingsEnabled(); + FetchSyncRecords(bookmarks, history, preferences, 1000); +} + +} // namespace browser_sync diff --git a/chromium_src/components/browser_sync/profile_sync_service.h b/chromium_src/components/browser_sync/profile_sync_service.h new file mode 100644 index 000000000000..a0b557e7b4ee --- /dev/null +++ b/chromium_src/components/browser_sync/profile_sync_service.h @@ -0,0 +1,15 @@ +#include "brave/components/brave_sync/brave_sync_service.h" +#include "brave/components/brave_sync/client/brave_sync_client.h" +#include "brave/components/brave_sync/jslib_messages_fwd.h" + +namespace brave_sync { +namespace prefs { +class Prefs; +} // namespace prefs +} // namespace brave_sync + +namespace syncer { +class Syncer; +} // namespace syncer + +#include "../../../../components/browser_sync/profile_sync_service.h" diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc b/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc new file mode 100644 index 000000000000..c0919a30d895 --- /dev/null +++ b/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc @@ -0,0 +1,35 @@ +#include "../../../../../../components/sync/driver/glue/sync_backend_host_core.cc" + +#include "brave/components/brave_sync/jslib_messages.h" + +namespace syncer { + +void SyncBackendHostCore::OnNudgeSyncCycle( + brave_sync::RecordsListPtr records_list) { + host_.Call(FROM_HERE, + &SyncBackendHostImpl::HandleNudgeSyncCycle, + base::Passed(&records_list)); +} + +void SyncBackendHostCore::OnPollSyncCycle(GetRecordsCallback cb, + base::WaitableEvent* wevent) { + host_.Call(FROM_HERE, + &SyncBackendHostImpl::HandlePollSyncCycle, cb, wevent); +} + +void SyncBackendHostCore::DoDispatchGetRecordsCallback( + GetRecordsCallback cb, std::unique_ptr records) { + cb.Run(std::move(records)); +} + +void SyncBackendHostCore::BraveInit(SyncManager::InitArgs* args) { + DCHECK(args); + args->nudge_sync_cycle_delegate_function = + base::BindRepeating(&SyncBackendHostCore::OnNudgeSyncCycle, + weak_ptr_factory_.GetWeakPtr()); + args->poll_sync_cycle_delegate_function = + base::BindRepeating(&SyncBackendHostCore::OnPollSyncCycle, + weak_ptr_factory_.GetWeakPtr()); +} + +} // namespace syncer diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_core.h b/chromium_src/components/sync/driver/glue/sync_backend_host_core.h new file mode 100644 index 000000000000..caa0d7424b5e --- /dev/null +++ b/chromium_src/components/sync/driver/glue/sync_backend_host_core.h @@ -0,0 +1,6 @@ +#include "brave/components/brave_sync/jslib_messages_fwd.h" +namespace syncer { +using brave_sync::GetRecordsCallback; +using brave_sync::RecordsList; +} // namespace syncer +#include "../../../../../../components/sync/driver/glue/sync_backend_host_core.h" diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_impl.cc b/chromium_src/components/sync/driver/glue/sync_backend_host_impl.cc new file mode 100644 index 000000000000..b09e50a418c4 --- /dev/null +++ b/chromium_src/components/sync/driver/glue/sync_backend_host_impl.cc @@ -0,0 +1,30 @@ +#include "../../../../../../components/sync/driver/glue/sync_backend_host_impl.cc" + +#include "brave/components/brave_sync/jslib_messages.h" + +namespace syncer { + +void SyncBackendHostImpl::HandleNudgeSyncCycle( + brave_sync::RecordsListPtr records_list) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK(nudge_sync_cycle_delegate_function_); + nudge_sync_cycle_delegate_function_.Run(std::move(records_list)); +} + +void SyncBackendHostImpl::HandlePollSyncCycle( + GetRecordsCallback cb, + base::WaitableEvent* wevent) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK(poll_sync_cycle_delegate_function_); + poll_sync_cycle_delegate_function_.Run(cb, wevent); +} + +void SyncBackendHostImpl::DispatchGetRecordsCallback( + GetRecordsCallback cb, std::unique_ptr records) { + sync_task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&SyncBackendHostCore::DoDispatchGetRecordsCallback, core_, + cb, std::move(records))); +} + +} // namespacd syncer diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_impl.h b/chromium_src/components/sync/driver/glue/sync_backend_host_impl.h new file mode 100644 index 000000000000..a3e3db0e699e --- /dev/null +++ b/chromium_src/components/sync/driver/glue/sync_backend_host_impl.h @@ -0,0 +1,6 @@ +#include "brave/components/brave_sync/jslib_messages_fwd.h" +namespace syncer { +using brave_sync::GetRecordsCallback; +using brave_sync::RecordsList; +} // namespace syncer +#include "../../../../../../components/sync/driver/glue/sync_backend_host_impl.h" diff --git a/chromium_src/components/sync/driver/sync_client.h b/chromium_src/components/sync/driver/sync_client.h new file mode 100644 index 000000000000..d2e2ea7e6f10 --- /dev/null +++ b/chromium_src/components/sync/driver/sync_client.h @@ -0,0 +1,5 @@ +namespace brave_sync { +class BraveSyncClient; +} // namespace brave_sync + +#include "../../../../../components/sync/driver/sync_client.h" diff --git a/chromium_src/components/sync/engine/sync_engine.h b/chromium_src/components/sync/engine/sync_engine.h new file mode 100644 index 000000000000..faf39481077a --- /dev/null +++ b/chromium_src/components/sync/engine/sync_engine.h @@ -0,0 +1,2 @@ +#include "brave/components/brave_sync/jslib_messages_fwd.h" +#include "../../../../../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 new file mode 100644 index 000000000000..f4cd5a839aa0 --- /dev/null +++ b/chromium_src/components/sync/engine/sync_manager.h @@ -0,0 +1,5 @@ +#include "brave/components/brave_sync/jslib_messages_fwd.h" +namespace syncer { +class Syncer; +} // namespace syncer +#include "../../../../../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 new file mode 100644 index 000000000000..38ae238d9c7f --- /dev/null +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -0,0 +1,165 @@ +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 + +#include "../../../../../components/sync/engine_impl/commit.cc" +#include "brave/components/brave_sync/jslib_const.h" +#include "brave/components/brave_sync/jslib_messages_fwd.h" +#include "brave/components/brave_sync/jslib_messages.h" +#include "components/sync/base/time.h" +#include "components/sync/base/unique_position.h" + +namespace syncer { +namespace { +using brave_sync::jslib::SyncRecord; +using brave_sync::jslib::MetaInfo; +const char kBookmarkBarTag[] = "bookmark_bar"; + +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); +} + +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(); + 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.title(); + bookmark->site.customTitle = bm_specifics.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 mattters for direct children of permanent nodes + bookmark->hideInToolbar = entity.parent_id_string() != kBookmarkBarTag; + + std::string originator_cache_guid; + std::string originator_client_item_id; + 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() == "prev_object_id") { + bookmark->prevObjectId = bm_specifics.meta_info(i).value(); + } else if (bm_specifics.meta_info(i).key() == "prev_order") { + bookmark->prevOrder = bm_specifics.meta_info(i).value(); + } else if (bm_specifics.meta_info(i).key() == "next_order") { + bookmark->nextOrder = bm_specifics.meta_info(i).value(); + } else if (bm_specifics.meta_info(i).key() == "parent_order") { + bookmark->parentOrder = 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() == "originator_cache_guid") { + originator_cache_guid = bm_specifics.meta_info(i).value(); + } else if (bm_specifics.meta_info(i).key() == + "originator_client_item_id") { + originator_client_item_id = bm_specifics.meta_info(i).value(); + } + } + + 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; + } + + DCHECK(!record->objectId.empty()); + + MetaInfo metaInfo; + metaInfo.key = "originator_cache_guid"; + if (originator_cache_guid.empty()) { + originator_cache_guid = cache_guid; + } + metaInfo.value = originator_cache_guid; + bookmark->metaInfo.push_back(metaInfo); + + metaInfo.key = "originator_client_item_id"; + if (originator_client_item_id.empty()) { + originator_client_item_id = entity.id_string(); + } + metaInfo.value = originator_client_item_id; + bookmark->metaInfo.push_back(metaInfo); + + metaInfo.key = "version"; + metaInfo.value = std::to_string(version); + bookmark->metaInfo.push_back(metaInfo); + + metaInfo.key = "mtime"; + metaInfo.value = std::to_string(entity.mtime()); + bookmark->metaInfo.push_back(metaInfo); + + metaInfo.key = "ctime"; + metaInfo.value = std::to_string(entity.ctime()); + bookmark->metaInfo.push_back(metaInfo); + + record->SetBookmark(std::move(bookmark)); + 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 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 new file mode 100644 index 000000000000..374c81d96589 --- /dev/null +++ b/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h @@ -0,0 +1,2 @@ +#include "brave/components/brave_sync/jslib_messages_fwd.h" +#include "../../../../../../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 new file mode 100644 index 000000000000..507c361dec01 --- /dev/null +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -0,0 +1,218 @@ +#include "components/sync/engine_impl/get_updates_processor.h" + +namespace syncer { +namespace { +SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*, ModelTypeSet*, + std::unique_ptr); +} // namespace +} // namespace syncer +#include "../../../../../components/sync/engine_impl/get_updates_processor.cc" +#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/syncable/syncable_proto_util.h" +#include "components/sync/engine_impl/loopback_server/loopback_server_entity.h" +#include "url/gurl.h" + +namespace syncer { +namespace { + +using brave_sync::jslib::Bookmark; +using brave_sync::jslib::SyncRecord; +using syncable::Id; +static const char kBookmarkBarTag[] = "bookmark_bar"; +static const char kOtherBookmarksTag[] = "other_bookmarks"; +static const char kBookmarkBarFolderName[] = "Bookmark Bar"; +static const char kOtherBookmarksFolderName[] = "Other 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"; + +uint64_t GetIndexByOrder(const std::string& record_order) { + uint64_t index = 0; + char last_ch = record_order.back(); + bool result = base::StringToUint64(std::string(&last_ch), &index); + --index; + DCHECK(index >= 0); + DCHECK(result); + return index; +} + +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_title(bookmark.site.title); + bm_specifics->set_creation_time_us( + TimeToProtoTime(bookmark.site.creationTime)); + bm_specifics->set_icon_url(bookmark.site.favicon); + // 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) { + if (metaInfo.key == "originator_cache_guid") { + entity->set_originator_cache_guid(metaInfo.value); + sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info(); + meta_info->set_key("originator_cache_guid"); + meta_info->set_value(metaInfo.value); + } else if (metaInfo.key == "originator_client_item_id") { + entity->set_originator_client_item_id(metaInfo.value); + sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info(); + meta_info->set_key("originator_client_item_id"); + meta_info->set_value(metaInfo.value); + } else if (metaInfo.key == "version") { + int64_t version; + bool result = base::StringToInt64(metaInfo.value, &version); + DCHECK(result); + entity->set_version(version + 1); + } else if (metaInfo.key == "mtime") { + int64_t mtime; + bool result = base::StringToInt64(metaInfo.value, &mtime); + DCHECK(result); + entity->set_mtime(mtime); + } else if (metaInfo.key == "ctime") { + int64_t ctime; + bool result = base::StringToInt64(metaInfo.value, &ctime); + DCHECK(result); + entity->set_ctime(ctime); + } + } +} + +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()) + entity->set_parent_id_string(bookmark_record.parentFolderObjectId); + else if (!bookmark_record.hideInToolbar) + entity->set_parent_id_string(std::string(kBookmarkBarTag)); + else + entity->set_parent_id_string(std::string(kOtherBookmarksTag)); + entity->set_non_unique_name(bookmark_record.site.title); + entity->set_folder(bookmark_record.isFolder); + + ExtractBookmarkMeta(entity, &specifics, bookmark_record); + + // TODO(darkdh): migrate to UniquePosition + entity->set_position_in_parent(GetIndexByOrder(bookmark_record.order)); + std::string suffix = GenerateSyncableBookmarkHash(entity->originator_cache_guid(), + entity->originator_client_item_id()); + UniquePosition uniquePosition = UniquePosition::FromInt64(GetIndexByOrder(bookmark_record.order), + suffix); + auto* unique_position_pb = entity->mutable_unique_position(); + *unique_position_pb = uniquePosition.ToProto(); + 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, kBookmarkBarTag); + AddPermanentNode(entities.Add(), kOtherBookmarksFolderName, + kOtherBookmarksTag); + if (records) { + for (const auto& record : *records.get()) { + AddBookmarkNode(entities.Add(), record.get()); + } + } + std::copy(entities.begin(), entities.end(), + RepeatedPtrFieldBackInserter(gu_response->mutable_entries())); + } + gu_response->set_changes_remaining(0); + } +} + +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 new file mode 100644 index 000000000000..00861b5ec12f --- /dev/null +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.h @@ -0,0 +1,5 @@ +#include "brave/components/brave_sync/jslib_messages_fwd.h" +namespace syncer { +using brave_sync::RecordsList; +} // namespace syncer +#include "../../../../../components/sync/engine_impl/get_updates_processor.h" diff --git a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc new file mode 100644 index 000000000000..9c1d3e75f9fc --- /dev/null +++ b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc @@ -0,0 +1,12 @@ +#include "../../../../../components/sync/engine_impl/sync_manager_impl.cc" +#include "brave/components/brave_sync/jslib_messages.h" + +namespace syncer { + +void SyncManagerImpl::BraveInit(InitArgs* args) { + DCHECK(args); + scheduler_->SetNudgeAndPollDelegate(args->nudge_sync_cycle_delegate_function, + args->poll_sync_cycle_delegate_function); +} + +} // namespace syncer diff --git a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc new file mode 100644 index 000000000000..7d232932a336 --- /dev/null +++ b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc @@ -0,0 +1,33 @@ +#include "../../../../../components/sync/engine_impl/sync_scheduler_impl.cc" + +#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(cb, wevent); +} + +void SyncSchedulerImpl::SetNudgeAndPollDelegate( + brave_sync::NudgeSyncCycleDelegate nudge_delegate, + brave_sync::PollSyncCycleDelegate poll_delegate) { + nudge_sync_cycle_delegate_function_ = nudge_delegate; + poll_sync_cycle_delegate_function_ = poll_delegate; +} + +void SyncSchedulerImpl::TryBraveSyncCycleJob() { + SyncCycle cycle(cycle_context_, this); + if (mode_ != CONFIGURATION_MODE && mode_ != CLEAR_SERVER_DATA_MODE) { + syncer_->DownloadBraveRecords(&cycle); + } +} + +} // namespace syncer diff --git a/chromium_src/components/sync/engine_impl/syncer.cc b/chromium_src/components/sync/engine_impl/syncer.cc new file mode 100644 index 000000000000..8568fdd9548b --- /dev/null +++ b/chromium_src/components/sync/engine_impl/syncer.cc @@ -0,0 +1,26 @@ +#include "brave/components/brave_sync/jslib_messages.h" +#include "base/synchronization/waitable_event.h" +#include "../../../../../components/sync/engine_impl/syncer.cc" + +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::BindRepeating(&Syncer::OnGetRecords, AsWeakPtr()); + base::WaitableEvent wevent; + cycle->delegate()->OnPollSyncCycle(on_get_records, &wevent); + // Make sure OnGetRecords will be the next task on sync thread + wevent.Wait(); +} + +} // namespace syncer + diff --git a/chromium_src/components/sync/engine_impl/syncer.h b/chromium_src/components/sync/engine_impl/syncer.h new file mode 100644 index 000000000000..efd21a62c803 --- /dev/null +++ b/chromium_src/components/sync/engine_impl/syncer.h @@ -0,0 +1,6 @@ +#include "base/memory/weak_ptr.h" +#include "brave/components/brave_sync/jslib_messages_fwd.h" +namespace syncer { +class GetUpdatesProcessor; +} // namespace syncer +#include "../../../../../components/sync/engine_impl/syncer.h" diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc new file mode 100644 index 000000000000..50f2bff406a4 --- /dev/null +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -0,0 +1,108 @@ +namespace bookmarks { +class BookmarkModel; +class BookmarkNode; +} // namespace bookmarks + +namespace sync_bookmarks { +namespace { + +void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, + bookmarks::BookmarkModel* bookmark_model); + +} // namespace +} // namespace sync_bookmarks + +#include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" +#include "brave/components/brave_sync/tools.h" +#include "components/bookmarks/browser/bookmark_model.h" +namespace sync_bookmarks { +namespace { + +void GetPrevObjectId(const bookmarks::BookmarkNode* parent, + int index, + std::string* prev_object_id) { + DCHECK_GE(index, 0); + auto* prev_node = index == 0 ? + nullptr : + parent->GetChild(index - 1); + + if (prev_node) + prev_node->GetMetaInfo("object_id", prev_object_id); +} + +void GetOrder(const bookmarks::BookmarkNode* parent, + int index, + std::string* prev_order, + std::string* next_order, + std::string* parent_order) { + DCHECK_GE(index, 0); + auto* prev_node = index == 0 ? + nullptr : + parent->GetChild(index - 1); + auto* next_node = index == parent->child_count() - 1 ? + nullptr : + parent->GetChild(index + 1); + + if (prev_node) + prev_node->GetMetaInfo("order", prev_order); + + if (next_node) + next_node->GetMetaInfo("order", next_order); + + parent->GetMetaInfo("order", parent_order); +} + +void AddMetaInfo(bookmarks::BookmarkModel* bookmark_model, + const bookmarks::BookmarkNode* node, + const std::string& key, + const std::string& value) { + bookmark_model->SetNodeMetaInfo(node, key, value); +} + +void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, + bookmarks::BookmarkModel* bookmark_model) { + std::string prev_object_id; + int index = node->parent()->GetIndexOf(node); + GetPrevObjectId(node->parent(), index, &prev_object_id); + AddMetaInfo(bookmark_model, node, + "prev_object_id", prev_object_id); + + std::string parent_order; + std::string prev_order; + std::string next_order; + GetOrder(node->parent(), index, &prev_order, &next_order, &parent_order); + AddMetaInfo(bookmark_model, node, + "prev_order", prev_order); + AddMetaInfo(bookmark_model, node, + "next_order", next_order); + AddMetaInfo(bookmark_model, node, + "parent_order", parent_order); + // clear the order which will be calculated when sending + AddMetaInfo(bookmark_model, node, "order", std::string()); + + std::string object_id; + node->GetMetaInfo("object_id", &object_id); + // newly created node + if (object_id.empty()) { + object_id = brave_sync::tools::GenerateObjectId(); + } + AddMetaInfo(bookmark_model, node, + "object_id", object_id); + + std::string parent_object_id; + node->parent()->GetMetaInfo("object_id", &parent_object_id); + AddMetaInfo(bookmark_model, node, + "parent_object_id", parent_object_id); + + std::string sync_timestamp; + node->GetMetaInfo("sync_timestamp", &sync_timestamp); + if (sync_timestamp.empty()) { + sync_timestamp = std::to_string(base::Time::Now().ToJsTime()); + } + DCHECK(!sync_timestamp.empty()); + AddMetaInfo(bookmark_model, node, + "sync_timestamp", sync_timestamp); +} + +} // namespace +} // namespace sync_bookmarks diff --git a/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc b/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc new file mode 100644 index 000000000000..b343b1f005d9 --- /dev/null +++ b/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc @@ -0,0 +1,116 @@ +// This override is for kSyncUSSBookmarks +// TODO(darkdh): use same implementation as bookmark_change_processor.cc in the +// same file since we store objectId in meta info now +namespace bookmarks { +class BookmarkModel; +class BookmarkNode; +} // namespace bookmarks + +namespace sync_bookmarks { +class SyncedBookmarkTracker; +namespace { + +void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, + const SyncedBookmarkTracker* bookmark_tracker, + bookmarks::BookmarkModel* bookmark_model); + +} // namespace +} // namespace sync_bookmarks + +#include "../../../../components/sync_bookmarks/bookmark_local_changes_builder.cc" +#include "brave/components/brave_sync/tools.h" +#include "components/bookmarks/browser/bookmark_model.h" +namespace sync_bookmarks { +namespace { + +void GetPrevObjectId(const bookmarks::BookmarkNode* parent, + const SyncedBookmarkTracker* bookmark_tracker, + int index, + std::string* prev_object_id) { + DCHECK_GE(index, 0); + auto* prev_node = index == 0 ? + nullptr : + parent->GetChild(index - 1); + + if (prev_node) { + const SyncedBookmarkTracker::Entity* prev_entity = + bookmark_tracker->GetEntityForBookmarkNode(prev_node); + *prev_object_id = prev_entity->metadata()->server_id(); + } +} + +void GetOrder(const bookmarks::BookmarkNode* parent, + int index, + std::string* prev_order, + std::string* next_order, + std::string* parent_order) { + DCHECK_GE(index, 0); + auto* prev_node = index == 0 ? + nullptr : + parent->GetChild(index - 1); + auto* next_node = index == parent->child_count() - 1 ? + nullptr : + parent->GetChild(index + 1); + + if (prev_node) + prev_node->GetMetaInfo("order", prev_order); + + if (next_node) + next_node->GetMetaInfo("order", next_order); + + parent->GetMetaInfo("order", parent_order); +} + +void AddMetaInfo(bookmarks::BookmarkModel* bookmark_model, + const bookmarks::BookmarkNode* node, + const std::string& key, + const std::string& value) { + bookmark_model->SetNodeMetaInfo(node, key, value); +} + +void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, + const SyncedBookmarkTracker* bookmark_tracker, + bookmarks::BookmarkModel* bookmark_model) { + std::string prev_object_id; + int index = node->parent()->GetIndexOf(node); + GetPrevObjectId(node->parent(), bookmark_tracker, index, &prev_object_id); + AddMetaInfo(bookmark_model, node, + "prev_object_id", prev_object_id); + + std::string parent_order; + std::string prev_order; + std::string next_order; + GetOrder(node->parent(), index, &prev_order, &next_order, &parent_order); + AddMetaInfo(bookmark_model, node, + "prev_order", prev_order); + AddMetaInfo(bookmark_model, node, + "next_order", next_order); + AddMetaInfo(bookmark_model, node, + "parent_order", parent_order); + + std::string object_id; + node->GetMetaInfo("object_id", &object_id); + // newly created node + if (object_id.empty()) { + object_id = brave_sync::tools::GenerateObjectId(); + } + AddMetaInfo(bookmark_model, node, + "object_id", object_id); + + std::string parent_object_id; + node->parent()->GetMetaInfo("object_id", &parent_object_id); + AddMetaInfo(bookmark_model, node, + "parent_object_id", parent_object_id); + + std::string sync_timestamp; + node->GetMetaInfo("sync_timestamp", &sync_timestamp); + if (sync_timestamp.empty()) { + sync_timestamp = std::to_string(base::Time::Now().ToJsTime()); + } + DCHECK(!sync_timestamp.empty()); + AddMetaInfo(bookmark_model, node, + "sync_timestamp", sync_timestamp); +} + +} // namespace +} // namespace sync_bookmarks diff --git a/common/extensions/api/brave_sync.json b/common/extensions/api/brave_sync.json index 9f5210df07e2..bc8c8ba61cc8 100644 --- a/common/extensions/api/brave_sync.json +++ b/common/extensions/api/brave_sync.json @@ -46,6 +46,15 @@ "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", @@ -62,7 +71,8 @@ "order" : {"type": "string", "optional": true}, "prevOrder" : {"type": "string", "optional": true}, "nextOrder" : {"type": "string", "optional": true}, - "parentOrder" : {"type": "string", "optional": true} + "parentOrder" : {"type": "string", "optional": true}, + "metaInfo" : { "type": "array", "items": {"$ref" : "MetaInfo" }, "optional": true } } }, { diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index d7c466aa5b96..8ef811575960 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -80,8 +80,8 @@ source_set("core") { source_set("brave_sync") { sources = [ - "brave_sync_service_factory.h", - "brave_sync_service_factory.cc", + "brave_sync_service.cc", + "brave_sync_service.h", "brave_sync_service_observer.h", ] @@ -89,6 +89,7 @@ source_set("brave_sync") { ":core", "buildflags", "//base", + "//components/browser_sync", "//components/bookmarks/browser", "//components/keyed_service/content", "//components/keyed_service/core", diff --git a/components/brave_sync/brave_sync_prefs.cc b/components/brave_sync/brave_sync_prefs.cc index 65ed1fc7c72e..27c6b23a1476 100644 --- a/components/brave_sync/brave_sync_prefs.cc +++ b/components/brave_sync/brave_sync_prefs.cc @@ -9,6 +9,7 @@ #include "brave/components/brave_sync/settings.h" #include "brave/components/brave_sync/sync_devices.h" #include "components/prefs/pref_service.h" +#include "components/pref_registry/pref_registry_syncable.h" namespace brave_sync { namespace prefs { @@ -31,6 +32,26 @@ const char kSyncMigrateBookmarksVersion[] Prefs::Prefs(PrefService* pref_service) : pref_service_(pref_service) {} +void Prefs::RegisterProfilePrefs( + user_prefs::PrefRegistrySyncable* registry) { + registry->RegisterStringPref(prefs::kSyncDeviceId, std::string()); + registry->RegisterStringPref(prefs::kSyncSeed, std::string()); + registry->RegisterStringPref(prefs::kSyncPrevSeed, std::string()); + registry->RegisterStringPref(prefs::kSyncDeviceName, std::string()); + registry->RegisterStringPref(prefs::kSyncBookmarksBaseOrder, std::string()); + + registry->RegisterBooleanPref(prefs::kSyncEnabled, false); + registry->RegisterBooleanPref(prefs::kSyncBookmarksEnabled, false); + registry->RegisterBooleanPref(prefs::kSyncSiteSettingsEnabled, false); + registry->RegisterBooleanPref(prefs::kSyncHistoryEnabled, false); + + registry->RegisterTimePref(prefs::kSyncLatestRecordTime, base::Time()); + registry->RegisterTimePref(prefs::kSyncLastFetchTime, base::Time()); + + registry->RegisterStringPref(prefs::kSyncDeviceList, std::string()); + registry->RegisterStringPref(prefs::kSyncApiVersion, std::string("0")); +} + std::string Prefs::GetSeed() const { return pref_service_->GetString(kSyncSeed); } diff --git a/components/brave_sync/brave_sync_prefs.h b/components/brave_sync/brave_sync_prefs.h index 1941307950f7..b3f7380fc575 100644 --- a/components/brave_sync/brave_sync_prefs.h +++ b/components/brave_sync/brave_sync_prefs.h @@ -18,6 +18,10 @@ namespace base { class Time; } +namespace user_prefs { +class PrefRegistrySyncable; +} + namespace brave_sync { class Settings; @@ -62,6 +66,8 @@ class Prefs { public: explicit Prefs(PrefService* pref_service); + static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); + std::string GetSeed() const; void SetSeed(const std::string& seed); std::string GetPrevSeed() const; diff --git a/components/brave_sync/brave_sync_service.h b/components/brave_sync/brave_sync_service.h index a4e7c24dd586..cc381134af08 100644 --- a/components/brave_sync/brave_sync_service.h +++ b/components/brave_sync/brave_sync_service.h @@ -9,7 +9,6 @@ #include "base/macros.h" #include "base/observer_list.h" #include "components/bookmarks/browser/bookmark_storage.h" -#include "components/keyed_service/core/keyed_service.h" #include "extensions/buildflags/buildflags.h" class Profile; @@ -25,10 +24,10 @@ bookmarks::BookmarkPermanentNodeList LoadExtraNodes(bookmarks::LoadExtraCallback callback, int64_t* next_node_id); bool IsSyncManagedNode(const bookmarks::BookmarkPermanentNode* node); -class BraveSyncService : public KeyedService { +class BraveSyncService { public: BraveSyncService(); - ~BraveSyncService() override; + virtual ~BraveSyncService(); typedef base::Callback, std::unique_ptr)> @@ -58,7 +57,7 @@ class BraveSyncService : public KeyedService { static bool is_enabled(); #if BUILDFLAG(ENABLE_EXTENSIONS) - virtual BraveSyncClient* GetSyncClient() = 0; + virtual BraveSyncClient* GetBraveSyncClient() = 0; #endif diff --git a/components/brave_sync/brave_sync_service_impl.cc b/components/brave_sync/brave_sync_service_impl.cc index ad667dd67a7e..3b60c7795ff6 100644 --- a/components/brave_sync/brave_sync_service_impl.cc +++ b/components/brave_sync/brave_sync_service_impl.cc @@ -80,7 +80,7 @@ SyncRecordPtr PrepareResolvedDevice( } // namespace BraveSyncServiceImpl::BraveSyncServiceImpl(Profile* profile) : - sync_client_(BraveSyncClient::Create(this, profile)), + sync_client_(BraveSyncClient::Create(profile)), sync_initialized_(false), sync_words_(std::string()), profile_(profile), @@ -90,6 +90,7 @@ BraveSyncServiceImpl::BraveSyncServiceImpl(Profile* profile) : sync_client_.get(), sync_prefs_.get())), timer_(std::make_unique()) { + sync_client_->set_sync_message_handler(this); // Moniter syncs prefs required in GetSettingsAndDevices profile_pref_change_registrar_.Init(profile->GetPrefs()); profile_pref_change_registrar_.Add( @@ -126,7 +127,7 @@ BraveSyncServiceImpl::BraveSyncServiceImpl(Profile* profile) : BraveSyncServiceImpl::~BraveSyncServiceImpl() { } -BraveSyncClient* BraveSyncServiceImpl::GetSyncClient() { +BraveSyncClient* BraveSyncServiceImpl::GetBraveSyncClient() { return sync_client_.get(); } diff --git a/components/brave_sync/brave_sync_service_impl.h b/components/brave_sync/brave_sync_service_impl.h index 5bb61311c8a0..9cbbce409be8 100644 --- a/components/brave_sync/brave_sync_service_impl.h +++ b/components/brave_sync/brave_sync_service_impl.h @@ -15,6 +15,7 @@ #include "base/time/time.h" #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" +#include "components/keyed_service/core/keyed_service.h" #include "components/prefs/pref_change_registrar.h" FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkAdded); @@ -61,6 +62,7 @@ using SendDeviceSyncRecordCallback = base::OnceCallbackGetPrefs())), extension_loaded_(false), @@ -63,6 +60,12 @@ SyncMessageHandler* BraveSyncClientImpl::sync_message_handler() { return handler_; } +void BraveSyncClientImpl::set_sync_message_handler( + SyncMessageHandler* handler) { + DCHECK(handler); + handler_ = handler; +} + void BraveSyncClientImpl::SendGotInitData(const Uint8Array& seed, const Uint8Array& device_id, const client_data::Config& config, @@ -151,8 +154,10 @@ void BraveSyncClientImpl::OnSyncEnabledChanged() { void BraveSyncClientImpl::OnExtensionReady( content::BrowserContext* browser_context, const extensions::Extension* extension) { - if (extension->id() == brave_sync_extension_id) + if (extension->id() == brave_sync_extension_id) { + DCHECK(handler_); handler_->BackgroundSyncStarted(true); + } } void BraveSyncClientImpl::OnExtensionLoaded( @@ -170,6 +175,7 @@ void BraveSyncClientImpl::OnExtensionUnloaded( extensions::UnloadedExtensionReason reason) { if (extension->id() == brave_sync_extension_id) { extension_loaded_ = false; + DCHECK(handler_); handler_->BackgroundSyncStopped(true); } } diff --git a/components/brave_sync/client/brave_sync_client_impl.h b/components/brave_sync/client/brave_sync_client_impl.h index 45dc30c2c894..023811c81b7a 100644 --- a/components/brave_sync/client/brave_sync_client_impl.h +++ b/components/brave_sync/client/brave_sync_client_impl.h @@ -38,6 +38,7 @@ class BraveSyncClientImpl : public BraveSyncClient, // BraveSync to Browser messages SyncMessageHandler* sync_message_handler() override; + void set_sync_message_handler(SyncMessageHandler* handler) override; // Browser to BraveSync messages void SendGotInitData(const Uint8Array& seed, const Uint8Array& device_id, @@ -62,7 +63,7 @@ class BraveSyncClientImpl : public BraveSyncClient, friend class ::BraveSyncServiceTest; static void set_for_testing(BraveSyncClient* sync_client); - BraveSyncClientImpl(SyncMessageHandler* handler, Profile* profile); + explicit BraveSyncClientImpl(Profile* profile); void OnExtensionInitialized() override; void OnSyncEnabledChanged() override; diff --git a/components/brave_sync/client/client_ext_impl_data.cc b/components/brave_sync/client/client_ext_impl_data.cc index 5322044c99b8..f6256d582d09 100644 --- a/components/brave_sync/client/client_ext_impl_data.cc +++ b/components/brave_sync/client/client_ext_impl_data.cc @@ -65,6 +65,20 @@ std::unique_ptr FromExtSiteSetting( return site_setting; } +std::unique_ptr> FromExtMetaInfo( + const std::vector& ext_meta_info) { + auto meta_info = std::make_unique>(); + + for (auto& ext_meta : ext_meta_info) { + brave_sync::jslib::MetaInfo meta; + meta.key = ext_meta.key; + meta.value = ext_meta.value; + meta_info->push_back(meta); + } + + return meta_info; +} + std::unique_ptr FromExtBookmark( const extensions::api::brave_sync::Bookmark &ext_bookmark) { auto bookmark = std::make_unique(); @@ -85,6 +99,9 @@ std::unique_ptr FromExtBookmark( if (ext_bookmark.order) { bookmark->order = *ext_bookmark.order; } + if (ext_bookmark.meta_info) { + bookmark->metaInfo = std::move(*FromExtMetaInfo(*ext_bookmark.meta_info)); + } return bookmark; } @@ -103,6 +120,21 @@ std::unique_ptr FromLibSite( return ext_site; } +std::unique_ptr> +FromLibMetaInfo(const std::vector& lib_metaInfo) { + auto ext_meta_info = + std::make_unique>(); + + for (auto& metaInfo : lib_metaInfo) { + auto meta_info = std::make_unique(); + meta_info->key = metaInfo.key; + meta_info->value = metaInfo.value; + ext_meta_info->push_back(std::move(*meta_info)); + } + + return ext_meta_info; +} + std::unique_ptr FromLibBookmark( const jslib::Bookmark &lib_bookmark) { auto ext_bookmark = std::make_unique(); @@ -141,6 +173,10 @@ std::unique_ptr FromLibBookmark( ext_bookmark->parent_order.reset(new std::string(lib_bookmark.parentOrder)); + if (!lib_bookmark.metaInfo.empty()) { + ext_bookmark->meta_info = FromLibMetaInfo(lib_bookmark.metaInfo); + } + return ext_bookmark; } diff --git a/components/brave_sync/jslib_messages.cc b/components/brave_sync/jslib_messages.cc index 9653f63c0004..8f99471e5b3b 100644 --- a/components/brave_sync/jslib_messages.cc +++ b/components/brave_sync/jslib_messages.cc @@ -26,6 +26,19 @@ std::unique_ptr Site::Clone(const Site& site) { return std::make_unique(site); } +MetaInfo::MetaInfo() = default; + +MetaInfo::MetaInfo(const MetaInfo& metaInfo) { + key = metaInfo.key; + value = metaInfo.value; +} + +MetaInfo::~MetaInfo() = default; + +std::unique_ptr MetaInfo::Clone(const MetaInfo& metaInfo) { + return std::make_unique(metaInfo); +} + Bookmark::Bookmark() : isFolder(false), hideInToolbar(false) {} Bookmark::Bookmark(const Bookmark& bookmark) { @@ -35,6 +48,7 @@ Bookmark::Bookmark(const Bookmark& bookmark) { fields = bookmark.fields; hideInToolbar = bookmark.hideInToolbar; order = bookmark.order; + metaInfo = bookmark.metaInfo; } Bookmark::~Bookmark() = default; @@ -141,6 +155,11 @@ const Device& SyncRecord::GetDevice() const { return *device_.get(); } +Bookmark* SyncRecord::mutable_bookmark() { + DCHECK(has_bookmark()); + return bookmark_.get(); +} + void SyncRecord::SetBookmark(std::unique_ptr bookmark) { DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && !has_device()); bookmark_ = std::move(bookmark); diff --git a/components/brave_sync/jslib_messages.h b/components/brave_sync/jslib_messages.h index 9fe963eb3dbe..2112a44bd9c3 100644 --- a/components/brave_sync/jslib_messages.h +++ b/components/brave_sync/jslib_messages.h @@ -37,6 +37,17 @@ class Site { std::string favicon; }; +class MetaInfo { +public: + MetaInfo(); + MetaInfo(const MetaInfo& metaInfo); + ~MetaInfo(); + static std::unique_ptr Clone(const MetaInfo& metaInfo); + + std::string key; + std::string value; +}; + class Bookmark { public: Bookmark(); @@ -54,6 +65,7 @@ class Bookmark { std::string prevOrder; std::string nextOrder; std::string parentOrder; + std::vector metaInfo; }; class SiteSetting { @@ -131,6 +143,7 @@ class SyncRecord { const Site& GetHistorySite() const; const SiteSetting& GetSiteSetting() const; const Device& GetDevice() const; + Bookmark* mutable_bookmark(); void SetBookmark(std::unique_ptr bookmark); void SetHistorySite(std::unique_ptr history_site); diff --git a/components/brave_sync/jslib_messages_fwd.h b/components/brave_sync/jslib_messages_fwd.h index 43274a279d37..b749439be9a5 100644 --- a/components/brave_sync/jslib_messages_fwd.h +++ b/components/brave_sync/jslib_messages_fwd.h @@ -5,6 +5,8 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SYNC_JSLIB_MESSAGES_FWD_H_ #define BRAVE_COMPONENTS_BRAVE_SYNC_JSLIB_MESSAGES_FWD_H_ +#include "base/callback.h" +#include "base/synchronization/waitable_event.h" #include "build/build_config.h" // TODO(darkdh): forward declaration with unique_ptr on Windows @@ -18,6 +20,10 @@ class SyncRecord; } #endif +namespace syncer { +class Syncer; +} // namespace syncer + namespace brave_sync { typedef std::unique_ptr SyncRecordPtr; @@ -28,6 +34,12 @@ typedef std::unique_ptr SyncRecordAndExistingPtr; typedef std::vector SyncRecordAndExistingList; using Uint8Array = std::vector; +using GetRecordsCallback = + base::RepeatingCallback)>; +using NudgeSyncCycleDelegate = + base::Callback; +using PollSyncCycleDelegate = + base::Callback; } // namespace brave_sync diff --git a/patches/chrome-browser-sync-chrome_sync_client.cc.patch b/patches/chrome-browser-sync-chrome_sync_client.cc.patch new file mode 100644 index 000000000000..1884ca97b8c1 --- /dev/null +++ b/patches/chrome-browser-sync-chrome_sync_client.cc.patch @@ -0,0 +1,14 @@ +diff --git a/chrome/browser/sync/chrome_sync_client.cc b/chrome/browser/sync/chrome_sync_client.cc +index 8c36199a7b7514d1ac5e710a938287a167da91a5..50e07746517364f85c93ee6feae38eea16de7892 100644 +--- a/chrome/browser/sync/chrome_sync_client.cc ++++ b/chrome/browser/sync/chrome_sync_client.cc +@@ -159,7 +159,8 @@ syncer::ModelTypeSet GetDisabledTypesFromCommandLine() { + + } // namespace + +-ChromeSyncClient::ChromeSyncClient(Profile* profile) : profile_(profile) {} ++ChromeSyncClient::ChromeSyncClient(Profile* profile) : profile_(profile), ++ brave_sync_client_(brave_sync::BraveSyncClient::Create(profile)) {} + + ChromeSyncClient::~ChromeSyncClient() { + } diff --git a/patches/chrome-browser-sync-chrome_sync_client.h.patch b/patches/chrome-browser-sync-chrome_sync_client.h.patch new file mode 100644 index 000000000000..2010b44ec7c6 --- /dev/null +++ b/patches/chrome-browser-sync-chrome_sync_client.h.patch @@ -0,0 +1,21 @@ +diff --git a/chrome/browser/sync/chrome_sync_client.h b/chrome/browser/sync/chrome_sync_client.h +index ae728503c195e1c9cf6da57ce08641632d8ae3ae..5ddf2944e4393f270cb53bc926f36f49c303bcbf 100644 +--- a/chrome/browser/sync/chrome_sync_client.h ++++ b/chrome/browser/sync/chrome_sync_client.h +@@ -62,6 +62,7 @@ class ChromeSyncClient : public syncer::SyncClient { + scoped_refptr CreateModelWorkerForGroup( + syncer::ModelSafeGroup group) override; + syncer::SyncApiComponentFactory* GetSyncApiComponentFactory() override; ++ brave_sync::BraveSyncClient* GetBraveSyncClient() override; + + // Helpers for overriding getters in tests. + void SetSyncApiComponentFactoryForTesting( +@@ -85,6 +86,8 @@ class ChromeSyncClient : public syncer::SyncClient { + // Generates and monitors the ExtensionsActivity object used by sync. + ExtensionsActivityMonitor extensions_activity_monitor_; + ++ std::unique_ptr brave_sync_client_; ++ + DISALLOW_COPY_AND_ASSIGN(ChromeSyncClient); + }; + diff --git a/patches/components-browser_sync-profile_sync_service.cc.patch b/patches/components-browser_sync-profile_sync_service.cc.patch new file mode 100644 index 000000000000..1ee11304d142 --- /dev/null +++ b/patches/components-browser_sync-profile_sync_service.cc.patch @@ -0,0 +1,84 @@ +diff --git a/components/browser_sync/profile_sync_service.cc b/components/browser_sync/profile_sync_service.cc +index a0355393caba17c8343ec2a771eeb29d731d27e4..08a9666b1ac5fcd6c6ab737b2874afc331e02a69 100644 +--- a/components/browser_sync/profile_sync_service.cc ++++ b/components/browser_sync/profile_sync_service.cc +@@ -198,6 +198,8 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK(sync_client_); + ++ BraveSyncSetup(); ++ + // If Sync is disabled via command line flag, then ProfileSyncService + // shouldn't be instantiated. + DCHECK(IsSyncAllowedByFlag()); +@@ -539,7 +541,10 @@ void ProfileSyncService::StartUpSlowEngineComponents() { + ->GetLocalDeviceInfoProvider() + ->GetSyncUserAgent(); + params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); +- params.credentials = auth_manager_->GetCredentials(); ++ if (IsBraveSyncEnabled()) ++ params.credentials = GetDummyCredentials(); ++ else ++ params.credentials = auth_manager_->GetCredentials(); + DCHECK(!params.credentials.account_id.empty() || IsLocalSyncEnabled()); + if (!base::FeatureList::IsEnabled(switches::kSyncE2ELatencyMeasurement)) { + invalidation::InvalidationService* invalidator = +@@ -571,13 +576,14 @@ void ProfileSyncService::StartUpSlowEngineComponents() { + params.short_poll_interval = sync_prefs_.GetShortPollInterval(); + if (params.short_poll_interval.is_zero()) { + params.short_poll_interval = +- base::TimeDelta::FromSeconds(syncer::kDefaultShortPollIntervalSeconds); ++ base::TimeDelta::FromSeconds(syncer::kBraveDefaultShortPollIntervalSeconds); + } + params.long_poll_interval = sync_prefs_.GetLongPollInterval(); + if (params.long_poll_interval.is_zero()) { + params.long_poll_interval = +- base::TimeDelta::FromSeconds(syncer::kDefaultLongPollIntervalSeconds); ++ base::TimeDelta::FromSeconds(syncer::kBraveDefaultLongPollIntervalSeconds); + } ++ BraveEngineParamsInit(¶ms); + + engine_->Initialize(std::move(params)); + +@@ -721,6 +727,7 @@ int ProfileSyncService::GetDisableReasons() const { + DCHECK(IsSyncAllowedByFlag()); + + int result = DISABLE_REASON_NONE; ++ if (IsBraveSyncEnabled()) return result; + if (!user_settings_->IsSyncAllowedByPlatform()) { + result = result | DISABLE_REASON_PLATFORM_OVERRIDE; + } +@@ -1465,7 +1472,7 @@ void ProfileSyncService::ConfigureDataTypeManager( + // Note: When local Sync is enabled, then we want full-sync mode (not just + // transport), even though Sync-the-feature is not considered enabled. + bool use_transport_only_mode = +- !IsSyncFeatureEnabled() && !IsLocalSyncEnabled(); ++ !IsSyncFeatureEnabled() && !IsLocalSyncEnabled() && !IsBraveSyncEnabled(); + + syncer::ModelTypeSet types = GetPreferredDataTypes(); + // In transport-only mode, only a subset of data types is supported. +@@ -1860,6 +1867,7 @@ void ProfileSyncService::GetAllNodes( + + syncer::ModelTypeSet all_types = GetActiveDataTypes(); + all_types.PutAll(syncer::ControlTypes()); ++ + scoped_refptr helper = + new GetAllNodesRequestHelper(all_types, callback); + +@@ -1891,12 +1899,14 @@ void ProfileSyncService::GetAllNodes( + + AccountInfo ProfileSyncService::GetAuthenticatedAccountInfo() const { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +- return auth_manager_->GetActiveAccountInfo().account_info; ++ return GetDummyAccountInfo(); ++ // return auth_manager_->GetActiveAccountInfo().account_info; + } + + bool ProfileSyncService::IsAuthenticatedAccountPrimary() const { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +- return auth_manager_->GetActiveAccountInfo().is_primary; ++ return true; ++ // return auth_manager_->GetActiveAccountInfo().is_primary; + } + + void ProfileSyncService::SetInvalidationsForSessionsEnabled(bool enabled) { diff --git a/patches/components-browser_sync-profile_sync_service.h.patch b/patches/components-browser_sync-profile_sync_service.h.patch new file mode 100644 index 000000000000..d3a0f3a01e22 --- /dev/null +++ b/patches/components-browser_sync-profile_sync_service.h.patch @@ -0,0 +1,122 @@ +diff --git a/components/browser_sync/profile_sync_service.h b/components/browser_sync/profile_sync_service.h +index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3e3f63167 100644 +--- a/components/browser_sync/profile_sync_service.h ++++ b/components/browser_sync/profile_sync_service.h +@@ -138,7 +138,9 @@ class ProfileSyncService : public syncer::SyncService, + public syncer::SyncPrefObserver, + public syncer::DataTypeManagerObserver, + public syncer::UnrecoverableErrorHandler, +- public identity::IdentityManager::Observer { ++ public identity::IdentityManager::Observer, ++ public brave_sync::BraveSyncService, ++ public brave_sync::SyncMessageHandler { + public: + // If AUTO_START, sync will set IsFirstSetupComplete() automatically and sync + // will begin syncing without the user needing to confirm sync settings. +@@ -368,6 +370,43 @@ class ProfileSyncService : public syncer::SyncService, + + syncer::SyncClient* GetSyncClientForTest(); + ++ //TODO(darkdh): subclass ProfileSyncService ++ brave_sync::BraveSyncClient* GetBraveSyncClient() override; ++ // BraveSyncService messages from UI ++ void OnSetupSyncHaveCode(const std::string& sync_words, ++ const std::string& device_name) override; ++ void OnSetupSyncNewToSync(const std::string& device_name) override; ++ void OnDeleteDevice(const std::string& device_id) override; ++ void OnResetSync() override; ++ void GetSettingsAndDevices( ++ const GetSettingsAndDevicesCallback& callback) override; ++ void GetSyncWords() override; ++ std::string GetSeed() override; ++ void OnSetSyncEnabled(const bool sync_this_device) override; ++ void OnSetSyncBookmarks(const bool sync_bookmarks) override; ++ void OnSetSyncBrowsingHistory(const bool sync_browsing_history) override; ++ void OnSetSyncSavedSiteSettings(const bool sync_saved_site_settings) override; ++ ++ // SyncMessageHandler overrides ++ void BackgroundSyncStarted(bool startup) override; ++ void BackgroundSyncStopped(bool shutdown) override; ++ void OnSyncDebug(const std::string& message) override; ++ void OnSyncSetupError(const std::string& error) override; ++ void OnGetInitData(const std::string& sync_version) override; ++ void OnSaveInitData(const brave_sync::Uint8Array& seed, ++ const brave_sync::Uint8Array& device_id) override; ++ void OnSyncReady() override; ++ void OnGetExistingObjects(const std::string& category_name, ++ std::unique_ptr records, ++ const base::Time &last_record_time_stamp, ++ const bool is_truncated) override; ++ void OnResolvedSyncRecords(const std::string& category_name, ++ std::unique_ptr records) override; ++ void OnDeletedSyncUser() override; ++ void OnDeleteSyncSiteSettings() override; ++ void OnSaveBookmarksBaseOrder(const std::string& order) override; ++ void OnSyncWordsPrepared(const std::string& words) override; ++ + private: + // Passed as an argument to StopImpl to control whether or not the sync + // engine should clear its data directory when it shuts down. See StopImpl +@@ -377,6 +416,28 @@ class ProfileSyncService : public syncer::SyncService, + CLEAR_DATA, + }; + ++ bool IsBraveSyncEnabled() const; ++ void BraveSyncSetup(); ++ void BraveEngineParamsInit(syncer::SyncEngine::InitParams*); ++ void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); ++ void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, ++ base::WaitableEvent* wevent); ++ void FetchSyncRecords(const bool bookmarks, const bool history, ++ const bool preferences, int max_records); ++ void SendCreateDevice(); ++ void SendDeviceSyncRecord( ++ const int action, ++ const std::string& device_name, ++ const std::string& device_id, ++ const std::string& object_id); ++ void OnResolvedPreferences(const brave_sync::RecordsList& records); ++ void OnBraveSyncPrefsChanged(const std::string& pref); ++ void NotifySyncSetupError(const std::string& error); ++ void NotifySyncStateChanged(); ++ void NotifyHaveSyncWords(const std::string& sync_words); ++ ++ void ResetSyncInternal(); ++ + // Shorthand for user_settings_.IsFirstSetupComplete(). + bool IsFirstSetupComplete() const; + +@@ -506,6 +567,8 @@ class ProfileSyncService : public syncer::SyncService, + // The class that handles getting, setting, and persisting sync preferences. + syncer::SyncPrefs sync_prefs_; + ++ std::unique_ptr brave_sync_prefs_; ++ + // Encapsulates user signin - used to set/get the user's authenticated + // email address and sign-out upon error. + identity::IdentityManager* const identity_manager_; +@@ -638,6 +701,24 @@ class ProfileSyncService : public syncer::SyncService, + // sync is stopped after a callback from |user_settings_|). + bool is_stopping_and_clearing_; + ++ // True when is in active sync chain ++ bool brave_sync_configured_ = false; ++ ++ // True if we have received SyncReady from JS lib ++ bool brave_sync_initialized_ = false; ++ ++ // Prevent two sequential calls OnSetupSyncHaveCode or OnSetupSyncNewToSync ++ // while being initializing ++ bool brave_sync_initializing_ = false; ++ ++ std::string brave_sync_words_; ++ ++ brave_sync::GetRecordsCallback get_record_cb_; ++ base::WaitableEvent* wevent_; ++ ++ // Registrar used to monitor the brave_profile prefs. ++ PrefChangeRegistrar brave_pref_change_registrar_; ++ + // This weak factory invalidates its issued pointers when Sync is disabled. + base::WeakPtrFactory sync_enabled_weak_factory_; + diff --git a/patches/components-sync-driver-data_type_manager_impl.cc.patch b/patches/components-sync-driver-data_type_manager_impl.cc.patch new file mode 100644 index 000000000000..d52d8a315fea --- /dev/null +++ b/patches/components-sync-driver-data_type_manager_impl.cc.patch @@ -0,0 +1,14 @@ +diff --git a/components/sync/driver/data_type_manager_impl.cc b/components/sync/driver/data_type_manager_impl.cc +index ea180493bb90741e1601391bb5b1a0a5e11b9303..eda3e4328549761dfe286f9e72f49071e72698d3 100644 +--- a/components/sync/driver/data_type_manager_impl.cc ++++ b/components/sync/driver/data_type_manager_impl.cc +@@ -611,7 +611,8 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( + DCHECK(Intersection(downloaded_types_, types_to_journal).Empty()); + DCHECK(Intersection(downloaded_types_, crypto_types).Empty()); + // |downloaded_types_| was already updated to include all enabled types. +- DCHECK(downloaded_types_.HasAll(types_to_download)); ++ // TODO(darkdh): fix Control Type download ++ // DCHECK(downloaded_types_.HasAll(types_to_download)); + + DVLOG(1) << "Types " << ModelTypeSetToString(types_to_download) + << " added; calling ConfigureDataTypes"; diff --git a/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch b/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch new file mode 100644 index 000000000000..15bbaee9f7cf --- /dev/null +++ b/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch @@ -0,0 +1,32 @@ +diff --git a/components/sync/driver/glue/sync_backend_host_core.cc b/components/sync/driver/glue/sync_backend_host_core.cc +index 2bbe1dadae8202bb35eaac9fa069d6ab12b08ce6..c5fc10b4bffdd1030a0659ad0a3f250b62713682 100644 +--- a/components/sync/driver/glue/sync_backend_host_core.cc ++++ b/components/sync/driver/glue/sync_backend_host_core.cc +@@ -354,6 +354,7 @@ void SyncBackendHostCore::DoInitialize(SyncEngine::InitParams params) { + args.saved_nigori_state = std::move(params.saved_nigori_state); + args.short_poll_interval = params.short_poll_interval; + args.long_poll_interval = params.long_poll_interval; ++ BraveInit(&args); + sync_manager_->Init(&args); + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( + this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get()); +@@ -413,12 +414,13 @@ void SyncBackendHostCore::DoInitialProcessControlTypes() { + return; + } + +- if (!sync_manager_->InitialSyncEndedTypes().HasAll(ControlTypes())) { +- LOG(ERROR) << "Failed to download control types"; +- host_.Call(FROM_HERE, +- &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); +- return; +- } ++ // TODO(darkdh): move device record into control type ++ // if (!sync_manager_->InitialSyncEndedTypes().HasAll(ControlTypes())) { ++ // LOG(ERROR) << "Failed to download control types"; ++ // host_.Call(FROM_HERE, ++ // &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); ++ // return; ++ // } + + DCHECK_EQ(user_share->directory->cache_guid(), sync_manager_->cache_guid()); + host_.Call(FROM_HERE, diff --git a/patches/components-sync-driver-glue-sync_backend_host_core.h.patch b/patches/components-sync-driver-glue-sync_backend_host_core.h.patch new file mode 100644 index 000000000000..78f51aa859e2 --- /dev/null +++ b/patches/components-sync-driver-glue-sync_backend_host_core.h.patch @@ -0,0 +1,24 @@ +diff --git a/components/sync/driver/glue/sync_backend_host_core.h b/components/sync/driver/glue/sync_backend_host_core.h +index dced9de5a2081185acb22c900e69e90080e54cdf..0f4b0822bb819c0b505eab58d7ea503e39490d4d 100644 +--- a/components/sync/driver/glue/sync_backend_host_core.h ++++ b/components/sync/driver/glue/sync_backend_host_core.h +@@ -176,11 +176,19 @@ class SyncBackendHostCore + + bool HasUnsyncedItemsForTest() const; + ++ void DoDispatchGetRecordsCallback(GetRecordsCallback cb, ++ std::unique_ptr records); ++ + private: + friend class base::RefCountedThreadSafe; + + ~SyncBackendHostCore() override; + ++ void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); ++ void OnPollSyncCycle(GetRecordsCallback cb, ++ base::WaitableEvent* wevent); ++ void BraveInit(SyncManager::InitArgs* args); ++ + // Invoked when initialization of syncapi is complete and we can start + // our timer. + // This must be called from the thread on which SaveChanges is intended to diff --git a/patches/components-sync-driver-glue-sync_backend_host_impl.cc.patch b/patches/components-sync-driver-glue-sync_backend_host_impl.cc.patch new file mode 100644 index 000000000000..4e2573a9e2de --- /dev/null +++ b/patches/components-sync-driver-glue-sync_backend_host_impl.cc.patch @@ -0,0 +1,15 @@ +diff --git a/components/sync/driver/glue/sync_backend_host_impl.cc b/components/sync/driver/glue/sync_backend_host_impl.cc +index 4c0bb4d0d0af424b46dd0cb1ab7bf38c7018b8a0..760b6a839fc7f8d4f68d187b96c54277dbca37d6 100644 +--- a/components/sync/driver/glue/sync_backend_host_impl.cc ++++ b/components/sync/driver/glue/sync_backend_host_impl.cc +@@ -70,6 +70,10 @@ void SyncBackendHostImpl::Initialize(InitParams params) { + sync_task_runner_ = params.sync_task_runner; + host_ = params.host; + registrar_ = params.registrar.get(); ++ nudge_sync_cycle_delegate_function_ = ++ params.nudge_sync_cycle_delegate_function; ++ poll_sync_cycle_delegate_function_ = ++ params.poll_sync_cycle_delegate_function; + + sync_task_runner_->PostTask( + FROM_HERE, base::BindOnce(&SyncBackendHostCore::DoInitialize, core_, diff --git a/patches/components-sync-driver-glue-sync_backend_host_impl.h.patch b/patches/components-sync-driver-glue-sync_backend_host_impl.h.patch new file mode 100644 index 000000000000..7b787a6f0411 --- /dev/null +++ b/patches/components-sync-driver-glue-sync_backend_host_impl.h.patch @@ -0,0 +1,27 @@ +diff --git a/components/sync/driver/glue/sync_backend_host_impl.h b/components/sync/driver/glue/sync_backend_host_impl.h +index c9a8f8fd314da2b7b7621d5af97326b4241e6493..2e16d98f56a3a31c7d5af1315665253c8b4b3c5a 100644 +--- a/components/sync/driver/glue/sync_backend_host_impl.h ++++ b/components/sync/driver/glue/sync_backend_host_impl.h +@@ -154,6 +154,12 @@ class SyncBackendHostImpl : public SyncEngine, public InvalidationHandler { + ModelType type, + const StatusCounters& counters); + ++ void HandleNudgeSyncCycle(brave_sync::RecordsListPtr records_list); ++ void HandlePollSyncCycle(GetRecordsCallback cb, ++ base::WaitableEvent* wevent); ++ void DispatchGetRecordsCallback( ++ GetRecordsCallback cb, std::unique_ptr records) override; ++ + // Overwrites the kSyncInvalidationVersions preference with the most recent + // set of invalidation versions for each type. + void UpdateInvalidationVersions( +@@ -229,6 +235,9 @@ class SyncBackendHostImpl : public SyncEngine, public InvalidationHandler { + ModelTypeSet last_enabled_types_; + bool sessions_invalidation_enabled_ = false; + ++ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function_; ++ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function_; ++ + // Checks that we're on the same thread this was constructed on (UI thread). + SEQUENCE_CHECKER(sequence_checker_); + diff --git a/patches/components-sync-driver-sync_client.h.patch b/patches/components-sync-driver-sync_client.h.patch new file mode 100644 index 000000000000..9935988a3a87 --- /dev/null +++ b/patches/components-sync-driver-sync_client.h.patch @@ -0,0 +1,13 @@ +diff --git a/components/sync/driver/sync_client.h b/components/sync/driver/sync_client.h +index d38f986e2c55ab20453e868f934cb7f5e7982de1..b2f9685d2129a1325e541aefbdbe0a476d58c2eb 100644 +--- a/components/sync/driver/sync_client.h ++++ b/components/sync/driver/sync_client.h +@@ -110,6 +110,8 @@ class SyncClient { + // Returns the current SyncApiComponentFactory instance. + virtual SyncApiComponentFactory* GetSyncApiComponentFactory() = 0; + ++ virtual brave_sync::BraveSyncClient* GetBraveSyncClient() = 0; ++ + private: + DISALLOW_COPY_AND_ASSIGN(SyncClient); + }; diff --git a/patches/components-sync-engine-sync_engine.h.patch b/patches/components-sync-engine-sync_engine.h.patch new file mode 100644 index 000000000000..59f57b71121c --- /dev/null +++ b/patches/components-sync-engine-sync_engine.h.patch @@ -0,0 +1,24 @@ +diff --git a/components/sync/engine/sync_engine.h b/components/sync/engine/sync_engine.h +index 826cc5072e20b1760a64e8edca2933e83f797730..0a3187d2ae99e3f8b5e60ac289891a1d8b8112bd 100644 +--- a/components/sync/engine/sync_engine.h ++++ b/components/sync/engine/sync_engine.h +@@ -82,6 +82,8 @@ class SyncEngine : public ModelTypeConfigurer { + // Define the polling intervals. Must not be zero. + base::TimeDelta short_poll_interval; + base::TimeDelta long_poll_interval; ++ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; ++ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function; + + private: + DISALLOW_COPY_AND_ASSIGN(InitParams); +@@ -191,6 +193,10 @@ class SyncEngine : public ModelTypeConfigurer { + // Enables/Disables invalidations for session sync related datatypes. + virtual void SetInvalidationsForSessionsEnabled(bool enabled) = 0; + ++ virtual void DispatchGetRecordsCallback( ++ brave_sync::GetRecordsCallback cb, ++ std::unique_ptr records) {}; ++ + private: + DISALLOW_COPY_AND_ASSIGN(SyncEngine); + }; diff --git a/patches/components-sync-engine-sync_manager.h.patch b/patches/components-sync-engine-sync_manager.h.patch new file mode 100644 index 000000000000..4a243f0410cb --- /dev/null +++ b/patches/components-sync-engine-sync_manager.h.patch @@ -0,0 +1,14 @@ +diff --git a/components/sync/engine/sync_manager.h b/components/sync/engine/sync_manager.h +index 514b05be4efe57ec9ae24c99186455456e56793b..0f2f3456c249aea0738c4d8da45b4ecce52f96d5 100644 +--- a/components/sync/engine/sync_manager.h ++++ b/components/sync/engine/sync_manager.h +@@ -250,6 +250,9 @@ class SyncManager { + // Define the polling intervals. Must not be zero. + base::TimeDelta short_poll_interval; + base::TimeDelta long_poll_interval; ++ ++ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; ++ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function; + }; + + // The state of sync the feature. If the user turned on sync explicitly, it diff --git a/patches/components-sync-engine_impl-commit.cc.patch b/patches/components-sync-engine_impl-commit.cc.patch new file mode 100644 index 000000000000..95afab704039 --- /dev/null +++ b/patches/components-sync-engine_impl-commit.cc.patch @@ -0,0 +1,16 @@ +diff --git a/components/sync/engine_impl/commit.cc b/components/sync/engine_impl/commit.cc +index c17988c44c5e5687549f8a18f8cd00b56da43422..be3e56546ce19abac3b8a5b470123ceb5c8b11f0 100644 +--- a/components/sync/engine_impl/commit.cc ++++ b/components/sync/engine_impl/commit.cc +@@ -130,8 +130,9 @@ SyncerError Commit::PostAndProcessResponse( + + TRACE_EVENT_BEGIN0("sync", "PostCommit"); + sync_pb::ClientToServerResponse response; +- const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( +- &message_, &response, cycle, nullptr); ++ // const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( ++ // &message_, &response, cycle, nullptr); ++ const SyncerError post_result = PostBraveCommit(&message_, &response, cycle); + TRACE_EVENT_END0("sync", "PostCommit"); + + // TODO(rlarocque): Use result that includes errors captured later? diff --git a/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch b/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch new file mode 100644 index 000000000000..f8e3a1d2df99 --- /dev/null +++ b/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch @@ -0,0 +1,15 @@ +diff --git a/components/sync/engine_impl/cycle/sync_cycle.h b/components/sync/engine_impl/cycle/sync_cycle.h +index b41478d4cf2c1f3ee5a0e7effc43fe21b6184383..6c3b5a6972cf80cb5597f570bcc4c3abc0de9555 100644 +--- a/components/sync/engine_impl/cycle/sync_cycle.h ++++ b/components/sync/engine_impl/cycle/sync_cycle.h +@@ -84,6 +84,10 @@ class SyncCycle { + // Called when server requests a migration. + virtual void OnReceivedMigrationRequest(ModelTypeSet types) = 0; + ++ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) {} ++ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, ++ base::WaitableEvent* wevent) {} ++ + protected: + virtual ~Delegate() {} + }; diff --git a/patches/components-sync-engine_impl-get_updates_processor.cc.patch b/patches/components-sync-engine_impl-get_updates_processor.cc.patch new file mode 100644 index 000000000000..e4fcdf6788e7 --- /dev/null +++ b/patches/components-sync-engine_impl-get_updates_processor.cc.patch @@ -0,0 +1,33 @@ +diff --git a/components/sync/engine_impl/get_updates_processor.cc b/components/sync/engine_impl/get_updates_processor.cc +index df71de3ef237e61b5cda7d96fe3a24a8f8f1bf6f..e0d3d7d6b04a68e58585494eb59799f3db52eb60 100644 +--- a/components/sync/engine_impl/get_updates_processor.cc ++++ b/components/sync/engine_impl/get_updates_processor.cc +@@ -28,6 +28,7 @@ using TypeSyncEntityMap = std::map; + using TypeToIndexMap = std::map; + + bool ShouldRequestEncryptionKey(SyncCycleContext* context) { ++ return false; + syncable::Directory* dir = context->directory(); + syncable::ReadTransaction trans(FROM_HERE, dir); + syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler(); +@@ -37,6 +38,7 @@ bool ShouldRequestEncryptionKey(SyncCycleContext* context) { + SyncerError HandleGetEncryptionKeyResponse( + const sync_pb::ClientToServerResponse& update_response, + syncable::Directory* dir) { ++ return SyncerError(SyncerError::SYNCER_OK); + bool success = false; + if (update_response.get_updates().encryption_keys_size() == 0) { + LOG(ERROR) << "Failed to receive encryption key from server."; +@@ -220,8 +222,10 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( + + ModelTypeSet partial_failure_data_types; + +- SyncerError result = SyncerProtoUtil::PostClientToServerMessage( +- msg, &update_response, cycle, &partial_failure_data_types); ++ // SyncerError result = SyncerProtoUtil::PostClientToServerMessage( ++ // msg, &update_response, cycle, &partial_failure_data_types); ++ SyncerError result = ApplyBraveRecords(&update_response, request_types, ++ std::move(brave_records_)); + + DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( + update_response); diff --git a/patches/components-sync-engine_impl-get_updates_processor.h.patch b/patches/components-sync-engine_impl-get_updates_processor.h.patch new file mode 100644 index 000000000000..b96a2a52dbc8 --- /dev/null +++ b/patches/components-sync-engine_impl-get_updates_processor.h.patch @@ -0,0 +1,22 @@ +diff --git a/components/sync/engine_impl/get_updates_processor.h b/components/sync/engine_impl/get_updates_processor.h +index c5560ec8113670c57f80245199031732f5795f23..29491b1919e38c21efe2194910070f55c3fcb276 100644 +--- a/components/sync/engine_impl/get_updates_processor.h ++++ b/components/sync/engine_impl/get_updates_processor.h +@@ -45,6 +45,8 @@ class GetUpdatesProcessor { + // server, or an appropriate error value in case of failure. + SyncerError DownloadUpdates(ModelTypeSet* request_types, SyncCycle* cycle); + ++ void AddBraveRecords(std::unique_ptr records); ++ + // Applies any downloaded and processed updates. + void ApplyUpdates(const ModelTypeSet& gu_types, + StatusController* status_controller); +@@ -96,6 +98,8 @@ class GetUpdatesProcessor { + + const GetUpdatesDelegate& delegate_; + ++ std::unique_ptr brave_records_; ++ + DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessor); + }; + diff --git a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch new file mode 100644 index 000000000000..9031bb5ba31d --- /dev/null +++ b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/sync/engine_impl/sync_manager_impl.cc b/components/sync/engine_impl/sync_manager_impl.cc +index a35bf89947af81e071f788458b8298448ee6d442..a01af29dd5ce191a98df575376e941d3bcf8029f 100644 +--- a/components/sync/engine_impl/sync_manager_impl.cc ++++ b/components/sync/engine_impl/sync_manager_impl.cc +@@ -304,6 +304,8 @@ void SyncManagerImpl::Init(InitArgs* args) { + name_, cycle_context_.get(), args->cancelation_signal, + args->enable_local_sync_backend); + ++ BraveInit(args); ++ + scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); + + initialized_ = true; diff --git a/patches/components-sync-engine_impl-sync_manager_impl.h.patch b/patches/components-sync-engine_impl-sync_manager_impl.h.patch new file mode 100644 index 000000000000..c4f2ddf8b757 --- /dev/null +++ b/patches/components-sync-engine_impl-sync_manager_impl.h.patch @@ -0,0 +1,13 @@ +diff --git a/components/sync/engine_impl/sync_manager_impl.h b/components/sync/engine_impl/sync_manager_impl.h +index 4a6f7f40110d0f38bf40a994c0c5eb90535d9af5..3f6de6795abd0020b0e5d5518d7a506d50ed4e3b 100644 +--- a/components/sync/engine_impl/sync_manager_impl.h ++++ b/components/sync/engine_impl/sync_manager_impl.h +@@ -205,6 +205,8 @@ class SyncManagerImpl + + using NotificationInfoMap = std::map; + ++ void BraveInit(InitArgs* args); ++ + // Determine if the parents or predecessors differ between the old and new + // versions of an entry. Note that a node's index may change without its + // UNIQUE_POSITION changing if its sibling nodes were changed. To handle such diff --git a/patches/components-sync-engine_impl-sync_scheduler.h.patch b/patches/components-sync-engine_impl-sync_scheduler.h.patch new file mode 100644 index 000000000000..ad664d3431f9 --- /dev/null +++ b/patches/components-sync-engine_impl-sync_scheduler.h.patch @@ -0,0 +1,14 @@ +diff --git a/components/sync/engine_impl/sync_scheduler.h b/components/sync/engine_impl/sync_scheduler.h +index 8fdb1ab1603eca3a9a4851edfa9ccd9006a65f92..5edfe9b45c498a84684d2602ad717f344792cc1a 100644 +--- a/components/sync/engine_impl/sync_scheduler.h ++++ b/components/sync/engine_impl/sync_scheduler.h +@@ -143,6 +143,9 @@ class SyncScheduler : public SyncCycle::Delegate { + // Called when the network layer detects a connection status change. + virtual void OnConnectionStatusChange( + network::mojom::ConnectionType type) = 0; ++ ++ virtual void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, ++ brave_sync::PollSyncCycleDelegate) {} + }; + + } // namespace syncer diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch new file mode 100644 index 000000000000..23d32c758acc --- /dev/null +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync/engine_impl/sync_scheduler_impl.cc b/components/sync/engine_impl/sync_scheduler_impl.cc +index 8442f8521ee12924eed5daa0182656bc7553b758..f8192fe5c2d80149b468fb0b544ea7c31e479289 100644 +--- a/components/sync/engine_impl/sync_scheduler_impl.cc ++++ b/components/sync/engine_impl/sync_scheduler_impl.cc +@@ -704,6 +704,7 @@ void SyncSchedulerImpl::TryCanaryJob() { + } + + void SyncSchedulerImpl::TrySyncCycleJob() { ++ TryBraveSyncCycleJob(); + // Post call to TrySyncCycleJobImpl on current sequence. Later request for + // access token will be here. + base::SequencedTaskRunnerHandle::Get()->PostTask( diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch new file mode 100644 index 000000000000..9aeeaabf6277 --- /dev/null +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch @@ -0,0 +1,34 @@ +diff --git a/components/sync/engine_impl/sync_scheduler_impl.h b/components/sync/engine_impl/sync_scheduler_impl.h +index c2233fd5f7de560e47970eaa2d710d26c0b74e27..dc2272937e4e553b435051fcb7fb754d065c623f 100644 +--- a/components/sync/engine_impl/sync_scheduler_impl.h ++++ b/components/sync/engine_impl/sync_scheduler_impl.h +@@ -81,6 +81,11 @@ class SyncSchedulerImpl : public SyncScheduler { + const SyncProtocolError& sync_protocol_error) override; + void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override; + void OnReceivedMigrationRequest(ModelTypeSet types) override; ++ void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; ++ void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, ++ base::WaitableEvent* wevent) override; ++ void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, ++ brave_sync::PollSyncCycleDelegate) override; + + bool IsGlobalThrottle() const; + bool IsGlobalBackoff() const; +@@ -183,6 +188,7 @@ class SyncSchedulerImpl : public SyncScheduler { + // current thread. In the future it will request access token here. + void TrySyncCycleJob(); + void TrySyncCycleJobImpl(); ++ void TryBraveSyncCycleJob(); + + // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). + // This function is for global throttling. +@@ -294,6 +300,9 @@ class SyncSchedulerImpl : public SyncScheduler { + // Used to prevent changing nudge delays by the server in integration tests. + bool force_short_nudge_delay_for_test_ = false; + ++ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function_; ++ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function_; ++ + SEQUENCE_CHECKER(sequence_checker_); + + base::WeakPtrFactory weak_ptr_factory_; diff --git a/patches/components-sync-engine_impl-syncer.cc.patch b/patches/components-sync-engine_impl-syncer.cc.patch new file mode 100644 index 000000000000..6b4e5b02e3b1 --- /dev/null +++ b/patches/components-sync-engine_impl-syncer.cc.patch @@ -0,0 +1,28 @@ +diff --git a/components/sync/engine_impl/syncer.cc b/components/sync/engine_impl/syncer.cc +index d4d745fcd5a2d254dfcbdc44ed370e4479b28698..7c56e61aa54e2a054a840750c0ee3c62ac4c15e3 100644 +--- a/components/sync/engine_impl/syncer.cc ++++ b/components/sync/engine_impl/syncer.cc +@@ -34,6 +34,7 @@ void HandleCycleBegin(SyncCycle* cycle) { + + Syncer::Syncer(CancelationSignal* cancelation_signal) + : cancelation_signal_(cancelation_signal), is_syncing_(false) {} ++ // weak_ptr_factory_(this) {} + + Syncer::~Syncer() {} + +@@ -111,6 +112,7 @@ bool Syncer::DownloadAndApplyUpdates(ModelTypeSet* request_types, + Difference(*request_types, requested_commit_only_types); + GetUpdatesProcessor get_updates_processor( + cycle->context()->model_type_registry()->update_handler_map(), delegate); ++ get_updates_processor.AddBraveRecords(std::move(brave_records_)); + SyncerError download_result; + do { + download_result = +@@ -170,6 +172,7 @@ SyncerError Syncer::BuildAndPostCommits(const ModelTypeSet& request_types, + SyncerError error = commit->PostAndProcessResponse( + nudge_tracker, cycle, cycle->mutable_status_controller(), + cycle->context()->extensions_activity()); ++ + commit->CleanUp(); + if (error.value() != SyncerError::SYNCER_OK) { + return error; diff --git a/patches/components-sync-engine_impl-syncer.h.patch b/patches/components-sync-engine_impl-syncer.h.patch new file mode 100644 index 000000000000..ece6fc7bc72c --- /dev/null +++ b/patches/components-sync-engine_impl-syncer.h.patch @@ -0,0 +1,36 @@ +diff --git a/components/sync/engine_impl/syncer.h b/components/sync/engine_impl/syncer.h +index fd1203f8963834e69ce80be254527deecf57fdfd..efbb10a68436bd342a34560555b5a654597fe79a 100644 +--- a/components/sync/engine_impl/syncer.h ++++ b/components/sync/engine_impl/syncer.h +@@ -32,7 +32,7 @@ class SyncCycle; + // A Syncer instance expects to run on a dedicated thread. Calls to SyncShare() + // may take an unbounded amount of time because it may block on network I/O, on + // lock contention, or on tasks posted to other threads. +-class Syncer { ++class Syncer : public base::SupportsWeakPtr { + public: + explicit Syncer(CancelationSignal* cancelation_signal); + virtual ~Syncer(); +@@ -74,10 +74,13 @@ class Syncer { + // otherwise. + virtual bool PostClearServerData(SyncCycle* cycle); + ++ void DownloadBraveRecords(SyncCycle* cycle); ++ + private: + bool DownloadAndApplyUpdates(ModelTypeSet* request_types, + SyncCycle* cycle, + const GetUpdatesDelegate& delegate); ++ void OnGetRecords(std::unique_ptr records); + + // This function will commit batches of unsynced items to the server until the + // number of unsynced and ready to commit items reaches zero or an error is +@@ -99,6 +102,8 @@ class Syncer { + // Whether the syncer is in the middle of a sync attempt. + bool is_syncing_; + ++ std::unique_ptr brave_records_; ++ + DISALLOW_COPY_AND_ASSIGN(Syncer); + }; + diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch new file mode 100644 index 000000000000..e2d108a583f7 --- /dev/null +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -0,0 +1,40 @@ +diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc +index 32cbf98c9aef52a321a2ca67e403c570090ffa5c..ac3e9d0a4975deb6c531f2c990763dde9b00c81a 100644 +--- a/components/sync_bookmarks/bookmark_change_processor.cc ++++ b/components/sync_bookmarks/bookmark_change_processor.cc +@@ -89,6 +89,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( + bookmark_specifics.set_url(src->url().spec()); + } + bookmark_specifics.set_creation_time_us(src->date_added().ToInternalValue()); ++ AddBraveMetaInfo(src, model); + dst->SetBookmarkSpecifics(bookmark_specifics); + SetSyncNodeFavicon(src, model, dst); + SetSyncNodeMetaInfo(src, dst); +@@ -248,6 +249,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { + // Acquire a scoped write lock via a transaction. + syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); + sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); ++ bookmark_model_->RemoveObserver(this); + if (sync_id != syncer::kInvalidId) { + UpdateSyncNode( + node, bookmark_model_, &trans, model_associator_, error_handler()); +@@ -261,6 +263,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { + model_associator_, + error_handler()); + } ++ bookmark_model_->AddObserver(this); + } + + if (syncer::kInvalidId != sync_id) { +@@ -420,6 +423,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, + return; + } + ++ bookmark_model_->RemoveObserver(this); ++ AddBraveMetaInfo(child, model); ++ SetSyncNodeMetaInfo(child, &sync_node); ++ bookmark_model_->AddObserver(this); ++ + if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, + model_associator_)) { + syncer::SyncError error(FROM_HERE, diff --git a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch new file mode 100644 index 000000000000..cc406af2f33e --- /dev/null +++ b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync_bookmarks/bookmark_local_changes_builder.cc b/components/sync_bookmarks/bookmark_local_changes_builder.cc +index 92bda90302a1b3a153226056a3eb0aed0c02e725..1d1e531f67dfe247209b6e6d66b1adcbc70ecff3 100644 +--- a/components/sync_bookmarks/bookmark_local_changes_builder.cc ++++ b/components/sync_bookmarks/bookmark_local_changes_builder.cc +@@ -73,6 +73,7 @@ BookmarkLocalChangesBuilder::BuildCommitRequests(size_t max_entries) const { + // EntityData should contain empty specifics to indicate deletion. + data.specifics = CreateSpecificsFromBookmarkNode( + node, bookmark_model_, /*force_favicon_load=*/true); ++ AddBraveMetaInfo(node, bookmark_tracker_, bookmark_model_); + } + request.entity = data.PassToPtr(); + request.sequence_number = metadata->sequence_number(); From 5d9fd404eee8f90eb4e8f756840367cbeac91f7d Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Fri, 12 Apr 2019 16:35:29 +0300 Subject: [PATCH 02/73] Fixed build on Linux --- components/brave_sync/BUILD.gn | 22 +++++++++++++++------- patches/components-sync-BUILD.gn.patch | 12 ++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 patches/components-sync-BUILD.gn.patch diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 8ef811575960..973240905b81 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -40,19 +40,26 @@ if (enable_brave_sync) { } } -source_set("core") { +source_set("jslib_messages") { sources = [ - "bookmark_order_util.cc", - "bookmark_order_util.h", - "brave_sync_prefs.cc", - "brave_sync_prefs.h", - "brave_sync_service.cc", - "brave_sync_service.h", "jslib_const.cc", "jslib_const.h", "jslib_messages.cc", "jslib_messages.h", "jslib_messages_fwd.h", + ] + + deps = [ + "//base", + ] +} + +source_set("core") { + sources = [ + "bookmark_order_util.cc", + "bookmark_order_util.h", + "brave_sync_prefs.cc", + "brave_sync_prefs.h", "model/change_processor.h", "settings.cc", "settings.h", @@ -65,6 +72,7 @@ source_set("core") { ] deps = [ + ":jslib_messages", "//base", "//components/prefs", "//crypto", diff --git a/patches/components-sync-BUILD.gn.patch b/patches/components-sync-BUILD.gn.patch new file mode 100644 index 000000000000..597cfcc526ec --- /dev/null +++ b/patches/components-sync-BUILD.gn.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync/BUILD.gn b/components/sync/BUILD.gn +index a06f30a7859a7015dbf1a35d2e0392d2e99d8abf..1c003dc6c60d99af68a0a84e3ed82eed542b7733 100644 +--- a/components/sync/BUILD.gn ++++ b/components/sync/BUILD.gn +@@ -579,6 +579,7 @@ jumbo_static_library("sync") { + ] + deps = [ + "//base:i18n", ++ "//brave/components/brave_sync:jslib_messages", + "//components/data_use_measurement/core", + "//components/invalidation/impl:feature_list", + "//components/invalidation/public", From d08cd5ed8df9a5a720e62d30c90a521a50cb7cfa Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 11 Apr 2019 12:39:07 -0700 Subject: [PATCH 03/73] Upgrade to 74.0.3729.75 --- app/brave_main_delegate.cc | 4 ++ browser/extensions/api/brave_sync_api.cc | 2 +- browser/ui/webui/sync/sync_ui.cc | 2 +- .../bookmarks/bookmark_model_factory.cc | 4 +- .../browser_sync/profile_sync_service.cc | 31 ++++++--- .../driver/glue/sync_backend_host_core.cc | 4 +- ...ckend_host_impl.cc => sync_engine_impl.cc} | 8 +-- ...backend_host_impl.h => sync_engine_impl.h} | 2 +- .../sync/engine_impl/get_updates_processor.cc | 18 ++++-- .../sync/engine_impl/sync_scheduler_impl.cc | 2 +- ...e-browser-sync-chrome_sync_client.cc.patch | 12 ++-- ...me-browser-sync-chrome_sync_client.h.patch | 10 +-- ...browser_sync-profile_sync_service.cc.patch | 63 ++++--------------- ...-browser_sync-profile_sync_service.h.patch | 55 ++++++---------- patches/components-sync-BUILD.gn.patch | 4 +- ...ync-driver-data_type_manager_impl.cc.patch | 4 +- ...river-glue-sync_backend_host_core.cc.patch | 18 +++--- ...driver-glue-sync_backend_host_core.h.patch | 4 +- ...river-glue-sync_backend_host_impl.cc.patch | 15 ----- ...driver-glue-sync_backend_host_impl.h.patch | 27 -------- ...sync-driver-glue-sync_engine_impl.cc.patch | 15 +++++ ...-sync-driver-glue-sync_engine_impl.h.patch | 27 ++++++++ ...components-sync-driver-sync_client.h.patch | 4 +- ...components-sync-engine-sync_engine.h.patch | 13 ++-- ...omponents-sync-engine-sync_manager.h.patch | 10 +-- ...omponents-sync-engine_impl-commit.cc.patch | 8 +-- ...engine_impl-get_updates_processor.cc.patch | 18 ++---- ...-engine_impl-get_updates_processor.h.patch | 14 ++--- ...ync-engine_impl-sync_manager_impl.cc.patch | 5 +- ...sync-engine_impl-sync_manager_impl.h.patch | 4 +- ...ts-sync-engine_impl-sync_scheduler.h.patch | 4 +- ...c-engine_impl-sync_scheduler_impl.cc.patch | 4 +- ...nc-engine_impl-sync_scheduler_impl.h.patch | 13 ++-- ...omponents-sync-engine_impl-syncer.cc.patch | 20 +----- ...components-sync-engine_impl-syncer.h.patch | 23 +++---- ...ync-engine_impl-syncer_proto_util.cc.patch | 14 +++++ ...okmarks-bookmark_change_processor.cc.patch | 10 +-- ...ks-bookmark_local_changes_builder.cc.patch | 6 +- 38 files changed, 228 insertions(+), 273 deletions(-) rename chromium_src/components/sync/driver/glue/{sync_backend_host_impl.cc => sync_engine_impl.cc} (77%) rename chromium_src/components/sync/driver/glue/{sync_backend_host_impl.h => sync_engine_impl.h} (67%) delete mode 100644 patches/components-sync-driver-glue-sync_backend_host_impl.cc.patch delete mode 100644 patches/components-sync-driver-glue-sync_backend_host_impl.h.patch create mode 100644 patches/components-sync-driver-glue-sync_engine_impl.cc.patch create mode 100644 patches/components-sync-driver-glue-sync_engine_impl.h.patch create mode 100644 patches/components-sync-engine_impl-syncer_proto_util.cc.patch diff --git a/app/brave_main_delegate.cc b/app/brave_main_delegate.cc index 97564b7fabe3..b915c3d4b54e 100644 --- a/app/brave_main_delegate.cc +++ b/app/brave_main_delegate.cc @@ -28,6 +28,7 @@ #include "components/autofill/core/common/autofill_payments_features.h" #include "components/omnibox/common/omnibox_features.h" #include "components/password_manager/core/common/password_manager_features.h" +#include "components/sync/driver/sync_driver_switches.h" #include "components/unified_consent/feature.h" #include "extensions/common/extension_features.h" #include "services/network/public/cpp/features.h" @@ -159,6 +160,9 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) { // Disabled features. const std::unordered_set disabled_features = { autofill::features::kAutofillServerCommunication.name, + // TODO(darkdh): remove this when USS bookmarks is mature + // 84919fdb99b162030a1113d5990667885b774064 + switches::kSyncUSSBookmarks.name, network::features::kNetworkService.name, unified_consent::kUnifiedConsent.name, }; diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index e0f2133120b1..aceb875dbda4 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -27,7 +27,7 @@ namespace api { namespace { ProfileSyncService* GetProfileSyncService(BrowserContext* browser_context) { - return ProfileSyncServiceFactory::GetForProfile( + return ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( Profile::FromBrowserContext(browser_context)); } diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index cd16f5a0f9d4..50583e54dfea 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -121,7 +121,7 @@ void SyncUIDOMHandler::Init() { Profile* profile = Profile::FromWebUI(web_ui()); sync_service_ = static_cast( - ProfileSyncServiceFactory::GetForProfile(profile)); + ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile(profile)); if (sync_service_) sync_service_->AddObserver(this); } diff --git a/chromium_src/chrome/browser/bookmarks/bookmark_model_factory.cc b/chromium_src/chrome/browser/bookmarks/bookmark_model_factory.cc index a3cc1bfedc6f..e65b9e757cb0 100644 --- a/chromium_src/chrome/browser/bookmarks/bookmark_model_factory.cc +++ b/chromium_src/chrome/browser/bookmarks/bookmark_model_factory.cc @@ -1,4 +1,6 @@ #include "chrome/browser/bookmarks/chrome_bookmark_client.h" #include "brave/browser/bookmarks/brave_bookmark_client.h" -#define ChromeBookmarkClient BraveBookmarkClient +// Stop loading old Brave permanent nodes, GetEntityForBookmarkNode will fail +// see 9645795920481e2a80613a72aeddba1a65490dac +// #define ChromeBookmarkClient BraveBookmarkClient #include "../../../../../../chrome/browser/bookmarks/bookmark_model_factory.cc" diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/browser_sync/profile_sync_service.cc index 4a14a7984c29..9bebfed70ed7 100644 --- a/chromium_src/components/browser_sync/profile_sync_service.cc +++ b/chromium_src/components/browser_sync/profile_sync_service.cc @@ -6,10 +6,9 @@ syncer::SyncCredentials GetDummyCredentials(); AccountInfo GetDummyAccountInfo(); } } -namespace syncer { -const int64_t kBraveDefaultShortPollIntervalSeconds = 60; -const int64_t kBraveDefaultLongPollIntervalSeconds = 90; -} + +// For use_transport_only_mode +#define IsSyncFeatureEnabled IsBraveSyncEnabled #include "../../../../components/browser_sync/profile_sync_service.cc" #include "base/bind.h" @@ -22,12 +21,18 @@ const int64_t kBraveDefaultLongPollIntervalSeconds = 90; #include "brave/components/brave_sync/sync_devices.h" #include "brave/components/brave_sync/tools.h" #include "brave/components/brave_sync/values_conv.h" +#include "chrome/browser/sync/chrome_sync_client.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/sync/engine_impl/syncer.h" #include "content/public/browser/browser_thread.h" #include "net/base/network_interfaces.h" #include "ui/base/models/tree_node_iterator.h" +namespace syncer { +const int64_t kBraveDefaultShortPollIntervalSeconds = 60; +const int64_t kBraveDefaultLongPollIntervalSeconds = 90; +} + namespace browser_sync { using brave_sync::GetRecordsCallback; @@ -484,9 +489,6 @@ void ProfileSyncService::OnSaveInitData(const Uint8Array& seed, brave_sync_configured_ = true; - user_settings_->SetChosenDataTypes(false, syncer::ModelTypeSet()); - OnSetSyncBookmarks(true); - brave_sync_initializing_ = false; } @@ -504,6 +506,8 @@ void ProfileSyncService::OnSyncReady() { DCHECK(false == brave_sync_initialized_); brave_sync_initialized_ = true; + user_settings_->SetChosenDataTypes(false, syncer::ModelTypeSet()); + OnSetSyncBookmarks(true); user_settings_->SetSyncRequested(true); } @@ -524,7 +528,9 @@ void ProfileSyncService::OnGetExistingObjects( std::make_unique(); CreateResolveList( *records.get(), records_and_existing_objects.get(), - sync_client_->GetBookmarkModel(), + // TODO(darkdh): find another way to obtain bookmark model + // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 + static_cast(sync_client_.get())->GetBookmarkModel(), brave_sync_prefs_.get()); GetBraveSyncClient()->SendResolveSyncRecords( category_name, std::move(records_and_existing_objects)); @@ -764,6 +770,15 @@ void ProfileSyncService::BraveEngineParamsInit( params->poll_sync_cycle_delegate_function = base::BindRepeating(&ProfileSyncService::OnPollSyncCycle, sync_enabled_weak_factory_.GetWeakPtr()); + + params->credentials = GetDummyCredentials(); + + sync_prefs_.SetShortPollInterval( + base::TimeDelta::FromSeconds( + syncer::kBraveDefaultShortPollIntervalSeconds)); + sync_prefs_.SetLongPollInterval( + base::TimeDelta::FromSeconds( + syncer::kBraveDefaultLongPollIntervalSeconds)); } void ProfileSyncService::OnNudgeSyncCycle( diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc b/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc index c0919a30d895..ad9313cc03fb 100644 --- a/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc +++ b/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc @@ -7,14 +7,14 @@ namespace syncer { void SyncBackendHostCore::OnNudgeSyncCycle( brave_sync::RecordsListPtr records_list) { host_.Call(FROM_HERE, - &SyncBackendHostImpl::HandleNudgeSyncCycle, + &SyncEngineImpl::HandleNudgeSyncCycle, base::Passed(&records_list)); } void SyncBackendHostCore::OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent) { host_.Call(FROM_HERE, - &SyncBackendHostImpl::HandlePollSyncCycle, cb, wevent); + &SyncEngineImpl::HandlePollSyncCycle, cb, wevent); } void SyncBackendHostCore::DoDispatchGetRecordsCallback( diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_impl.cc b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc similarity index 77% rename from chromium_src/components/sync/driver/glue/sync_backend_host_impl.cc rename to chromium_src/components/sync/driver/glue/sync_engine_impl.cc index b09e50a418c4..4e87750ed9cb 100644 --- a/chromium_src/components/sync/driver/glue/sync_backend_host_impl.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc @@ -1,17 +1,17 @@ -#include "../../../../../../components/sync/driver/glue/sync_backend_host_impl.cc" +#include "../../../../../../components/sync/driver/glue/sync_engine_impl.cc" #include "brave/components/brave_sync/jslib_messages.h" namespace syncer { -void SyncBackendHostImpl::HandleNudgeSyncCycle( +void SyncEngineImpl::HandleNudgeSyncCycle( brave_sync::RecordsListPtr records_list) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(nudge_sync_cycle_delegate_function_); nudge_sync_cycle_delegate_function_.Run(std::move(records_list)); } -void SyncBackendHostImpl::HandlePollSyncCycle( +void SyncEngineImpl::HandlePollSyncCycle( GetRecordsCallback cb, base::WaitableEvent* wevent) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); @@ -19,7 +19,7 @@ void SyncBackendHostImpl::HandlePollSyncCycle( poll_sync_cycle_delegate_function_.Run(cb, wevent); } -void SyncBackendHostImpl::DispatchGetRecordsCallback( +void SyncEngineImpl::DispatchGetRecordsCallback( GetRecordsCallback cb, std::unique_ptr records) { sync_task_runner_->PostTask( FROM_HERE, diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_impl.h b/chromium_src/components/sync/driver/glue/sync_engine_impl.h similarity index 67% rename from chromium_src/components/sync/driver/glue/sync_backend_host_impl.h rename to chromium_src/components/sync/driver/glue/sync_engine_impl.h index a3e3db0e699e..5223e21b0949 100644 --- a/chromium_src/components/sync/driver/glue/sync_backend_host_impl.h +++ b/chromium_src/components/sync/driver/glue/sync_engine_impl.h @@ -3,4 +3,4 @@ namespace syncer { using brave_sync::GetRecordsCallback; using brave_sync::RecordsList; } // namespace syncer -#include "../../../../../../components/sync/driver/glue/sync_backend_host_impl.h" +#include "../../../../../../components/sync/driver/glue/sync_engine_impl.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 index 507c361dec01..600f4173747a 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -22,10 +22,12 @@ namespace { using brave_sync::jslib::Bookmark; using brave_sync::jslib::SyncRecord; using syncable::Id; -static const char kBookmarkBarTag[] = "bookmark_bar"; -static const char kOtherBookmarksTag[] = "other_bookmarks"; +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"; @@ -146,9 +148,9 @@ void AddBookmarkNode(sync_pb::SyncEntity* entity, const SyncRecord* record) { if (!bookmark_record.parentFolderObjectId.empty()) entity->set_parent_id_string(bookmark_record.parentFolderObjectId); else if (!bookmark_record.hideInToolbar) - entity->set_parent_id_string(std::string(kBookmarkBarTag)); + entity->set_parent_id_string(std::string(kBookmarkBarFolderServerTag)); else - entity->set_parent_id_string(std::string(kOtherBookmarksTag)); + entity->set_parent_id_string(std::string(kOtherBookmarksFolderServerTag)); entity->set_non_unique_name(bookmark_record.site.title); entity->set_folder(bookmark_record.isFolder); @@ -182,9 +184,13 @@ void ConstructUpdateResponse(sync_pb::GetUpdatesResponse* gu_response, if (type == BOOKMARKS) { google::protobuf::RepeatedPtrField entities; AddRootForType(entities.Add(), BOOKMARKS); - AddPermanentNode(entities.Add(), kBookmarkBarFolderName, kBookmarkBarTag); + AddPermanentNode(entities.Add(), kBookmarkBarFolderName, + kBookmarkBarFolderServerTag); AddPermanentNode(entities.Add(), kOtherBookmarksFolderName, - kOtherBookmarksTag); + kOtherBookmarksFolderServerTag); + // required since 84f01c4c006cf89941138f3591db129a5b3cde54 + AddPermanentNode(entities.Add(), kSyncedBookmarksFolderName, + kSyncedBookmarksFolderServerTag); if (records) { for (const auto& record : *records.get()) { AddBookmarkNode(entities.Add(), record.get()); diff --git a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc index 7d232932a336..7ff63b6ebc5d 100644 --- a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc +++ b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc @@ -25,7 +25,7 @@ void SyncSchedulerImpl::SetNudgeAndPollDelegate( void SyncSchedulerImpl::TryBraveSyncCycleJob() { SyncCycle cycle(cycle_context_, this); - if (mode_ != CONFIGURATION_MODE && mode_ != CLEAR_SERVER_DATA_MODE) { + if (mode_ != CONFIGURATION_MODE) { syncer_->DownloadBraveRecords(&cycle); } } diff --git a/patches/chrome-browser-sync-chrome_sync_client.cc.patch b/patches/chrome-browser-sync-chrome_sync_client.cc.patch index 1884ca97b8c1..cdafe24dcdb2 100644 --- a/patches/chrome-browser-sync-chrome_sync_client.cc.patch +++ b/patches/chrome-browser-sync-chrome_sync_client.cc.patch @@ -1,14 +1,14 @@ diff --git a/chrome/browser/sync/chrome_sync_client.cc b/chrome/browser/sync/chrome_sync_client.cc -index 8c36199a7b7514d1ac5e710a938287a167da91a5..50e07746517364f85c93ee6feae38eea16de7892 100644 +index 3efbe8f776e1ecfd212fee726fad5c360d9788c6..ce8f6e05186781e40a0224125ed248a6fa102dc9 100644 --- a/chrome/browser/sync/chrome_sync_client.cc +++ b/chrome/browser/sync/chrome_sync_client.cc -@@ -159,7 +159,8 @@ syncer::ModelTypeSet GetDisabledTypesFromCommandLine() { +@@ -164,7 +164,8 @@ syncer::ModelTypeSet GetDisabledTypesFromCommandLine() { } // namespace --ChromeSyncClient::ChromeSyncClient(Profile* profile) : profile_(profile) {} +-ChromeSyncClient::ChromeSyncClient(Profile* profile) : profile_(profile) { +ChromeSyncClient::ChromeSyncClient(Profile* profile) : profile_(profile), -+ brave_sync_client_(brave_sync::BraveSyncClient::Create(profile)) {} ++ brave_sync_client_(brave_sync::BraveSyncClient::Create(profile)) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); - ChromeSyncClient::~ChromeSyncClient() { - } + profile_web_data_service_ = diff --git a/patches/chrome-browser-sync-chrome_sync_client.h.patch b/patches/chrome-browser-sync-chrome_sync_client.h.patch index 2010b44ec7c6..9ccf532522b0 100644 --- a/patches/chrome-browser-sync-chrome_sync_client.h.patch +++ b/patches/chrome-browser-sync-chrome_sync_client.h.patch @@ -1,16 +1,16 @@ diff --git a/chrome/browser/sync/chrome_sync_client.h b/chrome/browser/sync/chrome_sync_client.h -index ae728503c195e1c9cf6da57ce08641632d8ae3ae..5ddf2944e4393f270cb53bc926f36f49c303bcbf 100644 +index c89058c8815f8983dafaeb88edf1a239f11a9b08..bb22a19336d91fcf476607a3399bbbe850fa5f47 100644 --- a/chrome/browser/sync/chrome_sync_client.h +++ b/chrome/browser/sync/chrome_sync_client.h -@@ -62,6 +62,7 @@ class ChromeSyncClient : public syncer::SyncClient { +@@ -60,6 +60,7 @@ class ChromeSyncClient : public browser_sync::BrowserSyncClient { scoped_refptr CreateModelWorkerForGroup( syncer::ModelSafeGroup group) override; syncer::SyncApiComponentFactory* GetSyncApiComponentFactory() override; + brave_sync::BraveSyncClient* GetBraveSyncClient() override; - // Helpers for overriding getters in tests. - void SetSyncApiComponentFactoryForTesting( -@@ -85,6 +86,8 @@ class ChromeSyncClient : public syncer::SyncClient { + private: + Profile* const profile_; +@@ -82,6 +83,8 @@ class ChromeSyncClient : public browser_sync::BrowserSyncClient { // Generates and monitors the ExtensionsActivity object used by sync. ExtensionsActivityMonitor extensions_activity_monitor_; diff --git a/patches/components-browser_sync-profile_sync_service.cc.patch b/patches/components-browser_sync-profile_sync_service.cc.patch index 1ee11304d142..7db14b5c3f39 100644 --- a/patches/components-browser_sync-profile_sync_service.cc.patch +++ b/patches/components-browser_sync-profile_sync_service.cc.patch @@ -1,84 +1,45 @@ diff --git a/components/browser_sync/profile_sync_service.cc b/components/browser_sync/profile_sync_service.cc -index a0355393caba17c8343ec2a771eeb29d731d27e4..08a9666b1ac5fcd6c6ab737b2874afc331e02a69 100644 +index 787e2d24941cbaa469373ed5baad14d1ac9f3722..8f5a0b7a2d4e263992822375621ed624027913fd 100644 --- a/components/browser_sync/profile_sync_service.cc +++ b/components/browser_sync/profile_sync_service.cc -@@ -198,6 +198,8 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +@@ -184,6 +184,8 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) DCHECK(sync_client_); + DCHECK(IsLocalSyncEnabled() || identity_manager_ != nullptr); + BraveSyncSetup(); + // If Sync is disabled via command line flag, then ProfileSyncService // shouldn't be instantiated. - DCHECK(IsSyncAllowedByFlag()); -@@ -539,7 +541,10 @@ void ProfileSyncService::StartUpSlowEngineComponents() { - ->GetLocalDeviceInfoProvider() + DCHECK(switches::IsSyncAllowedByFlag()); +@@ -480,6 +482,8 @@ void ProfileSyncService::StartUpSlowEngineComponents() { ->GetSyncUserAgent(); params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); -- params.credentials = auth_manager_->GetCredentials(); -+ if (IsBraveSyncEnabled()) -+ params.credentials = GetDummyCredentials(); -+ else -+ params.credentials = auth_manager_->GetCredentials(); + params.credentials = auth_manager_->GetCredentials(); ++ if (IsBraveSyncEnabled()) ++ BraveEngineParamsInit(¶ms); DCHECK(!params.credentials.account_id.empty() || IsLocalSyncEnabled()); if (!base::FeatureList::IsEnabled(switches::kSyncE2ELatencyMeasurement)) { invalidation::InvalidationService* invalidator = -@@ -571,13 +576,14 @@ void ProfileSyncService::StartUpSlowEngineComponents() { - params.short_poll_interval = sync_prefs_.GetShortPollInterval(); - if (params.short_poll_interval.is_zero()) { - params.short_poll_interval = -- base::TimeDelta::FromSeconds(syncer::kDefaultShortPollIntervalSeconds); -+ base::TimeDelta::FromSeconds(syncer::kBraveDefaultShortPollIntervalSeconds); - } - params.long_poll_interval = sync_prefs_.GetLongPollInterval(); - if (params.long_poll_interval.is_zero()) { - params.long_poll_interval = -- base::TimeDelta::FromSeconds(syncer::kDefaultLongPollIntervalSeconds); -+ base::TimeDelta::FromSeconds(syncer::kBraveDefaultLongPollIntervalSeconds); - } -+ BraveEngineParamsInit(¶ms); - - engine_->Initialize(std::move(params)); - -@@ -721,6 +727,7 @@ int ProfileSyncService::GetDisableReasons() const { - DCHECK(IsSyncAllowedByFlag()); +@@ -663,6 +667,7 @@ int ProfileSyncService::GetDisableReasons() const { + DCHECK(switches::IsSyncAllowedByFlag()); int result = DISABLE_REASON_NONE; + if (IsBraveSyncEnabled()) return result; if (!user_settings_->IsSyncAllowedByPlatform()) { result = result | DISABLE_REASON_PLATFORM_OVERRIDE; } -@@ -1465,7 +1472,7 @@ void ProfileSyncService::ConfigureDataTypeManager( - // Note: When local Sync is enabled, then we want full-sync mode (not just - // transport), even though Sync-the-feature is not considered enabled. - bool use_transport_only_mode = -- !IsSyncFeatureEnabled() && !IsLocalSyncEnabled(); -+ !IsSyncFeatureEnabled() && !IsLocalSyncEnabled() && !IsBraveSyncEnabled(); - - syncer::ModelTypeSet types = GetPreferredDataTypes(); - // In transport-only mode, only a subset of data types is supported. -@@ -1860,6 +1867,7 @@ void ProfileSyncService::GetAllNodes( - - syncer::ModelTypeSet all_types = GetActiveDataTypes(); - all_types.PutAll(syncer::ControlTypes()); -+ - scoped_refptr helper = - new GetAllNodesRequestHelper(all_types, callback); - -@@ -1891,12 +1899,14 @@ void ProfileSyncService::GetAllNodes( +@@ -1753,12 +1758,12 @@ void ProfileSyncService::GetAllNodes( - AccountInfo ProfileSyncService::GetAuthenticatedAccountInfo() const { + CoreAccountInfo ProfileSyncService::GetAuthenticatedAccountInfo() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - return auth_manager_->GetActiveAccountInfo().account_info; + return GetDummyAccountInfo(); -+ // return auth_manager_->GetActiveAccountInfo().account_info; } bool ProfileSyncService::IsAuthenticatedAccountPrimary() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - return auth_manager_->GetActiveAccountInfo().is_primary; + return true; -+ // return auth_manager_->GetActiveAccountInfo().is_primary; } void ProfileSyncService::SetInvalidationsForSessionsEnabled(bool enabled) { diff --git a/patches/components-browser_sync-profile_sync_service.h.patch b/patches/components-browser_sync-profile_sync_service.h.patch index d3a0f3a01e22..f6c08a8fac7a 100644 --- a/patches/components-browser_sync-profile_sync_service.h.patch +++ b/patches/components-browser_sync-profile_sync_service.h.patch @@ -1,8 +1,8 @@ diff --git a/components/browser_sync/profile_sync_service.h b/components/browser_sync/profile_sync_service.h -index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3e3f63167 100644 +index 6c01395b954ac146084865b0268992f277b4914c..f56688195f34abb11c30573d63832fe67ba8218d 100644 --- a/components/browser_sync/profile_sync_service.h +++ b/components/browser_sync/profile_sync_service.h -@@ -138,7 +138,9 @@ class ProfileSyncService : public syncer::SyncService, +@@ -137,7 +137,9 @@ class ProfileSyncService : public syncer::SyncService, public syncer::SyncPrefObserver, public syncer::DataTypeManagerObserver, public syncer::UnrecoverableErrorHandler, @@ -13,7 +13,7 @@ index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3 public: // If AUTO_START, sync will set IsFirstSetupComplete() automatically and sync // will begin syncing without the user needing to confirm sync settings. -@@ -368,6 +370,43 @@ class ProfileSyncService : public syncer::SyncService, +@@ -346,6 +348,42 @@ class ProfileSyncService : public syncer::SyncService, syncer::SyncClient* GetSyncClientForTest(); @@ -21,12 +21,11 @@ index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3 + brave_sync::BraveSyncClient* GetBraveSyncClient() override; + // BraveSyncService messages from UI + void OnSetupSyncHaveCode(const std::string& sync_words, -+ const std::string& device_name) override; ++ const std::string& device_name) override; + void OnSetupSyncNewToSync(const std::string& device_name) override; + void OnDeleteDevice(const std::string& device_id) override; + void OnResetSync() override; -+ void GetSettingsAndDevices( -+ const GetSettingsAndDevicesCallback& callback) override; ++ void GetSettingsAndDevices(const GetSettingsAndDevicesCallback& callback) override; + void GetSyncWords() override; + std::string GetSeed() override; + void OnSetSyncEnabled(const bool sync_this_device) override; @@ -44,11 +43,11 @@ index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3 + const brave_sync::Uint8Array& device_id) override; + void OnSyncReady() override; + void OnGetExistingObjects(const std::string& category_name, -+ std::unique_ptr records, -+ const base::Time &last_record_time_stamp, -+ const bool is_truncated) override; ++ std::unique_ptr records, ++ const base::Time &last_record_time_stamp, ++ const bool is_truncated) override; + void OnResolvedSyncRecords(const std::string& category_name, -+ std::unique_ptr records) override; ++ std::unique_ptr records) override; + void OnDeletedSyncUser() override; + void OnDeleteSyncSiteSettings() override; + void OnSaveBookmarksBaseOrder(const std::string& order) override; @@ -57,9 +56,9 @@ index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3 private: // Passed as an argument to StopImpl to control whether or not the sync // engine should clear its data directory when it shuts down. See StopImpl -@@ -377,6 +416,28 @@ class ProfileSyncService : public syncer::SyncService, - CLEAR_DATA, - }; +@@ -465,6 +503,46 @@ class ProfileSyncService : public syncer::SyncService, + // Called by SyncServiceCrypto when a passphrase is required or accepted. + void ReconfigureDueToPassphrase(syncer::ConfigureReason reason); + bool IsBraveSyncEnabled() const; + void BraveSyncSetup(); @@ -70,11 +69,10 @@ index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3 + void FetchSyncRecords(const bool bookmarks, const bool history, + const bool preferences, int max_records); + void SendCreateDevice(); -+ void SendDeviceSyncRecord( -+ const int action, -+ const std::string& device_name, -+ const std::string& device_id, -+ const std::string& object_id); ++ void SendDeviceSyncRecord(const int action, ++ const std::string& device_name, ++ const std::string& device_id, ++ const std::string& object_id); + void OnResolvedPreferences(const brave_sync::RecordsList& records); + void OnBraveSyncPrefsChanged(const std::string& pref); + void NotifySyncSetupError(const std::string& error); @@ -83,22 +81,7 @@ index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3 + + void ResetSyncInternal(); + - // Shorthand for user_settings_.IsFirstSetupComplete(). - bool IsFirstSetupComplete() const; - -@@ -506,6 +567,8 @@ class ProfileSyncService : public syncer::SyncService, - // The class that handles getting, setting, and persisting sync preferences. - syncer::SyncPrefs sync_prefs_; - + std::unique_ptr brave_sync_prefs_; -+ - // Encapsulates user signin - used to set/get the user's authenticated - // email address and sign-out upon error. - identity::IdentityManager* const identity_manager_; -@@ -638,6 +701,24 @@ class ProfileSyncService : public syncer::SyncService, - // sync is stopped after a callback from |user_settings_|). - bool is_stopping_and_clearing_; - + // True when is in active sync chain + bool brave_sync_configured_ = false; + @@ -117,6 +100,6 @@ index 74818b55931cf9896bf781b598a27d04962714cf..1da0f20a01cb58d09bcf78a6532a03d3 + // Registrar used to monitor the brave_profile prefs. + PrefChangeRegistrar brave_pref_change_registrar_; + - // This weak factory invalidates its issued pointers when Sync is disabled. - base::WeakPtrFactory sync_enabled_weak_factory_; - + // This profile's SyncClient, which abstracts away non-Sync dependencies and + // the Sync API component factory. + const std::unique_ptr sync_client_; diff --git a/patches/components-sync-BUILD.gn.patch b/patches/components-sync-BUILD.gn.patch index 597cfcc526ec..61f70c50a842 100644 --- a/patches/components-sync-BUILD.gn.patch +++ b/patches/components-sync-BUILD.gn.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/BUILD.gn b/components/sync/BUILD.gn -index a06f30a7859a7015dbf1a35d2e0392d2e99d8abf..1c003dc6c60d99af68a0a84e3ed82eed542b7733 100644 +index 129a82836e0b07552504b6f98cd1ae2c7a4e941e..5565f9aa8e3ba6618481dc1bd5cf5bb538bd41a8 100644 --- a/components/sync/BUILD.gn +++ b/components/sync/BUILD.gn -@@ -579,6 +579,7 @@ jumbo_static_library("sync") { +@@ -574,6 +574,7 @@ jumbo_static_library("sync") { ] deps = [ "//base:i18n", diff --git a/patches/components-sync-driver-data_type_manager_impl.cc.patch b/patches/components-sync-driver-data_type_manager_impl.cc.patch index d52d8a315fea..ed027472f6b4 100644 --- a/patches/components-sync-driver-data_type_manager_impl.cc.patch +++ b/patches/components-sync-driver-data_type_manager_impl.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/data_type_manager_impl.cc b/components/sync/driver/data_type_manager_impl.cc -index ea180493bb90741e1601391bb5b1a0a5e11b9303..eda3e4328549761dfe286f9e72f49071e72698d3 100644 +index 9dc9226269704e8a2412634b231a6d54c8bc93f6..b40ac1bbef7ccb7b29022176d11e725a86ac7835 100644 --- a/components/sync/driver/data_type_manager_impl.cc +++ b/components/sync/driver/data_type_manager_impl.cc -@@ -611,7 +611,8 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( +@@ -596,7 +596,8 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( DCHECK(Intersection(downloaded_types_, types_to_journal).Empty()); DCHECK(Intersection(downloaded_types_, crypto_types).Empty()); // |downloaded_types_| was already updated to include all enabled types. diff --git a/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch b/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch index 15bbaee9f7cf..23b00f4ded7e 100644 --- a/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch +++ b/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch @@ -1,32 +1,32 @@ diff --git a/components/sync/driver/glue/sync_backend_host_core.cc b/components/sync/driver/glue/sync_backend_host_core.cc -index 2bbe1dadae8202bb35eaac9fa069d6ab12b08ce6..c5fc10b4bffdd1030a0659ad0a3f250b62713682 100644 +index 9f962da6b18298365c01e8b9154d39a5c43afc38..3b6e42c0ac23fac125e7e4b57f15d30cdd408a75 100644 --- a/components/sync/driver/glue/sync_backend_host_core.cc +++ b/components/sync/driver/glue/sync_backend_host_core.cc -@@ -354,6 +354,7 @@ void SyncBackendHostCore::DoInitialize(SyncEngine::InitParams params) { - args.saved_nigori_state = std::move(params.saved_nigori_state); - args.short_poll_interval = params.short_poll_interval; - args.long_poll_interval = params.long_poll_interval; +@@ -353,6 +353,7 @@ void SyncBackendHostCore::DoInitialize(SyncEngine::InitParams params) { + args.cache_guid = params.cache_guid; + args.birthday = params.birthday; + args.bag_of_chips = params.bag_of_chips; + BraveInit(&args); sync_manager_->Init(&args); base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get()); -@@ -413,12 +414,13 @@ void SyncBackendHostCore::DoInitialProcessControlTypes() { +@@ -412,12 +413,13 @@ void SyncBackendHostCore::DoInitialProcessControlTypes() { return; } - if (!sync_manager_->InitialSyncEndedTypes().HasAll(ControlTypes())) { - LOG(ERROR) << "Failed to download control types"; - host_.Call(FROM_HERE, -- &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); +- &SyncEngineImpl::HandleInitializationFailureOnFrontendLoop); - return; - } + // TODO(darkdh): move device record into control type + // if (!sync_manager_->InitialSyncEndedTypes().HasAll(ControlTypes())) { + // LOG(ERROR) << "Failed to download control types"; + // host_.Call(FROM_HERE, -+ // &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); ++ // &SyncEngineImpl::HandleInitializationFailureOnFrontendLoop); + // return; + // } DCHECK_EQ(user_share->directory->cache_guid(), sync_manager_->cache_guid()); - host_.Call(FROM_HERE, + host_.Call( diff --git a/patches/components-sync-driver-glue-sync_backend_host_core.h.patch b/patches/components-sync-driver-glue-sync_backend_host_core.h.patch index 78f51aa859e2..e8397b2e27f7 100644 --- a/patches/components-sync-driver-glue-sync_backend_host_core.h.patch +++ b/patches/components-sync-driver-glue-sync_backend_host_core.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/glue/sync_backend_host_core.h b/components/sync/driver/glue/sync_backend_host_core.h -index dced9de5a2081185acb22c900e69e90080e54cdf..0f4b0822bb819c0b505eab58d7ea503e39490d4d 100644 +index d545f996333a652dfb4b87b24da6cd7dde428ed7..42df877d3e6fc1f0c1232c76327c2ac9a5cf598c 100644 --- a/components/sync/driver/glue/sync_backend_host_core.h +++ b/components/sync/driver/glue/sync_backend_host_core.h -@@ -176,11 +176,19 @@ class SyncBackendHostCore +@@ -174,11 +174,19 @@ class SyncBackendHostCore bool HasUnsyncedItemsForTest() const; diff --git a/patches/components-sync-driver-glue-sync_backend_host_impl.cc.patch b/patches/components-sync-driver-glue-sync_backend_host_impl.cc.patch deleted file mode 100644 index 4e2573a9e2de..000000000000 --- a/patches/components-sync-driver-glue-sync_backend_host_impl.cc.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/components/sync/driver/glue/sync_backend_host_impl.cc b/components/sync/driver/glue/sync_backend_host_impl.cc -index 4c0bb4d0d0af424b46dd0cb1ab7bf38c7018b8a0..760b6a839fc7f8d4f68d187b96c54277dbca37d6 100644 ---- a/components/sync/driver/glue/sync_backend_host_impl.cc -+++ b/components/sync/driver/glue/sync_backend_host_impl.cc -@@ -70,6 +70,10 @@ void SyncBackendHostImpl::Initialize(InitParams params) { - sync_task_runner_ = params.sync_task_runner; - host_ = params.host; - registrar_ = params.registrar.get(); -+ nudge_sync_cycle_delegate_function_ = -+ params.nudge_sync_cycle_delegate_function; -+ poll_sync_cycle_delegate_function_ = -+ params.poll_sync_cycle_delegate_function; - - sync_task_runner_->PostTask( - FROM_HERE, base::BindOnce(&SyncBackendHostCore::DoInitialize, core_, diff --git a/patches/components-sync-driver-glue-sync_backend_host_impl.h.patch b/patches/components-sync-driver-glue-sync_backend_host_impl.h.patch deleted file mode 100644 index 7b787a6f0411..000000000000 --- a/patches/components-sync-driver-glue-sync_backend_host_impl.h.patch +++ /dev/null @@ -1,27 +0,0 @@ -diff --git a/components/sync/driver/glue/sync_backend_host_impl.h b/components/sync/driver/glue/sync_backend_host_impl.h -index c9a8f8fd314da2b7b7621d5af97326b4241e6493..2e16d98f56a3a31c7d5af1315665253c8b4b3c5a 100644 ---- a/components/sync/driver/glue/sync_backend_host_impl.h -+++ b/components/sync/driver/glue/sync_backend_host_impl.h -@@ -154,6 +154,12 @@ class SyncBackendHostImpl : public SyncEngine, public InvalidationHandler { - ModelType type, - const StatusCounters& counters); - -+ void HandleNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ void HandlePollSyncCycle(GetRecordsCallback cb, -+ base::WaitableEvent* wevent); -+ void DispatchGetRecordsCallback( -+ GetRecordsCallback cb, std::unique_ptr records) override; -+ - // Overwrites the kSyncInvalidationVersions preference with the most recent - // set of invalidation versions for each type. - void UpdateInvalidationVersions( -@@ -229,6 +235,9 @@ class SyncBackendHostImpl : public SyncEngine, public InvalidationHandler { - ModelTypeSet last_enabled_types_; - bool sessions_invalidation_enabled_ = false; - -+ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function_; -+ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function_; -+ - // Checks that we're on the same thread this was constructed on (UI thread). - SEQUENCE_CHECKER(sequence_checker_); - diff --git a/patches/components-sync-driver-glue-sync_engine_impl.cc.patch b/patches/components-sync-driver-glue-sync_engine_impl.cc.patch new file mode 100644 index 000000000000..baf7d072a2ba --- /dev/null +++ b/patches/components-sync-driver-glue-sync_engine_impl.cc.patch @@ -0,0 +1,15 @@ +diff --git a/components/sync/driver/glue/sync_engine_impl.cc b/components/sync/driver/glue/sync_engine_impl.cc +index 0eec6d65d61988411827349e601d936ca66adf4c..17d6d1dcde9e20894fed756cc620171e04e8e6c1 100644 +--- a/components/sync/driver/glue/sync_engine_impl.cc ++++ b/components/sync/driver/glue/sync_engine_impl.cc +@@ -59,6 +59,10 @@ void SyncEngineImpl::Initialize(InitParams params) { + sync_task_runner_ = params.sync_task_runner; + host_ = params.host; + registrar_ = params.registrar.get(); ++ nudge_sync_cycle_delegate_function_ = ++ params.nudge_sync_cycle_delegate_function; ++ poll_sync_cycle_delegate_function_ = ++ params.poll_sync_cycle_delegate_function; + + sync_task_runner_->PostTask( + FROM_HERE, base::BindOnce(&SyncBackendHostCore::DoInitialize, core_, diff --git a/patches/components-sync-driver-glue-sync_engine_impl.h.patch b/patches/components-sync-driver-glue-sync_engine_impl.h.patch new file mode 100644 index 000000000000..58121dab5fbd --- /dev/null +++ b/patches/components-sync-driver-glue-sync_engine_impl.h.patch @@ -0,0 +1,27 @@ +diff --git a/components/sync/driver/glue/sync_engine_impl.h b/components/sync/driver/glue/sync_engine_impl.h +index db4f0ef865957a38dc1b510f31ebd49b83cb57b9..4daca79263fec199188e54667d1a9b7312ba7aac 100644 +--- a/components/sync/driver/glue/sync_engine_impl.h ++++ b/components/sync/driver/glue/sync_engine_impl.h +@@ -158,6 +158,12 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { + + SyncEngineHost* host() { return host_; } + ++ void HandleNudgeSyncCycle(brave_sync::RecordsListPtr records_list); ++ void HandlePollSyncCycle(GetRecordsCallback cb, ++ base::WaitableEvent* wevent); ++ void DispatchGetRecordsCallback( ++ GetRecordsCallback cb, std::unique_ptr records) override; ++ + private: + friend class SyncBackendHostCore; + +@@ -221,6 +227,9 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { + ModelTypeSet last_enabled_types_; + bool sessions_invalidation_enabled_ = false; + ++ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function_; ++ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function_; ++ + // Checks that we're on the same thread this was constructed on (UI thread). + SEQUENCE_CHECKER(sequence_checker_); + diff --git a/patches/components-sync-driver-sync_client.h.patch b/patches/components-sync-driver-sync_client.h.patch index 9935988a3a87..31d7a844728f 100644 --- a/patches/components-sync-driver-sync_client.h.patch +++ b/patches/components-sync-driver-sync_client.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/sync_client.h b/components/sync/driver/sync_client.h -index d38f986e2c55ab20453e868f934cb7f5e7982de1..b2f9685d2129a1325e541aefbdbe0a476d58c2eb 100644 +index 1cc9f14d35f7edae21fc21a3bd9970a7e60f4222..e19603dcf48f4d9d1c88961dccfaaef7ccf08824 100644 --- a/components/sync/driver/sync_client.h +++ b/components/sync/driver/sync_client.h -@@ -110,6 +110,8 @@ class SyncClient { +@@ -73,6 +73,8 @@ class SyncClient { // Returns the current SyncApiComponentFactory instance. virtual SyncApiComponentFactory* GetSyncApiComponentFactory() = 0; diff --git a/patches/components-sync-engine-sync_engine.h.patch b/patches/components-sync-engine-sync_engine.h.patch index 59f57b71121c..698ac2f82dec 100644 --- a/patches/components-sync-engine-sync_engine.h.patch +++ b/patches/components-sync-engine-sync_engine.h.patch @@ -1,23 +1,24 @@ diff --git a/components/sync/engine/sync_engine.h b/components/sync/engine/sync_engine.h -index 826cc5072e20b1760a64e8edca2933e83f797730..0a3187d2ae99e3f8b5e60ac289891a1d8b8112bd 100644 +index 2ed8818bde7b036e3bcbc704d77aebcaa78881dc..4aee53695e927ef582a610ac49067bf32d92cede 100644 --- a/components/sync/engine/sync_engine.h +++ b/components/sync/engine/sync_engine.h -@@ -82,6 +82,8 @@ class SyncEngine : public ModelTypeConfigurer { - // Define the polling intervals. Must not be zero. +@@ -88,6 +88,9 @@ class SyncEngine : public ModelTypeConfigurer { base::TimeDelta short_poll_interval; base::TimeDelta long_poll_interval; + + brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; + brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function; - ++ private: DISALLOW_COPY_AND_ASSIGN(InitParams); -@@ -191,6 +193,10 @@ class SyncEngine : public ModelTypeConfigurer { + }; +@@ -193,6 +196,10 @@ class SyncEngine : public ModelTypeConfigurer { // Enables/Disables invalidations for session sync related datatypes. virtual void SetInvalidationsForSessionsEnabled(bool enabled) = 0; + virtual void DispatchGetRecordsCallback( + brave_sync::GetRecordsCallback cb, -+ std::unique_ptr records) {}; ++ std::unique_ptr records) {} + private: DISALLOW_COPY_AND_ASSIGN(SyncEngine); diff --git a/patches/components-sync-engine-sync_manager.h.patch b/patches/components-sync-engine-sync_manager.h.patch index 4a243f0410cb..74a151b461a4 100644 --- a/patches/components-sync-engine-sync_manager.h.patch +++ b/patches/components-sync-engine-sync_manager.h.patch @@ -1,11 +1,11 @@ diff --git a/components/sync/engine/sync_manager.h b/components/sync/engine/sync_manager.h -index 514b05be4efe57ec9ae24c99186455456e56793b..0f2f3456c249aea0738c4d8da45b4ecce52f96d5 100644 +index 2a678f0a8d284de73dc0ef020b7869e7a570783d..1964971defdbb437b97ac44a7e8497fe566db907 100644 --- a/components/sync/engine/sync_manager.h +++ b/components/sync/engine/sync_manager.h -@@ -250,6 +250,9 @@ class SyncManager { - // Define the polling intervals. Must not be zero. - base::TimeDelta short_poll_interval; - base::TimeDelta long_poll_interval; +@@ -257,6 +257,9 @@ class SyncManager { + std::string cache_guid; + std::string birthday; + std::string bag_of_chips; + + brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; + brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function; diff --git a/patches/components-sync-engine_impl-commit.cc.patch b/patches/components-sync-engine_impl-commit.cc.patch index 95afab704039..aefc1179452e 100644 --- a/patches/components-sync-engine_impl-commit.cc.patch +++ b/patches/components-sync-engine_impl-commit.cc.patch @@ -1,15 +1,13 @@ diff --git a/components/sync/engine_impl/commit.cc b/components/sync/engine_impl/commit.cc -index c17988c44c5e5687549f8a18f8cd00b56da43422..be3e56546ce19abac3b8a5b470123ceb5c8b11f0 100644 +index 312f59cb0e7126d2c7d3059f3eef8819f993c523..29d49da7aaa37cb7e4e4b6e5ca3d59dc7c35ec85 100644 --- a/components/sync/engine_impl/commit.cc +++ b/components/sync/engine_impl/commit.cc -@@ -130,8 +130,9 @@ SyncerError Commit::PostAndProcessResponse( +@@ -131,8 +131,7 @@ SyncerError Commit::PostAndProcessResponse( TRACE_EVENT_BEGIN0("sync", "PostCommit"); sync_pb::ClientToServerResponse response; - const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( -- &message_, &response, cycle, nullptr); -+ // const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( -+ // &message_, &response, cycle, nullptr); +- message_, &response, cycle, nullptr); + const SyncerError post_result = PostBraveCommit(&message_, &response, cycle); TRACE_EVENT_END0("sync", "PostCommit"); diff --git a/patches/components-sync-engine_impl-get_updates_processor.cc.patch b/patches/components-sync-engine_impl-get_updates_processor.cc.patch index e4fcdf6788e7..a8000185f0ba 100644 --- a/patches/components-sync-engine_impl-get_updates_processor.cc.patch +++ b/patches/components-sync-engine_impl-get_updates_processor.cc.patch @@ -1,16 +1,8 @@ diff --git a/components/sync/engine_impl/get_updates_processor.cc b/components/sync/engine_impl/get_updates_processor.cc -index df71de3ef237e61b5cda7d96fe3a24a8f8f1bf6f..e0d3d7d6b04a68e58585494eb59799f3db52eb60 100644 +index e98ba9aa0801461d6698ba3ca6f39cf8f7153220..d007dd0260a97dc68d2113b6a2de3a94ab707f52 100644 --- a/components/sync/engine_impl/get_updates_processor.cc +++ b/components/sync/engine_impl/get_updates_processor.cc -@@ -28,6 +28,7 @@ using TypeSyncEntityMap = std::map; - using TypeToIndexMap = std::map; - - bool ShouldRequestEncryptionKey(SyncCycleContext* context) { -+ return false; - syncable::Directory* dir = context->directory(); - syncable::ReadTransaction trans(FROM_HERE, dir); - syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler(); -@@ -37,6 +38,7 @@ bool ShouldRequestEncryptionKey(SyncCycleContext* context) { +@@ -37,6 +37,7 @@ bool ShouldRequestEncryptionKey(SyncCycleContext* context) { SyncerError HandleGetEncryptionKeyResponse( const sync_pb::ClientToServerResponse& update_response, syncable::Directory* dir) { @@ -18,14 +10,12 @@ index df71de3ef237e61b5cda7d96fe3a24a8f8f1bf6f..e0d3d7d6b04a68e58585494eb59799f3 bool success = false; if (update_response.get_updates().encryption_keys_size() == 0) { LOG(ERROR) << "Failed to receive encryption key from server."; -@@ -220,8 +222,10 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( +@@ -222,8 +223,8 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( ModelTypeSet partial_failure_data_types; - SyncerError result = SyncerProtoUtil::PostClientToServerMessage( -- msg, &update_response, cycle, &partial_failure_data_types); -+ // SyncerError result = SyncerProtoUtil::PostClientToServerMessage( -+ // msg, &update_response, cycle, &partial_failure_data_types); +- *msg, &update_response, cycle, &partial_failure_data_types); + SyncerError result = ApplyBraveRecords(&update_response, request_types, + std::move(brave_records_)); diff --git a/patches/components-sync-engine_impl-get_updates_processor.h.patch b/patches/components-sync-engine_impl-get_updates_processor.h.patch index b96a2a52dbc8..763613b80dc5 100644 --- a/patches/components-sync-engine_impl-get_updates_processor.h.patch +++ b/patches/components-sync-engine_impl-get_updates_processor.h.patch @@ -1,16 +1,16 @@ diff --git a/components/sync/engine_impl/get_updates_processor.h b/components/sync/engine_impl/get_updates_processor.h -index c5560ec8113670c57f80245199031732f5795f23..29491b1919e38c21efe2194910070f55c3fcb276 100644 +index c5560ec8113670c57f80245199031732f5795f23..8097b4954a8b9f595e2c1eb7447770dcd4437d39 100644 --- a/components/sync/engine_impl/get_updates_processor.h +++ b/components/sync/engine_impl/get_updates_processor.h -@@ -45,6 +45,8 @@ class GetUpdatesProcessor { - // server, or an appropriate error value in case of failure. - SyncerError DownloadUpdates(ModelTypeSet* request_types, SyncCycle* cycle); +@@ -49,6 +49,8 @@ class GetUpdatesProcessor { + void ApplyUpdates(const ModelTypeSet& gu_types, + StatusController* status_controller); + void AddBraveRecords(std::unique_ptr records); + - // Applies any downloaded and processed updates. - void ApplyUpdates(const ModelTypeSet& gu_types, - StatusController* status_controller); + private: + // Populates a GetUpdates request message with per-type information. + void PrepareGetUpdates(const ModelTypeSet& gu_types, @@ -96,6 +98,8 @@ class GetUpdatesProcessor { const GetUpdatesDelegate& delegate_; diff --git a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch index 9031bb5ba31d..29ee76149658 100644 --- a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch +++ b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch @@ -1,13 +1,12 @@ diff --git a/components/sync/engine_impl/sync_manager_impl.cc b/components/sync/engine_impl/sync_manager_impl.cc -index a35bf89947af81e071f788458b8298448ee6d442..a01af29dd5ce191a98df575376e941d3bcf8029f 100644 +index f7a287c56667e43e85222bfecf9a076f1c717cb4..06de0e38047b933e21df845b9925b39307faca4f 100644 --- a/components/sync/engine_impl/sync_manager_impl.cc +++ b/components/sync/engine_impl/sync_manager_impl.cc -@@ -304,6 +304,8 @@ void SyncManagerImpl::Init(InitArgs* args) { +@@ -370,6 +370,7 @@ void SyncManagerImpl::Init(InitArgs* args) { name_, cycle_context_.get(), args->cancelation_signal, args->enable_local_sync_backend); + BraveInit(args); -+ scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); initialized_ = true; diff --git a/patches/components-sync-engine_impl-sync_manager_impl.h.patch b/patches/components-sync-engine_impl-sync_manager_impl.h.patch index c4f2ddf8b757..481dfa8cef06 100644 --- a/patches/components-sync-engine_impl-sync_manager_impl.h.patch +++ b/patches/components-sync-engine_impl-sync_manager_impl.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/sync_manager_impl.h b/components/sync/engine_impl/sync_manager_impl.h -index 4a6f7f40110d0f38bf40a994c0c5eb90535d9af5..3f6de6795abd0020b0e5d5518d7a506d50ed4e3b 100644 +index d0f1d63cc184c2b0780fea268a52cf52262efbd9..07bff3e8280dc7b621895076fd09851ffacfe4b2 100644 --- a/components/sync/engine_impl/sync_manager_impl.h +++ b/components/sync/engine_impl/sync_manager_impl.h -@@ -205,6 +205,8 @@ class SyncManagerImpl +@@ -202,6 +202,8 @@ class SyncManagerImpl using NotificationInfoMap = std::map; diff --git a/patches/components-sync-engine_impl-sync_scheduler.h.patch b/patches/components-sync-engine_impl-sync_scheduler.h.patch index ad664d3431f9..3e58e6299fc2 100644 --- a/patches/components-sync-engine_impl-sync_scheduler.h.patch +++ b/patches/components-sync-engine_impl-sync_scheduler.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/sync_scheduler.h b/components/sync/engine_impl/sync_scheduler.h -index 8fdb1ab1603eca3a9a4851edfa9ccd9006a65f92..5edfe9b45c498a84684d2602ad717f344792cc1a 100644 +index 5628c5b9c3139846cee938dd2ff882623a4e3e76..336055bf5ddd60dd9a717fbfea07dddb5f09fc78 100644 --- a/components/sync/engine_impl/sync_scheduler.h +++ b/components/sync/engine_impl/sync_scheduler.h -@@ -143,6 +143,9 @@ class SyncScheduler : public SyncCycle::Delegate { +@@ -125,6 +125,9 @@ class SyncScheduler : public SyncCycle::Delegate { // Called when the network layer detects a connection status change. virtual void OnConnectionStatusChange( network::mojom::ConnectionType type) = 0; diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch index 23d32c758acc..8635e0898308 100644 --- a/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/sync_scheduler_impl.cc b/components/sync/engine_impl/sync_scheduler_impl.cc -index 8442f8521ee12924eed5daa0182656bc7553b758..f8192fe5c2d80149b468fb0b544ea7c31e479289 100644 +index 8cc16fa6acbd49d4c7bdcd9571fa97f919314710..cbbea83e2a143be848157895cbb64ded689dd358 100644 --- a/components/sync/engine_impl/sync_scheduler_impl.cc +++ b/components/sync/engine_impl/sync_scheduler_impl.cc -@@ -704,6 +704,7 @@ void SyncSchedulerImpl::TryCanaryJob() { +@@ -668,6 +668,7 @@ void SyncSchedulerImpl::TryCanaryJob() { } void SyncSchedulerImpl::TrySyncCycleJob() { diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch index 9aeeaabf6277..07102d8ab41d 100644 --- a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch @@ -1,20 +1,21 @@ diff --git a/components/sync/engine_impl/sync_scheduler_impl.h b/components/sync/engine_impl/sync_scheduler_impl.h -index c2233fd5f7de560e47970eaa2d710d26c0b74e27..dc2272937e4e553b435051fcb7fb754d065c623f 100644 +index 56f6bf0ef065f776c24d473f7b9cc3b1d8d81e7d..ab31cca4a79738d27c8255c8a951dc7d92191d13 100644 --- a/components/sync/engine_impl/sync_scheduler_impl.h +++ b/components/sync/engine_impl/sync_scheduler_impl.h -@@ -81,6 +81,11 @@ class SyncSchedulerImpl : public SyncScheduler { - const SyncProtocolError& sync_protocol_error) override; +@@ -81,6 +81,12 @@ class SyncSchedulerImpl : public SyncScheduler { void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override; void OnReceivedMigrationRequest(ModelTypeSet types) override; + + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; + void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, + base::WaitableEvent* wevent) override; + void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, + brave_sync::PollSyncCycleDelegate) override; - ++ bool IsGlobalThrottle() const; bool IsGlobalBackoff() const; -@@ -183,6 +188,7 @@ class SyncSchedulerImpl : public SyncScheduler { + +@@ -179,6 +185,7 @@ class SyncSchedulerImpl : public SyncScheduler { // current thread. In the future it will request access token here. void TrySyncCycleJob(); void TrySyncCycleJobImpl(); @@ -22,7 +23,7 @@ index c2233fd5f7de560e47970eaa2d710d26c0b74e27..dc2272937e4e553b435051fcb7fb754d // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). // This function is for global throttling. -@@ -294,6 +300,9 @@ class SyncSchedulerImpl : public SyncScheduler { +@@ -288,6 +295,9 @@ class SyncSchedulerImpl : public SyncScheduler { // Used to prevent changing nudge delays by the server in integration tests. bool force_short_nudge_delay_for_test_ = false; diff --git a/patches/components-sync-engine_impl-syncer.cc.patch b/patches/components-sync-engine_impl-syncer.cc.patch index 6b4e5b02e3b1..bc79a7ca5a5e 100644 --- a/patches/components-sync-engine_impl-syncer.cc.patch +++ b/patches/components-sync-engine_impl-syncer.cc.patch @@ -1,16 +1,8 @@ diff --git a/components/sync/engine_impl/syncer.cc b/components/sync/engine_impl/syncer.cc -index d4d745fcd5a2d254dfcbdc44ed370e4479b28698..7c56e61aa54e2a054a840750c0ee3c62ac4c15e3 100644 +index 185e6463d605f8d13c2fa0a125d988e1f92e2aa3..d53834f95eca1f36d3bd2cccd5be4e2ddf919877 100644 --- a/components/sync/engine_impl/syncer.cc +++ b/components/sync/engine_impl/syncer.cc -@@ -34,6 +34,7 @@ void HandleCycleBegin(SyncCycle* cycle) { - - Syncer::Syncer(CancelationSignal* cancelation_signal) - : cancelation_signal_(cancelation_signal), is_syncing_(false) {} -+ // weak_ptr_factory_(this) {} - - Syncer::~Syncer() {} - -@@ -111,6 +112,7 @@ bool Syncer::DownloadAndApplyUpdates(ModelTypeSet* request_types, +@@ -104,6 +104,7 @@ bool Syncer::DownloadAndApplyUpdates(ModelTypeSet* request_types, Difference(*request_types, requested_commit_only_types); GetUpdatesProcessor get_updates_processor( cycle->context()->model_type_registry()->update_handler_map(), delegate); @@ -18,11 +10,3 @@ index d4d745fcd5a2d254dfcbdc44ed370e4479b28698..7c56e61aa54e2a054a840750c0ee3c62 SyncerError download_result; do { download_result = -@@ -170,6 +172,7 @@ SyncerError Syncer::BuildAndPostCommits(const ModelTypeSet& request_types, - SyncerError error = commit->PostAndProcessResponse( - nudge_tracker, cycle, cycle->mutable_status_controller(), - cycle->context()->extensions_activity()); -+ - commit->CleanUp(); - if (error.value() != SyncerError::SYNCER_OK) { - return error; diff --git a/patches/components-sync-engine_impl-syncer.h.patch b/patches/components-sync-engine_impl-syncer.h.patch index ece6fc7bc72c..cf0e35bdb86f 100644 --- a/patches/components-sync-engine_impl-syncer.h.patch +++ b/patches/components-sync-engine_impl-syncer.h.patch @@ -1,5 +1,5 @@ diff --git a/components/sync/engine_impl/syncer.h b/components/sync/engine_impl/syncer.h -index fd1203f8963834e69ce80be254527deecf57fdfd..efbb10a68436bd342a34560555b5a654597fe79a 100644 +index 23b389eada81c850c3a8856678d046e599a060da..add8bd72373425029cef6cec03d1e5787afbc2c6 100644 --- a/components/sync/engine_impl/syncer.h +++ b/components/sync/engine_impl/syncer.h @@ -32,7 +32,7 @@ class SyncCycle; @@ -11,26 +11,23 @@ index fd1203f8963834e69ce80be254527deecf57fdfd..efbb10a68436bd342a34560555b5a654 public: explicit Syncer(CancelationSignal* cancelation_signal); virtual ~Syncer(); -@@ -74,10 +74,13 @@ class Syncer { +@@ -69,6 +69,8 @@ class Syncer { // otherwise. - virtual bool PostClearServerData(SyncCycle* cycle); + virtual bool PollSyncShare(ModelTypeSet request_types, SyncCycle* cycle); + void DownloadBraveRecords(SyncCycle* cycle); + private: bool DownloadAndApplyUpdates(ModelTypeSet* request_types, SyncCycle* cycle, - const GetUpdatesDelegate& delegate); -+ void OnGetRecords(std::unique_ptr records); - - // This function will commit batches of unsynced items to the server until the - // number of unsynced and ready to commit items reaches zero or an error is -@@ -99,6 +102,8 @@ class Syncer { - // Whether the syncer is in the middle of a sync attempt. - bool is_syncing_; +@@ -89,6 +91,10 @@ class Syncer { + bool HandleCycleEnd(SyncCycle* cycle, + sync_pb::SyncEnums::GetUpdatesOrigin origin); ++ void OnGetRecords(std::unique_ptr records); ++ + std::unique_ptr brave_records_; + - DISALLOW_COPY_AND_ASSIGN(Syncer); - }; + CancelationSignal* const cancelation_signal_; + // Whether the syncer is in the middle of a sync attempt. diff --git a/patches/components-sync-engine_impl-syncer_proto_util.cc.patch b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch new file mode 100644 index 000000000000..67b8374a3fa5 --- /dev/null +++ b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch @@ -0,0 +1,14 @@ +diff --git a/components/sync/engine_impl/syncer_proto_util.cc b/components/sync/engine_impl/syncer_proto_util.cc +index 5c695de7675bb390c99eea546ccc015c066cd44c..00458c17cc22a5d32ba3f8a74c14f191301a17f5 100644 +--- a/components/sync/engine_impl/syncer_proto_util.cc ++++ b/components/sync/engine_impl/syncer_proto_util.cc +@@ -436,7 +436,8 @@ void SyncerProtoUtil::AddRequiredFieldsToClientToServerMessage( + DCHECK(msg); + SetProtocolVersion(msg); + AddRequestBirthday(cycle->context()->directory(), msg); +- DCHECK(msg->has_store_birthday() || !IsBirthdayRequired(*msg)); ++ // TODO(darkdh): deal with a6aca7bcee196866fc53d487f0025c502df7611a ++ // DCHECK(msg->has_store_birthday() || !IsBirthdayRequired(*msg)); + AddBagOfChips(cycle->context()->directory(), msg); + msg->set_api_key(google_apis::GetAPIKey()); + msg->mutable_client_status()->CopyFrom(cycle->context()->client_status()); diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index e2d108a583f7..a3bdbd08bb73 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index 32cbf98c9aef52a321a2ca67e403c570090ffa5c..ac3e9d0a4975deb6c531f2c990763dde9b00c81a 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..2b41a540a8e172cda43bce61dcfcfdcb133a34fd 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc -@@ -89,6 +89,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( +@@ -85,6 +85,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( bookmark_specifics.set_url(src->url().spec()); } bookmark_specifics.set_creation_time_us(src->date_added().ToInternalValue()); @@ -10,7 +10,7 @@ index 32cbf98c9aef52a321a2ca67e403c570090ffa5c..ac3e9d0a4975deb6c531f2c990763dde dst->SetBookmarkSpecifics(bookmark_specifics); SetSyncNodeFavicon(src, model, dst); SetSyncNodeMetaInfo(src, dst); -@@ -248,6 +249,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { +@@ -244,6 +245,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { // Acquire a scoped write lock via a transaction. syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); @@ -18,7 +18,7 @@ index 32cbf98c9aef52a321a2ca67e403c570090ffa5c..ac3e9d0a4975deb6c531f2c990763dde if (sync_id != syncer::kInvalidId) { UpdateSyncNode( node, bookmark_model_, &trans, model_associator_, error_handler()); -@@ -261,6 +263,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { +@@ -257,6 +259,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { model_associator_, error_handler()); } @@ -26,7 +26,7 @@ index 32cbf98c9aef52a321a2ca67e403c570090ffa5c..ac3e9d0a4975deb6c531f2c990763dde } if (syncer::kInvalidId != sync_id) { -@@ -420,6 +423,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -416,6 +419,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, return; } diff --git a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch index cc406af2f33e..a6ea15b3dae9 100644 --- a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch @@ -1,11 +1,11 @@ diff --git a/components/sync_bookmarks/bookmark_local_changes_builder.cc b/components/sync_bookmarks/bookmark_local_changes_builder.cc -index 92bda90302a1b3a153226056a3eb0aed0c02e725..1d1e531f67dfe247209b6e6d66b1adcbc70ecff3 100644 +index 9d4210fe4771ac67df1f9563f1fc722f8fc35aae..8bd933938ea30e89eb1b02cbecf7d0d6466ec75b 100644 --- a/components/sync_bookmarks/bookmark_local_changes_builder.cc +++ b/components/sync_bookmarks/bookmark_local_changes_builder.cc -@@ -73,6 +73,7 @@ BookmarkLocalChangesBuilder::BuildCommitRequests(size_t max_entries) const { - // EntityData should contain empty specifics to indicate deletion. +@@ -66,6 +66,7 @@ BookmarkLocalChangesBuilder::BuildCommitRequests(size_t max_entries) const { data.specifics = CreateSpecificsFromBookmarkNode( node, bookmark_model_, /*force_favicon_load=*/true); + data.non_unique_name = data.specifics.bookmark().title(); + AddBraveMetaInfo(node, bookmark_tracker_, bookmark_model_); } request.entity = data.PassToPtr(); From 5371a9bb93a9c5cb3299b7dc29dd28dce877477c Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Thu, 18 Apr 2019 15:19:22 +0300 Subject: [PATCH 04/73] Pass icon data --- chromium_src/components/sync/engine_impl/commit.cc | 8 ++++++++ .../components/sync/engine_impl/get_updates_processor.cc | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/chromium_src/components/sync/engine_impl/commit.cc b/chromium_src/components/sync/engine_impl/commit.cc index 38ae238d9c7f..65cbb2f4aa3f 100644 --- a/chromium_src/components/sync/engine_impl/commit.cc +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -16,6 +16,7 @@ SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message, } // namespace syncer #include "../../../../../components/sync/engine_impl/commit.cc" +#include "base/base64.h" #include "brave/components/brave_sync/jslib_const.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" #include "brave/components/brave_sync/jslib_messages.h" @@ -141,6 +142,13 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, metaInfo.value = std::to_string(entity.ctime()); bookmark->metaInfo.push_back(metaInfo); + if (bm_specifics.has_favicon()) { + std::string icon_base64; + base::Base64Encode(bm_specifics.favicon(), &icon_base64); + metaInfo.key = "icon_data"; + metaInfo.value = icon_base64; + bookmark->metaInfo.push_back(metaInfo); + } record->SetBookmark(std::move(bookmark)); record_list->push_back(std::move(record)); } diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index 600f4173747a..f9d39bc5cf48 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -7,6 +7,7 @@ SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*, ModelTypeSet*, } // namespace } // namespace syncer #include "../../../../../components/sync/engine_impl/get_updates_processor.cc" +#include "base/base64.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" @@ -98,6 +99,10 @@ void ExtractBookmarkMeta(sync_pb::SyncEntity* entity, bool result = base::StringToInt64(metaInfo.value, &ctime); DCHECK(result); entity->set_ctime(ctime); + } else if (metaInfo.key == "icon_data") { + std::string icon_data_decoded; + base::Base64Decode(metaInfo.value, &icon_data_decoded); + bm_specifics->set_favicon(icon_data_decoded); } } } From e7155d4387a2a7e5ef65c63931707d8ae649962d Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 18 Apr 2019 09:41:37 -0700 Subject: [PATCH 05/73] Migrate from legacy sync --- .../browser_sync/profile_sync_service.cc | 13 ++++--------- chromium_src/components/sync/engine_impl/commit.cc | 9 ++++++++- .../sync/engine_impl/get_updates_processor.cc | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/browser_sync/profile_sync_service.cc index 9bebfed70ed7..cd4a6f0e1ef9 100644 --- a/chromium_src/components/browser_sync/profile_sync_service.cc +++ b/chromium_src/components/browser_sync/profile_sync_service.cc @@ -207,11 +207,10 @@ std::unique_ptr BookmarkNodeToSyncBookmark( if (parent_order.empty() && node->parent()->is_permanent_node()) { if (node->parent() == model->bookmark_bar_node()) parent_order = - brave_sync_prefs->GetBookmarksBaseOrder() + '0'; + brave_sync_prefs->GetBookmarksBaseOrder() + '1'; else - // TODO(darkdh): put this to 1 when old code fix the order parent_order = - brave_sync_prefs->GetBookmarksBaseOrder() + '0'; + brave_sync_prefs->GetBookmarksBaseOrder() + '2'; } bookmark->prevOrder = prev_order; bookmark->nextOrder = next_order; @@ -783,7 +782,6 @@ void ProfileSyncService::BraveEngineParamsInit( void ProfileSyncService::OnNudgeSyncCycle( brave_sync::RecordsListPtr records) { - LOG(ERROR) << __func__; for (auto& record : *records) { record->deviceId = brave_sync_prefs_->GetThisDeviceId(); if (record->has_bookmark()) { @@ -793,12 +791,11 @@ void ProfileSyncService::OnNudgeSyncCycle( // bookmark toolbar if (!bookmark->hideInToolbar) bookmark->parentOrder = - brave_sync_prefs_->GetBookmarksBaseOrder() + '0'; + brave_sync_prefs_->GetBookmarksBaseOrder() + '1'; // other bookmarks else - // TODO(darkdh): put this to 1 when old code fix the order bookmark->parentOrder = - brave_sync_prefs_->GetBookmarksBaseOrder() + '0'; + brave_sync_prefs_->GetBookmarksBaseOrder() + '2'; } } } @@ -810,8 +807,6 @@ void ProfileSyncService::OnNudgeSyncCycle( void ProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent) { - LOG(ERROR) << __func__; - if (IsTimeEmpty(brave_sync_prefs_->GetLastFetchTime())) SendCreateDevice(); GetBraveSyncClient()->SendFetchSyncDevices(); diff --git a/chromium_src/components/sync/engine_impl/commit.cc b/chromium_src/components/sync/engine_impl/commit.cc index 65cbb2f4aa3f..fbfa175e37df 100644 --- a/chromium_src/components/sync/engine_impl/commit.cc +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -74,6 +74,7 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, std::string originator_cache_guid; std::string originator_client_item_id; + 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(); @@ -98,6 +99,11 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, } else if (bm_specifics.meta_info(i).key() == "originator_client_item_id") { originator_client_item_id = 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; } } @@ -150,7 +156,8 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, bookmark->metaInfo.push_back(metaInfo); } record->SetBookmark(std::move(bookmark)); - record_list->push_back(std::move(record)); + if (!skip_record) + record_list->push_back(std::move(record)); } sync_pb::CommitResponse_EntryResponse* entry_response = response->mutable_commit()->add_entryresponse(); diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index f9d39bc5cf48..66802d11b69d 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -107,6 +107,18 @@ void ExtractBookmarkMeta(sync_pb::SyncEntity* entity, } } +void MigrateFromLegacySync(sync_pb::SyncEntity* entity) { + if (!entity->has_originator_cache_guid()) { + entity->set_originator_cache_guid("legacy_originator_cache_guid"); + } + if (!entity->has_originator_client_item_id()) { + entity->set_originator_client_item_id("legacy_originator_client_item_id"); + } + if (!entity->has_version()) { + entity->set_version(1); + } +} + void AddRootForType(sync_pb::SyncEntity* entity, ModelType type) { DCHECK(entity); sync_pb::EntitySpecifics specifics; @@ -161,6 +173,8 @@ void AddBookmarkNode(sync_pb::SyncEntity* entity, const SyncRecord* record) { ExtractBookmarkMeta(entity, &specifics, bookmark_record); + MigrateFromLegacySync(entity); + // TODO(darkdh): migrate to UniquePosition entity->set_position_in_parent(GetIndexByOrder(bookmark_record.order)); std::string suffix = GenerateSyncableBookmarkHash(entity->originator_cache_guid(), From 2b431d6e787b0ebbc212d0c7a3d4807095d4f0d5 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 19 Apr 2019 18:54:42 -0700 Subject: [PATCH 06/73] Introduce IsFirstLoadedFavicon to avoid favicon loading trigged sending duplicate records --- .../bookmark_change_processor.cc | 21 +++++++++++ ...okmarks-bookmark_change_processor.cc.patch | 35 +++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 50f2bff406a4..6fafece87cab 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -9,6 +9,8 @@ namespace { void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, bookmarks::BookmarkModel* bookmark_model); +bool IsFirstLoadedFavicon(const bookmarks::BookmarkNode* node); + } // namespace } // namespace sync_bookmarks @@ -104,5 +106,24 @@ void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, "sync_timestamp", sync_timestamp); } +bool IsFirstLoadedFavicon(const BookmarkNode* node) { + // Avoid sending duplicate records right after applying CREATE records, + // BookmarkChangeProcessor::SetBookmarkFavicon, put favicon data into database + // BookmarkNode::favicon() and BookmarkNode::icon_url() are available only + // after first successfuly BookmarkModel::GetFavicon() which means + // BookmarkModel::OnFaviconDataAvailable has image result available. + // So we set metainfo to know if it is first time favicon load after create + // node from remote record + std::string FirstLoadedFavicon; + if (node->GetMetaInfo("FirstLoadedFavicon", &FirstLoadedFavicon)) { + if (!node->icon_url()) + return true; + BookmarkNode* mutable_node = const_cast(node); + mutable_node->DeleteMetaInfo("FirstLoadedFavicon"); + return true; + } + return false; +} + } // namespace } // namespace sync_bookmarks diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index a3bdbd08bb73..ac1b34a076ee 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..2b41a540a8e172cda43bce61dcfcfdcb133a34fd 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..76eec7bcf64a9bb28b4709f9ae01352933e1197e 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -85,6 +85,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -26,7 +26,17 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..2b41a540a8e172cda43bce61dcfcfdcb } if (syncer::kInvalidId != sync_id) { -@@ -416,6 +419,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -383,7 +386,8 @@ int64_t BookmarkChangeProcessor::UpdateSyncNode( + + void BookmarkChangeProcessor::BookmarkMetaInfoChanged( + BookmarkModel* model, const BookmarkNode* node) { +- BookmarkNodeChanged(model, node); ++ // TODO(darkdh): make sure the meta info changed is what we want to sync ++ // BookmarkNodeChanged(model, node); + } + + void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -416,6 +420,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, return; } @@ -38,3 +48,24 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..2b41a540a8e172cda43bce61dcfcfdcb if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, model_associator_)) { syncer::SyncError error(FROM_HERE, +@@ -458,6 +467,11 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( + return; + } + ++ model->RemoveObserver(this); ++ bool first_loaded_favicon = IsFirstLoadedFavicon(node); ++ model->AddObserver(this); ++ if (first_loaded_favicon) return; ++ + CreateOrUpdateSyncNode(node); + } + +@@ -718,6 +732,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( + << src.GetBookmarkSpecifics().url(); + continue; + } ++ BookmarkNode* mutable_node = const_cast(dst); ++ mutable_node->SetMetaInfo("FirstLoadedFavicon", "true"); + model_associator_->Associate(dst, src); + } + From 22e770b885df000bfb9abf7a0ef9a45f233e12ef Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 22 Apr 2019 15:04:24 -0700 Subject: [PATCH 07/73] Remove unused code --- browser/BUILD.gn | 2 - browser/bookmarks/brave_bookmark_client.h | 25 - browser/profiles/brave_profile_manager.cc | 1 - .../bookmarks/bookmark_model_factory.cc | 6 - components/brave_sync/BUILD.gn | 7 - components/brave_sync/brave_sync_service.h | 2 - .../brave_sync/brave_sync_service_factory.h | 46 - .../brave_sync/brave_sync_service_impl.cc | 732 ------------ .../brave_sync/brave_sync_service_impl.h | 225 ---- .../client/bookmark_change_processor.cc | 1050 ----------------- .../client/bookmark_change_processor.h | 147 --- components/brave_sync/client/bookmark_node.cc | 14 - components/brave_sync/client/bookmark_node.h | 31 - .../brave_sync/model/change_processor.h | 50 - 14 files changed, 2338 deletions(-) delete mode 100644 browser/bookmarks/brave_bookmark_client.h delete mode 100644 chromium_src/chrome/browser/bookmarks/bookmark_model_factory.cc delete mode 100644 components/brave_sync/brave_sync_service_factory.h delete mode 100644 components/brave_sync/brave_sync_service_impl.cc delete mode 100644 components/brave_sync/brave_sync_service_impl.h delete mode 100644 components/brave_sync/client/bookmark_change_processor.cc delete mode 100644 components/brave_sync/client/bookmark_change_processor.h delete mode 100644 components/brave_sync/client/bookmark_node.cc delete mode 100644 components/brave_sync/client/bookmark_node.h delete mode 100644 components/brave_sync/model/change_processor.h diff --git a/browser/BUILD.gn b/browser/BUILD.gn index f8d14af0061a..6bb9414a7de2 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -21,8 +21,6 @@ source_set("browser_process") { "autocomplete/brave_autocomplete_provider_client.h", "autocomplete/brave_autocomplete_scheme_classifier.cc", "autocomplete/brave_autocomplete_scheme_classifier.h", - "bookmarks/brave_bookmark_client.cc", - "bookmarks/brave_bookmark_client.h", "brave_shields/ad_block_pref_service_factory.cc", "brave_shields/ad_block_pref_service_factory.h", "brave_shields/cookie_pref_service_factory.cc", diff --git a/browser/bookmarks/brave_bookmark_client.h b/browser/bookmarks/brave_bookmark_client.h deleted file mode 100644 index ed3e7a96d99e..000000000000 --- a/browser/bookmarks/brave_bookmark_client.h +++ /dev/null @@ -1,25 +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_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_ -#define BRAVE_BROWSER_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_ - -#include "chrome/browser/bookmarks/chrome_bookmark_client.h" - -class BraveBookmarkClient : public ChromeBookmarkClient { - public: - BraveBookmarkClient( - Profile* profile, - bookmarks::ManagedBookmarkService* managed_bookmark_service, - sync_bookmarks::BookmarkSyncService* bookmark_sync_service); - - bookmarks::LoadExtraCallback GetLoadExtraNodesCallback() override; - bool IsPermanentNodeVisible( - const bookmarks::BookmarkPermanentNode* node) override; - - private: - DISALLOW_COPY_AND_ASSIGN(BraveBookmarkClient); -}; - -#endif // BRAVE_BROWSER_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_ diff --git a/browser/profiles/brave_profile_manager.cc b/browser/profiles/brave_profile_manager.cc index 98358a0c5ca4..422fe3ba85b7 100644 --- a/browser/profiles/brave_profile_manager.cc +++ b/browser/profiles/brave_profile_manager.cc @@ -22,7 +22,6 @@ #include "brave/components/brave_shields/browser/ad_block_regional_service.h" #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/brave_shields_util.h" -#include "brave/components/brave_sync/brave_sync_service_factory.h" #include "brave/content/browser/webui/brave_shared_resources_data_source.h" #include "chrome/browser/browser_process.h" #include "chrome/common/chrome_constants.h" diff --git a/chromium_src/chrome/browser/bookmarks/bookmark_model_factory.cc b/chromium_src/chrome/browser/bookmarks/bookmark_model_factory.cc deleted file mode 100644 index e65b9e757cb0..000000000000 --- a/chromium_src/chrome/browser/bookmarks/bookmark_model_factory.cc +++ /dev/null @@ -1,6 +0,0 @@ -#include "chrome/browser/bookmarks/chrome_bookmark_client.h" -#include "brave/browser/bookmarks/brave_bookmark_client.h" -// Stop loading old Brave permanent nodes, GetEntityForBookmarkNode will fail -// see 9645795920481e2a80613a72aeddba1a65490dac -// #define ChromeBookmarkClient BraveBookmarkClient -#include "../../../../../../chrome/browser/bookmarks/bookmark_model_factory.cc" diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 973240905b81..c413728192fb 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -7,15 +7,9 @@ import("//tools/grit/repack.gni") if (enable_brave_sync) { source_set("js_sync_lib_impl") { sources = [ - "brave_sync_service_impl.cc", - "brave_sync_service_impl.h", "client/brave_sync_client.h", "client/brave_sync_client_impl.cc", "client/brave_sync_client_impl.h", - "client/bookmark_change_processor.cc", - "client/bookmark_change_processor.h", - "client/bookmark_node.cc", - "client/bookmark_node.h", "client/client_ext_impl_data.cc", "client/client_ext_impl_data.h", "client/client_data.cc", @@ -60,7 +54,6 @@ source_set("core") { "bookmark_order_util.h", "brave_sync_prefs.cc", "brave_sync_prefs.h", - "model/change_processor.h", "settings.cc", "settings.h", "sync_devices.cc", diff --git a/components/brave_sync/brave_sync_service.h b/components/brave_sync/brave_sync_service.h index cc381134af08..ced50161e767 100644 --- a/components/brave_sync/brave_sync_service.h +++ b/components/brave_sync/brave_sync_service.h @@ -20,8 +20,6 @@ class BraveSyncServiceObserver; class Settings; class SyncDevices; -bookmarks::BookmarkPermanentNodeList -LoadExtraNodes(bookmarks::LoadExtraCallback callback, int64_t* next_node_id); bool IsSyncManagedNode(const bookmarks::BookmarkPermanentNode* node); class BraveSyncService { diff --git a/components/brave_sync/brave_sync_service_factory.h b/components/brave_sync/brave_sync_service_factory.h deleted file mode 100644 index 421286942045..000000000000 --- a/components/brave_sync/brave_sync_service_factory.h +++ /dev/null @@ -1,46 +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_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_SERVICE_FACTORY_H_ -#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_SERVICE_FACTORY_H_ - -#include "base/macros.h" -#include "base/memory/singleton.h" -#include "components/keyed_service/content/browser_context_keyed_service_factory.h" - -class Profile; - -namespace brave_sync { - -class BraveSyncService; - -class BraveSyncServiceFactory : public BrowserContextKeyedServiceFactory { - public: - static BraveSyncService* GetForProfile(Profile* profile); - static BraveSyncService* GetForBrowserContext( - content::BrowserContext* context); - - static BraveSyncServiceFactory* GetInstance(); - - private: - friend struct base::DefaultSingletonTraits; - - BraveSyncServiceFactory(); - ~BraveSyncServiceFactory() override; - - // BrowserContextKeyedServiceFactory: - KeyedService* BuildServiceInstanceFor( - content::BrowserContext* context) const override; - void RegisterProfilePrefs( - user_prefs::PrefRegistrySyncable* registry) override; - content::BrowserContext* GetBrowserContextToUse( - content::BrowserContext* context) const override; - bool ServiceIsNULLWhileTesting() const override; - - DISALLOW_COPY_AND_ASSIGN(BraveSyncServiceFactory); -}; - -} // namespace brave_sync - -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_SERVICE_FACTORY_H_ diff --git a/components/brave_sync/brave_sync_service_impl.cc b/components/brave_sync/brave_sync_service_impl.cc deleted file mode 100644 index 3b60c7795ff6..000000000000 --- a/components/brave_sync/brave_sync_service_impl.cc +++ /dev/null @@ -1,732 +0,0 @@ -/* Copyright 2016 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_sync_service_impl.h" - -#include -#include -#include -#include - -#include "base/task/post_task.h" -#include "brave/browser/ui/webui/sync/sync_ui.h" -#include "brave/components/brave_sync/bookmark_order_util.h" -#include "brave/components/brave_sync/brave_sync_prefs.h" -#include "brave/components/brave_sync/brave_sync_service_observer.h" -#include "brave/components/brave_sync/client/bookmark_change_processor.h" -#include "brave/components/brave_sync/client/brave_sync_client_impl.h" -#include "brave/components/brave_sync/sync_devices.h" -#include "brave/components/brave_sync/jslib_const.h" -#include "brave/components/brave_sync/jslib_messages.h" -#include "brave/components/brave_sync/settings.h" -#include "brave/components/brave_sync/tools.h" -#include "brave/components/brave_sync/values_conv.h" -#include "chrome/browser/profiles/profile.h" -#include "content/public/browser/browser_task_traits.h" -#include "content/public/browser/browser_thread.h" -#include "components/bookmarks/browser/bookmark_model.h" -#include "net/base/network_interfaces.h" - -namespace brave_sync { - -namespace { - -RecordsListPtr CreateDeviceCreationRecordExtension( - const std::string& deviceName, - const std::string& objectId, - const jslib::SyncRecord::Action &action, - const std::string& deviceId) { - RecordsListPtr records = std::make_unique(); - - SyncRecordPtr record = std::make_unique(); - - record->action = action; - record->deviceId = deviceId; - record->objectId = objectId; - record->objectData = jslib_const::SyncObjectData_DEVICE; // "device" - - std::unique_ptr device = std::make_unique(); - device->name = deviceName; - record->SetDevice(std::move(device)); - - records->emplace_back(std::move(record)); - - return records; -} - -SyncRecordPtr PrepareResolvedDevice( - SyncDevice* device, - int action) { - auto record = std::make_unique(); - - record->action = ConvertEnum(action, - brave_sync::jslib::SyncRecord::Action::A_MIN, - brave_sync::jslib::SyncRecord::Action::A_MAX, - brave_sync::jslib::SyncRecord::Action::A_INVALID); - record->deviceId = device->device_id_; - record->objectId = device->object_id_; - record->objectData = jslib_const::SyncObjectData_DEVICE; // "device" - - std::unique_ptr device_record = - std::make_unique(); - device_record->name = device->name_; - record->SetDevice(std::move(device_record)); - - return record; -} - -} // namespace - -BraveSyncServiceImpl::BraveSyncServiceImpl(Profile* profile) : - sync_client_(BraveSyncClient::Create(profile)), - sync_initialized_(false), - sync_words_(std::string()), - profile_(profile), - sync_prefs_(new brave_sync::prefs::Prefs(profile->GetPrefs())), - bookmark_change_processor_(BookmarkChangeProcessor::Create( - profile, - sync_client_.get(), - sync_prefs_.get())), - timer_(std::make_unique()) { - sync_client_->set_sync_message_handler(this); - // Moniter syncs prefs required in GetSettingsAndDevices - profile_pref_change_registrar_.Init(profile->GetPrefs()); - profile_pref_change_registrar_.Add( - prefs::kSyncEnabled, - base::Bind(&BraveSyncServiceImpl::OnSyncPrefsChanged, - base::Unretained(this))); - profile_pref_change_registrar_.Add( - prefs::kSyncDeviceName, - base::Bind(&BraveSyncServiceImpl::OnSyncPrefsChanged, - base::Unretained(this))); - profile_pref_change_registrar_.Add( - prefs::kSyncDeviceList, - base::Bind(&BraveSyncServiceImpl::OnSyncPrefsChanged, - base::Unretained(this))); - profile_pref_change_registrar_.Add( - prefs::kSyncBookmarksEnabled, - base::Bind(&BraveSyncServiceImpl::OnSyncPrefsChanged, - base::Unretained(this))); - profile_pref_change_registrar_.Add( - prefs::kSyncSiteSettingsEnabled, - base::Bind(&BraveSyncServiceImpl::OnSyncPrefsChanged, - base::Unretained(this))); - profile_pref_change_registrar_.Add( - prefs::kSyncHistoryEnabled, - base::Bind(&BraveSyncServiceImpl::OnSyncPrefsChanged, - base::Unretained(this))); - - if (!sync_prefs_->GetSeed().empty() && - !sync_prefs_->GetThisDeviceName().empty()) { - sync_configured_ = true; - } -} - -BraveSyncServiceImpl::~BraveSyncServiceImpl() { -} - -BraveSyncClient* BraveSyncServiceImpl::GetBraveSyncClient() { - return sync_client_.get(); -} - -bool BraveSyncServiceImpl::IsSyncConfigured() { - return sync_configured_ && - // When there is 0 or 1 device, it means chain is not completely created, - // so we should give a chance to make force reset in |OnSetupSyncHaveCode| - // or in |OnSetupSyncNewToSync| - (sync_prefs_->GetSyncDevices()->size() >= 2); -} - -bool BraveSyncServiceImpl::IsSyncInitialized() { - return sync_initialized_; -} - -void BraveSyncServiceImpl::Shutdown() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - bookmark_change_processor_->Stop(); - - StopLoop(); -} - -void BraveSyncServiceImpl::OnSetupSyncHaveCode(const std::string& sync_words, - const std::string& device_name) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - if (sync_words.empty()) { - OnSyncSetupError("ERR_SYNC_WRONG_WORDS"); - return; - } - - if (initializing_) { - NotifyLogMessage("currently initializing"); - return; - } - - if (IsSyncConfigured()) { - NotifyLogMessage("already configured"); - return; - } - - ForceCompleteReset(); - DCHECK(!sync_prefs_->GetSyncEnabled()); - SetDeviceName(device_name); - initializing_ = true; - - sync_prefs_->SetSyncEnabled(true); - sync_words_ = sync_words; -} - -void BraveSyncServiceImpl::OnSetupSyncNewToSync( - const std::string& device_name) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - if (initializing_) { - NotifyLogMessage("currently initializing"); - return; - } - - if (IsSyncConfigured()) { - NotifyLogMessage("already configured"); - return; - } - - ForceCompleteReset(); - - DCHECK(!sync_prefs_->GetSyncEnabled()); - - sync_words_.clear(); // If the previous attempt was connect to sync chain - // and failed to receive save-init-data - SetDeviceName(device_name); - initializing_ = true; - - sync_prefs_->SetSyncEnabled(true); -} - -void BraveSyncServiceImpl::OnDeleteDevice(const std::string& device_id) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - auto sync_devices = sync_prefs_->GetSyncDevices(); - - const SyncDevice *device = sync_devices->GetByDeviceId(device_id); - if (device) { - const std::string device_name = device->name_; - const std::string object_id = device->object_id_; - SendDeviceSyncRecord( - jslib::SyncRecord::Action::A_DELETE, device_name, device_id, object_id); - } -} - -void BraveSyncServiceImpl::OnResetSync() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - auto sync_devices = sync_prefs_->GetSyncDevices(); - - if (sync_devices->size() == 0) { - // Fail safe option - VLOG(2) << "[Sync] " << __func__ << " unexpected zero device size"; - ResetSyncInternal(); - } else { - // We have to send delete record and wait for library deleted response then - // we can reset it by ResetInternal() - const std::string device_id = sync_prefs_->GetThisDeviceId(); - OnDeleteDevice(device_id); - reseting_ = true; - } -} - -void BraveSyncServiceImpl::GetSettingsAndDevices( - const GetSettingsAndDevicesCallback& callback) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - auto settings = sync_prefs_->GetBraveSyncSettings(); - auto devices = sync_prefs_->GetSyncDevices(); - callback.Run(std::move(settings), std::move(devices)); -} - -void BraveSyncServiceImpl::GetSyncWords() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - // Ask sync client - DCHECK(sync_client_); - std::string seed = sync_prefs_->GetSeed(); - sync_client_->NeedSyncWords(seed); -} - -std::string BraveSyncServiceImpl::GetSeed() { - return sync_prefs_->GetSeed(); -} - -void BraveSyncServiceImpl::OnSetSyncEnabled(const bool sync_this_device) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - sync_prefs_->SetSyncEnabled(sync_this_device); -} - -void BraveSyncServiceImpl::OnSetSyncBookmarks(const bool sync_bookmarks) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); -} - -void BraveSyncServiceImpl::OnSetSyncBrowsingHistory( - const bool sync_browsing_history) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - sync_prefs_->SetSyncHistoryEnabled(sync_browsing_history); -} - -void BraveSyncServiceImpl::OnSetSyncSavedSiteSettings( - const bool sync_saved_site_settings) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - sync_prefs_->SetSyncSiteSettingsEnabled(sync_saved_site_settings); -} - -// SyncLibToBrowserHandler overrides -void BraveSyncServiceImpl::BackgroundSyncStarted(bool startup) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - if (startup) - bookmark_change_processor_->Start(); - - StartLoop(); -} - -void BraveSyncServiceImpl::BackgroundSyncStopped(bool shutdown) { - if (shutdown) - Shutdown(); - else - StopLoop(); -} - -void BraveSyncServiceImpl::OnSyncDebug(const std::string& message) { - NotifyLogMessage(message); -} - -void BraveSyncServiceImpl::OnSyncSetupError(const std::string& error) { - if (initializing_) { - sync_prefs_->Clear(); - initializing_ = false; - } - NotifySyncSetupError(error); -} - -void BraveSyncServiceImpl::OnGetInitData(const std::string& sync_version) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - Uint8Array seed; - if (!sync_words_.empty()) { - VLOG(1) << "[Brave Sync] Init from sync words"; - } else if (!sync_prefs_->GetSeed().empty()) { - seed = Uint8ArrayFromString(sync_prefs_->GetSeed()); - VLOG(1) << "[Brave Sync] Init from prefs"; - } else { - VLOG(1) << "[Brave Sync] Init new chain"; - } - - Uint8Array device_id; - if (!sync_prefs_->GetThisDeviceId().empty()) { - device_id = Uint8ArrayFromString(sync_prefs_->GetThisDeviceId()); - VLOG(1) << "[Brave Sync] Init device id from prefs: " << - StrFromUint8Array(device_id); - } else { - VLOG(1) << "[Brave Sync] Init empty device id"; - } - - DCHECK(!sync_version.empty()); - // TODO(bridiver) - this seems broken because using the version we get back - // from the server (currently v1.4.2) causes things to break. What is the - // the point of having this value? - sync_prefs_->SetApiVersion("0"); - - brave_sync::client_data::Config config; - config.api_version = sync_prefs_->GetApiVersion(); - config.server_url = "https://sync.brave.com"; - config.debug = true; - sync_client_->SendGotInitData(seed, device_id, config, sync_words_); -} - -void BraveSyncServiceImpl::OnSaveInitData(const Uint8Array& seed, - const Uint8Array& device_id) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - DCHECK(!sync_initialized_); - // If we are here and initializing_ is false, we have came - // not from OnSetupSyncNewToSync or OnSetupSyncHaveCode. - // One case is we put wrong code words and then restarted before cleared - // kSyncEnabled pref. This should not happen. - DCHECK(initializing_); - - std::string seed_str = StrFromUint8Array(seed); - std::string device_id_str = StrFromUint8Array(device_id); - - std::string prev_seed_str = sync_prefs_->GetPrevSeed(); - - sync_words_.clear(); - DCHECK(!seed_str.empty()); - - if (prev_seed_str == seed_str) { // reconnecting to previous sync chain - sync_prefs_->SetPrevSeed(std::string()); - } else if (!prev_seed_str.empty()) { // connect/create to new sync chain - bookmark_change_processor_->Reset(true); - sync_prefs_->SetPrevSeed(std::string()); - } else { - // This is not required, because when there is no previous seed, bookmarks - // should not have a metadata. However, this is done by intention, to be - // a remedy for cases when sync had been reset and prev_seed_str had been - // cleared when it shouldn't (brave-browser#3188). - bookmark_change_processor_->Reset(true); - } - - sync_prefs_->SetSeed(seed_str); - sync_prefs_->SetThisDeviceId(device_id_str); - - sync_configured_ = true; - - sync_prefs_->SetSyncBookmarksEnabled(true); - // TODO(bridiver) - re-enable these when we add history, site settings - sync_prefs_->SetSyncSiteSettingsEnabled(false); - sync_prefs_->SetSyncHistoryEnabled(false); - - initializing_ = false; -} - -void BraveSyncServiceImpl::OnSyncReady() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - const std::string bookmarks_base_order = sync_prefs_->GetBookmarksBaseOrder(); - if (bookmarks_base_order.empty()) { - std::string platform = tools::GetPlatformName(); - sync_client_->SendGetBookmarksBaseOrder(sync_prefs_->GetThisDeviceId(), - platform); - // OnSyncReady will be called by OnSaveBookmarksBaseOrder - return; - } - - DCHECK(false == sync_initialized_); - sync_initialized_ = true; - - // fetch the records - RequestSyncData(); -} - -void BraveSyncServiceImpl::OnGetExistingObjects( - const std::string& category_name, - std::unique_ptr records, - const base::Time &last_record_time_stamp, - const bool is_truncated) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - // TODO(bridiver) - what do we do with is_truncated ? - // It appears to be ignored in b-l - if (!tools::IsTimeEmpty(last_record_time_stamp)) { - sync_prefs_->SetLatestRecordTime(last_record_time_stamp); - } - - if (category_name == jslib_const::kBookmarks) { - auto records_and_existing_objects = - std::make_unique(); - bookmark_change_processor_->GetAllSyncData( - *records.get(), records_and_existing_objects.get()); - sync_client_->SendResolveSyncRecords( - category_name, std::move(records_and_existing_objects)); - } else if (category_name == brave_sync::jslib_const::kPreferences) { - auto existing_records = PrepareResolvedPreferences(*records.get()); - sync_client_->SendResolveSyncRecords( - category_name, std::move(existing_records)); - } -} - -void BraveSyncServiceImpl::OnResolvedSyncRecords( - const std::string& category_name, - std::unique_ptr records) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - if (category_name == brave_sync::jslib_const::kPreferences) { - OnResolvedPreferences(*records.get()); - } else if (category_name == brave_sync::jslib_const::kBookmarks) { - bookmark_change_processor_->ApplyChangesFromSyncModel(*records.get()); - bookmark_change_processor_->SendUnsynced(); - } else if (category_name == brave_sync::jslib_const::kHistorySites) { - NOTIMPLEMENTED(); - } -} - -std::unique_ptr -BraveSyncServiceImpl::PrepareResolvedPreferences(const RecordsList& records) { - auto sync_devices = sync_prefs_->GetSyncDevices(); - - auto records_and_existing_objects = - std::make_unique(); - - for (const SyncRecordPtr& record : records) { - auto resolved_record = std::make_unique(); - resolved_record->first = jslib::SyncRecord::Clone(*record); - auto* device = sync_devices->GetByObjectId(record->objectId); - if (device) - resolved_record->second = PrepareResolvedDevice(device, record->action); - records_and_existing_objects->emplace_back(std::move(resolved_record)); - } - - return records_and_existing_objects; -} - -void BraveSyncServiceImpl::OnResolvedPreferences(const RecordsList& records) { - const std::string this_device_id = sync_prefs_->GetThisDeviceId(); - bool this_device_deleted = false; - bool contains_only_one_device = false; - - auto sync_devices = sync_prefs_->GetSyncDevices(); - for (const auto &record : records) { - DCHECK(record->has_device() || record->has_sitesetting()); - if (record->has_device()) { - bool actually_merged = false; - sync_devices->Merge( - SyncDevice(record->GetDevice().name, - record->objectId, - record->deviceId, - record->syncTimestamp.ToJsTime()), - record->action, - &actually_merged); - this_device_deleted = this_device_deleted || - (record->deviceId == this_device_id && - record->action == jslib::SyncRecord::Action::A_DELETE && - actually_merged); - contains_only_one_device = sync_devices->size() < 2 && - record->action == jslib::SyncRecord::Action::A_DELETE && - actually_merged; - } - } // for each device - - sync_prefs_->SetSyncDevices(*sync_devices); - - if (this_device_deleted) { - ResetSyncInternal(); - } else if (contains_only_one_device) { - // We see amount of devices had been decreased to 1 and it is not this - // device had been deleted. So call OnResetSync which will send DELETE - // record for this device - OnResetSync(); - } -} - -void BraveSyncServiceImpl::OnSyncPrefsChanged(const std::string& pref) { - if (pref == prefs::kSyncEnabled) { - sync_client_->OnSyncEnabledChanged(); - if (!sync_prefs_->GetSyncEnabled()) - sync_initialized_ = false; - } - NotifySyncStateChanged(); -} - -void BraveSyncServiceImpl::OnDeletedSyncUser() { - NOTIMPLEMENTED(); -} - -void BraveSyncServiceImpl::OnDeleteSyncSiteSettings() { - NOTIMPLEMENTED(); -} - -void BraveSyncServiceImpl::OnSaveBookmarksBaseOrder(const std::string& order) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - DCHECK(!order.empty()); - sync_prefs_->SetBookmarksBaseOrder(order); - OnSyncReady(); -} - -void BraveSyncServiceImpl::OnSaveBookmarkOrder(const std::string& object_id, - const std::string& order) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - DCHECK(!order.empty()); - bookmark_change_processor_->ApplyOrder(object_id, order); -} - -void BraveSyncServiceImpl::OnSyncWordsPrepared(const std::string& words) { - NotifyHaveSyncWords(words); -} - -// Here we query sync lib for the records after initialization (or again later) -void BraveSyncServiceImpl::RequestSyncData() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - const bool bookmarks = sync_prefs_->GetSyncBookmarksEnabled(); - const bool history = sync_prefs_->GetSyncHistoryEnabled(); - const bool preferences = sync_prefs_->GetSyncSiteSettingsEnabled(); - - if (!bookmarks && !history && !preferences) - return; - - base::Time last_fetch_time = sync_prefs_->GetLastFetchTime(); - - if (tools::IsTimeEmpty(last_fetch_time)) { - SendCreateDevice(); - } - - sync_client_->SendFetchSyncDevices(); - - if (sync_prefs_->GetSyncDevices()->size() <= 1) { - // No sense to fetch or sync bookmarks when there no at least two devices - // in chain - // Set last fetch time here because we had fetched devices at least - sync_prefs_->SetLastFetchTime(base::Time::Now()); - return; - } - - if (tools::IsTimeEmpty(last_fetch_time)) { - bookmark_change_processor_->InitialSync(); - } - - FetchSyncRecords(bookmarks, history, preferences, 1000); -} - -void BraveSyncServiceImpl::FetchSyncRecords(const bool bookmarks, - const bool history, const bool preferences, int max_records) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - DCHECK(bookmarks || history || preferences); - if (!(bookmarks || history || preferences)) { - return; - } - - std::vector category_names; - using brave_sync::jslib_const::kHistorySites; - using brave_sync::jslib_const::kBookmarks; - using brave_sync::jslib_const::kPreferences; - if (history) { - category_names.push_back(kHistorySites); // "HISTORY_SITES"; - } - if (bookmarks) { - category_names.push_back(kBookmarks); // "BOOKMARKS"; - } - if (preferences) { - category_names.push_back(kPreferences); // "PREFERENCES"; - } - - DCHECK(sync_client_); - sync_prefs_->SetLastFetchTime(base::Time::Now()); - - base::Time start_at_time = sync_prefs_->GetLatestRecordTime(); - sync_client_->SendFetchSyncRecords( - category_names, - start_at_time, - max_records); -} - -void BraveSyncServiceImpl::SendCreateDevice() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - std::string device_name = sync_prefs_->GetThisDeviceName(); - std::string object_id = brave_sync::tools::GenerateObjectId(); - std::string device_id = sync_prefs_->GetThisDeviceId(); - CHECK(!device_id.empty()); - - SendDeviceSyncRecord( - jslib::SyncRecord::Action::A_CREATE, - device_name, - device_id, - object_id); -} - -void BraveSyncServiceImpl::SendDeviceSyncRecord( - const int action, - const std::string& device_name, - const std::string& device_id, - const std::string& object_id) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - RecordsListPtr records = CreateDeviceCreationRecordExtension( - device_name, - object_id, - static_cast(action), - device_id); - sync_client_->SendSyncRecords( - jslib_const::SyncRecordType_PREFERENCES, *records); -} - -static const int64_t kCheckUpdatesIntervalSec = 60; - -void BraveSyncServiceImpl::StartLoop() { - timer_->Start(FROM_HERE, - base::TimeDelta::FromSeconds(kCheckUpdatesIntervalSec), - this, - &BraveSyncServiceImpl::LoopProc); -} - -void BraveSyncServiceImpl::StopLoop() { - timer_->Stop(); -} - -void BraveSyncServiceImpl::LoopProc() { - base::CreateSingleThreadTaskRunnerWithTraits( - {content::BrowserThread::UI})->PostTask( - FROM_HERE, - base::BindOnce(&BraveSyncServiceImpl::LoopProcThreadAligned, - // the timer will always be destroyed before the service - base::Unretained(this))); -} - -void BraveSyncServiceImpl::LoopProcThreadAligned() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - if (!sync_initialized_) { - return; - } - - RequestSyncData(); -} - -void BraveSyncServiceImpl::NotifyLogMessage(const std::string& message) { - DLOG(INFO) << message; -} - -void BraveSyncServiceImpl::NotifySyncSetupError(const std::string& error) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - for (auto& observer : observers_) - observer.OnSyncSetupError(this, error); -} - -void BraveSyncServiceImpl::NotifySyncStateChanged() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - for (auto& observer : observers_) - observer.OnSyncStateChanged(this); -} - -void BraveSyncServiceImpl::NotifyHaveSyncWords( - const std::string& sync_words) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - for (auto& observer : observers_) - observer.OnHaveSyncWords(this, sync_words); -} - -void BraveSyncServiceImpl::ResetSyncInternal() { - bookmark_change_processor_->Reset(false); - - sync_prefs_->SetPrevSeed(sync_prefs_->GetSeed()); - - sync_prefs_->Clear(); - - sync_configured_ = false; - sync_initialized_ = false; - - sync_prefs_->SetSyncEnabled(false); - - reseting_ = false; -} - -void BraveSyncServiceImpl::ForceCompleteReset() { - if (reseting_) { - ResetSyncInternal(); - } -} - -void BraveSyncServiceImpl::SetDeviceName(const std::string& name) { - if (name.empty()) { - std::string hostname = net::GetHostName(); - if (hostname.empty()) { -#if defined(OS_MACOSX) - hostname = std::string("Mac Desktop"); -#elif defined(OS_LINUX) - hostname = std::string("Linux Desktop"); -#elif defined(OS_WIN) - hostname = std::string("Windows Desktop"); -#endif - } - sync_prefs_->SetThisDeviceName(hostname); - } else { - sync_prefs_->SetThisDeviceName(name); - } -} - -} // namespace brave_sync diff --git a/components/brave_sync/brave_sync_service_impl.h b/components/brave_sync/brave_sync_service_impl.h deleted file mode 100644 index 9cbbce409be8..000000000000 --- a/components/brave_sync/brave_sync_service_impl.h +++ /dev/null @@ -1,225 +0,0 @@ -/* Copyright 2016 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_BRAVE_SYNC_SERVICE_IMPL_H_ -#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_SERVICE_IMPL_H_ - -#include -#include -#include - -#include "base/macros.h" -#include "base/scoped_observer.h" -#include "base/time/time.h" -#include "brave/components/brave_sync/brave_sync_service.h" -#include "brave/components/brave_sync/client/brave_sync_client.h" -#include "components/keyed_service/core/keyed_service.h" -#include "components/prefs/pref_change_registrar.h" - -FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkAdded); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkDeleted); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, GetSyncWords); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, GetSeed); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnDeleteDevice); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnDeleteDeviceWhenSelfDeleted); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnResetSync); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, ClientOnGetInitData); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnGetInitData); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSaveBookmarksBaseOrder); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncPrefsChanged); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncDebug); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncReadyAlreadyWithSync); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncReadyNewToSync); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnGetExistingObjects); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, BackgroundSyncStarted); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, BackgroundSyncStopped); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, - OnSetupSyncHaveCode_Reset_SetupAgain); - -class BraveSyncServiceTest; - -namespace base { -class RepeatingTimer; -} - -namespace brave_sync { - -class SyncDevices; -class Settings; -class BookmarkChangeProcessor; - -namespace prefs { -class Prefs; -} // namespace prefs - -using SendDeviceSyncRecordCallback = base::OnceCallback; - -class BraveSyncServiceImpl - : public BraveSyncService, - public KeyedService, - public SyncMessageHandler { - public: - explicit BraveSyncServiceImpl(Profile *profile); - ~BraveSyncServiceImpl() override; - - // KeyedService overrides - void Shutdown() override; - - // BraveSyncService messages from UI - void OnSetupSyncHaveCode(const std::string& sync_words, - const std::string& device_name) override; - void OnSetupSyncNewToSync(const std::string& device_name) override; - void OnDeleteDevice(const std::string& device_id) override; - void OnResetSync() override; - void GetSyncWords() override; - std::string GetSeed() override; - void OnSetSyncEnabled(const bool sync_this_device) override; - void OnSetSyncBookmarks(const bool sync_bookmarks) override; - void OnSetSyncBrowsingHistory(const bool sync_browsing_history) override; - void OnSetSyncSavedSiteSettings(const bool sync_saved_site_settings) override; - - void GetSettingsAndDevices( - const GetSettingsAndDevicesCallback& callback) override; - - bool IsSyncConfigured(); - bool IsSyncInitialized(); - - BraveSyncClient* GetBraveSyncClient() override; - - private: - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkAdded); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkDeleted); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, GetSyncWords); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, GetSeed); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnDeleteDevice); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, - OnDeleteDeviceWhenSelfDeleted); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnResetSync); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, ClientOnGetInitData); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSaveBookmarksBaseOrder); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetInitData); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncPrefsChanged); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncDebug); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncReadyAlreadyWithSync); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncReadyNewToSync); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetExistingObjects); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BackgroundSyncStarted); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BackgroundSyncStopped); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, - OnSetupSyncHaveCode_Reset_SetupAgain); - - friend class ::BraveSyncServiceTest; - - // SyncMessageHandler overrides - void BackgroundSyncStarted(bool startup) override; - void BackgroundSyncStopped(bool shutdown) override; - void OnSyncDebug(const std::string& message) override; - void OnSyncSetupError(const std::string& error) override; - void OnGetInitData(const std::string& sync_version) override; - void OnSaveInitData(const Uint8Array& seed, - const Uint8Array& device_id) override; - void OnSyncReady() override; - void OnGetExistingObjects(const std::string& category_name, - std::unique_ptr records, - const base::Time &last_record_time_stamp, - const bool is_truncated) override; - void OnResolvedSyncRecords(const std::string& category_name, - std::unique_ptr records) override; - void OnDeletedSyncUser() override; - void OnDeleteSyncSiteSettings() override; - void OnSaveBookmarksBaseOrder(const std::string& order) override; - void OnSaveBookmarkOrder(const std::string& object_id, - const std::string& order) override; - void OnSyncWordsPrepared(const std::string& words) override; - - void OnResolvedHistorySites(const RecordsList &records); - void OnResolvedPreferences(const RecordsList &records); - std::unique_ptr PrepareResolvedPreferences( - const RecordsList& records); - - void OnSyncPrefsChanged(const std::string& pref); - - // Other private methods - void RequestSyncData(); - void FetchSyncRecords(const bool bookmarks, const bool history, - const bool preferences, int max_records); - - void SendCreateDevice(); - void SendDeviceSyncRecord( - const int action, - const std::string& device_name, - const std::string& device_id, - const std::string& object_id); - - void SetUpdateDeleteDeviceName_Ext( - const std::string& action, - const std::string& deviceName, - const std::string& deviceId, - const std::string& objectId); - - void StartLoop(); - void StopLoop(); - void LoopProc(); - void LoopProcThreadAligned(); - - void GetExistingHistoryObjects( - const RecordsList &records, - const base::Time &last_record_time_stamp, - const bool is_truncated); - - void NotifyLogMessage(const std::string& message); - void NotifySyncSetupError(const std::string& error); - void NotifySyncStateChanged(); - void NotifyHaveSyncWords(const std::string& sync_words); - - void ResetSyncInternal(); - void ForceCompleteReset(); - bool GetResettingForTest() const { - return reseting_; - } - - void SetDeviceName(const std::string& name); - - std::unique_ptr sync_client_; - - // True when is in active sync chain - bool sync_configured_ = false; - // True if we have received SyncReady from JS lib - bool sync_initialized_ = false; - - // Prevent two sequential calls OnSetupSyncHaveCode or OnSetupSyncNewToSync - // while being initializing - bool initializing_ = false; - - bool reseting_ = false; - - std::string sync_words_; - - std::unique_ptr settings_; - - Profile* profile_; - std::unique_ptr sync_prefs_; - - std::unique_ptr bookmark_change_processor_; - // Moment when FETCH_SYNC_RECORDS was sent, - // will be saved on GET_EXISTING_OBJECTS to be sure request was processed - base::Time last_time_fetch_sent_; - - std::unique_ptr timer_; - - // Registrar used to monitor the profile prefs. - PrefChangeRegistrar profile_pref_change_registrar_; - - DISALLOW_COPY_AND_ASSIGN(BraveSyncServiceImpl); -}; - -} // namespace brave_sync - -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_SERVICE_IMPL_H_ diff --git a/components/brave_sync/client/bookmark_change_processor.cc b/components/brave_sync/client/bookmark_change_processor.cc deleted file mode 100644 index b3c16e123ad9..000000000000 --- a/components/brave_sync/client/bookmark_change_processor.cc +++ /dev/null @@ -1,1050 +0,0 @@ -/* Copyright 2016 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/client/bookmark_change_processor.h" - -#include -#include -#include -#include -#include - -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "brave/components/brave_sync/bookmark_order_util.h" -#include "brave/components/brave_sync/client/bookmark_node.h" -#include "brave/components/brave_sync/jslib_const.h" -#include "brave/components/brave_sync/jslib_messages.h" -#include "brave/components/brave_sync/tools.h" -#include "chrome/browser/bookmarks/bookmark_model_factory.h" -#include "chrome/browser/profiles/profile.h" -#include "components/bookmarks/browser/bookmark_model.h" -#include "components/bookmarks/browser/bookmark_storage.h" -#include "components/bookmarks/browser/bookmark_utils.h" -#include "components/bookmarks/common/bookmark_pref_names.h" -#include "components/prefs/pref_service.h" -#include "ui/base/models/tree_node_iterator.h" - -using bookmarks::BookmarkNode; -using bookmarks::BookmarkModel; - -namespace { - -class ScopedPauseObserver { - public: - explicit ScopedPauseObserver(brave_sync::BookmarkChangeProcessor* processor) : - processor_(processor) { - DCHECK_NE(processor_, nullptr); - processor_->Stop(); - } - ~ScopedPauseObserver() { - processor_->Start(); - } - - private: - brave_sync::BookmarkChangeProcessor* processor_; // Not owned -}; - -const char kDeletedBookmarksTitle[] = "Deleted Bookmarks"; -const char kPendingBookmarksTitle[] = "Pending Bookmarks"; - -std::unique_ptr - MakePermanentNode(const std::string& title, int64_t* next_node_id) { - using brave_sync::BraveBookmarkPermanentNode; - auto node = std::make_unique(*next_node_id); - (*next_node_id)++; - node->set_type(bookmarks::BookmarkNode::FOLDER); - node->set_visible(false); - node->SetTitle(base::UTF8ToUTF16(title)); - - return node; -} - -} // namespace - -namespace brave_sync { - -bool IsSyncManagedNodeDeleted(const bookmarks::BookmarkPermanentNode* node) { - return node->GetTitledUrlNodeTitle() == - base::UTF8ToUTF16(kDeletedBookmarksTitle); -} - -bool IsSyncManagedNodePending(const bookmarks::BookmarkPermanentNode* node) { - return node->GetTitledUrlNodeTitle() == - base::UTF8ToUTF16(kPendingBookmarksTitle); -} - -bool IsSyncManagedNode(const bookmarks::BookmarkPermanentNode* node) { - return IsSyncManagedNodeDeleted(node) || IsSyncManagedNodePending(node); -} - -bookmarks::BookmarkPermanentNodeList -LoadExtraNodes(bookmarks::LoadExtraCallback callback, - int64_t* next_node_id) { - // TODO(bridiver) - deleted node should not be visible - bookmarks::BookmarkPermanentNodeList extra_nodes; - if (callback) - extra_nodes = std::move(callback).Run(next_node_id); - - auto deleted_node = MakePermanentNode(kDeletedBookmarksTitle, next_node_id); - extra_nodes.push_back(std::move(deleted_node)); - - auto pending_node = MakePermanentNode(kPendingBookmarksTitle, next_node_id); - extra_nodes.push_back(std::move(pending_node)); - - return extra_nodes; -} - -namespace { - -void GetOrder(const bookmarks::BookmarkNode* parent, - int index, - std::string* prev_order, - std::string* next_order, - std::string* parent_order) { - DCHECK_GE(index, 0); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - auto* next_node = index == parent->child_count() - 1 ? - nullptr : - parent->GetChild(index + 1); - - if (prev_node) - prev_node->GetMetaInfo("order", prev_order); - - if (next_node) - next_node->GetMetaInfo("order", next_order); - - parent->GetMetaInfo("order", parent_order); -} - -void GetPrevObjectId(const bookmarks::BookmarkNode* parent, - int index, - std::string* prev_object_id) { - DCHECK_GE(index, 0); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - - if (prev_node) - prev_node->GetMetaInfo("object_id", prev_object_id); -} - -const bookmarks::BookmarkNode* FindByObjectId(bookmarks::BookmarkModel* model, - const std::string& object_id) { - ui::TreeNodeIterator - iterator(model->root_node()); - while (iterator.has_next()) { - const bookmarks::BookmarkNode* node = iterator.Next(); - std::string node_object_id; - node->GetMetaInfo("object_id", &node_object_id); - - if (!node_object_id.empty() && object_id == node_object_id) - return node; - } - return nullptr; -} - -uint64_t GetIndexByOrder(const bookmarks::BookmarkNode* root_node, - const std::string& record_order) { - int index = 0; - while (index < root_node->child_count()) { - const bookmarks::BookmarkNode* node = root_node->GetChild(index); - std::string node_order; - node->GetMetaInfo("order", &node_order); - - if (!node_order.empty() && - brave_sync::CompareOrder(record_order, node_order)) - return index; - - ++index; - } - return index; -} - -uint64_t GetIndex(const bookmarks::BookmarkNode* root_node, - const jslib::Bookmark& record) { - return GetIndexByOrder(root_node, record.order); -} - -// this should only be called for resolved records we get from the server -void UpdateNode(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* node, - const jslib::SyncRecord* record, - const bookmarks::BookmarkNode* pending_node_root = nullptr) { - auto bookmark = record->GetBookmark(); - if (bookmark.isFolder) { - // SetDateFolderModified - } else { - model->SetURL(node, GURL(bookmark.site.location)); - // TODO(alexeyb): apply these: - // sync_bookmark.site.customTitle - // sync_bookmark.site.lastAccessedTime - // sync_bookmark.site.favicon - } - - const auto& title = !bookmark.site.title.empty() ? - bookmark.site.title : bookmark.site.customTitle; - model->SetTitle(node, - base::UTF8ToUTF16(title)); - model->SetDateAdded(node, bookmark.site.creationTime); - model->SetNodeMetaInfo(node, "object_id", record->objectId); - model->SetNodeMetaInfo(node, "order", bookmark.order); - - if (pending_node_root && node->parent() == pending_node_root) { - model->SetNodeMetaInfo(node, "parent_object_id", - bookmark.parentFolderObjectId); - } -} - -const bookmarks::BookmarkNode* FindParent(bookmarks::BookmarkModel* model, - const jslib::Bookmark& bookmark, - bookmarks::BookmarkNode* - pending_node_root) { - auto* parent_node = FindByObjectId(model, bookmark.parentFolderObjectId); - - if (!parent_node) { - if (!bookmark.parentFolderObjectId.empty()) { - return pending_node_root; - } - if ( - // this flag is a bit odd, but if the node doesn't have a parent and - // hideInToolbar is false, then this bookmark should go in the - // toolbar root. We don't care about this flag for records with - // a parent id because they will be inserted into the correct - // parent folder - !bookmark.hideInToolbar || - // mobile generated bookmarks go also in bookmark bar - (!bookmark.order.empty() && bookmark.order.at(0) == '2')) { - parent_node = model->bookmark_bar_node(); - } else { - parent_node = model->other_node(); - } - } - - return parent_node; -} - -} // namespace - -// static -BookmarkChangeProcessor* BookmarkChangeProcessor::Create( - Profile* profile, - BraveSyncClient* sync_client, - prefs::Prefs* sync_prefs) { - return new BookmarkChangeProcessor(profile, sync_client, sync_prefs); -} - -BookmarkChangeProcessor::BookmarkChangeProcessor( - Profile* profile, - BraveSyncClient* sync_client, - prefs::Prefs* sync_prefs) - : sync_client_(sync_client), - sync_prefs_(sync_prefs), - profile_(profile), - bookmark_model_(BookmarkModelFactory::GetForBrowserContext( - Profile::FromBrowserContext(profile))), - deleted_node_root_(nullptr), - pending_node_root_(nullptr) { - DCHECK(sync_client_); - DCHECK(sync_prefs); - DCHECK(bookmark_model_); -} - -BookmarkChangeProcessor::~BookmarkChangeProcessor() { - Stop(); -} - -void BookmarkChangeProcessor::Start() { - bookmark_model_->AddObserver(this); -} - -void BookmarkChangeProcessor::Stop() { - if (bookmark_model_) - bookmark_model_->RemoveObserver(this); -} - -void BookmarkChangeProcessor::BookmarkModelLoaded(BookmarkModel* model, - bool ids_reassigned) { - // This may be invoked after bookmarks import - VLOG(1) << __func__; -} - -void BookmarkChangeProcessor::BookmarkModelBeingDeleted( - bookmarks::BookmarkModel* model) { - NOTREACHED(); - bookmark_model_ = nullptr; -} - -void BookmarkChangeProcessor::BookmarkNodeAdded(BookmarkModel* model, - const BookmarkNode* parent, - int index) { -} - -void BookmarkChangeProcessor::OnWillRemoveBookmarks(BookmarkModel* model, - const BookmarkNode* parent, - int old_index, - const BookmarkNode* node) { -} - - -void BookmarkChangeProcessor::CloneBookmarkNodeForDeleteImpl( - const bookmarks::BookmarkNodeData::Element& element, - bookmarks::BookmarkNode* parent, - int index) { - auto cloned_node = - std::make_unique(element.id(), element.url); - if (!element.is_url) { - cloned_node->set_type(bookmarks::BookmarkNode::FOLDER); - for (int i = 0; i < static_cast(element.children.size()); ++i) - CloneBookmarkNodeForDeleteImpl(element.children[i], cloned_node.get(), i); - } else { - // default type is URL and we will hit - // [url_index.cc(122)] "Check failed: i != nodes_ordered_by_url_set_.end()." - // However, clone nodes should be dummy nodes which only need - // object_id meta info. - cloned_node->set_type(bookmarks::BookmarkNode::OTHER_NODE); - } - cloned_node->SetTitle(element.title); - - // clear sync timestsamp so this sends in unsynced records - bookmarks::BookmarkNode::MetaInfoMap meta_info_map = element.meta_info_map; - meta_info_map.erase("sync_timestamp"); - cloned_node->SetMetaInfoMap(meta_info_map); - - auto* cloned_node_ptr = cloned_node.get(); - parent->Add(std::move(cloned_node), index); - // we call `Changed` here because we don't want to update the order - BookmarkNodeChanged(bookmark_model_, cloned_node_ptr); -} - -void BookmarkChangeProcessor::CloneBookmarkNodeForDelete( - const std::vector& elements, - bookmarks::BookmarkNode* parent, - int index) { - for (size_t i = 0; i < elements.size(); ++i) { - CloneBookmarkNodeForDeleteImpl( - elements[i], parent, index + static_cast(i)); - } -} - -void BookmarkChangeProcessor::BookmarkNodeRemoved( - BookmarkModel* model, - const BookmarkNode* parent, - int old_index, - const BookmarkNode* node, - const std::set& no_longer_bookmarked) { - // TODO(bridiver) - should this be in OnWillRemoveBookmarks? - // copy into the deleted node tree without firing any events - - // The node which has not yet been sent, should not be cloned into removed. - std::string node_object_id; - node->GetMetaInfo("object_id", &node_object_id); - if (node_object_id.empty()) { - return; - } - - auto* deleted_node = GetDeletedNodeRoot(); - CHECK(deleted_node); - bookmarks::BookmarkNodeData data(node); - CloneBookmarkNodeForDelete( - data.elements, deleted_node, deleted_node->child_count()); -} - -void BookmarkChangeProcessor::BookmarkAllUserNodesRemoved( - BookmarkModel* model, - const std::set& removed_urls) { - // this only happens on profile deletion and we don't want - // to wipe out the remote store when that happens -} - -void BookmarkChangeProcessor::BookmarkNodeChanged(BookmarkModel* model, - const BookmarkNode* node) { - // clearing the sync_timestamp will put the record back in the `Unsynced` list - model->DeleteNodeMetaInfo(node, "sync_timestamp"); - // also clear the last send time because this is a new change - model->DeleteNodeMetaInfo(node, "last_send_time"); - // restart resend exponential delays - model->DeleteNodeMetaInfo(node, "send_retry_number"); - - model->SetNodeMetaInfo(node, - "last_updated_time", - std::to_string(base::Time::Now().ToJsTime())); -} - -void BookmarkChangeProcessor::BookmarkMetaInfoChanged( - BookmarkModel* model, const BookmarkNode* node) { - // Ignore metadata changes. - // These are: - // Brave managed: "object_id", "order", "sync_timestamp", - // "last_send_time", "last_updated_time" - // Chromium managed: kBookmarkLastVisitDateOnMobileKey, - // kBookmarkLastVisitDateOnDesktopKey, kBookmarkDismissedFromNTP, - // submitted by private JS API - // Not interested in any of these. -} - -void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, - const BookmarkNode* old_parent, int old_index, - const BookmarkNode* new_parent, int new_index) { - auto* node = new_parent->GetChild(new_index); - model->DeleteNodeMetaInfo(node, "order"); - BookmarkNodeChanged(model, node); - // TODO(darkdh): handle old_parent == new_parent to avoid duplicate order - // clearing. Also https://github.com/brave/sync/issues/231 blocks update to - // another devices - for (int i = old_index; i < old_parent->child_count(); ++i) { - auto* shifted_node = old_parent->GetChild(i); - model->DeleteNodeMetaInfo(shifted_node, "order"); - BookmarkNodeChanged(model, shifted_node); - } - for (int i = new_index; i < new_parent->child_count(); ++i) { - auto* shifted_node = new_parent->GetChild(i); - model->DeleteNodeMetaInfo(shifted_node, "order"); - BookmarkNodeChanged(model, shifted_node); - } -} - -void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( - BookmarkModel* model, - const BookmarkNode* node) { - // TODO(darkdh): This will be triggered right after apply sync CREATE records - // So the node applied from sync record will be put into unsync list - // BookmarkNodeChanged(model, node); -} - -void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( - BookmarkModel* model, const BookmarkNode* node) { - // this should be safe to ignore as it's only called for managed bookmarks -} - -void BookmarkChangeProcessor::Reset(bool clear_meta_info) { - ui::TreeNodeIterator - iterator(bookmark_model_->root_node()); - bookmark_model_->BeginExtensiveChanges(); - - if (clear_meta_info) { - while (iterator.has_next()) { - const bookmarks::BookmarkNode* node = iterator.Next(); - bookmark_model_->DeleteNodeMetaInfo(node, "object_id"); - bookmark_model_->DeleteNodeMetaInfo(node, "order"); - bookmark_model_->DeleteNodeMetaInfo(node, "sync_timestamp"); - bookmark_model_->DeleteNodeMetaInfo(node, "last_send_time"); - bookmark_model_->DeleteNodeMetaInfo(node, "last_updated_time"); - bookmark_model_->DeleteNodeMetaInfo(node, "send_retry_number"); - } - } - - auto* deleted_node = GetDeletedNodeRoot(); - CHECK(deleted_node); - deleted_node->DeleteAll(); - auto* pending_node = GetPendingNodeRoot(); - CHECK(pending_node); - pending_node->DeleteAll(); - bookmark_model_->EndExtensiveChanges(); -} - -void BookmarkChangeProcessor::DeleteSelfAndChildren( - const bookmarks::BookmarkNode* node) { - DCHECK(node->is_folder()); - for (int i = 0; i < node->child_count(); ++i) { - if (node->GetChild(i)->is_folder()) { - DeleteSelfAndChildren(node->GetChild(i)); - } else { - bookmark_model_->Remove(node->GetChild(i)); - } - } - bookmark_model_->Remove(node); -} - -void ValidateFolderOrders(const bookmarks::BookmarkNode* folder_node) { - DCHECK(folder_node); - - // Validate direct children order - std::string left_order; - std::string right_order; - for (auto i = 0; i < folder_node->child_count(); ++i) { - const auto* node = folder_node->GetChild(i); - std::string order; - node->GetMetaInfo("order", &order); - if (order.empty()) { - continue; - } - - if (left_order.empty()) { - left_order = order; - continue; - } - - if (right_order.empty()) { - right_order = order; - } else { - left_order = right_order; - right_order = order; - } - - DCHECK(!left_order.empty()); - DCHECK(!right_order.empty()); - - bool compare_result = CompareOrder(left_order, right_order); - if (!compare_result) { - DLOG(ERROR) << "ValidateFolderOrders failed"; - DLOG(ERROR) << "folder_node=" << folder_node->GetTitle(); - DLOG(ERROR) << "folder_node->child_count()=" << - folder_node->child_count(); - DLOG(ERROR) << "i=" << i; - DLOG(ERROR) << "left_order=" << left_order; - DLOG(ERROR) << "right_order=" << right_order; - DLOG(ERROR) << "Unexpected situation of invalid order"; - return; - } - } -} - -void BookmarkChangeProcessor::ApplyChangesFromSyncModel( - const RecordsList &records) { - ScopedPauseObserver pause(this); - bookmark_model_->BeginExtensiveChanges(); - for (const auto& sync_record : records) { - DCHECK(sync_record->has_bookmark()); - DCHECK(!sync_record->objectId.empty()); - - auto* node = FindByObjectId(bookmark_model_, sync_record->objectId); - auto bookmark_record = sync_record->GetBookmark(); - - if (node && sync_record->action == jslib::SyncRecord::Action::A_UPDATE) { - int64_t old_parent_local_id = node->parent()->id(); - const bookmarks::BookmarkNode* old_parent_node = - bookmarks::GetBookmarkNodeByID(bookmark_model_, old_parent_local_id); - - std::string old_parent_object_id; - if (old_parent_node) { - old_parent_node->GetMetaInfo("object_id", &old_parent_object_id); - } - - const bookmarks::BookmarkNode* new_parent_node = nullptr; - if (bookmark_record.parentFolderObjectId != old_parent_object_id) { - new_parent_node = FindParent(bookmark_model_, bookmark_record, - GetPendingNodeRoot()); - } - - if (new_parent_node) { - DCHECK(!bookmark_record.order.empty()); - int64_t index = GetIndex(new_parent_node, bookmark_record); - bookmark_model_->Move(node, new_parent_node, index); - } else if (!bookmark_record.order.empty()) { - std::string order; - node->GetMetaInfo("order", &order); - DCHECK(!order.empty()); - if (bookmark_record.order != order) { - int64_t index = GetIndex(node->parent(), bookmark_record); - bookmark_model_->Move(node, node->parent(), index); - } - } - UpdateNode(bookmark_model_, node, sync_record.get()); - } else if (node && - sync_record->action == jslib::SyncRecord::Action::A_DELETE) { - if (node->parent() == GetDeletedNodeRoot()) { - // this is a deleted node so remove without firing events - int index = GetDeletedNodeRoot()->GetIndexOf(node); - GetDeletedNodeRoot()->Remove(index); - } else { - // normal remove - if (node->is_folder()) { - DeleteSelfAndChildren(node); - } else { - bookmark_model_->Remove(node); - } - } - } else if (sync_record->action == jslib::SyncRecord::Action::A_CREATE) { - bool folder_was_created = false; - const bookmarks::BookmarkNode* parent_node = nullptr; - if (!node) { - // TODO(bridiver) make sure there isn't an existing record for objectId - parent_node = - FindParent(bookmark_model_, bookmark_record, GetPendingNodeRoot()); - - const BookmarkNode* bookmark_bar = bookmark_model_->bookmark_bar_node(); - bool bookmark_bar_was_empty = bookmark_bar->children().empty(); - - if (bookmark_record.isFolder) { - node = bookmark_model_->AddFolder( - parent_node, - GetIndex(parent_node, bookmark_record), - base::UTF8ToUTF16(bookmark_record.site.title)); - folder_was_created = true; - } else { - node = bookmark_model_->AddURL(parent_node, - GetIndex(parent_node, bookmark_record), - base::UTF8ToUTF16(bookmark_record.site.title), - GURL(bookmark_record.site.location)); - } - if (bookmark_bar_was_empty) - profile_->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, - true); - } - UpdateNode(bookmark_model_, node, sync_record.get(), - GetPendingNodeRoot()); - -#ifndef NDEBUG - if (parent_node) { - ValidateFolderOrders(parent_node); - } -#endif - - if (folder_was_created) { - CompletePendingNodesMove(node, sync_record->objectId); - } - } - } - bookmark_model_->EndExtensiveChanges(); -} - -void BookmarkChangeProcessor::CompletePendingNodesMove( - const bookmarks::BookmarkNode* created_folder_node, - const std::string& created_folder_object_id) { - DCHECK(GetPendingNodeRoot()); - - // node, node_order - using MoveInfo = std::tuple; - std::vector move_infos; - - bookmarks::BookmarkNode* pending_node_root = GetPendingNodeRoot(); - for (int i = 0; i < pending_node_root->child_count(); ++i) { - bookmarks::BookmarkNode* node = pending_node_root->GetChild(i); - - std::string parent_object_id; - node->GetMetaInfo("parent_object_id", &parent_object_id); - if (parent_object_id.empty()) { - // The node has been attached to folder which is still in Pending nodes - continue; - } - - if (created_folder_object_id != parent_object_id) { - // Node is still pending, because waits for another parent - continue; - } - - std::string order; - node->GetMetaInfo("order", &order); - - DCHECK(!order.empty()); - move_infos.push_back(std::make_tuple(node, order)); - } - - for (auto& move_info : move_infos) { - auto* node = std::get<0>(move_info); - const auto& order = std::get<1>(move_info); - int64_t index = GetIndexByOrder(created_folder_node, order); - - bookmark_model_->Move(node, created_folder_node, index); - // Now we dont need "parent_object_id" metainfo on node, because node - // is attached to proper parent. Note that parent can still be a child - // of "Pending Bookmarks" note. - node->DeleteMetaInfo("parent_object_id"); -#ifndef NDEBUG - ValidateFolderOrders(created_folder_node); -#endif - } -} - -int BookmarkChangeProcessor::GetPermanentNodeIndex( - const bookmarks::BookmarkNode* node) const { - DCHECK(node->is_permanent_node()); - if (node == bookmark_model_->bookmark_bar_node()) { - return 1; - } else if (node == bookmark_model_->other_node()) { - return 2; - } else if (node == bookmark_model_->mobile_node()) { - LOG(WARNING) << "[BraveSync] " << __func__ << " unexpected mobile_node"; - return 3; - } else if (node == - const_cast(this)->GetDeletedNodeRoot()) { - // Brave defined pseudo node for storing deleted bookmark until get - // acknowledge about record present in sync cloud - return 4; - } else { - NOTREACHED(); - return -1; - } -} - -std::unique_ptr -BookmarkChangeProcessor::BookmarkNodeToSyncBookmark( - const bookmarks::BookmarkNode* node) { - if (node->is_permanent_node() || !node->parent()) - return std::unique_ptr(); - - auto record = std::make_unique(); - record->deviceId = sync_prefs_->GetThisDeviceId(); - record->objectData = jslib_const::SyncObjectData_BOOKMARK; - - auto bookmark = std::make_unique(); - bookmark->site.location = node->url().spec(); - bookmark->site.title = base::UTF16ToUTF8(node->GetTitledUrlNodeTitle()); - bookmark->site.customTitle = base::UTF16ToUTF8(node->GetTitle()); - // bookmark->site.lastAccessedTime - ignored - bookmark->site.creationTime = node->date_added(); - bookmark->site.favicon = node->icon_url() ? node->icon_url()->spec() : ""; - // Url may have type OTHER_NODE if it is in Deleted Bookmarks - bookmark->isFolder = (node->type() != bookmarks::BookmarkNode::URL && - node->type() != bookmarks::BookmarkNode::OTHER_NODE); - bookmark->hideInToolbar = - !node->HasAncestor(bookmark_model_->bookmark_bar_node()); - - std::string object_id; - node->GetMetaInfo("object_id", &object_id); - record->objectId = object_id; - - std::string parent_object_id; - node->parent()->GetMetaInfo("object_id", &parent_object_id); - bookmark->parentFolderObjectId = parent_object_id; - - std::string order; - node->GetMetaInfo("order", &order); - bookmark->order = order; - - int index = node->parent()->GetIndexOf(node); - std::string prev_object_id; - GetPrevObjectId(node->parent(), index, &prev_object_id); - bookmark->prevObjectId = prev_object_id; - - std::string prev_order, next_order, parent_order; - GetOrder(node->parent(), index, &prev_order, &next_order, &parent_order); - if (parent_order.empty() && node->parent()->is_permanent_node()) { - int permanent_parent_index = GetPermanentNodeIndex(node->parent()); - parent_order = - sync_prefs_->GetBookmarksBaseOrder() + - std::to_string(permanent_parent_index); - } - bookmark->prevOrder = prev_order; - bookmark->nextOrder = next_order; - bookmark->parentOrder = parent_order; - - auto* deleted_node = GetDeletedNodeRoot(); - CHECK(deleted_node); - std::string sync_timestamp; - node->GetMetaInfo("sync_timestamp", &sync_timestamp); - - if (!sync_timestamp.empty()) { - record->syncTimestamp = base::Time::FromJsTime(std::stod(sync_timestamp)); - } else { - record->syncTimestamp = base::Time::Now(); - } - - // Situation below means the node was created and then deleted before send - // Should be ignored - if (record->objectId.empty() && node->HasAncestor(deleted_node)) { - return nullptr; - } - - if (record->objectId.empty()) { - record->objectId = tools::GenerateObjectId(); - record->action = jslib::SyncRecord::Action::A_CREATE; - bookmark_model_->SetNodeMetaInfo(node, "object_id", record->objectId); - } else if (node->HasAncestor(deleted_node)) { - record->action = jslib::SyncRecord::Action::A_DELETE; - } else { - record->action = jslib::SyncRecord::Action::A_UPDATE; - DCHECK(!record->objectId.empty()); - } - - record->SetBookmark(std::move(bookmark)); - - return record; -} - -bool IsUnsynced(const bookmarks::BookmarkNode* node) { - std::string sync_timestamp; - node->GetMetaInfo("sync_timestamp", &sync_timestamp); - - if (sync_timestamp.empty()) - return true; - - std::string last_updated_time; - node->GetMetaInfo("last_updated_time", &last_updated_time); - - return !last_updated_time.empty() && - base::Time::FromJsTime(std::stod(last_updated_time)) > - base::Time::FromJsTime(std::stod(sync_timestamp)); -} - -void BookmarkChangeProcessor::GetAllSyncData( - const std::vector>& records, - SyncRecordAndExistingList* records_and_existing_objects) { - for (const auto& record : records) { - auto resolved_record = std::make_unique(); - resolved_record->first = jslib::SyncRecord::Clone(*record); - auto* node = FindByObjectId(bookmark_model_, record->objectId); - if (node) { - resolved_record->second = BookmarkNodeToSyncBookmark(node); - // Update "sync_timestamp" - bookmark_model_->SetNodeMetaInfo(node, - "sync_timestamp", - std::to_string(record->syncTimestamp.ToJsTime())); - - // got confirmation record had been reached server, no need to retry - bookmark_model_->DeleteNodeMetaInfo(node, "send_retry_number"); - } - - records_and_existing_objects->push_back(std::move(resolved_record)); - } -} - -bookmarks::BookmarkNode* BookmarkChangeProcessor::GetDeletedNodeRoot() { - if (!deleted_node_root_) { - ui::TreeNodeIterator - iterator(bookmark_model_->root_node()); - while (iterator.has_next()) { - const bookmarks::BookmarkNode* node = iterator.Next(); - if (node->is_permanent_node() && - IsSyncManagedNodeDeleted( - static_cast(node))) { - deleted_node_root_ = const_cast(node); - return deleted_node_root_; - } - } - } - DCHECK(deleted_node_root_); - return deleted_node_root_; -} - -bookmarks::BookmarkNode* BookmarkChangeProcessor::GetPendingNodeRoot() { - if (!pending_node_root_) { - ui::TreeNodeIterator - iterator(bookmark_model_->root_node()); - while (iterator.has_next()) { - const bookmarks::BookmarkNode* node = iterator.Next(); - if (node->is_permanent_node() && - IsSyncManagedNodePending( - static_cast(node))) { - pending_node_root_ = const_cast(node); - return pending_node_root_; - } - } - } - DCHECK(pending_node_root_); - return pending_node_root_; -} - -int BookmarkChangeProcessor::FindMigrateSubOrderLength( - const std::string& order) { - // Old order subject to be migrated is ... - // Return value is the substring length before the 3rd point - - if (order.length() < 6) { - DCHECK(false) << "The minimal length of order required is 6, like '1.0.1.'"; - return -1; - } - - // 1st segment is guaranteed to be "1" or "2" - size_t pos2 = order.find('.', 2); - if (std::string::npos == pos2) { - DCHECK(false) << "Should find 2nd '.' in order"; - return -1; - } - - size_t pos3 = order.find('.', pos2 + 1); - if (std::string::npos == pos3) { - DCHECK(false) << "Should find 3rd '.' in order"; - return -1; - } - - std::string third_segment(order.begin() + pos2 + 1, order.begin() + pos3); - if (third_segment != "0") { - // No need to migrate - return -1; - } - - if (pos3 == order.length() - 1) { - DLOG(WARNING) << "Should have at least one digit after 3rd '.'"; - return -1; - } - - return pos3; -} - -void BookmarkChangeProcessor::MigrateOrdersForPermanentNode( - bookmarks::BookmarkNode* permanent_node) { - - // Before After - // bookmarks_bar child "order":"1.0.0.1" "order":"1.0.1.1" - // other_bookmarks child "order":"1.0.0.1" "order":"1.0.2.1" - - // The old order part to be migrated is ... - // The substring before the 3rd point - // Third segment should be "0" only for migration - - int permanent_node_index = GetPermanentNodeIndex(permanent_node); - std::string perm_new_order = sync_prefs_->GetBookmarksBaseOrder() + - std::to_string(permanent_node_index); - - ui::TreeNodeIterator - iterator(permanent_node); - while (iterator.has_next()) { - bookmarks::BookmarkNode* node = iterator.Next(); - - std::string old_node_order; - if (node->GetMetaInfo("order", &old_node_order) - && !old_node_order.empty()) { - int old_suborder_length = FindMigrateSubOrderLength(old_node_order); - if (old_suborder_length == -1) { - continue; - } - - std::string new_node_order = perm_new_order + - old_node_order.substr(old_suborder_length); - - node->SetMetaInfo("order", new_node_order); - BookmarkNodeChanged(bookmark_model_, node); - } - } -} - -void BookmarkChangeProcessor::MigrateOrders() { - if (sync_prefs_->GetMigratedBookmarksVersion() >= 1) { - return; - } - for (const auto* node : { bookmark_model_->bookmark_bar_node(), - bookmark_model_->other_node() }) { - MigrateOrdersForPermanentNode(const_cast(node)); - } - - sync_prefs_->SetMigratedBookmarksVersion(1); -} - -const std::vector - BookmarkChangeProcessor::kExponentialWaits = {10, 20, 40, 80}; -const int BookmarkChangeProcessor::kMaxSendRetries = - BookmarkChangeProcessor::kExponentialWaits.size(); - -namespace { - -int GetCurrentRetryNumber(const bookmarks::BookmarkNode* node) { - std::string send_retry_number; - node->GetMetaInfo("send_retry_number", &send_retry_number); - if (send_retry_number.empty()) { - return 0; - } - int retry_number = 0; - if (!base::StringToInt(send_retry_number, &retry_number)) { - return 0; - } - return retry_number; -} - -} // namespace - -// static -std::vector BookmarkChangeProcessor::GetExponentialWaitsForTests() { - return kExponentialWaits; -} - -// static -base::TimeDelta BookmarkChangeProcessor::GetRetryExponentialWaitAmount( - int retry_number) { - DCHECK_GE(retry_number, 1); - DCHECK_LE(retry_number, kMaxSendRetries); - - // failsafe option - if (retry_number == 0) { - return base::TimeDelta::FromMinutes(0); - } - - if (retry_number > kMaxSendRetries) { - retry_number = kMaxSendRetries; - } - return base::TimeDelta::FromMinutes(kExponentialWaits[retry_number - 1]); -} - -// static -void BookmarkChangeProcessor::SetCurrentRetryNumber( - bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* node, int retry_number) { - if (retry_number > kMaxSendRetries) { - retry_number = kMaxSendRetries; - } - DCHECK_GE(retry_number, 1); - DCHECK_LE(retry_number, kMaxSendRetries); - model->SetNodeMetaInfo(node, "send_retry_number", - std::to_string(retry_number)); -} - -void BookmarkChangeProcessor::SendUnsynced() { - MigrateOrders(); - - std::vector> records; - bool sent_at_least_once = false; - - auto* deleted_node = GetDeletedNodeRoot(); - CHECK(deleted_node); - std::vector root_nodes = { - bookmark_model_->other_node(), - bookmark_model_->bookmark_bar_node(), - deleted_node - }; - - for (const auto* root_node : root_nodes) { - ui::TreeNodeIterator - iterator(root_node); - while (iterator.has_next()) { - const bookmarks::BookmarkNode* node = iterator.Next(); - - // only send unsynced records - if (!IsUnsynced(node)) - continue; - - std::string last_send_time; - node->GetMetaInfo("last_send_time", &last_send_time); - size_t current_retry_number = GetCurrentRetryNumber(node); - if (!last_send_time.empty() && - // don't send more often than |kExponentialWaits| requires - (base::Time::Now() - - base::Time::FromJsTime(std::stod(last_send_time))) < - GetRetryExponentialWaitAmount(current_retry_number)) { - continue; - } - - bookmark_model_->SetNodeMetaInfo(node, - "last_send_time", std::to_string(base::Time::Now().ToJsTime())); - SetCurrentRetryNumber(bookmark_model_, node, current_retry_number + 1); - - auto record = BookmarkNodeToSyncBookmark(node); - if (record) - records.push_back(std::move(record)); - - if (records.size() == 1000) { - sync_client_->SendSyncRecords( - jslib_const::SyncRecordType_BOOKMARKS, records); - sent_at_least_once = true; - records.clear(); - } - } - } - if (!records.empty()) { - sync_client_->SendSyncRecords( - jslib_const::SyncRecordType_BOOKMARKS, records); - sent_at_least_once = true; - records.clear(); - } - - if (sent_at_least_once) { - sync_client_->ClearOrderMap(); - } -} - -void BookmarkChangeProcessor::InitialSync() {} - -void BookmarkChangeProcessor::ApplyOrder(const std::string& object_id, - const std::string& order) { - ScopedPauseObserver pause(this); - auto* node = FindByObjectId(bookmark_model_, object_id); - if (node) { - bookmark_model_->SetNodeMetaInfo(node, "order", order); - } -} - -} // namespace brave_sync diff --git a/components/brave_sync/client/bookmark_change_processor.h b/components/brave_sync/client/bookmark_change_processor.h deleted file mode 100644 index dbeb00badacf..000000000000 --- a/components/brave_sync/client/bookmark_change_processor.h +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright 2018 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_CLIENT_BOOKMARK_CHANGE_PROCESSOR_H_ -#define BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BOOKMARK_CHANGE_PROCESSOR_H_ - -#include -#include -#include -#include - -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "base/time/time.h" -#include "brave/components/brave_sync/brave_sync_prefs.h" -#include "brave/components/brave_sync/client/brave_sync_client.h" -#include "brave/components/brave_sync/model/change_processor.h" -#include "components/bookmarks/browser/bookmark_model_observer.h" -#include "components/bookmarks/browser/bookmark_node.h" -#include "components/bookmarks/browser/bookmark_node_data.h" - -FORWARD_DECLARE_TEST(BraveBookmarkChangeProcessorTest, IgnoreRapidCreateDelete); -FORWARD_DECLARE_TEST(BraveBookmarkChangeProcessorTest, - MigrateOrdersForPermanentNodes); -FORWARD_DECLARE_TEST(BraveBookmarkChangeProcessorTest, ExponentialResend); - -class BraveBookmarkChangeProcessorTest; - -namespace brave_sync { - -class BookmarkChangeProcessor : public ChangeProcessor, - bookmarks::BookmarkModelObserver { - public: - static BookmarkChangeProcessor* Create( - Profile* profile, - BraveSyncClient* sync_client, - prefs::Prefs* sync_prefs); - ~BookmarkChangeProcessor() override; - - // ChangeProcessor implementation - void Start() override; - void Stop() override; - void Reset(bool clear_meta_info) override; - void ApplyChangesFromSyncModel(const RecordsList &records) override; - void GetAllSyncData( - const std::vector>& records, - SyncRecordAndExistingList* records_and_existing_objects) override; - void SendUnsynced() override; - void InitialSync() override; - - void ApplyOrder(const std::string& object_id, const std::string& order); - - private: - friend class ::BraveBookmarkChangeProcessorTest; - FRIEND_TEST_ALL_PREFIXES(::BraveBookmarkChangeProcessorTest, - IgnoreRapidCreateDelete); - FRIEND_TEST_ALL_PREFIXES(::BraveBookmarkChangeProcessorTest, - MigrateOrdersForPermanentNodes); - FRIEND_TEST_ALL_PREFIXES(::BraveBookmarkChangeProcessorTest, - ExponentialResend); - - BookmarkChangeProcessor(Profile* profile, - BraveSyncClient* sync_client, - prefs::Prefs* sync_prefs); - - // bookmarks::BookmarkModelObserver: - void BookmarkModelLoaded(bookmarks::BookmarkModel* model, - bool ids_reassigned) override; - void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; - void BookmarkNodeMoved(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* old_parent, - int old_index, - const bookmarks::BookmarkNode* new_parent, - int new_index) override; - void BookmarkNodeAdded(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* parent, - int index) override; - void OnWillRemoveBookmarks(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* parent, - int old_index, - const bookmarks::BookmarkNode* node) override; - void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* parent, - int old_index, - const bookmarks::BookmarkNode* node, - const std::set& no_longer_bookmarked) override; - void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, - const std::set& removed_urls) override; - void BookmarkNodeChanged(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* node) override; - void BookmarkMetaInfoChanged(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* node) override; - void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* node) override; - void BookmarkNodeChildrenReordered( - bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* node) override; - - std::unique_ptr BookmarkNodeToSyncBookmark( - const bookmarks::BookmarkNode* node); - bookmarks::BookmarkNode* GetDeletedNodeRoot(); - bookmarks::BookmarkNode* GetPendingNodeRoot(); - void CloneBookmarkNodeForDeleteImpl( - const bookmarks::BookmarkNodeData::Element& element, - bookmarks::BookmarkNode* parent, - int index); - void CloneBookmarkNodeForDelete( - const std::vector& elements, - bookmarks::BookmarkNode* parent, - int index); - // BookmarkModel::Remove will remove parent but put its children under - // "Other Bookmarks" so we need to explicitly delete children - void DeleteSelfAndChildren(const bookmarks::BookmarkNode* node); - - void CompletePendingNodesMove( - const bookmarks::BookmarkNode* created_folder_node, - const std::string& created_folder_object_id); - - void MigrateOrders(); - void MigrateOrdersForPermanentNode(bookmarks::BookmarkNode* perm_node); - int GetPermanentNodeIndex(const bookmarks::BookmarkNode* node) const; - static int FindMigrateSubOrderLength(const std::string& order); - - static base::TimeDelta GetRetryExponentialWaitAmount(int retry_number); - static void SetCurrentRetryNumber(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* node, int retry_number); - static std::vector GetExponentialWaitsForTests(); - - static const std::vector kExponentialWaits; - static const int kMaxSendRetries; - - BraveSyncClient* sync_client_; // not owned - prefs::Prefs* sync_prefs_; // not owned - Profile* profile_; // not owned - bookmarks::BookmarkModel* bookmark_model_; // not owned - - bookmarks::BookmarkNode* deleted_node_root_; - bookmarks::BookmarkNode* pending_node_root_; - - DISALLOW_COPY_AND_ASSIGN(BookmarkChangeProcessor); -}; - -} // namespace brave_sync - -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BOOKMARK_CHANGE_PROCESSOR_H_ diff --git a/components/brave_sync/client/bookmark_node.cc b/components/brave_sync/client/bookmark_node.cc deleted file mode 100644 index 0118d7ffb92c..000000000000 --- a/components/brave_sync/client/bookmark_node.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include "brave/components/brave_sync/client/bookmark_node.h" - -namespace brave_sync { - -BraveBookmarkPermanentNode::BraveBookmarkPermanentNode(int64_t id) - : bookmarks::BookmarkPermanentNode(id) {} - -BraveBookmarkPermanentNode::~BraveBookmarkPermanentNode() = default; - -bool BraveBookmarkPermanentNode::IsVisible() const { - return visible_; -} - -} // namespace brave_sync diff --git a/components/brave_sync/client/bookmark_node.h b/components/brave_sync/client/bookmark_node.h deleted file mode 100644 index 5cd1c8d3b134..000000000000 --- a/components/brave_sync/client/bookmark_node.h +++ /dev/null @@ -1,31 +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_COMPONENTS_BRAVE_SYNC_CLIENT_BOOKMARK_NODE_H_ -#define BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BOOKMARK_NODE_H_ - -#include "components/bookmarks/browser/bookmark_node.h" - -namespace brave_sync { - -// Sync Managed PerrmanentNode -class BraveBookmarkPermanentNode : public bookmarks::BookmarkPermanentNode { - public: - explicit BraveBookmarkPermanentNode(int64_t id); - ~BraveBookmarkPermanentNode() override; - - void set_visible(bool value) { visible_ = value; } - - // BookmarkNode overrides: - bool IsVisible() const override; - - private: - bool visible_ = false; - - DISALLOW_COPY_AND_ASSIGN(BraveBookmarkPermanentNode); -}; - -} // namespace brave_sync - -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BOOKMARK_NODE_H_ diff --git a/components/brave_sync/model/change_processor.h b/components/brave_sync/model/change_processor.h deleted file mode 100644 index 1ff4e6756dd4..000000000000 --- a/components/brave_sync/model/change_processor.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright 2018 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_MODEL_CHANGE_PROCESSOR_H_ -#define BRAVE_COMPONENTS_BRAVE_SYNC_MODEL_CHANGE_PROCESSOR_H_ - -#include -#include - -#include "base/macros.h" -#include "base/time/time.h" -#include "brave/components/brave_sync/client/client_ext_impl_data.h" - -namespace brave_sync { - -class ChangeProcessor { - public: - virtual ~ChangeProcessor() = default; - - // start processing local changes - virtual void Start() = 0; - // stop processing local changes - virtual void Stop() = 0; - - // reset all sync data, but do not delete local records - // with clear_meta_info == false, we perserve meta info for reconnecting to - // previous sync chain and only clear permanent nodes managed by sync. - // If we want to connect/create to new sync chain, we should clear meta info. - virtual void Reset(bool clear_meta_info) = 0; - - // setup permanent nodes - virtual void InitialSync() = 0; - - // get all local sync data matching `records` and return the matched pair - // in `records_and_existing_objects` - virtual void GetAllSyncData( - const std::vector>& records, - SyncRecordAndExistingList* records_and_existing_objects) = 0; - // update local data from `records` - virtual void ApplyChangesFromSyncModel(const RecordsList& records) = 0; - // send any new records that have not yet been synced to the server - // for each record, with respect to an exponential resend periods - virtual void SendUnsynced() = 0; -}; - -} // namespace brave_sync - -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_MODEL_CHANGE_PROCESSOR_H_ From be433970b4db38b077e8157209baff18806aa23f Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 22 Apr 2019 21:29:31 -0700 Subject: [PATCH 08/73] Fix Reset bug and prevent shutdown sync thread hanging --- .../browser_sync/profile_sync_service.cc | 18 ++++++++++++------ ...-browser_sync-profile_sync_service.cc.patch | 15 ++++++++++++--- ...s-browser_sync-profile_sync_service.h.patch | 5 +++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/browser_sync/profile_sync_service.cc index cd4a6f0e1ef9..256abb5576a6 100644 --- a/chromium_src/components/browser_sync/profile_sync_service.cc +++ b/chromium_src/components/browser_sync/profile_sync_service.cc @@ -355,7 +355,7 @@ std::string ProfileSyncService::GetSeed() { void ProfileSyncService::OnSetSyncEnabled(const bool sync_this_device) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - brave_sync_prefs_->SetSyncEnabled(true); + brave_sync_prefs_->SetSyncEnabled(sync_this_device); } void ProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { @@ -546,10 +546,7 @@ void ProfileSyncService::OnResolvedSyncRecords( // Send records to syncer if (get_record_cb_) engine_->DispatchGetRecordsCallback(get_record_cb_, std::move(records)); - if (wevent_) { - wevent_->Signal(); - wevent_ = nullptr; - } + SignalWaitableEvent(); } else if (category_name == kHistorySites) { NOTIMPLEMENTED(); } @@ -711,8 +708,10 @@ void ProfileSyncService::OnResolvedPreferences(const RecordsList& records) { void ProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { if (pref == brave_sync::prefs::kSyncEnabled) { GetBraveSyncClient()->OnSyncEnabledChanged(); - if (!brave_sync_prefs_->GetSyncEnabled()) + if (!brave_sync_prefs_->GetSyncEnabled()) { brave_sync_initialized_ = false; + user_settings_->SetSyncRequested(false); + } } NotifySyncStateChanged(); } @@ -825,4 +824,11 @@ void ProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, FetchSyncRecords(bookmarks, history, preferences, 1000); } +void ProfileSyncService::SignalWaitableEvent() { + if (wevent_) { + wevent_->Signal(); + wevent_ = nullptr; + } +} + } // namespace browser_sync diff --git a/patches/components-browser_sync-profile_sync_service.cc.patch b/patches/components-browser_sync-profile_sync_service.cc.patch index 7db14b5c3f39..1a54eaebf135 100644 --- a/patches/components-browser_sync-profile_sync_service.cc.patch +++ b/patches/components-browser_sync-profile_sync_service.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/browser_sync/profile_sync_service.cc b/components/browser_sync/profile_sync_service.cc -index 787e2d24941cbaa469373ed5baad14d1ac9f3722..8f5a0b7a2d4e263992822375621ed624027913fd 100644 +index 787e2d24941cbaa469373ed5baad14d1ac9f3722..30f2983ad798474de49046914dc060faaa3faf1d 100644 --- a/components/browser_sync/profile_sync_service.cc +++ b/components/browser_sync/profile_sync_service.cc @@ -184,6 +184,8 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) @@ -20,7 +20,16 @@ index 787e2d24941cbaa469373ed5baad14d1ac9f3722..8f5a0b7a2d4e263992822375621ed624 DCHECK(!params.credentials.account_id.empty() || IsLocalSyncEnabled()); if (!base::FeatureList::IsEnabled(switches::kSyncE2ELatencyMeasurement)) { invalidation::InvalidationService* invalidator = -@@ -663,6 +667,7 @@ int ProfileSyncService::GetDisableReasons() const { +@@ -550,6 +554,8 @@ void ProfileSyncService::Shutdown() { + DCHECK(!observers_.might_have_observers()); + + auth_manager_.reset(); ++ ++ SignalWaitableEvent(); + + if (sync_thread_) + sync_thread_->Stop(); +@@ -663,6 +669,7 @@ int ProfileSyncService::GetDisableReasons() const { DCHECK(switches::IsSyncAllowedByFlag()); int result = DISABLE_REASON_NONE; @@ -28,7 +37,7 @@ index 787e2d24941cbaa469373ed5baad14d1ac9f3722..8f5a0b7a2d4e263992822375621ed624 if (!user_settings_->IsSyncAllowedByPlatform()) { result = result | DISABLE_REASON_PLATFORM_OVERRIDE; } -@@ -1753,12 +1758,12 @@ void ProfileSyncService::GetAllNodes( +@@ -1753,12 +1760,12 @@ void ProfileSyncService::GetAllNodes( CoreAccountInfo ProfileSyncService::GetAuthenticatedAccountInfo() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); diff --git a/patches/components-browser_sync-profile_sync_service.h.patch b/patches/components-browser_sync-profile_sync_service.h.patch index f6c08a8fac7a..7ed40f671f1e 100644 --- a/patches/components-browser_sync-profile_sync_service.h.patch +++ b/patches/components-browser_sync-profile_sync_service.h.patch @@ -1,5 +1,5 @@ diff --git a/components/browser_sync/profile_sync_service.h b/components/browser_sync/profile_sync_service.h -index 6c01395b954ac146084865b0268992f277b4914c..f56688195f34abb11c30573d63832fe67ba8218d 100644 +index 6c01395b954ac146084865b0268992f277b4914c..c23fc377beaebcef2a894e8c4e2f9f76e77d58d6 100644 --- a/components/browser_sync/profile_sync_service.h +++ b/components/browser_sync/profile_sync_service.h @@ -137,7 +137,9 @@ class ProfileSyncService : public syncer::SyncService, @@ -56,7 +56,7 @@ index 6c01395b954ac146084865b0268992f277b4914c..f56688195f34abb11c30573d63832fe6 private: // Passed as an argument to StopImpl to control whether or not the sync // engine should clear its data directory when it shuts down. See StopImpl -@@ -465,6 +503,46 @@ class ProfileSyncService : public syncer::SyncService, +@@ -465,6 +503,47 @@ class ProfileSyncService : public syncer::SyncService, // Called by SyncServiceCrypto when a passphrase is required or accepted. void ReconfigureDueToPassphrase(syncer::ConfigureReason reason); @@ -66,6 +66,7 @@ index 6c01395b954ac146084865b0268992f277b4914c..f56688195f34abb11c30573d63832fe6 + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); + void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, + base::WaitableEvent* wevent); ++ void SignalWaitableEvent(); + void FetchSyncRecords(const bool bookmarks, const bool history, + const bool preferences, int max_records); + void SendCreateDevice(); From 78e0d85f54d4f489cfd4c76acde663d345cb2667 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 24 Apr 2019 20:22:37 -0700 Subject: [PATCH 09/73] Implement OnSaveBookmarkOrder from #2326 --- .../browser_sync/profile_sync_service.cc | 14 ++++++++++++++ ...nents-browser_sync-profile_sync_service.h.patch | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/browser_sync/profile_sync_service.cc index 256abb5576a6..99fead2dda16 100644 --- a/chromium_src/components/browser_sync/profile_sync_service.cc +++ b/chromium_src/components/browser_sync/profile_sync_service.cc @@ -567,6 +567,20 @@ void ProfileSyncService::OnSaveBookmarksBaseOrder(const std::string& order) { OnSyncReady(); } +void ProfileSyncService::OnSaveBookmarkOrder(const std::string& object_id, + const std::string& order) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + DCHECK(!order.empty()); + bookmarks::BookmarkModel* model = + // TODO(darkdh): find another way to obtain bookmark model + // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 + static_cast(sync_client_.get())->GetBookmarkModel(); + auto* node = FindByObjectId(model, object_id); + if (node) { + model->SetNodeMetaInfo(node, "order", order); + } +} + void ProfileSyncService::OnSyncWordsPrepared(const std::string& words) { NotifyHaveSyncWords(words); } diff --git a/patches/components-browser_sync-profile_sync_service.h.patch b/patches/components-browser_sync-profile_sync_service.h.patch index 7ed40f671f1e..c43b049e8211 100644 --- a/patches/components-browser_sync-profile_sync_service.h.patch +++ b/patches/components-browser_sync-profile_sync_service.h.patch @@ -1,5 +1,5 @@ diff --git a/components/browser_sync/profile_sync_service.h b/components/browser_sync/profile_sync_service.h -index 6c01395b954ac146084865b0268992f277b4914c..c23fc377beaebcef2a894e8c4e2f9f76e77d58d6 100644 +index 6c01395b954ac146084865b0268992f277b4914c..e6c7eb64cf1167f58159cdfd4c9f58f62b620451 100644 --- a/components/browser_sync/profile_sync_service.h +++ b/components/browser_sync/profile_sync_service.h @@ -137,7 +137,9 @@ class ProfileSyncService : public syncer::SyncService, @@ -13,7 +13,7 @@ index 6c01395b954ac146084865b0268992f277b4914c..c23fc377beaebcef2a894e8c4e2f9f76 public: // If AUTO_START, sync will set IsFirstSetupComplete() automatically and sync // will begin syncing without the user needing to confirm sync settings. -@@ -346,6 +348,42 @@ class ProfileSyncService : public syncer::SyncService, +@@ -346,6 +348,44 @@ class ProfileSyncService : public syncer::SyncService, syncer::SyncClient* GetSyncClientForTest(); @@ -51,12 +51,14 @@ index 6c01395b954ac146084865b0268992f277b4914c..c23fc377beaebcef2a894e8c4e2f9f76 + void OnDeletedSyncUser() override; + void OnDeleteSyncSiteSettings() override; + void OnSaveBookmarksBaseOrder(const std::string& order) override; ++ void OnSaveBookmarkOrder(const std::string& object_id, ++ const std::string& order) override; + void OnSyncWordsPrepared(const std::string& words) override; + private: // Passed as an argument to StopImpl to control whether or not the sync // engine should clear its data directory when it shuts down. See StopImpl -@@ -465,6 +503,47 @@ class ProfileSyncService : public syncer::SyncService, +@@ -465,6 +505,47 @@ class ProfileSyncService : public syncer::SyncService, // Called by SyncServiceCrypto when a passphrase is required or accepted. void ReconfigureDueToPassphrase(syncer::ConfigureReason reason); From 372552b52666f6abd5ac35513c683c526cd9f948 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 26 Apr 2019 16:57:38 -0700 Subject: [PATCH 10/73] Redefine order calculation to be simply parent_order + index_in_parent deprecate all the logic through brave/sync for getting order --- browser/extensions/api/brave_sync_api.cc | 12 -- browser/extensions/api/brave_sync_api.h | 6 - .../extensions/api/brave_sync_event_router.cc | 9 -- .../extensions/api/brave_sync_event_router.h | 2 - .../browser_sync/profile_sync_service.cc | 87 ++----------- .../components/sync/engine_impl/commit.cc | 8 -- .../bookmark_change_processor.cc | 111 +---------------- .../bookmark_local_changes_builder.cc | 115 +----------------- common/extensions/api/brave_sync.json | 25 ---- components/brave_sync/BUILD.gn | 2 + .../brave_sync/client/brave_sync_client.h | 4 - .../client/brave_sync_client_impl.cc | 5 - .../client/brave_sync_client_impl.h | 2 - .../brave_sync/client/client_ext_impl_data.cc | 14 --- components/brave_sync/extension/background.js | 84 +------------ components/brave_sync/jslib_messages.h | 4 - components/brave_sync/syncer_helper.cc | 81 ++++++++++++ components/brave_sync/syncer_helper.h | 22 ++++ ...-browser_sync-profile_sync_service.h.patch | 8 +- ...okmarks-bookmark_change_processor.cc.patch | 49 +++++--- ...ookmarks-bookmark_change_processor.h.patch | 13 ++ ...ks-bookmark_local_changes_builder.cc.patch | 4 +- 22 files changed, 174 insertions(+), 493 deletions(-) create mode 100644 components/brave_sync/syncer_helper.cc create mode 100644 components/brave_sync/syncer_helper.h create mode 100644 patches/components-sync_bookmarks-bookmark_change_processor.h.patch diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index aceb875dbda4..034264fb6092 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -142,18 +142,6 @@ BraveSyncSaveBookmarksBaseOrderFunction::Run() { return RespondNow(NoArguments()); } -ExtensionFunction::ResponseAction BraveSyncSaveBookmarkOrderFunction::Run() { - std::unique_ptr params( - brave_sync::SaveBookmarkOrder::Params::Create(*args_)); - EXTENSION_FUNCTION_VALIDATE(params.get()); - - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); - DCHECK(sync_service); - sync_service->OnSaveBookmarkOrder(params->object_id, params->order); - - return RespondNow(NoArguments()); -} - ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() { std::unique_ptr params( brave_sync::SyncWordsPrepared::Params::Create(*args_)); diff --git a/browser/extensions/api/brave_sync_api.h b/browser/extensions/api/brave_sync_api.h index 7c10e77808b8..7f7831dcc8df 100644 --- a/browser/extensions/api/brave_sync_api.h +++ b/browser/extensions/api/brave_sync_api.h @@ -60,12 +60,6 @@ class BraveSyncSaveBookmarksBaseOrderFunction ResponseAction Run() override; }; -class BraveSyncSaveBookmarkOrderFunction : public UIThreadExtensionFunction { - ~BraveSyncSaveBookmarkOrderFunction() override {} - DECLARE_EXTENSION_FUNCTION("braveSync.saveBookmarkOrder", UNKNOWN) - ResponseAction Run() override; -}; - class BraveSyncSyncWordsPreparedFunction : public UIThreadExtensionFunction { ~BraveSyncSyncWordsPreparedFunction() override {} DECLARE_EXTENSION_FUNCTION("braveSync.syncWordsPrepared", UNKNOWN) diff --git a/browser/extensions/api/brave_sync_event_router.cc b/browser/extensions/api/brave_sync_event_router.cc index f4ce1d3f3792..528c0de06592 100644 --- a/browser/extensions/api/brave_sync_event_router.cc +++ b/browser/extensions/api/brave_sync_event_router.cc @@ -142,13 +142,4 @@ void BraveSyncEventRouter::LoadClient() { event_router_->BroadcastEvent(std::move(event)); } -void BraveSyncEventRouter::ClearOrderMap() { - auto args = std::make_unique(); - std::unique_ptr event( - new Event(extensions::events::FOR_TEST, - extensions::api::brave_sync::OnClearOrderMap::kEventName, - std::move(args))); - event_router_->BroadcastEvent(std::move(event)); -} - } // namespace extensions diff --git a/browser/extensions/api/brave_sync_event_router.h b/browser/extensions/api/brave_sync_event_router.h index eac52983442b..3e106073b01c 100644 --- a/browser/extensions/api/brave_sync_event_router.h +++ b/browser/extensions/api/brave_sync_event_router.h @@ -57,8 +57,6 @@ class BraveSyncEventRouter { void NeedSyncWords(const std::string& seed); - void ClearOrderMap(); - void LoadClient(); private: diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/browser_sync/profile_sync_service.cc index 99fead2dda16..8eef44605ba2 100644 --- a/chromium_src/components/browser_sync/profile_sync_service.cc +++ b/chromium_src/components/browser_sync/profile_sync_service.cc @@ -126,40 +126,6 @@ const bookmarks::BookmarkNode* FindByObjectId(bookmarks::BookmarkModel* model, return nullptr; } -void GetPrevObjectId(const bookmarks::BookmarkNode* parent, - int index, - std::string* prev_object_id) { - DCHECK_GE(index, 0); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - - if (prev_node) - prev_node->GetMetaInfo("object_id", prev_object_id); -} - -void GetOrder(const bookmarks::BookmarkNode* parent, - int index, - std::string* prev_order, - std::string* next_order, - std::string* parent_order) { - DCHECK_GE(index, 0); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - auto* next_node = index == parent->child_count() - 1 ? - nullptr : - parent->GetChild(index + 1); - - if (prev_node) - prev_node->GetMetaInfo("order", prev_order); - - if (next_node) - next_node->GetMetaInfo("order", next_order); - - parent->GetMetaInfo("order", parent_order); -} - std::unique_ptr BookmarkNodeToSyncBookmark( bookmarks::BookmarkModel* model, brave_sync::prefs::Prefs* brave_sync_prefs, @@ -195,27 +161,9 @@ std::unique_ptr BookmarkNodeToSyncBookmark( std::string order; node->GetMetaInfo("order", &order); + DCHECK(!order.empty()); bookmark->order = order; - int index = node->parent()->GetIndexOf(node); - std::string prev_object_id; - GetPrevObjectId(node->parent(), index, &prev_object_id); - bookmark->prevObjectId = prev_object_id; - - std::string prev_order, next_order, parent_order; - GetOrder(node->parent(), index, &prev_order, &next_order, &parent_order); - if (parent_order.empty() && node->parent()->is_permanent_node()) { - if (node->parent() == model->bookmark_bar_node()) - parent_order = - brave_sync_prefs->GetBookmarksBaseOrder() + '1'; - else - parent_order = - brave_sync_prefs->GetBookmarksBaseOrder() + '2'; - } - bookmark->prevOrder = prev_order; - bookmark->nextOrder = next_order; - bookmark->parentOrder = parent_order; - std::string sync_timestamp; node->GetMetaInfo("sync_timestamp", &sync_timestamp); DCHECK(!sync_timestamp.empty()); @@ -564,21 +512,17 @@ void ProfileSyncService::OnSaveBookmarksBaseOrder(const std::string& order) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(!order.empty()); brave_sync_prefs_->SetBookmarksBaseOrder(order); - OnSyncReady(); -} - -void ProfileSyncService::OnSaveBookmarkOrder(const std::string& object_id, - const std::string& order) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - DCHECK(!order.empty()); bookmarks::BookmarkModel* model = // TODO(darkdh): find another way to obtain bookmark model // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 static_cast(sync_client_.get())->GetBookmarkModel(); - auto* node = FindByObjectId(model, object_id); - if (node) { - model->SetNodeMetaInfo(node, "order", order); - } + bookmarks::BookmarkNode* mutable_bookmark_bar_node = + const_cast(model->bookmark_bar_node()); + model->SetNodeMetaInfo(mutable_bookmark_bar_node, "order", order + "1"); + bookmarks::BookmarkNode* mutable_other_node = + const_cast(model->other_node()); + model->SetNodeMetaInfo(mutable_other_node, "order", order + "2"); + OnSyncReady(); } void ProfileSyncService::OnSyncWordsPrepared(const std::string& words) { @@ -797,25 +741,10 @@ void ProfileSyncService::OnNudgeSyncCycle( brave_sync::RecordsListPtr records) { for (auto& record : *records) { record->deviceId = brave_sync_prefs_->GetThisDeviceId(); - if (record->has_bookmark()) { - auto* bookmark = record->mutable_bookmark(); - if (bookmark->parentOrder.empty() && - bookmark->parentFolderObjectId.empty()) { - // bookmark toolbar - if (!bookmark->hideInToolbar) - bookmark->parentOrder = - brave_sync_prefs_->GetBookmarksBaseOrder() + '1'; - // other bookmarks - else - bookmark->parentOrder = - brave_sync_prefs_->GetBookmarksBaseOrder() + '2'; - } - } } if (!records->empty()) GetBraveSyncClient()->SendSyncRecords( brave_sync::jslib_const::SyncRecordType_BOOKMARKS, *records); - GetBraveSyncClient()->ClearOrderMap(); } void ProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, diff --git a/chromium_src/components/sync/engine_impl/commit.cc b/chromium_src/components/sync/engine_impl/commit.cc index fbfa175e37df..1c3d3e681882 100644 --- a/chromium_src/components/sync/engine_impl/commit.cc +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -78,14 +78,6 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, 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() == "prev_object_id") { - bookmark->prevObjectId = bm_specifics.meta_info(i).value(); - } else if (bm_specifics.meta_info(i).key() == "prev_order") { - bookmark->prevOrder = bm_specifics.meta_info(i).value(); - } else if (bm_specifics.meta_info(i).key() == "next_order") { - bookmark->nextOrder = bm_specifics.meta_info(i).value(); - } else if (bm_specifics.meta_info(i).key() == "parent_order") { - bookmark->parentOrder = 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") { diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 6fafece87cab..9b3371675524 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -1,112 +1,10 @@ -namespace bookmarks { -class BookmarkModel; -class BookmarkNode; -} // namespace bookmarks - -namespace sync_bookmarks { -namespace { - -void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, - bookmarks::BookmarkModel* bookmark_model); - -bool IsFirstLoadedFavicon(const bookmarks::BookmarkNode* node); - -} // namespace -} // namespace sync_bookmarks - +#include "brave/components/brave_sync/syncer_helper.h" #include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" -#include "brave/components/brave_sync/tools.h" #include "components/bookmarks/browser/bookmark_model.h" -namespace sync_bookmarks { -namespace { - -void GetPrevObjectId(const bookmarks::BookmarkNode* parent, - int index, - std::string* prev_object_id) { - DCHECK_GE(index, 0); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - - if (prev_node) - prev_node->GetMetaInfo("object_id", prev_object_id); -} - -void GetOrder(const bookmarks::BookmarkNode* parent, - int index, - std::string* prev_order, - std::string* next_order, - std::string* parent_order) { - DCHECK_GE(index, 0); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - auto* next_node = index == parent->child_count() - 1 ? - nullptr : - parent->GetChild(index + 1); - - if (prev_node) - prev_node->GetMetaInfo("order", prev_order); - if (next_node) - next_node->GetMetaInfo("order", next_order); - - parent->GetMetaInfo("order", parent_order); -} - -void AddMetaInfo(bookmarks::BookmarkModel* bookmark_model, - const bookmarks::BookmarkNode* node, - const std::string& key, - const std::string& value) { - bookmark_model->SetNodeMetaInfo(node, key, value); -} - -void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, - bookmarks::BookmarkModel* bookmark_model) { - std::string prev_object_id; - int index = node->parent()->GetIndexOf(node); - GetPrevObjectId(node->parent(), index, &prev_object_id); - AddMetaInfo(bookmark_model, node, - "prev_object_id", prev_object_id); - - std::string parent_order; - std::string prev_order; - std::string next_order; - GetOrder(node->parent(), index, &prev_order, &next_order, &parent_order); - AddMetaInfo(bookmark_model, node, - "prev_order", prev_order); - AddMetaInfo(bookmark_model, node, - "next_order", next_order); - AddMetaInfo(bookmark_model, node, - "parent_order", parent_order); - // clear the order which will be calculated when sending - AddMetaInfo(bookmark_model, node, "order", std::string()); - - std::string object_id; - node->GetMetaInfo("object_id", &object_id); - // newly created node - if (object_id.empty()) { - object_id = brave_sync::tools::GenerateObjectId(); - } - AddMetaInfo(bookmark_model, node, - "object_id", object_id); - - std::string parent_object_id; - node->parent()->GetMetaInfo("object_id", &parent_object_id); - AddMetaInfo(bookmark_model, node, - "parent_object_id", parent_object_id); - - std::string sync_timestamp; - node->GetMetaInfo("sync_timestamp", &sync_timestamp); - if (sync_timestamp.empty()) { - sync_timestamp = std::to_string(base::Time::Now().ToJsTime()); - } - DCHECK(!sync_timestamp.empty()); - AddMetaInfo(bookmark_model, node, - "sync_timestamp", sync_timestamp); -} +namespace sync_bookmarks { -bool IsFirstLoadedFavicon(const BookmarkNode* node) { +bool BookmarkChangeProcessor::IsFirstLoadedFavicon(const BookmarkNode* node) { // Avoid sending duplicate records right after applying CREATE records, // BookmarkChangeProcessor::SetBookmarkFavicon, put favicon data into database // BookmarkNode::favicon() and BookmarkNode::icon_url() are available only @@ -118,12 +16,13 @@ bool IsFirstLoadedFavicon(const BookmarkNode* node) { if (node->GetMetaInfo("FirstLoadedFavicon", &FirstLoadedFavicon)) { if (!node->icon_url()) return true; + bookmark_model_->RemoveObserver(this); BookmarkNode* mutable_node = const_cast(node); mutable_node->DeleteMetaInfo("FirstLoadedFavicon"); + bookmark_model_->AddObserver(this); return true; } return false; } -} // namespace } // namespace sync_bookmarks diff --git a/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc b/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc index b343b1f005d9..4fa9caabef30 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc @@ -1,116 +1,3 @@ // This override is for kSyncUSSBookmarks -// TODO(darkdh): use same implementation as bookmark_change_processor.cc in the -// same file since we store objectId in meta info now -namespace bookmarks { -class BookmarkModel; -class BookmarkNode; -} // namespace bookmarks - -namespace sync_bookmarks { -class SyncedBookmarkTracker; -namespace { - -void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, - const SyncedBookmarkTracker* bookmark_tracker, - bookmarks::BookmarkModel* bookmark_model); - -} // namespace -} // namespace sync_bookmarks - +#include "brave/components/brave_sync/syncer_helper.h" #include "../../../../components/sync_bookmarks/bookmark_local_changes_builder.cc" -#include "brave/components/brave_sync/tools.h" -#include "components/bookmarks/browser/bookmark_model.h" -namespace sync_bookmarks { -namespace { - -void GetPrevObjectId(const bookmarks::BookmarkNode* parent, - const SyncedBookmarkTracker* bookmark_tracker, - int index, - std::string* prev_object_id) { - DCHECK_GE(index, 0); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - - if (prev_node) { - const SyncedBookmarkTracker::Entity* prev_entity = - bookmark_tracker->GetEntityForBookmarkNode(prev_node); - *prev_object_id = prev_entity->metadata()->server_id(); - } -} - -void GetOrder(const bookmarks::BookmarkNode* parent, - int index, - std::string* prev_order, - std::string* next_order, - std::string* parent_order) { - DCHECK_GE(index, 0); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - auto* next_node = index == parent->child_count() - 1 ? - nullptr : - parent->GetChild(index + 1); - - if (prev_node) - prev_node->GetMetaInfo("order", prev_order); - - if (next_node) - next_node->GetMetaInfo("order", next_order); - - parent->GetMetaInfo("order", parent_order); -} - -void AddMetaInfo(bookmarks::BookmarkModel* bookmark_model, - const bookmarks::BookmarkNode* node, - const std::string& key, - const std::string& value) { - bookmark_model->SetNodeMetaInfo(node, key, value); -} - -void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, - const SyncedBookmarkTracker* bookmark_tracker, - bookmarks::BookmarkModel* bookmark_model) { - std::string prev_object_id; - int index = node->parent()->GetIndexOf(node); - GetPrevObjectId(node->parent(), bookmark_tracker, index, &prev_object_id); - AddMetaInfo(bookmark_model, node, - "prev_object_id", prev_object_id); - - std::string parent_order; - std::string prev_order; - std::string next_order; - GetOrder(node->parent(), index, &prev_order, &next_order, &parent_order); - AddMetaInfo(bookmark_model, node, - "prev_order", prev_order); - AddMetaInfo(bookmark_model, node, - "next_order", next_order); - AddMetaInfo(bookmark_model, node, - "parent_order", parent_order); - - std::string object_id; - node->GetMetaInfo("object_id", &object_id); - // newly created node - if (object_id.empty()) { - object_id = brave_sync::tools::GenerateObjectId(); - } - AddMetaInfo(bookmark_model, node, - "object_id", object_id); - - std::string parent_object_id; - node->parent()->GetMetaInfo("object_id", &parent_object_id); - AddMetaInfo(bookmark_model, node, - "parent_object_id", parent_object_id); - - std::string sync_timestamp; - node->GetMetaInfo("sync_timestamp", &sync_timestamp); - if (sync_timestamp.empty()) { - sync_timestamp = std::to_string(base::Time::Now().ToJsTime()); - } - DCHECK(!sync_timestamp.empty()); - AddMetaInfo(bookmark_model, node, - "sync_timestamp", sync_timestamp); -} - -} // namespace -} // namespace sync_bookmarks diff --git a/common/extensions/api/brave_sync.json b/common/extensions/api/brave_sync.json index bc8c8ba61cc8..01a1fcfa03bc 100644 --- a/common/extensions/api/brave_sync.json +++ b/common/extensions/api/brave_sync.json @@ -64,14 +64,9 @@ "isFolder" : {"type": "boolean"}, "parentFolderObjectId" : {"type" : "binary", "optional": true}, "parentFolderObjectIdStr" : {"type" : "string", "optional": true}, - "prevObjectId" : {"type" : "binary", "optional": true}, - "prevObjectIdStr" : {"type" : "string", "optional": true}, "fields" : { "type": "array", "items": {"type": "string" }, "optional": true }, "hideInToolbar" : {"type": "boolean", "optional": true}, "order" : {"type": "string", "optional": true}, - "prevOrder" : {"type": "string", "optional": true}, - "nextOrder" : {"type": "string", "optional": true}, - "parentOrder" : {"type": "string", "optional": true}, "metaInfo" : { "type": "array", "items": {"$ref" : "MetaInfo" }, "optional": true } } }, @@ -298,11 +293,6 @@ "type": "function", "description": "Browser informs extension page to load js sync library.", "parameters": [] - }, - { - "name": "onClearOrderMap", - "type": "function", - "description": "Browser informs extension page all portions of bookmarks are sent, so it is time to clear the order map" } ], "functions": [ @@ -428,21 +418,6 @@ } ] }, - { - "name": "saveBookmarkOrder", - "type": "function", - "description": "Browser update order of certain object", - "parameters": [ - { - "type": "string", - "name": "object_id" - }, - { - "type": "string", - "name": "order" - } - ] - }, { "name": "syncWordsPrepared", "type": "function", diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index c413728192fb..c879561e4f17 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -58,6 +58,8 @@ source_set("core") { "settings.h", "sync_devices.cc", "sync_devices.h", + "syncer_helper.cc", + "syncer_helper.h", "tools.cc", "tools.h", "values_conv.cc", diff --git a/components/brave_sync/client/brave_sync_client.h b/components/brave_sync/client/brave_sync_client.h index eee02bf5dbef..dd9b0e50f05a 100644 --- a/components/brave_sync/client/brave_sync_client.h +++ b/components/brave_sync/client/brave_sync_client.h @@ -51,8 +51,6 @@ class SyncMessageHandler { virtual void OnDeleteSyncSiteSettings() = 0; // SAVE_BOOKMARKS_BASE_ORDER virtual void OnSaveBookmarksBaseOrder(const std::string& order) = 0; - virtual void OnSaveBookmarkOrder(const std::string& object_id, - const std::string& order) = 0; virtual void OnSyncWordsPrepared(const std::string& words) = 0; }; @@ -88,8 +86,6 @@ class BraveSyncClient { virtual void OnExtensionInitialized() = 0; virtual void OnSyncEnabledChanged() = 0; - - virtual void ClearOrderMap() = 0; }; } // namespace brave_sync diff --git a/components/brave_sync/client/brave_sync_client_impl.cc b/components/brave_sync/client/brave_sync_client_impl.cc index 2fb0a7714e71..7a49ee99e787 100644 --- a/components/brave_sync/client/brave_sync_client_impl.cc +++ b/components/brave_sync/client/brave_sync_client_impl.cc @@ -208,9 +208,4 @@ void BraveSyncClientImpl::OnExtensionSystemReady() { } } -void BraveSyncClientImpl::ClearOrderMap() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - brave_sync_event_router_->ClearOrderMap(); -} - } // namespace brave_sync diff --git a/components/brave_sync/client/brave_sync_client_impl.h b/components/brave_sync/client/brave_sync_client_impl.h index 023811c81b7a..ab4d531ec36c 100644 --- a/components/brave_sync/client/brave_sync_client_impl.h +++ b/components/brave_sync/client/brave_sync_client_impl.h @@ -79,8 +79,6 @@ class BraveSyncClientImpl : public BraveSyncClient, void LoadOrUnloadExtension(bool load); void OnExtensionSystemReady(); - void ClearOrderMap() override; - SyncMessageHandler* handler_; // not owned Profile* profile_; // not owned std::unique_ptr sync_prefs_; diff --git a/components/brave_sync/client/client_ext_impl_data.cc b/components/brave_sync/client/client_ext_impl_data.cc index f6256d582d09..8c8bbef074e6 100644 --- a/components/brave_sync/client/client_ext_impl_data.cc +++ b/components/brave_sync/client/client_ext_impl_data.cc @@ -150,14 +150,6 @@ std::unique_ptr FromLibBookmark( new std::string(lib_bookmark.parentFolderObjectId)); } - if (!lib_bookmark.prevObjectId.empty()) { - ext_bookmark->prev_object_id.reset( - new std::vector( - UCharVecFromString(lib_bookmark.prevObjectId))); - ext_bookmark->prev_object_id_str.reset( - new std::string(lib_bookmark.prevObjectId)); - } - if (!lib_bookmark.fields.empty()) { ext_bookmark->fields.reset( new std::vector(lib_bookmark.fields)); @@ -167,12 +159,6 @@ std::unique_ptr FromLibBookmark( ext_bookmark->order.reset(new std::string(lib_bookmark.order)); - ext_bookmark->prev_order.reset(new std::string(lib_bookmark.prevOrder)); - - ext_bookmark->next_order.reset(new std::string(lib_bookmark.nextOrder)); - - ext_bookmark->parent_order.reset(new std::string(lib_bookmark.parentOrder)); - if (!lib_bookmark.metaInfo.empty()) { ext_bookmark->meta_info = FromLibMetaInfo(lib_bookmark.metaInfo); } diff --git a/components/brave_sync/extension/background.js b/components/brave_sync/extension/background.js index 9e1ca430ed8e..70ee291ff96d 100644 --- a/components/brave_sync/extension/background.js +++ b/components/brave_sync/extension/background.js @@ -34,13 +34,9 @@ chrome.braveSync.onResolveSyncRecords.addListener(function(category_name, record if ('localRecord' in cur_rec) { fixupSyncRecordBrowserToExt(cur_rec.serverRecord); fixupSyncRecordBrowserToExt(cur_rec.localRecord); - getOrder(cur_rec.localRecord); - removeLocalMeta(cur_rec.serverRecord); - removeLocalMeta(cur_rec.localRecord); recordsAndExistingObjectsArrArr.push([cur_rec.serverRecord, cur_rec.localRecord]); } else { fixupSyncRecordBrowserToExt(cur_rec.serverRecord); - removeLocalMeta(cur_rec.serverRecord); recordsAndExistingObjectsArrArr.push([cur_rec.serverRecord, null]); } } @@ -51,10 +47,7 @@ chrome.braveSync.onResolveSyncRecords.addListener(function(category_name, record chrome.braveSync.onSendSyncRecords.addListener(function(category_name, records) { // Fixup ids for (var i = 0; i < records.length; ++i) { - // getOrder requires objectIdStr to send back order - getOrder(records[i]); fixupSyncRecordBrowserToExt(records[i]); - removeLocalMeta(records[i]); } console.log(`"send-sync-records" category_name=${JSON.stringify(category_name)} records=${JSON.stringify(records)}`); callbackList["send-sync-records"](null, category_name, records); @@ -78,60 +71,12 @@ chrome.braveSync.onLoadClient.addListener(function() { LoadJsLibScript(); }); -chrome.braveSync.onClearOrderMap.addListener(function() { - orderMap = {}; -}); - chrome.braveSync.extensionInitialized(); console.log("chrome.braveSync.extensionInitialized"); //------------------------------------------------------------- -function getOrder(record) { - if ('bookmark' in record) { - if (!record.bookmark.order) { - getBookmarkOrderCallback = (order) => { - record.bookmark.order = order; - if (record.objectId) - orderMap[record.objectId] = order; - if (record.objectIdStr) - chrome.braveSync.saveBookmarkOrder(record.objectIdStr, order); - getBookmarkOrderCallback = null; - } - - var prevOrder = record.bookmark.prevOrder; - var parentOrder = record.bookmark.parentOrder; - if (!prevOrder && orderMap[record.bookmark.prevObjectId]) - prevOrder = orderMap[record.bookmark.prevObjectId]; - if (!parentOrder && orderMap[record.bookmark.parentFolderObjectId]) - parentOrder = orderMap[record.bookmark.parentFolderObjectId]; - console.log(`"get-bookmark-order" prevOrder=${prevOrder}` + - ` nextOrder=${record.bookmark.nextOrder} parentOrder=${parentOrder}`); - callbackList["get-bookmark-order"](null, prevOrder, - record.bookmark.nextOrder, parentOrder); - while(getBookmarkOrderCallback); - } - } -} - -function removeLocalMeta(record) { - if ('bookmark' in record) { - if ('prevObjectId' in record.bookmark) { - delete record.bookmark.prevObjectId; - } - if ('prevOrder' in record.bookmark) { - delete record.bookmark.prevOrder; - } - if ('nextOrder' in record.bookmark) { - delete record.bookmark.nextOrder; - } - if ('parentOrder' in record.bookmark) { - delete record.bookmark.parentOrder; - } - } -} - -function fixupBookmarkFields(category_name, records) { +function fixupBookmarkParentFolderObjectId(category_name, records) { // records[0].bookmark.parentFolderObjectId can be either Uint8Array or Array[] // Uint8Array is expanded to "binary", // Array[] is expanded to "array" of "integer" in schema @@ -139,9 +84,6 @@ function fixupBookmarkFields(category_name, records) { if (category_name == "BOOKMARKS") { for(var i = 0; i < records.length; ++i) { fixupSyncRecordExtToBrowser(records[i]); - // Until brave-sync cannot deal with metaInfo field, this field causes - // "Error at property 'bookmark': Unexpected property: 'metaInfo'" - delete records[i].bookmark.metaInfo; } } } @@ -203,21 +145,6 @@ function fixupSyncRecordExtToBrowser(sync_record) { } delete sync_record.bookmark.parentFolderObjectIdStr; } - if ('prevObjectId' in sync_record.bookmark) { - if (Array.isArray(sync_record.bookmark.prevObjectId)) { - sync_record.bookmark.prevObjectId = new Uint8Array(sync_record.bookmark.prevObjectId); - } else if (sync_record.bookmark.prevObjectId == null || sync_record.bookmark.prevObjectId.length == 0) { - sync_record.bookmark.prevObjectId = new Uint8Array(); - } - } else { - sync_record.bookmark.prevObjectId = new Uint8Array(); - } - if ('prevObjectIdStr' in sync_record.bookmark) { - if (sync_record.bookmark.prevObjectIdStr) { - sync_record.bookmark.prevObjectId = new Uint8Array(IntArrayFromString(sync_record.bookmark.prevObjectIdStr)); - } - delete sync_record.bookmark.prevObjectIdStr; - } } } @@ -261,7 +188,7 @@ class InjectedObject { chrome.braveSync.syncReady(); break; case "get-existing-objects": - fixupBookmarkFields(arg1, arg2); + fixupBookmarkParentFolderObjectId(arg1, arg2); console.log(`"get-existing-objects" category_name=${JSON.stringify(arg1)} records=${JSON.stringify(arg2)} lastRecordTimeStamp=${arg3 ? arg3 : 0} isTruncated=${arg4 != undefined ? arg4 : false} `); chrome.braveSync.getExistingObjects(arg1/*category_name*/, arg2/*records*/, arg3 ? arg3 : 0/*lastRecordTimeStamp*/, arg4 != undefined ? arg4 : false/*isTruncated*/); @@ -275,12 +202,6 @@ class InjectedObject { console.log(`"save-bookmarks-base-order" order=${JSON.stringify(arg1)} `); chrome.braveSync.saveBookmarksBaseOrder(arg1/*order*/); break; - case "save-bookmark-order": - console.log(`"save-bookmark-order" order=${JSON.stringify(arg1)} prevOrder=${JSON.stringify(arg2)} nextOrder=${JSON.stringify(arg3)} parentOrder=${JSON.stringify(arg4)}`); - if (getBookmarkOrderCallback) { - getBookmarkOrderCallback(arg1); - } - break; default: console.log('background.js TAGAB InjectedObject.handleMessage unknown message', message, arg1, arg2, arg3, arg4); console.log('background.js TAGAB message=' + message); @@ -311,7 +232,6 @@ function LoadJsLibScript() { var callbackList = {}; /* message name to callback function */ var getBookmarkOrderCallback = null; -var orderMap = {} if (!self.chrome) { self.chrome = {}; diff --git a/components/brave_sync/jslib_messages.h b/components/brave_sync/jslib_messages.h index 2112a44bd9c3..9b2d6fda0075 100644 --- a/components/brave_sync/jslib_messages.h +++ b/components/brave_sync/jslib_messages.h @@ -58,13 +58,9 @@ class Bookmark { Site site; bool isFolder; std::string parentFolderObjectId; // bytes - std::string prevObjectId; // bytes std::vector fields; bool hideInToolbar; std::string order; - std::string prevOrder; - std::string nextOrder; - std::string parentOrder; std::vector metaInfo; }; diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc new file mode 100644 index 000000000000..4bf60a1654e2 --- /dev/null +++ b/components/brave_sync/syncer_helper.cc @@ -0,0 +1,81 @@ +/* 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/syncer_helper.h" + +#include "base/strings/string_number_conversions.h" +#include "brave/components/brave_sync/tools.h" +#include "components/bookmarks/browser/bookmark_model.h" + +namespace brave_sync { +namespace { + +void ClearOrder(const bookmarks::BookmarkNode* leaf) { + bookmarks::BookmarkNode* node = const_cast(leaf); + while (!node->is_permanent_node()) { + node->DeleteMetaInfo("order"); + node = node->parent(); + } +} + +void SetOrder(bookmarks::BookmarkModel* model, + const bookmarks::BookmarkNode* node, + const std::string& parent_order) { + DCHECK(!parent_order.empty()); + int index = node->parent()->GetIndexOf(node); + std::string order = parent_order + "." + base::NumberToString(index + 1); + model->SetNodeMetaInfo(node, "order", order); +} + +void ReCalculateOrder(bookmarks::BookmarkModel* model, + const bookmarks::BookmarkNode* node) { + DCHECK(!node->is_permanent_node()); + std::string parent_order; + const bookmarks::BookmarkNode* parent = node->parent(); + parent->GetMetaInfo("order", &parent_order); + if (parent_order.empty()) { + ReCalculateOrder(model, node->parent()); + } else { + SetOrder(model, node, parent_order); + } +} + +} // namespace + +void AddBraveMetaInfo( + const bookmarks::BookmarkNode* node, + bookmarks::BookmarkModel* model, + bool has_new_parent) { + if (has_new_parent) { + ClearOrder(node); + ReCalculateOrder(model, node); + } else { + std::string parent_order; + node->parent()->GetMetaInfo("order", &parent_order); + SetOrder(model, node, parent_order); + } + + std::string object_id; + node->GetMetaInfo("object_id", &object_id); + // newly created node + if (object_id.empty()) { + object_id = tools::GenerateObjectId(); + } + model->SetNodeMetaInfo(node, "object_id", object_id); + + std::string parent_object_id; + node->parent()->GetMetaInfo("object_id", &parent_object_id); + model->SetNodeMetaInfo(node, "parent_object_id", parent_object_id); + + std::string sync_timestamp; + node->GetMetaInfo("sync_timestamp", &sync_timestamp); + if (sync_timestamp.empty()) { + sync_timestamp = std::to_string(base::Time::Now().ToJsTime()); + } + DCHECK(!sync_timestamp.empty()); + model->SetNodeMetaInfo(node, "sync_timestamp", sync_timestamp); +} + +} // namespace brave_sync diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h new file mode 100644 index 000000000000..1334c4b68e60 --- /dev/null +++ b/components/brave_sync/syncer_helper.h @@ -0,0 +1,22 @@ +/* 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_SYNCER_HELPER_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ + +namespace bookmarks { +class BookmarkModel; +class BookmarkNode; +} // namespace bookmarks + +namespace brave_sync { + +void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, + bookmarks::BookmarkModel* bookmark_model, + bool has_new_parent); + +} // namespace brave_sync + +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ diff --git a/patches/components-browser_sync-profile_sync_service.h.patch b/patches/components-browser_sync-profile_sync_service.h.patch index c43b049e8211..7ed40f671f1e 100644 --- a/patches/components-browser_sync-profile_sync_service.h.patch +++ b/patches/components-browser_sync-profile_sync_service.h.patch @@ -1,5 +1,5 @@ diff --git a/components/browser_sync/profile_sync_service.h b/components/browser_sync/profile_sync_service.h -index 6c01395b954ac146084865b0268992f277b4914c..e6c7eb64cf1167f58159cdfd4c9f58f62b620451 100644 +index 6c01395b954ac146084865b0268992f277b4914c..c23fc377beaebcef2a894e8c4e2f9f76e77d58d6 100644 --- a/components/browser_sync/profile_sync_service.h +++ b/components/browser_sync/profile_sync_service.h @@ -137,7 +137,9 @@ class ProfileSyncService : public syncer::SyncService, @@ -13,7 +13,7 @@ index 6c01395b954ac146084865b0268992f277b4914c..e6c7eb64cf1167f58159cdfd4c9f58f6 public: // If AUTO_START, sync will set IsFirstSetupComplete() automatically and sync // will begin syncing without the user needing to confirm sync settings. -@@ -346,6 +348,44 @@ class ProfileSyncService : public syncer::SyncService, +@@ -346,6 +348,42 @@ class ProfileSyncService : public syncer::SyncService, syncer::SyncClient* GetSyncClientForTest(); @@ -51,14 +51,12 @@ index 6c01395b954ac146084865b0268992f277b4914c..e6c7eb64cf1167f58159cdfd4c9f58f6 + void OnDeletedSyncUser() override; + void OnDeleteSyncSiteSettings() override; + void OnSaveBookmarksBaseOrder(const std::string& order) override; -+ void OnSaveBookmarkOrder(const std::string& object_id, -+ const std::string& order) override; + void OnSyncWordsPrepared(const std::string& words) override; + private: // Passed as an argument to StopImpl to control whether or not the sync // engine should clear its data directory when it shuts down. See StopImpl -@@ -465,6 +505,47 @@ class ProfileSyncService : public syncer::SyncService, +@@ -465,6 +503,47 @@ class ProfileSyncService : public syncer::SyncService, // Called by SyncServiceCrypto when a passphrase is required or accepted. void ReconfigureDueToPassphrase(syncer::ConfigureReason reason); diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index ac1b34a076ee..7fa7a15a5ba9 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,15 +1,15 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..76eec7bcf64a9bb28b4709f9ae01352933e1197e 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..edb2a70362e72bac1bc3edae59a3e8b43a4367f8 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc -@@ -85,6 +85,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( - bookmark_specifics.set_url(src->url().spec()); - } +@@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( bookmark_specifics.set_creation_time_us(src->date_added().ToInternalValue()); -+ AddBraveMetaInfo(src, model); dst->SetBookmarkSpecifics(bookmark_specifics); SetSyncNodeFavicon(src, model, dst); ++ brave_sync::AddBraveMetaInfo(src, model, false); SetSyncNodeMetaInfo(src, dst); + } + @@ -244,6 +245,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { // Acquire a scoped write lock via a transaction. syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); @@ -40,27 +40,48 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..76eec7bcf64a9bb28b4709f9ae013529 return; } -+ bookmark_model_->RemoveObserver(this); -+ AddBraveMetaInfo(child, model); ++ model->RemoveObserver(this); ++ brave_sync::AddBraveMetaInfo(child, model, old_parent != new_parent); + SetSyncNodeMetaInfo(child, &sync_node); -+ bookmark_model_->AddObserver(this); ++ model->AddObserver(this); + if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -458,6 +467,11 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( +@@ -429,6 +438,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, + + UpdateTransactionVersion(new_version, model, + std::vector(1, child)); ++ ++ BookmarkNodeChildrenReordered(model, new_parent); ++ if (old_parent != new_parent) { ++ BookmarkNodeChildrenReordered(model, old_parent); ++ } + } + + void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( +@@ -458,6 +472,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( return; } -+ model->RemoveObserver(this); -+ bool first_loaded_favicon = IsFirstLoadedFavicon(node); -+ model->AddObserver(this); -+ if (first_loaded_favicon) return; ++ if (IsFirstLoadedFavicon(node)) return; + CreateOrUpdateSyncNode(node); } -@@ -718,6 +732,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -490,6 +506,11 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( + DCHECK_EQ(sync_child.GetParentId(), + model_associator_->GetSyncIdFromChromeId(node->id())); + ++ model->RemoveObserver(this); ++ brave_sync::AddBraveMetaInfo(child, model, false); ++ SetSyncNodeMetaInfo(child, &sync_child); ++ model->AddObserver(this); ++ + if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, + model_associator_)) { + syncer::SyncError error(FROM_HERE, +@@ -718,6 +739,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.h.patch b/patches/components-sync_bookmarks-bookmark_change_processor.h.patch new file mode 100644 index 000000000000..f2d179201854 --- /dev/null +++ b/patches/components-sync_bookmarks-bookmark_change_processor.h.patch @@ -0,0 +1,13 @@ +diff --git a/components/sync_bookmarks/bookmark_change_processor.h b/components/sync_bookmarks/bookmark_change_processor.h +index e11a2ddf641edc7098c06433fd22d86467e2aabf..9017b2b0ca991299af08e1341a35efd9a4f61253 100644 +--- a/components/sync_bookmarks/bookmark_change_processor.h ++++ b/components/sync_bookmarks/bookmark_change_processor.h +@@ -238,6 +238,8 @@ class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, + // Returns false if |node| should not be synced. + bool CanSyncNode(const bookmarks::BookmarkNode* node); + ++ bool IsFirstLoadedFavicon(const bookmarks::BookmarkNode* node); ++ + SEQUENCE_CHECKER(sequence_checker_); + + // The bookmark model we are processing changes from. Non-null when diff --git a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch index a6ea15b3dae9..ba7b641b0194 100644 --- a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/sync_bookmarks/bookmark_local_changes_builder.cc b/components/sync_bookmarks/bookmark_local_changes_builder.cc -index 9d4210fe4771ac67df1f9563f1fc722f8fc35aae..8bd933938ea30e89eb1b02cbecf7d0d6466ec75b 100644 +index 9d4210fe4771ac67df1f9563f1fc722f8fc35aae..ee2beb034b5e5f487c0fca0e88a31a7c241180ea 100644 --- a/components/sync_bookmarks/bookmark_local_changes_builder.cc +++ b/components/sync_bookmarks/bookmark_local_changes_builder.cc @@ -66,6 +66,7 @@ BookmarkLocalChangesBuilder::BuildCommitRequests(size_t max_entries) const { data.specifics = CreateSpecificsFromBookmarkNode( node, bookmark_model_, /*force_favicon_load=*/true); data.non_unique_name = data.specifics.bookmark().title(); -+ AddBraveMetaInfo(node, bookmark_tracker_, bookmark_model_); ++ brave_sync::AddBraveMetaInfo(node, bookmark_model_, true); } request.entity = data.PassToPtr(); request.sequence_number = metadata->sequence_number(); From 889642898c18332ece0c7a10fdb285d8c43654ff Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 30 Apr 2019 07:08:30 -0700 Subject: [PATCH 11/73] Fix wrong sync code crash --- components/brave_sync/brave_sync_prefs.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/components/brave_sync/brave_sync_prefs.cc b/components/brave_sync/brave_sync_prefs.cc index 27c6b23a1476..15f5c7dcb257 100644 --- a/components/brave_sync/brave_sync_prefs.cc +++ b/components/brave_sync/brave_sync_prefs.cc @@ -50,6 +50,7 @@ void Prefs::RegisterProfilePrefs( registry->RegisterStringPref(prefs::kSyncDeviceList, std::string()); registry->RegisterStringPref(prefs::kSyncApiVersion, std::string("0")); + registry->RegisterIntegerPref(prefs::kSyncMigrateBookmarksVersion, 0); } std::string Prefs::GetSeed() const { From 8ca067585a137f59013d6b74a5611ead8375771f Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 6 May 2019 14:53:20 -0700 Subject: [PATCH 12/73] Subclass browser_sync::ProfileSyncService --- browser/extensions/api/brave_sync_api.cc | 38 +- browser/ui/webui/sync/sync_ui.cc | 3 +- .../sync/profile_sync_service_factory.cc | 9 + .../sync/profile_sync_service_factory.h | 4 + .../browser_sync/profile_sync_service.cc | 732 +---------------- .../browser_sync/profile_sync_service.h | 15 - components/brave_sync/BUILD.gn | 2 + .../brave_sync/brave_profile_sync_service.cc | 768 ++++++++++++++++++ .../brave_sync/brave_profile_sync_service.h | 126 +++ ...sync-profile_sync_service_factory.cc.patch | 13 + ...-sync-profile_sync_service_factory.h.patch | 13 + ...browser_sync-profile_sync_service.cc.patch | 45 +- ...-browser_sync-profile_sync_service.h.patch | 109 +-- 13 files changed, 995 insertions(+), 882 deletions(-) create mode 100644 chromium_src/chrome/browser/sync/profile_sync_service_factory.cc create mode 100644 chromium_src/chrome/browser/sync/profile_sync_service_factory.h delete mode 100644 chromium_src/components/browser_sync/profile_sync_service.h create mode 100644 components/brave_sync/brave_profile_sync_service.cc create mode 100644 components/brave_sync/brave_profile_sync_service.h create mode 100644 patches/chrome-browser-sync-profile_sync_service_factory.cc.patch create mode 100644 patches/chrome-browser-sync-profile_sync_service_factory.h.patch diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index 034264fb6092..9ecad7545271 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -10,6 +10,7 @@ #include #include "brave/common/extensions/api/brave_sync.h" +#include "brave/components/brave_sync/brave_profile_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" #include "brave/components/brave_sync/client/client_ext_impl_data.h" #include "brave/components/brave_sync/values_conv.h" @@ -18,7 +19,7 @@ #include "components/browser_sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" -using browser_sync::ProfileSyncService; +using brave_sync::BraveProfileSyncService; using content::BrowserContext; namespace extensions { @@ -26,8 +27,9 @@ namespace api { namespace { -ProfileSyncService* GetProfileSyncService(BrowserContext* browser_context) { - return ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( +BraveProfileSyncService* GetProfileSyncService( + BrowserContext* browser_context) { + return ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( Profile::FromBrowserContext(browser_context)); } @@ -37,7 +39,8 @@ ExtensionFunction::ResponseAction BraveSyncGetInitDataFunction::Run() { brave_sync::GetInitData::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnGetInitData(params->sync_version); @@ -49,7 +52,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncSetupErrorFunction::Run() { brave_sync::SyncSetupError::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnSyncSetupError( params->error); @@ -62,7 +66,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncDebugFunction::Run() { brave_sync::SyncDebug::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnSyncDebug( params->message); @@ -75,7 +80,8 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { brave_sync::SaveInitData::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnSaveInitData( params->seed ? *params->seed : std::vector(), @@ -85,7 +91,8 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { } ExtensionFunction::ResponseAction BraveSyncSyncReadyFunction::Run() { - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnSyncReady(); @@ -100,7 +107,8 @@ ExtensionFunction::ResponseAction BraveSyncGetExistingObjectsFunction::Run() { auto records = std::make_unique>(); ::brave_sync::ConvertSyncRecords(params->records, *records.get()); - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnGetExistingObjects( params->category_name, @@ -119,7 +127,8 @@ ExtensionFunction::ResponseAction BraveSyncResolvedSyncRecordsFunction::Run() { auto records = std::make_unique>(); ::brave_sync::ConvertSyncRecords(params->records, *records.get()); - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnResolvedSyncRecords( params->category_name, @@ -134,7 +143,8 @@ BraveSyncSaveBookmarksBaseOrderFunction::Run() { brave_sync::SaveBookmarksBaseOrder::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnSaveBookmarksBaseOrder( params->order); @@ -147,7 +157,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() { brave_sync::SyncWordsPrepared::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->OnSyncWordsPrepared(params->words); @@ -156,7 +167,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() { ExtensionFunction::ResponseAction BraveSyncExtensionInitializedFunction::Run() { // Also inform sync client extension started - ProfileSyncService* sync_service = GetProfileSyncService(browser_context()); + BraveProfileSyncService* sync_service = + GetProfileSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->OnExtensionInitialized(); diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index 50583e54dfea..98928360129e 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/memory/weak_ptr.h" #include "brave/common/webui_url_constants.h" +#include "brave/components/brave_sync/brave_profile_sync_service.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_resources.h" @@ -121,7 +122,7 @@ void SyncUIDOMHandler::Init() { Profile* profile = Profile::FromWebUI(web_ui()); sync_service_ = static_cast( - ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile(profile)); + ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile(profile)); if (sync_service_) sync_service_->AddObserver(this); } diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc new file mode 100644 index 000000000000..1390be708b19 --- /dev/null +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -0,0 +1,9 @@ +#include "brave/components/brave_sync/brave_profile_sync_service.h" +using brave_sync::BraveProfileSyncService; +#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" + +// static +BraveProfileSyncService* +ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile(Profile* profile) { + return static_cast(GetForProfile(profile)); +} diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.h b/chromium_src/chrome/browser/sync/profile_sync_service_factory.h new file mode 100644 index 000000000000..20da561ee9cf --- /dev/null +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.h @@ -0,0 +1,4 @@ +namespace brave_sync { +class BraveProfileSyncService; +} // namespace brave_sync +#include "../../../../../chrome/browser/sync/profile_sync_service_factory.h" diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/browser_sync/profile_sync_service.cc index 8eef44605ba2..afbee9d7feca 100644 --- a/chromium_src/components/browser_sync/profile_sync_service.cc +++ b/chromium_src/components/browser_sync/profile_sync_service.cc @@ -1,32 +1,12 @@ -#include "components/signin/core/browser/account_info.h" -#include "components/sync/engine/sync_credentials.h" -namespace browser_sync { -namespace { -syncer::SyncCredentials GetDummyCredentials(); -AccountInfo GetDummyAccountInfo(); -} -} - // For use_transport_only_mode #define IsSyncFeatureEnabled IsBraveSyncEnabled #include "../../../../components/browser_sync/profile_sync_service.cc" #include "base/bind.h" -#include "base/strings/utf_string_conversions.h" -#include "brave/components/brave_sync/brave_sync_prefs.h" -#include "brave/components/brave_sync/brave_sync_service_observer.h" -#include "brave/components/brave_sync/jslib_const.h" #include "brave/components/brave_sync/jslib_messages.h" -#include "brave/components/brave_sync/settings.h" -#include "brave/components/brave_sync/sync_devices.h" -#include "brave/components/brave_sync/tools.h" -#include "brave/components/brave_sync/values_conv.h" #include "chrome/browser/sync/chrome_sync_client.h" -#include "components/bookmarks/browser/bookmark_model.h" -#include "components/sync/engine_impl/syncer.h" +#include "components/sync/engine/sync_credentials.h" #include "content/public/browser/browser_thread.h" -#include "net/base/network_interfaces.h" -#include "ui/base/models/tree_node_iterator.h" namespace syncer { const int64_t kBraveDefaultShortPollIntervalSeconds = 60; @@ -35,45 +15,8 @@ const int64_t kBraveDefaultLongPollIntervalSeconds = 90; namespace browser_sync { -using brave_sync::GetRecordsCallback; -using brave_sync::jslib::Device; -using brave_sync::jslib::SyncRecord; -using brave_sync::jslib_const::kHistorySites; -using brave_sync::jslib_const::kBookmarks; -using brave_sync::jslib_const::kPreferences; -using brave_sync::jslib_const::SyncObjectData_DEVICE; -using brave_sync::jslib_const::SyncRecordType_PREFERENCES; -using brave_sync::RecordsList; -using brave_sync::RecordsListPtr; -using brave_sync::StrFromUint8Array; -using brave_sync::SyncDevice; -using brave_sync::SyncRecordAndExisting; -using brave_sync::SyncRecordAndExistingList; -using brave_sync::SyncRecordPtr; -using brave_sync::tools::IsTimeEmpty; -using brave_sync::Uint8Array; -using brave_sync::Uint8ArrayFromString; - namespace { -void NotifyLogMessage(const std::string& message) { - DLOG(INFO) << message; -} - -std::string GetDeviceName() { - std::string hostname = net::GetHostName(); - if (hostname.empty()) { -#if defined(OS_MACOSX) - hostname = std::string("Mac Desktop"); -#elif defined(OS_LINUX) - hostname = std::string("Linux Desktop"); -#elif defined(OS_WIN) - hostname = std::string("Windows Desktop"); -#endif - } - return hostname; -} - syncer::SyncCredentials GetDummyCredentials() { syncer::SyncCredentials credentials; credentials.account_id = "dummy_account_id"; @@ -82,639 +25,21 @@ syncer::SyncCredentials GetDummyCredentials() { return credentials; } -AccountInfo GetDummyAccountInfo() { - AccountInfo account_info; - account_info.account_id = "dummy_account_id"; - return account_info; -} - -RecordsListPtr CreateDeviceCreationRecordExtension( - const std::string& deviceName, - const std::string& objectId, - const SyncRecord::Action &action, - const std::string& deviceId) { - RecordsListPtr records = std::make_unique(); - - SyncRecordPtr record = std::make_unique(); - - record->action = action; - record->deviceId = deviceId; - record->objectId = objectId; - record->objectData = SyncObjectData_DEVICE; // "device" - - std::unique_ptr device = std::make_unique(); - device->name = deviceName; - record->SetDevice(std::move(device)); - - records->emplace_back(std::move(record)); - - return records; -} - -const bookmarks::BookmarkNode* FindByObjectId(bookmarks::BookmarkModel* model, - const std::string& object_id) { - ui::TreeNodeIterator - iterator(model->root_node()); - while (iterator.has_next()) { - const bookmarks::BookmarkNode* node = iterator.Next(); - std::string node_object_id; - node->GetMetaInfo("object_id", &node_object_id); - - if (!node_object_id.empty() && object_id == node_object_id) - return node; - } - return nullptr; -} - -std::unique_ptr BookmarkNodeToSyncBookmark( - bookmarks::BookmarkModel* model, - brave_sync::prefs::Prefs* brave_sync_prefs, - const bookmarks::BookmarkNode* node, - const SyncRecord::Action& action) { - if (node->is_permanent_node() || !node->parent()) - return std::unique_ptr(); - - auto record = std::make_unique(); - record->deviceId = brave_sync_prefs->GetThisDeviceId(); - record->objectData = brave_sync::jslib_const::SyncObjectData_BOOKMARK; - - auto bookmark = std::make_unique(); - bookmark->site.location = node->url().spec(); - bookmark->site.title = base::UTF16ToUTF8(node->GetTitledUrlNodeTitle()); - bookmark->site.customTitle = base::UTF16ToUTF8(node->GetTitle()); - // bookmark->site.lastAccessedTime - ignored - bookmark->site.creationTime = node->date_added(); - bookmark->site.favicon = node->icon_url() ? node->icon_url()->spec() : ""; - // Url may have type OTHER_NODE if it is in Deleted Bookmarks - bookmark->isFolder = (node->type() != bookmarks::BookmarkNode::URL && - node->type() != bookmarks::BookmarkNode::OTHER_NODE); - bookmark->hideInToolbar = - node->parent() != model->bookmark_bar_node(); - - std::string object_id; - node->GetMetaInfo("object_id", &object_id); - record->objectId = object_id; - - std::string parent_object_id; - node->parent()->GetMetaInfo("object_id", &parent_object_id); - bookmark->parentFolderObjectId = parent_object_id; - - std::string order; - node->GetMetaInfo("order", &order); - DCHECK(!order.empty()); - bookmark->order = order; - - std::string sync_timestamp; - node->GetMetaInfo("sync_timestamp", &sync_timestamp); - DCHECK(!sync_timestamp.empty()); - - record->syncTimestamp = base::Time::FromJsTime(std::stod(sync_timestamp)); - - record->action = brave_sync::jslib::SyncRecord::Action::A_UPDATE; - - record->SetBookmark(std::move(bookmark)); - - return record; -} - -void CreateResolveList( - const std::vector>& records, - SyncRecordAndExistingList* records_and_existing_objects, - bookmarks::BookmarkModel* model, - brave_sync::prefs::Prefs* brave_sync_prefs) { - for (const auto& record : records) { - auto resolved_record = std::make_unique(); - resolved_record->first = SyncRecord::Clone(*record); - auto* node = FindByObjectId(model, record->objectId); - if (node) { - resolved_record->second = BookmarkNodeToSyncBookmark(model, - brave_sync_prefs, - node, - record->action); - } - - records_and_existing_objects->push_back(std::move(resolved_record)); - } -} - } // namespace -void ProfileSyncService::OnSetupSyncHaveCode(const std::string& sync_words, - const std::string& device_name) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - if (sync_words.empty()) { - OnSyncSetupError("ERR_SYNC_WRONG_WORDS"); - return; - } - - if (brave_sync_initializing_) { - NotifyLogMessage("currently initializing"); - return; - } - - if (brave_sync_configured_) { - NotifyLogMessage("already configured"); - return; - } - - if (device_name.empty()) - brave_sync_prefs_->SetThisDeviceName(GetDeviceName()); - else - brave_sync_prefs_->SetThisDeviceName(device_name); - brave_sync_initializing_ = true; - - brave_sync_prefs_->SetSyncEnabled(true); - brave_sync_words_ = sync_words; -} - -void ProfileSyncService::OnSetupSyncNewToSync( - const std::string& device_name) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - if (brave_sync_initializing_) { - NotifyLogMessage("currently initializing"); - return; - } - - if (brave_sync_configured_) { - NotifyLogMessage("already configured"); - return; - } - - brave_sync_words_.clear(); // If the previous attempt was connect to sync chain - // and failed to receive save-init-data - if (device_name.empty()) - brave_sync_prefs_->SetThisDeviceName(GetDeviceName()); - else - brave_sync_prefs_->SetThisDeviceName(device_name); - - brave_sync_initializing_ = true; - - brave_sync_prefs_->SetSyncEnabled(true); -} - -void ProfileSyncService::OnDeleteDevice(const std::string& device_id) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - auto sync_devices = brave_sync_prefs_->GetSyncDevices(); - - const SyncDevice *device = sync_devices->GetByDeviceId(device_id); - if (device) { - const std::string device_name = device->name_; - const std::string object_id = device->object_id_; - SendDeviceSyncRecord( - SyncRecord::Action::A_DELETE, device_name, device_id, object_id); - } -} - -void ProfileSyncService::OnResetSync() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - auto sync_devices = brave_sync_prefs_->GetSyncDevices(); - - if (sync_devices->size() == 0) { - // Fail safe option - VLOG(2) << "[Sync] " << __func__ << " unexpected zero device size"; - ResetSyncInternal(); - } else { - // We have to send delete record and wait for library deleted response then - // we can reset it by ResetInternal() - const std::string device_id = brave_sync_prefs_->GetThisDeviceId(); - OnDeleteDevice(device_id); - } -} - -void ProfileSyncService::GetSettingsAndDevices( - const GetSettingsAndDevicesCallback& callback) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - auto settings = brave_sync_prefs_->GetBraveSyncSettings(); - auto devices = brave_sync_prefs_->GetSyncDevices(); - callback.Run(std::move(settings), std::move(devices)); -} - -void ProfileSyncService::GetSyncWords() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - // Ask sync client - std::string seed = brave_sync_prefs_->GetSeed(); - GetBraveSyncClient()->NeedSyncWords(seed); -} - -std::string ProfileSyncService::GetSeed() { - return brave_sync_prefs_->GetSeed(); -} - -void ProfileSyncService::OnSetSyncEnabled(const bool sync_this_device) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - brave_sync_prefs_->SetSyncEnabled(sync_this_device); -} - -void ProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - // POC so only do bookmarks - syncer::ModelTypeSet type_set = user_settings_->GetChosenDataTypes(); - if (sync_bookmarks) - type_set.Put(syncer::BOOKMARKS); - else - type_set.Remove(syncer::BOOKMARKS); - user_settings_->SetChosenDataTypes(false, type_set); - brave_sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); -} - -void ProfileSyncService::OnSetSyncBrowsingHistory( - const bool sync_browsing_history) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); -#if 0 - brave_sync_prefs_->SetSyncHistoryEnabled(sync_browsing_history); -#endif -} - -void ProfileSyncService::OnSetSyncSavedSiteSettings( - const bool sync_saved_site_settings) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); -#if 0 - brave_sync_prefs_->SetSyncSiteSettingsEnabled(sync_saved_site_settings); -#endif -} - -void ProfileSyncService::BackgroundSyncStarted(bool startup) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); -#if 0 - if (startup) - bookmark_change_processor_->Start(); - - StartLoop(); -#endif -} - -void ProfileSyncService::BackgroundSyncStopped(bool shutdown) { -#if 0 - if (shutdown) - Shutdown(); - else - StopLoop(); -#endif +syncer::SyncClient* ProfileSyncService::GetSyncClient() { + DCHECK(sync_client_); + return sync_client_.get(); } -void ProfileSyncService::OnSyncDebug(const std::string& message) { - NotifyLogMessage(message); +syncer::SyncUserSettings* ProfileSyncService::GetSyncUserSettings() { + DCHECK(user_settings_); + return user_settings_.get(); } -void ProfileSyncService::OnSyncSetupError(const std::string& error) { - if (brave_sync_initializing_) { - brave_sync_prefs_->Clear(); - brave_sync_initializing_ = false; - } - NotifySyncSetupError(error); -} - -void ProfileSyncService::OnGetInitData(const std::string& sync_version) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - Uint8Array seed; - if (!brave_sync_words_.empty()) { - VLOG(1) << "[Brave Sync] Init from sync words"; - } else if (!brave_sync_prefs_->GetSeed().empty()) { - seed = Uint8ArrayFromString(brave_sync_prefs_->GetSeed()); - VLOG(1) << "[Brave Sync] Init from prefs"; - } else { - VLOG(1) << "[Brave Sync] Init new chain"; - } - - Uint8Array device_id; - if (!brave_sync_prefs_->GetThisDeviceId().empty()) { - device_id = Uint8ArrayFromString(brave_sync_prefs_->GetThisDeviceId()); - VLOG(1) << "[Brave Sync] Init device id from prefs: " << - StrFromUint8Array(device_id); - } else { - VLOG(1) << "[Brave Sync] Init empty device id"; - } - - DCHECK(!sync_version.empty()); - // TODO(bridiver) - this seems broken because using the version we get back - // from the server (currently v1.4.2) causes things to break. What is the - // the point of having this value? - brave_sync_prefs_->SetApiVersion("0"); - - brave_sync::client_data::Config config; - config.api_version = brave_sync_prefs_->GetApiVersion(); - config.server_url = "https://sync.brave.com"; - config.debug = true; - GetBraveSyncClient()->SendGotInitData(seed, device_id, config, brave_sync_words_); -} - -void ProfileSyncService::OnSaveInitData(const Uint8Array& seed, - const Uint8Array& device_id) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - DCHECK(!brave_sync_initialized_); - // If we are here and brave_sync_initializing_ is false, we have came - // not from OnSetupSyncNewToSync or OnSetupSyncHaveCode. - // One case is we put wrong code words and then restarted before cleared - // kSyncEnabled pref. This should not happen. - DCHECK(brave_sync_initializing_); - - std::string seed_str = StrFromUint8Array(seed); - std::string device_id_str = StrFromUint8Array(device_id); - - std::string prev_seed_str = brave_sync_prefs_->GetPrevSeed(); - - brave_sync_words_.clear(); - DCHECK(!seed_str.empty()); - - if (prev_seed_str == seed_str) { // reconnecting to previous sync chain - brave_sync_prefs_->SetPrevSeed(std::string()); - } else if (!prev_seed_str.empty()) { // connect/create to new sync chain - // bookmark_change_processor_->Reset(true); - brave_sync_prefs_->SetPrevSeed(std::string()); - } else { - // This is not required, because when there is no previous seed, bookmarks - // should not have a metadata. However, this is done by intention, to be - // a remedy for cases when sync had been reset and prev_seed_str had been - // cleared when it shouldn't (brave-browser#3188). - // bookmark_change_processor_->Reset(true); - } - - brave_sync_prefs_->SetSeed(seed_str); - brave_sync_prefs_->SetThisDeviceId(device_id_str); - - brave_sync_configured_ = true; - - brave_sync_initializing_ = false; -} - -void ProfileSyncService::OnSyncReady() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - const std::string bookmarks_base_order = brave_sync_prefs_->GetBookmarksBaseOrder(); - if (bookmarks_base_order.empty()) { - std::string platform = brave_sync::tools::GetPlatformName(); - GetBraveSyncClient()->SendGetBookmarksBaseOrder(brave_sync_prefs_->GetThisDeviceId(), - platform); - // OnSyncReady will be called by OnSaveBookmarksBaseOrder - return; - } - - DCHECK(false == brave_sync_initialized_); - brave_sync_initialized_ = true; - - user_settings_->SetChosenDataTypes(false, syncer::ModelTypeSet()); - OnSetSyncBookmarks(true); - user_settings_->SetSyncRequested(true); -} - -void ProfileSyncService::OnGetExistingObjects( - const std::string& category_name, - std::unique_ptr records, - const base::Time &last_record_time_stamp, - const bool is_truncated) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - // TODO(bridiver) - what do we do with is_truncated ? - // It appears to be ignored in b-l - if (!IsTimeEmpty(last_record_time_stamp)) { - brave_sync_prefs_->SetLatestRecordTime(last_record_time_stamp); - } - - if (category_name == kBookmarks) { - auto records_and_existing_objects = - std::make_unique(); - CreateResolveList( - *records.get(), records_and_existing_objects.get(), - // TODO(darkdh): find another way to obtain bookmark model - // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 - static_cast(sync_client_.get())->GetBookmarkModel(), - brave_sync_prefs_.get()); - GetBraveSyncClient()->SendResolveSyncRecords( - category_name, std::move(records_and_existing_objects)); - } -} - -void ProfileSyncService::OnResolvedSyncRecords( - const std::string& category_name, - std::unique_ptr records) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - if (category_name == brave_sync::jslib_const::kPreferences) { - OnResolvedPreferences(*records.get()); - } else if (category_name == kBookmarks) { - // Send records to syncer - if (get_record_cb_) - engine_->DispatchGetRecordsCallback(get_record_cb_, std::move(records)); - SignalWaitableEvent(); - } else if (category_name == kHistorySites) { - NOTIMPLEMENTED(); - } -} - -void ProfileSyncService::OnDeletedSyncUser() { - NOTIMPLEMENTED(); -} - -void ProfileSyncService::OnDeleteSyncSiteSettings() { - NOTIMPLEMENTED(); -} - -void ProfileSyncService::OnSaveBookmarksBaseOrder(const std::string& order) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - DCHECK(!order.empty()); - brave_sync_prefs_->SetBookmarksBaseOrder(order); - bookmarks::BookmarkModel* model = - // TODO(darkdh): find another way to obtain bookmark model - // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 - static_cast(sync_client_.get())->GetBookmarkModel(); - bookmarks::BookmarkNode* mutable_bookmark_bar_node = - const_cast(model->bookmark_bar_node()); - model->SetNodeMetaInfo(mutable_bookmark_bar_node, "order", order + "1"); - bookmarks::BookmarkNode* mutable_other_node = - const_cast(model->other_node()); - model->SetNodeMetaInfo(mutable_other_node, "order", order + "2"); - OnSyncReady(); -} - -void ProfileSyncService::OnSyncWordsPrepared(const std::string& words) { - NotifyHaveSyncWords(words); -} - -void ProfileSyncService::NotifySyncSetupError(const std::string& error) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - for (auto& observer : brave_sync::BraveSyncService::observers_) - observer.OnSyncSetupError(this, error); -} - -void ProfileSyncService::NotifySyncStateChanged() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - for (auto& observer : brave_sync::BraveSyncService::observers_) - observer.OnSyncStateChanged(this); -} - -void ProfileSyncService::NotifyHaveSyncWords( - const std::string& sync_words) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - for (auto& observer : brave_sync::BraveSyncService::observers_) - observer.OnHaveSyncWords(this, sync_words); -} - -void ProfileSyncService::ResetSyncInternal() { - brave_sync_prefs_->SetPrevSeed(brave_sync_prefs_->GetSeed()); - - brave_sync_prefs_->Clear(); - - brave_sync_configured_ = false; - brave_sync_initialized_ = false; - - brave_sync_prefs_->SetSyncEnabled(false); -} - -void ProfileSyncService::FetchSyncRecords(const bool bookmarks, - const bool history, - const bool preferences, - int max_records) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(bookmarks || history || preferences); - if (!(bookmarks || history || preferences)) { - return; - } - - std::vector category_names; - if (history) { - category_names.push_back(kHistorySites); // "HISTORY_SITES"; - } - if (bookmarks) { - category_names.push_back(kBookmarks); // "BOOKMARKS"; - } - if (preferences) { - category_names.push_back(kPreferences); // "PREFERENCES"; - } - - brave_sync_prefs_->SetLastFetchTime(base::Time::Now()); - - base::Time start_at_time = brave_sync_prefs_->GetLatestRecordTime(); - GetBraveSyncClient()->SendFetchSyncRecords( - category_names, - start_at_time, - max_records); -} - -void ProfileSyncService::SendCreateDevice() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - - std::string device_name = brave_sync_prefs_->GetThisDeviceName(); - std::string object_id = brave_sync::tools::GenerateObjectId(); - std::string device_id = brave_sync_prefs_->GetThisDeviceId(); - CHECK(!device_id.empty()); - - SendDeviceSyncRecord( - SyncRecord::Action::A_CREATE, - device_name, - device_id, - object_id); -} - -void ProfileSyncService::SendDeviceSyncRecord( - const int action, - const std::string& device_name, - const std::string& device_id, - const std::string& object_id) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - RecordsListPtr records = CreateDeviceCreationRecordExtension( - device_name, - object_id, - static_cast(action), - device_id); - GetBraveSyncClient()->SendSyncRecords( - SyncRecordType_PREFERENCES, *records); -} - -brave_sync::BraveSyncClient* ProfileSyncService::GetBraveSyncClient() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - return sync_client_->GetBraveSyncClient(); -} - -void ProfileSyncService::OnResolvedPreferences(const RecordsList& records) { - const std::string this_device_id = brave_sync_prefs_->GetThisDeviceId(); - bool this_device_deleted = false; - bool contains_only_one_device = false; - - auto sync_devices = brave_sync_prefs_->GetSyncDevices(); - for (const auto &record : records) { - DCHECK(record->has_device() || record->has_sitesetting()); - if (record->has_device()) { - bool actually_merged = false; - sync_devices->Merge( - SyncDevice(record->GetDevice().name, - record->objectId, - record->deviceId, - record->syncTimestamp.ToJsTime()), - record->action, - &actually_merged); - this_device_deleted = this_device_deleted || - (record->deviceId == this_device_id && - record->action == SyncRecord::Action::A_DELETE && - actually_merged); - contains_only_one_device = sync_devices->size() < 2 && - record->action == SyncRecord::Action::A_DELETE && - actually_merged; - } - } // for each device - - brave_sync_prefs_->SetSyncDevices(*sync_devices); - - if (this_device_deleted) { - ResetSyncInternal(); - } else if (contains_only_one_device) { - // We see amount of devices had been decreased to 1 and it is not this - // device had been deleted. So call OnResetSync which will send DELETE - // record for this device - OnResetSync(); - } -} - -void ProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { - if (pref == brave_sync::prefs::kSyncEnabled) { - GetBraveSyncClient()->OnSyncEnabledChanged(); - if (!brave_sync_prefs_->GetSyncEnabled()) { - brave_sync_initialized_ = false; - user_settings_->SetSyncRequested(false); - } - } - NotifySyncStateChanged(); -} - -bool ProfileSyncService::IsBraveSyncEnabled() const{ - return brave_sync_prefs_->GetSyncEnabled(); -} - -void ProfileSyncService::BraveSyncSetup() { - brave_sync_words_ = std::string(); - brave_sync_prefs_ = - std::make_unique(sync_client_->GetPrefService()); - sync_client_->GetBraveSyncClient()->set_sync_message_handler(this); - - // Moniter syncs prefs required in GetSettingsAndDevices - brave_pref_change_registrar_.Init(sync_client_->GetPrefService()); - brave_pref_change_registrar_.Add( - brave_sync::prefs::kSyncEnabled, - base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, - base::Unretained(this))); - brave_pref_change_registrar_.Add( - brave_sync::prefs::kSyncDeviceName, - base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, - base::Unretained(this))); - brave_pref_change_registrar_.Add( - brave_sync::prefs::kSyncDeviceList, - base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, - base::Unretained(this))); - brave_pref_change_registrar_.Add( - brave_sync::prefs::kSyncBookmarksEnabled, - base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, - base::Unretained(this))); - brave_pref_change_registrar_.Add( - brave_sync::prefs::kSyncSiteSettingsEnabled, - base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, - base::Unretained(this))); - brave_pref_change_registrar_.Add( - brave_sync::prefs::kSyncHistoryEnabled, - base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, - base::Unretained(this))); - - if (!brave_sync_prefs_->GetSeed().empty() && - !brave_sync_prefs_->GetThisDeviceName().empty()) { - brave_sync_configured_ = true; - } +syncer::SyncEngine* ProfileSyncService::GetSyncEngine() { + DCHECK(engine_); + return engine_.get(); } void ProfileSyncService::BraveEngineParamsInit( @@ -738,40 +63,13 @@ void ProfileSyncService::BraveEngineParamsInit( } void ProfileSyncService::OnNudgeSyncCycle( - brave_sync::RecordsListPtr records) { - for (auto& record : *records) { - record->deviceId = brave_sync_prefs_->GetThisDeviceId(); - } - if (!records->empty()) - GetBraveSyncClient()->SendSyncRecords( - brave_sync::jslib_const::SyncRecordType_BOOKMARKS, *records); -} + brave_sync::RecordsListPtr records_list) {} -void ProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, - base::WaitableEvent* wevent) { - if (IsTimeEmpty(brave_sync_prefs_->GetLastFetchTime())) - SendCreateDevice(); - GetBraveSyncClient()->SendFetchSyncDevices(); - - if (!brave_sync_initialized_) { - wevent->Signal(); - return; - } - - get_record_cb_ = cb; - wevent_ = wevent; - - const bool bookmarks = brave_sync_prefs_->GetSyncBookmarksEnabled(); - const bool history = brave_sync_prefs_->GetSyncHistoryEnabled(); - const bool preferences = brave_sync_prefs_->GetSyncSiteSettingsEnabled(); - FetchSyncRecords(bookmarks, history, preferences, 1000); -} +void ProfileSyncService::OnPollSyncCycle(brave_sync::GetRecordsCallback cb, + base::WaitableEvent* wevent) {} -void ProfileSyncService::SignalWaitableEvent() { - if (wevent_) { - wevent_->Signal(); - wevent_ = nullptr; - } +bool ProfileSyncService::IsBraveSyncEnabled() const { + return false; } } // namespace browser_sync diff --git a/chromium_src/components/browser_sync/profile_sync_service.h b/chromium_src/components/browser_sync/profile_sync_service.h deleted file mode 100644 index a0b557e7b4ee..000000000000 --- a/chromium_src/components/browser_sync/profile_sync_service.h +++ /dev/null @@ -1,15 +0,0 @@ -#include "brave/components/brave_sync/brave_sync_service.h" -#include "brave/components/brave_sync/client/brave_sync_client.h" -#include "brave/components/brave_sync/jslib_messages_fwd.h" - -namespace brave_sync { -namespace prefs { -class Prefs; -} // namespace prefs -} // namespace brave_sync - -namespace syncer { -class Syncer; -} // namespace syncer - -#include "../../../../components/browser_sync/profile_sync_service.h" diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index c879561e4f17..d1374364d461 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -85,6 +85,8 @@ source_set("brave_sync") { sources = [ "brave_sync_service.cc", "brave_sync_service.h", + "brave_profile_sync_service.cc", + "brave_profile_sync_service.h", "brave_sync_service_observer.h", ] diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc new file mode 100644 index 000000000000..5369fb0ba54b --- /dev/null +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -0,0 +1,768 @@ +/* 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.h" + +#include "base/bind.h" +#include "base/strings/utf_string_conversions.h" +#include "brave/components/brave_sync/values_conv.h" +#include "brave/components/brave_sync/brave_sync_prefs.h" +#include "brave/components/brave_sync/brave_sync_service_observer.h" +#include "brave/components/brave_sync/jslib_const.h" +#include "brave/components/brave_sync/jslib_messages.h" +#include "brave/components/brave_sync/settings.h" +#include "brave/components/brave_sync/sync_devices.h" +#include "brave/components/brave_sync/tools.h" +#include "chrome/browser/sync/chrome_sync_client.h" +#include "components/bookmarks/browser/bookmark_model.h" +#include "components/signin/core/browser/account_info.h" +#include "components/sync/engine_impl/syncer.h" +#include "content/public/browser/browser_thread.h" +#include "net/base/network_interfaces.h" +#include "ui/base/models/tree_node_iterator.h" + +namespace brave_sync { + +using browser_sync::ChromeSyncClient; +using jslib::SyncRecord; +using jslib_const::kBookmarks; +using jslib_const::kHistorySites; +using jslib_const::kPreferences; +using jslib_const::SyncObjectData_DEVICE; +using jslib_const::SyncRecordType_PREFERENCES; +using jslib::Device; +using tools::IsTimeEmpty; + + +namespace { + +AccountInfo GetDummyAccountInfo() { + AccountInfo account_info; + account_info.account_id = "dummy_account_id"; + return account_info; +} + +void NotifyLogMessage(const std::string& message) { + DLOG(INFO) << message; +} + +std::string GetDeviceName() { + std::string hostname = net::GetHostName(); + if (hostname.empty()) { +#if defined(OS_MACOSX) + hostname = std::string("Mac Desktop"); +#elif defined(OS_LINUX) + hostname = std::string("Linux Desktop"); +#elif defined(OS_WIN) + hostname = std::string("Windows Desktop"); +#endif + } + return hostname; +} + +RecordsListPtr CreateDeviceCreationRecordExtension( + const std::string& deviceName, + const std::string& objectId, + const SyncRecord::Action &action, + const std::string& deviceId) { + RecordsListPtr records = std::make_unique(); + + SyncRecordPtr record = std::make_unique(); + + record->action = action; + record->deviceId = deviceId; + record->objectId = objectId; + record->objectData = SyncObjectData_DEVICE; // "device" + + std::unique_ptr device = std::make_unique(); + device->name = deviceName; + record->SetDevice(std::move(device)); + + records->emplace_back(std::move(record)); + + return records; +} + +const bookmarks::BookmarkNode* FindByObjectId(bookmarks::BookmarkModel* model, + const std::string& object_id) { + ui::TreeNodeIterator + iterator(model->root_node()); + while (iterator.has_next()) { + const bookmarks::BookmarkNode* node = iterator.Next(); + std::string node_object_id; + node->GetMetaInfo("object_id", &node_object_id); + + if (!node_object_id.empty() && object_id == node_object_id) + return node; + } + return nullptr; +} + +std::unique_ptr BookmarkNodeToSyncBookmark( + bookmarks::BookmarkModel* model, + prefs::Prefs* brave_sync_prefs, + const bookmarks::BookmarkNode* node, + const SyncRecord::Action& action) { + if (node->is_permanent_node() || !node->parent()) + return std::unique_ptr(); + + auto record = std::make_unique(); + record->deviceId = brave_sync_prefs->GetThisDeviceId(); + record->objectData = jslib_const::SyncObjectData_BOOKMARK; + + auto bookmark = std::make_unique(); + bookmark->site.location = node->url().spec(); + bookmark->site.title = base::UTF16ToUTF8(node->GetTitledUrlNodeTitle()); + bookmark->site.customTitle = base::UTF16ToUTF8(node->GetTitle()); + // bookmark->site.lastAccessedTime - ignored + bookmark->site.creationTime = node->date_added(); + bookmark->site.favicon = node->icon_url() ? node->icon_url()->spec() : ""; + // Url may have type OTHER_NODE if it is in Deleted Bookmarks + bookmark->isFolder = (node->type() != bookmarks::BookmarkNode::URL && + node->type() != bookmarks::BookmarkNode::OTHER_NODE); + bookmark->hideInToolbar = + node->parent() != model->bookmark_bar_node(); + + std::string object_id; + node->GetMetaInfo("object_id", &object_id); + record->objectId = object_id; + + std::string parent_object_id; + node->parent()->GetMetaInfo("object_id", &parent_object_id); + bookmark->parentFolderObjectId = parent_object_id; + + std::string order; + node->GetMetaInfo("order", &order); + DCHECK(!order.empty()); + bookmark->order = order; + + std::string sync_timestamp; + node->GetMetaInfo("sync_timestamp", &sync_timestamp); + DCHECK(!sync_timestamp.empty()); + + record->syncTimestamp = base::Time::FromJsTime(std::stod(sync_timestamp)); + + record->action = jslib::SyncRecord::Action::A_UPDATE; + + record->SetBookmark(std::move(bookmark)); + + return record; +} + +void CreateResolveList( + const std::vector>& records, + SyncRecordAndExistingList* records_and_existing_objects, + bookmarks::BookmarkModel* model, + prefs::Prefs* brave_sync_prefs) { + for (const auto& record : records) { + auto resolved_record = std::make_unique(); + resolved_record->first = SyncRecord::Clone(*record); + auto* node = FindByObjectId(model, record->objectId); + if (node) { + resolved_record->second = BookmarkNodeToSyncBookmark(model, + brave_sync_prefs, + node, + record->action); + } + + records_and_existing_objects->push_back(std::move(resolved_record)); + } +} + +} // namespace + +BraveProfileSyncService::BraveProfileSyncService(InitParams init_params) + : browser_sync::ProfileSyncService(std::move(init_params)) { + brave_sync_words_ = std::string(); + brave_sync_prefs_ = + std::make_unique( + ProfileSyncService::GetSyncClient()->GetPrefService()); + GetBraveSyncClient()->set_sync_message_handler(this); + + // Moniter syncs prefs required in GetSettingsAndDevices + brave_pref_change_registrar_.Init( + ProfileSyncService::GetSyncClient()->GetPrefService()); + brave_pref_change_registrar_.Add( + prefs::kSyncEnabled, + base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + prefs::kSyncDeviceName, + base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + prefs::kSyncDeviceList, + base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + prefs::kSyncBookmarksEnabled, + base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + prefs::kSyncSiteSettingsEnabled, + base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_pref_change_registrar_.Add( + prefs::kSyncHistoryEnabled, + base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + + if (!brave_sync_prefs_->GetSeed().empty() && + !brave_sync_prefs_->GetThisDeviceName().empty()) { + brave_sync_configured_ = true; + } +} + +void BraveProfileSyncService::OnNudgeSyncCycle( + RecordsListPtr records) { + for (auto& record : *records) { + record->deviceId = brave_sync_prefs_->GetThisDeviceId(); + } + if (!records->empty()) + GetBraveSyncClient()->SendSyncRecords( + jslib_const::SyncRecordType_BOOKMARKS, *records); +} + +BraveProfileSyncService::~BraveProfileSyncService() {} + +void BraveProfileSyncService::OnSetupSyncHaveCode(const std::string& sync_words, + const std::string& device_name) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + if (sync_words.empty()) { + OnSyncSetupError("ERR_SYNC_WRONG_WORDS"); + return; + } + + if (brave_sync_initializing_) { + NotifyLogMessage("currently initializing"); + return; + } + + if (brave_sync_configured_) { + NotifyLogMessage("already configured"); + return; + } + + if (device_name.empty()) + brave_sync_prefs_->SetThisDeviceName(GetDeviceName()); + else + brave_sync_prefs_->SetThisDeviceName(device_name); + brave_sync_initializing_ = true; + + brave_sync_prefs_->SetSyncEnabled(true); + brave_sync_words_ = sync_words; +} + +void BraveProfileSyncService::OnSetupSyncNewToSync( + const std::string& device_name) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + if (brave_sync_initializing_) { + NotifyLogMessage("currently initializing"); + return; + } + + if (brave_sync_configured_) { + NotifyLogMessage("already configured"); + return; + } + + // If the previous attempt was connect to sync chain + // and failed to receive save-init-data + brave_sync_words_.clear(); + + if (device_name.empty()) + brave_sync_prefs_->SetThisDeviceName(GetDeviceName()); + else + brave_sync_prefs_->SetThisDeviceName(device_name); + + brave_sync_initializing_ = true; + + brave_sync_prefs_->SetSyncEnabled(true); +} + +void BraveProfileSyncService::OnDeleteDevice(const std::string& device_id) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + auto sync_devices = brave_sync_prefs_->GetSyncDevices(); + + const SyncDevice *device = sync_devices->GetByDeviceId(device_id); + if (device) { + const std::string device_name = device->name_; + const std::string object_id = device->object_id_; + SendDeviceSyncRecord( + SyncRecord::Action::A_DELETE, device_name, device_id, object_id); + } +} + +void BraveProfileSyncService::OnResetSync() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + auto sync_devices = brave_sync_prefs_->GetSyncDevices(); + + if (sync_devices->size() == 0) { + // Fail safe option + VLOG(2) << "[Sync] " << __func__ << " unexpected zero device size"; + ResetSyncInternal(); + } else { + // We have to send delete record and wait for library deleted response then + // we can reset it by ResetInternal() + const std::string device_id = brave_sync_prefs_->GetThisDeviceId(); + OnDeleteDevice(device_id); + } +} + +void BraveProfileSyncService::GetSettingsAndDevices( + const GetSettingsAndDevicesCallback& callback) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + auto settings = brave_sync_prefs_->GetBraveSyncSettings(); + auto devices = brave_sync_prefs_->GetSyncDevices(); + callback.Run(std::move(settings), std::move(devices)); +} + +void BraveProfileSyncService::GetSyncWords() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + // Ask sync client + std::string seed = brave_sync_prefs_->GetSeed(); + GetBraveSyncClient()->NeedSyncWords(seed); +} + +std::string BraveProfileSyncService::GetSeed() { + return brave_sync_prefs_->GetSeed(); +} + +void BraveProfileSyncService::OnSetSyncEnabled(const bool sync_this_device) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + brave_sync_prefs_->SetSyncEnabled(sync_this_device); +} + +void BraveProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + syncer::ModelTypeSet type_set = + ProfileSyncService::GetSyncUserSettings()->GetChosenDataTypes(); + if (sync_bookmarks) + type_set.Put(syncer::BOOKMARKS); + else + type_set.Remove(syncer::BOOKMARKS); + ProfileSyncService::GetSyncUserSettings()->SetChosenDataTypes(false, + type_set); + brave_sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); +} + +void BraveProfileSyncService::OnSetSyncBrowsingHistory( + const bool sync_browsing_history) { + NOTIMPLEMENTED(); +} + +void BraveProfileSyncService::OnSetSyncSavedSiteSettings( + const bool sync_saved_site_settings) { + NOTIMPLEMENTED(); +} + +void BraveProfileSyncService::BackgroundSyncStarted(bool startup) { + NOTIMPLEMENTED(); +} + +void BraveProfileSyncService::BackgroundSyncStopped(bool shutdown) { + NOTIMPLEMENTED(); +} + +void BraveProfileSyncService::OnSyncDebug(const std::string& message) { + NotifyLogMessage(message); +} + +void BraveProfileSyncService::OnSyncSetupError(const std::string& error) { + if (brave_sync_initializing_) { + brave_sync_prefs_->Clear(); + brave_sync_initializing_ = false; + } + NotifySyncSetupError(error); +} + +void BraveProfileSyncService::OnGetInitData(const std::string& sync_version) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + Uint8Array seed; + if (!brave_sync_words_.empty()) { + VLOG(1) << "[Brave Sync] Init from sync words"; + } else if (!brave_sync_prefs_->GetSeed().empty()) { + seed = Uint8ArrayFromString(brave_sync_prefs_->GetSeed()); + VLOG(1) << "[Brave Sync] Init from prefs"; + } else { + VLOG(1) << "[Brave Sync] Init new chain"; + } + + Uint8Array device_id; + if (!brave_sync_prefs_->GetThisDeviceId().empty()) { + device_id = Uint8ArrayFromString(brave_sync_prefs_->GetThisDeviceId()); + VLOG(1) << "[Brave Sync] Init device id from prefs: " << + StrFromUint8Array(device_id); + } else { + VLOG(1) << "[Brave Sync] Init empty device id"; + } + + DCHECK(!sync_version.empty()); + // TODO(bridiver) - this seems broken because using the version we get back + // from the server (currently v1.4.2) causes things to break. What is the + // the point of having this value? + brave_sync_prefs_->SetApiVersion("0"); + + client_data::Config config; + config.api_version = brave_sync_prefs_->GetApiVersion(); + config.server_url = "https://sync.brave.com"; + config.debug = true; + GetBraveSyncClient()->SendGotInitData(seed, device_id, config, + brave_sync_words_); +} + +void BraveProfileSyncService::OnSaveInitData(const Uint8Array& seed, + const Uint8Array& device_id) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + DCHECK(!brave_sync_initialized_); + // If we are here and brave_sync_initializing_ is false, we have came + // not from OnSetupSyncNewToSync or OnSetupSyncHaveCode. + // One case is we put wrong code words and then restarted before cleared + // kSyncEnabled pref. This should not happen. + DCHECK(brave_sync_initializing_); + + std::string seed_str = StrFromUint8Array(seed); + std::string device_id_str = StrFromUint8Array(device_id); + + std::string prev_seed_str = brave_sync_prefs_->GetPrevSeed(); + + brave_sync_words_.clear(); + DCHECK(!seed_str.empty()); + + if (prev_seed_str == seed_str) { // reconnecting to previous sync chain + brave_sync_prefs_->SetPrevSeed(std::string()); + } else if (!prev_seed_str.empty()) { // connect/create to new sync chain + // bookmark_change_processor_->Reset(true); + brave_sync_prefs_->SetPrevSeed(std::string()); + } else { + // This is not required, because when there is no previous seed, bookmarks + // should not have a metadata. However, this is done by intention, to be + // a remedy for cases when sync had been reset and prev_seed_str had been + // cleared when it shouldn't (brave-browser#3188). + // bookmark_change_processor_->Reset(true); + } + + brave_sync_prefs_->SetSeed(seed_str); + brave_sync_prefs_->SetThisDeviceId(device_id_str); + + brave_sync_configured_ = true; + + brave_sync_initializing_ = false; +} + +void BraveProfileSyncService::OnSyncReady() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + const std::string bookmarks_base_order = + brave_sync_prefs_->GetBookmarksBaseOrder(); + if (bookmarks_base_order.empty()) { + std::string platform = tools::GetPlatformName(); + GetBraveSyncClient()->SendGetBookmarksBaseOrder( + brave_sync_prefs_->GetThisDeviceId(), + platform); + // OnSyncReady will be called by OnSaveBookmarksBaseOrder + return; + } + + bookmarks::BookmarkModel* model = + // TODO(darkdh): find another way to obtain bookmark model + // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 + static_cast( + ProfileSyncService::GetSyncClient())->GetBookmarkModel(); + SetPermanentNodesOrder(model, brave_sync_prefs_->GetBookmarksBaseOrder()); + + DCHECK(false == brave_sync_initialized_); + brave_sync_initialized_ = true; + + ProfileSyncService::GetSyncUserSettings() + ->SetChosenDataTypes(false, syncer::ModelTypeSet()); + OnSetSyncBookmarks(true); + ProfileSyncService::GetSyncUserSettings()->SetSyncRequested(true); +} + +void BraveProfileSyncService::OnGetExistingObjects( + const std::string& category_name, + std::unique_ptr records, + const base::Time &last_record_time_stamp, + const bool is_truncated) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + // TODO(bridiver) - what do we do with is_truncated ? + // It appears to be ignored in b-l + if (!IsTimeEmpty(last_record_time_stamp)) { + brave_sync_prefs_->SetLatestRecordTime(last_record_time_stamp); + } + + if (category_name == kBookmarks) { + auto records_and_existing_objects = + std::make_unique(); + CreateResolveList( + *records.get(), records_and_existing_objects.get(), + // TODO(darkdh): find another way to obtain bookmark model + // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 + static_cast( + ProfileSyncService::GetSyncClient())->GetBookmarkModel(), + brave_sync_prefs_.get()); + GetBraveSyncClient()->SendResolveSyncRecords( + category_name, std::move(records_and_existing_objects)); + } +} + +void BraveProfileSyncService::OnResolvedSyncRecords( + const std::string& category_name, + std::unique_ptr records) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + if (category_name == jslib_const::kPreferences) { + OnResolvedPreferences(*records.get()); + } else if (category_name == kBookmarks) { + // Send records to syncer + if (get_record_cb_) + ProfileSyncService::GetSyncEngine()->DispatchGetRecordsCallback( + get_record_cb_, std::move(records)); + SignalWaitableEvent(); + } else if (category_name == kHistorySites) { + NOTIMPLEMENTED(); + } +} + +void BraveProfileSyncService::OnDeletedSyncUser() { + NOTIMPLEMENTED(); +} + +void BraveProfileSyncService::OnDeleteSyncSiteSettings() { + NOTIMPLEMENTED(); +} + +void BraveProfileSyncService::OnSaveBookmarksBaseOrder( + const std::string& order) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + DCHECK(!order.empty()); + brave_sync_prefs_->SetBookmarksBaseOrder(order); + OnSyncReady(); +} + +void BraveProfileSyncService::OnSyncWordsPrepared(const std::string& words) { + NotifyHaveSyncWords(words); +} + +int BraveProfileSyncService::GetDisableReasons() const { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + + if (IsBraveSyncEnabled()) + return syncer::SyncService::DISABLE_REASON_NONE; + return ProfileSyncService::GetDisableReasons(); +} + +CoreAccountInfo BraveProfileSyncService::GetAuthenticatedAccountInfo() const { + return GetDummyAccountInfo(); +} + +bool BraveProfileSyncService::IsAuthenticatedAccountPrimary() const { + return true; +} + +void BraveProfileSyncService::Shutdown() { + SignalWaitableEvent(); + browser_sync::ProfileSyncService::Shutdown(); +} + +void BraveProfileSyncService::NotifySyncSetupError(const std::string& error) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + for (auto& observer : BraveSyncService::observers_) + observer.OnSyncSetupError(this, error); +} + +void BraveProfileSyncService::NotifySyncStateChanged() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + for (auto& observer : BraveSyncService::observers_) + observer.OnSyncStateChanged(this); +} + +void BraveProfileSyncService::NotifyHaveSyncWords( + const std::string& sync_words) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + for (auto& observer : BraveSyncService::observers_) + observer.OnHaveSyncWords(this, sync_words); +} + +void BraveProfileSyncService::ResetSyncInternal() { + brave_sync_prefs_->SetPrevSeed(brave_sync_prefs_->GetSeed()); + + brave_sync_prefs_->Clear(); + + brave_sync_configured_ = false; + brave_sync_initialized_ = false; + + brave_sync_prefs_->SetSyncEnabled(false); +} + +void BraveProfileSyncService::SetPermanentNodesOrder( + bookmarks::BookmarkModel* model, + const std::string& base_order) { + std::string order; + model->bookmark_bar_node()->GetMetaInfo("order", &order); + if (order.empty()) { + bookmarks::BookmarkNode* mutable_bookmark_bar_node = + const_cast(model->bookmark_bar_node()); + model->SetNodeMetaInfo(mutable_bookmark_bar_node, "order", + base_order + "1"); + } + order.clear(); + model->other_node()->GetMetaInfo("order", &order); + if (order.empty()) { + bookmarks::BookmarkNode* mutable_other_node = + const_cast(model->other_node()); + model->SetNodeMetaInfo(mutable_other_node, "order", base_order + "2"); + } +} + +void BraveProfileSyncService::FetchSyncRecords(const bool bookmarks, + const bool history, + const bool preferences, + int max_records) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK(bookmarks || history || preferences); + if (!(bookmarks || history || preferences)) { + return; + } + + std::vector category_names; + if (history) { + category_names.push_back(kHistorySites); // "HISTORY_SITES"; + } + if (bookmarks) { + category_names.push_back(kBookmarks); // "BOOKMARKS"; + } + if (preferences) { + category_names.push_back(kPreferences); // "PREFERENCES"; + } + + brave_sync_prefs_->SetLastFetchTime(base::Time::Now()); + + base::Time start_at_time = brave_sync_prefs_->GetLatestRecordTime(); + GetBraveSyncClient()->SendFetchSyncRecords( + category_names, + start_at_time, + max_records); +} + +void BraveProfileSyncService::SendCreateDevice() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + + std::string device_name = brave_sync_prefs_->GetThisDeviceName(); + std::string object_id = tools::GenerateObjectId(); + std::string device_id = brave_sync_prefs_->GetThisDeviceId(); + CHECK(!device_id.empty()); + + SendDeviceSyncRecord( + SyncRecord::Action::A_CREATE, + device_name, + device_id, + object_id); +} + +void BraveProfileSyncService::SendDeviceSyncRecord( + const int action, + const std::string& device_name, + const std::string& device_id, + const std::string& object_id) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + RecordsListPtr records = CreateDeviceCreationRecordExtension( + device_name, + object_id, + static_cast(action), + device_id); + GetBraveSyncClient()->SendSyncRecords( + SyncRecordType_PREFERENCES, *records); +} + +void BraveProfileSyncService::OnResolvedPreferences( + const RecordsList& records) { + const std::string this_device_id = brave_sync_prefs_->GetThisDeviceId(); + bool this_device_deleted = false; + bool contains_only_one_device = false; + + auto sync_devices = brave_sync_prefs_->GetSyncDevices(); + for (const auto &record : records) { + DCHECK(record->has_device() || record->has_sitesetting()); + if (record->has_device()) { + bool actually_merged = false; + sync_devices->Merge( + SyncDevice(record->GetDevice().name, + record->objectId, + record->deviceId, + record->syncTimestamp.ToJsTime()), + record->action, + &actually_merged); + this_device_deleted = this_device_deleted || + (record->deviceId == this_device_id && + record->action == SyncRecord::Action::A_DELETE && + actually_merged); + contains_only_one_device = sync_devices->size() < 2 && + record->action == SyncRecord::Action::A_DELETE && + actually_merged; + } + } // for each device + + brave_sync_prefs_->SetSyncDevices(*sync_devices); + + if (this_device_deleted) { + ResetSyncInternal(); + } else if (contains_only_one_device) { + // We see amount of devices had been decreased to 1 and it is not this + // device had been deleted. So call OnResetSync which will send DELETE + // record for this device + OnResetSync(); + } +} + +void BraveProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { + if (pref == prefs::kSyncEnabled) { + GetBraveSyncClient()->OnSyncEnabledChanged(); + if (!brave_sync_prefs_->GetSyncEnabled()) { + brave_sync_initialized_ = false; + ProfileSyncService::GetSyncUserSettings()->SetSyncRequested(false); + } + } + NotifySyncStateChanged(); +} + +BraveSyncClient* BraveProfileSyncService::GetBraveSyncClient() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + return ProfileSyncService::GetSyncClient()->GetBraveSyncClient(); +} + +bool BraveProfileSyncService::IsBraveSyncEnabled() const{ + return brave_sync_prefs_->GetSyncEnabled(); +} + +void BraveProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, + base::WaitableEvent* wevent) { + if (IsTimeEmpty(brave_sync_prefs_->GetLastFetchTime())) + SendCreateDevice(); + GetBraveSyncClient()->SendFetchSyncDevices(); + + if (!brave_sync_initialized_) { + wevent->Signal(); + return; + } + + get_record_cb_ = cb; + wevent_ = wevent; + + const bool bookmarks = brave_sync_prefs_->GetSyncBookmarksEnabled(); + const bool history = brave_sync_prefs_->GetSyncHistoryEnabled(); + const bool preferences = brave_sync_prefs_->GetSyncSiteSettingsEnabled(); + FetchSyncRecords(bookmarks, history, preferences, 1000); +} + +void BraveProfileSyncService::SignalWaitableEvent() { + if (wevent_) { + wevent_->Signal(); + wevent_ = nullptr; + } +} + +} // namespace brave_sync diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h new file mode 100644 index 000000000000..de4aaef9949a --- /dev/null +++ b/components/brave_sync/brave_profile_sync_service.h @@ -0,0 +1,126 @@ +/* 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_BRAVE_PROFILE_SYNC_SERVICE_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_H_ + +#include "brave/components/brave_sync/brave_sync_service.h" +#include "brave/components/brave_sync/client/brave_sync_client.h" +#include "brave/components/brave_sync/jslib_messages_fwd.h" +#include "components/browser_sync/profile_sync_service.h" + +namespace brave_sync { +namespace prefs { +class Prefs; +} // namespace prefs + +class BraveProfileSyncService : public browser_sync::ProfileSyncService, + public BraveSyncService, + public SyncMessageHandler { + public: + explicit BraveProfileSyncService(InitParams init_params); + + ~BraveProfileSyncService() override; + + // BraveSyncService implementation + void OnSetupSyncHaveCode(const std::string& sync_words, + const std::string& device_name) override; + void OnSetupSyncNewToSync(const std::string& device_name) override; + void OnDeleteDevice(const std::string& device_id) override; + void OnResetSync() override; + void GetSettingsAndDevices( + const GetSettingsAndDevicesCallback& callback) override; + void GetSyncWords() override; + std::string GetSeed() override; + void OnSetSyncEnabled(const bool sync_this_device) override; + void OnSetSyncBookmarks(const bool sync_bookmarks) override; + void OnSetSyncBrowsingHistory(const bool sync_browsing_history) override; + void OnSetSyncSavedSiteSettings(const bool sync_saved_site_settings) override; + + // SyncMessageHandler implementation + void BackgroundSyncStarted(bool startup) override; + void BackgroundSyncStopped(bool shutdown) override; + void OnSyncDebug(const std::string& message) override; + void OnSyncSetupError(const std::string& error) override; + void OnGetInitData(const std::string& sync_version) override; + void OnSaveInitData(const brave_sync::Uint8Array& seed, + const brave_sync::Uint8Array& device_id) override; + void OnSyncReady() override; + void OnGetExistingObjects(const std::string& category_name, + std::unique_ptr records, + const base::Time &last_record_time_stamp, + const bool is_truncated) override; + void OnResolvedSyncRecords( + const std::string& category_name, + std::unique_ptr records) override; + void OnDeletedSyncUser() override; + void OnDeleteSyncSiteSettings() override; + void OnSaveBookmarksBaseOrder(const std::string& order) override; + void OnSyncWordsPrepared(const std::string& words) override; + + // syncer::SyncService implementation + int GetDisableReasons() const override; + CoreAccountInfo GetAuthenticatedAccountInfo() const override; + bool IsAuthenticatedAccountPrimary() const override; + + // KeyedService implementation. This must be called exactly + // once (before this object is destroyed). + void Shutdown() override; + + brave_sync::BraveSyncClient* GetBraveSyncClient() override; + + private: + + bool IsBraveSyncEnabled() const override; + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; + void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, + base::WaitableEvent* wevent) override; + void SignalWaitableEvent(); + void FetchSyncRecords(const bool bookmarks, const bool history, + const bool preferences, int max_records); + void SendCreateDevice(); + void SendDeviceSyncRecord(const int action, + const std::string& device_name, + const std::string& device_id, + const std::string& object_id); + void OnResolvedPreferences(const brave_sync::RecordsList& records); + void OnBraveSyncPrefsChanged(const std::string& pref); + void NotifySyncSetupError(const std::string& error); + void NotifySyncStateChanged(); + void NotifyHaveSyncWords(const std::string& sync_words); + + void ResetSyncInternal(); + + void SetPermanentNodesOrder(bookmarks::BookmarkModel* model, + const std::string& base_order); + + std::unique_ptr brave_sync_prefs_; + // True when is in active sync chain + bool brave_sync_configured_ = false; + + // True if we have received SyncReady from JS lib + bool brave_sync_initialized_ = false; + + // Prevent two sequential calls OnSetupSyncHaveCode or OnSetupSyncNewToSync + // while being initializing + bool brave_sync_initializing_ = false; + + std::string brave_sync_words_; + + brave_sync::GetRecordsCallback get_record_cb_; + base::WaitableEvent* wevent_; + + // Registrar used to monitor the brave_profile prefs. + PrefChangeRegistrar brave_pref_change_registrar_; + + // Used to ensure that certain operations are performed on the sequence that + // this object was created on. + SEQUENCE_CHECKER(sequence_checker_); + + DISALLOW_COPY_AND_ASSIGN(BraveProfileSyncService); +}; +} // namespace brave_sync + +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_H_ diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch new file mode 100644 index 000000000000..d9fd9f37abdd --- /dev/null +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc +index 0aa70dfd168a13b85dc09b784624f686c4026177..0f69ff3a4f8e66626781b740ea27edfa68dbfea3 100644 +--- a/chrome/browser/sync/profile_sync_service_factory.cc ++++ b/chrome/browser/sync/profile_sync_service_factory.cc +@@ -254,7 +254,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( + : ProfileSyncService::MANUAL_START; + } + +- auto pss = std::make_unique(std::move(init_params)); ++ auto pss = std::make_unique(std::move(init_params)); + pss->Initialize(); + return pss.release(); + } diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.h.patch b/patches/chrome-browser-sync-profile_sync_service_factory.h.patch new file mode 100644 index 000000000000..096eb17c5598 --- /dev/null +++ b/patches/chrome-browser-sync-profile_sync_service_factory.h.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/sync/profile_sync_service_factory.h b/chrome/browser/sync/profile_sync_service_factory.h +index ccbf83240e4fd135d1c8f3cf7a451d78b9a3ad90..02d7bdf45ec6bc557ee5252a2847be06b222bfb1 100644 +--- a/chrome/browser/sync/profile_sync_service_factory.h ++++ b/chrome/browser/sync/profile_sync_service_factory.h +@@ -38,6 +38,8 @@ class ProfileSyncServiceFactory : public BrowserContextKeyedServiceFactory { + // absolutely necessary! Prefer GetForProfile instead. + static browser_sync::ProfileSyncService* GetAsProfileSyncServiceForProfile( + Profile* profile); ++ static brave_sync::BraveProfileSyncService* ++ GetAsBraveProfileSyncServiceForProfile(Profile* profile); + + // Returns whether a SyncService has already been created for the profile. + // Note that GetForProfile will create the service if it doesn't exist yet. diff --git a/patches/components-browser_sync-profile_sync_service.cc.patch b/patches/components-browser_sync-profile_sync_service.cc.patch index 1a54eaebf135..506b3f8838bc 100644 --- a/patches/components-browser_sync-profile_sync_service.cc.patch +++ b/patches/components-browser_sync-profile_sync_service.cc.patch @@ -1,17 +1,8 @@ diff --git a/components/browser_sync/profile_sync_service.cc b/components/browser_sync/profile_sync_service.cc -index 787e2d24941cbaa469373ed5baad14d1ac9f3722..30f2983ad798474de49046914dc060faaa3faf1d 100644 +index 787e2d24941cbaa469373ed5baad14d1ac9f3722..f8d2fa4e53602d61fb777d113489af5413a11d0a 100644 --- a/components/browser_sync/profile_sync_service.cc +++ b/components/browser_sync/profile_sync_service.cc -@@ -184,6 +184,8 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) - DCHECK(sync_client_); - DCHECK(IsLocalSyncEnabled() || identity_manager_ != nullptr); - -+ BraveSyncSetup(); -+ - // If Sync is disabled via command line flag, then ProfileSyncService - // shouldn't be instantiated. - DCHECK(switches::IsSyncAllowedByFlag()); -@@ -480,6 +482,8 @@ void ProfileSyncService::StartUpSlowEngineComponents() { +@@ -480,6 +480,8 @@ void ProfileSyncService::StartUpSlowEngineComponents() { ->GetSyncUserAgent(); params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); params.credentials = auth_manager_->GetCredentials(); @@ -20,35 +11,3 @@ index 787e2d24941cbaa469373ed5baad14d1ac9f3722..30f2983ad798474de49046914dc060fa DCHECK(!params.credentials.account_id.empty() || IsLocalSyncEnabled()); if (!base::FeatureList::IsEnabled(switches::kSyncE2ELatencyMeasurement)) { invalidation::InvalidationService* invalidator = -@@ -550,6 +554,8 @@ void ProfileSyncService::Shutdown() { - DCHECK(!observers_.might_have_observers()); - - auth_manager_.reset(); -+ -+ SignalWaitableEvent(); - - if (sync_thread_) - sync_thread_->Stop(); -@@ -663,6 +669,7 @@ int ProfileSyncService::GetDisableReasons() const { - DCHECK(switches::IsSyncAllowedByFlag()); - - int result = DISABLE_REASON_NONE; -+ if (IsBraveSyncEnabled()) return result; - if (!user_settings_->IsSyncAllowedByPlatform()) { - result = result | DISABLE_REASON_PLATFORM_OVERRIDE; - } -@@ -1753,12 +1760,12 @@ void ProfileSyncService::GetAllNodes( - - CoreAccountInfo ProfileSyncService::GetAuthenticatedAccountInfo() const { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); -- return auth_manager_->GetActiveAccountInfo().account_info; -+ return GetDummyAccountInfo(); - } - - bool ProfileSyncService::IsAuthenticatedAccountPrimary() const { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); -- return auth_manager_->GetActiveAccountInfo().is_primary; -+ return true; - } - - void ProfileSyncService::SetInvalidationsForSessionsEnabled(bool enabled) { diff --git a/patches/components-browser_sync-profile_sync_service.h.patch b/patches/components-browser_sync-profile_sync_service.h.patch index 7ed40f671f1e..294143a38d8c 100644 --- a/patches/components-browser_sync-profile_sync_service.h.patch +++ b/patches/components-browser_sync-profile_sync_service.h.patch @@ -1,106 +1,29 @@ diff --git a/components/browser_sync/profile_sync_service.h b/components/browser_sync/profile_sync_service.h -index 6c01395b954ac146084865b0268992f277b4914c..c23fc377beaebcef2a894e8c4e2f9f76e77d58d6 100644 +index 6c01395b954ac146084865b0268992f277b4914c..680c8dc34f82925f51a9d0c0ecc8137f91baa10f 100644 --- a/components/browser_sync/profile_sync_service.h +++ b/components/browser_sync/profile_sync_service.h -@@ -137,7 +137,9 @@ class ProfileSyncService : public syncer::SyncService, - public syncer::SyncPrefObserver, - public syncer::DataTypeManagerObserver, - public syncer::UnrecoverableErrorHandler, -- public identity::IdentityManager::Observer { -+ public identity::IdentityManager::Observer, -+ public brave_sync::BraveSyncService, -+ public brave_sync::SyncMessageHandler { - public: - // If AUTO_START, sync will set IsFirstSetupComplete() automatically and sync - // will begin syncing without the user needing to confirm sync settings. -@@ -346,6 +348,42 @@ class ProfileSyncService : public syncer::SyncService, +@@ -346,6 +346,15 @@ class ProfileSyncService : public syncer::SyncService, syncer::SyncClient* GetSyncClientForTest(); -+ //TODO(darkdh): subclass ProfileSyncService -+ brave_sync::BraveSyncClient* GetBraveSyncClient() override; -+ // BraveSyncService messages from UI -+ void OnSetupSyncHaveCode(const std::string& sync_words, -+ const std::string& device_name) override; -+ void OnSetupSyncNewToSync(const std::string& device_name) override; -+ void OnDeleteDevice(const std::string& device_id) override; -+ void OnResetSync() override; -+ void GetSettingsAndDevices(const GetSettingsAndDevicesCallback& callback) override; -+ void GetSyncWords() override; -+ std::string GetSeed() override; -+ void OnSetSyncEnabled(const bool sync_this_device) override; -+ void OnSetSyncBookmarks(const bool sync_bookmarks) override; -+ void OnSetSyncBrowsingHistory(const bool sync_browsing_history) override; -+ void OnSetSyncSavedSiteSettings(const bool sync_saved_site_settings) override; -+ -+ // SyncMessageHandler overrides -+ void BackgroundSyncStarted(bool startup) override; -+ void BackgroundSyncStopped(bool shutdown) override; -+ void OnSyncDebug(const std::string& message) override; -+ void OnSyncSetupError(const std::string& error) override; -+ void OnGetInitData(const std::string& sync_version) override; -+ void OnSaveInitData(const brave_sync::Uint8Array& seed, -+ const brave_sync::Uint8Array& device_id) override; -+ void OnSyncReady() override; -+ void OnGetExistingObjects(const std::string& category_name, -+ std::unique_ptr records, -+ const base::Time &last_record_time_stamp, -+ const bool is_truncated) override; -+ void OnResolvedSyncRecords(const std::string& category_name, -+ std::unique_ptr records) override; -+ void OnDeletedSyncUser() override; -+ void OnDeleteSyncSiteSettings() override; -+ void OnSaveBookmarksBaseOrder(const std::string& order) override; -+ void OnSyncWordsPrepared(const std::string& words) override; ++ protected: ++ syncer::SyncClient* GetSyncClient(); ++ syncer::SyncUserSettings* GetSyncUserSettings(); ++ syncer::SyncEngine* GetSyncEngine(); ++ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); ++ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, ++ base::WaitableEvent* wevent); ++ virtual bool IsBraveSyncEnabled() const; + private: // Passed as an argument to StopImpl to control whether or not the sync // engine should clear its data directory when it shuts down. See StopImpl -@@ -465,6 +503,47 @@ class ProfileSyncService : public syncer::SyncService, - // Called by SyncServiceCrypto when a passphrase is required or accepted. - void ReconfigureDueToPassphrase(syncer::ConfigureReason reason); +@@ -355,6 +364,8 @@ class ProfileSyncService : public syncer::SyncService, + CLEAR_DATA, + }; -+ bool IsBraveSyncEnabled() const; -+ void BraveSyncSetup(); + void BraveEngineParamsInit(syncer::SyncEngine::InitParams*); -+ void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, -+ base::WaitableEvent* wevent); -+ void SignalWaitableEvent(); -+ void FetchSyncRecords(const bool bookmarks, const bool history, -+ const bool preferences, int max_records); -+ void SendCreateDevice(); -+ void SendDeviceSyncRecord(const int action, -+ const std::string& device_name, -+ const std::string& device_id, -+ const std::string& object_id); -+ void OnResolvedPreferences(const brave_sync::RecordsList& records); -+ void OnBraveSyncPrefsChanged(const std::string& pref); -+ void NotifySyncSetupError(const std::string& error); -+ void NotifySyncStateChanged(); -+ void NotifyHaveSyncWords(const std::string& sync_words); -+ -+ void ResetSyncInternal(); -+ -+ std::unique_ptr brave_sync_prefs_; -+ // True when is in active sync chain -+ bool brave_sync_configured_ = false; -+ -+ // True if we have received SyncReady from JS lib -+ bool brave_sync_initialized_ = false; + -+ // Prevent two sequential calls OnSetupSyncHaveCode or OnSetupSyncNewToSync -+ // while being initializing -+ bool brave_sync_initializing_ = false; -+ -+ std::string brave_sync_words_; -+ -+ brave_sync::GetRecordsCallback get_record_cb_; -+ base::WaitableEvent* wevent_; -+ -+ // Registrar used to monitor the brave_profile prefs. -+ PrefChangeRegistrar brave_pref_change_registrar_; -+ - // This profile's SyncClient, which abstracts away non-Sync dependencies and - // the Sync API component factory. - const std::unique_ptr sync_client_; + // Shorthand for user_settings_.IsFirstSetupComplete(). + bool IsFirstSetupComplete() const; + From 4972a86d4d00c6dedcf4e9d5a2eec12ac0957316 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 6 May 2019 21:55:02 -0700 Subject: [PATCH 13/73] Fix DCHECK failure because of lacking permanent nodes order when launching from legacy sync profile --- .../brave_sync/brave_profile_sync_service.cc | 54 ++++++++++++------- .../brave_sync/brave_profile_sync_service.h | 16 +++++- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 5369fb0ba54b..a01cbaca1a04 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -13,6 +13,7 @@ #include "brave/components/brave_sync/jslib_const.h" #include "brave/components/brave_sync/jslib_messages.h" #include "brave/components/brave_sync/settings.h" +#include "brave/components/brave_sync/syncer_helper.h" #include "brave/components/brave_sync/sync_devices.h" #include "brave/components/brave_sync/tools.h" #include "chrome/browser/sync/chrome_sync_client.h" @@ -208,11 +209,16 @@ BraveProfileSyncService::BraveProfileSyncService(InitParams init_params) prefs::kSyncHistoryEnabled, base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, base::Unretained(this))); + // TODO(darkdh): find another way to obtain bookmark model + // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 + model_ = static_cast( + ProfileSyncService::GetSyncClient())->GetBookmarkModel(); if (!brave_sync_prefs_->GetSeed().empty() && !brave_sync_prefs_->GetThisDeviceName().empty()) { brave_sync_configured_ = true; } + } void BraveProfileSyncService::OnNudgeSyncCycle( @@ -467,12 +473,7 @@ void BraveProfileSyncService::OnSyncReady() { return; } - bookmarks::BookmarkModel* model = - // TODO(darkdh): find another way to obtain bookmark model - // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 - static_cast( - ProfileSyncService::GetSyncClient())->GetBookmarkModel(); - SetPermanentNodesOrder(model, brave_sync_prefs_->GetBookmarksBaseOrder()); + SetPermanentNodesOrder(brave_sync_prefs_->GetBookmarksBaseOrder()); DCHECK(false == brave_sync_initialized_); brave_sync_initialized_ = true; @@ -500,10 +501,7 @@ void BraveProfileSyncService::OnGetExistingObjects( std::make_unique(); CreateResolveList( *records.get(), records_and_existing_objects.get(), - // TODO(darkdh): find another way to obtain bookmark model - // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 - static_cast( - ProfileSyncService::GetSyncClient())->GetBookmarkModel(), + model_, brave_sync_prefs_.get()); GetBraveSyncClient()->SendResolveSyncRecords( category_name, std::move(records_and_existing_objects)); @@ -599,25 +597,27 @@ void BraveProfileSyncService::ResetSyncInternal() { } void BraveProfileSyncService::SetPermanentNodesOrder( - bookmarks::BookmarkModel* model, const std::string& base_order) { + DCHECK(model_); + DCHECK(!base_order.empty()); std::string order; - model->bookmark_bar_node()->GetMetaInfo("order", &order); + model_->bookmark_bar_node()->GetMetaInfo("order", &order); if (order.empty()) { bookmarks::BookmarkNode* mutable_bookmark_bar_node = - const_cast(model->bookmark_bar_node()); - model->SetNodeMetaInfo(mutable_bookmark_bar_node, "order", - base_order + "1"); + const_cast(model_->bookmark_bar_node()); + model_->SetNodeMetaInfo(mutable_bookmark_bar_node, "order", + base_order + "1"); } order.clear(); - model->other_node()->GetMetaInfo("order", &order); + model_->other_node()->GetMetaInfo("order", &order); if (order.empty()) { bookmarks::BookmarkNode* mutable_other_node = - const_cast(model->other_node()); - model->SetNodeMetaInfo(mutable_other_node, "order", base_order + "2"); + const_cast(model_->other_node()); + model_->SetNodeMetaInfo(mutable_other_node, "order", base_order + "2"); } } + void BraveProfileSyncService::FetchSyncRecords(const bool bookmarks, const bool history, const bool preferences, @@ -734,6 +734,24 @@ BraveSyncClient* BraveProfileSyncService::GetBraveSyncClient() { return ProfileSyncService::GetSyncClient()->GetBraveSyncClient(); } +void BraveProfileSyncService::OnEngineInitialized( + syncer::ModelTypeSet initial_types, + const syncer::WeakHandle& js_backend, + const syncer::WeakHandle& + debug_info_listener, + const std::string& cache_guid, + const std::string& session_name, + const std::string& birthday, + const std::string& bag_of_chips, + bool success) { + // For launching from legacy sync profile + SetPermanentNodesOrder(brave_sync_prefs_->GetBookmarksBaseOrder()); + ProfileSyncService::OnEngineInitialized(initial_types, js_backend, + debug_info_listener, cache_guid, + session_name, birthday, bag_of_chips, + success); +} + bool BraveProfileSyncService::IsBraveSyncEnabled() const{ return brave_sync_prefs_->GetSyncEnabled(); } diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index de4aaef9949a..a6081e33aa71 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -72,6 +72,17 @@ class BraveProfileSyncService : public browser_sync::ProfileSyncService, brave_sync::BraveSyncClient* GetBraveSyncClient() override; private: + // SyncEngineHost implementation. + void OnEngineInitialized( + syncer::ModelTypeSet initial_types, + const syncer::WeakHandle& js_backend, + const syncer::WeakHandle& + debug_info_listener, + const std::string& cache_guid, + const std::string& session_name, + const std::string& birthday, + const std::string& bag_of_chips, + bool success) override; bool IsBraveSyncEnabled() const override; void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; @@ -93,8 +104,7 @@ class BraveProfileSyncService : public browser_sync::ProfileSyncService, void ResetSyncInternal(); - void SetPermanentNodesOrder(bookmarks::BookmarkModel* model, - const std::string& base_order); + void SetPermanentNodesOrder(const std::string& base_order); std::unique_ptr brave_sync_prefs_; // True when is in active sync chain @@ -115,6 +125,8 @@ class BraveProfileSyncService : public browser_sync::ProfileSyncService, // Registrar used to monitor the brave_profile prefs. PrefChangeRegistrar brave_pref_change_registrar_; + bookmarks::BookmarkModel* model_ = nullptr; + // Used to ensure that certain operations are performed on the sequence that // this object was created on. SEQUENCE_CHECKER(sequence_checker_); From 64632505ddb229fcc5524699a957e971baf2a98d Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 7 May 2019 15:01:42 -0700 Subject: [PATCH 14/73] Handle same index from different devices by order --- .../sync/engine_impl/get_updates_processor.cc | 21 +++---------------- components/brave_sync/syncer_helper.cc | 21 +++++++++++++++++++ components/brave_sync/syncer_helper.h | 5 +++++ ...okmarks-bookmark_change_processor.cc.patch | 10 +++++++-- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index 66802d11b69d..56a39ce09c7c 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -33,16 +33,6 @@ static const char kSyncedBookmarksFolderName[] = "Synced Bookmarks"; // referred to as top level enities. static const char kRootParentTag[] = "0"; -uint64_t GetIndexByOrder(const std::string& record_order) { - uint64_t index = 0; - char last_ch = record_order.back(); - bool result = base::StringToUint64(std::string(&last_ch), &index); - --index; - DCHECK(index >= 0); - DCHECK(result); - return index; -} - void AddBookmarkSpecifics(sync_pb::EntitySpecifics* specifics, const SyncRecord* record) { DCHECK(specifics); @@ -175,14 +165,9 @@ void AddBookmarkNode(sync_pb::SyncEntity* entity, const SyncRecord* record) { MigrateFromLegacySync(entity); - // TODO(darkdh): migrate to UniquePosition - entity->set_position_in_parent(GetIndexByOrder(bookmark_record.order)); - std::string suffix = GenerateSyncableBookmarkHash(entity->originator_cache_guid(), - entity->originator_client_item_id()); - UniquePosition uniquePosition = UniquePosition::FromInt64(GetIndexByOrder(bookmark_record.order), - suffix); - auto* unique_position_pb = entity->mutable_unique_position(); - *unique_position_pb = uniquePosition.ToProto(); + // Position will be calculated later by order comparison + // TODO(darkdh): dealing with USS remote changes handler + entity->set_position_in_parent(0); if (record->action == SyncRecord::Action::A_DELETE) entity->set_deleted(true); else diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index 4bf60a1654e2..129d65134ae7 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -6,6 +6,7 @@ #include "brave/components/brave_sync/syncer_helper.h" #include "base/strings/string_number_conversions.h" +#include "brave/components/brave_sync/bookmark_order_util.h" #include "brave/components/brave_sync/tools.h" #include "components/bookmarks/browser/bookmark_model.h" @@ -78,4 +79,24 @@ void AddBraveMetaInfo( model->SetNodeMetaInfo(node, "sync_timestamp", sync_timestamp); } +uint64_t GetIndexByOrder(const bookmarks::BookmarkNode* parent, + const bookmarks::BookmarkNode* src) { + int index = 0; + std::string src_order; + src->GetMetaInfo("order", &src_order); + DCHECK(!src_order.empty()); + while (index < parent->child_count()) { + const bookmarks::BookmarkNode* node = parent->GetChild(index); + std::string node_order; + node->GetMetaInfo("order", &node_order); + + if (!node_order.empty() && + CompareOrder(src_order, node_order)) + return index; + + ++index; + } + return index; +} + } // namespace brave_sync diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h index 1334c4b68e60..d24f61ad092b 100644 --- a/components/brave_sync/syncer_helper.h +++ b/components/brave_sync/syncer_helper.h @@ -6,6 +6,8 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ #define BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ +#include + namespace bookmarks { class BookmarkModel; class BookmarkNode; @@ -17,6 +19,9 @@ void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, bookmarks::BookmarkModel* bookmark_model, bool has_new_parent); +uint64_t GetIndexByOrder(const bookmarks::BookmarkNode* parent, + const bookmarks::BookmarkNode* src); + } // namespace brave_sync #endif // BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 7fa7a15a5ba9..4aa4b69fd127 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..edb2a70362e72bac1bc3edae59a3e8b43a4367f8 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..cce316290140855ea9cccd3eb152850a61435407 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -81,7 +81,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..edb2a70362e72bac1bc3edae59a3e8b4 if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -718,6 +739,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -718,10 +739,13 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } @@ -90,3 +90,9 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..edb2a70362e72bac1bc3edae59a3e8b4 model_associator_->Associate(dst, src); } +- to_reposition.insert(std::make_pair(src.GetPositionIndex(), dst)); ++ uint64_t index = brave_sync::GetIndexByOrder(dst->parent(), dst); ++ to_reposition.insert(std::make_pair(index, dst)); + bookmark_model_->SetNodeSyncTransactionVersion(dst, model_version); + } + From 05731ecf58e614fcac0e94ae5110ef715fe21568 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 9 May 2019 09:55:10 -0700 Subject: [PATCH 15/73] Set user-chosen sync type only when first time sync setup or migrated from legacy sync. Otherwise, previous sync type will be purged. --- .../brave_sync/brave_profile_sync_service.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index a01cbaca1a04..c4b8b2781854 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -478,10 +478,16 @@ void BraveProfileSyncService::OnSyncReady() { DCHECK(false == brave_sync_initialized_); brave_sync_initialized_ = true; - ProfileSyncService::GetSyncUserSettings() - ->SetChosenDataTypes(false, syncer::ModelTypeSet()); - OnSetSyncBookmarks(true); - ProfileSyncService::GetSyncUserSettings()->SetSyncRequested(true); + syncer::SyncPrefs sync_prefs(ProfileSyncService::GetSyncClient() + ->GetPrefService()); + // first time setup sync or migrated from legacy sync + if (sync_prefs.GetLastSyncedTime().is_null()) { + ProfileSyncService::GetSyncUserSettings() + ->SetChosenDataTypes(false, syncer::ModelTypeSet()); + // default enable bookmark + OnSetSyncBookmarks(true); + ProfileSyncService::GetSyncUserSettings()->SetSyncRequested(true); + } } void BraveProfileSyncService::OnGetExistingObjects( From 4f6ed562f1eb95c204a1fe4b6cbf00893a27f83e Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 9 May 2019 12:17:25 -0700 Subject: [PATCH 16/73] Using MigratedBookmarksVersion >= 2 to check legacy sync migration status so that sync engine only starts after OnSyncReady --- .../browser_sync/profile_sync_service.cc | 5 --- .../brave_sync/brave_profile_sync_service.cc | 41 +++++++------------ .../brave_sync/brave_profile_sync_service.h | 11 ----- ...-browser_sync-profile_sync_service.h.patch | 7 ++-- 4 files changed, 18 insertions(+), 46 deletions(-) diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/browser_sync/profile_sync_service.cc index afbee9d7feca..2442e7005ce3 100644 --- a/chromium_src/components/browser_sync/profile_sync_service.cc +++ b/chromium_src/components/browser_sync/profile_sync_service.cc @@ -32,11 +32,6 @@ syncer::SyncClient* ProfileSyncService::GetSyncClient() { return sync_client_.get(); } -syncer::SyncUserSettings* ProfileSyncService::GetSyncUserSettings() { - DCHECK(user_settings_); - return user_settings_.get(); -} - syncer::SyncEngine* ProfileSyncService::GetSyncEngine() { DCHECK(engine_); return engine_.get(); diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index c4b8b2781854..3691bfc894bf 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -345,12 +345,12 @@ void BraveProfileSyncService::OnSetSyncEnabled(const bool sync_this_device) { void BraveProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); syncer::ModelTypeSet type_set = - ProfileSyncService::GetSyncUserSettings()->GetChosenDataTypes(); + ProfileSyncService::GetUserSettings()->GetChosenDataTypes(); if (sync_bookmarks) type_set.Put(syncer::BOOKMARKS); else type_set.Remove(syncer::BOOKMARKS); - ProfileSyncService::GetSyncUserSettings()->SetChosenDataTypes(false, + ProfileSyncService::GetUserSettings()->SetChosenDataTypes(false, type_set); brave_sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); } @@ -473,20 +473,22 @@ void BraveProfileSyncService::OnSyncReady() { return; } - SetPermanentNodesOrder(brave_sync_prefs_->GetBookmarksBaseOrder()); - DCHECK(false == brave_sync_initialized_); brave_sync_initialized_ = true; + // For launching from legacy sync profile and also brand new profile + if (brave_sync_prefs_->GetMigratedBookmarksVersion() < 2) + SetPermanentNodesOrder(brave_sync_prefs_->GetBookmarksBaseOrder()); + syncer::SyncPrefs sync_prefs(ProfileSyncService::GetSyncClient() ->GetPrefService()); // first time setup sync or migrated from legacy sync if (sync_prefs.GetLastSyncedTime().is_null()) { - ProfileSyncService::GetSyncUserSettings() + ProfileSyncService::GetUserSettings() ->SetChosenDataTypes(false, syncer::ModelTypeSet()); // default enable bookmark OnSetSyncBookmarks(true); - ProfileSyncService::GetSyncUserSettings()->SetSyncRequested(true); + ProfileSyncService::GetUserSettings()->SetSyncRequested(true); } } @@ -554,8 +556,12 @@ void BraveProfileSyncService::OnSyncWordsPrepared(const std::string& words) { int BraveProfileSyncService::GetDisableReasons() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (IsBraveSyncEnabled()) + // legacy sync only support bookmark sync so we have to wait for migration + // complete before enable sync engine + if (IsBraveSyncEnabled() && + brave_sync_prefs_->GetMigratedBookmarksVersion() >= 2) return syncer::SyncService::DISABLE_REASON_NONE; + // kSyncManaged is disabled by us return ProfileSyncService::GetDisableReasons(); } @@ -621,6 +627,7 @@ void BraveProfileSyncService::SetPermanentNodesOrder( const_cast(model_->other_node()); model_->SetNodeMetaInfo(mutable_other_node, "order", base_order + "2"); } + brave_sync_prefs_->SetMigratedBookmarksVersion(2); } @@ -729,7 +736,7 @@ void BraveProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { GetBraveSyncClient()->OnSyncEnabledChanged(); if (!brave_sync_prefs_->GetSyncEnabled()) { brave_sync_initialized_ = false; - ProfileSyncService::GetSyncUserSettings()->SetSyncRequested(false); + ProfileSyncService::GetUserSettings()->SetSyncRequested(false); } } NotifySyncStateChanged(); @@ -740,24 +747,6 @@ BraveSyncClient* BraveProfileSyncService::GetBraveSyncClient() { return ProfileSyncService::GetSyncClient()->GetBraveSyncClient(); } -void BraveProfileSyncService::OnEngineInitialized( - syncer::ModelTypeSet initial_types, - const syncer::WeakHandle& js_backend, - const syncer::WeakHandle& - debug_info_listener, - const std::string& cache_guid, - const std::string& session_name, - const std::string& birthday, - const std::string& bag_of_chips, - bool success) { - // For launching from legacy sync profile - SetPermanentNodesOrder(brave_sync_prefs_->GetBookmarksBaseOrder()); - ProfileSyncService::OnEngineInitialized(initial_types, js_backend, - debug_info_listener, cache_guid, - session_name, birthday, bag_of_chips, - success); -} - bool BraveProfileSyncService::IsBraveSyncEnabled() const{ return brave_sync_prefs_->GetSyncEnabled(); } diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index a6081e33aa71..4480b60c249b 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -72,17 +72,6 @@ class BraveProfileSyncService : public browser_sync::ProfileSyncService, brave_sync::BraveSyncClient* GetBraveSyncClient() override; private: - // SyncEngineHost implementation. - void OnEngineInitialized( - syncer::ModelTypeSet initial_types, - const syncer::WeakHandle& js_backend, - const syncer::WeakHandle& - debug_info_listener, - const std::string& cache_guid, - const std::string& session_name, - const std::string& birthday, - const std::string& bag_of_chips, - bool success) override; bool IsBraveSyncEnabled() const override; void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; diff --git a/patches/components-browser_sync-profile_sync_service.h.patch b/patches/components-browser_sync-profile_sync_service.h.patch index 294143a38d8c..35493eb0217a 100644 --- a/patches/components-browser_sync-profile_sync_service.h.patch +++ b/patches/components-browser_sync-profile_sync_service.h.patch @@ -1,14 +1,13 @@ diff --git a/components/browser_sync/profile_sync_service.h b/components/browser_sync/profile_sync_service.h -index 6c01395b954ac146084865b0268992f277b4914c..680c8dc34f82925f51a9d0c0ecc8137f91baa10f 100644 +index 6c01395b954ac146084865b0268992f277b4914c..734f5623f889f9e576a7e4d5fb39dae0a278290a 100644 --- a/components/browser_sync/profile_sync_service.h +++ b/components/browser_sync/profile_sync_service.h -@@ -346,6 +346,15 @@ class ProfileSyncService : public syncer::SyncService, +@@ -346,6 +346,14 @@ class ProfileSyncService : public syncer::SyncService, syncer::SyncClient* GetSyncClientForTest(); + protected: + syncer::SyncClient* GetSyncClient(); -+ syncer::SyncUserSettings* GetSyncUserSettings(); + syncer::SyncEngine* GetSyncEngine(); + virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); + virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, @@ -18,7 +17,7 @@ index 6c01395b954ac146084865b0268992f277b4914c..680c8dc34f82925f51a9d0c0ecc8137f private: // Passed as an argument to StopImpl to control whether or not the sync // engine should clear its data directory when it shuts down. See StopImpl -@@ -355,6 +364,8 @@ class ProfileSyncService : public syncer::SyncService, +@@ -355,6 +363,8 @@ class ProfileSyncService : public syncer::SyncService, CLEAR_DATA, }; From 73627bbe11e33fde62eaab9e846a9f71698fb2dd Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 9 May 2019 18:06:23 -0700 Subject: [PATCH 17/73] Stub out Control Types --- .../components-sync-base-model_type.h.patch | 12 ++++++++++ ...ync-driver-data_type_manager_impl.cc.patch | 21 +++++++++--------- ...river-glue-sync_backend_host_core.cc.patch | 22 +------------------ 3 files changed, 24 insertions(+), 31 deletions(-) create mode 100644 patches/components-sync-base-model_type.h.patch diff --git a/patches/components-sync-base-model_type.h.patch b/patches/components-sync-base-model_type.h.patch new file mode 100644 index 000000000000..0cf2ba452d09 --- /dev/null +++ b/patches/components-sync-base-model_type.h.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync/base/model_type.h b/components/sync/base/model_type.h +index ca6acf4cdbded08bbd1a69c27827ecf0374a0d11..56f2ae314dfff6d8df3df67ec1edd9b92d1d9d93 100644 +--- a/components/sync/base/model_type.h ++++ b/components/sync/base/model_type.h +@@ -271,6 +271,7 @@ constexpr ModelTypeSet ProxyTypes() { + // - They support custom update application and conflict resolution logic. + // - All change processing occurs on the sync thread (GROUP_PASSIVE). + constexpr ModelTypeSet ControlTypes() { ++ return ModelTypeSet(UNSPECIFIED); + return ModelTypeSet::FromRange(FIRST_CONTROL_MODEL_TYPE, + LAST_CONTROL_MODEL_TYPE); + } diff --git a/patches/components-sync-driver-data_type_manager_impl.cc.patch b/patches/components-sync-driver-data_type_manager_impl.cc.patch index ed027472f6b4..c650c8f8c570 100644 --- a/patches/components-sync-driver-data_type_manager_impl.cc.patch +++ b/patches/components-sync-driver-data_type_manager_impl.cc.patch @@ -1,14 +1,15 @@ diff --git a/components/sync/driver/data_type_manager_impl.cc b/components/sync/driver/data_type_manager_impl.cc -index 9dc9226269704e8a2412634b231a6d54c8bc93f6..b40ac1bbef7ccb7b29022176d11e725a86ac7835 100644 +index 9dc9226269704e8a2412634b231a6d54c8bc93f6..c746e46fdec8c992fcafb87f3e89927979165019 100644 --- a/components/sync/driver/data_type_manager_impl.cc +++ b/components/sync/driver/data_type_manager_impl.cc -@@ -596,7 +596,8 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( - DCHECK(Intersection(downloaded_types_, types_to_journal).Empty()); - DCHECK(Intersection(downloaded_types_, crypto_types).Empty()); - // |downloaded_types_| was already updated to include all enabled types. -- DCHECK(downloaded_types_.HasAll(types_to_download)); -+ // TODO(darkdh): fix Control Type download -+ // DCHECK(downloaded_types_.HasAll(types_to_download)); +@@ -546,8 +546,8 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( + types_to_download.PutAll(clean_types); + types_to_download.RemoveAll(ProxyTypes()); + types_to_download.RemoveAll(CommitOnlyTypes()); +- if (!types_to_download.Empty()) +- types_to_download.Put(NIGORI); ++ // if (!types_to_download.Empty()) ++ // types_to_download.Put(NIGORI); - DVLOG(1) << "Types " << ModelTypeSetToString(types_to_download) - << " added; calling ConfigureDataTypes"; + // TODO(sync): crbug.com/137550. + // It's dangerous to configure types that have progress markers. Types with diff --git a/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch b/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch index 23b00f4ded7e..ac3bae239685 100644 --- a/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch +++ b/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync/driver/glue/sync_backend_host_core.cc b/components/sync/driver/glue/sync_backend_host_core.cc -index 9f962da6b18298365c01e8b9154d39a5c43afc38..3b6e42c0ac23fac125e7e4b57f15d30cdd408a75 100644 +index 9f962da6b18298365c01e8b9154d39a5c43afc38..f020379378dce7a5b27dcf3f807fd191cd2ee0f7 100644 --- a/components/sync/driver/glue/sync_backend_host_core.cc +++ b/components/sync/driver/glue/sync_backend_host_core.cc @@ -353,6 +353,7 @@ void SyncBackendHostCore::DoInitialize(SyncEngine::InitParams params) { @@ -10,23 +10,3 @@ index 9f962da6b18298365c01e8b9154d39a5c43afc38..3b6e42c0ac23fac125e7e4b57f15d30c sync_manager_->Init(&args); base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get()); -@@ -412,12 +413,13 @@ void SyncBackendHostCore::DoInitialProcessControlTypes() { - return; - } - -- if (!sync_manager_->InitialSyncEndedTypes().HasAll(ControlTypes())) { -- LOG(ERROR) << "Failed to download control types"; -- host_.Call(FROM_HERE, -- &SyncEngineImpl::HandleInitializationFailureOnFrontendLoop); -- return; -- } -+ // TODO(darkdh): move device record into control type -+ // if (!sync_manager_->InitialSyncEndedTypes().HasAll(ControlTypes())) { -+ // LOG(ERROR) << "Failed to download control types"; -+ // host_.Call(FROM_HERE, -+ // &SyncEngineImpl::HandleInitializationFailureOnFrontendLoop); -+ // return; -+ // } - - DCHECK_EQ(user_share->directory->cache_guid(), sync_manager_->cache_guid()); - host_.Call( From 2d4662f477e05d7d8c033c7e4cfdb623d63a2611 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 13 May 2019 15:16:31 -0700 Subject: [PATCH 18/73] Fix index calculation when applying remote records --- components/brave_sync/syncer_helper.cc | 27 +++++++++++++------ components/brave_sync/syncer_helper.h | 4 +-- ...okmarks-bookmark_change_processor.cc.patch | 4 +-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index 129d65134ae7..0bd545816251 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -43,6 +43,18 @@ void ReCalculateOrder(bookmarks::BookmarkModel* model, } } +uint64_t GetIndexByOrder(const std::string& record_order) { + uint64_t index = 0; + size_t last_dot_index = record_order.rfind("."); + DCHECK(last_dot_index != std::string::npos); + std::string last_digit = record_order.substr(last_dot_index + 1); + bool result = base::StringToUint64(last_digit, &index); + --index; + DCHECK(index >= 0); + DCHECK(result); + return index; +} + } // namespace void AddBraveMetaInfo( @@ -79,22 +91,21 @@ void AddBraveMetaInfo( model->SetNodeMetaInfo(node, "sync_timestamp", sync_timestamp); } -uint64_t GetIndexByOrder(const bookmarks::BookmarkNode* parent, - const bookmarks::BookmarkNode* src) { +uint64_t GetIndex(const bookmarks::BookmarkNode* parent, + const bookmarks::BookmarkNode* src) { int index = 0; std::string src_order; src->GetMetaInfo("order", &src_order); DCHECK(!src_order.empty()); - while (index < parent->child_count()) { - const bookmarks::BookmarkNode* node = parent->GetChild(index); + index = GetIndexByOrder(src_order); + const bookmarks::BookmarkNode* node = parent->GetChild(index); + if (node) { std::string node_order; node->GetMetaInfo("order", &node_order); if (!node_order.empty() && - CompareOrder(src_order, node_order)) - return index; - - ++index; + CompareOrder(node_order, src_order)) + return index + 1; } return index; } diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h index d24f61ad092b..bd236811976f 100644 --- a/components/brave_sync/syncer_helper.h +++ b/components/brave_sync/syncer_helper.h @@ -19,8 +19,8 @@ void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, bookmarks::BookmarkModel* bookmark_model, bool has_new_parent); -uint64_t GetIndexByOrder(const bookmarks::BookmarkNode* parent, - const bookmarks::BookmarkNode* src); +uint64_t GetIndex(const bookmarks::BookmarkNode* parent, + const bookmarks::BookmarkNode* src); } // namespace brave_sync diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 4aa4b69fd127..6a24d8a69a5f 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..cce316290140855ea9cccd3eb152850a61435407 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..3b4110a5e4803b7ede262ab416376fda0879b94d 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -91,7 +91,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..cce316290140855ea9cccd3eb152850a } - to_reposition.insert(std::make_pair(src.GetPositionIndex(), dst)); -+ uint64_t index = brave_sync::GetIndexByOrder(dst->parent(), dst); ++ uint64_t index = brave_sync::GetIndex(dst->parent(), dst); + to_reposition.insert(std::make_pair(index, dst)); bookmark_model_->SetNodeSyncTransactionVersion(dst, model_version); } From 5d4d8c2411cf88a001cc360cdbfa1f3a29d2b645 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 15 May 2019 17:14:36 -0700 Subject: [PATCH 19/73] Migrate BraveSyncServiceTest --- .../components/sync/driver/sync_client.cc | 9 + .../bookmark_order_util_unittest.cc | 18 +- .../brave_sync/brave_profile_sync_service.cc | 14 +- .../brave_sync/brave_profile_sync_service.h | 46 ++++- .../brave_sync/brave_sync_service_unittest.cc | 184 +++++++----------- components/brave_sync/test_util.cc | 29 +-- components/brave_sync/test_util.h | 1 + ...components-sync-driver-sync_client.h.patch | 4 +- test/BUILD.gn | 1 - 9 files changed, 146 insertions(+), 160 deletions(-) create mode 100644 chromium_src/components/sync/driver/sync_client.cc diff --git a/chromium_src/components/sync/driver/sync_client.cc b/chromium_src/components/sync/driver/sync_client.cc new file mode 100644 index 000000000000..bdbf540face7 --- /dev/null +++ b/chromium_src/components/sync/driver/sync_client.cc @@ -0,0 +1,9 @@ +#include "../../../../../components/sync/driver/sync_client.cc" + +namespace syncer { + +brave_sync::BraveSyncClient* SyncClient::GetBraveSyncClient() { + return nullptr; +} + +} diff --git a/components/brave_sync/bookmark_order_util_unittest.cc b/components/brave_sync/bookmark_order_util_unittest.cc index 87b634593e1e..0b6e2f54b48c 100644 --- a/components/brave_sync/bookmark_order_util_unittest.cc +++ b/components/brave_sync/bookmark_order_util_unittest.cc @@ -8,24 +8,18 @@ namespace brave_sync { -class BookmarkOrderUtilTest : public testing::Test { -public: -protected: -private: -}; - -TEST_F(BookmarkOrderUtilTest, OrderToIntVect_EmptyString) { +TEST(BookmarkOrderUtilTest, OrderToIntVect_EmptyString) { std::vector result = OrderToIntVect(""); EXPECT_TRUE(result.empty()); } -TEST_F(BookmarkOrderUtilTest, OrderToIntVect_SingleValue) { +TEST(BookmarkOrderUtilTest, OrderToIntVect_SingleValue) { std::vector result = OrderToIntVect("1"); ASSERT_EQ(result.size(), 1u); EXPECT_EQ(result.at(0), 1); } -TEST_F(BookmarkOrderUtilTest, OrderToIntVect_TypicalValue) { +TEST(BookmarkOrderUtilTest, OrderToIntVect_TypicalValue) { std::vector result = OrderToIntVect("1.7.4"); ASSERT_EQ(result.size(), 3u); EXPECT_TRUE(result.at(0) == 1); @@ -33,18 +27,18 @@ TEST_F(BookmarkOrderUtilTest, OrderToIntVect_TypicalValue) { EXPECT_TRUE(result.at(2) == 4); } -TEST_F(BookmarkOrderUtilTest, OrderToIntVect_WrongValue) { +TEST(BookmarkOrderUtilTest, OrderToIntVect_WrongValue) { std::vector result = OrderToIntVect(".."); EXPECT_TRUE(result.empty()); } -TEST_F(BookmarkOrderUtilTest, OrderToIntVect_SemiWrongValue) { +TEST(BookmarkOrderUtilTest, OrderToIntVect_SemiWrongValue) { std::vector result = OrderToIntVect(".5."); ASSERT_EQ(result.size(), 1u); EXPECT_EQ(result.at(0), 5); } -TEST_F(BookmarkOrderUtilTest, CompareOrder) { +TEST(BookmarkOrderUtilTest, CompareOrder) { EXPECT_FALSE(CompareOrder("", "")); EXPECT_TRUE(CompareOrder("1", "2")); EXPECT_TRUE(CompareOrder("1", "1.1")); diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 3691bfc894bf..51777d190593 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -357,20 +357,18 @@ void BraveProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { void BraveProfileSyncService::OnSetSyncBrowsingHistory( const bool sync_browsing_history) { - NOTIMPLEMENTED(); + brave_sync_prefs_->SetSyncHistoryEnabled(sync_browsing_history); } void BraveProfileSyncService::OnSetSyncSavedSiteSettings( const bool sync_saved_site_settings) { - NOTIMPLEMENTED(); + brave_sync_prefs_->SetSyncSiteSettingsEnabled(sync_saved_site_settings); } void BraveProfileSyncService::BackgroundSyncStarted(bool startup) { - NOTIMPLEMENTED(); } void BraveProfileSyncService::BackgroundSyncStopped(bool shutdown) { - NOTIMPLEMENTED(); } void BraveProfileSyncService::OnSyncDebug(const std::string& message) { @@ -751,6 +749,14 @@ bool BraveProfileSyncService::IsBraveSyncEnabled() const{ return brave_sync_prefs_->GetSyncEnabled(); } +bool BraveProfileSyncService::IsBraveSyncInitialized() const { + return brave_sync_initialized_; +} + +bool BraveProfileSyncService::IsBraveSyncConfigured() const { + return brave_sync_configured_; +} + void BraveProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent) { if (IsTimeEmpty(brave_sync_prefs_->GetLastFetchTime())) diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 4480b60c249b..779f9e713327 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -11,6 +11,26 @@ #include "brave/components/brave_sync/jslib_messages_fwd.h" #include "components/browser_sync/profile_sync_service.h" +FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkAdded); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkDeleted); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, GetSyncWords); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, GetSeed); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnBraveSyncPrefsChanged); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnDeleteDevice); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnDeleteDeviceWhenSelfDeleted); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnResetSync); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, ClientOnGetInitData); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnGetInitData); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSaveBookmarksBaseOrder); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncPrefsChanged); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncDebug); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncReadyAlreadyWithSync); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncReadyNewToSync); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnGetExistingObjects); + +class BraveSyncServiceTest; + namespace brave_sync { namespace prefs { class Prefs; @@ -71,9 +91,31 @@ class BraveProfileSyncService : public browser_sync::ProfileSyncService, brave_sync::BraveSyncClient* GetBraveSyncClient() override; + bool IsBraveSyncEnabled() const override; + bool IsBraveSyncInitialized() const; + bool IsBraveSyncConfigured() const; + private: + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkAdded); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkDeleted); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, GetSyncWords); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, GetSeed); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnBraveSyncPrefsChanged); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnDeleteDevice); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, + OnDeleteDeviceWhenSelfDeleted); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnResetSync); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, ClientOnGetInitData); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSaveBookmarksBaseOrder); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetInitData); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncPrefsChanged); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncDebug); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncReadyAlreadyWithSync); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncReadyNewToSync); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetExistingObjects); + friend class ::BraveSyncServiceTest; - bool IsBraveSyncEnabled() const override; void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) override; @@ -109,7 +151,7 @@ class BraveProfileSyncService : public browser_sync::ProfileSyncService, std::string brave_sync_words_; brave_sync::GetRecordsCallback get_record_cb_; - base::WaitableEvent* wevent_; + base::WaitableEvent* wevent_ = nullptr; // Registrar used to monitor the brave_profile prefs. PrefChangeRegistrar brave_pref_change_registrar_; diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index bc4b73e51411..027de0f3ba0f 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -5,11 +5,11 @@ #include "base/files/scoped_temp_dir.h" #include "base/strings/utf_string_conversions.h" -#include "brave/components/brave_sync/client/bookmark_change_processor.h" #include "brave/components/brave_sync/client/brave_sync_client_impl.h" #include "brave/components/brave_sync/client/client_ext_impl_data.h" -#include "brave/components/brave_sync/brave_sync_service_impl.h" -#include "brave/components/brave_sync/brave_sync_service_factory.h" +#include "brave/components/brave_sync/brave_profile_sync_service.h" +#include "brave/components/brave_sync/brave_sync_prefs.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/jslib_const.h" #include "brave/components/brave_sync/jslib_messages.h" @@ -19,6 +19,7 @@ #include "brave/components/brave_sync/values_conv.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service_factory.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_utils.h" #include "components/bookmarks/test/test_bookmark_client.h" @@ -70,7 +71,7 @@ // BraveSyncService SyncMessageHandler overrides // Name | Covered //------------------------------------- -// BackgroundSyncStarted | +, BraveSyncServiceTest.BookmarkAddedImpl +// BackgroundSyncStarted | N/A // BackgroundSyncStopped | + // OnSyncDebug | + // OnSyncSetupError | Need UI handler @@ -78,7 +79,7 @@ // OnSaveInitData | BraveSyncServiceTest.GetSeed // OnSyncReady | + // OnGetExistingObjects | + -// OnResolvedSyncRecords | BraveSyncServiceTest.BookmarkAddedImpl +// OnResolvedSyncRecords | N/A // OnDeletedSyncUser | N/A // OnDeleteSyncSiteSettings | N/A // OnSaveBookmarksBaseOrder | + @@ -86,16 +87,15 @@ // OnResolvedHistorySites | N/A // OnResolvedPreferences | BraveSyncServiceTest.OnDeleteDevice, // | BraveSyncServiceTest.OnResetSync -// OnSyncPrefsChanged | + +// OnBraveSyncPrefsChanged | + using brave_sync::BraveSyncService; -using brave_sync::BraveSyncServiceImpl; +using brave_sync::BraveProfileSyncService; using brave_sync::BraveSyncServiceObserver; using brave_sync::jslib::SyncRecord; using brave_sync::MockBraveSyncClient; using brave_sync::RecordsList; using brave_sync::SimpleDeviceRecord; -using network::TestNetworkConnectionTracker; using network::mojom::ConnectionType; using testing::_; using testing::AtLeast; @@ -129,39 +129,34 @@ class BraveSyncServiceTest : public testing::Test { profile(), base::BindRepeating(&brave_sync::BuildFakeBookmarkModelForTests)); - brave_sync::BraveSyncClientImpl::set_for_testing( - new MockBraveSyncClient()); + sync_client_ = new MockBraveSyncClient(); + brave_sync::BraveSyncClientImpl::set_for_testing(sync_client_); - sync_service_ = static_cast( - brave_sync::BraveSyncServiceFactory::GetInstance()->GetForProfile( - profile())); + EXPECT_CALL(*sync_client(), set_sync_message_handler(_)); - sync_client_ = - static_cast(sync_service_->GetSyncClient()); + sync_service_ = + ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( + profile()); + + EXPECT_EQ(sync_client_, sync_service_->GetBraveSyncClient()); observer_.reset(new MockBraveSyncServiceObserver); - sync_service_->AddObserver(observer_.get()); + sync_service_->BraveSyncService::AddObserver(observer_.get()); EXPECT_TRUE(sync_service_ != NULL); - - // TestNetworkConnectionTracker::CreateInstance has been called in - // TestingBrowserProcess - TestNetworkConnectionTracker* tracker = - TestNetworkConnectionTracker::GetInstance(); - tracker->SetConnectionType(ConnectionType::CONNECTION_UNKNOWN); } void TearDown() override { - sync_service_->RemoveObserver(observer_.get()); + sync_service_->BraveSyncService::RemoveObserver(observer_.get()); // this will also trigger a shutdown of the brave sync service profile_.reset(); } - void BookmarkAddedImpl(); - Profile* profile() { return profile_.get(); } - BraveSyncServiceImpl* sync_service() { return sync_service_; } + BraveProfileSyncService* sync_service() { return sync_service_; } MockBraveSyncClient* sync_client() { return sync_client_; } MockBraveSyncServiceObserver* observer() { return observer_.get(); } + brave_sync::prefs::Prefs* brave_sync_prefs() { + return sync_service_->brave_sync_prefs_.get(); } private: // Need this as a very first member to run tests in UI thread @@ -170,7 +165,7 @@ class BraveSyncServiceTest : public testing::Test { content::TestBrowserThreadBundle thread_bundle_; std::unique_ptr profile_; - BraveSyncServiceImpl* sync_service_; + BraveProfileSyncService* sync_service_; MockBraveSyncClient* sync_client_; std::unique_ptr observer_; @@ -185,8 +180,8 @@ TEST_F(BraveSyncServiceTest, SetSyncEnabled) { sync_service()->OnSetSyncEnabled(true); EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncEnabled)); - EXPECT_FALSE(sync_service()->IsSyncInitialized()); - EXPECT_FALSE(sync_service()->IsSyncConfigured()); + EXPECT_FALSE(sync_service()->IsBraveSyncInitialized()); + EXPECT_FALSE(sync_service()->IsBraveSyncConfigured()); } TEST_F(BraveSyncServiceTest, SetSyncDisabled) { @@ -201,60 +196,16 @@ TEST_F(BraveSyncServiceTest, SetSyncDisabled) { sync_service()->OnSetSyncEnabled(false); EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncEnabled)); - EXPECT_FALSE(sync_service()->IsSyncInitialized()); - EXPECT_FALSE(sync_service()->IsSyncConfigured()); + EXPECT_FALSE(sync_service()->IsBraveSyncInitialized()); + EXPECT_FALSE(sync_service()->IsBraveSyncConfigured()); } TEST_F(BraveSyncServiceTest, IsSyncConfiguredOnNewProfile) { - EXPECT_FALSE(sync_service()->IsSyncConfigured()); + EXPECT_FALSE(sync_service()->IsBraveSyncConfigured()); } TEST_F(BraveSyncServiceTest, IsSyncInitializedOnNewProfile) { - EXPECT_FALSE(sync_service()->IsSyncInitialized()); -} - -void BraveSyncServiceTest::BookmarkAddedImpl() { - // BraveSyncService: real - // BraveSyncClient: mock - // Invoke BraveSyncService::BookmarkAdded - // Expect BraveSyncClient::SendSyncRecords invoked - EXPECT_CALL(*sync_client(), OnSyncEnabledChanged).Times(1); - EXPECT_CALL(*observer(), - OnSyncStateChanged(sync_service())).Times(AtLeast(1)); - sync_service()->OnSetupSyncNewToSync("UnitTestBookmarkAdded"); - sync_service()->BackgroundSyncStarted(true/*startup*/); - - auto* bookmark_model = BookmarkModelFactory::GetForBrowserContext(profile()); - bookmarks::AddIfNotBookmarked(bookmark_model, - GURL("https://a.com"), - base::ASCIIToUTF16("A.com - title")); - // Force service send bookmarks and fire the mock - EXPECT_CALL(*sync_client(), SendSyncRecords(_, _)).Times(1); - sync_service()->OnResolvedSyncRecords(brave_sync::jslib_const::kBookmarks, - std::make_unique()); -} - -TEST_F(BraveSyncServiceTest, BookmarkAdded) { - BookmarkAddedImpl(); -} - -TEST_F(BraveSyncServiceTest, BookmarkDeleted) { - BookmarkAddedImpl(); - auto* bookmark_model = BookmarkModelFactory::GetForBrowserContext(profile()); - - // And just now can actually test delete - std::vector nodes; - bookmarks::GetMostRecentlyAddedEntries(bookmark_model, 1, &nodes); - ASSERT_EQ(nodes.size(), 1u); - ASSERT_NE(nodes.at(0), nullptr); - // TODO(alexeyb): preciece with mock expect filter - EXPECT_CALL(*sync_client(), SendSyncRecords(_, _)).Times(1); - bookmark_model->Remove(nodes.at(0)); - // record->action = jslib::SyncRecord::Action::A_DELETE; - // <= BookmarkNodeToSyncBookmark <= BookmarkChangeProcessor::SendUnsynced - // <= BraveSyncServiceImpl::OnResolvedSyncRecords - sync_service()->OnResolvedSyncRecords(brave_sync::jslib_const::kBookmarks, - std::make_unique()); + EXPECT_FALSE(sync_service()->IsBraveSyncInitialized()); } TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode) { @@ -266,7 +217,7 @@ TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode) { brave_sync::prefs::kSyncEnabled)); } -TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_EmptyDeviceName) { +TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCodeEmptyDeviceName) { EXPECT_CALL(*sync_client(), OnSyncEnabledChanged); // Expecting sync state changed twice: for enabled state and for device name EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(2); @@ -286,7 +237,7 @@ TEST_F(BraveSyncServiceTest, OnSetupSyncNewToSync) { brave_sync::prefs::kSyncEnabled)); } -TEST_F(BraveSyncServiceTest, OnSetupSyncNewToSync_EmptyDeviceName) { +TEST_F(BraveSyncServiceTest, OnSetupSyncNewToSyncEmptyDeviceName) { EXPECT_CALL(*sync_client(), OnSyncEnabledChanged); // Expecting sync state changed twice: for enabled state and for device name EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(2); @@ -357,11 +308,11 @@ TEST_F(BraveSyncServiceTest, GetSeed) { // Service gets seed from client via BraveSyncServiceImpl::OnSaveInitData const auto binary_seed = brave_sync::Uint8Array(16, 77); - EXPECT_TRUE(sync_service()->sync_prefs_->GetPrevSeed().empty()); + EXPECT_TRUE(brave_sync_prefs()->GetPrevSeed().empty()); sync_service()->OnSaveInitData(binary_seed, {0}); std::string expected_seed = brave_sync::StrFromUint8Array(binary_seed); EXPECT_EQ(sync_service()->GetSeed(), expected_seed); - EXPECT_TRUE(sync_service()->sync_prefs_->GetPrevSeed().empty()); + EXPECT_TRUE(brave_sync_prefs()->GetPrevSeed().empty()); } bool DevicesContains(brave_sync::SyncDevices* devices, const std::string& id, @@ -403,8 +354,8 @@ TEST_F(BraveSyncServiceTest, OnDeleteDevice) { EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); sync_service()->OnResolvedPreferences(records); - sync_service()->sync_prefs_->SetThisDeviceId("1"); - auto devices = sync_service()->sync_prefs_->GetSyncDevices(); + brave_sync_prefs()->SetThisDeviceId("1"); + auto devices = brave_sync_prefs()->GetSyncDevices(); EXPECT_TRUE(DevicesContains(devices.get(), "1", "device1")); EXPECT_TRUE(DevicesContains(devices.get(), "2", "device2")); @@ -428,14 +379,14 @@ TEST_F(BraveSyncServiceTest, OnDeleteDevice) { EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); sync_service()->OnResolvedPreferences(resolved_records); - auto devices_final = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices_final = brave_sync_prefs()->GetSyncDevices(); EXPECT_TRUE(DevicesContains(devices_final.get(), "1", "device1")); EXPECT_TRUE(DevicesContains(devices_final.get(), "2", "device2")); EXPECT_FALSE(DevicesContains(devices_final.get(), "3", "device3")); } TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice) { - sync_service()->sync_prefs_->SetThisDeviceId("1"); + brave_sync_prefs()->SetThisDeviceId("1"); RecordsList records; records.push_back(SimpleDeviceRecord( SyncRecord::Action::A_CREATE, @@ -446,7 +397,7 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice) { EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); sync_service()->OnResolvedPreferences(records); - auto devices = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices = brave_sync_prefs()->GetSyncDevices(); EXPECT_TRUE(DevicesContains(devices.get(), "1", "device1")); EXPECT_TRUE(DevicesContains(devices.get(), "2", "device2")); @@ -465,10 +416,13 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice) { sync_service()->OnResolvedPreferences(resolved_records); - auto devices_semi_final = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices_semi_final = brave_sync_prefs()->GetSyncDevices(); EXPECT_FALSE(DevicesContains(devices_semi_final.get(), "2", "device2")); EXPECT_TRUE(DevicesContains(devices_semi_final.get(), "1", "device1")); + // Enabled->Disabled + EXPECT_CALL(*sync_client(), OnSyncEnabledChanged).Times(1); + // Emulate sending DELETE for this device RecordsList resolved_records2; auto resolved_record2 = SyncRecord::Clone(*records.at(0)); @@ -478,14 +432,14 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenOneDevice) { sync_service()->OnResolvedPreferences(resolved_records2); - auto devices_final = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices_final = brave_sync_prefs()->GetSyncDevices(); EXPECT_FALSE(DevicesContains(devices_final.get(), "1", "device1")); EXPECT_FALSE(DevicesContains(devices_final.get(), "2", "device2")); - EXPECT_FALSE(sync_service()->IsSyncConfigured()); + EXPECT_FALSE(sync_service()->IsBraveSyncConfigured()); } TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenSelfDeleted) { - sync_service()->sync_prefs_->SetThisDeviceId("1"); + brave_sync_prefs()->SetThisDeviceId("1"); RecordsList records; records.push_back(SimpleDeviceRecord( SyncRecord::Action::A_CREATE, @@ -496,7 +450,7 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenSelfDeleted) { EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); sync_service()->OnResolvedPreferences(records); - auto devices = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices = brave_sync_prefs()->GetSyncDevices(); EXPECT_TRUE(DevicesContains(devices.get(), "1", "device1")); EXPECT_TRUE(DevicesContains(devices.get(), "2", "device2")); @@ -505,6 +459,9 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenSelfDeleted) { ContainsDeviceRecord(SyncRecord::Action::A_DELETE, "device1"))).Times(1); sync_service()->OnDeleteDevice("1"); + // Enabled->Disabled + EXPECT_CALL(*sync_client(), OnSyncEnabledChanged).Times(1); + RecordsList resolved_records; auto resolved_record = SyncRecord::Clone(*records.at(0)); resolved_record->action = SyncRecord::Action::A_DELETE; @@ -513,11 +470,11 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenSelfDeleted) { EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(3); sync_service()->OnResolvedPreferences(resolved_records); - auto devices_final = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices_final = brave_sync_prefs()->GetSyncDevices(); EXPECT_FALSE(DevicesContains(devices_final.get(), "1", "device1")); EXPECT_FALSE(DevicesContains(devices_final.get(), "2", "device2")); - EXPECT_FALSE(sync_service()->IsSyncConfigured()); + EXPECT_FALSE(sync_service()->IsBraveSyncConfigured()); } TEST_F(BraveSyncServiceTest, OnResetSync) { @@ -527,7 +484,7 @@ TEST_F(BraveSyncServiceTest, OnResetSync) { sync_service()->OnSetupSyncNewToSync("this_device"); EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncEnabled)); - sync_service()->sync_prefs_->SetThisDeviceId("0"); + brave_sync_prefs()->SetThisDeviceId("0"); RecordsList records; records.push_back(SimpleDeviceRecord( @@ -539,11 +496,15 @@ TEST_F(BraveSyncServiceTest, OnResetSync) { sync_service()->OnResolvedPreferences(records); - auto devices = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices = brave_sync_prefs()->GetSyncDevices(); EXPECT_TRUE(DevicesContains(devices.get(), "0", "this_device")); EXPECT_TRUE(DevicesContains(devices.get(), "1", "device1")); + EXPECT_CALL(*sync_client(), SendSyncRecords("PREFERENCES", + ContainsDeviceRecord(SyncRecord::Action::A_DELETE, + "this_device"))).Times(1); + sync_service()->OnResetSync(); RecordsList resolved_records; auto resolved_record = SyncRecord::Clone(*records.at(0)); @@ -551,7 +512,7 @@ TEST_F(BraveSyncServiceTest, OnResetSync) { resolved_records.push_back(std::move(resolved_record)); sync_service()->OnResolvedPreferences(resolved_records); - auto devices_final = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices_final = brave_sync_prefs()->GetSyncDevices(); EXPECT_FALSE(DevicesContains(devices_final.get(), "0", "this_device")); EXPECT_FALSE(DevicesContains(devices_final.get(), "1", "device1")); @@ -580,8 +541,8 @@ TEST_F(BraveSyncServiceTest, OnResetSync) { EXPECT_EQ(profile()->GetPrefs()->GetString( brave_sync::prefs::kSyncApiVersion), "0"); - EXPECT_FALSE(sync_service()->IsSyncInitialized()); - EXPECT_FALSE(sync_service()->IsSyncConfigured()); + EXPECT_FALSE(sync_service()->IsBraveSyncInitialized()); + EXPECT_FALSE(sync_service()->IsBraveSyncConfigured()); } TEST_F(BraveSyncServiceTest, OnSetSyncBookmarks) { @@ -629,22 +590,27 @@ TEST_F(BraveSyncServiceTest, OnGetInitData) { } TEST_F(BraveSyncServiceTest, OnSaveBookmarksBaseOrder) { + EXPECT_CALL(*sync_client(), OnSyncEnabledChanged).Times(1); + // kSyncEnabled and kSyncBookmarksEnabled + EXPECT_CALL(*observer(), OnSyncStateChanged).Times(2); + sync_service()->OnSetSyncEnabled(true); sync_service()->OnSaveBookmarksBaseOrder("1.1."); EXPECT_EQ(profile()->GetPrefs()->GetString( brave_sync::prefs::kSyncBookmarksBaseOrder), "1.1."); } -TEST_F(BraveSyncServiceTest, OnSyncPrefsChanged) { +TEST_F(BraveSyncServiceTest, OnBraveSyncPrefsChanged) { EXPECT_CALL(*sync_client(), OnSyncEnabledChanged).Times(1); EXPECT_CALL(*observer(), OnSyncStateChanged); - sync_service()->OnSyncPrefsChanged(brave_sync::prefs::kSyncEnabled); + sync_service()->OnBraveSyncPrefsChanged(brave_sync::prefs::kSyncEnabled); } -TEST_F(BraveSyncServiceTest, OnSyncReadyAlreadyWithSync) { - EXPECT_FALSE(sync_service()->IsSyncInitialized()); +TEST_F(BraveSyncServiceTest, DISABLED_OnSyncReadyAlreadyWithSync) { + EXPECT_FALSE(sync_service()->IsBraveSyncInitialized()); + sync_service()->OnSetSyncEnabled(true); profile()->GetPrefs()->SetString( brave_sync::prefs::kSyncBookmarksBaseOrder, "1.1."); - // OnSyncPrefsChanged => OnSyncStateChanged for + // OnBraveSyncPrefsChanged => OnSyncStateChanged for // kSyncSiteSettingsEnabled (1) and kSyncDeviceList (2) EXPECT_CALL(*observer(), OnSyncStateChanged).Times(2); profile()->GetPrefs()->SetBoolean( @@ -675,7 +641,7 @@ TEST_F(BraveSyncServiceTest, OnSyncReadyAlreadyWithSync) { EXPECT_CALL(*sync_client(), SendFetchSyncRecords).Times(1); EXPECT_CALL(*sync_client(), SendFetchSyncDevices).Times(1); sync_service()->OnSyncReady(); - EXPECT_TRUE(sync_service()->IsSyncInitialized()); + EXPECT_TRUE(sync_service()->IsBraveSyncInitialized()); } TEST_F(BraveSyncServiceTest, OnSyncReadyNewToSync) { @@ -696,16 +662,6 @@ TEST_F(BraveSyncServiceTest, OnGetExistingObjects) { false); } -TEST_F(BraveSyncServiceTest, BackgroundSyncStarted) { - sync_service()->BackgroundSyncStarted(false); - EXPECT_TRUE(sync_service()->timer_->IsRunning()); -} - -TEST_F(BraveSyncServiceTest, BackgroundSyncStopped) { - sync_service()->BackgroundSyncStopped(false); - EXPECT_FALSE(sync_service()->timer_->IsRunning()); -} - TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { EXPECT_FALSE(sync_service()->GetResettingForTest()); EXPECT_CALL(*sync_client(), OnSyncEnabledChanged).Times(1); diff --git a/components/brave_sync/test_util.cc b/components/brave_sync/test_util.cc index b7858a045a7e..ede54853e6fe 100644 --- a/components/brave_sync/test_util.cc +++ b/components/brave_sync/test_util.cc @@ -6,11 +6,11 @@ #include "base/files/file_util.h" #include "base/strings/utf_string_conversions.h" -#include "brave/components/brave_sync/brave_sync_service_factory.h" -#include "brave/components/brave_sync/client/bookmark_node.h" +#include "brave/components/brave_sync/brave_sync_prefs.h" #include "brave/components/brave_sync/tools.h" #include "brave/components/brave_sync/values_conv.h" #include "chrome/browser/prefs/browser_prefs.h" +#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" #include "components/bookmarks/browser/bookmark_model.h" @@ -18,21 +18,6 @@ #include "components/sync_preferences/pref_service_mock_factory.h" #include "components/sync_preferences/testing_pref_service_syncable.h" -namespace { - -using namespace bookmarks; - -void AddPermanentNode(BookmarkPermanentNodeList* extra_nodes, int64_t id, - const std::string& title) { - auto node = std::make_unique(id); - node->set_type(bookmarks::BookmarkNode::FOLDER); - node->set_visible(false); - node->SetTitle(base::UTF8ToUTF16(title)); - extra_nodes->push_back(std::move(node)); -} - -} // namespace - namespace brave_sync { MockBraveSyncClient::MockBraveSyncClient() {} @@ -40,13 +25,14 @@ MockBraveSyncClient::MockBraveSyncClient() {} MockBraveSyncClient::~MockBraveSyncClient() {} std::unique_ptr CreateBraveSyncProfile(const base::FilePath& path) { - BraveSyncServiceFactory::GetInstance(); + ProfileSyncServiceFactory::GetInstance(); sync_preferences::PrefServiceMockFactory factory; auto registry = base::MakeRefCounted(); std::unique_ptr prefs( factory.CreateSyncable(registry.get())); RegisterUserProfilePrefs(registry.get()); + prefs::Prefs::RegisterProfilePrefs(registry.get()); TestingProfile::Builder profile_builder; profile_builder.SetPrefService(std::move(prefs)); @@ -59,13 +45,6 @@ std::unique_ptr BuildFakeBookmarkModelForTests( // Don't need context, unless we have more than one profile using namespace bookmarks; std::unique_ptr client(new TestBookmarkClient()); - BookmarkPermanentNodeList extra_nodes; - - // These hard-coded titles cannot be changed - AddPermanentNode(&extra_nodes, 0xDE1E7ED40DE, "Deleted Bookmarks"); - AddPermanentNode(&extra_nodes, 0x9E7D17640DE, "Pending Bookmarks"); - - client->SetExtraNodesToLoad(std::move(extra_nodes)); std::unique_ptr model( TestBookmarkClient::CreateModelWithClient(std::move(client))); return model; diff --git a/components/brave_sync/test_util.h b/components/brave_sync/test_util.h index e63894af871e..3698be4b1c2b 100644 --- a/components/brave_sync/test_util.h +++ b/components/brave_sync/test_util.h @@ -32,6 +32,7 @@ class MockBraveSyncClient : public BraveSyncClient { ~MockBraveSyncClient() override; MOCK_METHOD0(sync_message_handler, SyncMessageHandler*()); + MOCK_METHOD1(set_sync_message_handler, void(SyncMessageHandler*)); MOCK_METHOD4(SendGotInitData, void(const Uint8Array& seed, const Uint8Array& device_id, const client_data::Config& config, const std::string& sync_words)); diff --git a/patches/components-sync-driver-sync_client.h.patch b/patches/components-sync-driver-sync_client.h.patch index 31d7a844728f..9926adca257b 100644 --- a/patches/components-sync-driver-sync_client.h.patch +++ b/patches/components-sync-driver-sync_client.h.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/driver/sync_client.h b/components/sync/driver/sync_client.h -index 1cc9f14d35f7edae21fc21a3bd9970a7e60f4222..e19603dcf48f4d9d1c88961dccfaaef7ccf08824 100644 +index 1cc9f14d35f7edae21fc21a3bd9970a7e60f4222..9c69b2e5cab29d7c757b6a06d3619bcb32fa681b 100644 --- a/components/sync/driver/sync_client.h +++ b/components/sync/driver/sync_client.h @@ -73,6 +73,8 @@ class SyncClient { // Returns the current SyncApiComponentFactory instance. virtual SyncApiComponentFactory* GetSyncApiComponentFactory() = 0; -+ virtual brave_sync::BraveSyncClient* GetBraveSyncClient() = 0; ++ virtual brave_sync::BraveSyncClient* GetBraveSyncClient(); + private: DISALLOW_COPY_AND_ASSIGN(SyncClient); diff --git a/test/BUILD.gn b/test/BUILD.gn index 018af9247f9a..c869acd29a02 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -93,7 +93,6 @@ test("brave_unit_tests") { "//brave/components/brave_shields/browser/https_everywhere_recently_used_cache_unittest.cpp", "//brave/components/brave_sync/bookmark_order_util_unittest.cc", "//brave/components/brave_sync/brave_sync_service_unittest.cc", - "//brave/components/brave_sync/client/bookmark_change_processor_unittest.cc", "//brave/components/brave_webtorrent/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc", "//brave/components/invalidation/fcm_unittest.cc", "//brave/components/gcm_driver/gcm_unittest.cc", From 57cf686e174a169bd4ce50e32c0cc78bd6ca8e9c Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 16 May 2019 23:03:01 -0700 Subject: [PATCH 20/73] Add test for SyncerHelper also 1. remove unecessary const_cast 2. fix empty order bug in ReCalculateOrder 3. add ScopedPauseObserver to reduce patch --- .../bookmark_change_processor.cc | 28 +- .../brave_sync/brave_profile_sync_service.cc | 8 +- .../brave_sync/brave_sync_service_unittest.cc | 66 +- .../bookmark_change_processor_unittest.cc | 1580 ----------------- components/brave_sync/syncer_helper.cc | 24 +- components/brave_sync/syncer_helper.h | 2 + .../brave_sync/syncer_helper_unittest.cc | 311 ++++ ...okmarks-bookmark_change_processor.cc.patch | 33 +- test/BUILD.gn | 1 + 9 files changed, 405 insertions(+), 1648 deletions(-) delete mode 100644 components/brave_sync/client/bookmark_change_processor_unittest.cc create mode 100644 components/brave_sync/syncer_helper_unittest.cc diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 9b3371675524..5bba06e28e2b 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -1,6 +1,29 @@ +#include "components/bookmarks/browser/bookmark_model.h" + +namespace { + +class ScopedPauseObserver { + public: + explicit ScopedPauseObserver(bookmarks::BookmarkModel* model, + bookmarks::BookmarkModelObserver* observer) : + model_(model), observer_(observer) { + DCHECK_NE(observer_, nullptr); + DCHECK_NE(model_, nullptr); + model_->RemoveObserver(observer_); + } + ~ScopedPauseObserver() { + model_->AddObserver(observer_); + } + + private: + bookmarks::BookmarkModel* model_; // Not owned + bookmarks::BookmarkModelObserver* observer_; +}; + +} // namespace + #include "brave/components/brave_sync/syncer_helper.h" #include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" -#include "components/bookmarks/browser/bookmark_model.h" namespace sync_bookmarks { @@ -16,10 +39,9 @@ bool BookmarkChangeProcessor::IsFirstLoadedFavicon(const BookmarkNode* node) { if (node->GetMetaInfo("FirstLoadedFavicon", &FirstLoadedFavicon)) { if (!node->icon_url()) return true; - bookmark_model_->RemoveObserver(this); + ScopedPauseObserver pause(bookmark_model_, this); BookmarkNode* mutable_node = const_cast(node); mutable_node->DeleteMetaInfo("FirstLoadedFavicon"); - bookmark_model_->AddObserver(this); return true; } return false; diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 51777d190593..239151bbf5bd 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -613,17 +613,13 @@ void BraveProfileSyncService::SetPermanentNodesOrder( std::string order; model_->bookmark_bar_node()->GetMetaInfo("order", &order); if (order.empty()) { - bookmarks::BookmarkNode* mutable_bookmark_bar_node = - const_cast(model_->bookmark_bar_node()); - model_->SetNodeMetaInfo(mutable_bookmark_bar_node, "order", + model_->SetNodeMetaInfo(model_->bookmark_bar_node(), "order", base_order + "1"); } order.clear(); model_->other_node()->GetMetaInfo("order", &order); if (order.empty()) { - bookmarks::BookmarkNode* mutable_other_node = - const_cast(model_->other_node()); - model_->SetNodeMetaInfo(mutable_other_node, "order", base_order + "2"); + model_->SetNodeMetaInfo(model_->other_node(), "order", base_order + "2"); } brave_sync_prefs_->SetMigratedBookmarksVersion(2); } diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 027de0f3ba0f..903b6e1afee7 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -26,7 +26,6 @@ #include "components/prefs/pref_service.h" #include "content/public/browser/network_service_instance.h" #include "content/public/test/test_browser_thread_bundle.h" -#include "services/network/test/test_network_connection_tracker.h" #include "net/base/network_interfaces.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -89,6 +88,7 @@ // | BraveSyncServiceTest.OnResetSync // OnBraveSyncPrefsChanged | + +using bookmarks::BookmarkModel; using brave_sync::BraveSyncService; using brave_sync::BraveProfileSyncService; using brave_sync::BraveSyncServiceObserver; @@ -96,10 +96,34 @@ using brave_sync::jslib::SyncRecord; using brave_sync::MockBraveSyncClient; using brave_sync::RecordsList; using brave_sync::SimpleDeviceRecord; -using network::mojom::ConnectionType; using testing::_; using testing::AtLeast; +bool DevicesContains(brave_sync::SyncDevices* devices, const std::string& id, + const std::string& name) { + DCHECK(devices); + for (const auto& device : devices->devices_) { + if (device.device_id_ == id && device.name_ == name) { + return true; + } + } + return false; +} + +MATCHER_P2(ContainsDeviceRecord, action, name, + "contains device sync record with params") { + for (const auto& record : arg) { + if (record->has_device()) { + const auto& device = record->GetDevice(); + if (record->action == action && + device.name == name) { + return true; + } + } + } + return false; +} + class MockBraveSyncServiceObserver : public BraveSyncServiceObserver { public: MockBraveSyncServiceObserver() {} @@ -129,6 +153,10 @@ class BraveSyncServiceTest : public testing::Test { profile(), base::BindRepeating(&brave_sync::BuildFakeBookmarkModelForTests)); + model_ = BookmarkModelFactory::GetForBrowserContext( + Profile::FromBrowserContext(profile_.get())); + EXPECT_NE(model(), nullptr); + sync_client_ = new MockBraveSyncClient(); brave_sync::BraveSyncClientImpl::set_for_testing(sync_client_); @@ -154,6 +182,7 @@ class BraveSyncServiceTest : public testing::Test { Profile* profile() { return profile_.get(); } BraveProfileSyncService* sync_service() { return sync_service_; } MockBraveSyncClient* sync_client() { return sync_client_; } + BookmarkModel* model() { return model_; } MockBraveSyncServiceObserver* observer() { return observer_.get(); } brave_sync::prefs::Prefs* brave_sync_prefs() { return sync_service_->brave_sync_prefs_.get(); } @@ -167,6 +196,7 @@ class BraveSyncServiceTest : public testing::Test { std::unique_ptr profile_; BraveProfileSyncService* sync_service_; MockBraveSyncClient* sync_client_; + BookmarkModel* model_; // Not owns std::unique_ptr observer_; base::ScopedTempDir temp_dir_; @@ -315,31 +345,6 @@ TEST_F(BraveSyncServiceTest, GetSeed) { EXPECT_TRUE(brave_sync_prefs()->GetPrevSeed().empty()); } -bool DevicesContains(brave_sync::SyncDevices* devices, const std::string& id, - const std::string& name) { - DCHECK(devices); - for (const auto& device : devices->devices_) { - if (device.device_id_ == id && device.name_ == name) { - return true; - } - } - return false; -} - -MATCHER_P2(ContainsDeviceRecord, action, name, - "contains device sync record with params") { - for (const auto& record : arg) { - if (record->has_device()) { - const auto& device = record->GetDevice(); - if (record->action == action && - device.name == name) { - return true; - } - } - } - return false; -} - TEST_F(BraveSyncServiceTest, OnDeleteDevice) { RecordsList records; records.push_back(SimpleDeviceRecord( @@ -597,6 +602,13 @@ TEST_F(BraveSyncServiceTest, OnSaveBookmarksBaseOrder) { sync_service()->OnSaveBookmarksBaseOrder("1.1."); EXPECT_EQ(profile()->GetPrefs()->GetString( brave_sync::prefs::kSyncBookmarksBaseOrder), "1.1."); + // Permanent node order + std::string order; + model()->bookmark_bar_node()->GetMetaInfo("order", &order); + EXPECT_EQ(order, "1.1.1"); + order.clear(); + model()->other_node()->GetMetaInfo("order", &order); + EXPECT_EQ(order, "1.1.2"); } TEST_F(BraveSyncServiceTest, OnBraveSyncPrefsChanged) { diff --git a/components/brave_sync/client/bookmark_change_processor_unittest.cc b/components/brave_sync/client/bookmark_change_processor_unittest.cc deleted file mode 100644 index 4f50abe941cd..000000000000 --- a/components/brave_sync/client/bookmark_change_processor_unittest.cc +++ /dev/null @@ -1,1580 +0,0 @@ -/* Copyright 2016 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 -#include -#include - -#include "base/files/scoped_temp_dir.h" -#include "base/strings/utf_string_conversions.h" -#include "base/strings/string_number_conversions.h" -#include "brave/components/brave_sync/client/bookmark_change_processor.h" -#include "brave/components/brave_sync/client/brave_sync_client_impl.h" -#include "brave/components/brave_sync/client/client_ext_impl_data.h" -#include "brave/components/brave_sync/brave_sync_service_impl.h" -#include "brave/components/brave_sync/brave_sync_service_factory.h" -#include "brave/components/brave_sync/brave_sync_service_observer.h" -#include "brave/components/brave_sync/jslib_const.h" -#include "brave/components/brave_sync/jslib_messages.h" -#include "brave/components/brave_sync/test_util.h" -#include "chrome/browser/bookmarks/bookmark_model_factory.h" -#include "chrome/browser/profiles/profile.h" -#include "components/bookmarks/browser/bookmark_model.h" -#include "components/bookmarks/browser/bookmark_utils.h" -#include "components/bookmarks/common/bookmark_pref_names.h" -#include "components/bookmarks/test/test_bookmark_client.h" -#include "components/prefs/pref_service.h" -#include "content/public/test/test_browser_thread_bundle.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -// npm run test -- brave_unit_tests --filter=BraveBookmarkChangeProcessorTest.* - -// BookmarkChangeProcessor::methods -// Name | Covered -//------------------------------------- -// Create | + in SetUp -// Start | + -// Stop | + -// Reset | + -// ApplyChangesFromSyncModel | + -// GetAllSyncData | + -// SendUnsynced | + -// InitialSync | N/A -// ApplyOrder | + - -// bookmarks::BookmarkModelObserver overrides: -// Name | Covered -// BookmarkModelLoaded | N/A -// BookmarkModelBeingDeleted | N/A -// BookmarkNodeMoved | + -// BookmarkNodeAdded | N/A -// OnWillRemoveBookmarks | N/A -// BookmarkNodeRemoved | + -// BookmarkAllUserNodesRemoved | N/A -// BookmarkNodeChanged | + -// BookmarkMetaInfoChanged | + -// BookmarkNodeFaviconChanged | + - -using testing::_; -using testing::AtLeast; - -using bookmarks::BookmarkClient; -using bookmarks::BookmarkModel; -using bookmarks::BookmarkNode; - -using brave_sync::jslib::SyncRecord; -using brave_sync::MockBraveSyncClient; -using brave_sync::RecordsList; -using brave_sync::SimpleBookmarkSyncRecord; -using brave_sync::SimpleFolderSyncRecord; - -MATCHER_P2(ContainsRecord, action, location, - "contains sync record with params") { - for (const auto& record : arg) { - if (record->has_bookmark()) { - const auto& bookmark = record->GetBookmark(); - if (record->action == action && - bookmark.site.location == location) { - return true; - } - } - } - return false; -} - -MATCHER_P(RecordsNumber, expected_number, - "contains specified sync record number") { - return static_cast(arg.size()) == static_cast(expected_number); -} - -MATCHER_P(AllRecordsHaveAction, expected_action, - "all records have expected action") { - if (arg.empty()) { - return false; - } - - for (const auto& record : arg) { - if (record->action != expected_action) { - return false; - } - } - return true; -} - -class BraveBookmarkChangeProcessorTest : public testing::Test { - public: - BraveBookmarkChangeProcessorTest() {} - ~BraveBookmarkChangeProcessorTest() override {} - - protected: - void SetUp() override { - EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); - - profile_ = brave_sync::CreateBraveSyncProfile(temp_dir_.GetPath()); - EXPECT_TRUE(profile_.get() != NULL); - - sync_client_.reset(new MockBraveSyncClient()); - - BookmarkModelFactory::GetInstance()->SetTestingFactory( - profile_.get(), - base::BindRepeating(&brave_sync::BuildFakeBookmarkModelForTests)); - - model_ = BookmarkModelFactory::GetForBrowserContext( - Profile::FromBrowserContext(profile_.get())); - - sync_prefs_.reset(new brave_sync::prefs::Prefs(profile_->GetPrefs())); - - change_processor_.reset(brave_sync::BookmarkChangeProcessor::Create( - profile_.get(), - sync_client(), - sync_prefs_.get() )); - - EXPECT_NE(sync_client(), nullptr); - EXPECT_NE(bookmark_client(), nullptr); - EXPECT_NE(model(), nullptr); - EXPECT_NE(change_processor(), nullptr); - } - - void TearDown() override { - change_processor()->Stop(); - change_processor_.reset(); - profile_.reset(); - } - - MockBraveSyncClient* sync_client() { return sync_client_.get(); } - BookmarkClient* bookmark_client() { return model_->client(); } - BookmarkModel* model() { return model_; } - brave_sync::prefs::Prefs* sync_prefs() { return sync_prefs_.get(); } - brave_sync::BookmarkChangeProcessor* change_processor() { - return change_processor_.get(); - } - const bookmarks::BookmarkPermanentNode* GetDeletedNodeRoot() { - return static_cast( - change_processor_->GetDeletedNodeRoot()); - } - const bookmarks::BookmarkPermanentNode* GetPendingNodeRoot() { - return static_cast( - change_processor_->GetPendingNodeRoot()); - } - - void BookmarkAddedImpl(); - void BookmarkCreatedFromSyncImpl(); - bool HasAnySyncMetaInfo(const BookmarkNode* node); - void AddSimpleHierarchy( - const BookmarkNode** folder1, const BookmarkNode** node_a, - const BookmarkNode** node_b, const BookmarkNode** node_c); - - private: - // Need this as a very first member to run tests in UI thread - // When this is set, class should not install any other MessageLoops, like - // base::test::ScopedTaskEnvironment - content::TestBrowserThreadBundle thread_bundle_; - - std::unique_ptr sync_client_; - BookmarkModel* model_; // Not owns - std::unique_ptr change_processor_; - std::unique_ptr profile_; - std::unique_ptr sync_prefs_; - base::ScopedTempDir temp_dir_; -}; - -TEST_F(BraveBookmarkChangeProcessorTest, StartObserver) { - // The mark of observer processed: metainfo "last_updated_time" is set - const auto* node_a = model()->AddURL(model()->other_node(), 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - model()->SetTitle(node_a, base::ASCIIToUTF16("A.com - title - upated")); - std::string last_updated_time_a; - node_a->GetMetaInfo("last_updated_time", &last_updated_time_a); - EXPECT_TRUE(last_updated_time_a.empty()); - - change_processor()->Start(); - - const auto* node_b = model()->AddURL(model()->other_node(), 0, - base::ASCIIToUTF16("B.com - title"), - GURL("https://b.com/")); - model()->SetTitle(node_b, base::ASCIIToUTF16("B.com - title - upated")); - std::string last_updated_time_b; - node_b->GetMetaInfo("last_updated_time", &last_updated_time_b); - EXPECT_TRUE(!last_updated_time_b.empty()); -} - -TEST_F(BraveBookmarkChangeProcessorTest, StopObserver) { - // The mark of observer processed: metainfo "last_updated_time" is set - change_processor()->Start(); - const auto* node_a = model()->AddURL(model()->other_node(), 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - model()->SetTitle(node_a, base::ASCIIToUTF16("A.com - title - upated")); - std::string last_updated_time_a; - node_a->GetMetaInfo("last_updated_time", &last_updated_time_a); - EXPECT_TRUE(!last_updated_time_a.empty()); - - change_processor()->Stop(); - - const auto* node_b = model()->AddURL(model()->other_node(), 0, - base::ASCIIToUTF16("B.com - title"), - GURL("https://b.com/")); - model()->SetTitle(node_b, base::ASCIIToUTF16("B.com - title - upated")); - std::string last_updated_time_b; - node_b->GetMetaInfo("last_updated_time", &last_updated_time_b); - EXPECT_TRUE(last_updated_time_b.empty()); -} - -bool BraveBookmarkChangeProcessorTest::HasAnySyncMetaInfo( - const BookmarkNode* node) { - DCHECK(node); - const std::vector keys = {"object_id", "order", "sync_timestamp", - "last_send_time", "last_updated_time", "parent_object_id"}; - for (const auto& key : keys) { - std::string value; - if (node->GetMetaInfo(key, &value) && !value.empty()) { - return true; - } - } - return false; -} - -void BraveBookmarkChangeProcessorTest::AddSimpleHierarchy( - const BookmarkNode** folder1, const BookmarkNode** node_a, - const BookmarkNode** node_b, const BookmarkNode** node_c) { - *folder1 = model()->AddFolder(model()->other_node(), 0, - base::ASCIIToUTF16("Folder1")); - - *node_a = model()->AddURL(*folder1, 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - - *node_b = model()->AddURL(*folder1, 1, - base::ASCIIToUTF16("B.com - title"), - GURL("https://b.com/")); - - *node_c = model()->AddURL(*folder1, 2, - base::ASCIIToUTF16("C.com - title"), - GURL("https://c.com/")); -} - -TEST_F(BraveBookmarkChangeProcessorTest, ResetClearMeta) { - // Reset does clear of the metainfo, but - // to fillup the metainfo now need to send it to sync - change_processor()->Start(); - - const BookmarkNode* folder1; - const BookmarkNode* node_a; - const BookmarkNode* node_b; - const BookmarkNode* node_c; - AddSimpleHierarchy(&folder1, &node_a, &node_b, &node_c); - - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(1); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); - - EXPECT_TRUE(HasAnySyncMetaInfo(folder1)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_a)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_b)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_c)); - - model()->AddURL(GetDeletedNodeRoot(), 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - model()->AddURL(GetPendingNodeRoot(), 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - EXPECT_FALSE(GetDeletedNodeRoot()->children().empty()); - EXPECT_FALSE(GetPendingNodeRoot()->children().empty()); - - change_processor()->Reset(true); - - EXPECT_FALSE(HasAnySyncMetaInfo(folder1)); - EXPECT_FALSE(HasAnySyncMetaInfo(node_a)); - EXPECT_FALSE(HasAnySyncMetaInfo(node_b)); - EXPECT_FALSE(HasAnySyncMetaInfo(node_c)); - EXPECT_TRUE(GetDeletedNodeRoot()->children().empty()); - EXPECT_TRUE(GetPendingNodeRoot()->children().empty()); -} - -TEST_F(BraveBookmarkChangeProcessorTest, ResetPreserveMeta) { - // Reset does clear of the metainfo, but - // to fillup the metainfo now need to send it to sync - change_processor()->Start(); - - const BookmarkNode* folder1; - const BookmarkNode* node_a; - const BookmarkNode* node_b; - const BookmarkNode* node_c; - AddSimpleHierarchy(&folder1, &node_a, &node_b, &node_c); - - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(1); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); - - EXPECT_TRUE(HasAnySyncMetaInfo(folder1)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_a)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_b)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_c)); - - model()->AddURL(GetDeletedNodeRoot(), 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - model()->AddURL(GetPendingNodeRoot(), 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - EXPECT_FALSE(GetDeletedNodeRoot()->children().empty()); - EXPECT_FALSE(GetPendingNodeRoot()->children().empty()); - - change_processor()->Reset(false); - - EXPECT_TRUE(HasAnySyncMetaInfo(folder1)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_a)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_b)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_c)); - EXPECT_TRUE(GetDeletedNodeRoot()->children().empty()); - EXPECT_TRUE(GetPendingNodeRoot()->children().empty()); -} - - -TEST_F(BraveBookmarkChangeProcessorTest, DISABLED_InitialSync) { - // BookmarkChangeProcessor::InitialSync does not do anything now - // All work for obtaining order is done in background.js -} - -void BraveBookmarkChangeProcessorTest::BookmarkAddedImpl() { - change_processor()->Start(); - - bookmarks::AddIfNotBookmarked(model(), - GURL("https://a.com/"), - base::ASCIIToUTF16("A.com - title")); - - using brave_sync::jslib::SyncRecord; - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", - ContainsRecord(SyncRecord::Action::A_CREATE, "https://a.com/"))).Times(1); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); -} - -TEST_F(BraveBookmarkChangeProcessorTest, BookmarkAdded) { - BookmarkAddedImpl(); -} - -TEST_F(BraveBookmarkChangeProcessorTest, BookmarkDeleted) { - // Add bookmark first - BookmarkAddedImpl(); - using brave_sync::jslib::SyncRecord; - - // And just now can actually test delete - std::vector nodes; - bookmarks::GetMostRecentlyAddedEntries(model(), 1, &nodes); - ASSERT_EQ(nodes.size(), 1u); - ASSERT_NE(nodes.at(0), nullptr); - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", - ContainsRecord(SyncRecord::Action::A_DELETE, "https://a.com/"))).Times(1); - model()->Remove(nodes.at(0)); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); - EXPECT_FALSE(GetDeletedNodeRoot()->IsVisible()); -} - -TEST_F(BraveBookmarkChangeProcessorTest, BookmarkModified) { - // Add bookmark first - BookmarkAddedImpl(); - using brave_sync::jslib::SyncRecord; - - // And just now can actually test modify - std::vector nodes; - bookmarks::GetMostRecentlyAddedEntries(model(), 1, &nodes); - ASSERT_EQ(nodes.size(), 1u); - ASSERT_NE(nodes.at(0), nullptr); - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", - ContainsRecord(SyncRecord::Action::A_UPDATE, - "https://a-m.com/"))).Times(1); - model()->SetURL(nodes.at(0), GURL("https://a-m.com/")); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); -} - -TEST_F(BraveBookmarkChangeProcessorTest, BookmarkMovedInFolder) { - change_processor()->Start(); - - const BookmarkNode* folder1; - const BookmarkNode* node_a; - const BookmarkNode* node_b; - const BookmarkNode* node_c; - AddSimpleHierarchy(&folder1, &node_a, &node_b, &node_c); - - int intex_a = folder1->GetIndexOf(node_a); - EXPECT_EQ(intex_a, 0); - int intex_b = folder1->GetIndexOf(node_b); - EXPECT_EQ(intex_b, 1); - int intex_c = folder1->GetIndexOf(node_c); - EXPECT_EQ(intex_c, 2); - - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(1); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); - - EXPECT_TRUE(HasAnySyncMetaInfo(folder1)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_a)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_b)); - EXPECT_TRUE(HasAnySyncMetaInfo(node_c)); - - model()->Move(node_a, folder1, 2); - - intex_a = folder1->GetIndexOf(node_a); - EXPECT_EQ(intex_a, 1); - intex_b = folder1->GetIndexOf(node_b); - EXPECT_EQ(intex_b, 0); - intex_c = folder1->GetIndexOf(node_c); - EXPECT_EQ(intex_c, 2); - - - // Sould see at least one syncRecord Modified - using brave_sync::jslib::SyncRecord; - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", - AllRecordsHaveAction(SyncRecord::Action::A_UPDATE))).Times(1); - // BookmarkNodeMoved does not reset "last_send_time" so SendUnsynced - // ignores order change untill unsynced_send_interval passes, - // so here below unsynced_send_interval is 0 - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(/*base::TimeDelta::FromMinutes(0)*/); -} - -TEST_F(BraveBookmarkChangeProcessorTest, DISABLED_MoveNodesBetweenDirs) { - // 1. Create these: - // Other - // Folder1 - // a.com - // Folder2 - // b.com - // 2. Move b.com => Folder1 - - change_processor()->Start(); - - const auto* folder1 = model()->AddFolder(model()->other_node(), 0, - base::ASCIIToUTF16("Folder1")); - - [[maybe_unused]] const auto* node_a = model()->AddURL(folder1, 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - - const auto* folder2 = model()->AddFolder(model()->other_node(), 1, - base::ASCIIToUTF16("Folder2")); - [[maybe_unused]] const auto* node_b = model()->AddURL(folder2, 0, - base::ASCIIToUTF16("B.com - title"), - GURL("https://b.com/")); - - // Send all created objects - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", - RecordsNumber(4))).Times(1); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); -} - -TEST_F(BraveBookmarkChangeProcessorTest, DeleteFolderWithNodes) { - // 1. Create these: - // Other - // Folder1 - // a.com - // b.com - // c.com - // 2. Delete Folder1 - - change_processor()->Start(); - - const BookmarkNode* folder1; - const BookmarkNode* node_a; - const BookmarkNode* node_b; - const BookmarkNode* node_c; - AddSimpleHierarchy(&folder1, &node_a, &node_b, &node_c); - - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", - RecordsNumber(4))).Times(1); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); - - model()->Remove(folder1); - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(1); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); -} - -// Another type of tests with `change_processor()->ApplyChangesFromSyncModel` -// Without any mocks -// May ignore order, because it will be moved into background.js - -void BraveBookmarkChangeProcessorTest::BookmarkCreatedFromSyncImpl() { - change_processor()->Start(); - - RecordsList records; - const char* record_a_object_id = - "121, 194, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130"; - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_a_object_id, - "https://a.com/", - "A.com - title", - "1.1.1.1", "")); - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://b.com/", - "B.com - title", - "1.1.1.2", "")); - - change_processor()->ApplyChangesFromSyncModel(records); - - // Expecting we can find the bookmarks in a model - std::vector nodes_a; - model()->GetNodesByURL(GURL("https://a.com/"), &nodes_a); - ASSERT_EQ(nodes_a.size(), 1u); - const auto* node_a = nodes_a.at(0); - EXPECT_EQ(node_a->url().spec(), "https://a.com/"); - - std::vector nodes_b; - model()->GetNodesByURL(GURL("https://b.com/"), &nodes_b); - ASSERT_EQ(nodes_b.size(), 1u); - const auto* node_b = nodes_b.at(0); - EXPECT_EQ(node_b->url().spec(), "https://b.com/"); - - EXPECT_EQ(node_a->parent(), node_b->parent()); - - int index_a = node_a->parent()->GetIndexOf(node_a); - EXPECT_NE(index_a, -1); - - int index_b = node_b->parent()->GetIndexOf(node_b); - EXPECT_NE(index_b, -1); - - EXPECT_LT(index_a, index_b); - - EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( - bookmarks::prefs::kShowBookmarkBar)); -} - -TEST_F(BraveBookmarkChangeProcessorTest, BookmarkCreatedFromSync) { - BookmarkCreatedFromSyncImpl(); -} - -TEST_F(BraveBookmarkChangeProcessorTest, BookmarkRemovedFromSync) { - BookmarkCreatedFromSyncImpl(); - - RecordsList records; - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_DELETE, - "121, 194, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130", - "https://a.com/", - "A.com - title", - "1.1.1.1", "")); - - change_processor()->ApplyChangesFromSyncModel(records); - std::vector nodes_a; - model()->GetNodesByURL(GURL("https://a.com/"), &nodes_a); - ASSERT_EQ(nodes_a.size(), 0u); - - std::vector nodes_b; - model()->GetNodesByURL(GURL("https://b.com/"), &nodes_b); - ASSERT_EQ(nodes_b.size(), 1u); - const auto* node_b = nodes_b.at(0); - EXPECT_EQ(node_b->url().spec(), "https://b.com/"); -} - -TEST_F(BraveBookmarkChangeProcessorTest, NestedFoldersCreatedFromSync) { - // Create these: - // Other - // Folder1 - // Folder2 - // Folder3 - // a.com - // b.com - // Then verify in a model - - change_processor()->Start(); - - RecordsList records; - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder1", - "1.1.1.1", - "", true, "")); - - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder2", - "1.1.1.1.1", - records.at(0)->objectId, - true, "")); - - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder3", - "1.1.1.1.1.1", - records.at(1)->objectId, - true, "")); - - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://a.com/", - "A.com - title", - "1.1.1.1.1.1.1", - records.at(2)->objectId)); - - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://b.com/", - "B.com - title", - "1.1.1.1.1.1.2", - records.at(2)->objectId)); - - change_processor()->ApplyChangesFromSyncModel(records); - - // Verify the model - ASSERT_EQ(model()->other_node()->child_count(), 1); - const auto* folder1 = model()->other_node()->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder1->GetTitle()), "Folder1"); - - ASSERT_EQ(folder1->child_count(), 1); - const auto* folder2 = folder1->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder2->GetTitle()), "Folder2"); - - ASSERT_EQ(folder2->child_count(), 1); - const auto* folder3 = folder2->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder3->GetTitle()), "Folder3"); - - ASSERT_EQ(folder3->child_count(), 2); - const auto* node_a = folder3->GetChild(0); - EXPECT_EQ(node_a->url().spec(), "https://a.com/"); - const auto* node_b = folder3->GetChild(1); - EXPECT_EQ(node_b->url().spec(), "https://b.com/"); -} - -TEST_F(BraveBookmarkChangeProcessorTest, ChildrenOfPermanentNodesFromSync) { - // Record with 1.x.y order, with hideInToolbar=false and empty - // parent_object_id should go to toolbar node - // Record with 2.x.y order, without parent_object_id should go to mobile_node - // Record with 1.x.y order, with hideInToolbar=true and empty - // parent_object_id should go to other_node - - change_processor()->Start(); - - RecordsList records; - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder1", - "1.1.1", - "", false, "")); - - ASSERT_EQ(model()->bookmark_bar_node()->child_count(), 0); - change_processor()->ApplyChangesFromSyncModel(records); - ASSERT_EQ(model()->bookmark_bar_node()->child_count(), 1); - const auto* folder1 = model()->bookmark_bar_node()->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder1->GetTitle()), "Folder1"); - - records.clear(); - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder2", - "2.1.1", - "", false, "")); - ASSERT_EQ(model()->mobile_node()->child_count(), 0); - change_processor()->ApplyChangesFromSyncModel(records); - ASSERT_EQ(model()->mobile_node()->child_count(), 0); - ASSERT_EQ(model()->bookmark_bar_node()->child_count(), 2); - const auto* folder2 = model()->bookmark_bar_node()->GetChild(1); - EXPECT_EQ(base::UTF16ToUTF8(folder2->GetTitle()), "Folder2"); - - records.clear(); - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder3", - "1.1.1", - "", true, "")); - ASSERT_EQ(model()->other_node()->child_count(), 0); - change_processor()->ApplyChangesFromSyncModel(records); - ASSERT_EQ(model()->other_node()->child_count(), 1); - const auto* folder3 = model()->other_node()->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder3->GetTitle()), "Folder3"); -} - -TEST_F(BraveBookmarkChangeProcessorTest, Utf8FromSync) { - // Send Greek text - const wchar_t* const title_wide = - L"\x03a0\x03b1\x03b3\x03ba\x03cc\x03c3\x03bc\x03b9" - L"\x03bf\x03c2\x0020\x0399\x03c3\x03c4\x03cc\x03c2"; - auto title_wide_len = std::wcslen(title_wide); - - std::string title_utf8; - ASSERT_TRUE(base::WideToUTF8(title_wide, title_wide_len, &title_utf8)); - - base::string16 title_utf16; - ASSERT_TRUE(base::WideToUTF16(title_wide, title_wide_len, &title_utf16)); - - change_processor()->Start(); - - RecordsList records; - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - title_utf8, - "1.1.1", - "", false, "")); - - ASSERT_EQ(model()->bookmark_bar_node()->child_count(), 0); - change_processor()->ApplyChangesFromSyncModel(records); - const auto* folder1 = model()->bookmark_bar_node()->GetChild(0); - EXPECT_EQ(folder1->GetTitle(), title_utf16); -} - -TEST_F(BraveBookmarkChangeProcessorTest, ChangeOrderUnderSameParentFromSync) { - BookmarkCreatedFromSyncImpl(); - - RecordsList records; - const char* record_a_object_id = - "121, 194, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130"; - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_UPDATE, - record_a_object_id, - "https://a.com/", - "A.com - title", - "1.1.1.2", "")); - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_UPDATE, - "", - "https://b.com/", - "B.com - title", - "1.1.1.1", "")); - - change_processor()->ApplyChangesFromSyncModel(records); - - // Expecting we can find the bookmarks in a model - std::vector nodes_a; - model()->GetNodesByURL(GURL("https://a.com/"), &nodes_a); - ASSERT_EQ(nodes_a.size(), 1u); - const auto* node_a = nodes_a.at(0); - EXPECT_EQ(node_a->url().spec(), "https://a.com/"); - - std::vector nodes_b; - model()->GetNodesByURL(GURL("https://b.com/"), &nodes_b); - ASSERT_EQ(nodes_b.size(), 1u); - const auto* node_b = nodes_b.at(0); - EXPECT_EQ(node_b->url().spec(), "https://b.com/"); - - EXPECT_EQ(node_a->parent(), node_b->parent()); - - int index_a = node_a->parent()->GetIndexOf(node_a); - EXPECT_NE(index_a, -1); - - int index_b = node_b->parent()->GetIndexOf(node_b); - EXPECT_NE(index_b, -1); - - EXPECT_LT(index_b, index_a); -} - -::testing::AssertionResult AssertSyncRecordsBookmarkEqual( - const char* left_expr, - const char* right_expr, - SyncRecord* left, - SyncRecord* right) { - DCHECK(left); - DCHECK(right); - - DCHECK(left->has_bookmark()); - DCHECK(right->has_bookmark()); - - #define FAIL_IF_FIELD_NOT_EQUAL(FIELD_NAME) \ - if (left->FIELD_NAME != right->FIELD_NAME) { \ - return ::testing::AssertionFailure() << left_expr << " and " << right_expr \ - << " are not equal by " << #FIELD_NAME << " field (" \ - << left->FIELD_NAME << " vs " << right->FIELD_NAME << ")"; \ - } - - // Ignore action and device_id - FAIL_IF_FIELD_NOT_EQUAL(objectId); - FAIL_IF_FIELD_NOT_EQUAL(GetBookmark().site.location); - FAIL_IF_FIELD_NOT_EQUAL(GetBookmark().site.title); - FAIL_IF_FIELD_NOT_EQUAL(GetBookmark().isFolder); - FAIL_IF_FIELD_NOT_EQUAL(GetBookmark().parentFolderObjectId); - FAIL_IF_FIELD_NOT_EQUAL(GetBookmark().order); - #undef FAIL_IF_FIELD_NOT_EQUAL - - return ::testing::AssertionSuccess(); -} - -TEST_F(BraveBookmarkChangeProcessorTest, GetAllSyncData) { - // This is a resolve operation in terms of sync js lib - // 1) ApplyChangesFromSyncModel - // 2) GetAllSyncData() => (must resolve) => SyncRecordAndExistingList - // 3) Verify all is good - - change_processor()->Start(); - - RecordsList records; - const char* record_a_object_id = - "111, 111, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130"; - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_a_object_id, - "https://a.com/", - "A.com - title", - "1.1.1.1", "")); - const char* record_b_object_id = - "222, 222, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130"; - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_b_object_id, - "https://b.com/", - "B.com - title", - "1.1.1.2", "")); - const char* record_c_object_id = - "33, 33, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130"; - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_c_object_id, - "https://c.com/", - "C.com - title", - "1.1.1.3", "")); - - change_processor()->ApplyChangesFromSyncModel(records); - - RecordsList records_to_resolve; - - records_to_resolve.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_UPDATE, - record_b_object_id, - "https://b.com/", - "B.com - title - modified", - "1.1.1.2", "")); - - records_to_resolve.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_DELETE, - record_c_object_id, - "https://c.com/", - "C.com - title", - "1.1.1.3", "")); - - const char* record_d_object_id = - "44, 44, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130"; - records_to_resolve.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_d_object_id, - "https://d.com/", - "D.com - title", - "1.1.1.4", "")); - - brave_sync::SyncRecordAndExistingList records_and_existing_objects; - change_processor()->GetAllSyncData(records_to_resolve, - &records_and_existing_objects); - ASSERT_EQ(records_and_existing_objects.size(), 3u); - - const auto& pair_at_0 = records_and_existing_objects.at(0); - - EXPECT_PRED_FORMAT2(AssertSyncRecordsBookmarkEqual, - records_to_resolve.at(0).get(), pair_at_0->first.get()); - EXPECT_PRED_FORMAT2(AssertSyncRecordsBookmarkEqual, - records.at(1).get(), pair_at_0->second.get()); - - const auto& pair_at_1 = records_and_existing_objects.at(1); - EXPECT_PRED_FORMAT2(AssertSyncRecordsBookmarkEqual, - records_to_resolve.at(1).get(), pair_at_1->first.get()); - EXPECT_PRED_FORMAT2(AssertSyncRecordsBookmarkEqual, - records.at(2).get(), pair_at_1->second.get()); - - const auto& pair_at_2 = records_and_existing_objects.at(2); - EXPECT_PRED_FORMAT2(AssertSyncRecordsBookmarkEqual, - records_to_resolve.at(2).get(), pair_at_2->first.get()); - EXPECT_EQ(pair_at_2->second.get(), nullptr); -} - -TEST_F(BraveBookmarkChangeProcessorTest, TitleCustomTitle) { - // Should be able to create folder when title = "" and customTitle != "" - // Create these: - // Other - // Folder1 (use title) - // Folder2 (use customTitle) - // Then verify in a model - - change_processor()->Start(); - - RecordsList records; - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder1", - "1.1.1.1", - "", true, "")); - - records.push_back(SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "1.1.1.1.1", - records.at(0)->objectId, - true, - "Folder2")); - - change_processor()->ApplyChangesFromSyncModel(records); - - // Verify the model - ASSERT_EQ(model()->other_node()->child_count(), 1); - const auto* folder1 = model()->other_node()->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder1->GetTitle()), "Folder1"); - - ASSERT_EQ(folder1->child_count(), 1); - const auto* folder2 = folder1->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder2->GetTitle()), "Folder2"); -} - -TEST_F(BraveBookmarkChangeProcessorTest, BookmarkFromMobileGoesToToolbar) { - change_processor()->Start(); - auto a_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://a.com/", - "A.com - title", - "2.1.1", - ""); - RecordsList records; - records.push_back(std::move(a_record)); - change_processor()->ApplyChangesFromSyncModel(records); - // Verify the model, now we should find the folder and the nodes - EXPECT_EQ(model()->other_node()->child_count(), 0); - EXPECT_EQ(model()->mobile_node()->child_count(), 0); - ASSERT_EQ(model()->bookmark_bar_node()->child_count(), 1); - - const auto* node_a = model()->bookmark_bar_node()->GetChild(0); - EXPECT_EQ(node_a->url().spec(), "https://a.com/"); -} - -TEST_F(BraveBookmarkChangeProcessorTest, ItemAheadOfFolder) { - // Create these: - // Other - // Folder1 - // a.com - // b.com - // With a broken sequence - // Then verify in a model - - change_processor()->Start(); - - auto folder1_record = SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder1", - "1.1.1.1.1.1", - "", true, ""); - - auto a_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://a.com/", - "A.com - title", - "1.1.1.1.1.1.1", - folder1_record->objectId); - - auto b_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://b.com/", - "B.com - title", - "1.1.1.1.1.1.2", - folder1_record->objectId); - - RecordsList records; - records.push_back(std::move(a_record)); - records.push_back(std::move(b_record)); - - change_processor()->ApplyChangesFromSyncModel(records); - - // Verify the model, for now we should not find anything - EXPECT_EQ(model()->GetMostRecentlyAddedUserNodeForURL(GURL("https://a.com/")), - nullptr); - EXPECT_EQ(model()->GetMostRecentlyAddedUserNodeForURL(GURL("https://b.com/")), - nullptr); - - RecordsList records2; - records2.push_back(std::move(folder1_record)); - change_processor()->ApplyChangesFromSyncModel(records2); - - // Verify the model, now we should find the folder and the nodes - ASSERT_EQ(model()->other_node()->child_count(), 1); - const auto* folder1 = model()->other_node()->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder1->GetTitle()), "Folder1"); - - ASSERT_EQ(folder1->child_count(), 2); - const auto* node_a = folder1->GetChild(0); - EXPECT_EQ(node_a->url().spec(), "https://a.com/"); - const auto* node_b = folder1->GetChild(1); - EXPECT_EQ(node_b->url().spec(), "https://b.com/"); - EXPECT_FALSE(GetPendingNodeRoot()->IsVisible()); -} - -TEST_F(BraveBookmarkChangeProcessorTest, ItemAheadOfFolderAgressive) { - // Send these: - // Other - // Folder1 - // Folder2 - // Folder3 - // a.com - // b.com - // In a backwards order: - // b.com, a.com, - // Folder2, - // Folder3, - // Folder1 - // Then verify in a model - - change_processor()->Start(); - - auto folder1_record = SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder1", - "1.1.1.1", - "", true, ""); - - auto folder2_record = SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder2", - "1.1.1.1.1", - folder1_record->objectId, - true, ""); - - auto folder3_record = SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder3", - "1.1.1.1.1.1", - folder2_record->objectId, - true, ""); - - auto a_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://a.com/", - "A.com - title", - "1.1.1.1.1.1.1", - folder3_record->objectId); - - auto b_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://b.com/", - "B.com - title", - "1.1.1.1.1.1.2", - folder3_record->objectId); - - // Send in a backwards order - { - RecordsList records1; - records1.push_back(std::move(b_record)); - records1.push_back(std::move(a_record)); - change_processor()->ApplyChangesFromSyncModel(records1); - - // Verify the model, for now we should not find anything - EXPECT_EQ( - model()->GetMostRecentlyAddedUserNodeForURL(GURL("https://a.com/")), - nullptr); - EXPECT_EQ( - model()->GetMostRecentlyAddedUserNodeForURL(GURL("https://b.com/")), - nullptr); - } - - { - RecordsList records2; - records2.push_back(std::move(folder2_record)); - change_processor()->ApplyChangesFromSyncModel(records2); - EXPECT_EQ( - model()->GetMostRecentlyAddedUserNodeForURL(GURL("https://a.com/")), - nullptr); - EXPECT_EQ( - model()->GetMostRecentlyAddedUserNodeForURL(GURL("https://b.com/")), - nullptr); - } - - { - RecordsList records3; - records3.push_back(std::move(folder3_record)); - change_processor()->ApplyChangesFromSyncModel(records3); - EXPECT_EQ( - model()->GetMostRecentlyAddedUserNodeForURL(GURL("https://a.com/")), - nullptr); - EXPECT_EQ( - model()->GetMostRecentlyAddedUserNodeForURL(GURL("https://b.com/")), - nullptr); - // TODO(alexeyb): Verify there are some records attached to - // "Pending Bookmarks" node - } - - { - RecordsList records4; - records4.push_back(std::move(folder1_record)); - change_processor()->ApplyChangesFromSyncModel(records4); - } - - // Verify now all is as expected - ASSERT_EQ(model()->other_node()->child_count(), 1); - const auto* folder1 = model()->other_node()->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder1->GetTitle()), "Folder1"); - - ASSERT_EQ(folder1->child_count(), 1); - const auto* folder2 = folder1->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder2->GetTitle()), "Folder2"); - - ASSERT_EQ(folder2->child_count(), 1); - const auto* folder3 = folder2->GetChild(0); - EXPECT_EQ(base::UTF16ToUTF8(folder3->GetTitle()), "Folder3"); - - ASSERT_EQ(folder3->child_count(), 2); - const auto* node_a = folder3->GetChild(0); - EXPECT_EQ(node_a->url().spec(), "https://a.com/"); - const auto* node_b = folder3->GetChild(1); - EXPECT_EQ(node_b->url().spec(), "https://b.com/"); - EXPECT_FALSE(GetPendingNodeRoot()->IsVisible()); -} - -TEST_F(BraveBookmarkChangeProcessorTest, - ItemAheadOfFolderRequireStrictSorting) { - // Send these: - // Other - // +--0-1.com 1.1.1.1 - // +--Folder1 1.1.1.2 - // | +--1-1.com 1.1.1.2.1 - // | +--Folder2 1.1.1.2.2 - // | | +--2-1.com 1.1.1.2.2.1 - // | | +--Folder3 1.1.1.2.2.2 - // | | | +--a.com 1.1.1.2.2.2.1 - // | | | +--b.com 1.1.1.2.2.2.2 - // | | +--2-2.com 1.1.1.2.2.3 - // | | +--2-3.com 1.1.1.2.2.4 - // | +--1-2.com 1.1.1.2.3 - // +--0-2.com 1.1.1.3 - // - // In an order: - // Folder2, 2-1.com, Folder3, a.com, b.com - // 2-3.com, 2-2.com, 1-2.com - // Folder1, 0-1.com, 0-2.com, 1-1.com - // Then verify in a model - - change_processor()->Start(); - - auto folder1_record = SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder1", - "1.1.1.2", - "", true, ""); - - auto folder2_record = SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder2", - "1.1.1.2.2", - folder1_record->objectId, - true, ""); - - auto folder3_record = SimpleFolderSyncRecord( - SyncRecord::Action::A_CREATE, - "Folder3", - "1.1.1.2.2.2", - folder2_record->objectId, - true, ""); - - auto _0_1_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://0-1.com/", - "0-1.com - title", - "1.1.1.1", - ""); - auto _0_2_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://0-2.com/", - "0-2.com - title", - "1.1.1.3", - ""); - - auto _1_1_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://1-1.com/", - "1-1.com - title", - "1.1.1.2.1", - folder1_record->objectId); - auto _1_2_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://1-2.com/", - "1-2.com - title", - "1.1.1.2.3", - folder1_record->objectId); - - auto _2_1_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://2-1.com/", - "2-1.com - title", - "1.1.1.2.2.1", - folder2_record->objectId); - auto _2_2_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://2-2.com/", - "2-2.com - title", - "1.1.1.2.2.3", - folder2_record->objectId); - auto _2_3_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://2-3.com/", - "2-3.com - title", - "1.1.1.2.2.4", - folder2_record->objectId); - - auto a_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://a.com/", - "A.com - title", - "1.1.1.1.1.1.1", - folder3_record->objectId); - - auto b_record = SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - "", - "https://b.com/", - "B.com - title", - "1.1.1.1.1.1.2", - folder3_record->objectId); - - // Send in an order - { - RecordsList records1; - records1.push_back(std::move(folder2_record)); - records1.push_back(std::move(_2_1_record)); - records1.push_back(std::move(folder3_record)); - records1.push_back(std::move(a_record)); - records1.push_back(std::move(b_record)); - change_processor()->ApplyChangesFromSyncModel(records1); - } - - { - RecordsList records2; - // 2-3 before 2-2 is important - records2.push_back(std::move(_2_3_record)); - records2.push_back(std::move(_2_2_record)); - records2.push_back(std::move(_1_2_record)); - change_processor()->ApplyChangesFromSyncModel(records2); - } - - { - RecordsList records3; - records3.push_back(std::move(folder1_record)); - records3.push_back(std::move(_0_1_record)); - records3.push_back(std::move(_0_2_record)); - records3.push_back(std::move(_1_1_record)); - - change_processor()->ApplyChangesFromSyncModel(records3); - } - - // Verify now all is as expected - ASSERT_EQ(model()->other_node()->child_count(), 3); - const auto* node_0_1 = model()->other_node()->GetChild(0); - EXPECT_EQ(node_0_1->url().spec(), "https://0-1.com/"); - const auto* folder1 = model()->other_node()->GetChild(1); - EXPECT_EQ(base::UTF16ToUTF8(folder1->GetTitle()), "Folder1"); - const auto* node_0_2 = model()->other_node()->GetChild(2); - EXPECT_EQ(node_0_2->url().spec(), "https://0-2.com/"); - - ASSERT_EQ(folder1->child_count(), 3); - const auto* node_1_1 = folder1->GetChild(0); - EXPECT_EQ(node_1_1->url().spec(), "https://1-1.com/"); - const auto* folder2 = folder1->GetChild(1); - EXPECT_EQ(base::UTF16ToUTF8(folder2->GetTitle()), "Folder2"); - const auto* node_1_2 = folder1->GetChild(2); - EXPECT_EQ(node_1_2->url().spec(), "https://1-2.com/"); - - ASSERT_EQ(folder2->child_count(), 4); - const auto* node_2_1 = folder2->GetChild(0); - EXPECT_EQ(node_2_1->url().spec(), "https://2-1.com/"); - const auto* folder3 = folder2->GetChild(1); - EXPECT_EQ(base::UTF16ToUTF8(folder3->GetTitle()), "Folder3"); - // Below fails if GetIndex uses tree iteartor - const auto* node_2_2 = folder2->GetChild(2); - EXPECT_EQ(node_2_2->url().spec(), "https://2-2.com/"); - - ASSERT_EQ(folder3->child_count(), 2); - const auto* node_a = folder3->GetChild(0); - EXPECT_EQ(node_a->url().spec(), "https://a.com/"); - const auto* node_b = folder3->GetChild(1); - EXPECT_EQ(node_b->url().spec(), "https://b.com/"); - EXPECT_FALSE(GetPendingNodeRoot()->IsVisible()); -} - -TEST_F(BraveBookmarkChangeProcessorTest, IgnoreRapidCreateDelete) { - change_processor()->Start(); - - const auto* node_a = model()->AddURL(model()->other_node(), 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - model()->Remove(node_a); - - EXPECT_EQ(change_processor()->GetDeletedNodeRoot()->child_count(), 0); - - // Expect there will be no calls, because no any records to send - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(0); - change_processor()->SendUnsynced(); -} - -TEST_F(BraveBookmarkChangeProcessorTest, IgnoreMetadataSet) { - change_processor()->Start(); - - const auto* node_a = model()->AddURL(model()->other_node(), 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); - - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(1); - change_processor()->SendUnsynced(); - - model()->SetNodeMetaInfo(node_a, "last_visited", "2019"); - // Not interested in metadata changes, expecting no calls - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(0); - change_processor()->SendUnsynced(); -} - -TEST_F(BraveBookmarkChangeProcessorTest, MigrateOrdersForPermanentNodes) { - EXPECT_EQ(change_processor()->GetPermanentNodeIndex( - model()->bookmark_bar_node()), 1); - EXPECT_EQ(change_processor()->GetPermanentNodeIndex( - model()->other_node()), 2); - - using brave_sync::BookmarkChangeProcessor; - EXPECT_EQ(BookmarkChangeProcessor::FindMigrateSubOrderLength("1.0.0.1"), 5); - EXPECT_EQ(BookmarkChangeProcessor::FindMigrateSubOrderLength("1.12.0.1"), 6); - EXPECT_EQ(BookmarkChangeProcessor::FindMigrateSubOrderLength("1.12.1.1"), -1); - EXPECT_EQ(BookmarkChangeProcessor::FindMigrateSubOrderLength("1.0.10."), -1); - EXPECT_EQ(BookmarkChangeProcessor::FindMigrateSubOrderLength("1.0.1."), -1); - - sync_prefs()->SetBookmarksBaseOrder("1.0."); - - change_processor()->Start(); - - EXPECT_EQ(sync_prefs()->GetMigratedBookmarksVersion(), 0); - - const auto* node_OB = model()->AddURL(model()->other_node(), 0, - base::ASCIIToUTF16("OB item - title"), - GURL("https://ob_item.com/")); - const_cast(node_OB)->SetMetaInfo( - "order", "1.0.0.1"); - - const auto* node_BB = model()->AddURL(model()->bookmark_bar_node(), 0, - base::ASCIIToUTF16("BB item - title"), - GURL("https://bb_item.com/")); - const_cast(node_BB)->SetMetaInfo( - "order", "1.0.0.1"); - - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(1); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(1); - change_processor()->SendUnsynced(); - - std::string OB_order, BB_order; - node_OB->GetMetaInfo("order", &OB_order); - node_BB->GetMetaInfo("order", &BB_order); - - EXPECT_EQ(BB_order, "1.0.1.1"); - EXPECT_EQ(OB_order, "1.0.2.1"); - - EXPECT_EQ(sync_prefs()->GetMigratedBookmarksVersion(), 1); -} - -TEST_F(BraveBookmarkChangeProcessorTest, ApplyOrder) { - BookmarkCreatedFromSyncImpl(); - const char* record_a_object_id = - "121, 194, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130"; - const char* new_order = "1.1.1.3"; - change_processor()->ApplyOrder(record_a_object_id, new_order); - std::vector nodes_a; - model()->GetNodesByURL(GURL("https://a.com/"), &nodes_a); - ASSERT_EQ(nodes_a.size(), 1u); - const auto* node_a = nodes_a.at(0); - std::string order; - node_a->GetMetaInfo("order", &order); - EXPECT_EQ(order, new_order); -} - -namespace { - -const bookmarks::BookmarkNode* GetSingleNodeByUrl( - bookmarks::BookmarkModel* model, const std::string& url) { - std::vector nodes; - model->GetNodesByURL(GURL(url), &nodes); - size_t nodes_size = nodes.size(); - CHECK_EQ(nodes_size, 1u); - const bookmarks::BookmarkNode* node = nodes.at(0); - return node; -} - -} // namespace - -TEST_F(BraveBookmarkChangeProcessorTest, SyncTimestampMetaUpdateWay) { - // Should update "sync_timestamp": - // "get-existing-objects" => model => "resolve-sync-records" - // (GetAllSyncData) - // - // Should not update "sync_timestamp": - // "resolved-sync-records" => model - // (ApplyChangesFromSyncModel) - - change_processor()->Start(); - - RecordsList records; - const char* record_b_object_id = - "222, 222, 37, 61, 199, 11, 166, 234, " - "214, 197, 45, 215, 241, 206, 219, 130"; - records.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_b_object_id, - "https://b.com/", - "B.com - title", - "1.1.1.2", "")); - - change_processor()->ApplyChangesFromSyncModel(records); - - std::string node_b_sync_timestamp; - GetSingleNodeByUrl(model(), "https://b.com/")->GetMetaInfo( - "sync_timestamp", &node_b_sync_timestamp); - EXPECT_EQ(node_b_sync_timestamp, ""); - - RecordsList records_to_resolve; - records_to_resolve.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_UPDATE, - record_b_object_id, - "https://b.com/", - "B.com - title - modified", - "1.1.1.2", "")); - auto timestamp_resolve = base::Time::Now(); - records_to_resolve.at(0)->syncTimestamp = timestamp_resolve; - - brave_sync::SyncRecordAndExistingList records_and_existing_objects; - change_processor()->GetAllSyncData(records_to_resolve, - &records_and_existing_objects); - GetSingleNodeByUrl(model(), "https://b.com/")->GetMetaInfo( - "sync_timestamp", &node_b_sync_timestamp); - - EXPECT_EQ(node_b_sync_timestamp, - std::to_string(timestamp_resolve.ToJsTime())); -} - -namespace { - -size_t g_overridden_minutes = 0; -std::unique_ptr OverrideForMinutes( - int overridden_minutes) { - g_overridden_minutes = overridden_minutes; - return std::make_unique( - []() { - return base::subtle::TimeNowIgnoringOverride() + - base::TimeDelta::FromMinutes(g_overridden_minutes); - }, - nullptr, - nullptr); -} - -} // namespace - -TEST_F(BraveBookmarkChangeProcessorTest, ExponentialResend) { - change_processor()->Start(); - bookmarks::AddIfNotBookmarked(model(), - GURL("https://a.com/"), - base::ASCIIToUTF16("A.com")); - - std::string send_retry_number; - GetSingleNodeByUrl(model(), "https://a.com/")->GetMetaInfo( - "send_retry_number", &send_retry_number); - EXPECT_TRUE(send_retry_number.empty()); - - int expected_send_retry_number = 0; - - std::string record_a_object_id; - - static const std::vector exponential_waits = - brave_sync::BookmarkChangeProcessor::GetExponentialWaitsForTests(); - const int max_send_retries = exponential_waits.size(); - std::set should_sent_at; - size_t current_sum = 0; - should_sent_at.insert(0); - for (size_t j = 0; j < exponential_waits.size(); ++j) { - current_sum += exponential_waits[j]; - should_sent_at.insert(current_sum); - } - auto contains = [](const std::set& set, int val) { - return set.find(val) != set.end(); - }; - // Following statemets are correct only if - // BookmarkChangeProcessor::kExponentialWaits is {10, 20, 40, 80} - EXPECT_TRUE(contains(should_sent_at, 0)); - EXPECT_TRUE(contains(should_sent_at, 10)); - EXPECT_TRUE(contains(should_sent_at, 30)); - EXPECT_TRUE(contains(should_sent_at, 70)); - EXPECT_TRUE(contains(should_sent_at, 150)); - size_t i = 0; - for (; i <= 151; ++i) { - auto time_override = OverrideForMinutes(i); - bool is_send_expected = contains(should_sent_at, i); - int expect_call_times = is_send_expected ? 1 : 0; - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times( - expect_call_times); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(expect_call_times); - change_processor()->SendUnsynced(); - - if (is_send_expected) { - ++expected_send_retry_number; - if (expected_send_retry_number > max_send_retries) - expected_send_retry_number = max_send_retries; - send_retry_number.clear(); - GetSingleNodeByUrl(model(), "https://a.com/")->GetMetaInfo( - "send_retry_number", &send_retry_number); - EXPECT_EQ(send_retry_number, - base::NumberToString(expected_send_retry_number)); - } - - // On first send object_id is assigned - if (i == 0) { - GetSingleNodeByUrl(model(), "https://a.com/")->GetMetaInfo( - "object_id", &record_a_object_id); - EXPECT_NE(record_a_object_id.length(), 0u); - } - } - - // resolve to confirm records - RecordsList records_to_resolve; - records_to_resolve.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_a_object_id, - "https://a.com/", - "A.com", - "1.1.1.1", "")); - auto timestamp_resolve = base::Time::Now(); - records_to_resolve.at(0)->syncTimestamp = timestamp_resolve; - brave_sync::SyncRecordAndExistingList records_and_existing_objects; - change_processor()->GetAllSyncData(records_to_resolve, - &records_and_existing_objects); - - // Ensure "send_retry_number" metainfo is cleared - send_retry_number.clear(); - GetSingleNodeByUrl(model(), "https://a.com/")->GetMetaInfo( - "send_retry_number", &send_retry_number); - EXPECT_TRUE(send_retry_number.empty()); - - // and now expect to see records never sent, because bookmark was comfirmed - // as seen on server and was not changed locally - for (; i <= 302; ++i) { - auto time_override = OverrideForMinutes(i); - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(0); - EXPECT_CALL(*sync_client(), ClearOrderMap()).Times(0); - change_processor()->SendUnsynced(); - } -} diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index 0bd545816251..0936f0d584ee 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -38,9 +38,9 @@ void ReCalculateOrder(bookmarks::BookmarkModel* model, parent->GetMetaInfo("order", &parent_order); if (parent_order.empty()) { ReCalculateOrder(model, node->parent()); - } else { - SetOrder(model, node, parent_order); + parent->GetMetaInfo("order", &parent_order); } + SetOrder(model, node, parent_order); } uint64_t GetIndexByOrder(const std::string& record_order) { @@ -86,26 +86,30 @@ void AddBraveMetaInfo( node->GetMetaInfo("sync_timestamp", &sync_timestamp); if (sync_timestamp.empty()) { sync_timestamp = std::to_string(base::Time::Now().ToJsTime()); + model->SetNodeMetaInfo(node, "sync_timestamp", sync_timestamp); } DCHECK(!sync_timestamp.empty()); - model->SetNodeMetaInfo(node, "sync_timestamp", sync_timestamp); } uint64_t GetIndex(const bookmarks::BookmarkNode* parent, const bookmarks::BookmarkNode* src) { + DCHECK(parent); + DCHECK(src); int index = 0; std::string src_order; src->GetMetaInfo("order", &src_order); DCHECK(!src_order.empty()); index = GetIndexByOrder(src_order); - const bookmarks::BookmarkNode* node = parent->GetChild(index); - if (node) { - std::string node_order; - node->GetMetaInfo("order", &node_order); + if (index < parent->child_count()) { + const bookmarks::BookmarkNode* node = parent->GetChild(index); + if (node) { + std::string node_order; + node->GetMetaInfo("order", &node_order); - if (!node_order.empty() && - CompareOrder(node_order, src_order)) - return index + 1; + DCHECK(!node_order.empty()); + if (CompareOrder(node_order, src_order)) + return index + 1; + } } return index; } diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h index bd236811976f..795df3430003 100644 --- a/components/brave_sync/syncer_helper.h +++ b/components/brave_sync/syncer_helper.h @@ -19,6 +19,8 @@ void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, bookmarks::BookmarkModel* bookmark_model, bool has_new_parent); + +// |src| is the node which is about to be inserted into |parent| uint64_t GetIndex(const bookmarks::BookmarkNode* parent, const bookmarks::BookmarkNode* src); diff --git a/components/brave_sync/syncer_helper_unittest.cc b/components/brave_sync/syncer_helper_unittest.cc new file mode 100644 index 000000000000..9ab0ab733896 --- /dev/null +++ b/components/brave_sync/syncer_helper_unittest.cc @@ -0,0 +1,311 @@ +/* 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 +#include +#include +#include + +#include "base/files/scoped_temp_dir.h" +#include "base/strings/string_number_conversions.h" +#include "base/strings/utf_string_conversions.h" +#include "brave/components/brave_sync/syncer_helper.h" +#include "brave/components/brave_sync/test_util.h" +#include "chrome/browser/bookmarks/bookmark_model_factory.h" +#include "chrome/browser/profiles/profile.h" +#include "components/bookmarks/browser/bookmark_model.h" +#include "components/bookmarks/browser/bookmark_utils.h" +#include "components/bookmarks/common/bookmark_pref_names.h" +#include "components/bookmarks/test/test_bookmark_client.h" +#include "components/prefs/pref_service.h" +#include "content/public/test/test_browser_thread_bundle.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using testing::_; +using testing::AtLeast; + +using bookmarks::BookmarkClient; +using bookmarks::BookmarkModel; +using bookmarks::BookmarkNode; + +namespace brave_sync { + +class SyncerHelperTest : public testing::Test { + public: + SyncerHelperTest() {} + ~SyncerHelperTest() override {} + + protected: + void SetUp() override { + EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); + + profile_ = CreateBraveSyncProfile(temp_dir_.GetPath()); + EXPECT_TRUE(profile_.get() != NULL); + + BookmarkModelFactory::GetInstance()->SetTestingFactory( + profile_.get(), + base::BindRepeating(&BuildFakeBookmarkModelForTests)); + + model_ = BookmarkModelFactory::GetForBrowserContext( + Profile::FromBrowserContext(profile_.get())); + + EXPECT_NE(bookmark_client(), nullptr); + EXPECT_NE(model(), nullptr); + + // SetPermanentNodesOrder + model_->SetNodeMetaInfo(model_->bookmark_bar_node(), "order", "1.0.1"); + + model_->SetNodeMetaInfo(model_->other_node(), "order", "1.0.2"); + + } + + void TearDown() override { + profile_.reset(); + } + + BookmarkClient* bookmark_client() { return model_->client(); } + BookmarkModel* model() { return model_; } + + private: + // Need this as a very first member to run tests in UI thread + // When this is set, class should not install any other MessageLoops, like + // base::test::ScopedTaskEnvironment + content::TestBrowserThreadBundle thread_bundle_; + + BookmarkModel* model_; // Not owns + std::unique_ptr profile_; + base::ScopedTempDir temp_dir_; +}; + +TEST_F(SyncerHelperTest, AddBraveMetaInfoCreateOrUpdate) { + std::string order; + std::string sync_timestamp; + const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("Folder1")); + AddBraveMetaInfo(folder1, model(), false); + folder1->GetMetaInfo("order", &order); + EXPECT_EQ(order, "1.0.1.1"); + std::string folder1_id; + folder1->GetMetaInfo("object_id", &folder1_id); + EXPECT_TRUE(!folder1_id.empty()); + std::string folder1_parent_id; + folder1->GetMetaInfo("parent_object_id", &folder1_parent_id); + EXPECT_TRUE(folder1_parent_id.empty()); + folder1->GetMetaInfo("sync_timestamp", &sync_timestamp); + EXPECT_TRUE(!sync_timestamp.empty()); + + const auto *node_a = model()->AddURL(folder1, 0, + base::ASCIIToUTF16("A.com - title"), + GURL("https://a.com/")); + order.clear(); + sync_timestamp.clear(); + AddBraveMetaInfo(node_a, model(), false); + node_a->GetMetaInfo("order", &order); + EXPECT_EQ(order, "1.0.1.1.1"); + std::string node_a_id; + node_a->GetMetaInfo("object_id", &node_a_id); + EXPECT_TRUE(!node_a_id.empty()); + std::string node_a_parent_id; + node_a->GetMetaInfo("parent_object_id", &node_a_parent_id); + EXPECT_EQ(node_a_parent_id, folder1_id); + node_a->GetMetaInfo("sync_timestamp", &sync_timestamp); + EXPECT_TRUE(!sync_timestamp.empty()); + + // Update + order.clear(); + node_a_id.clear(); + node_a_parent_id.clear(); + model()->SetURL(node_a, GURL("https://a-m.com/")); + AddBraveMetaInfo(node_a, model(), false); + node_a->GetMetaInfo("order", &order); + EXPECT_EQ(order, "1.0.1.1.1"); + node_a->GetMetaInfo("object_id", &node_a_id); + EXPECT_TRUE(!node_a_id.empty()); + node_a->GetMetaInfo("parent_object_id", &node_a_parent_id); + EXPECT_EQ(node_a_parent_id, folder1_id); + std::string new_sync_timestamp; + node_a->GetMetaInfo("sync_timestamp", &new_sync_timestamp); + EXPECT_EQ(new_sync_timestamp, sync_timestamp); +} + +TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeMoved) { + const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("Folder1")); + AddBraveMetaInfo(folder1, model(), false); + const auto *node_a = model()->AddURL(folder1, 0, + base::ASCIIToUTF16("A.com - title"), + GURL("https://a.com/")); + AddBraveMetaInfo(node_a, model(), false); + model()->Move(node_a, model()->bookmark_bar_node(), 1); + AddBraveMetaInfo(node_a, model(), true); + + std::string order; + node_a->GetMetaInfo("order", &order); + EXPECT_EQ(order, "1.0.1.2"); + std::string node_a_id; + node_a->GetMetaInfo("object_id", &node_a_id); + EXPECT_TRUE(!node_a_id.empty()); + std::string node_a_parent_id; + node_a->GetMetaInfo("parent_object_id", &node_a_parent_id); + EXPECT_TRUE(node_a_parent_id.empty()); + std::string sync_timestamp; + node_a->GetMetaInfo("sync_timestamp", &sync_timestamp); + EXPECT_TRUE(!sync_timestamp.empty()); +} + +TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeChildrenReordered) { + const auto *node_a = model()->AddURL(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("A.com - title"), + GURL("https://a.com/")); + AddBraveMetaInfo(node_a, model(), false); + const auto *node_b = model()->AddURL(model()->bookmark_bar_node(), 1, + base::ASCIIToUTF16("B.com - title"), + GURL("https://b.com/")); + AddBraveMetaInfo(node_b, model(), false); + const auto *node_c = model()->AddURL(model()->bookmark_bar_node(), 2, + base::ASCIIToUTF16("C.com - title"), + GURL("https://c.com/")); + AddBraveMetaInfo(node_c, model(), false); + std::string order_a; + std::string order_b; + std::string order_c; + node_a->GetMetaInfo("order", &order_a); + EXPECT_EQ(order_a, "1.0.1.1"); + node_b->GetMetaInfo("order", &order_b); + EXPECT_EQ(order_b, "1.0.1.2"); + node_c->GetMetaInfo("order", &order_c); + EXPECT_EQ(order_c, "1.0.1.3"); + + model()->Move(node_c, model()->bookmark_bar_node(), 0); + AddBraveMetaInfo(node_a, model(), false); + AddBraveMetaInfo(node_b, model(), false); + AddBraveMetaInfo(node_c, model(), false); + + order_a.clear(); + order_b.clear(); + order_c.clear(); + + node_a->GetMetaInfo("order", &order_a); + EXPECT_EQ(order_a, "1.0.1.2"); + node_b->GetMetaInfo("order", &order_b); + EXPECT_EQ(order_b, "1.0.1.3"); + node_c->GetMetaInfo("order", &order_c); + EXPECT_EQ(order_c, "1.0.1.1"); +} + +TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeMovedReordered) { + const auto *node_a = model()->AddURL(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("A.com - title"), + GURL("https://a.com/")); + AddBraveMetaInfo(node_a, model(), false); + const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 1, + base::ASCIIToUTF16("Folder1")); + AddBraveMetaInfo(folder1, model(), false); + const auto *node_b = model()->AddURL(folder1, 0, + base::ASCIIToUTF16("B.com - title"), + GURL("https://b.com/")); + AddBraveMetaInfo(node_b, model(), false); + const auto *node_c = model()->AddURL(folder1, 1, + base::ASCIIToUTF16("C.com - title"), + GURL("https://c.com/")); + AddBraveMetaInfo(node_c, model(), false); + + std::string order_a; + std::string order_b; + std::string order_c; + std::string order_folder1; + node_a->GetMetaInfo("order", &order_a); + EXPECT_EQ(order_a, "1.0.1.1"); + node_b->GetMetaInfo("order", &order_b); + EXPECT_EQ(order_b, "1.0.1.2.1"); + node_c->GetMetaInfo("order", &order_c); + EXPECT_EQ(order_c, "1.0.1.2.2"); + folder1->GetMetaInfo("order", &order_folder1); + EXPECT_EQ(order_folder1, "1.0.1.2"); + + model()->Move(node_a, folder1, 0); + AddBraveMetaInfo(node_a, model(), true); + AddBraveMetaInfo(folder1, model(), false); + AddBraveMetaInfo(node_b, model(), false); + AddBraveMetaInfo(node_c, model(), false); + + order_a.clear(); + order_b.clear(); + order_c.clear(); + order_folder1.clear(); + + node_a->GetMetaInfo("order", &order_a); + EXPECT_EQ(order_a, "1.0.1.1.1"); + node_b->GetMetaInfo("order", &order_b); + EXPECT_EQ(order_b, "1.0.1.1.2"); + node_c->GetMetaInfo("order", &order_c); + EXPECT_EQ(order_c, "1.0.1.1.3"); + folder1->GetMetaInfo("order", &order_folder1); + EXPECT_EQ(order_folder1, "1.0.1.1"); +} + +TEST_F(SyncerHelperTest, GetIndexInPermanentNodes) { + BookmarkNode node(GURL("https://brave.com")); + node.SetMetaInfo("order", "1.0.1.1"); + EXPECT_EQ(GetIndex(model()->bookmark_bar_node(), &node), 0u); + + node.SetMetaInfo("order", "1.0.2.1"); + EXPECT_EQ(GetIndex(model()->other_node(), &node), 0u); + + const auto* node_a = model()->AddURL(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("a.com"), + GURL("https://a.com/")); + // compare device id + model()->SetNodeMetaInfo(node_a, "order", "1.1.1.1"); + node.SetMetaInfo("order", "1.0.1.1"); + EXPECT_EQ(GetIndex(model()->bookmark_bar_node(), &node), 0u); + model()->SetNodeMetaInfo(node_a, "order", "1.0.1.1"); + node.SetMetaInfo("order", "1.1.1.1"); + EXPECT_EQ(GetIndex(model()->bookmark_bar_node(), &node), 1u); + + // compare platform id + model()->SetNodeMetaInfo(node_a, "order", "2.0.1.1"); + node.SetMetaInfo("order", "1.0.1.1"); + EXPECT_EQ(GetIndex(model()->bookmark_bar_node(), &node), 0u); + model()->SetNodeMetaInfo(node_a, "order", "1.0.1.1"); + node.SetMetaInfo("order", "2.0.1.1"); + EXPECT_EQ(GetIndex(model()->bookmark_bar_node(), &node), 1u); +} + +TEST_F(SyncerHelperTest, GetIndexMoreChildren) { + for (int i = 0; i < 10; ++i) { + const auto* node_a = model()->AddURL(model()->bookmark_bar_node(), i, + base::ASCIIToUTF16("a.com"), + GURL("https://a.com/")); + std::string order = "1.1.1." + base::NumberToString(i); + model()->SetNodeMetaInfo(node_a, "order", order); + } + // inserted as 10th child + BookmarkNode node(GURL("https://brave.com")); + node.SetMetaInfo("order", "1.0.1.10"); + EXPECT_EQ(GetIndex(model()->bookmark_bar_node(), &node), 9u); + node.SetMetaInfo("order", "1.1.1.10"); + EXPECT_EQ(GetIndex(model()->bookmark_bar_node(), &node), 10u); +} + +TEST_F(SyncerHelperTest, GetIndexInFolder) { + const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("Folder1")); + model()->SetNodeMetaInfo(folder1, "order", "1.0.1.1"); + BookmarkNode node(GURL("https://brave.com")); + node.SetMetaInfo("order", "1.0.1.1.1"); + EXPECT_EQ(GetIndex(folder1, &node), 0u); + + // appended at the end + const auto* node_a = model()->AddURL(folder1, 0, + base::ASCIIToUTF16("a.com"), + GURL("https://a.com/")); + model()->SetNodeMetaInfo(node_a, "order", "1.0.1.1.1"); + node.SetMetaInfo("order", "1.0.1.1.2"); + EXPECT_EQ(GetIndex(folder1, &node), 1u); +} + +} // namespace brave_sync diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 6a24d8a69a5f..1267e3b78aa2 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..3b4110a5e4803b7ede262ab416376fda0879b94d 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..06d371a7136f7f287db0bdae8fd18ae7de4656c1 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -14,19 +14,11 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..3b4110a5e4803b7ede262ab416376fda // Acquire a scoped write lock via a transaction. syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); -+ bookmark_model_->RemoveObserver(this); ++ ScopedPauseObserver pause(bookmark_model_, this); if (sync_id != syncer::kInvalidId) { UpdateSyncNode( node, bookmark_model_, &trans, model_associator_, error_handler()); -@@ -257,6 +259,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { - model_associator_, - error_handler()); - } -+ bookmark_model_->AddObserver(this); - } - - if (syncer::kInvalidId != sync_id) { -@@ -383,7 +386,8 @@ int64_t BookmarkChangeProcessor::UpdateSyncNode( +@@ -383,7 +385,8 @@ int64_t BookmarkChangeProcessor::UpdateSyncNode( void BookmarkChangeProcessor::BookmarkMetaInfoChanged( BookmarkModel* model, const BookmarkNode* node) { @@ -36,19 +28,18 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..3b4110a5e4803b7ede262ab416376fda } void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, -@@ -416,6 +420,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -416,6 +419,10 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, return; } -+ model->RemoveObserver(this); ++ ScopedPauseObserver pause(bookmark_model_, this); + brave_sync::AddBraveMetaInfo(child, model, old_parent != new_parent); + SetSyncNodeMetaInfo(child, &sync_node); -+ model->AddObserver(this); + if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -429,6 +438,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -429,6 +436,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, UpdateTransactionVersion(new_version, model, std::vector(1, child)); @@ -60,7 +51,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..3b4110a5e4803b7ede262ab416376fda } void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( -@@ -458,6 +472,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( +@@ -458,6 +470,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( return; } @@ -69,24 +60,22 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..3b4110a5e4803b7ede262ab416376fda CreateOrUpdateSyncNode(node); } -@@ -490,6 +506,11 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( +@@ -490,6 +504,10 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( DCHECK_EQ(sync_child.GetParentId(), model_associator_->GetSyncIdFromChromeId(node->id())); -+ model->RemoveObserver(this); ++ ScopedPauseObserver pause(bookmark_model_, this); + brave_sync::AddBraveMetaInfo(child, model, false); + SetSyncNodeMetaInfo(child, &sync_child); -+ model->AddObserver(this); + if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -718,10 +739,13 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -718,10 +736,12 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } -+ BookmarkNode* mutable_node = const_cast(dst); -+ mutable_node->SetMetaInfo("FirstLoadedFavicon", "true"); ++ bookmark_model_->SetNodeMetaInfo(dst, "FirstLoadedFavicon", "true"); model_associator_->Associate(dst, src); } diff --git a/test/BUILD.gn b/test/BUILD.gn index c869acd29a02..63ccfcb73d8e 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -93,6 +93,7 @@ test("brave_unit_tests") { "//brave/components/brave_shields/browser/https_everywhere_recently_used_cache_unittest.cpp", "//brave/components/brave_sync/bookmark_order_util_unittest.cc", "//brave/components/brave_sync/brave_sync_service_unittest.cc", + "//brave/components/brave_sync/syncer_helper_unittest.cc", "//brave/components/brave_webtorrent/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc", "//brave/components/invalidation/fcm_unittest.cc", "//brave/components/gcm_driver/gcm_unittest.cc", From a766cdddd638e07e60c54a6379e3e4d59689aa7e Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 20 May 2019 23:15:52 -0700 Subject: [PATCH 21/73] C75.0.3770.38 Upgrade --- browser/extensions/api/brave_sync_api.cc | 1 - browser/ui/webui/sync/sync_ui.cc | 1 - ...nd_host_core.cc => sync_engine_backend.cc} | 14 ++++---- ...kend_host_core.h => sync_engine_backend.h} | 2 +- .../sync/driver/glue/sync_engine_impl.cc | 2 +- .../driver}/profile_sync_service.cc | 32 +++---------------- .../sync/engine_impl/get_updates_processor.cc | 1 + .../brave_sync/brave_profile_sync_service.cc | 16 +++++----- .../brave_sync/brave_profile_sync_service.h | 4 +-- ...e-browser-sync-chrome_sync_client.cc.patch | 4 +-- ...me-browser-sync-chrome_sync_client.h.patch | 8 ++--- ...sync-profile_sync_service_factory.cc.patch | 10 +++--- ...-sync-profile_sync_service_factory.h.patch | 4 +-- ...browser_sync-profile_sync_service.cc.patch | 13 -------- ...-browser_sync-profile_sync_service.h.patch | 28 ---------------- patches/components-sync-BUILD.gn.patch | 10 +++--- .../components-sync-base-model_type.h.patch | 8 ++--- ...ync-driver-data_type_manager_impl.cc.patch | 4 +-- ...river-glue-sync_backend_host_core.cc.patch | 12 ------- ...driver-glue-sync_backend_host_core.h.patch | 24 -------------- ...c-driver-glue-sync_engine_backend.cc.patch | 12 +++++++ ...nc-driver-glue-sync_engine_backend.h.patch | 24 ++++++++++++++ ...sync-driver-glue-sync_engine_impl.cc.patch | 4 +-- ...-sync-driver-glue-sync_engine_impl.h.patch | 8 ++--- ...-sync-driver-profile_sync_service.cc.patch | 13 ++++++++ ...s-sync-driver-profile_sync_service.h.patch | 28 ++++++++++++++++ ...components-sync-driver-sync_client.h.patch | 6 ++-- ...components-sync-engine-sync_engine.h.patch | 14 ++++---- ...omponents-sync-engine-sync_manager.h.patch | 4 +-- ...-sync-engine_impl-cycle-sync_cycle.h.patch | 4 +-- ...engine_impl-get_updates_processor.cc.patch | 8 ++--- ...ync-engine_impl-sync_manager_impl.cc.patch | 9 ++++-- ...sync-engine_impl-sync_manager_impl.h.patch | 4 +-- ...c-engine_impl-sync_scheduler_impl.cc.patch | 4 +-- ...nc-engine_impl-sync_scheduler_impl.h.patch | 8 ++--- ...omponents-sync-engine_impl-syncer.cc.patch | 4 +-- ...ync-engine_impl-syncer_proto_util.cc.patch | 4 +-- ...okmarks-bookmark_change_processor.cc.patch | 13 ++++---- ...ks-bookmark_local_changes_builder.cc.patch | 12 +++---- 39 files changed, 180 insertions(+), 201 deletions(-) rename chromium_src/components/sync/driver/glue/{sync_backend_host_core.cc => sync_engine_backend.cc} (63%) rename chromium_src/components/sync/driver/glue/{sync_backend_host_core.h => sync_engine_backend.h} (67%) rename chromium_src/components/{browser_sync => sync/driver}/profile_sync_service.cc (61%) delete mode 100644 patches/components-browser_sync-profile_sync_service.cc.patch delete mode 100644 patches/components-browser_sync-profile_sync_service.h.patch delete mode 100644 patches/components-sync-driver-glue-sync_backend_host_core.cc.patch delete mode 100644 patches/components-sync-driver-glue-sync_backend_host_core.h.patch create mode 100644 patches/components-sync-driver-glue-sync_engine_backend.cc.patch create mode 100644 patches/components-sync-driver-glue-sync_engine_backend.h.patch create mode 100644 patches/components-sync-driver-profile_sync_service.cc.patch create mode 100644 patches/components-sync-driver-profile_sync_service.h.patch diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index 9ecad7545271..d4c6a8d3b252 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -16,7 +16,6 @@ #include "brave/components/brave_sync/values_conv.h" #include "brave/components/brave_sync/jslib_messages.h" #include "chrome/browser/profiles/profile.h" -#include "components/browser_sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" using brave_sync::BraveProfileSyncService; diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index 98928360129e..8dc037ce9298 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -16,7 +16,6 @@ #include "brave/components/brave_sync/values_conv.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/profile_sync_service_factory.h" -#include "components/browser_sync/profile_sync_service.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_ui_message_handler.h" diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc similarity index 63% rename from chromium_src/components/sync/driver/glue/sync_backend_host_core.cc rename to chromium_src/components/sync/driver/glue/sync_engine_backend.cc index ad9313cc03fb..4cc82d118c8e 100644 --- a/chromium_src/components/sync/driver/glue/sync_backend_host_core.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc @@ -1,34 +1,34 @@ -#include "../../../../../../components/sync/driver/glue/sync_backend_host_core.cc" +#include "../../../../../../components/sync/driver/glue/sync_engine_backend.cc" #include "brave/components/brave_sync/jslib_messages.h" namespace syncer { -void SyncBackendHostCore::OnNudgeSyncCycle( +void SyncEngineBackend::OnNudgeSyncCycle( brave_sync::RecordsListPtr records_list) { host_.Call(FROM_HERE, &SyncEngineImpl::HandleNudgeSyncCycle, base::Passed(&records_list)); } -void SyncBackendHostCore::OnPollSyncCycle(GetRecordsCallback cb, +void SyncEngineBackend::OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent) { host_.Call(FROM_HERE, &SyncEngineImpl::HandlePollSyncCycle, cb, wevent); } -void SyncBackendHostCore::DoDispatchGetRecordsCallback( +void SyncEngineBackend::DoDispatchGetRecordsCallback( GetRecordsCallback cb, std::unique_ptr records) { cb.Run(std::move(records)); } -void SyncBackendHostCore::BraveInit(SyncManager::InitArgs* args) { +void SyncEngineBackend::BraveInit(SyncManager::InitArgs* args) { DCHECK(args); args->nudge_sync_cycle_delegate_function = - base::BindRepeating(&SyncBackendHostCore::OnNudgeSyncCycle, + base::BindRepeating(&SyncEngineBackend::OnNudgeSyncCycle, weak_ptr_factory_.GetWeakPtr()); args->poll_sync_cycle_delegate_function = - base::BindRepeating(&SyncBackendHostCore::OnPollSyncCycle, + base::BindRepeating(&SyncEngineBackend::OnPollSyncCycle, weak_ptr_factory_.GetWeakPtr()); } diff --git a/chromium_src/components/sync/driver/glue/sync_backend_host_core.h b/chromium_src/components/sync/driver/glue/sync_engine_backend.h similarity index 67% rename from chromium_src/components/sync/driver/glue/sync_backend_host_core.h rename to chromium_src/components/sync/driver/glue/sync_engine_backend.h index caa0d7424b5e..9fc6b28917c5 100644 --- a/chromium_src/components/sync/driver/glue/sync_backend_host_core.h +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.h @@ -3,4 +3,4 @@ namespace syncer { using brave_sync::GetRecordsCallback; using brave_sync::RecordsList; } // namespace syncer -#include "../../../../../../components/sync/driver/glue/sync_backend_host_core.h" +#include "../../../../../../components/sync/driver/glue/sync_engine_backend.h" diff --git a/chromium_src/components/sync/driver/glue/sync_engine_impl.cc b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc index 4e87750ed9cb..7f54f287a298 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_impl.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc @@ -23,7 +23,7 @@ void SyncEngineImpl::DispatchGetRecordsCallback( GetRecordsCallback cb, std::unique_ptr records) { sync_task_runner_->PostTask( FROM_HERE, - base::BindOnce(&SyncBackendHostCore::DoDispatchGetRecordsCallback, core_, + base::BindOnce(&SyncEngineBackend::DoDispatchGetRecordsCallback, backend_, cb, std::move(records))); } diff --git a/chromium_src/components/browser_sync/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc similarity index 61% rename from chromium_src/components/browser_sync/profile_sync_service.cc rename to chromium_src/components/sync/driver/profile_sync_service.cc index 2442e7005ce3..1b33eee5b8ab 100644 --- a/chromium_src/components/browser_sync/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -1,31 +1,14 @@ // For use_transport_only_mode #define IsSyncFeatureEnabled IsBraveSyncEnabled -#include "../../../../components/browser_sync/profile_sync_service.cc" +#include "../../../../components/sync/driver/profile_sync_service.cc" #include "base/bind.h" #include "brave/components/brave_sync/jslib_messages.h" #include "chrome/browser/sync/chrome_sync_client.h" -#include "components/sync/engine/sync_credentials.h" #include "content/public/browser/browser_thread.h" namespace syncer { -const int64_t kBraveDefaultShortPollIntervalSeconds = 60; -const int64_t kBraveDefaultLongPollIntervalSeconds = 90; -} - -namespace browser_sync { - -namespace { - -syncer::SyncCredentials GetDummyCredentials() { - syncer::SyncCredentials credentials; - credentials.account_id = "dummy_account_id"; - credentials.email = "dummy_email"; - credentials.sync_token = "dummy_access_token"; - return credentials; -} - -} // namespace +const int64_t kBraveDefaultPollIntervalSeconds = 60; syncer::SyncClient* ProfileSyncService::GetSyncClient() { DCHECK(sync_client_); @@ -47,14 +30,9 @@ void ProfileSyncService::BraveEngineParamsInit( base::BindRepeating(&ProfileSyncService::OnPollSyncCycle, sync_enabled_weak_factory_.GetWeakPtr()); - params->credentials = GetDummyCredentials(); - - sync_prefs_.SetShortPollInterval( - base::TimeDelta::FromSeconds( - syncer::kBraveDefaultShortPollIntervalSeconds)); - sync_prefs_.SetLongPollInterval( + sync_prefs_.SetPollInterval( base::TimeDelta::FromSeconds( - syncer::kBraveDefaultLongPollIntervalSeconds)); + syncer::kBraveDefaultPollIntervalSeconds)); } void ProfileSyncService::OnNudgeSyncCycle( @@ -67,4 +45,4 @@ bool ProfileSyncService::IsBraveSyncEnabled() const { return false; } -} // namespace browser_sync +} // namespace syncer diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index 56a39ce09c7c..eab7e3b77db3 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -13,6 +13,7 @@ SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*, ModelTypeSet*, #include "base/time/time.h" #include "brave/components/brave_sync/jslib_messages.h" #include "components/sync/base/hash_util.h" +#include "components/sync/base/time.h" #include "components/sync/syncable/syncable_proto_util.h" #include "components/sync/engine_impl/loopback_server/loopback_server_entity.h" #include "url/gurl.h" diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 239151bbf5bd..2afa55fed87b 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -175,7 +175,7 @@ void CreateResolveList( } // namespace BraveProfileSyncService::BraveProfileSyncService(InitParams init_params) - : browser_sync::ProfileSyncService(std::move(init_params)) { + : syncer::ProfileSyncService(std::move(init_params)) { brave_sync_words_ = std::string(); brave_sync_prefs_ = std::make_unique( @@ -344,13 +344,13 @@ void BraveProfileSyncService::OnSetSyncEnabled(const bool sync_this_device) { void BraveProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - syncer::ModelTypeSet type_set = - ProfileSyncService::GetUserSettings()->GetChosenDataTypes(); + syncer::UserSelectableTypeSet type_set = + ProfileSyncService::GetUserSettings()->GetSelectedTypes(); if (sync_bookmarks) - type_set.Put(syncer::BOOKMARKS); + type_set.Put(syncer::UserSelectableType::kBookmarks); else - type_set.Remove(syncer::BOOKMARKS); - ProfileSyncService::GetUserSettings()->SetChosenDataTypes(false, + type_set.Remove(syncer::UserSelectableType::kBookmarks); + ProfileSyncService::GetUserSettings()->SetSelectedTypes(false, type_set); brave_sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); } @@ -483,7 +483,7 @@ void BraveProfileSyncService::OnSyncReady() { // first time setup sync or migrated from legacy sync if (sync_prefs.GetLastSyncedTime().is_null()) { ProfileSyncService::GetUserSettings() - ->SetChosenDataTypes(false, syncer::ModelTypeSet()); + ->SetSelectedTypes(false, syncer::UserSelectableTypeSet()); // default enable bookmark OnSetSyncBookmarks(true); ProfileSyncService::GetUserSettings()->SetSyncRequested(true); @@ -573,7 +573,7 @@ bool BraveProfileSyncService::IsAuthenticatedAccountPrimary() const { void BraveProfileSyncService::Shutdown() { SignalWaitableEvent(); - browser_sync::ProfileSyncService::Shutdown(); + syncer::ProfileSyncService::Shutdown(); } void BraveProfileSyncService::NotifySyncSetupError(const std::string& error) { diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 779f9e713327..5a1d3f3741af 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -9,7 +9,7 @@ #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" -#include "components/browser_sync/profile_sync_service.h" +#include "components/sync/driver/profile_sync_service.h" FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkAdded); FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkDeleted); @@ -36,7 +36,7 @@ namespace prefs { class Prefs; } // namespace prefs -class BraveProfileSyncService : public browser_sync::ProfileSyncService, +class BraveProfileSyncService : public syncer::ProfileSyncService, public BraveSyncService, public SyncMessageHandler { public: diff --git a/patches/chrome-browser-sync-chrome_sync_client.cc.patch b/patches/chrome-browser-sync-chrome_sync_client.cc.patch index cdafe24dcdb2..bc1b9f467d7f 100644 --- a/patches/chrome-browser-sync-chrome_sync_client.cc.patch +++ b/patches/chrome-browser-sync-chrome_sync_client.cc.patch @@ -1,8 +1,8 @@ diff --git a/chrome/browser/sync/chrome_sync_client.cc b/chrome/browser/sync/chrome_sync_client.cc -index 3efbe8f776e1ecfd212fee726fad5c360d9788c6..ce8f6e05186781e40a0224125ed248a6fa102dc9 100644 +index ffb7c9f0a5fb78d160fbcfdba6cd3e3b8ed10179..0afc072de8a2f8f874baa66374078df5fcb62b3f 100644 --- a/chrome/browser/sync/chrome_sync_client.cc +++ b/chrome/browser/sync/chrome_sync_client.cc -@@ -164,7 +164,8 @@ syncer::ModelTypeSet GetDisabledTypesFromCommandLine() { +@@ -165,7 +165,8 @@ syncer::ModelTypeSet GetDisabledTypesFromCommandLine() { } // namespace diff --git a/patches/chrome-browser-sync-chrome_sync_client.h.patch b/patches/chrome-browser-sync-chrome_sync_client.h.patch index 9ccf532522b0..fcb9fd8961c2 100644 --- a/patches/chrome-browser-sync-chrome_sync_client.h.patch +++ b/patches/chrome-browser-sync-chrome_sync_client.h.patch @@ -1,16 +1,16 @@ diff --git a/chrome/browser/sync/chrome_sync_client.h b/chrome/browser/sync/chrome_sync_client.h -index c89058c8815f8983dafaeb88edf1a239f11a9b08..bb22a19336d91fcf476607a3399bbbe850fa5f47 100644 +index f52eb2c251db195a2b4ba8b5a85ea5b05102f686..2dc398a6be0cbb3c148cb34cdf811ed1fea48934 100644 --- a/chrome/browser/sync/chrome_sync_client.h +++ b/chrome/browser/sync/chrome_sync_client.h -@@ -60,6 +60,7 @@ class ChromeSyncClient : public browser_sync::BrowserSyncClient { - scoped_refptr CreateModelWorkerForGroup( +@@ -63,6 +63,7 @@ class ChromeSyncClient : public browser_sync::BrowserSyncClient { syncer::ModelSafeGroup group) override; syncer::SyncApiComponentFactory* GetSyncApiComponentFactory() override; + syncer::SyncTypePreferenceProvider* GetPreferenceProvider() override; + brave_sync::BraveSyncClient* GetBraveSyncClient() override; private: Profile* const profile_; -@@ -82,6 +83,8 @@ class ChromeSyncClient : public browser_sync::BrowserSyncClient { +@@ -85,6 +86,8 @@ class ChromeSyncClient : public browser_sync::BrowserSyncClient { // Generates and monitors the ExtensionsActivity object used by sync. ExtensionsActivityMonitor extensions_activity_monitor_; diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch index d9fd9f37abdd..e2dfaf2d7dd8 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -1,13 +1,13 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc -index 0aa70dfd168a13b85dc09b784624f686c4026177..0f69ff3a4f8e66626781b740ea27edfa68dbfea3 100644 +index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..dcc3be3371db7c3f68dd1353030bbe6d2c1cb451 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc -@@ -254,7 +254,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( - : ProfileSyncService::MANUAL_START; +@@ -263,7 +263,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( } -- auto pss = std::make_unique(std::move(init_params)); -+ auto pss = std::make_unique(std::move(init_params)); + auto pss = +- std::make_unique(std::move(init_params)); ++ std::make_unique(std::move(init_params)); pss->Initialize(); return pss.release(); } diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.h.patch b/patches/chrome-browser-sync-profile_sync_service_factory.h.patch index 096eb17c5598..e2a5240b2068 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.h.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.h.patch @@ -1,10 +1,10 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.h b/chrome/browser/sync/profile_sync_service_factory.h -index ccbf83240e4fd135d1c8f3cf7a451d78b9a3ad90..02d7bdf45ec6bc557ee5252a2847be06b222bfb1 100644 +index 2e2f416a055c4bcc67c02b43ccc90ac8c13bc8f0..faaf8531cb8f28e7c46550b47c5d4ed476a9ee93 100644 --- a/chrome/browser/sync/profile_sync_service_factory.h +++ b/chrome/browser/sync/profile_sync_service_factory.h @@ -38,6 +38,8 @@ class ProfileSyncServiceFactory : public BrowserContextKeyedServiceFactory { // absolutely necessary! Prefer GetForProfile instead. - static browser_sync::ProfileSyncService* GetAsProfileSyncServiceForProfile( + static syncer::ProfileSyncService* GetAsProfileSyncServiceForProfile( Profile* profile); + static brave_sync::BraveProfileSyncService* + GetAsBraveProfileSyncServiceForProfile(Profile* profile); diff --git a/patches/components-browser_sync-profile_sync_service.cc.patch b/patches/components-browser_sync-profile_sync_service.cc.patch deleted file mode 100644 index 506b3f8838bc..000000000000 --- a/patches/components-browser_sync-profile_sync_service.cc.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/components/browser_sync/profile_sync_service.cc b/components/browser_sync/profile_sync_service.cc -index 787e2d24941cbaa469373ed5baad14d1ac9f3722..f8d2fa4e53602d61fb777d113489af5413a11d0a 100644 ---- a/components/browser_sync/profile_sync_service.cc -+++ b/components/browser_sync/profile_sync_service.cc -@@ -480,6 +480,8 @@ void ProfileSyncService::StartUpSlowEngineComponents() { - ->GetSyncUserAgent(); - params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); - params.credentials = auth_manager_->GetCredentials(); -+ if (IsBraveSyncEnabled()) -+ BraveEngineParamsInit(¶ms); - DCHECK(!params.credentials.account_id.empty() || IsLocalSyncEnabled()); - if (!base::FeatureList::IsEnabled(switches::kSyncE2ELatencyMeasurement)) { - invalidation::InvalidationService* invalidator = diff --git a/patches/components-browser_sync-profile_sync_service.h.patch b/patches/components-browser_sync-profile_sync_service.h.patch deleted file mode 100644 index 35493eb0217a..000000000000 --- a/patches/components-browser_sync-profile_sync_service.h.patch +++ /dev/null @@ -1,28 +0,0 @@ -diff --git a/components/browser_sync/profile_sync_service.h b/components/browser_sync/profile_sync_service.h -index 6c01395b954ac146084865b0268992f277b4914c..734f5623f889f9e576a7e4d5fb39dae0a278290a 100644 ---- a/components/browser_sync/profile_sync_service.h -+++ b/components/browser_sync/profile_sync_service.h -@@ -346,6 +346,14 @@ class ProfileSyncService : public syncer::SyncService, - - syncer::SyncClient* GetSyncClientForTest(); - -+ protected: -+ syncer::SyncClient* GetSyncClient(); -+ syncer::SyncEngine* GetSyncEngine(); -+ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, -+ base::WaitableEvent* wevent); -+ virtual bool IsBraveSyncEnabled() const; -+ - private: - // Passed as an argument to StopImpl to control whether or not the sync - // engine should clear its data directory when it shuts down. See StopImpl -@@ -355,6 +363,8 @@ class ProfileSyncService : public syncer::SyncService, - CLEAR_DATA, - }; - -+ void BraveEngineParamsInit(syncer::SyncEngine::InitParams*); -+ - // Shorthand for user_settings_.IsFirstSetupComplete(). - bool IsFirstSetupComplete() const; - diff --git a/patches/components-sync-BUILD.gn.patch b/patches/components-sync-BUILD.gn.patch index 61f70c50a842..108ae7deb8c6 100644 --- a/patches/components-sync-BUILD.gn.patch +++ b/patches/components-sync-BUILD.gn.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/BUILD.gn b/components/sync/BUILD.gn -index 129a82836e0b07552504b6f98cd1ae2c7a4e941e..5565f9aa8e3ba6618481dc1bd5cf5bb538bd41a8 100644 +index 0606b7e68670877100114732174af25ad0b42f77..c75b39c7d0c7647b17a047eb732089bf38549956 100644 --- a/components/sync/BUILD.gn +++ b/components/sync/BUILD.gn -@@ -574,6 +574,7 @@ jumbo_static_library("sync") { +@@ -99,6 +99,7 @@ jumbo_static_library("base") { ] deps = [ "//base:i18n", + "//brave/components/brave_sync:jslib_messages", - "//components/data_use_measurement/core", - "//components/invalidation/impl:feature_list", - "//components/invalidation/public", + "//components/os_crypt", + "//components/pref_registry", + "//components/prefs", diff --git a/patches/components-sync-base-model_type.h.patch b/patches/components-sync-base-model_type.h.patch index 0cf2ba452d09..f4b243990bb9 100644 --- a/patches/components-sync-base-model_type.h.patch +++ b/patches/components-sync-base-model_type.h.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/base/model_type.h b/components/sync/base/model_type.h -index ca6acf4cdbded08bbd1a69c27827ecf0374a0d11..56f2ae314dfff6d8df3df67ec1edd9b92d1d9d93 100644 +index db7e7d7d68eabab6ed7e1a3ccfe125e3e571e382..3bf5bd32c2aa567d16a6f90953556fb5283dc592 100644 --- a/components/sync/base/model_type.h +++ b/components/sync/base/model_type.h -@@ -271,6 +271,7 @@ constexpr ModelTypeSet ProxyTypes() { +@@ -241,6 +241,7 @@ constexpr ModelTypeSet ProxyTypes() { // - They support custom update application and conflict resolution logic. // - All change processing occurs on the sync thread (GROUP_PASSIVE). constexpr ModelTypeSet ControlTypes() { + return ModelTypeSet(UNSPECIFIED); - return ModelTypeSet::FromRange(FIRST_CONTROL_MODEL_TYPE, - LAST_CONTROL_MODEL_TYPE); + return ModelTypeSet(NIGORI); } + diff --git a/patches/components-sync-driver-data_type_manager_impl.cc.patch b/patches/components-sync-driver-data_type_manager_impl.cc.patch index c650c8f8c570..86e8c3946808 100644 --- a/patches/components-sync-driver-data_type_manager_impl.cc.patch +++ b/patches/components-sync-driver-data_type_manager_impl.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/data_type_manager_impl.cc b/components/sync/driver/data_type_manager_impl.cc -index 9dc9226269704e8a2412634b231a6d54c8bc93f6..c746e46fdec8c992fcafb87f3e89927979165019 100644 +index f19aeafebc707eaf703b0fa71bf1c2d80dba2596..2b0a2cfe99203e331dabb6ec741649b0af4bf0aa 100644 --- a/components/sync/driver/data_type_manager_impl.cc +++ b/components/sync/driver/data_type_manager_impl.cc -@@ -546,8 +546,8 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( +@@ -542,8 +542,8 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( types_to_download.PutAll(clean_types); types_to_download.RemoveAll(ProxyTypes()); types_to_download.RemoveAll(CommitOnlyTypes()); diff --git a/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch b/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch deleted file mode 100644 index ac3bae239685..000000000000 --- a/patches/components-sync-driver-glue-sync_backend_host_core.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/sync/driver/glue/sync_backend_host_core.cc b/components/sync/driver/glue/sync_backend_host_core.cc -index 9f962da6b18298365c01e8b9154d39a5c43afc38..f020379378dce7a5b27dcf3f807fd191cd2ee0f7 100644 ---- a/components/sync/driver/glue/sync_backend_host_core.cc -+++ b/components/sync/driver/glue/sync_backend_host_core.cc -@@ -353,6 +353,7 @@ void SyncBackendHostCore::DoInitialize(SyncEngine::InitParams params) { - args.cache_guid = params.cache_guid; - args.birthday = params.birthday; - args.bag_of_chips = params.bag_of_chips; -+ BraveInit(&args); - sync_manager_->Init(&args); - base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( - this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get()); diff --git a/patches/components-sync-driver-glue-sync_backend_host_core.h.patch b/patches/components-sync-driver-glue-sync_backend_host_core.h.patch deleted file mode 100644 index e8397b2e27f7..000000000000 --- a/patches/components-sync-driver-glue-sync_backend_host_core.h.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/components/sync/driver/glue/sync_backend_host_core.h b/components/sync/driver/glue/sync_backend_host_core.h -index d545f996333a652dfb4b87b24da6cd7dde428ed7..42df877d3e6fc1f0c1232c76327c2ac9a5cf598c 100644 ---- a/components/sync/driver/glue/sync_backend_host_core.h -+++ b/components/sync/driver/glue/sync_backend_host_core.h -@@ -174,11 +174,19 @@ class SyncBackendHostCore - - bool HasUnsyncedItemsForTest() const; - -+ void DoDispatchGetRecordsCallback(GetRecordsCallback cb, -+ std::unique_ptr records); -+ - private: - friend class base::RefCountedThreadSafe; - - ~SyncBackendHostCore() override; - -+ void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ void OnPollSyncCycle(GetRecordsCallback cb, -+ base::WaitableEvent* wevent); -+ void BraveInit(SyncManager::InitArgs* args); -+ - // Invoked when initialization of syncapi is complete and we can start - // our timer. - // This must be called from the thread on which SaveChanges is intended to diff --git a/patches/components-sync-driver-glue-sync_engine_backend.cc.patch b/patches/components-sync-driver-glue-sync_engine_backend.cc.patch new file mode 100644 index 000000000000..0eca29264b48 --- /dev/null +++ b/patches/components-sync-driver-glue-sync_engine_backend.cc.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync/driver/glue/sync_engine_backend.cc b/components/sync/driver/glue/sync_engine_backend.cc +index 508c26a99ecb044bcca60f34ef4c787bb06fdc9f..7c88be6e419e2f981181a71f4031a8a564b56f59 100644 +--- a/components/sync/driver/glue/sync_engine_backend.cc ++++ b/components/sync/driver/glue/sync_engine_backend.cc +@@ -370,6 +370,7 @@ void SyncEngineBackend::DoInitialize(SyncEngine::InitParams params) { + args.cache_guid = params.cache_guid; + args.birthday = params.birthday; + args.bag_of_chips = params.bag_of_chips; ++ BraveInit(&args); + sync_manager_->Init(&args); + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( + this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get()); diff --git a/patches/components-sync-driver-glue-sync_engine_backend.h.patch b/patches/components-sync-driver-glue-sync_engine_backend.h.patch new file mode 100644 index 000000000000..13e27db38a90 --- /dev/null +++ b/patches/components-sync-driver-glue-sync_engine_backend.h.patch @@ -0,0 +1,24 @@ +diff --git a/components/sync/driver/glue/sync_engine_backend.h b/components/sync/driver/glue/sync_engine_backend.h +index 8cc3e5305b1010e025dbaf8a23c6180813fa9ef8..071673e8b51c234f95042d0ac84283c7a257aaad 100644 +--- a/components/sync/driver/glue/sync_engine_backend.h ++++ b/components/sync/driver/glue/sync_engine_backend.h +@@ -177,11 +177,19 @@ class SyncEngineBackend : public base::RefCountedThreadSafe, + + bool HasUnsyncedItemsForTest() const; + ++ void DoDispatchGetRecordsCallback(GetRecordsCallback cb, ++ std::unique_ptr records); ++ + private: + friend class base::RefCountedThreadSafe; + + ~SyncEngineBackend() override; + ++ void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); ++ void OnPollSyncCycle(GetRecordsCallback cb, ++ base::WaitableEvent* wevent); ++ void BraveInit(SyncManager::InitArgs* args); ++ + // For the olg tango based invalidations method returns true if the + // invalidation has version lower than last seen version for this datatype. + bool ShouldIgnoreRedundantInvalidation(const Invalidation& invalidation, diff --git a/patches/components-sync-driver-glue-sync_engine_impl.cc.patch b/patches/components-sync-driver-glue-sync_engine_impl.cc.patch index baf7d072a2ba..199d93c893d2 100644 --- a/patches/components-sync-driver-glue-sync_engine_impl.cc.patch +++ b/patches/components-sync-driver-glue-sync_engine_impl.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync/driver/glue/sync_engine_impl.cc b/components/sync/driver/glue/sync_engine_impl.cc -index 0eec6d65d61988411827349e601d936ca66adf4c..17d6d1dcde9e20894fed756cc620171e04e8e6c1 100644 +index 5140252fbd55ffd37ae00625dc56ec927ea12de2..6fdf7aeb059b2ca5b09e03c99feb8eb04774b26d 100644 --- a/components/sync/driver/glue/sync_engine_impl.cc +++ b/components/sync/driver/glue/sync_engine_impl.cc @@ -59,6 +59,10 @@ void SyncEngineImpl::Initialize(InitParams params) { @@ -12,4 +12,4 @@ index 0eec6d65d61988411827349e601d936ca66adf4c..17d6d1dcde9e20894fed756cc620171e + params.poll_sync_cycle_delegate_function; sync_task_runner_->PostTask( - FROM_HERE, base::BindOnce(&SyncBackendHostCore::DoInitialize, core_, + FROM_HERE, base::BindOnce(&SyncEngineBackend::DoInitialize, backend_, diff --git a/patches/components-sync-driver-glue-sync_engine_impl.h.patch b/patches/components-sync-driver-glue-sync_engine_impl.h.patch index 58121dab5fbd..389650a46fa7 100644 --- a/patches/components-sync-driver-glue-sync_engine_impl.h.patch +++ b/patches/components-sync-driver-glue-sync_engine_impl.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/glue/sync_engine_impl.h b/components/sync/driver/glue/sync_engine_impl.h -index db4f0ef865957a38dc1b510f31ebd49b83cb57b9..4daca79263fec199188e54667d1a9b7312ba7aac 100644 +index 9fce092e22ca630fa3f5efa0bc1e963a86659625..89f7155a590b71cdab381967009384ef2d040c06 100644 --- a/components/sync/driver/glue/sync_engine_impl.h +++ b/components/sync/driver/glue/sync_engine_impl.h -@@ -158,6 +158,12 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { +@@ -160,6 +160,12 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { SyncEngineHost* host() { return host_; } @@ -13,9 +13,9 @@ index db4f0ef865957a38dc1b510f31ebd49b83cb57b9..4daca79263fec199188e54667d1a9b73 + GetRecordsCallback cb, std::unique_ptr records) override; + private: - friend class SyncBackendHostCore; + friend class SyncEngineBackend; -@@ -221,6 +227,9 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { +@@ -215,6 +221,9 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { ModelTypeSet last_enabled_types_; bool sessions_invalidation_enabled_ = false; diff --git a/patches/components-sync-driver-profile_sync_service.cc.patch b/patches/components-sync-driver-profile_sync_service.cc.patch new file mode 100644 index 000000000000..860c15ffff0b --- /dev/null +++ b/patches/components-sync-driver-profile_sync_service.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/sync/driver/profile_sync_service.cc b/components/sync/driver/profile_sync_service.cc +index 7c7daae97e5fe9ec16aa231628c28d1a9d6db100..75f5fc3052996ff4f6d373a095d229cdfc7eb419 100644 +--- a/components/sync/driver/profile_sync_service.cc ++++ b/components/sync/driver/profile_sync_service.cc +@@ -458,6 +458,8 @@ void ProfileSyncService::StartUpSlowEngineComponents() { + params.sync_user_agent = MakeUserAgentForSync(channel_); + params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); + params.authenticated_account_id = GetAuthenticatedAccountInfo().account_id; ++ if (IsBraveSyncEnabled()) ++ BraveEngineParamsInit(¶ms); + DCHECK(!params.authenticated_account_id.empty() || IsLocalSyncEnabled()); + if (!base::FeatureList::IsEnabled(switches::kSyncE2ELatencyMeasurement)) { + invalidation::InvalidationService* invalidator = diff --git a/patches/components-sync-driver-profile_sync_service.h.patch b/patches/components-sync-driver-profile_sync_service.h.patch new file mode 100644 index 000000000000..f0d1ec175ce2 --- /dev/null +++ b/patches/components-sync-driver-profile_sync_service.h.patch @@ -0,0 +1,28 @@ +diff --git a/components/sync/driver/profile_sync_service.h b/components/sync/driver/profile_sync_service.h +index 3df5ee21f6ec37c5915607ec9196909c62545572..d23a45c2e548e6db6d1d2f6bee0957697dcd2235 100644 +--- a/components/sync/driver/profile_sync_service.h ++++ b/components/sync/driver/profile_sync_service.h +@@ -257,6 +257,14 @@ class ProfileSyncService : public SyncService, + + SyncClient* GetSyncClientForTest(); + ++ protected: ++ syncer::SyncClient* GetSyncClient(); ++ syncer::SyncEngine* GetSyncEngine(); ++ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); ++ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, ++ base::WaitableEvent* wevent); ++ virtual bool IsBraveSyncEnabled() const; ++ + private: + friend class TestProfileSyncService; + +@@ -268,6 +276,8 @@ class ProfileSyncService : public SyncService, + CLEAR_DATA, + }; + ++ void BraveEngineParamsInit(syncer::SyncEngine::InitParams*); ++ + enum UnrecoverableErrorReason { + ERROR_REASON_UNSET, + ERROR_REASON_SYNCER, diff --git a/patches/components-sync-driver-sync_client.h.patch b/patches/components-sync-driver-sync_client.h.patch index 9926adca257b..d419df12a610 100644 --- a/patches/components-sync-driver-sync_client.h.patch +++ b/patches/components-sync-driver-sync_client.h.patch @@ -1,10 +1,10 @@ diff --git a/components/sync/driver/sync_client.h b/components/sync/driver/sync_client.h -index 1cc9f14d35f7edae21fc21a3bd9970a7e60f4222..9c69b2e5cab29d7c757b6a06d3619bcb32fa681b 100644 +index 90db4a23b4241364d6cd464df621531073745be5..4ed7da95a55295a7771b9dd19a052f608e8a1d3a 100644 --- a/components/sync/driver/sync_client.h +++ b/components/sync/driver/sync_client.h @@ -73,6 +73,8 @@ class SyncClient { - // Returns the current SyncApiComponentFactory instance. - virtual SyncApiComponentFactory* GetSyncApiComponentFactory() = 0; + // Returns the preference provider, or null if none exists. + virtual SyncTypePreferenceProvider* GetPreferenceProvider() = 0; + virtual brave_sync::BraveSyncClient* GetBraveSyncClient(); + diff --git a/patches/components-sync-engine-sync_engine.h.patch b/patches/components-sync-engine-sync_engine.h.patch index 698ac2f82dec..f76123c1045d 100644 --- a/patches/components-sync-engine-sync_engine.h.patch +++ b/patches/components-sync-engine-sync_engine.h.patch @@ -1,10 +1,10 @@ diff --git a/components/sync/engine/sync_engine.h b/components/sync/engine/sync_engine.h -index 2ed8818bde7b036e3bcbc704d77aebcaa78881dc..4aee53695e927ef582a610ac49067bf32d92cede 100644 +index e4d2ab4d38f6fffd2929277be51ec618180e0086..721df77d28d5d5a2c43660df09edd0697492f071 100644 --- a/components/sync/engine/sync_engine.h +++ b/components/sync/engine/sync_engine.h -@@ -88,6 +88,9 @@ class SyncEngine : public ModelTypeConfigurer { - base::TimeDelta short_poll_interval; - base::TimeDelta long_poll_interval; +@@ -87,6 +87,9 @@ class SyncEngine : public ModelTypeConfigurer { + // Define the polling interval. Must not be zero. + base::TimeDelta poll_interval; + brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; + brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function; @@ -12,9 +12,9 @@ index 2ed8818bde7b036e3bcbc704d77aebcaa78881dc..4aee53695e927ef582a610ac49067bf3 private: DISALLOW_COPY_AND_ASSIGN(InitParams); }; -@@ -193,6 +196,10 @@ class SyncEngine : public ModelTypeConfigurer { - // Enables/Disables invalidations for session sync related datatypes. - virtual void SetInvalidationsForSessionsEnabled(bool enabled) = 0; +@@ -199,6 +202,10 @@ class SyncEngine : public ModelTypeConfigurer { + virtual std::unique_ptr + GetNigoriControllerDelegate() = 0; + virtual void DispatchGetRecordsCallback( + brave_sync::GetRecordsCallback cb, diff --git a/patches/components-sync-engine-sync_manager.h.patch b/patches/components-sync-engine-sync_manager.h.patch index 74a151b461a4..88a806744eda 100644 --- a/patches/components-sync-engine-sync_manager.h.patch +++ b/patches/components-sync-engine-sync_manager.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine/sync_manager.h b/components/sync/engine/sync_manager.h -index 2a678f0a8d284de73dc0ef020b7869e7a570783d..1964971defdbb437b97ac44a7e8497fe566db907 100644 +index 8dfd2480f2a7483062fe57890fd442c9b420c5a0..ae26dd17fe9cbb12298f87ef81a398b9ac239912 100644 --- a/components/sync/engine/sync_manager.h +++ b/components/sync/engine/sync_manager.h -@@ -257,6 +257,9 @@ class SyncManager { +@@ -254,6 +254,9 @@ class SyncManager { std::string cache_guid; std::string birthday; std::string bag_of_chips; diff --git a/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch b/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch index f8e3a1d2df99..150b82906de1 100644 --- a/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch +++ b/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/cycle/sync_cycle.h b/components/sync/engine_impl/cycle/sync_cycle.h -index b41478d4cf2c1f3ee5a0e7effc43fe21b6184383..6c3b5a6972cf80cb5597f570bcc4c3abc0de9555 100644 +index 0971b6014231f8046eca9202840acc6167960057..e7c9f40c1f3294650597dab18d558c998cf8dd95 100644 --- a/components/sync/engine_impl/cycle/sync_cycle.h +++ b/components/sync/engine_impl/cycle/sync_cycle.h -@@ -84,6 +84,10 @@ class SyncCycle { +@@ -80,6 +80,10 @@ class SyncCycle { // Called when server requests a migration. virtual void OnReceivedMigrationRequest(ModelTypeSet types) = 0; diff --git a/patches/components-sync-engine_impl-get_updates_processor.cc.patch b/patches/components-sync-engine_impl-get_updates_processor.cc.patch index a8000185f0ba..51528b4a2749 100644 --- a/patches/components-sync-engine_impl-get_updates_processor.cc.patch +++ b/patches/components-sync-engine_impl-get_updates_processor.cc.patch @@ -1,16 +1,16 @@ diff --git a/components/sync/engine_impl/get_updates_processor.cc b/components/sync/engine_impl/get_updates_processor.cc -index e98ba9aa0801461d6698ba3ca6f39cf8f7153220..d007dd0260a97dc68d2113b6a2de3a94ab707f52 100644 +index faeff075cf940e8c1db7941f4c3dca27bf63f580..3829f379ca8167982e6a82654e3bb6ed9773b07d 100644 --- a/components/sync/engine_impl/get_updates_processor.cc +++ b/components/sync/engine_impl/get_updates_processor.cc -@@ -37,6 +37,7 @@ bool ShouldRequestEncryptionKey(SyncCycleContext* context) { +@@ -36,6 +36,7 @@ bool ShouldRequestEncryptionKey(SyncCycleContext* context) { SyncerError HandleGetEncryptionKeyResponse( const sync_pb::ClientToServerResponse& update_response, - syncable::Directory* dir) { + SyncCycleContext* context) { + return SyncerError(SyncerError::SYNCER_OK); bool success = false; if (update_response.get_updates().encryption_keys_size() == 0) { LOG(ERROR) << "Failed to receive encryption key from server."; -@@ -222,8 +223,8 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( +@@ -223,8 +224,8 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( ModelTypeSet partial_failure_data_types; diff --git a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch index 29ee76149658..f9ba4e9a2c76 100644 --- a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch +++ b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch @@ -1,10 +1,13 @@ diff --git a/components/sync/engine_impl/sync_manager_impl.cc b/components/sync/engine_impl/sync_manager_impl.cc -index f7a287c56667e43e85222bfecf9a076f1c717cb4..06de0e38047b933e21df845b9925b39307faca4f 100644 +index 60404b7479d5d5d23b13c2aa969133c927f34ecd..121487690c3279dfad941a8b7b85fbb6099faba3 100644 --- a/components/sync/engine_impl/sync_manager_impl.cc +++ b/components/sync/engine_impl/sync_manager_impl.cc -@@ -370,6 +370,7 @@ void SyncManagerImpl::Init(InitArgs* args) { +@@ -359,8 +359,9 @@ void SyncManagerImpl::Init(InitArgs* args) { + args->invalidator_client_id, args->poll_interval); + scheduler_ = args->engine_components_factory->BuildScheduler( name_, cycle_context_.get(), args->cancelation_signal, - args->enable_local_sync_backend); +- args->enable_local_sync_backend); ++ true); + BraveInit(args); scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); diff --git a/patches/components-sync-engine_impl-sync_manager_impl.h.patch b/patches/components-sync-engine_impl-sync_manager_impl.h.patch index 481dfa8cef06..2cdc7ab98783 100644 --- a/patches/components-sync-engine_impl-sync_manager_impl.h.patch +++ b/patches/components-sync-engine_impl-sync_manager_impl.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/sync_manager_impl.h b/components/sync/engine_impl/sync_manager_impl.h -index d0f1d63cc184c2b0780fea268a52cf52262efbd9..07bff3e8280dc7b621895076fd09851ffacfe4b2 100644 +index 10c1a959d084e504f8bcf58b05c047bd6b5ca33d..2b8b6769ae84f10eae4f0b5f01e360282dd497df 100644 --- a/components/sync/engine_impl/sync_manager_impl.h +++ b/components/sync/engine_impl/sync_manager_impl.h -@@ -202,6 +202,8 @@ class SyncManagerImpl +@@ -199,6 +199,8 @@ class SyncManagerImpl using NotificationInfoMap = std::map; diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch index 8635e0898308..0462e2958f40 100644 --- a/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/sync_scheduler_impl.cc b/components/sync/engine_impl/sync_scheduler_impl.cc -index 8cc16fa6acbd49d4c7bdcd9571fa97f919314710..cbbea83e2a143be848157895cbb64ded689dd358 100644 +index 217652eec756c9e4ff4bf7bd74a9cd481672ed1b..1f8066050f62b7d4bc882a5af2c24aec7b6999f2 100644 --- a/components/sync/engine_impl/sync_scheduler_impl.cc +++ b/components/sync/engine_impl/sync_scheduler_impl.cc -@@ -668,6 +668,7 @@ void SyncSchedulerImpl::TryCanaryJob() { +@@ -660,6 +660,7 @@ void SyncSchedulerImpl::TryCanaryJob() { } void SyncSchedulerImpl::TrySyncCycleJob() { diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch index 07102d8ab41d..b89871e9dfb4 100644 --- a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/sync_scheduler_impl.h b/components/sync/engine_impl/sync_scheduler_impl.h -index 56f6bf0ef065f776c24d473f7b9cc3b1d8d81e7d..ab31cca4a79738d27c8255c8a951dc7d92191d13 100644 +index 4bab39098da187109f291f1c0ab03fd0cc34d326..f48cf362f1030fd8b269ad213330255de95ea82c 100644 --- a/components/sync/engine_impl/sync_scheduler_impl.h +++ b/components/sync/engine_impl/sync_scheduler_impl.h -@@ -81,6 +81,12 @@ class SyncSchedulerImpl : public SyncScheduler { +@@ -79,6 +79,12 @@ class SyncSchedulerImpl : public SyncScheduler { void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override; void OnReceivedMigrationRequest(ModelTypeSet types) override; @@ -15,7 +15,7 @@ index 56f6bf0ef065f776c24d473f7b9cc3b1d8d81e7d..ab31cca4a79738d27c8255c8a951dc7d bool IsGlobalThrottle() const; bool IsGlobalBackoff() const; -@@ -179,6 +185,7 @@ class SyncSchedulerImpl : public SyncScheduler { +@@ -177,6 +183,7 @@ class SyncSchedulerImpl : public SyncScheduler { // current thread. In the future it will request access token here. void TrySyncCycleJob(); void TrySyncCycleJobImpl(); @@ -23,7 +23,7 @@ index 56f6bf0ef065f776c24d473f7b9cc3b1d8d81e7d..ab31cca4a79738d27c8255c8a951dc7d // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). // This function is for global throttling. -@@ -288,6 +295,9 @@ class SyncSchedulerImpl : public SyncScheduler { +@@ -281,6 +288,9 @@ class SyncSchedulerImpl : public SyncScheduler { // Used to prevent changing nudge delays by the server in integration tests. bool force_short_nudge_delay_for_test_ = false; diff --git a/patches/components-sync-engine_impl-syncer.cc.patch b/patches/components-sync-engine_impl-syncer.cc.patch index bc79a7ca5a5e..2d8b96f9e20f 100644 --- a/patches/components-sync-engine_impl-syncer.cc.patch +++ b/patches/components-sync-engine_impl-syncer.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/syncer.cc b/components/sync/engine_impl/syncer.cc -index 185e6463d605f8d13c2fa0a125d988e1f92e2aa3..d53834f95eca1f36d3bd2cccd5be4e2ddf919877 100644 +index ca2de93b0400bc718446f6aea2930000166df515..5a65337357aedd08edef53f7d14ca5f6a2c1802f 100644 --- a/components/sync/engine_impl/syncer.cc +++ b/components/sync/engine_impl/syncer.cc -@@ -104,6 +104,7 @@ bool Syncer::DownloadAndApplyUpdates(ModelTypeSet* request_types, +@@ -111,6 +111,7 @@ bool Syncer::DownloadAndApplyUpdates(ModelTypeSet* request_types, Difference(*request_types, requested_commit_only_types); GetUpdatesProcessor get_updates_processor( cycle->context()->model_type_registry()->update_handler_map(), delegate); diff --git a/patches/components-sync-engine_impl-syncer_proto_util.cc.patch b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch index 67b8374a3fa5..d66a165c8029 100644 --- a/patches/components-sync-engine_impl-syncer_proto_util.cc.patch +++ b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine_impl/syncer_proto_util.cc b/components/sync/engine_impl/syncer_proto_util.cc -index 5c695de7675bb390c99eea546ccc015c066cd44c..00458c17cc22a5d32ba3f8a74c14f191301a17f5 100644 +index 6706d0225207d266b1ed74cc712462052b3180a6..a58ea213c65714d4841d656e85d320c856ebc266 100644 --- a/components/sync/engine_impl/syncer_proto_util.cc +++ b/components/sync/engine_impl/syncer_proto_util.cc -@@ -436,7 +436,8 @@ void SyncerProtoUtil::AddRequiredFieldsToClientToServerMessage( +@@ -434,7 +434,8 @@ void SyncerProtoUtil::AddRequiredFieldsToClientToServerMessage( DCHECK(msg); SetProtocolVersion(msg); AddRequestBirthday(cycle->context()->directory(), msg); diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 1267e3b78aa2..2a7447e4bdfd 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..06d371a7136f7f287db0bdae8fd18ae7de4656c1 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..81744cb05711149192d93d0a2e688cf706720248 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -39,19 +39,18 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..06d371a7136f7f287db0bdae8fd18ae7 if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -429,6 +436,11 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -429,6 +436,10 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, UpdateTransactionVersion(new_version, model, std::vector(1, child)); + + BookmarkNodeChildrenReordered(model, new_parent); -+ if (old_parent != new_parent) { ++ if (old_parent != new_parent) + BookmarkNodeChildrenReordered(model, old_parent); -+ } } void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( -@@ -458,6 +470,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( +@@ -458,6 +469,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( return; } @@ -60,7 +59,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..06d371a7136f7f287db0bdae8fd18ae7 CreateOrUpdateSyncNode(node); } -@@ -490,6 +504,10 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( +@@ -490,6 +503,10 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( DCHECK_EQ(sync_child.GetParentId(), model_associator_->GetSyncIdFromChromeId(node->id())); @@ -71,7 +70,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..06d371a7136f7f287db0bdae8fd18ae7 if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -718,10 +736,12 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -718,10 +735,12 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } diff --git a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch index ba7b641b0194..7c9822526a76 100644 --- a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/sync_bookmarks/bookmark_local_changes_builder.cc b/components/sync_bookmarks/bookmark_local_changes_builder.cc -index 9d4210fe4771ac67df1f9563f1fc722f8fc35aae..ee2beb034b5e5f487c0fca0e88a31a7c241180ea 100644 +index f0b7bc6f9cea4eb3cb2386906bfc57be8bb5f802..5a96ebc0b5a2e3534d513a67b400c6997e786c05 100644 --- a/components/sync_bookmarks/bookmark_local_changes_builder.cc +++ b/components/sync_bookmarks/bookmark_local_changes_builder.cc -@@ -66,6 +66,7 @@ BookmarkLocalChangesBuilder::BuildCommitRequests(size_t max_entries) const { - data.specifics = CreateSpecificsFromBookmarkNode( +@@ -66,6 +66,7 @@ syncer::CommitRequestDataList BookmarkLocalChangesBuilder::BuildCommitRequests( + data->specifics = CreateSpecificsFromBookmarkNode( node, bookmark_model_, /*force_favicon_load=*/true); - data.non_unique_name = data.specifics.bookmark().title(); + data->non_unique_name = data->specifics.bookmark().title(); + brave_sync::AddBraveMetaInfo(node, bookmark_model_, true); } - request.entity = data.PassToPtr(); - request.sequence_number = metadata->sequence_number(); + auto request = std::make_unique(); + request->entity = std::move(data); From ed609294398da648c0f1a96b594809dc6a59be64 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Mon, 20 May 2019 17:47:09 +0300 Subject: [PATCH 22/73] Dont send bookmarks until chain is created. Re-do of brave-core pr#2016 --- components/brave_sync/brave_profile_sync_service.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 2afa55fed87b..2f5837b6ba54 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -485,7 +485,7 @@ void BraveProfileSyncService::OnSyncReady() { ProfileSyncService::GetUserSettings() ->SetSelectedTypes(false, syncer::UserSelectableTypeSet()); // default enable bookmark - OnSetSyncBookmarks(true); + brave_sync_prefs_->SetSyncBookmarksEnabled(true); ProfileSyncService::GetUserSettings()->SetSyncRequested(true); } } @@ -692,6 +692,7 @@ void BraveProfileSyncService::OnResolvedPreferences( bool contains_only_one_device = false; auto sync_devices = brave_sync_prefs_->GetSyncDevices(); + auto old_devices_size = sync_devices->size(); for (const auto &record : records) { DCHECK(record->has_device() || record->has_sitesetting()); if (record->has_device()) { @@ -715,6 +716,12 @@ void BraveProfileSyncService::OnResolvedPreferences( brave_sync_prefs_->SetSyncDevices(*sync_devices); + if (old_devices_size < 2 && sync_devices->size() >= 2) { + // Re-enable sync of bookmarks + bool sync_bookmarks = brave_sync_prefs_->GetSyncBookmarksEnabled(); + OnSetSyncBookmarks(sync_bookmarks); + } + if (this_device_deleted) { ResetSyncInternal(); } else if (contains_only_one_device) { From 6e31e373b25e7758291386c23fe61d41de88dc8d Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Fri, 24 May 2019 19:09:19 +0300 Subject: [PATCH 23/73] Force DEVICE_INFO to have nudge cycles --- components/brave_sync/brave_profile_sync_service.cc | 8 ++++++++ components/brave_sync/brave_profile_sync_service.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 2f5837b6ba54..93a1f5115ca6 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -490,6 +490,14 @@ void BraveProfileSyncService::OnSyncReady() { } } +syncer::ModelTypeSet BraveProfileSyncService::GetPreferredDataTypes() const { + // Force DEVICE_INFO type to have nudge cycle each time to fetch + // Brave sync devices. + // Will be picked up by ProfileSyncService::ConfigureDataTypeManager + return Union(ProfileSyncService::GetPreferredDataTypes(), + { syncer::DEVICE_INFO }); +} + void BraveProfileSyncService::OnGetExistingObjects( const std::string& category_name, std::unique_ptr records, diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 5a1d3f3741af..561151d1156f 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -95,6 +95,8 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, bool IsBraveSyncInitialized() const; bool IsBraveSyncConfigured() const; + syncer::ModelTypeSet GetPreferredDataTypes() const override; + private: FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkAdded); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkDeleted); From 1db950ad837cc6d265c8afb3e39a779506b7569b Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 24 May 2019 11:14:44 -0700 Subject: [PATCH 24/73] Register brave_sync pref with chromium sync --- browser/brave_profile_prefs.cc | 4 ---- chromium_src/components/sync/base/sync_prefs.cc | 2 ++ components/brave_sync/test_util.cc | 2 -- patches/components-sync-base-sync_prefs.cc.patch | 12 ++++++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 chromium_src/components/sync/base/sync_prefs.cc create mode 100644 patches/components-sync-base-sync_prefs.cc.patch diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 6c9024a326bf..b011b7c4d518 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -8,7 +8,6 @@ #include "brave/common/pref_names.h" #include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h" #include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" -#include "brave/components/brave_sync/brave_sync_prefs.h" #include "chrome/browser/net/prediction_options.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/common/pref_names.h" @@ -45,9 +44,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterBooleanPref(kLocationBarIsWide, false); registry->RegisterBooleanPref(kHideBraveRewardsButton, false); - //TODO(darkdh): merge into upstream SyncPrefs - brave_sync::prefs::Prefs::RegisterProfilePrefs(registry); - registry->RegisterBooleanPref(kWidevineOptedIn, false); registry->RegisterBooleanPref(kAskWidevineInstall, true); #if BUILDFLAG(BUNDLE_WIDEVINE_CDM) diff --git a/chromium_src/components/sync/base/sync_prefs.cc b/chromium_src/components/sync/base/sync_prefs.cc new file mode 100644 index 000000000000..beada7e637d7 --- /dev/null +++ b/chromium_src/components/sync/base/sync_prefs.cc @@ -0,0 +1,2 @@ +#include "brave/components/brave_sync/brave_sync_prefs.h" +#include "../../../../components/sync/base/sync_prefs.cc" diff --git a/components/brave_sync/test_util.cc b/components/brave_sync/test_util.cc index ede54853e6fe..7879ba204ee0 100644 --- a/components/brave_sync/test_util.cc +++ b/components/brave_sync/test_util.cc @@ -6,7 +6,6 @@ #include "base/files/file_util.h" #include "base/strings/utf_string_conversions.h" -#include "brave/components/brave_sync/brave_sync_prefs.h" #include "brave/components/brave_sync/tools.h" #include "brave/components/brave_sync/values_conv.h" #include "chrome/browser/prefs/browser_prefs.h" @@ -32,7 +31,6 @@ std::unique_ptr CreateBraveSyncProfile(const base::FilePath& path) { std::unique_ptr prefs( factory.CreateSyncable(registry.get())); RegisterUserProfilePrefs(registry.get()); - prefs::Prefs::RegisterProfilePrefs(registry.get()); TestingProfile::Builder profile_builder; profile_builder.SetPrefService(std::move(prefs)); diff --git a/patches/components-sync-base-sync_prefs.cc.patch b/patches/components-sync-base-sync_prefs.cc.patch new file mode 100644 index 000000000000..04c067ef6526 --- /dev/null +++ b/patches/components-sync-base-sync_prefs.cc.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync/base/sync_prefs.cc b/components/sync/base/sync_prefs.cc +index e0233e2c1fe41e7aca1514321881a9defe99e11f..8331c1add5cbc209023cfb938b11ef8c564e2b90 100644 +--- a/components/sync/base/sync_prefs.cc ++++ b/components/sync/base/sync_prefs.cc +@@ -186,6 +186,7 @@ void SyncPrefs::RegisterProfilePrefs( + #if defined(OS_CHROMEOS) + registry->RegisterStringPref(kSyncSpareBootstrapToken, ""); + #endif ++ brave_sync::prefs::Prefs::RegisterProfilePrefs(registry); + } + + void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { From bd689d0e83d18c3e23b47e46f0693c92a0ed28e6 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 24 May 2019 15:30:05 -0700 Subject: [PATCH 25/73] Consolidate BraveSyncServiceTest --- .../brave_sync/brave_profile_sync_service.cc | 6 +- .../brave_sync/brave_profile_sync_service.h | 4 +- .../brave_sync/brave_sync_service_unittest.cc | 96 ++++++++++++------- 3 files changed, 66 insertions(+), 40 deletions(-) diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 93a1f5115ca6..485dbad7c445 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -350,9 +350,9 @@ void BraveProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { type_set.Put(syncer::UserSelectableType::kBookmarks); else type_set.Remove(syncer::UserSelectableType::kBookmarks); - ProfileSyncService::GetUserSettings()->SetSelectedTypes(false, - type_set); - brave_sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); + ProfileSyncService::GetUserSettings()->SetSelectedTypes(false, type_set); + if (brave_sync_prefs_->GetSyncBookmarksEnabled() != sync_bookmarks) + brave_sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); } void BraveProfileSyncService::OnSetSyncBrowsingHistory( diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 561151d1156f..885b285b9a66 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -25,7 +25,7 @@ FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnGetInitData); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSaveBookmarksBaseOrder); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncPrefsChanged); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncDebug); -FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncReadyAlreadyWithSync); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, StartSyncNonDeviceRecords); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncReadyNewToSync); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnGetExistingObjects); @@ -113,7 +113,7 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetInitData); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncPrefsChanged); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncDebug); - FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncReadyAlreadyWithSync); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, StartSyncNonDeviceRecords); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncReadyNewToSync); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetExistingObjects); friend class ::BraveSyncServiceTest; diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 903b6e1afee7..270dc2fdceca 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -24,6 +24,7 @@ #include "components/bookmarks/browser/bookmark_utils.h" #include "components/bookmarks/test/test_bookmark_client.h" #include "components/prefs/pref_service.h" +#include "components/sync/base/pref_names.h" #include "content/public/browser/network_service_instance.h" #include "content/public/test/test_browser_thread_bundle.h" #include "net/base/network_interfaces.h" @@ -146,6 +147,8 @@ class BraveSyncServiceTest : public testing::Test { profile_ = brave_sync::CreateBraveSyncProfile(temp_dir_.GetPath()); EXPECT_TRUE(profile_.get() != NULL); + sync_prefs_ = std::make_unique(profile_->GetPrefs()); + // TODO(bridiver) - this is temporary until some changes are made to // to bookmark_change_processor to allow `set_for_testing` like // BraveSyncClient @@ -176,6 +179,8 @@ class BraveSyncServiceTest : public testing::Test { void TearDown() override { sync_service_->BraveSyncService::RemoveObserver(observer_.get()); // this will also trigger a shutdown of the brave sync service + sync_service_->Shutdown(); + sync_prefs_.reset(); profile_.reset(); } @@ -185,7 +190,11 @@ class BraveSyncServiceTest : public testing::Test { BookmarkModel* model() { return model_; } MockBraveSyncServiceObserver* observer() { return observer_.get(); } brave_sync::prefs::Prefs* brave_sync_prefs() { - return sync_service_->brave_sync_prefs_.get(); } + return sync_service_->brave_sync_prefs_.get(); + } + syncer::SyncPrefs* sync_prefs() { + return sync_prefs_.get(); + } private: // Need this as a very first member to run tests in UI thread @@ -197,6 +206,7 @@ class BraveSyncServiceTest : public testing::Test { BraveProfileSyncService* sync_service_; MockBraveSyncClient* sync_client_; BookmarkModel* model_; // Not owns + std::unique_ptr sync_prefs_; std::unique_ptr observer_; base::ScopedTempDir temp_dir_; @@ -548,6 +558,10 @@ TEST_F(BraveSyncServiceTest, OnResetSync) { EXPECT_FALSE(sync_service()->IsBraveSyncInitialized()); EXPECT_FALSE(sync_service()->IsBraveSyncConfigured()); + + EXPECT_FALSE(sync_prefs()->IsSyncRequested()); + EXPECT_FALSE(profile()->GetPrefs() + ->GetBoolean(syncer::prefs::kSyncBookmarks)); } TEST_F(BraveSyncServiceTest, OnSetSyncBookmarks) { @@ -555,12 +569,18 @@ TEST_F(BraveSyncServiceTest, OnSetSyncBookmarks) { brave_sync::prefs::kSyncBookmarksEnabled)); EXPECT_CALL(*observer(), OnSyncStateChanged).Times(1); sync_service()->OnSetSyncBookmarks(true); + EXPECT_TRUE(profile()->GetPrefs() + ->GetBoolean(syncer::prefs::kSyncBookmarks)); EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncBookmarksEnabled)); EXPECT_CALL(*observer(), OnSyncStateChanged).Times(1); sync_service()->OnSetSyncBookmarks(false); EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncBookmarksEnabled)); + EXPECT_FALSE(profile()->GetPrefs() + ->GetBoolean(syncer::prefs::kSyncBookmarks)); + EXPECT_CALL(*observer(), OnSyncStateChanged).Times(0); + sync_service()->OnSetSyncBookmarks(false); } TEST_F(BraveSyncServiceTest, OnSetSyncBrowsingHistory) { @@ -609,6 +629,7 @@ TEST_F(BraveSyncServiceTest, OnSaveBookmarksBaseOrder) { order.clear(); model()->other_node()->GetMetaInfo("order", &order); EXPECT_EQ(order, "1.1.2"); + EXPECT_EQ(brave_sync_prefs()->GetMigratedBookmarksVersion(), 2); } TEST_F(BraveSyncServiceTest, OnBraveSyncPrefsChanged) { @@ -617,51 +638,39 @@ TEST_F(BraveSyncServiceTest, OnBraveSyncPrefsChanged) { sync_service()->OnBraveSyncPrefsChanged(brave_sync::prefs::kSyncEnabled); } -TEST_F(BraveSyncServiceTest, DISABLED_OnSyncReadyAlreadyWithSync) { +TEST_F(BraveSyncServiceTest, StartSyncNonDeviceRecords) { EXPECT_FALSE(sync_service()->IsBraveSyncInitialized()); sync_service()->OnSetSyncEnabled(true); profile()->GetPrefs()->SetString( brave_sync::prefs::kSyncBookmarksBaseOrder, "1.1."); - // OnBraveSyncPrefsChanged => OnSyncStateChanged for - // kSyncSiteSettingsEnabled (1) and kSyncDeviceList (2) - EXPECT_CALL(*observer(), OnSyncStateChanged).Times(2); profile()->GetPrefs()->SetBoolean( - brave_sync::prefs::kSyncSiteSettingsEnabled, true); - profile()->GetPrefs()->SetTime( - brave_sync::prefs::kSyncLastFetchTime, base::Time::Now()); - const char* devices_json = R"( - { - "devices":[ - { - "device_id":"0", - "last_active":1552993896717.0, - "name":"Device1", - "object_id":"186, 247, 230, 75, 57, 111, 76, 166, 51, 142, 217, 221, 219, 237, 229, 235" - }, - { - "device_id":"1", - "last_active":1552993909257.0, - "name":"Device2", - "object_id":"36, 138, 200, 221, 191, 81, 214, 65, 134, 48, 55, 119, 162, 93, 33, 226" - } - ] - } - )"; - - profile()->GetPrefs()->SetString( - brave_sync::prefs::kSyncDeviceList, devices_json); - EXPECT_CALL(*sync_client(), SendFetchSyncRecords).Times(1); - EXPECT_CALL(*sync_client(), SendFetchSyncDevices).Times(1); - sync_service()->OnSyncReady(); - EXPECT_TRUE(sync_service()->IsBraveSyncInitialized()); + brave_sync::prefs::kSyncBookmarksEnabled, true); + EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); + brave_sync_prefs()->SetThisDeviceId("1"); + RecordsList records; + records.push_back(SimpleDeviceRecord( + SyncRecord::Action::A_CREATE, + "1", "device1")); + records.push_back(SimpleDeviceRecord( + SyncRecord::Action::A_CREATE, + "2", "device2")); + EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); + sync_service()->OnResolvedPreferences(records); + EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); } TEST_F(BraveSyncServiceTest, OnSyncReadyNewToSync) { EXPECT_CALL(*observer(), OnSyncStateChanged); - profile()->GetPrefs()->SetBoolean( - brave_sync::prefs::kSyncSiteSettingsEnabled, true); EXPECT_CALL(*sync_client(), SendGetBookmarksBaseOrder).Times(1); sync_service()->OnSyncReady(); + + // simulate OnSaveBookmarksBaseOrder + profile()->GetPrefs()->SetString( + brave_sync::prefs::kSyncBookmarksBaseOrder, "1.1."); + sync_service()->OnSyncReady(); + EXPECT_TRUE(sync_prefs()->IsSyncRequested()); + EXPECT_FALSE(profile()->GetPrefs() + ->GetBoolean(syncer::prefs::kSyncBookmarks)); } TEST_F(BraveSyncServiceTest, OnGetExistingObjects) { @@ -740,3 +749,20 @@ TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncEnabled)); } + +TEST_F(BraveSyncServiceTest, GetPreferredDataTypes) { + // Make sure GetPreferredDataTypes contains DEVICE_INFO which is needed for + // brave device record polling + EXPECT_TRUE(sync_service()->GetPreferredDataTypes().Has(syncer::DEVICE_INFO)); +} + +TEST_F(BraveSyncServiceTest, GetDisableReasons) { + EXPECT_NE(sync_service()->GetDisableReasons(), + syncer::SyncService::DISABLE_REASON_NONE); + sync_service()->OnSetSyncEnabled(true); + EXPECT_NE(sync_service()->GetDisableReasons(), + syncer::SyncService::DISABLE_REASON_NONE); + brave_sync_prefs()->SetMigratedBookmarksVersion(2); + EXPECT_EQ(sync_service()->GetDisableReasons(), + syncer::SyncService::DISABLE_REASON_NONE); +} From c5fbe1f2a267bc358f9040eb394eff5df7e3de22 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 28 May 2019 11:03:59 -0700 Subject: [PATCH 26/73] Remove manually disable field trail feature Make sure https://github.com/brave/brave-browser/pull/4551 and https://github.com/brave/brave-core/pull/2471 landed first --- app/brave_main_delegate.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/brave_main_delegate.cc b/app/brave_main_delegate.cc index b915c3d4b54e..97564b7fabe3 100644 --- a/app/brave_main_delegate.cc +++ b/app/brave_main_delegate.cc @@ -28,7 +28,6 @@ #include "components/autofill/core/common/autofill_payments_features.h" #include "components/omnibox/common/omnibox_features.h" #include "components/password_manager/core/common/password_manager_features.h" -#include "components/sync/driver/sync_driver_switches.h" #include "components/unified_consent/feature.h" #include "extensions/common/extension_features.h" #include "services/network/public/cpp/features.h" @@ -160,9 +159,6 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) { // Disabled features. const std::unordered_set disabled_features = { autofill::features::kAutofillServerCommunication.name, - // TODO(darkdh): remove this when USS bookmarks is mature - // 84919fdb99b162030a1113d5990667885b774064 - switches::kSyncUSSBookmarks.name, network::features::kNetworkService.name, unified_consent::kUnifiedConsent.name, }; From 5b0f830b763a70b0ba7b57625adecb3f998de9dc Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 28 May 2019 15:19:40 -0700 Subject: [PATCH 27/73] lint fix --- browser/extensions/api/brave_sync_api.cc | 4 +- .../extensions/api/brave_sync_event_router.cc | 12 ++- .../extensions/api/brave_sync_event_router.h | 22 +++-- browser/ui/webui/sync/sync_ui.cc | 18 ++-- .../chrome/browser/sync/chrome_sync_client.cc | 7 +- .../sync/profile_sync_service_factory.cc | 12 ++- .../sync/profile_sync_service_factory.h | 10 ++ .../components/sync/base/sync_prefs.cc | 7 +- .../sync/driver/glue/sync_engine_backend.cc | 12 ++- .../sync/driver/glue/sync_engine_backend.h | 10 ++ .../sync/driver/glue/sync_engine_impl.cc | 14 ++- .../sync/driver/glue/sync_engine_impl.h | 10 ++ .../sync/driver/profile_sync_service.cc | 7 +- .../components/sync/driver/sync_client.cc | 9 +- .../components/sync/driver/sync_client.h | 10 ++ .../components/sync/engine/sync_engine.h | 10 ++ .../components/sync/engine/sync_manager.h | 10 ++ .../components/sync/engine_impl/commit.cc | 11 ++- .../sync/engine_impl/cycle/sync_cycle.h | 10 ++ .../sync/engine_impl/get_updates_processor.cc | 15 ++- .../sync/engine_impl/get_updates_processor.h | 10 ++ .../sync/engine_impl/sync_manager_impl.cc | 7 +- .../sync/engine_impl/sync_scheduler_impl.cc | 7 +- .../components/sync/engine_impl/syncer.cc | 14 ++- .../components/sync/engine_impl/syncer.h | 11 +++ .../bookmark_change_processor.cc | 7 +- .../bookmark_local_changes_builder.cc | 7 +- .../bookmark_order_util_unittest.cc | 11 ++- .../brave_sync/brave_profile_sync_service.cc | 6 +- .../brave_sync/brave_profile_sync_service.h | 3 + components/brave_sync/brave_sync_service.cc | 8 +- components/brave_sync/brave_sync_service.h | 15 +-- .../brave_sync/brave_sync_service_unittest.cc | 5 +- .../client/brave_sync_client_impl.cc | 6 +- .../client/brave_sync_client_impl.h | 19 ++-- .../brave_sync/client/client_ext_impl_data.cc | 70 ++++++++------ .../brave_sync/client/client_ext_impl_data.h | 38 ++++---- components/brave_sync/jslib_messages.cc | 94 ++++++++++--------- components/brave_sync/jslib_messages.h | 48 +++++----- components/brave_sync/jslib_messages_fwd.h | 7 +- components/brave_sync/syncer_helper.cc | 2 +- .../brave_sync/syncer_helper_unittest.cc | 3 +- components/brave_sync/test_util.cc | 14 ++- components/brave_sync/test_util.h | 11 ++- 44 files changed, 450 insertions(+), 193 deletions(-) diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index d4c6a8d3b252..1fa14497f85b 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -104,7 +104,7 @@ ExtensionFunction::ResponseAction BraveSyncGetExistingObjectsFunction::Run() { EXTENSION_FUNCTION_VALIDATE(params.get()); auto records = std::make_unique>(); - ::brave_sync::ConvertSyncRecords(params->records, *records.get()); + ::brave_sync::ConvertSyncRecords(params->records, records.get()); BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); @@ -124,7 +124,7 @@ ExtensionFunction::ResponseAction BraveSyncResolvedSyncRecordsFunction::Run() { EXTENSION_FUNCTION_VALIDATE(params.get()); auto records = std::make_unique>(); - ::brave_sync::ConvertSyncRecords(params->records, *records.get()); + ::brave_sync::ConvertSyncRecords(params->records, records.get()); BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); diff --git a/browser/extensions/api/brave_sync_event_router.cc b/browser/extensions/api/brave_sync_event_router.cc index 528c0de06592..f84d3b4533d0 100644 --- a/browser/extensions/api/brave_sync_event_router.cc +++ b/browser/extensions/api/brave_sync_event_router.cc @@ -1,9 +1,13 @@ -/* 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/. */ +/* 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/extensions/api/brave_sync_event_router.h" +#include +#include + #include "brave/common/extensions/api/brave_sync.h" #include "chrome/browser/profiles/profile.h" #include "extensions/browser/extension_event_histogram_value.h" @@ -142,4 +146,4 @@ void BraveSyncEventRouter::LoadClient() { event_router_->BroadcastEvent(std::move(event)); } -} // namespace extensions +} // namespace extensions diff --git a/browser/extensions/api/brave_sync_event_router.h b/browser/extensions/api/brave_sync_event_router.h index 3e106073b01c..e9b19e55b35f 100644 --- a/browser/extensions/api/brave_sync_event_router.h +++ b/browser/extensions/api/brave_sync_event_router.h @@ -1,11 +1,13 @@ -/* 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/. */ +/* 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_BROWSER_EXTENSIONS_API_BRAVE_SYNC_EVENT_ROUTER_H_ #define BRAVE_BROWSER_EXTENSIONS_API_BRAVE_SYNC_EVENT_ROUTER_H_ #include +#include #include "extensions/browser/event_router.h" class Profile; @@ -16,9 +18,9 @@ namespace brave_sync { struct SyncRecord; struct Config; struct RecordAndExistingObject; -} // namespace brave_sync -} // namespace api -} // namespace extensions +} // namespace brave_sync +} // namespace api +} // namespace extensions using extensions::api::brave_sync::RecordAndExistingObject; @@ -30,7 +32,7 @@ namespace extensions { class BraveSyncEventRouter { public: - BraveSyncEventRouter(Profile* profile); + explicit BraveSyncEventRouter(Profile* profile); ~BraveSyncEventRouter(); void GotInitData( @@ -59,10 +61,10 @@ class BraveSyncEventRouter { void LoadClient(); -private: + private: EventRouter* event_router_; }; -} // namespace extensions +} // namespace extensions -#endif // BRAVE_BROWSER_EXTENSIONS_API_BRAVE_SYNC_EVENT_ROUTER_H_ +#endif // BRAVE_BROWSER_EXTENSIONS_API_BRAVE_SYNC_EVENT_ROUTER_H_ diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index 8dc037ce9298..5d3f3c217fca 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -1,12 +1,17 @@ -/* 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/. */ +/* 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_profile_sync_service.h" +#include "brave/components/brave_sync/brave_profile_sync_service.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_resources.h" @@ -121,7 +126,8 @@ void SyncUIDOMHandler::Init() { Profile* profile = Profile::FromWebUI(web_ui()); sync_service_ = static_cast( - ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile(profile)); + ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( + profile)); if (sync_service_) sync_service_->AddObserver(this); } @@ -247,7 +253,7 @@ void SyncUIDOMHandler::OnHaveSyncWords( "sync_ui_exports.haveSyncWords", base::Value(sync_words)); } -} // namespace +} // namespace SyncUI::SyncUI(content::WebUI* web_ui, const std::string& name) : BasicUI(web_ui, name, diff --git a/chromium_src/chrome/browser/sync/chrome_sync_client.cc b/chromium_src/chrome/browser/sync/chrome_sync_client.cc index 1822dc85b0d8..0bef1a6efe8f 100644 --- a/chromium_src/chrome/browser/sync/chrome_sync_client.cc +++ b/chromium_src/chrome/browser/sync/chrome_sync_client.cc @@ -1,5 +1,10 @@ +/* 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/client/brave_sync_client_impl.h" -#include "../../../../../chrome/browser/sync/chrome_sync_client.cc" +#include "../../../../../chrome/browser/sync/chrome_sync_client.cc" // NOLINT namespace browser_sync { diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index 1390be708b19..fde8c2d3d38c 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -1,9 +1,17 @@ +/* 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/chrome/browser/sync/profile_sync_service_factory.h" + #include "brave/components/brave_sync/brave_profile_sync_service.h" using brave_sync::BraveProfileSyncService; -#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" +#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" // NOLINT // static BraveProfileSyncService* -ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile(Profile* profile) { +ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( + Profile* profile) { return static_cast(GetForProfile(profile)); } diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.h b/chromium_src/chrome/browser/sync/profile_sync_service_factory.h index 20da561ee9cf..51d3d6a2e224 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.h +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.h @@ -1,4 +1,14 @@ +/* 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_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ + namespace brave_sync { class BraveProfileSyncService; } // namespace brave_sync #include "../../../../../chrome/browser/sync/profile_sync_service_factory.h" + +#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ // NOLINT diff --git a/chromium_src/components/sync/base/sync_prefs.cc b/chromium_src/components/sync/base/sync_prefs.cc index beada7e637d7..99164855dff1 100644 --- a/chromium_src/components/sync/base/sync_prefs.cc +++ b/chromium_src/components/sync/base/sync_prefs.cc @@ -1,2 +1,7 @@ +/* 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/brave_sync_prefs.h" -#include "../../../../components/sync/base/sync_prefs.cc" +#include "../../../../components/sync/base/sync_prefs.cc" // NOLINT diff --git a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc index 4cc82d118c8e..9d4d89c926ad 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc @@ -1,4 +1,14 @@ -#include "../../../../../../components/sync/driver/glue/sync_engine_backend.cc" +/* 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/glue/sync_engine_backend.cc" // NOLINT + +#include "brave/chromium_src/components/sync/driver/glue/sync_engine_backend.h" + +#include +#include #include "brave/components/brave_sync/jslib_messages.h" diff --git a/chromium_src/components/sync/driver/glue/sync_engine_backend.h b/chromium_src/components/sync/driver/glue/sync_engine_backend.h index 9fc6b28917c5..0c3b12993f24 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_backend.h +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.h @@ -1,6 +1,16 @@ +/* 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_BACKEND_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_BACKEND_H_ + #include "brave/components/brave_sync/jslib_messages_fwd.h" namespace syncer { using brave_sync::GetRecordsCallback; using brave_sync::RecordsList; } // namespace syncer #include "../../../../../../components/sync/driver/glue/sync_engine_backend.h" + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_BACKEND_H_ // NOLINT diff --git a/chromium_src/components/sync/driver/glue/sync_engine_impl.cc b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc index 7f54f287a298..7a1f6ea23172 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_impl.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc @@ -1,4 +1,14 @@ -#include "../../../../../../components/sync/driver/glue/sync_engine_impl.cc" +/* 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/glue/sync_engine_impl.cc" // NOLINT + +#include "brave/chromium_src/components/sync/driver/glue/sync_engine_impl.h" + +#include +#include #include "brave/components/brave_sync/jslib_messages.h" @@ -27,4 +37,4 @@ void SyncEngineImpl::DispatchGetRecordsCallback( cb, std::move(records))); } -} // namespacd syncer +} // namespace syncer diff --git a/chromium_src/components/sync/driver/glue/sync_engine_impl.h b/chromium_src/components/sync/driver/glue/sync_engine_impl.h index 5223e21b0949..ca10bc3f4e53 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_impl.h +++ b/chromium_src/components/sync/driver/glue/sync_engine_impl.h @@ -1,6 +1,16 @@ +/* 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_ + #include "brave/components/brave_sync/jslib_messages_fwd.h" namespace syncer { using brave_sync::GetRecordsCallback; using brave_sync::RecordsList; } // namespace syncer #include "../../../../../../components/sync/driver/glue/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 1b33eee5b8ab..3839ef1bfb05 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -1,6 +1,11 @@ +/* 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/. */ + // For use_transport_only_mode #define IsSyncFeatureEnabled IsBraveSyncEnabled -#include "../../../../components/sync/driver/profile_sync_service.cc" +#include "../../../../components/sync/driver/profile_sync_service.cc" // NOLINT #include "base/bind.h" #include "brave/components/brave_sync/jslib_messages.h" diff --git a/chromium_src/components/sync/driver/sync_client.cc b/chromium_src/components/sync/driver/sync_client.cc index bdbf540face7..3d3c20659d76 100644 --- a/chromium_src/components/sync/driver/sync_client.cc +++ b/chromium_src/components/sync/driver/sync_client.cc @@ -1,4 +1,11 @@ -#include "../../../../../components/sync/driver/sync_client.cc" +/* 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/sync_client.cc" // NOLINT + +#include "brave/chromium_src/components/sync/driver/sync_client.h" namespace syncer { diff --git a/chromium_src/components/sync/driver/sync_client.h b/chromium_src/components/sync/driver/sync_client.h index d2e2ea7e6f10..eb27db60efc9 100644 --- a/chromium_src/components/sync/driver/sync_client.h +++ b/chromium_src/components/sync/driver/sync_client.h @@ -1,5 +1,15 @@ +/* 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_SYNC_CLIENT_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_SYNC_CLIENT_H_ + namespace brave_sync { class BraveSyncClient; } // namespace brave_sync #include "../../../../../components/sync/driver/sync_client.h" + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_SYNC_CLIENT_H_ diff --git a/chromium_src/components/sync/engine/sync_engine.h b/chromium_src/components/sync/engine/sync_engine.h index faf39481077a..c18f8c7b41c6 100644 --- a/chromium_src/components/sync/engine/sync_engine.h +++ b/chromium_src/components/sync/engine/sync_engine.h @@ -1,2 +1,12 @@ +/* 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" #include "../../../../../components/sync/engine/sync_engine.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 index f4cd5a839aa0..137e988f3801 100644 --- a/chromium_src/components/sync/engine/sync_manager.h +++ b/chromium_src/components/sync/engine/sync_manager.h @@ -1,5 +1,15 @@ +/* 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 #include "../../../../../components/sync/engine/sync_manager.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 index 1c3d3e681882..1675b928a9a7 100644 --- a/chromium_src/components/sync/engine_impl/commit.cc +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -1,3 +1,8 @@ +/* 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; @@ -15,7 +20,7 @@ SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message, } // namespace syncer -#include "../../../../../components/sync/engine_impl/commit.cc" +#include "../../../../../components/sync/engine_impl/commit.cc" // NOLINT #include "base/base64.h" #include "brave/components/brave_sync/jslib_const.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" @@ -155,7 +160,7 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, response->mutable_commit()->add_entryresponse(); CreateSuccessfulCommitResponse(entity, entry_response, new_object_id); } - return record_list; + return record_list; } SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message, @@ -168,5 +173,5 @@ SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message, 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 index 374c81d96589..7a8c9c9a422e 100644 --- a/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h +++ b/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h @@ -1,2 +1,12 @@ +/* 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" #include "../../../../../../components/sync/engine_impl/cycle/sync_cycle.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 index eab7e3b77db3..a094867ff2c3 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -1,12 +1,22 @@ +/* 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" +#include "../../../../../components/sync/engine_impl/get_updates_processor.cc" // NOLINT #include "base/base64.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" @@ -126,7 +136,8 @@ void AddRootForType(sync_pb::SyncEntity* entity, ModelType type) { entity->mutable_specifics()->CopyFrom(specifics); } -void AddPermanentNode(sync_pb::SyncEntity* entity, const std::string& name, const std::string& tag) { +void AddPermanentNode(sync_pb::SyncEntity* entity, const std::string& name, + const std::string& tag) { DCHECK(entity); sync_pb::EntitySpecifics specifics; AddDefaultFieldValue(BOOKMARKS, &specifics); diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.h b/chromium_src/components/sync/engine_impl/get_updates_processor.h index 00861b5ec12f..2ef6e40fb3bd 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.h +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.h @@ -1,5 +1,15 @@ +/* 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 #include "../../../../../components/sync/engine_impl/get_updates_processor.h" + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_GET_UPDATES_PROCESSOR_H_ // NOLINT diff --git a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc index 9c1d3e75f9fc..97ab7e4754b2 100644 --- a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc +++ b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc @@ -1,4 +1,9 @@ -#include "../../../../../components/sync/engine_impl/sync_manager_impl.cc" +/* 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_manager_impl.cc" // NOLINT #include "brave/components/brave_sync/jslib_messages.h" namespace syncer { diff --git a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc index 7ff63b6ebc5d..5b22dc5e7f7a 100644 --- a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc +++ b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc @@ -1,4 +1,9 @@ -#include "../../../../../components/sync/engine_impl/sync_scheduler_impl.cc" +/* 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.cc" // NOLINT #include "brave/components/brave_sync/jslib_messages.h" diff --git a/chromium_src/components/sync/engine_impl/syncer.cc b/chromium_src/components/sync/engine_impl/syncer.cc index 8568fdd9548b..ca196354eab9 100644 --- a/chromium_src/components/sync/engine_impl/syncer.cc +++ b/chromium_src/components/sync/engine_impl/syncer.cc @@ -1,6 +1,14 @@ -#include "brave/components/brave_sync/jslib_messages.h" -#include "base/synchronization/waitable_event.h" -#include "../../../../../components/sync/engine_impl/syncer.cc" +/* 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 "../../../../../components/sync/engine_impl/syncer.cc" // NOLINT namespace syncer { diff --git a/chromium_src/components/sync/engine_impl/syncer.h b/chromium_src/components/sync/engine_impl/syncer.h index efd21a62c803..d7b0b1e999b7 100644 --- a/chromium_src/components/sync/engine_impl/syncer.h +++ b/chromium_src/components/sync/engine_impl/syncer.h @@ -1,6 +1,17 @@ +/* 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 "base/memory/weak_ptr.h" +#include "brave/components/brave_sync/jslib_messages.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" namespace syncer { class GetUpdatesProcessor; } // namespace syncer #include "../../../../../components/sync/engine_impl/syncer.h" + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 5bba06e28e2b..e0903b5aef78 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -1,3 +1,8 @@ +/* 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/bookmarks/browser/bookmark_model.h" namespace { @@ -23,7 +28,7 @@ class ScopedPauseObserver { } // namespace #include "brave/components/brave_sync/syncer_helper.h" -#include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" +#include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" // NOLINT namespace sync_bookmarks { diff --git a/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc b/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc index 4fa9caabef30..04d81814ca2f 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc @@ -1,3 +1,8 @@ +/* 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/. */ + // This override is for kSyncUSSBookmarks #include "brave/components/brave_sync/syncer_helper.h" -#include "../../../../components/sync_bookmarks/bookmark_local_changes_builder.cc" +#include "../../../../components/sync_bookmarks/bookmark_local_changes_builder.cc" // NOLINT diff --git a/components/brave_sync/bookmark_order_util_unittest.cc b/components/brave_sync/bookmark_order_util_unittest.cc index 0b6e2f54b48c..29f5b45ae9c0 100644 --- a/components/brave_sync/bookmark_order_util_unittest.cc +++ b/components/brave_sync/bookmark_order_util_unittest.cc @@ -1,4 +1,5 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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/. */ @@ -22,9 +23,9 @@ TEST(BookmarkOrderUtilTest, OrderToIntVect_SingleValue) { TEST(BookmarkOrderUtilTest, OrderToIntVect_TypicalValue) { std::vector result = OrderToIntVect("1.7.4"); ASSERT_EQ(result.size(), 3u); - EXPECT_TRUE(result.at(0) == 1); - EXPECT_TRUE(result.at(1) == 7); - EXPECT_TRUE(result.at(2) == 4); + EXPECT_EQ(result.at(0), 1); + EXPECT_EQ(result.at(1), 7); + EXPECT_EQ(result.at(2), 4); } TEST(BookmarkOrderUtilTest, OrderToIntVect_WrongValue) { @@ -54,4 +55,4 @@ TEST(BookmarkOrderUtilTest, CompareOrder) { EXPECT_FALSE(CompareOrder("1.7.0.2", "1.7.0.1")); } -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 485dbad7c445..28f2dc435e2b 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -5,6 +5,9 @@ #include "brave/components/brave_sync/brave_profile_sync_service.h" +#include +#include + #include "base/bind.h" #include "base/strings/utf_string_conversions.h" #include "brave/components/brave_sync/values_conv.h" @@ -218,7 +221,6 @@ BraveProfileSyncService::BraveProfileSyncService(InitParams init_params) !brave_sync_prefs_->GetThisDeviceName().empty()) { brave_sync_configured_ = true; } - } void BraveProfileSyncService::OnNudgeSyncCycle( @@ -756,7 +758,7 @@ BraveSyncClient* BraveProfileSyncService::GetBraveSyncClient() { return ProfileSyncService::GetSyncClient()->GetBraveSyncClient(); } -bool BraveProfileSyncService::IsBraveSyncEnabled() const{ +bool BraveProfileSyncService::IsBraveSyncEnabled() const { return brave_sync_prefs_->GetSyncEnabled(); } diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 885b285b9a66..3d9c3a0a975f 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -6,6 +6,9 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_H_ #define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_H_ +#include +#include + #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" diff --git a/components/brave_sync/brave_sync_service.cc b/components/brave_sync/brave_sync_service.cc index 20d180438766..bcef737d66ee 100644 --- a/components/brave_sync/brave_sync_service.cc +++ b/components/brave_sync/brave_sync_service.cc @@ -1,6 +1,8 @@ -/* 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/. */ +/* 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_sync_service.h" #include "base/command_line.h" diff --git a/components/brave_sync/brave_sync_service.h b/components/brave_sync/brave_sync_service.h index ced50161e767..58ab16e89720 100644 --- a/components/brave_sync/brave_sync_service.h +++ b/components/brave_sync/brave_sync_service.h @@ -1,9 +1,12 @@ -/* 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_SYNC_BRAVE_SYNC_SERVICE_H_ -#define BRAVE_COMPONENTS_SYNC_BRAVE_SYNC_SERVICE_H_ +/* 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_BRAVE_SYNC_SERVICE_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_SERVICE_H_ + +#include #include #include "base/macros.h" @@ -68,4 +71,4 @@ class BraveSyncService { } // namespace brave_sync -#endif // BRAVE_COMPONENTS_SYNC_BRAVE_SYNC_SERVICE_H_ +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_SERVICE_H_ diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 270dc2fdceca..fcdeadb0d847 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -3,6 +3,8 @@ * 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 "base/files/scoped_temp_dir.h" #include "base/strings/utf_string_conversions.h" #include "brave/components/brave_sync/client/brave_sync_client_impl.h" @@ -645,7 +647,8 @@ TEST_F(BraveSyncServiceTest, StartSyncNonDeviceRecords) { brave_sync::prefs::kSyncBookmarksBaseOrder, "1.1."); profile()->GetPrefs()->SetBoolean( brave_sync::prefs::kSyncBookmarksEnabled, true); - EXPECT_FALSE(profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); + EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( + syncer::prefs::kSyncBookmarks)); brave_sync_prefs()->SetThisDeviceId("1"); RecordsList records; records.push_back(SimpleDeviceRecord( diff --git a/components/brave_sync/client/brave_sync_client_impl.cc b/components/brave_sync/client/brave_sync_client_impl.cc index 7a49ee99e787..fda2f73b0e70 100644 --- a/components/brave_sync/client/brave_sync_client_impl.cc +++ b/components/brave_sync/client/brave_sync_client_impl.cc @@ -72,7 +72,7 @@ void BraveSyncClientImpl::SendGotInitData(const Uint8Array& seed, const std::string& sync_words) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); extensions::api::brave_sync::Config config_extension; - ConvertConfig(config, config_extension); + ConvertConfig(config, &config_extension); brave_sync_event_router_->GotInitData(seed, device_id, config_extension, sync_words); } @@ -99,7 +99,7 @@ void BraveSyncClientImpl::SendResolveSyncRecords( records_and_existing_objects_ext; ConvertResolvedPairs(*records_and_existing_objects, - records_and_existing_objects_ext); + &records_and_existing_objects_ext); brave_sync_event_router_->ResolveSyncRecords(category_name, records_and_existing_objects_ext); @@ -109,7 +109,7 @@ void BraveSyncClientImpl::SendSyncRecords(const std::string &category_name, const RecordsList &records) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); std::vector records_ext; - ConvertSyncRecordsFromLibToExt(records, records_ext); + ConvertSyncRecordsFromLibToExt(records, &records_ext); brave_sync_event_router_->SendSyncRecords(category_name, records_ext); } diff --git a/components/brave_sync/client/brave_sync_client_impl.h b/components/brave_sync/client/brave_sync_client_impl.h index ab4d531ec36c..9c47a0407da9 100644 --- a/components/brave_sync/client/brave_sync_client_impl.h +++ b/components/brave_sync/client/brave_sync_client_impl.h @@ -1,9 +1,14 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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_BRAVE_SYNC_CLIENT_IMPL_H -#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_CLIENT_IMPL_H +#ifndef BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BRAVE_SYNC_CLIENT_IMPL_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BRAVE_SYNC_CLIENT_IMPL_H_ + +#include +#include +#include #include "brave/components/brave_sync/client/brave_sync_client.h" #include "base/macros.h" @@ -21,7 +26,7 @@ class BraveSyncEventRouter; namespace brave_sync { namespace prefs { - class Prefs; +class Prefs; } using extensions::Extension; @@ -46,7 +51,7 @@ class BraveSyncClientImpl : public BraveSyncClient, void SendFetchSyncRecords( const std::vector &category_names, const base::Time &startAt, const int max_records) override; - void SendFetchSyncDevices() override ; + void SendFetchSyncDevices() override; void SendResolveSyncRecords( const std::string& category_name, std::unique_ptr records) override; @@ -92,6 +97,6 @@ class BraveSyncClientImpl : public BraveSyncClient, DISALLOW_COPY_AND_ASSIGN(BraveSyncClientImpl); }; -} // namespace brave_sync +} // namespace brave_sync -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_CLIENT_IMPL_H +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BRAVE_SYNC_CLIENT_IMPL_H_ diff --git a/components/brave_sync/client/client_ext_impl_data.cc b/components/brave_sync/client/client_ext_impl_data.cc index 8c8bbef074e6..bdc1d4e88156 100644 --- a/components/brave_sync/client/client_ext_impl_data.cc +++ b/components/brave_sync/client/client_ext_impl_data.cc @@ -1,9 +1,13 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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/client/client_ext_impl_data.h" +#include +#include + #include "brave/common/extensions/api/brave_sync.h" #include "brave/components/brave_sync/client/client_data.h" #include "brave/components/brave_sync/jslib_messages.h" @@ -12,10 +16,11 @@ namespace brave_sync { void ConvertConfig(const brave_sync::client_data::Config &config, - extensions::api::brave_sync::Config &config_extension) { - config_extension.api_version = config.api_version; - config_extension.server_url = config.server_url; - config_extension.debug = config.debug; + extensions::api::brave_sync::Config* config_extension) { + DCHECK(config_extension); + config_extension->api_version = config.api_version; + config_extension->server_url = config.server_url; + config_extension->debug = config.debug; } std::unique_ptr FromExtSite( @@ -51,7 +56,7 @@ std::unique_ptr FromExtSiteSetting( } CHECK_AND_ASSIGN(zoomLevel, zoom_level); CHECK_AND_ASSIGN(shieldsUp, shields_up); - //DCHECK(false); + // DCHECK(false); // site_setting-> = ext_site_setting.ad_control; // site_setting-> = ext_site_setting.cookie_control; CHECK_AND_ASSIGN(safeBrowsing, safe_browsing); @@ -113,8 +118,8 @@ std::unique_ptr FromLibSite( ext_site->location = lib_site.location; ext_site->title = lib_site.title; ext_site->custom_title = lib_site.customTitle; - ext_site->last_accessed_time = 0;//lib_site.lastAccessedTime.ToJsTime(); - ext_site->creation_time = 0;//lib_site.creationTime.ToJsTime(); + ext_site->last_accessed_time = 0; // lib_site.lastAccessedTime.ToJsTime(); + ext_site->creation_time = 0; // lib_site.creationTime.ToJsTime(); ext_site->favicon = lib_site.favicon; return ext_site; @@ -175,9 +180,9 @@ std::unique_ptr FromLibSiteSetting( ext_site_setting->zoom_level.reset(new double(lib_site_setting.zoomLevel)); ext_site_setting->shields_up.reset(new bool (lib_site_setting.shieldsUp)); - //ext_site_setting->ad_control = lib_site_setting.adControl; - //ext_site_setting->cookie_control = lib_site_setting.cookieControl; - //DCHECK(false); + // ext_site_setting->ad_control = lib_site_setting.adControl; + // ext_site_setting->cookie_control = lib_site_setting.cookieControl; + // DCHECK(false); ext_site_setting->safe_browsing.reset( new bool(lib_site_setting.safeBrowsing)); ext_site_setting->no_script.reset(new bool(lib_site_setting.noScript)); @@ -204,11 +209,11 @@ std::unique_ptr FromLibDevice( return ext_device; } -std::unique_ptr FromLibSyncRecord( +std::unique_ptr FromLibSyncRecord( const brave_sync::SyncRecordPtr &lib_record) { DCHECK(lib_record); - std::unique_ptr ext_record = - std::make_unique(); + std::unique_ptr ext_record = + std::make_unique(); ext_record->action = static_cast(lib_record->action); ext_record->device_id = UCharVecFromString(lib_record->deviceId); @@ -236,10 +241,12 @@ std::unique_ptr FromLibSyncRecord( } brave_sync::SyncRecordPtr FromExtSyncRecord( - const extensions::api::brave_sync::SyncRecord &ext_record) { - brave_sync::SyncRecordPtr record = std::make_unique(); + const SyncRecord &ext_record) { + brave_sync::SyncRecordPtr record = + std::make_unique(); - record->action = ConvertEnum(ext_record.action, + record->action = ConvertEnum( + ext_record.action, brave_sync::jslib::SyncRecord::Action::A_MIN, brave_sync::jslib::SyncRecord::Action::A_MAX, brave_sync::jslib::SyncRecord::Action::A_INVALID); @@ -288,21 +295,21 @@ brave_sync::SyncRecordPtr FromExtSyncRecord( void ConvertSyncRecords( const std::vector& ext_records, - std::vector &records) { - DCHECK(records.empty()); + std::vector* records) { + DCHECK(records); + DCHECK(records->empty()); - for (const extensions::api::brave_sync::SyncRecord &ext_record : ext_records) { + for (const auto &ext_record : ext_records) { brave_sync::SyncRecordPtr record = FromExtSyncRecord(ext_record); - records.emplace_back(std::move(record)); + records->emplace_back(std::move(record)); } } void ConvertResolvedPairs( const SyncRecordAndExistingList& records_and_existing_objects, - std::vector& - records_and_existing_objects_ext) { - - DCHECK(records_and_existing_objects_ext.empty()); + std::vector* records_and_existing_objects_ext) { + DCHECK(records_and_existing_objects_ext); + DCHECK(records_and_existing_objects_ext->empty()); for (const SyncRecordAndExistingPtr &src : records_and_existing_objects) { DCHECK(src->first.get() != nullptr); @@ -315,20 +322,21 @@ void ConvertResolvedPairs( dest->local_record = FromLibSyncRecord(src->second); } - records_and_existing_objects_ext.emplace_back(std::move(*dest)); + records_and_existing_objects_ext->emplace_back(std::move(*dest)); } } void ConvertSyncRecordsFromLibToExt( const std::vector& records, - std::vector& records_extension) { - DCHECK(records_extension.empty()); + std::vector* records_extension) { + DCHECK(records_extension); + DCHECK(records_extension->empty()); for (const brave_sync::SyncRecordPtr &src : records) { - std::unique_ptr dest = + std::unique_ptr dest = FromLibSyncRecord(src); - records_extension.emplace_back(std::move(*dest)); + records_extension->emplace_back(std::move(*dest)); } } -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/client/client_ext_impl_data.h b/components/brave_sync/client/client_ext_impl_data.h index 20965c7d1e2f..f8a02aeabea7 100644 --- a/components/brave_sync/client/client_ext_impl_data.h +++ b/components/brave_sync/client/client_ext_impl_data.h @@ -1,9 +1,10 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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_CLIENT_CLIENT_EXT_IMPL_DATA_H -#define BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_CLIENT_EXT_IMPL_DATA_H +#ifndef BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_CLIENT_EXT_IMPL_DATA_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_CLIENT_EXT_IMPL_DATA_H_ #include #include @@ -13,33 +14,38 @@ namespace extensions { namespace api { namespace brave_sync { - struct Config; - struct SyncRecord; - struct RecordAndExistingObject; +struct Config; +struct SyncRecord; +struct RecordAndExistingObject; } } } namespace brave_sync { namespace client_data { - class Config; +class Config; } } namespace brave_sync { +using extensions::api::brave_sync::SyncRecord; +using extensions::api::brave_sync::RecordAndExistingObject; + void ConvertConfig(const brave_sync::client_data::Config &config, - extensions::api::brave_sync::Config &config_extension); + extensions::api::brave_sync::Config* config_extension); -void ConvertSyncRecords(const std::vector &records_extension, - std::vector &records); +void ConvertSyncRecords(const std::vector &records_extension, + std::vector* records); -void ConvertResolvedPairs(const SyncRecordAndExistingList &records_and_existing_objects, - std::vector &records_and_existing_objects_ext); +void ConvertResolvedPairs( + const SyncRecordAndExistingList &records_and_existing_objects, + std::vector* records_and_existing_objects_ext); -void ConvertSyncRecordsFromLibToExt(const std::vector &records, - std::vector &records_extension); +void ConvertSyncRecordsFromLibToExt( + const std::vector &records, + std::vector* records_extension); -} // namespace brave_sync +} // namespace brave_sync -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_CLIENT_EXT_IMPL_DATA_H +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_CLIENT_EXT_IMPL_DATA_H_ diff --git a/components/brave_sync/jslib_messages.cc b/components/brave_sync/jslib_messages.cc index 8f99471e5b3b..89dca7e14b0b 100644 --- a/components/brave_sync/jslib_messages.cc +++ b/components/brave_sync/jslib_messages.cc @@ -1,7 +1,12 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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/jslib_messages.h" + +#include + #include "brave/components/brave_sync/values_conv.h" #include "base/logging.h" #include "base/values.h" @@ -54,7 +59,7 @@ Bookmark::Bookmark(const Bookmark& bookmark) { Bookmark::~Bookmark() = default; std::unique_ptr Bookmark::Clone(const Bookmark& bookmark) { - return std::make_unique(bookmark); + return std::make_unique(bookmark); } SiteSetting::SiteSetting() : zoomLevel(1.0f), shieldsUp(true), @@ -66,21 +71,22 @@ SiteSetting::SiteSetting() : zoomLevel(1.0f), shieldsUp(true), SiteSetting::~SiteSetting() = default; -std::unique_ptr SiteSetting::Clone(const SiteSetting& site_setting) { - auto ret_val = std::make_unique(); - ret_val->hostPattern = site_setting.hostPattern; - ret_val->zoomLevel = site_setting.zoomLevel; - ret_val->shieldsUp = site_setting.shieldsUp; - ret_val->adControl = site_setting.adControl; - ret_val->cookieControl = site_setting.cookieControl; - ret_val->safeBrowsing = site_setting.safeBrowsing; - ret_val->noScript = site_setting.noScript; - ret_val->httpsEverywhere = site_setting.httpsEverywhere; - ret_val->fingerprintingProtection = site_setting.fingerprintingProtection; - ret_val->ledgerPayments = site_setting.ledgerPayments; - ret_val->ledgerPaymentsShown = site_setting.ledgerPaymentsShown; - ret_val->fields = site_setting.fields; - return ret_val; +std::unique_ptr SiteSetting::Clone( + const SiteSetting& site_setting) { + auto ret_val = std::make_unique(); + ret_val->hostPattern = site_setting.hostPattern; + ret_val->zoomLevel = site_setting.zoomLevel; + ret_val->shieldsUp = site_setting.shieldsUp; + ret_val->adControl = site_setting.adControl; + ret_val->cookieControl = site_setting.cookieControl; + ret_val->safeBrowsing = site_setting.safeBrowsing; + ret_val->noScript = site_setting.noScript; + ret_val->httpsEverywhere = site_setting.httpsEverywhere; + ret_val->fingerprintingProtection = site_setting.fingerprintingProtection; + ret_val->ledgerPayments = site_setting.ledgerPayments; + ret_val->ledgerPaymentsShown = site_setting.ledgerPaymentsShown; + ret_val->fields = site_setting.fields; + return ret_val; } Device::Device() = default; @@ -88,9 +94,9 @@ Device::Device() = default; Device::~Device() = default; std::unique_ptr Device::Clone(const Device& device) { - auto ret_val = std::make_unique(); - ret_val->name = device.name; - return ret_val; + auto ret_val = std::make_unique(); + ret_val->name = device.name; + return ret_val; } SyncRecord::SyncRecord() : action(SyncRecord::Action::A_INVALID) {} @@ -98,25 +104,25 @@ SyncRecord::SyncRecord() : action(SyncRecord::Action::A_INVALID) {} SyncRecord::~SyncRecord() = default; std::unique_ptr SyncRecord::Clone(const SyncRecord& record) { - auto ret_val = std::make_unique(); + auto ret_val = std::make_unique(); - ret_val->action = record.action; - ret_val->deviceId = record.deviceId; - ret_val->objectId = record.objectId; - ret_val->objectData = record.objectData; - if (record.has_bookmark()) { - ret_val->SetBookmark(Bookmark::Clone(record.GetBookmark())); - } else if (record.has_historysite()) { - ret_val->SetHistorySite(Site::Clone(record.GetHistorySite())); - } else if (record.has_sitesetting()) { - ret_val->SetSiteSetting(SiteSetting::Clone(record.GetSiteSetting())); - } else if (record.has_device()) { - ret_val->SetDevice(Device::Clone(record.GetDevice())); - } + ret_val->action = record.action; + ret_val->deviceId = record.deviceId; + ret_val->objectId = record.objectId; + ret_val->objectData = record.objectData; + if (record.has_bookmark()) { + ret_val->SetBookmark(Bookmark::Clone(record.GetBookmark())); + } else if (record.has_historysite()) { + ret_val->SetHistorySite(Site::Clone(record.GetHistorySite())); + } else if (record.has_sitesetting()) { + ret_val->SetSiteSetting(SiteSetting::Clone(record.GetSiteSetting())); + } else if (record.has_device()) { + ret_val->SetDevice(Device::Clone(record.GetDevice())); + } - ret_val->syncTimestamp = record.syncTimestamp; + ret_val->syncTimestamp = record.syncTimestamp; - return ret_val; + return ret_val; } bool SyncRecord::has_bookmark() const { @@ -161,25 +167,29 @@ Bookmark* SyncRecord::mutable_bookmark() { } void SyncRecord::SetBookmark(std::unique_ptr bookmark) { - DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && !has_device()); + DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && + !has_device()); bookmark_ = std::move(bookmark); } void SyncRecord::SetHistorySite(std::unique_ptr history_site) { - DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && !has_device()); + DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && + !has_device()); history_site_ = std::move(history_site); } void SyncRecord::SetSiteSetting(std::unique_ptr site_setting) { - DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && !has_device()); + DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && + !has_device()); site_setting_ = std::move(site_setting); } void SyncRecord::SetDevice(std::unique_ptr device) { - DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && !has_device()); + DCHECK(!has_bookmark() && !has_historysite() && !has_sitesetting() && + !has_device()); device_ = std::move(device); } -} // jslib +} // namespace jslib -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/jslib_messages.h b/components/brave_sync/jslib_messages.h index 9b2d6fda0075..f5f1432fcb60 100644 --- a/components/brave_sync/jslib_messages.h +++ b/components/brave_sync/jslib_messages.h @@ -1,14 +1,16 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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 H_BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_JSLIB_MESSAGES_H -#define H_BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_JSLIB_MESSAGES_H + +#ifndef BRAVE_COMPONENTS_BRAVE_SYNC_JSLIB_MESSAGES_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_JSLIB_MESSAGES_H_ #include #include #include -#include +#include "base/time/time.h" namespace brave_sync { @@ -16,14 +18,17 @@ namespace jslib { // Simple C++ structures to work with messages from sync lib // Since it is not possible to use sync lib C++ protobuf generated by reasons: -// 1) Chromium everywhere uses `syntax = "proto2";`, sync-lib - `syntax = "proto3";` -// 2) forcing to use version 3 makes to have a deps "//third_party/protobuf:protobuf_full" : +// 1) Chromium everywhere uses `syntax = "proto2";`, +// sync-lib - `syntax = "proto3";` +// 2) forcing to use version 3 makes to have a deps +// "//third_party/protobuf:protobuf_full" : // marked `Do not use in Chrome code.` in src/third_party/protobuf/BUILD.gn -// 3) even with a depth of a deps "//third_party/protobuf:protobuf_full" there are questions -// how to convert json -> protobuf class, not all of fields were converted +// 3) even with a depth of a deps "//third_party/protobuf:protobuf_full" +// there are questions how to convert json -> protobuf class, +// not all of fields were converted class Site { -public: + public: Site(); Site(const Site& site); ~Site(); @@ -38,7 +43,7 @@ class Site { }; class MetaInfo { -public: + public: MetaInfo(); MetaInfo(const MetaInfo& metaInfo); ~MetaInfo(); @@ -49,7 +54,7 @@ class MetaInfo { }; class Bookmark { -public: + public: Bookmark(); Bookmark(const Bookmark& bookmark); ~Bookmark(); @@ -57,7 +62,7 @@ class Bookmark { Site site; bool isFolder; - std::string parentFolderObjectId; // bytes + std::string parentFolderObjectId; // bytes std::vector fields; bool hideInToolbar; std::string order; @@ -65,7 +70,7 @@ class Bookmark { }; class SiteSetting { -public: + public: SiteSetting(); ~SiteSetting(); static std::unique_ptr Clone(const SiteSetting& site_setting); @@ -101,7 +106,7 @@ class SiteSetting { }; class Device { -public: + public: Device(); ~Device(); static std::unique_ptr Clone(const Device& device); @@ -110,7 +115,7 @@ class Device { class SyncRecord { -public: + public: SyncRecord(); ~SyncRecord(); @@ -126,8 +131,8 @@ class SyncRecord { }; Action action; - std::string deviceId; // bytes - std::string objectId; // bytes + std::string deviceId; // bytes + std::string objectId; // bytes std::string objectData; @@ -147,15 +152,16 @@ class SyncRecord { void SetDevice(std::unique_ptr device); base::Time syncTimestamp; -private: + + private: std::unique_ptr bookmark_; std::unique_ptr history_site_; std::unique_ptr site_setting_; std::unique_ptr device_; }; -} // namespace jslib +} // namespace jslib -} // namespace brave_sync +} // namespace brave_sync -#endif // H_BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_JSLIB_MESSAGES_H +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_JSLIB_MESSAGES_H_ diff --git a/components/brave_sync/jslib_messages_fwd.h b/components/brave_sync/jslib_messages_fwd.h index b749439be9a5..6bd18820f48c 100644 --- a/components/brave_sync/jslib_messages_fwd.h +++ b/components/brave_sync/jslib_messages_fwd.h @@ -1,10 +1,15 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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_JSLIB_MESSAGES_FWD_H_ #define BRAVE_COMPONENTS_BRAVE_SYNC_JSLIB_MESSAGES_FWD_H_ +#include +#include +#include + #include "base/callback.h" #include "base/synchronization/waitable_event.h" #include "build/build_config.h" diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index 0936f0d584ee..b19965028bd9 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -50,7 +50,7 @@ uint64_t GetIndexByOrder(const std::string& record_order) { std::string last_digit = record_order.substr(last_dot_index + 1); bool result = base::StringToUint64(last_digit, &index); --index; - DCHECK(index >= 0); + DCHECK_GE(index, 0u); DCHECK(result); return index; } diff --git a/components/brave_sync/syncer_helper_unittest.cc b/components/brave_sync/syncer_helper_unittest.cc index 9ab0ab733896..ccf0ea6aad77 100644 --- a/components/brave_sync/syncer_helper_unittest.cc +++ b/components/brave_sync/syncer_helper_unittest.cc @@ -59,7 +59,6 @@ class SyncerHelperTest : public testing::Test { model_->SetNodeMetaInfo(model_->bookmark_bar_node(), "order", "1.0.1"); model_->SetNodeMetaInfo(model_->other_node(), "order", "1.0.2"); - } void TearDown() override { @@ -187,7 +186,7 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeChildrenReordered) { order_a.clear(); order_b.clear(); order_c.clear(); - + node_a->GetMetaInfo("order", &order_a); EXPECT_EQ(order_a, "1.0.1.2"); node_b->GetMetaInfo("order", &order_b); diff --git a/components/brave_sync/test_util.cc b/components/brave_sync/test_util.cc index 7879ba204ee0..b9bb4dea356d 100644 --- a/components/brave_sync/test_util.cc +++ b/components/brave_sync/test_util.cc @@ -1,9 +1,12 @@ -/* 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/. */ +/* 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/test_util.h" +#include + #include "base/files/file_util.h" #include "base/strings/utf_string_conversions.h" #include "brave/components/brave_sync/tools.h" @@ -40,8 +43,9 @@ std::unique_ptr CreateBraveSyncProfile(const base::FilePath& path) { std::unique_ptr BuildFakeBookmarkModelForTests( content::BrowserContext* context) { + using bookmarks::BookmarkModel; + using bookmarks::TestBookmarkClient; // Don't need context, unless we have more than one profile - using namespace bookmarks; std::unique_ptr client(new TestBookmarkClient()); std::unique_ptr model( TestBookmarkClient::CreateModelWithClient(std::move(client))); @@ -138,4 +142,4 @@ SyncRecordPtr SimpleDeviceRecord( return record; } -} // namespace +} // namespace brave_sync diff --git a/components/brave_sync/test_util.h b/components/brave_sync/test_util.h index 3698be4b1c2b..79382398c174 100644 --- a/components/brave_sync/test_util.h +++ b/components/brave_sync/test_util.h @@ -1,11 +1,14 @@ -/* 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/. */ +/* 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_TEST_UTIL_H_ #define BRAVE_COMPONENTS_BRAVE_SYNC_TEST_UTIL_H_ #include +#include +#include #include "base/files/file_path.h" #include "brave/components/brave_sync/client/brave_sync_client.h" @@ -42,7 +45,7 @@ class MockBraveSyncClient : public BraveSyncClient { MOCK_METHOD0(SendFetchSyncDevices, void()); MOCK_METHOD2(SendResolveSyncRecords, void(const std::string& category_name, std::unique_ptr list)); - MOCK_METHOD2(SendSyncRecords, void (const std::string& category_name, + MOCK_METHOD2(SendSyncRecords, void(const std::string& category_name, const RecordsList& records)); MOCK_METHOD0(SendDeleteSyncUser, void()); MOCK_METHOD1(SendDeleteSyncCategory, void(const std::string& category_name)); From a52425113cfb16180a95440c3bb91365e191e6fa Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 29 May 2019 10:34:59 -0700 Subject: [PATCH 28/73] Move BraveSyncClient to BraveProfileSyncService --- browser/extensions/api/brave_sync_api.cc | 32 ++++++++++--------- .../chrome/browser/sync/chrome_sync_client.cc | 15 --------- .../components/sync/driver/sync_client.cc | 16 ---------- .../components/sync/driver/sync_client.h | 15 --------- .../brave_sync/brave_profile_sync_service.cc | 28 ++++++++-------- .../brave_sync/brave_profile_sync_service.h | 6 ++-- .../brave_sync/brave_sync_service_unittest.cc | 2 -- .../brave_sync/client/brave_sync_client.h | 4 +-- .../client/brave_sync_client_impl.cc | 16 ++++------ .../client/brave_sync_client_impl.h | 3 +- components/brave_sync/test_util.h | 1 - ...e-browser-sync-chrome_sync_client.cc.patch | 14 -------- ...me-browser-sync-chrome_sync_client.h.patch | 21 ------------ ...sync-profile_sync_service_factory.cc.patch | 4 +-- ...components-sync-driver-sync_client.h.patch | 13 -------- 15 files changed, 47 insertions(+), 143 deletions(-) delete mode 100644 chromium_src/chrome/browser/sync/chrome_sync_client.cc delete mode 100644 chromium_src/components/sync/driver/sync_client.cc delete mode 100644 chromium_src/components/sync/driver/sync_client.h delete mode 100644 patches/chrome-browser-sync-chrome_sync_client.cc.patch delete mode 100644 patches/chrome-browser-sync-chrome_sync_client.h.patch delete mode 100644 patches/components-sync-driver-sync_client.h.patch diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index 1fa14497f85b..45e623c66f1c 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -41,7 +41,8 @@ ExtensionFunction::ResponseAction BraveSyncGetInitDataFunction::Run() { BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnGetInitData(params->sync_version); + sync_service->GetBraveSyncClient()->sync_message_handler()->OnGetInitData( + params->sync_version); return RespondNow(NoArguments()); } @@ -54,7 +55,7 @@ ExtensionFunction::ResponseAction BraveSyncSyncSetupErrorFunction::Run() { BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnSyncSetupError( + sync_service->GetBraveSyncClient()->sync_message_handler()->OnSyncSetupError( params->error); return RespondNow(NoArguments()); @@ -68,7 +69,7 @@ ExtensionFunction::ResponseAction BraveSyncSyncDebugFunction::Run() { BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnSyncDebug( + sync_service->GetBraveSyncClient()->sync_message_handler()->OnSyncDebug( params->message); return RespondNow(NoArguments()); @@ -82,7 +83,7 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnSaveInitData( + sync_service->GetBraveSyncClient()->sync_message_handler()->OnSaveInitData( params->seed ? *params->seed : std::vector(), params->device_id ? *params->device_id : std::vector()); @@ -109,11 +110,12 @@ ExtensionFunction::ResponseAction BraveSyncGetExistingObjectsFunction::Run() { BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnGetExistingObjects( - params->category_name, - std::move(records), - base::Time::FromJsTime(params->last_record_timestamp), - params->is_truncated); + sync_service->GetBraveSyncClient()->sync_message_handler() + ->OnGetExistingObjects( + params->category_name, + std::move(records), + base::Time::FromJsTime(params->last_record_timestamp), + params->is_truncated); return RespondNow(NoArguments()); } @@ -129,9 +131,8 @@ ExtensionFunction::ResponseAction BraveSyncResolvedSyncRecordsFunction::Run() { BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnResolvedSyncRecords( - params->category_name, - std::move(records)); + sync_service->GetBraveSyncClient()->sync_message_handler() + ->OnResolvedSyncRecords(params->category_name, std::move(records)); return RespondNow(NoArguments()); } @@ -145,8 +146,8 @@ BraveSyncSaveBookmarksBaseOrderFunction::Run() { BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnSaveBookmarksBaseOrder( - params->order); + sync_service->GetBraveSyncClient()->sync_message_handler() + ->OnSaveBookmarksBaseOrder(params->order); return RespondNow(NoArguments()); } @@ -159,7 +160,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() { BraveProfileSyncService* sync_service = GetProfileSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnSyncWordsPrepared(params->words); + sync_service->GetBraveSyncClient()->sync_message_handler() + ->OnSyncWordsPrepared(params->words); return RespondNow(NoArguments()); } diff --git a/chromium_src/chrome/browser/sync/chrome_sync_client.cc b/chromium_src/chrome/browser/sync/chrome_sync_client.cc deleted file mode 100644 index 0bef1a6efe8f..000000000000 --- a/chromium_src/chrome/browser/sync/chrome_sync_client.cc +++ /dev/null @@ -1,15 +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/client/brave_sync_client_impl.h" -#include "../../../../../chrome/browser/sync/chrome_sync_client.cc" // NOLINT - -namespace browser_sync { - -brave_sync::BraveSyncClient* ChromeSyncClient::GetBraveSyncClient() { - return brave_sync_client_.get(); -} - -} // namespace browser_sync diff --git a/chromium_src/components/sync/driver/sync_client.cc b/chromium_src/components/sync/driver/sync_client.cc deleted file mode 100644 index 3d3c20659d76..000000000000 --- a/chromium_src/components/sync/driver/sync_client.cc +++ /dev/null @@ -1,16 +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/sync_client.cc" // NOLINT - -#include "brave/chromium_src/components/sync/driver/sync_client.h" - -namespace syncer { - -brave_sync::BraveSyncClient* SyncClient::GetBraveSyncClient() { - return nullptr; -} - -} diff --git a/chromium_src/components/sync/driver/sync_client.h b/chromium_src/components/sync/driver/sync_client.h deleted file mode 100644 index eb27db60efc9..000000000000 --- a/chromium_src/components/sync/driver/sync_client.h +++ /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/. */ - -#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_SYNC_CLIENT_H_ -#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_SYNC_CLIENT_H_ - -namespace brave_sync { -class BraveSyncClient; -} // namespace brave_sync - -#include "../../../../../components/sync/driver/sync_client.h" - -#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_SYNC_CLIENT_H_ diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 28f2dc435e2b..95aee15b0962 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -13,6 +13,7 @@ #include "brave/components/brave_sync/values_conv.h" #include "brave/components/brave_sync/brave_sync_prefs.h" #include "brave/components/brave_sync/brave_sync_service_observer.h" +#include "brave/components/brave_sync/client/brave_sync_client_impl.h" #include "brave/components/brave_sync/jslib_const.h" #include "brave/components/brave_sync/jslib_messages.h" #include "brave/components/brave_sync/settings.h" @@ -177,13 +178,14 @@ void CreateResolveList( } // namespace -BraveProfileSyncService::BraveProfileSyncService(InitParams init_params) - : syncer::ProfileSyncService(std::move(init_params)) { +BraveProfileSyncService::BraveProfileSyncService(Profile* profile, + InitParams init_params) : + syncer::ProfileSyncService(std::move(init_params)), + brave_sync_client_(BraveSyncClient::Create(this, profile)) { brave_sync_words_ = std::string(); brave_sync_prefs_ = std::make_unique( ProfileSyncService::GetSyncClient()->GetPrefService()); - GetBraveSyncClient()->set_sync_message_handler(this); // Moniter syncs prefs required in GetSettingsAndDevices brave_pref_change_registrar_.Init( @@ -229,7 +231,7 @@ void BraveProfileSyncService::OnNudgeSyncCycle( record->deviceId = brave_sync_prefs_->GetThisDeviceId(); } if (!records->empty()) - GetBraveSyncClient()->SendSyncRecords( + brave_sync_client_->SendSyncRecords( jslib_const::SyncRecordType_BOOKMARKS, *records); } @@ -332,7 +334,7 @@ void BraveProfileSyncService::GetSyncWords() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); // Ask sync client std::string seed = brave_sync_prefs_->GetSeed(); - GetBraveSyncClient()->NeedSyncWords(seed); + brave_sync_client_->NeedSyncWords(seed); } std::string BraveProfileSyncService::GetSeed() { @@ -417,7 +419,7 @@ void BraveProfileSyncService::OnGetInitData(const std::string& sync_version) { config.api_version = brave_sync_prefs_->GetApiVersion(); config.server_url = "https://sync.brave.com"; config.debug = true; - GetBraveSyncClient()->SendGotInitData(seed, device_id, config, + brave_sync_client_->SendGotInitData(seed, device_id, config, brave_sync_words_); } @@ -466,7 +468,7 @@ void BraveProfileSyncService::OnSyncReady() { brave_sync_prefs_->GetBookmarksBaseOrder(); if (bookmarks_base_order.empty()) { std::string platform = tools::GetPlatformName(); - GetBraveSyncClient()->SendGetBookmarksBaseOrder( + brave_sync_client_->SendGetBookmarksBaseOrder( brave_sync_prefs_->GetThisDeviceId(), platform); // OnSyncReady will be called by OnSaveBookmarksBaseOrder @@ -519,7 +521,7 @@ void BraveProfileSyncService::OnGetExistingObjects( *records.get(), records_and_existing_objects.get(), model_, brave_sync_prefs_.get()); - GetBraveSyncClient()->SendResolveSyncRecords( + brave_sync_client_->SendResolveSyncRecords( category_name, std::move(records_and_existing_objects)); } } @@ -659,7 +661,7 @@ void BraveProfileSyncService::FetchSyncRecords(const bool bookmarks, brave_sync_prefs_->SetLastFetchTime(base::Time::Now()); base::Time start_at_time = brave_sync_prefs_->GetLatestRecordTime(); - GetBraveSyncClient()->SendFetchSyncRecords( + brave_sync_client_->SendFetchSyncRecords( category_names, start_at_time, max_records); @@ -691,7 +693,7 @@ void BraveProfileSyncService::SendDeviceSyncRecord( object_id, static_cast(action), device_id); - GetBraveSyncClient()->SendSyncRecords( + brave_sync_client_->SendSyncRecords( SyncRecordType_PREFERENCES, *records); } @@ -744,7 +746,7 @@ void BraveProfileSyncService::OnResolvedPreferences( void BraveProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { if (pref == prefs::kSyncEnabled) { - GetBraveSyncClient()->OnSyncEnabledChanged(); + brave_sync_client_->OnSyncEnabledChanged(); if (!brave_sync_prefs_->GetSyncEnabled()) { brave_sync_initialized_ = false; ProfileSyncService::GetUserSettings()->SetSyncRequested(false); @@ -755,7 +757,7 @@ void BraveProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { BraveSyncClient* BraveProfileSyncService::GetBraveSyncClient() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - return ProfileSyncService::GetSyncClient()->GetBraveSyncClient(); + return brave_sync_client_.get(); } bool BraveProfileSyncService::IsBraveSyncEnabled() const { @@ -774,7 +776,7 @@ void BraveProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent) { if (IsTimeEmpty(brave_sync_prefs_->GetLastFetchTime())) SendCreateDevice(); - GetBraveSyncClient()->SendFetchSyncDevices(); + brave_sync_client_->SendFetchSyncDevices(); if (!brave_sync_initialized_) { wevent->Signal(); diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 3d9c3a0a975f..40b1fb0891cf 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -43,7 +43,7 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, public BraveSyncService, public SyncMessageHandler { public: - explicit BraveProfileSyncService(InitParams init_params); + explicit BraveProfileSyncService(Profile* profile, InitParams init_params); ~BraveProfileSyncService() override; @@ -92,7 +92,7 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, // once (before this object is destroyed). void Shutdown() override; - brave_sync::BraveSyncClient* GetBraveSyncClient() override; + BraveSyncClient* GetBraveSyncClient() override; bool IsBraveSyncEnabled() const override; bool IsBraveSyncInitialized() const; @@ -163,6 +163,8 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, bookmarks::BookmarkModel* model_ = nullptr; + std::unique_ptr brave_sync_client_; + // Used to ensure that certain operations are performed on the sequence that // this object was created on. SEQUENCE_CHECKER(sequence_checker_); diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index fcdeadb0d847..54eff40178be 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -165,8 +165,6 @@ class BraveSyncServiceTest : public testing::Test { sync_client_ = new MockBraveSyncClient(); brave_sync::BraveSyncClientImpl::set_for_testing(sync_client_); - EXPECT_CALL(*sync_client(), set_sync_message_handler(_)); - sync_service_ = ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( profile()); diff --git a/components/brave_sync/client/brave_sync_client.h b/components/brave_sync/client/brave_sync_client.h index dd9b0e50f05a..51d92092b9c5 100644 --- a/components/brave_sync/client/brave_sync_client.h +++ b/components/brave_sync/client/brave_sync_client.h @@ -56,12 +56,12 @@ class SyncMessageHandler { class BraveSyncClient { public: - static BraveSyncClient* Create(Profile* profile); + static BraveSyncClient* Create(SyncMessageHandler* handler, + Profile* profile); virtual ~BraveSyncClient() = default; // BraveSync to Browser messages virtual SyncMessageHandler* sync_message_handler() = 0; - virtual void set_sync_message_handler(SyncMessageHandler*) = 0; virtual void SendGotInitData(const Uint8Array& seed, const Uint8Array& device_id, diff --git a/components/brave_sync/client/brave_sync_client_impl.cc b/components/brave_sync/client/brave_sync_client_impl.cc index fda2f73b0e70..1be22363b76f 100644 --- a/components/brave_sync/client/brave_sync_client_impl.cc +++ b/components/brave_sync/client/brave_sync_client_impl.cc @@ -34,15 +34,17 @@ void BraveSyncClientImpl::set_for_testing(BraveSyncClient* sync_client) { } // static -BraveSyncClient* BraveSyncClient::Create(Profile* profile) { +BraveSyncClient* BraveSyncClient::Create(SyncMessageHandler* handler, + Profile* profile) { if (brave_sync_client_for_testing_) return brave_sync_client_for_testing_; - return new BraveSyncClientImpl(profile); + return new BraveSyncClientImpl(handler, profile); } -BraveSyncClientImpl::BraveSyncClientImpl(Profile* profile) : - handler_(nullptr), +BraveSyncClientImpl::BraveSyncClientImpl(SyncMessageHandler* handler, + Profile* profile) : + handler_(handler), profile_(profile), sync_prefs_(new brave_sync::prefs::Prefs(profile->GetPrefs())), extension_loaded_(false), @@ -60,12 +62,6 @@ SyncMessageHandler* BraveSyncClientImpl::sync_message_handler() { return handler_; } -void BraveSyncClientImpl::set_sync_message_handler( - SyncMessageHandler* handler) { - DCHECK(handler); - handler_ = handler; -} - void BraveSyncClientImpl::SendGotInitData(const Uint8Array& seed, const Uint8Array& device_id, const client_data::Config& config, diff --git a/components/brave_sync/client/brave_sync_client_impl.h b/components/brave_sync/client/brave_sync_client_impl.h index 9c47a0407da9..ea6c376046d5 100644 --- a/components/brave_sync/client/brave_sync_client_impl.h +++ b/components/brave_sync/client/brave_sync_client_impl.h @@ -43,7 +43,6 @@ class BraveSyncClientImpl : public BraveSyncClient, // BraveSync to Browser messages SyncMessageHandler* sync_message_handler() override; - void set_sync_message_handler(SyncMessageHandler* handler) override; // Browser to BraveSync messages void SendGotInitData(const Uint8Array& seed, const Uint8Array& device_id, @@ -68,7 +67,7 @@ class BraveSyncClientImpl : public BraveSyncClient, friend class ::BraveSyncServiceTest; static void set_for_testing(BraveSyncClient* sync_client); - explicit BraveSyncClientImpl(Profile* profile); + explicit BraveSyncClientImpl(SyncMessageHandler* handler, Profile* profile); void OnExtensionInitialized() override; void OnSyncEnabledChanged() override; diff --git a/components/brave_sync/test_util.h b/components/brave_sync/test_util.h index 79382398c174..afc756a5d79e 100644 --- a/components/brave_sync/test_util.h +++ b/components/brave_sync/test_util.h @@ -35,7 +35,6 @@ class MockBraveSyncClient : public BraveSyncClient { ~MockBraveSyncClient() override; MOCK_METHOD0(sync_message_handler, SyncMessageHandler*()); - MOCK_METHOD1(set_sync_message_handler, void(SyncMessageHandler*)); MOCK_METHOD4(SendGotInitData, void(const Uint8Array& seed, const Uint8Array& device_id, const client_data::Config& config, const std::string& sync_words)); diff --git a/patches/chrome-browser-sync-chrome_sync_client.cc.patch b/patches/chrome-browser-sync-chrome_sync_client.cc.patch deleted file mode 100644 index bc1b9f467d7f..000000000000 --- a/patches/chrome-browser-sync-chrome_sync_client.cc.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/chrome/browser/sync/chrome_sync_client.cc b/chrome/browser/sync/chrome_sync_client.cc -index ffb7c9f0a5fb78d160fbcfdba6cd3e3b8ed10179..0afc072de8a2f8f874baa66374078df5fcb62b3f 100644 ---- a/chrome/browser/sync/chrome_sync_client.cc -+++ b/chrome/browser/sync/chrome_sync_client.cc -@@ -165,7 +165,8 @@ syncer::ModelTypeSet GetDisabledTypesFromCommandLine() { - - } // namespace - --ChromeSyncClient::ChromeSyncClient(Profile* profile) : profile_(profile) { -+ChromeSyncClient::ChromeSyncClient(Profile* profile) : profile_(profile), -+ brave_sync_client_(brave_sync::BraveSyncClient::Create(profile)) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - profile_web_data_service_ = diff --git a/patches/chrome-browser-sync-chrome_sync_client.h.patch b/patches/chrome-browser-sync-chrome_sync_client.h.patch deleted file mode 100644 index fcb9fd8961c2..000000000000 --- a/patches/chrome-browser-sync-chrome_sync_client.h.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/chrome/browser/sync/chrome_sync_client.h b/chrome/browser/sync/chrome_sync_client.h -index f52eb2c251db195a2b4ba8b5a85ea5b05102f686..2dc398a6be0cbb3c148cb34cdf811ed1fea48934 100644 ---- a/chrome/browser/sync/chrome_sync_client.h -+++ b/chrome/browser/sync/chrome_sync_client.h -@@ -63,6 +63,7 @@ class ChromeSyncClient : public browser_sync::BrowserSyncClient { - syncer::ModelSafeGroup group) override; - syncer::SyncApiComponentFactory* GetSyncApiComponentFactory() override; - syncer::SyncTypePreferenceProvider* GetPreferenceProvider() override; -+ brave_sync::BraveSyncClient* GetBraveSyncClient() override; - - private: - Profile* const profile_; -@@ -85,6 +86,8 @@ class ChromeSyncClient : public browser_sync::BrowserSyncClient { - // Generates and monitors the ExtensionsActivity object used by sync. - ExtensionsActivityMonitor extensions_activity_monitor_; - -+ std::unique_ptr brave_sync_client_; -+ - DISALLOW_COPY_AND_ASSIGN(ChromeSyncClient); - }; - diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch index e2dfaf2d7dd8..41ce7d87c20f 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -1,5 +1,5 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc -index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..dcc3be3371db7c3f68dd1353030bbe6d2c1cb451 100644 +index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..8afd2798eb69652dc99213ba69ce8a0a97318a5c 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc @@ -263,7 +263,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( @@ -7,7 +7,7 @@ index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..dcc3be3371db7c3f68dd1353030bbe6d auto pss = - std::make_unique(std::move(init_params)); -+ std::make_unique(std::move(init_params)); ++ std::make_unique(profile, std::move(init_params)); pss->Initialize(); return pss.release(); } diff --git a/patches/components-sync-driver-sync_client.h.patch b/patches/components-sync-driver-sync_client.h.patch deleted file mode 100644 index d419df12a610..000000000000 --- a/patches/components-sync-driver-sync_client.h.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/components/sync/driver/sync_client.h b/components/sync/driver/sync_client.h -index 90db4a23b4241364d6cd464df621531073745be5..4ed7da95a55295a7771b9dd19a052f608e8a1d3a 100644 ---- a/components/sync/driver/sync_client.h -+++ b/components/sync/driver/sync_client.h -@@ -73,6 +73,8 @@ class SyncClient { - // Returns the preference provider, or null if none exists. - virtual SyncTypePreferenceProvider* GetPreferenceProvider() = 0; - -+ virtual brave_sync::BraveSyncClient* GetBraveSyncClient(); -+ - private: - DISALLOW_COPY_AND_ASSIGN(SyncClient); - }; From 1e55ab60903384e872237a2542e574b7844ca967 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 28 May 2019 21:40:24 -0700 Subject: [PATCH 29/73] Android build fix brave_sync deps fix --- browser/extensions/BUILD.gn | 11 ++++++--- browser/ui/BUILD.gn | 21 ++++++++++++---- .../webui/brave_web_ui_controller_factory.cc | 15 ++++++++---- .../sync/profile_sync_service_factory.cc | 4 ++++ .../sync/profile_sync_service_factory.h | 4 ++++ components/brave_sync/BUILD.gn | 24 ++++++++++++------- .../brave_sync/brave_profile_sync_service.cc | 2 ++ .../brave_sync/brave_profile_sync_service.h | 2 ++ patches/chrome-browser-BUILD.gn.patch | 12 ++++++++-- ...sync-profile_sync_service_factory.cc.patch | 9 ++++--- ...-sync-profile_sync_service_factory.h.patch | 6 +++-- patches/components-sync-BUILD.gn.patch | 5 ++-- .../components-sync_bookmarks-BUILD.gn.patch | 12 ++++++++++ 13 files changed, 98 insertions(+), 29 deletions(-) create mode 100644 patches/components-sync_bookmarks-BUILD.gn.patch diff --git a/browser/extensions/BUILD.gn b/browser/extensions/BUILD.gn index 12590efc74ff..fd00c298c175 100644 --- a/browser/extensions/BUILD.gn +++ b/browser/extensions/BUILD.gn @@ -1,5 +1,6 @@ import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni") import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni") +import("//brave/components/brave_sync/buildflags/buildflags.gni") import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//build/config/features.gni") @@ -65,9 +66,6 @@ source_set("extensions") { "//brave/components/brave_component_updater/browser", "//brave/components/brave_extension:static_resources", "//brave/components/brave_extension:generated_resources", - "//brave/components/brave_sync", - "//brave/components/brave_sync:generated_resources", - "//brave/components/brave_sync:static_resources", "//components/prefs", "//components/update_client:patch_impl", "//components/update_client:unzip_impl", @@ -83,6 +81,13 @@ source_set("extensions") { "//brave/components/brave_rewards/resources/extension:static_resources", ] } + if (enable_brave_sync) { + deps += [ + "//brave/components/brave_sync", + "//brave/components/brave_sync:generated_resources", + "//brave/components/brave_sync:static_resources", + ] + } if (enable_brave_webtorrent) { deps += [ "//brave/components/brave_webtorrent:generated_resources", diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 28559b056fc7..bbf5e5f43931 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -3,6 +3,7 @@ import("//build/config/features.gni") import("//brave/browser/translate/buildflags/buildflags.gni") import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni") import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni") +import("//brave/components/brave_sync/buildflags/buildflags.gni") import("//chrome/common/features.gni") source_set("ui") { @@ -19,10 +20,15 @@ source_set("ui") { "webui/brave_web_ui_controller_factory.h", "webui/brave_webui_source.cc", "webui/brave_webui_source.h", - "webui/sync/sync_ui.cc", - "webui/sync/sync_ui.h", ] + if (enable_brave_sync) { + sources += [ + "webui/sync/sync_ui.cc", + "webui/sync/sync_ui.h", + ] + } + if (!is_android) { sources += [ "brave_browser_command_controller.cc", @@ -139,9 +145,6 @@ source_set("ui") { "//brave/components/brave_rewards/browser", "//brave/components/brave_rewards/resources", "//brave/components/brave_shields/browser", - "//brave/components/brave_sync", - "//brave/components/brave_sync:static_resources", - "//brave/components/brave_sync:generated_resources", "//brave/components/brave_welcome_ui:generated_resources", "//brave/browser:sparkle_buildflags", "//brave/browser/devtools", @@ -159,6 +162,14 @@ source_set("ui") { "//ui/gfx", ] + if (enable_brave_sync) { + deps += [ + "//brave/components/brave_sync", + "//brave/components/brave_sync:static_resources", + "//brave/components/brave_sync:generated_resources", + ] + } + if (!is_android) { deps += [ "//brave/app:brave_generated_resources_grit", diff --git a/browser/ui/webui/brave_web_ui_controller_factory.cc b/browser/ui/webui/brave_web_ui_controller_factory.cc index 092780e58dc5..3123b7ca2129 100644 --- a/browser/ui/webui/brave_web_ui_controller_factory.cc +++ b/browser/ui/webui/brave_web_ui_controller_factory.cc @@ -10,12 +10,12 @@ #include "base/memory/ptr_util.h" #include "brave/browser/ui/webui/brave_adblock_ui.h" #include "brave/browser/ui/webui/brave_new_tab_ui.h" -#include "brave/browser/ui/webui/sync/sync_ui.h" #include "brave/common/webui_url_constants.h" #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" #include "brave/components/brave_wallet/browser/buildflags/buildflags.h" #include "brave/components/brave_sync/brave_sync_service.h" #include "chrome/common/url_constants.h" +#include "extensions/buildflags/buildflags.h" #include "url/gurl.h" #if !defined(OS_ANDROID) @@ -33,6 +33,10 @@ #include "brave/browser/ui/webui/brave_wallet_ui.h" #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "brave/browser/ui/webui/sync/sync_ui.h" +#endif + using content::WebUI; using content::WebUIController; @@ -52,14 +56,17 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { template<> WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { auto host = url.host_piece(); - if (host == kBraveUISyncHost && brave_sync::BraveSyncService::is_enabled()) { - return new SyncUI(web_ui, url.host()); - } else if (host == kAdblockHost) { + if (host == kAdblockHost) { return new BraveAdblockUI(web_ui, url.host()); #if BUILDFLAG(BRAVE_WALLET_ENABLED) } else if (host == kWalletHost) { return new BraveWalletUI(web_ui, url.host()); #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) + } else if (host == kBraveUISyncHost && + brave_sync::BraveSyncService::is_enabled()) { + return new SyncUI(web_ui, url.host()); +#endif #if BUILDFLAG(BRAVE_REWARDS_ENABLED) } else if (host == kRewardsHost) { return new BraveRewardsUI(web_ui, url.host()); diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index fde8c2d3d38c..c93346266bdb 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -5,13 +5,17 @@ #include "brave/chromium_src/chrome/browser/sync/profile_sync_service_factory.h" +#if BUILDFLAG(ENABLE_EXTENSIONS) #include "brave/components/brave_sync/brave_profile_sync_service.h" using brave_sync::BraveProfileSyncService; +#endif #include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" // NOLINT +#if BUILDFLAG(ENABLE_EXTENSIONS) // static BraveProfileSyncService* ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( Profile* profile) { return static_cast(GetForProfile(profile)); } +#endif diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.h b/chromium_src/chrome/browser/sync/profile_sync_service_factory.h index 51d3d6a2e224..f7694faa0831 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.h +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.h @@ -6,9 +6,13 @@ #ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ #define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ +#include "extensions/buildflags/buildflags.h" + +#if BUILDFLAG(ENABLE_EXTENSIONS) namespace brave_sync { class BraveProfileSyncService; } // namespace brave_sync +#endif #include "../../../../../chrome/browser/sync/profile_sync_service_factory.h" #endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ // NOLINT diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index d1374364d461..1152ec0b7a13 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -7,6 +7,8 @@ import("//tools/grit/repack.gni") if (enable_brave_sync) { source_set("js_sync_lib_impl") { sources = [ + "brave_profile_sync_service.cc", + "brave_profile_sync_service.h", "client/brave_sync_client.h", "client/brave_sync_client_impl.cc", "client/brave_sync_client_impl.h", @@ -48,12 +50,23 @@ source_set("jslib_messages") { ] } +source_set("prefs") { + sources = [ + "brave_sync_prefs.cc", + "brave_sync_prefs.h", + ] + + deps = [ + "//components/prefs", + ] +} + source_set("core") { sources = [ "bookmark_order_util.cc", "bookmark_order_util.h", - "brave_sync_prefs.cc", - "brave_sync_prefs.h", + "brave_sync_service.cc", + "brave_sync_service.h", "settings.cc", "settings.h", "sync_devices.cc", @@ -68,8 +81,8 @@ source_set("core") { deps = [ ":jslib_messages", + ":prefs", "//base", - "//components/prefs", "//crypto", "//extensions/buildflags", ] @@ -83,10 +96,6 @@ source_set("core") { source_set("brave_sync") { sources = [ - "brave_sync_service.cc", - "brave_sync_service.h", - "brave_profile_sync_service.cc", - "brave_profile_sync_service.h", "brave_sync_service_observer.h", ] @@ -94,7 +103,6 @@ source_set("brave_sync") { ":core", "buildflags", "//base", - "//components/browser_sync", "//components/bookmarks/browser", "//components/keyed_service/content", "//components/keyed_service/core", diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 95aee15b0962..0217600e4027 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -755,10 +755,12 @@ void BraveProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { NotifySyncStateChanged(); } +#if BUILDFLAG(ENABLE_EXTENSIONS) BraveSyncClient* BraveProfileSyncService::GetBraveSyncClient() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); return brave_sync_client_.get(); } +#endif bool BraveProfileSyncService::IsBraveSyncEnabled() const { return brave_sync_prefs_->GetSyncEnabled(); diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 40b1fb0891cf..2f87959c34ec 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -92,7 +92,9 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, // once (before this object is destroyed). void Shutdown() override; +#if BUILDFLAG(ENABLE_EXTENSIONS) BraveSyncClient* GetBraveSyncClient() override; +#endif bool IsBraveSyncEnabled() const override; bool IsBraveSyncInitialized() const; diff --git a/patches/chrome-browser-BUILD.gn.patch b/patches/chrome-browser-BUILD.gn.patch index ab0a6ad1608f..d356c2aabb47 100644 --- a/patches/chrome-browser-BUILD.gn.patch +++ b/patches/chrome-browser-BUILD.gn.patch @@ -1,8 +1,16 @@ diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn -index 4f9844f6f8546efe591e679c41c7cd3b43c371a8..0e86b115bef94df9821adeffe944b0d3a63b587c 100644 +index 89006c99c02315f0c439dbf244d5ae3ce5cb7a0b..d2d69926e219836a2b09b7e7358be826f95ac553 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn -@@ -2142,6 +2142,7 @@ jumbo_split_static_library("browser") { +@@ -1810,6 +1810,7 @@ jumbo_split_static_library("browser") { + ":resource_prefetch_predictor_proto", + "//base:i18n", + "//base/allocator:buildflags", ++ "//brave/components/brave_sync", + "//cc", + "//chrome:extra_resources", + "//chrome:resources", +@@ -2099,6 +2100,7 @@ jumbo_split_static_library("browser") { "//ui/strings", "//ui/surface", "//ui/web_dialogs", diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch index 41ce7d87c20f..ac6fff444db5 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -1,13 +1,16 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc -index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..8afd2798eb69652dc99213ba69ce8a0a97318a5c 100644 +index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..c8414fb6cf9a829d1f3db822f688d4c5c91d523b 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc -@@ -263,7 +263,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( +@@ -263,7 +263,11 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( } auto pss = -- std::make_unique(std::move(init_params)); ++#if BUILDFLAG(ENABLE_EXTENSIONS) + std::make_unique(profile, std::move(init_params)); ++#else + std::make_unique(std::move(init_params)); ++#endif pss->Initialize(); return pss.release(); } diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.h.patch b/patches/chrome-browser-sync-profile_sync_service_factory.h.patch index e2a5240b2068..fb1a2bc3c7e5 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.h.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.h.patch @@ -1,13 +1,15 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.h b/chrome/browser/sync/profile_sync_service_factory.h -index 2e2f416a055c4bcc67c02b43ccc90ac8c13bc8f0..faaf8531cb8f28e7c46550b47c5d4ed476a9ee93 100644 +index 2e2f416a055c4bcc67c02b43ccc90ac8c13bc8f0..0e400986726357c866b9b93c215451e8f8f2e9b0 100644 --- a/chrome/browser/sync/profile_sync_service_factory.h +++ b/chrome/browser/sync/profile_sync_service_factory.h -@@ -38,6 +38,8 @@ class ProfileSyncServiceFactory : public BrowserContextKeyedServiceFactory { +@@ -38,6 +38,10 @@ class ProfileSyncServiceFactory : public BrowserContextKeyedServiceFactory { // absolutely necessary! Prefer GetForProfile instead. static syncer::ProfileSyncService* GetAsProfileSyncServiceForProfile( Profile* profile); ++#if BUILDFLAG(ENABLE_EXTENSIONS) + static brave_sync::BraveProfileSyncService* + GetAsBraveProfileSyncServiceForProfile(Profile* profile); ++#endif // Returns whether a SyncService has already been created for the profile. // Note that GetForProfile will create the service if it doesn't exist yet. diff --git a/patches/components-sync-BUILD.gn.patch b/patches/components-sync-BUILD.gn.patch index 108ae7deb8c6..bb7d3ccd50c6 100644 --- a/patches/components-sync-BUILD.gn.patch +++ b/patches/components-sync-BUILD.gn.patch @@ -1,12 +1,13 @@ diff --git a/components/sync/BUILD.gn b/components/sync/BUILD.gn -index 0606b7e68670877100114732174af25ad0b42f77..c75b39c7d0c7647b17a047eb732089bf38549956 100644 +index 0606b7e68670877100114732174af25ad0b42f77..22a62cebbd47644c4f189be012134f7c04c92af4 100644 --- a/components/sync/BUILD.gn +++ b/components/sync/BUILD.gn -@@ -99,6 +99,7 @@ jumbo_static_library("base") { +@@ -99,6 +99,8 @@ jumbo_static_library("base") { ] deps = [ "//base:i18n", + "//brave/components/brave_sync:jslib_messages", ++ "//brave/components/brave_sync:prefs", "//components/os_crypt", "//components/pref_registry", "//components/prefs", diff --git a/patches/components-sync_bookmarks-BUILD.gn.patch b/patches/components-sync_bookmarks-BUILD.gn.patch new file mode 100644 index 000000000000..9c00c7ff13f0 --- /dev/null +++ b/patches/components-sync_bookmarks-BUILD.gn.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync_bookmarks/BUILD.gn b/components/sync_bookmarks/BUILD.gn +index 3b36cc46b0b67ecd5cd74a3467f1f19398216977..aeb80257436f05d2f864fe24eb18df26fb6e1a06 100644 +--- a/components/sync_bookmarks/BUILD.gn ++++ b/components/sync_bookmarks/BUILD.gn +@@ -32,6 +32,7 @@ static_library("sync_bookmarks") { + + deps = [ + "//base", ++ "//brave/components/brave_sync:core", + "//components/bookmarks/browser", + "//components/favicon/core", + "//components/history/core/browser", From e2617dcd39008ac8b92adbc3ce4c575c38d1a845 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 29 May 2019 16:38:41 -0700 Subject: [PATCH 30/73] Replace brave_sync::BraveSyncService::is_enabled() with switches::IsBraveSyncAllowedByFlag() --- browser/bookmarks/brave_bookmark_client.cc | 40 ------------------- .../ui/brave_browser_command_controller.cc | 4 +- browser/ui/toolbar/brave_app_menu_model.cc | 4 +- .../webui/brave_web_ui_controller_factory.cc | 9 +++-- .../sync/profile_sync_service_factory.cc | 1 + common/brave_switches.cc | 6 +++ common/brave_switches.h | 4 ++ components/brave_sync/BUILD.gn | 8 ++-- .../brave_sync/brave_profile_sync_service.h | 1 + components/brave_sync/brave_sync_prefs.cc | 4 +- components/brave_sync/brave_sync_service.cc | 9 ----- components/brave_sync/brave_sync_service.h | 5 --- patches/chrome-browser-BUILD.gn.patch | 7 ++-- ...sync-profile_sync_service_factory.cc.patch | 11 ++++- 14 files changed, 40 insertions(+), 73 deletions(-) delete mode 100644 browser/bookmarks/brave_bookmark_client.cc diff --git a/browser/bookmarks/brave_bookmark_client.cc b/browser/bookmarks/brave_bookmark_client.cc deleted file mode 100644 index 4a5e49d88c41..000000000000 --- a/browser/bookmarks/brave_bookmark_client.cc +++ /dev/null @@ -1,40 +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/bookmarks/brave_bookmark_client.h" - -#include "brave/components/brave_sync/buildflags/buildflags.h" -#include "chrome/browser/profiles/profile.h" -#include "components/bookmarks/browser/bookmark_model.h" -#include "components/bookmarks/managed/managed_bookmark_service.h" -#include "components/sync_bookmarks/bookmark_sync_service.h" - -#if BUILDFLAG(ENABLE_BRAVE_SYNC) -#include "brave/components/brave_sync/brave_sync_service.h" -#endif - -BraveBookmarkClient::BraveBookmarkClient( - Profile* profile, - bookmarks::ManagedBookmarkService* managed_bookmark_service, - sync_bookmarks::BookmarkSyncService* bookmark_sync_service) - : ChromeBookmarkClient(profile, - managed_bookmark_service, - bookmark_sync_service) {} - -bookmarks::LoadExtraCallback BraveBookmarkClient::GetLoadExtraNodesCallback() { -#if BUILDFLAG(ENABLE_BRAVE_SYNC) - return base::BindOnce(&brave_sync::LoadExtraNodes, - ChromeBookmarkClient::GetLoadExtraNodesCallback()); -#endif - return ChromeBookmarkClient::GetLoadExtraNodesCallback(); -} - -bool BraveBookmarkClient::IsPermanentNodeVisible( - const bookmarks::BookmarkPermanentNode* node) { -#if BUILDFLAG(ENABLE_BRAVE_SYNC) - if (brave_sync::IsSyncManagedNode(node)) - return false; // don't display sync managed nodes -#endif - return ChromeBookmarkClient::IsPermanentNodeVisible(node); -} diff --git a/browser/ui/brave_browser_command_controller.cc b/browser/ui/brave_browser_command_controller.cc index 55fa4358e13d..4e91385538f8 100644 --- a/browser/ui/brave_browser_command_controller.cc +++ b/browser/ui/brave_browser_command_controller.cc @@ -10,8 +10,8 @@ #include "brave/browser/ui/brave_pages.h" #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" #include "brave/components/brave_wallet/browser/buildflags/buildflags.h" -#include "brave/components/brave_sync/brave_sync_service.h" #include "brave/browser/ui/browser_commands.h" +#include "brave/common/brave_switches.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" @@ -91,7 +91,7 @@ void BraveBrowserCommandController::InitBraveCommandState() { #if BUILDFLAG(BRAVE_WALLET_ENABLED) UpdateCommandForBraveWallet(); #endif - if (brave_sync::BraveSyncService::is_enabled()) + if (switches::IsBraveSyncAllowedByFlag()) UpdateCommandForBraveSync(); } UpdateCommandForBraveAdblock(); diff --git a/browser/ui/toolbar/brave_app_menu_model.cc b/browser/ui/toolbar/brave_app_menu_model.cc index 8821b4004b68..76f6e40fcac9 100644 --- a/browser/ui/toolbar/brave_app_menu_model.cc +++ b/browser/ui/toolbar/brave_app_menu_model.cc @@ -7,7 +7,7 @@ #include "brave/app/brave_command_ids.h" #include "brave/browser/profiles/profile_util.h" -#include "brave/components/brave_sync/brave_sync_service.h" +#include "brave/common/brave_switches.h" #include "brave/grit/brave_generated_resources.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/profiles/profile.h" @@ -43,7 +43,7 @@ void BraveAppMenuModel::InsertBraveMenuItems() { IDC_SHOW_BRAVE_WALLET, IDS_SHOW_BRAVE_WALLET); #endif - if (brave_sync::BraveSyncService::is_enabled()) { + if (switches::IsBraveSyncAllowedByFlag()) { InsertItemWithStringIdAt( #if BUILDFLAG(BRAVE_WALLET_ENABLED) GetIndexOfCommandId(IDC_SHOW_BRAVE_WALLET), diff --git a/browser/ui/webui/brave_web_ui_controller_factory.cc b/browser/ui/webui/brave_web_ui_controller_factory.cc index 3123b7ca2129..b32a65b721d5 100644 --- a/browser/ui/webui/brave_web_ui_controller_factory.cc +++ b/browser/ui/webui/brave_web_ui_controller_factory.cc @@ -10,10 +10,10 @@ #include "base/memory/ptr_util.h" #include "brave/browser/ui/webui/brave_adblock_ui.h" #include "brave/browser/ui/webui/brave_new_tab_ui.h" +#include "brave/common/brave_switches.h" #include "brave/common/webui_url_constants.h" #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" #include "brave/components/brave_wallet/browser/buildflags/buildflags.h" -#include "brave/components/brave_sync/brave_sync_service.h" #include "chrome/common/url_constants.h" #include "extensions/buildflags/buildflags.h" #include "url/gurl.h" @@ -63,8 +63,7 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { return new BraveWalletUI(web_ui, url.host()); #endif #if BUILDFLAG(ENABLE_EXTENSIONS) - } else if (host == kBraveUISyncHost && - brave_sync::BraveSyncService::is_enabled()) { + } else if (host == kBraveUISyncHost && switches::IsBraveSyncAllowedByFlag()) { return new SyncUI(web_ui, url.host()); #endif #if BUILDFLAG(BRAVE_REWARDS_ENABLED) @@ -105,8 +104,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, #endif url.host_piece() == kWelcomeHost || url.host_piece() == chrome::kChromeUIWelcomeURL || +#if BUILDFLAG(ENABLE_EXTENSIONS) (url.host_piece() == kBraveUISyncHost && - brave_sync::BraveSyncService::is_enabled()) || + switches::IsBraveSyncAllowedByFlag()) || +#endif url.host_piece() == chrome::kChromeUINewTabHost || url.host_piece() == chrome::kChromeUISettingsHost) { return &NewWebUI; diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index c93346266bdb..73cc9465de8c 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -5,6 +5,7 @@ #include "brave/chromium_src/chrome/browser/sync/profile_sync_service_factory.h" +#include "brave/common/brave_switches.h" #if BUILDFLAG(ENABLE_EXTENSIONS) #include "brave/components/brave_sync/brave_profile_sync_service.h" using brave_sync::BraveProfileSyncService; diff --git a/common/brave_switches.cc b/common/brave_switches.cc index 28da77521409..12b2c511cb00 100644 --- a/common/brave_switches.cc +++ b/common/brave_switches.cc @@ -5,8 +5,14 @@ #include "brave/common/brave_switches.h" +#include "base/command_line.h" + namespace switches { +bool IsBraveSyncAllowedByFlag() { + return !base::CommandLine::ForCurrentProcess()->HasSwitch(kDisableBraveSync); +} + // Allows disabling the Brave extension. // This is commonly used for loading the extension manually to debug things // in debug mode with auto-reloading. diff --git a/common/brave_switches.h b/common/brave_switches.h index a62e1e74bdcd..c5557e1563a8 100644 --- a/common/brave_switches.h +++ b/common/brave_switches.h @@ -8,6 +8,10 @@ namespace switches { +// This function can be called from any thread, and the implementation doesn't +// assume it's running on the UI thread. +bool IsBraveSyncAllowedByFlag(); + // All switches in alphabetical order. The switches should be documented // alongside the definition of their values in the .cc file. extern const char kDisableBraveExtension[]; diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 1152ec0b7a13..4a5fcbf838d8 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -54,6 +54,10 @@ source_set("prefs") { sources = [ "brave_sync_prefs.cc", "brave_sync_prefs.h", + "settings.cc", + "settings.h", + "sync_devices.cc", + "sync_devices.h", ] deps = [ @@ -67,10 +71,6 @@ source_set("core") { "bookmark_order_util.h", "brave_sync_service.cc", "brave_sync_service.h", - "settings.cc", - "settings.h", - "sync_devices.cc", - "sync_devices.h", "syncer_helper.cc", "syncer_helper.h", "tools.cc", diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 2f87959c34ec..287f66601a28 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -12,6 +12,7 @@ #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" +#include "components/bookmarks/browser/bookmark_model.h" #include "components/sync/driver/profile_sync_service.h" FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkAdded); diff --git a/components/brave_sync/brave_sync_prefs.cc b/components/brave_sync/brave_sync_prefs.cc index 15f5c7dcb257..2425b91ca53e 100644 --- a/components/brave_sync/brave_sync_prefs.cc +++ b/components/brave_sync/brave_sync_prefs.cc @@ -5,7 +5,6 @@ #include "brave/components/brave_sync/brave_sync_prefs.h" -#include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/settings.h" #include "brave/components/brave_sync/sync_devices.h" #include "components/prefs/pref_service.h" @@ -95,8 +94,7 @@ void Prefs::SetBookmarksBaseOrder(const std::string& order) { } bool Prefs::GetSyncEnabled() const { - return BraveSyncService::is_enabled() && - pref_service_->GetBoolean(kSyncEnabled); + return pref_service_->GetBoolean(kSyncEnabled); } void Prefs::SetSyncEnabled(const bool sync_this_device) { diff --git a/components/brave_sync/brave_sync_service.cc b/components/brave_sync/brave_sync_service.cc index bcef737d66ee..a196be76303f 100644 --- a/components/brave_sync/brave_sync_service.cc +++ b/components/brave_sync/brave_sync_service.cc @@ -5,8 +5,6 @@ #include "brave/components/brave_sync/brave_sync_service.h" -#include "base/command_line.h" -#include "brave/common/brave_switches.h" #include "brave/components/brave_sync/brave_sync_service_observer.h" namespace brave_sync { @@ -22,11 +20,4 @@ void BraveSyncService::RemoveObserver(BraveSyncServiceObserver* observer) { observers_.RemoveObserver(observer); } -// static -bool BraveSyncService::is_enabled() { - const base::CommandLine& command_line = - *base::CommandLine::ForCurrentProcess(); - return !command_line.HasSwitch(switches::kDisableBraveSync); -} - } // namespace brave_sync diff --git a/components/brave_sync/brave_sync_service.h b/components/brave_sync/brave_sync_service.h index 58ab16e89720..325f4bb58891 100644 --- a/components/brave_sync/brave_sync_service.h +++ b/components/brave_sync/brave_sync_service.h @@ -11,7 +11,6 @@ #include "base/macros.h" #include "base/observer_list.h" -#include "components/bookmarks/browser/bookmark_storage.h" #include "extensions/buildflags/buildflags.h" class Profile; @@ -23,8 +22,6 @@ class BraveSyncServiceObserver; class Settings; class SyncDevices; -bool IsSyncManagedNode(const bookmarks::BookmarkPermanentNode* node); - class BraveSyncService { public: BraveSyncService(); @@ -55,8 +52,6 @@ class BraveSyncService { void AddObserver(BraveSyncServiceObserver* observer); void RemoveObserver(BraveSyncServiceObserver* observer); - static bool is_enabled(); - #if BUILDFLAG(ENABLE_EXTENSIONS) virtual BraveSyncClient* GetBraveSyncClient() = 0; #endif diff --git a/patches/chrome-browser-BUILD.gn.patch b/patches/chrome-browser-BUILD.gn.patch index d356c2aabb47..58b1aa5d9d93 100644 --- a/patches/chrome-browser-BUILD.gn.patch +++ b/patches/chrome-browser-BUILD.gn.patch @@ -1,16 +1,17 @@ diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn -index 89006c99c02315f0c439dbf244d5ae3ce5cb7a0b..d2d69926e219836a2b09b7e7358be826f95ac553 100644 +index ed687fdfb15da8b1c9fad2b04fbfff5131690755..54d226aec1cb83c2230b34fb80e8925c80dd0226 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn -@@ -1810,6 +1810,7 @@ jumbo_split_static_library("browser") { +@@ -1810,6 +1810,8 @@ jumbo_split_static_library("browser") { ":resource_prefetch_predictor_proto", "//base:i18n", "//base/allocator:buildflags", + "//brave/components/brave_sync", ++ "//brave/common", "//cc", "//chrome:extra_resources", "//chrome:resources", -@@ -2099,6 +2100,7 @@ jumbo_split_static_library("browser") { +@@ -2099,6 +2101,7 @@ jumbo_split_static_library("browser") { "//ui/strings", "//ui/surface", "//ui/web_dialogs", diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch index ac6fff444db5..cfdd4b67b8a1 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -1,7 +1,16 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc -index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..c8414fb6cf9a829d1f3db822f688d4c5c91d523b 100644 +index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..a818f0fe4d029d6d6149ac221b79299d9dea5ec4 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc +@@ -104,7 +104,7 @@ ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { + // static + syncer::SyncService* ProfileSyncServiceFactory::GetForProfile( + Profile* profile) { +- if (!switches::IsSyncAllowedByFlag()) { ++ if (!switches::IsSyncAllowedByFlag() || !switches::IsBraveSyncAllowedByFlag()) { + return nullptr; + } + @@ -263,7 +263,11 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( } From bf1becba72b399cf1c2c19066e7565b762697e4d Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 31 May 2019 13:22:54 -0700 Subject: [PATCH 31/73] Window release build deps fix --- browser/profiles/BUILD.gn | 1 - components/brave_sync/BUILD.gn | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/browser/profiles/BUILD.gn b/browser/profiles/BUILD.gn index 7aa86f486f8e..a323388ff924 100644 --- a/browser/profiles/BUILD.gn +++ b/browser/profiles/BUILD.gn @@ -13,7 +13,6 @@ source_set("profiles") { "//brave/content:browser", "//brave/common/tor", "//brave/components/brave_ads/browser", - "//brave/components/brave_sync", "//brave/components/brave_rewards/browser", "//ui/base", ] diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 4a5fcbf838d8..5464c64572b2 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -86,12 +86,6 @@ source_set("core") { "//crypto", "//extensions/buildflags", ] - - if (enable_brave_sync) { - deps += [ - ":js_sync_lib_impl", - ] - } } source_set("brave_sync") { @@ -109,6 +103,12 @@ source_set("brave_sync") { "//components/pref_registry", "//content/public/browser", ] + + if (enable_brave_sync) { + deps += [ + ":js_sync_lib_impl", + ] + } } pack_web_resources("generated_resources") { From 902017fb4dde083baf8a12898651443ef2cc5c35 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 12 Jun 2019 11:05:49 -0700 Subject: [PATCH 32/73] single dep encapsulation --- components/brave_sync/BUILD.gn | 7 +++++++ patches/chrome-browser-BUILD.gn.patch | 13 ++----------- patches/components-sync-BUILD.gn.patch | 7 +++---- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 5464c64572b2..b2136eb2fa52 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -65,6 +65,13 @@ source_set("prefs") { ] } +source_set("syncer_export") { + deps = [ + ":jslib_messages", + ":prefs", + ] +} + source_set("core") { sources = [ "bookmark_order_util.cc", diff --git a/patches/chrome-browser-BUILD.gn.patch b/patches/chrome-browser-BUILD.gn.patch index 58b1aa5d9d93..da7f6bc29a70 100644 --- a/patches/chrome-browser-BUILD.gn.patch +++ b/patches/chrome-browser-BUILD.gn.patch @@ -1,17 +1,8 @@ diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn -index ed687fdfb15da8b1c9fad2b04fbfff5131690755..54d226aec1cb83c2230b34fb80e8925c80dd0226 100644 +index ed687fdfb15da8b1c9fad2b04fbfff5131690755..aa20037e76e20dac46cc38c923cb909cf0c0cdd9 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn -@@ -1810,6 +1810,8 @@ jumbo_split_static_library("browser") { - ":resource_prefetch_predictor_proto", - "//base:i18n", - "//base/allocator:buildflags", -+ "//brave/components/brave_sync", -+ "//brave/common", - "//cc", - "//chrome:extra_resources", - "//chrome:resources", -@@ -2099,6 +2101,7 @@ jumbo_split_static_library("browser") { +@@ -2099,6 +2099,7 @@ jumbo_split_static_library("browser") { "//ui/strings", "//ui/surface", "//ui/web_dialogs", diff --git a/patches/components-sync-BUILD.gn.patch b/patches/components-sync-BUILD.gn.patch index bb7d3ccd50c6..1e9c91dc7651 100644 --- a/patches/components-sync-BUILD.gn.patch +++ b/patches/components-sync-BUILD.gn.patch @@ -1,13 +1,12 @@ diff --git a/components/sync/BUILD.gn b/components/sync/BUILD.gn -index 0606b7e68670877100114732174af25ad0b42f77..22a62cebbd47644c4f189be012134f7c04c92af4 100644 +index 0606b7e68670877100114732174af25ad0b42f77..a95184ad1613aeca838ec51fc254509878d34f03 100644 --- a/components/sync/BUILD.gn +++ b/components/sync/BUILD.gn -@@ -99,6 +99,8 @@ jumbo_static_library("base") { +@@ -99,6 +99,7 @@ jumbo_static_library("base") { ] deps = [ "//base:i18n", -+ "//brave/components/brave_sync:jslib_messages", -+ "//brave/components/brave_sync:prefs", ++ "//brave/components/brave_sync:syncer_export", "//components/os_crypt", "//components/pref_registry", "//components/prefs", From 2b2e2e5c00c4304c5e9092fb2cafa85a58e99074 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 12 Jun 2019 11:58:40 -0700 Subject: [PATCH 33/73] IsSyncAllowedByFlag chromium_src override --- .../sync/driver/sync_driver_switches.cc | 18 ++++++++++++++++++ common/BUILD.gn | 14 ++++++++++++-- components/brave_sync/BUILD.gn | 1 + ...-sync-profile_sync_service_factory.cc.patch | 11 +---------- 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 chromium_src/components/sync/driver/sync_driver_switches.cc diff --git a/chromium_src/components/sync/driver/sync_driver_switches.cc b/chromium_src/components/sync/driver/sync_driver_switches.cc new file mode 100644 index 000000000000..1b656e72e96d --- /dev/null +++ b/chromium_src/components/sync/driver/sync_driver_switches.cc @@ -0,0 +1,18 @@ +/* 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 IsSyncAllowedByFlag IsSyncAllowedByFlag_ChromiumImpl +#include "../../../../../components/sync/driver/sync_driver_switches.cc" // NOLINT +#undef IsSyncAllowedByFlag + +#include "brave/common/brave_switches.h" + +namespace switches { + +bool IsSyncAllowedByFlag() { + return IsSyncAllowedByFlag_ChromiumImpl() && IsBraveSyncAllowedByFlag(); +} + +} // namespace switches diff --git a/common/BUILD.gn b/common/BUILD.gn index 00d67794bb6f..caadf808411a 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -25,6 +25,17 @@ source_set("pref_names") { ] } +source_set("switches") { + sources = [ + "brave_switches.cc", + "brave_switches.h", + ] + + deps = [ + "//base", + ] +} + source_set("common") { sources = [ "brave_content_client.cc", @@ -32,8 +43,6 @@ source_set("common") { "brave_isolated_worlds.h", "brave_paths.cc", "brave_paths.h", - "brave_switches.cc", - "brave_switches.h", "common_message_generator.cc", "common_message_generator.h", "importer/brave_referral.cc", @@ -80,6 +89,7 @@ source_set("common") { deps = [ ":pref_names", ":shield_exceptions", + ":switches", "//brave/chromium_src:common", "//content/public/common", ] diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index b2136eb2fa52..c5087d74a77c 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -69,6 +69,7 @@ source_set("syncer_export") { deps = [ ":jslib_messages", ":prefs", + "//brave/common:switches", ] } diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch index cfdd4b67b8a1..ac6fff444db5 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -1,16 +1,7 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc -index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..a818f0fe4d029d6d6149ac221b79299d9dea5ec4 100644 +index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..c8414fb6cf9a829d1f3db822f688d4c5c91d523b 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc -@@ -104,7 +104,7 @@ ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { - // static - syncer::SyncService* ProfileSyncServiceFactory::GetForProfile( - Profile* profile) { -- if (!switches::IsSyncAllowedByFlag()) { -+ if (!switches::IsSyncAllowedByFlag() || !switches::IsBraveSyncAllowedByFlag()) { - return nullptr; - } - @@ -263,7 +263,11 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( } From baf9003b1c95d1f1e398a9634f8c4a6e43b97be3 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 12 Jun 2019 14:37:49 -0700 Subject: [PATCH 34/73] remove GetAsBraveProfileSyncServiceForProfile and use ENABLE_BRAVE_SYNC in chromium --- browser/extensions/api/brave_sync_api.cc | 5 +++-- .../webui/brave_web_ui_controller_factory.cc | 8 ++++---- browser/ui/webui/sync/sync_ui.cc | 4 ++-- .../sync/profile_sync_service_factory.cc | 14 ++------------ .../sync/profile_sync_service_factory.h | 18 ------------------ components/brave_sync/BUILD.gn | 1 + .../brave_sync/brave_sync_service_unittest.cc | 6 +++--- ...-sync-profile_sync_service_factory.cc.patch | 4 ++-- ...r-sync-profile_sync_service_factory.h.patch | 15 --------------- 9 files changed, 17 insertions(+), 58 deletions(-) delete mode 100644 chromium_src/chrome/browser/sync/profile_sync_service_factory.h delete mode 100644 patches/chrome-browser-sync-profile_sync_service_factory.h.patch diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index 45e623c66f1c..63133f94ba88 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -28,8 +28,9 @@ namespace { BraveProfileSyncService* GetProfileSyncService( BrowserContext* browser_context) { - return ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( - Profile::FromBrowserContext(browser_context)); + return static_cast( + ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( + Profile::FromBrowserContext(browser_context))); } } // namespace diff --git a/browser/ui/webui/brave_web_ui_controller_factory.cc b/browser/ui/webui/brave_web_ui_controller_factory.cc index b32a65b721d5..50432e835eb2 100644 --- a/browser/ui/webui/brave_web_ui_controller_factory.cc +++ b/browser/ui/webui/brave_web_ui_controller_factory.cc @@ -13,9 +13,9 @@ #include "brave/common/brave_switches.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/common/url_constants.h" -#include "extensions/buildflags/buildflags.h" #include "url/gurl.h" #if !defined(OS_ANDROID) @@ -33,7 +33,7 @@ #include "brave/browser/ui/webui/brave_wallet_ui.h" #endif -#if BUILDFLAG(ENABLE_EXTENSIONS) +#if BUILDFLAG(ENABLE_BRAVE_SYNC) #include "brave/browser/ui/webui/sync/sync_ui.h" #endif @@ -62,7 +62,7 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { } else if (host == kWalletHost) { return new BraveWalletUI(web_ui, url.host()); #endif -#if BUILDFLAG(ENABLE_EXTENSIONS) +#if BUILDFLAG(ENABLE_BRAVE_SYNC) } else if (host == kBraveUISyncHost && switches::IsBraveSyncAllowedByFlag()) { return new SyncUI(web_ui, url.host()); #endif @@ -104,7 +104,7 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, #endif url.host_piece() == kWelcomeHost || url.host_piece() == chrome::kChromeUIWelcomeURL || -#if BUILDFLAG(ENABLE_EXTENSIONS) +#if BUILDFLAG(ENABLE_BRAVE_SYNC) (url.host_piece() == kBraveUISyncHost && switches::IsBraveSyncAllowedByFlag()) || #endif diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index 5d3f3c217fca..1610c4bbb133 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -125,8 +125,8 @@ void SyncUIDOMHandler::RegisterMessages() { void SyncUIDOMHandler::Init() { Profile* profile = Profile::FromWebUI(web_ui()); sync_service_ = - static_cast( - ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( + static_cast( + ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( profile)); if (sync_service_) sync_service_->AddObserver(this); diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index 73cc9465de8c..e4b83154a72e 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -3,20 +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/chromium_src/chrome/browser/sync/profile_sync_service_factory.h" +#include "brave/components/brave_sync/buildflags/buildflags.h" -#include "brave/common/brave_switches.h" -#if BUILDFLAG(ENABLE_EXTENSIONS) +#if BUILDFLAG(ENABLE_BRAVE_SYNC) #include "brave/components/brave_sync/brave_profile_sync_service.h" using brave_sync::BraveProfileSyncService; #endif #include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" // NOLINT - -#if BUILDFLAG(ENABLE_EXTENSIONS) -// static -BraveProfileSyncService* -ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( - Profile* profile) { - return static_cast(GetForProfile(profile)); -} -#endif diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.h b/chromium_src/chrome/browser/sync/profile_sync_service_factory.h deleted file mode 100644 index f7694faa0831..000000000000 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.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_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ -#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ - -#include "extensions/buildflags/buildflags.h" - -#if BUILDFLAG(ENABLE_EXTENSIONS) -namespace brave_sync { -class BraveProfileSyncService; -} // namespace brave_sync -#endif -#include "../../../../../chrome/browser/sync/profile_sync_service_factory.h" - -#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ // NOLINT diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index c5087d74a77c..80067f68ce9c 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -69,6 +69,7 @@ source_set("syncer_export") { deps = [ ":jslib_messages", ":prefs", + "buildflags", "//brave/common:switches", ] } diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 54eff40178be..8510fb0ff6cf 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -165,9 +165,9 @@ class BraveSyncServiceTest : public testing::Test { sync_client_ = new MockBraveSyncClient(); brave_sync::BraveSyncClientImpl::set_for_testing(sync_client_); - sync_service_ = - ProfileSyncServiceFactory::GetAsBraveProfileSyncServiceForProfile( - profile()); + sync_service_ = static_cast( + ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( + profile())); EXPECT_EQ(sync_client_, sync_service_->GetBraveSyncClient()); diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch index ac6fff444db5..afeaf7707ccc 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -1,12 +1,12 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc -index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..c8414fb6cf9a829d1f3db822f688d4c5c91d523b 100644 +index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..de1e275ac74060eefd9a340a5528e72cf9b4a931 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc @@ -263,7 +263,11 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( } auto pss = -+#if BUILDFLAG(ENABLE_EXTENSIONS) ++#if BUILDFLAG(ENABLE_BRAVE_SYNC) + std::make_unique(profile, std::move(init_params)); +#else std::make_unique(std::move(init_params)); diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.h.patch b/patches/chrome-browser-sync-profile_sync_service_factory.h.patch deleted file mode 100644 index fb1a2bc3c7e5..000000000000 --- a/patches/chrome-browser-sync-profile_sync_service_factory.h.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/chrome/browser/sync/profile_sync_service_factory.h b/chrome/browser/sync/profile_sync_service_factory.h -index 2e2f416a055c4bcc67c02b43ccc90ac8c13bc8f0..0e400986726357c866b9b93c215451e8f8f2e9b0 100644 ---- a/chrome/browser/sync/profile_sync_service_factory.h -+++ b/chrome/browser/sync/profile_sync_service_factory.h -@@ -38,6 +38,10 @@ class ProfileSyncServiceFactory : public BrowserContextKeyedServiceFactory { - // absolutely necessary! Prefer GetForProfile instead. - static syncer::ProfileSyncService* GetAsProfileSyncServiceForProfile( - Profile* profile); -+#if BUILDFLAG(ENABLE_EXTENSIONS) -+ static brave_sync::BraveProfileSyncService* -+ GetAsBraveProfileSyncServiceForProfile(Profile* profile); -+#endif - - // Returns whether a SyncService has already been created for the profile. - // Note that GetForProfile will create the service if it doesn't exist yet. From 55917003f6901ac6ba564888bf65de248f680264 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 12 Jun 2019 16:09:37 -0700 Subject: [PATCH 35/73] friend BraveProfileSyncService --- .../sync/driver/profile_sync_service.cc | 12 ++---------- .../sync/driver/profile_sync_service.h | 15 +++++++++++++++ .../brave_sync/brave_profile_sync_service.cc | 16 ++++++---------- ...ents-sync-driver-profile_sync_service.h.patch | 11 +++++------ 4 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 chromium_src/components/sync/driver/profile_sync_service.h diff --git a/chromium_src/components/sync/driver/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc index 3839ef1bfb05..53bea55c8319 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -3,6 +3,8 @@ * 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" + // For use_transport_only_mode #define IsSyncFeatureEnabled IsBraveSyncEnabled #include "../../../../components/sync/driver/profile_sync_service.cc" // NOLINT @@ -15,16 +17,6 @@ namespace syncer { const int64_t kBraveDefaultPollIntervalSeconds = 60; -syncer::SyncClient* ProfileSyncService::GetSyncClient() { - DCHECK(sync_client_); - return sync_client_.get(); -} - -syncer::SyncEngine* ProfileSyncService::GetSyncEngine() { - DCHECK(engine_); - return engine_.get(); -} - void ProfileSyncService::BraveEngineParamsInit( syncer::SyncEngine::InitParams* params) { DCHECK(params); diff --git a/chromium_src/components/sync/driver/profile_sync_service.h b/chromium_src/components/sync/driver/profile_sync_service.h new file mode 100644 index 000000000000..227d63477373 --- /dev/null +++ b/chromium_src/components/sync/driver/profile_sync_service.h @@ -0,0 +1,15 @@ +/* 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_PROFILE_SYNC_SERVICE_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ + +namespace brave_sync { +class BraveProfileSyncService; +} // namesapce brave_sync + +#include "../../../../../components/sync/driver/profile_sync_service.h" + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 0217600e4027..29c80fd86223 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -184,12 +184,10 @@ BraveProfileSyncService::BraveProfileSyncService(Profile* profile, brave_sync_client_(BraveSyncClient::Create(this, profile)) { brave_sync_words_ = std::string(); brave_sync_prefs_ = - std::make_unique( - ProfileSyncService::GetSyncClient()->GetPrefService()); + std::make_unique(sync_client_->GetPrefService()); // Moniter syncs prefs required in GetSettingsAndDevices - brave_pref_change_registrar_.Init( - ProfileSyncService::GetSyncClient()->GetPrefService()); + brave_pref_change_registrar_.Init(sync_client_->GetPrefService()); brave_pref_change_registrar_.Add( prefs::kSyncEnabled, base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, @@ -216,8 +214,8 @@ BraveProfileSyncService::BraveProfileSyncService(Profile* profile, base::Unretained(this))); // TODO(darkdh): find another way to obtain bookmark model // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 - model_ = static_cast( - ProfileSyncService::GetSyncClient())->GetBookmarkModel(); + model_ = static_cast(sync_client_.get()) + ->GetBookmarkModel(); if (!brave_sync_prefs_->GetSeed().empty() && !brave_sync_prefs_->GetThisDeviceName().empty()) { @@ -482,8 +480,7 @@ void BraveProfileSyncService::OnSyncReady() { if (brave_sync_prefs_->GetMigratedBookmarksVersion() < 2) SetPermanentNodesOrder(brave_sync_prefs_->GetBookmarksBaseOrder()); - syncer::SyncPrefs sync_prefs(ProfileSyncService::GetSyncClient() - ->GetPrefService()); + syncer::SyncPrefs sync_prefs(sync_client_->GetPrefService()); // first time setup sync or migrated from legacy sync if (sync_prefs.GetLastSyncedTime().is_null()) { ProfileSyncService::GetUserSettings() @@ -535,8 +532,7 @@ void BraveProfileSyncService::OnResolvedSyncRecords( } else if (category_name == kBookmarks) { // Send records to syncer if (get_record_cb_) - ProfileSyncService::GetSyncEngine()->DispatchGetRecordsCallback( - get_record_cb_, std::move(records)); + engine_->DispatchGetRecordsCallback(get_record_cb_, std::move(records)); SignalWaitableEvent(); } else if (category_name == kHistorySites) { NOTIMPLEMENTED(); diff --git a/patches/components-sync-driver-profile_sync_service.h.patch b/patches/components-sync-driver-profile_sync_service.h.patch index f0d1ec175ce2..4d064ad0769d 100644 --- a/patches/components-sync-driver-profile_sync_service.h.patch +++ b/patches/components-sync-driver-profile_sync_service.h.patch @@ -1,23 +1,22 @@ diff --git a/components/sync/driver/profile_sync_service.h b/components/sync/driver/profile_sync_service.h -index 3df5ee21f6ec37c5915607ec9196909c62545572..d23a45c2e548e6db6d1d2f6bee0957697dcd2235 100644 +index 3df5ee21f6ec37c5915607ec9196909c62545572..cbd81832b900c3eddfa4791c32bf828ba11df57b 100644 --- a/components/sync/driver/profile_sync_service.h +++ b/components/sync/driver/profile_sync_service.h -@@ -257,6 +257,14 @@ class ProfileSyncService : public SyncService, +@@ -257,7 +257,13 @@ class ProfileSyncService : public SyncService, SyncClient* GetSyncClientForTest(); -+ protected: -+ syncer::SyncClient* GetSyncClient(); -+ syncer::SyncEngine* GetSyncEngine(); + virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); + virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, + base::WaitableEvent* wevent); + virtual bool IsBraveSyncEnabled() const; + private: ++ friend class brave_sync::BraveProfileSyncService; friend class TestProfileSyncService; -@@ -268,6 +276,8 @@ class ProfileSyncService : public SyncService, + // Passed as an argument to StopImpl to control whether or not the sync +@@ -268,6 +274,8 @@ class ProfileSyncService : public SyncService, CLEAR_DATA, }; From 23fdeedb5e7d6442e488568924e2d3c0a538b326 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 13 Jun 2019 11:58:32 -0700 Subject: [PATCH 36/73] Using SyncEngineHost to avoid storing poll/nudge delegates --- .../sync/driver/glue/sync_engine_impl.cc | 6 ++--- .../sync/driver/profile_sync_service.cc | 6 ----- .../brave_sync/brave_profile_sync_service.h | 8 ++++--- ...nc-driver-glue-sync_engine_backend.h.patch | 15 ++++-------- ...sync-driver-glue-sync_engine_impl.cc.patch | 15 ------------ ...-sync-driver-glue-sync_engine_impl.h.patch | 24 ++++++------------- ...s-sync-driver-profile_sync_service.h.patch | 9 +++---- ...nents-sync-engine-sync_engine_host.h.patch | 15 ++++++++++++ 8 files changed, 37 insertions(+), 61 deletions(-) delete mode 100644 patches/components-sync-driver-glue-sync_engine_impl.cc.patch create mode 100644 patches/components-sync-engine-sync_engine_host.h.patch diff --git a/chromium_src/components/sync/driver/glue/sync_engine_impl.cc b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc index 7a1f6ea23172..c7ff36d04f9d 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_impl.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc @@ -17,16 +17,14 @@ namespace syncer { void SyncEngineImpl::HandleNudgeSyncCycle( brave_sync::RecordsListPtr records_list) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(nudge_sync_cycle_delegate_function_); - nudge_sync_cycle_delegate_function_.Run(std::move(records_list)); + host_->OnNudgeSyncCycle(std::move(records_list)); } void SyncEngineImpl::HandlePollSyncCycle( GetRecordsCallback cb, base::WaitableEvent* wevent) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(poll_sync_cycle_delegate_function_); - poll_sync_cycle_delegate_function_.Run(cb, wevent); + host_->OnPollSyncCycle(cb, wevent); } void SyncEngineImpl::DispatchGetRecordsCallback( diff --git a/chromium_src/components/sync/driver/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc index 53bea55c8319..16ce4b66acb4 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -32,12 +32,6 @@ void ProfileSyncService::BraveEngineParamsInit( syncer::kBraveDefaultPollIntervalSeconds)); } -void ProfileSyncService::OnNudgeSyncCycle( - brave_sync::RecordsListPtr records_list) {} - -void ProfileSyncService::OnPollSyncCycle(brave_sync::GetRecordsCallback cb, - base::WaitableEvent* wevent) {} - bool ProfileSyncService::IsBraveSyncEnabled() const { return false; } diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 287f66601a28..389222ec1e40 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -103,6 +103,11 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, syncer::ModelTypeSet GetPreferredDataTypes() const override; + // syncer::SyncEngineHost implementation + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; + void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, + base::WaitableEvent* wevent) override; + private: FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkAdded); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkDeleted); @@ -124,9 +129,6 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetExistingObjects); friend class ::BraveSyncServiceTest; - void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; - void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, - base::WaitableEvent* wevent) override; void SignalWaitableEvent(); void FetchSyncRecords(const bool bookmarks, const bool history, const bool preferences, int max_records); diff --git a/patches/components-sync-driver-glue-sync_engine_backend.h.patch b/patches/components-sync-driver-glue-sync_engine_backend.h.patch index 13e27db38a90..a48a42644b7a 100644 --- a/patches/components-sync-driver-glue-sync_engine_backend.h.patch +++ b/patches/components-sync-driver-glue-sync_engine_backend.h.patch @@ -1,24 +1,19 @@ diff --git a/components/sync/driver/glue/sync_engine_backend.h b/components/sync/driver/glue/sync_engine_backend.h -index 8cc3e5305b1010e025dbaf8a23c6180813fa9ef8..071673e8b51c234f95042d0ac84283c7a257aaad 100644 +index 8cc3e5305b1010e025dbaf8a23c6180813fa9ef8..8d1d1fd7d4ebadebf74ce295a37d5426fb2ade07 100644 --- a/components/sync/driver/glue/sync_engine_backend.h +++ b/components/sync/driver/glue/sync_engine_backend.h -@@ -177,11 +177,19 @@ class SyncEngineBackend : public base::RefCountedThreadSafe, +@@ -177,6 +177,14 @@ class SyncEngineBackend : public base::RefCountedThreadSafe, bool HasUnsyncedItemsForTest() const; + void DoDispatchGetRecordsCallback(GetRecordsCallback cb, + std::unique_ptr records); + - private: - friend class base::RefCountedThreadSafe; - - ~SyncEngineBackend() override; - + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); + void OnPollSyncCycle(GetRecordsCallback cb, + base::WaitableEvent* wevent); + void BraveInit(SyncManager::InitArgs* args); + - // For the olg tango based invalidations method returns true if the - // invalidation has version lower than last seen version for this datatype. - bool ShouldIgnoreRedundantInvalidation(const Invalidation& invalidation, + private: + friend class base::RefCountedThreadSafe; + diff --git a/patches/components-sync-driver-glue-sync_engine_impl.cc.patch b/patches/components-sync-driver-glue-sync_engine_impl.cc.patch deleted file mode 100644 index 199d93c893d2..000000000000 --- a/patches/components-sync-driver-glue-sync_engine_impl.cc.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/components/sync/driver/glue/sync_engine_impl.cc b/components/sync/driver/glue/sync_engine_impl.cc -index 5140252fbd55ffd37ae00625dc56ec927ea12de2..6fdf7aeb059b2ca5b09e03c99feb8eb04774b26d 100644 ---- a/components/sync/driver/glue/sync_engine_impl.cc -+++ b/components/sync/driver/glue/sync_engine_impl.cc -@@ -59,6 +59,10 @@ void SyncEngineImpl::Initialize(InitParams params) { - sync_task_runner_ = params.sync_task_runner; - host_ = params.host; - registrar_ = params.registrar.get(); -+ nudge_sync_cycle_delegate_function_ = -+ params.nudge_sync_cycle_delegate_function; -+ poll_sync_cycle_delegate_function_ = -+ params.poll_sync_cycle_delegate_function; - - sync_task_runner_->PostTask( - FROM_HERE, base::BindOnce(&SyncEngineBackend::DoInitialize, backend_, diff --git a/patches/components-sync-driver-glue-sync_engine_impl.h.patch b/patches/components-sync-driver-glue-sync_engine_impl.h.patch index 389650a46fa7..e9f5f2bad9c4 100644 --- a/patches/components-sync-driver-glue-sync_engine_impl.h.patch +++ b/patches/components-sync-driver-glue-sync_engine_impl.h.patch @@ -1,10 +1,10 @@ diff --git a/components/sync/driver/glue/sync_engine_impl.h b/components/sync/driver/glue/sync_engine_impl.h -index 9fce092e22ca630fa3f5efa0bc1e963a86659625..89f7155a590b71cdab381967009384ef2d040c06 100644 +index 9fce092e22ca630fa3f5efa0bc1e963a86659625..6b1c580ca9be2d3bdb3bf30221e13922629cd250 100644 --- a/components/sync/driver/glue/sync_engine_impl.h +++ b/components/sync/driver/glue/sync_engine_impl.h -@@ -160,6 +160,12 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { - - SyncEngineHost* host() { return host_; } +@@ -102,6 +102,12 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { + std::string GetOwnerName() const override; + void OnInvalidatorClientIdChange(const std::string& client_id) override; + void HandleNudgeSyncCycle(brave_sync::RecordsListPtr records_list); + void HandlePollSyncCycle(GetRecordsCallback cb, @@ -12,16 +12,6 @@ index 9fce092e22ca630fa3f5efa0bc1e963a86659625..89f7155a590b71cdab381967009384ef + void DispatchGetRecordsCallback( + GetRecordsCallback cb, std::unique_ptr records) override; + - private: - friend class SyncEngineBackend; - -@@ -215,6 +221,9 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { - ModelTypeSet last_enabled_types_; - bool sessions_invalidation_enabled_ = false; - -+ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function_; -+ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function_; -+ - // Checks that we're on the same thread this was constructed on (UI thread). - SEQUENCE_CHECKER(sequence_checker_); - + protected: + // The types and functions below are protected so that test + // subclasses can use them. diff --git a/patches/components-sync-driver-profile_sync_service.h.patch b/patches/components-sync-driver-profile_sync_service.h.patch index 4d064ad0769d..6e67cbbffcf1 100644 --- a/patches/components-sync-driver-profile_sync_service.h.patch +++ b/patches/components-sync-driver-profile_sync_service.h.patch @@ -1,14 +1,11 @@ diff --git a/components/sync/driver/profile_sync_service.h b/components/sync/driver/profile_sync_service.h -index 3df5ee21f6ec37c5915607ec9196909c62545572..cbd81832b900c3eddfa4791c32bf828ba11df57b 100644 +index 3df5ee21f6ec37c5915607ec9196909c62545572..c7daf0437953e1b795f030cb5a3ccf560d9c1ba3 100644 --- a/components/sync/driver/profile_sync_service.h +++ b/components/sync/driver/profile_sync_service.h -@@ -257,7 +257,13 @@ class ProfileSyncService : public SyncService, +@@ -257,7 +257,10 @@ class ProfileSyncService : public SyncService, SyncClient* GetSyncClientForTest(); -+ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, -+ base::WaitableEvent* wevent); + virtual bool IsBraveSyncEnabled() const; + private: @@ -16,7 +13,7 @@ index 3df5ee21f6ec37c5915607ec9196909c62545572..cbd81832b900c3eddfa4791c32bf828b friend class TestProfileSyncService; // Passed as an argument to StopImpl to control whether or not the sync -@@ -268,6 +274,8 @@ class ProfileSyncService : public SyncService, +@@ -268,6 +271,8 @@ class ProfileSyncService : public SyncService, CLEAR_DATA, }; diff --git a/patches/components-sync-engine-sync_engine_host.h.patch b/patches/components-sync-engine-sync_engine_host.h.patch new file mode 100644 index 000000000000..21da9d4d60fd --- /dev/null +++ b/patches/components-sync-engine-sync_engine_host.h.patch @@ -0,0 +1,15 @@ +diff --git a/components/sync/engine/sync_engine_host.h b/components/sync/engine/sync_engine_host.h +index c345abb5d7da17554c4a55bcbedd716a9b9c8e0d..fe8304d6ae6ff8af455d84103e3ea31a336e5a42 100644 +--- a/components/sync/engine/sync_engine_host.h ++++ b/components/sync/engine/sync_engine_host.h +@@ -87,6 +87,10 @@ class SyncEngineHost { + + // Called when the sync cycle returns there is an user actionable error. + virtual void OnActionableError(const SyncProtocolError& error) = 0; ++ ++ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) {} ++ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, ++ base::WaitableEvent* wevent) {} + }; + + } // namespace syncer From 0ff789faf19289a8eb90d8b9cbe7608bd9356cd3 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 13 Jun 2019 13:24:37 -0700 Subject: [PATCH 37/73] Move brave_sync::RegisterProfilePrefs to brave::RegisterProfilePrefs --- ...brave_autocomplete_provider_client_unittest.cc | 15 +++++++++++++-- .../autoplay_permission_context_unittest.cc | 1 - browser/brave_profile_prefs.cc | 3 +++ chromium_src/components/sync/base/sync_prefs.cc | 7 ------- components/brave_sync/BUILD.gn | 1 - patches/components-sync-base-sync_prefs.cc.patch | 12 ------------ 6 files changed, 16 insertions(+), 23 deletions(-) delete mode 100644 chromium_src/components/sync/base/sync_prefs.cc delete mode 100644 patches/components-sync-base-sync_prefs.cc.patch diff --git a/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc b/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc index 5a4d4344250b..78b495f1d294 100644 --- a/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc +++ b/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc @@ -6,8 +6,10 @@ #include "base/strings/utf_string_conversions.h" #include "brave/common/webui_url_constants.h" +#include "chrome/browser/prefs/browser_prefs.h" #include "chrome/common/webui_url_constants.h" #include "chrome/test/base/testing_profile.h" +#include "components/sync_preferences/testing_pref_service_syncable.h" #include "content/public/test/fake_service_worker_context.h" #include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" @@ -15,7 +17,7 @@ class BraveAutocompleteProviderClientUnitTest : public testing::Test { public: void SetUp() override { - profile_ = std::make_unique(); + profile_ = CreateProfile(); client_ = std::make_unique(profile_.get()); } @@ -26,7 +28,16 @@ class BraveAutocompleteProviderClientUnitTest : public testing::Test { return it != v.end(); } - protected: + private: + std::unique_ptr CreateProfile() { + TestingProfile::Builder builder; + auto prefs = + std::make_unique(); + RegisterUserProfilePrefs(prefs->registry()); + builder.SetPrefService(std::move(prefs)); + return builder.Build(); + } + content::TestBrowserThreadBundle test_browser_thread_bundle_; std::unique_ptr profile_; std::unique_ptr client_; diff --git a/browser/autoplay/autoplay_permission_context_unittest.cc b/browser/autoplay/autoplay_permission_context_unittest.cc index fbedba51246f..ab4d802b67cb 100644 --- a/browser/autoplay/autoplay_permission_context_unittest.cc +++ b/browser/autoplay/autoplay_permission_context_unittest.cc @@ -11,7 +11,6 @@ #include "base/bind.h" #include "base/macros.h" -#include "brave/common/pref_names.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/permissions/permission_request_id.h" #include "chrome/browser/permissions/permission_request_manager.h" diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index b011b7c4d518..40a2ba95204c 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -8,6 +8,7 @@ #include "brave/common/pref_names.h" #include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h" #include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" +#include "brave/components/brave_sync/brave_sync_prefs.h" #include "chrome/browser/net/prediction_options.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/common/pref_names.h" @@ -44,6 +45,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterBooleanPref(kLocationBarIsWide, false); registry->RegisterBooleanPref(kHideBraveRewardsButton, false); + brave_sync::prefs::Prefs::RegisterProfilePrefs(registry); + registry->RegisterBooleanPref(kWidevineOptedIn, false); registry->RegisterBooleanPref(kAskWidevineInstall, true); #if BUILDFLAG(BUNDLE_WIDEVINE_CDM) diff --git a/chromium_src/components/sync/base/sync_prefs.cc b/chromium_src/components/sync/base/sync_prefs.cc deleted file mode 100644 index 99164855dff1..000000000000 --- a/chromium_src/components/sync/base/sync_prefs.cc +++ /dev/null @@ -1,7 +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/brave_sync_prefs.h" -#include "../../../../components/sync/base/sync_prefs.cc" // NOLINT diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 80067f68ce9c..97533092ac47 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -68,7 +68,6 @@ source_set("prefs") { source_set("syncer_export") { deps = [ ":jslib_messages", - ":prefs", "buildflags", "//brave/common:switches", ] diff --git a/patches/components-sync-base-sync_prefs.cc.patch b/patches/components-sync-base-sync_prefs.cc.patch deleted file mode 100644 index 04c067ef6526..000000000000 --- a/patches/components-sync-base-sync_prefs.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/sync/base/sync_prefs.cc b/components/sync/base/sync_prefs.cc -index e0233e2c1fe41e7aca1514321881a9defe99e11f..8331c1add5cbc209023cfb938b11ef8c564e2b90 100644 ---- a/components/sync/base/sync_prefs.cc -+++ b/components/sync/base/sync_prefs.cc -@@ -186,6 +186,7 @@ void SyncPrefs::RegisterProfilePrefs( - #if defined(OS_CHROMEOS) - registry->RegisterStringPref(kSyncSpareBootstrapToken, ""); - #endif -+ brave_sync::prefs::Prefs::RegisterProfilePrefs(registry); - } - - void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { From d970cad240e5e609b3062c82a81327a0e142e396 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Sat, 15 Jun 2019 20:33:10 -0700 Subject: [PATCH 38/73] Chromium override SyncerProtoUtil --- ...e_autocomplete_provider_client_unittest.cc | 10 ++++-- .../sync/engine_impl/syncer_proto_util.cc | 31 +++++++++++++++++++ ...omponents-sync-engine_impl-commit.cc.patch | 12 +++---- ...engine_impl-get_updates_processor.cc.patch | 13 +++----- ...ync-engine_impl-syncer_proto_util.cc.patch | 14 --------- ...sync-engine_impl-syncer_proto_util.h.patch | 20 ++++++++++++ 6 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 chromium_src/components/sync/engine_impl/syncer_proto_util.cc delete mode 100644 patches/components-sync-engine_impl-syncer_proto_util.cc.patch create mode 100644 patches/components-sync-engine_impl-syncer_proto_util.h.patch diff --git a/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc b/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc index 78b495f1d294..f4a0a2698e5e 100644 --- a/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc +++ b/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc @@ -1,9 +1,14 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* 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/browser/autocomplete/brave_autocomplete_provider_client.h" +#include +#include +#include + #include "base/strings/utf_string_conversions.h" #include "brave/common/webui_url_constants.h" #include "chrome/browser/prefs/browser_prefs.h" @@ -45,6 +50,7 @@ class BraveAutocompleteProviderClientUnitTest : public testing::Test { TEST_F(BraveAutocompleteProviderClientUnitTest, SyncURLSuggestedNotSyncInternal) { - ASSERT_FALSE(BuiltinExists(base::ASCIIToUTF16(chrome::kChromeUISyncInternalsHost))); + ASSERT_FALSE(BuiltinExists( + base::ASCIIToUTF16(chrome::kChromeUISyncInternalsHost))); ASSERT_TRUE(BuiltinExists(base::ASCIIToUTF16(kBraveUISyncHost))); } diff --git a/chromium_src/components/sync/engine_impl/syncer_proto_util.cc b/chromium_src/components/sync/engine_impl/syncer_proto_util.cc new file mode 100644 index 000000000000..dd6a434fcec4 --- /dev/null +++ b/chromium_src/components/sync/engine_impl/syncer_proto_util.cc @@ -0,0 +1,31 @@ +/* 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/syncer_proto_util.h" +#define AddRequiredFieldsToClientToServerMessage AddRequiredFieldsToClientToServerMessage_ChromiumImpl // NOLINT +#define PostClientToServerMessage PostClientToServerMessage_ChromiumImpl +#include "../../../../../components/sync/engine_impl/syncer_proto_util.cc" // NOLINT +#undef PostClientToServerMessage +#undef AddRequiredFieldsToClientToServerMessage + +namespace syncer { +namespace { +} // namespace + +// static +void SyncerProtoUtil::AddRequiredFieldsToClientToServerMessage( + const SyncCycle* cycle, + sync_pb::ClientToServerMessage* msg) {} + +// static +SyncerError SyncerProtoUtil::PostClientToServerMessage( + const ClientToServerMessage& msg, + ClientToServerResponse* response, + SyncCycle* cycle, + ModelTypeSet* partial_failure_data_types) { + return SyncerError(SyncerError::SYNCER_OK); +} + +} // namespace syncer diff --git a/patches/components-sync-engine_impl-commit.cc.patch b/patches/components-sync-engine_impl-commit.cc.patch index aefc1179452e..751bb5663dcf 100644 --- a/patches/components-sync-engine_impl-commit.cc.patch +++ b/patches/components-sync-engine_impl-commit.cc.patch @@ -1,14 +1,12 @@ diff --git a/components/sync/engine_impl/commit.cc b/components/sync/engine_impl/commit.cc -index 312f59cb0e7126d2c7d3059f3eef8819f993c523..29d49da7aaa37cb7e4e4b6e5ca3d59dc7c35ec85 100644 +index 312f59cb0e7126d2c7d3059f3eef8819f993c523..f18e6269e050b2d0f099827095b28573fd7b5d68 100644 --- a/components/sync/engine_impl/commit.cc +++ b/components/sync/engine_impl/commit.cc -@@ -131,8 +131,7 @@ SyncerError Commit::PostAndProcessResponse( - - TRACE_EVENT_BEGIN0("sync", "PostCommit"); +@@ -133,6 +133,7 @@ SyncerError Commit::PostAndProcessResponse( sync_pb::ClientToServerResponse response; -- const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( -- message_, &response, cycle, nullptr); -+ const SyncerError post_result = PostBraveCommit(&message_, &response, cycle); + const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( + message_, &response, cycle, nullptr); ++ PostBraveCommit(&message_, &response, cycle); TRACE_EVENT_END0("sync", "PostCommit"); // TODO(rlarocque): Use result that includes errors captured later? diff --git a/patches/components-sync-engine_impl-get_updates_processor.cc.patch b/patches/components-sync-engine_impl-get_updates_processor.cc.patch index 51528b4a2749..7ecefc86ff8e 100644 --- a/patches/components-sync-engine_impl-get_updates_processor.cc.patch +++ b/patches/components-sync-engine_impl-get_updates_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync/engine_impl/get_updates_processor.cc b/components/sync/engine_impl/get_updates_processor.cc -index faeff075cf940e8c1db7941f4c3dca27bf63f580..3829f379ca8167982e6a82654e3bb6ed9773b07d 100644 +index faeff075cf940e8c1db7941f4c3dca27bf63f580..98992f1553a4622fe2a3918108fb8a89ac7bc5ff 100644 --- a/components/sync/engine_impl/get_updates_processor.cc +++ b/components/sync/engine_impl/get_updates_processor.cc @@ -36,6 +36,7 @@ bool ShouldRequestEncryptionKey(SyncCycleContext* context) { @@ -10,14 +10,11 @@ index faeff075cf940e8c1db7941f4c3dca27bf63f580..3829f379ca8167982e6a82654e3bb6ed bool success = false; if (update_response.get_updates().encryption_keys_size() == 0) { LOG(ERROR) << "Failed to receive encryption key from server."; -@@ -223,8 +224,8 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( +@@ -225,6 +226,7 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( - ModelTypeSet partial_failure_data_types; - -- SyncerError result = SyncerProtoUtil::PostClientToServerMessage( -- *msg, &update_response, cycle, &partial_failure_data_types); -+ SyncerError result = ApplyBraveRecords(&update_response, request_types, -+ std::move(brave_records_)); + SyncerError result = SyncerProtoUtil::PostClientToServerMessage( + *msg, &update_response, cycle, &partial_failure_data_types); ++ result = ApplyBraveRecords(&update_response, request_types, std::move(brave_records_)); DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( update_response); diff --git a/patches/components-sync-engine_impl-syncer_proto_util.cc.patch b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch deleted file mode 100644 index d66a165c8029..000000000000 --- a/patches/components-sync-engine_impl-syncer_proto_util.cc.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/components/sync/engine_impl/syncer_proto_util.cc b/components/sync/engine_impl/syncer_proto_util.cc -index 6706d0225207d266b1ed74cc712462052b3180a6..a58ea213c65714d4841d656e85d320c856ebc266 100644 ---- a/components/sync/engine_impl/syncer_proto_util.cc -+++ b/components/sync/engine_impl/syncer_proto_util.cc -@@ -434,7 +434,8 @@ void SyncerProtoUtil::AddRequiredFieldsToClientToServerMessage( - DCHECK(msg); - SetProtocolVersion(msg); - AddRequestBirthday(cycle->context()->directory(), msg); -- DCHECK(msg->has_store_birthday() || !IsBirthdayRequired(*msg)); -+ // TODO(darkdh): deal with a6aca7bcee196866fc53d487f0025c502df7611a -+ // DCHECK(msg->has_store_birthday() || !IsBirthdayRequired(*msg)); - AddBagOfChips(cycle->context()->directory(), msg); - msg->set_api_key(google_apis::GetAPIKey()); - msg->mutable_client_status()->CopyFrom(cycle->context()->client_status()); diff --git a/patches/components-sync-engine_impl-syncer_proto_util.h.patch b/patches/components-sync-engine_impl-syncer_proto_util.h.patch new file mode 100644 index 000000000000..382a315a03db --- /dev/null +++ b/patches/components-sync-engine_impl-syncer_proto_util.h.patch @@ -0,0 +1,20 @@ +diff --git a/components/sync/engine_impl/syncer_proto_util.h b/components/sync/engine_impl/syncer_proto_util.h +index c48993057a9e87c0cc5c025fa2e8756e5d2940d9..09dc6b0f3fc6291708b4716c74f132871f4b3d23 100644 +--- a/components/sync/engine_impl/syncer_proto_util.h ++++ b/components/sync/engine_impl/syncer_proto_util.h +@@ -47,6 +47,7 @@ class SyncerProtoUtil { + static void AddRequiredFieldsToClientToServerMessage( + const SyncCycle* cycle, + sync_pb::ClientToServerMessage* msg); ++ static void AddRequiredFieldsToClientToServerMessage_ChromiumImpl(const SyncCycle*, sync_pb::ClientToServerMessage*); + + // Posts the given message and fills the buffer with the returned value. + // Returns true on success. Also handles store birthday verification: will +@@ -57,6 +58,7 @@ class SyncerProtoUtil { + sync_pb::ClientToServerResponse* response, + SyncCycle* cycle, + ModelTypeSet* partial_failure_data_types); ++ static SyncerError PostClientToServerMessage_ChromiumImpl(const sync_pb::ClientToServerMessage&, sync_pb::ClientToServerResponse*, SyncCycle*, ModelTypeSet*); + + // Specifies where entity's position should be updated from the data in + // GetUpdates message. From 38b42cf7ff324a417d84801560d2080be1949745 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 17 Jun 2019 18:53:12 -0700 Subject: [PATCH 39/73] Update 75.0.3770.90 patch --- patches/chrome-browser-BUILD.gn.patch | 2 +- ...ts-sync-driver-glue-sync_engine_backend.h.patch | 11 ++++------- ...nents-sync-driver-glue-sync_engine_impl.h.patch | 10 ++++------ ...nents-sync-driver-profile_sync_service.cc.patch | 7 +++---- patches/components-sync-engine-sync_engine.h.patch | 8 +++----- ...components-sync-engine-sync_engine_host.h.patch | 7 +++---- ...nents-sync-engine_impl-cycle-sync_cycle.h.patch | 7 +++---- ...ponents-sync-engine_impl-sync_scheduler.h.patch | 7 +++---- ...ts-sync-engine_impl-sync_scheduler_impl.h.patch | 14 ++++++-------- 9 files changed, 30 insertions(+), 43 deletions(-) diff --git a/patches/chrome-browser-BUILD.gn.patch b/patches/chrome-browser-BUILD.gn.patch index da7f6bc29a70..e31e02ca1a28 100644 --- a/patches/chrome-browser-BUILD.gn.patch +++ b/patches/chrome-browser-BUILD.gn.patch @@ -1,5 +1,5 @@ diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn -index ed687fdfb15da8b1c9fad2b04fbfff5131690755..aa20037e76e20dac46cc38c923cb909cf0c0cdd9 100644 +index 600fe26a3f3537545d683d7fb9712446957d01fb..6d58c95c2ebe78709419b44fb9596cb3de20898c 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -2099,6 +2099,7 @@ jumbo_split_static_library("browser") { diff --git a/patches/components-sync-driver-glue-sync_engine_backend.h.patch b/patches/components-sync-driver-glue-sync_engine_backend.h.patch index a48a42644b7a..5cbaf9703e81 100644 --- a/patches/components-sync-driver-glue-sync_engine_backend.h.patch +++ b/patches/components-sync-driver-glue-sync_engine_backend.h.patch @@ -1,17 +1,14 @@ diff --git a/components/sync/driver/glue/sync_engine_backend.h b/components/sync/driver/glue/sync_engine_backend.h -index 8cc3e5305b1010e025dbaf8a23c6180813fa9ef8..8d1d1fd7d4ebadebf74ce295a37d5426fb2ade07 100644 +index 8cc3e5305b1010e025dbaf8a23c6180813fa9ef8..2cb09e7a0dfc52c833f1b47f67a3625f45117590 100644 --- a/components/sync/driver/glue/sync_engine_backend.h +++ b/components/sync/driver/glue/sync_engine_backend.h -@@ -177,6 +177,14 @@ class SyncEngineBackend : public base::RefCountedThreadSafe, +@@ -177,6 +177,11 @@ class SyncEngineBackend : public base::RefCountedThreadSafe, bool HasUnsyncedItemsForTest() const; -+ void DoDispatchGetRecordsCallback(GetRecordsCallback cb, -+ std::unique_ptr records); -+ ++ void DoDispatchGetRecordsCallback(GetRecordsCallback cb, std::unique_ptr records); + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ void OnPollSyncCycle(GetRecordsCallback cb, -+ base::WaitableEvent* wevent); ++ void OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent); + void BraveInit(SyncManager::InitArgs* args); + private: diff --git a/patches/components-sync-driver-glue-sync_engine_impl.h.patch b/patches/components-sync-driver-glue-sync_engine_impl.h.patch index e9f5f2bad9c4..d7bc83c0865b 100644 --- a/patches/components-sync-driver-glue-sync_engine_impl.h.patch +++ b/patches/components-sync-driver-glue-sync_engine_impl.h.patch @@ -1,16 +1,14 @@ diff --git a/components/sync/driver/glue/sync_engine_impl.h b/components/sync/driver/glue/sync_engine_impl.h -index 9fce092e22ca630fa3f5efa0bc1e963a86659625..6b1c580ca9be2d3bdb3bf30221e13922629cd250 100644 +index 9fce092e22ca630fa3f5efa0bc1e963a86659625..8663e3c7adebba9f631e42bd8cc966accab81e02 100644 --- a/components/sync/driver/glue/sync_engine_impl.h +++ b/components/sync/driver/glue/sync_engine_impl.h -@@ -102,6 +102,12 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { +@@ -102,6 +102,10 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { std::string GetOwnerName() const override; void OnInvalidatorClientIdChange(const std::string& client_id) override; + void HandleNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ void HandlePollSyncCycle(GetRecordsCallback cb, -+ base::WaitableEvent* wevent); -+ void DispatchGetRecordsCallback( -+ GetRecordsCallback cb, std::unique_ptr records) override; ++ void HandlePollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent); ++ void DispatchGetRecordsCallback(GetRecordsCallback cb, std::unique_ptr records) override; + protected: // The types and functions below are protected so that test diff --git a/patches/components-sync-driver-profile_sync_service.cc.patch b/patches/components-sync-driver-profile_sync_service.cc.patch index 860c15ffff0b..acbd76bd6b8e 100644 --- a/patches/components-sync-driver-profile_sync_service.cc.patch +++ b/patches/components-sync-driver-profile_sync_service.cc.patch @@ -1,13 +1,12 @@ diff --git a/components/sync/driver/profile_sync_service.cc b/components/sync/driver/profile_sync_service.cc -index 7c7daae97e5fe9ec16aa231628c28d1a9d6db100..75f5fc3052996ff4f6d373a095d229cdfc7eb419 100644 +index 3dc7667b7fc5a919f2025c53e040265927e6ea23..a0c7a38db6f26403988f3f8d14a8edb5ef7b8c30 100644 --- a/components/sync/driver/profile_sync_service.cc +++ b/components/sync/driver/profile_sync_service.cc -@@ -458,6 +458,8 @@ void ProfileSyncService::StartUpSlowEngineComponents() { +@@ -458,6 +458,7 @@ void ProfileSyncService::StartUpSlowEngineComponents() { params.sync_user_agent = MakeUserAgentForSync(channel_); params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); params.authenticated_account_id = GetAuthenticatedAccountInfo().account_id; -+ if (IsBraveSyncEnabled()) -+ BraveEngineParamsInit(¶ms); ++ if (IsBraveSyncEnabled()) BraveEngineParamsInit(¶ms); DCHECK(!params.authenticated_account_id.empty() || IsLocalSyncEnabled()); if (!base::FeatureList::IsEnabled(switches::kSyncE2ELatencyMeasurement)) { invalidation::InvalidationService* invalidator = diff --git a/patches/components-sync-engine-sync_engine.h.patch b/patches/components-sync-engine-sync_engine.h.patch index f76123c1045d..e79e67bf61e9 100644 --- a/patches/components-sync-engine-sync_engine.h.patch +++ b/patches/components-sync-engine-sync_engine.h.patch @@ -1,5 +1,5 @@ diff --git a/components/sync/engine/sync_engine.h b/components/sync/engine/sync_engine.h -index e4d2ab4d38f6fffd2929277be51ec618180e0086..721df77d28d5d5a2c43660df09edd0697492f071 100644 +index e4d2ab4d38f6fffd2929277be51ec618180e0086..2a74f799277bd6bdb56875daaef1edf107790e32 100644 --- a/components/sync/engine/sync_engine.h +++ b/components/sync/engine/sync_engine.h @@ -87,6 +87,9 @@ class SyncEngine : public ModelTypeConfigurer { @@ -12,13 +12,11 @@ index e4d2ab4d38f6fffd2929277be51ec618180e0086..721df77d28d5d5a2c43660df09edd069 private: DISALLOW_COPY_AND_ASSIGN(InitParams); }; -@@ -199,6 +202,10 @@ class SyncEngine : public ModelTypeConfigurer { +@@ -199,6 +202,8 @@ class SyncEngine : public ModelTypeConfigurer { virtual std::unique_ptr GetNigoriControllerDelegate() = 0; -+ virtual void DispatchGetRecordsCallback( -+ brave_sync::GetRecordsCallback cb, -+ std::unique_ptr records) {} ++ virtual void DispatchGetRecordsCallback(brave_sync::GetRecordsCallback cb, std::unique_ptr records) {} + private: DISALLOW_COPY_AND_ASSIGN(SyncEngine); diff --git a/patches/components-sync-engine-sync_engine_host.h.patch b/patches/components-sync-engine-sync_engine_host.h.patch index 21da9d4d60fd..84763492de4d 100644 --- a/patches/components-sync-engine-sync_engine_host.h.patch +++ b/patches/components-sync-engine-sync_engine_host.h.patch @@ -1,15 +1,14 @@ diff --git a/components/sync/engine/sync_engine_host.h b/components/sync/engine/sync_engine_host.h -index c345abb5d7da17554c4a55bcbedd716a9b9c8e0d..fe8304d6ae6ff8af455d84103e3ea31a336e5a42 100644 +index c345abb5d7da17554c4a55bcbedd716a9b9c8e0d..3049f6158b70f209871a38d30c3d94fab278a179 100644 --- a/components/sync/engine/sync_engine_host.h +++ b/components/sync/engine/sync_engine_host.h -@@ -87,6 +87,10 @@ class SyncEngineHost { +@@ -87,6 +87,9 @@ class SyncEngineHost { // Called when the sync cycle returns there is an user actionable error. virtual void OnActionableError(const SyncProtocolError& error) = 0; + + virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) {} -+ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, -+ base::WaitableEvent* wevent) {} ++ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) {} }; } // namespace syncer diff --git a/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch b/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch index 150b82906de1..a3e0a05e9183 100644 --- a/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch +++ b/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch @@ -1,14 +1,13 @@ diff --git a/components/sync/engine_impl/cycle/sync_cycle.h b/components/sync/engine_impl/cycle/sync_cycle.h -index 0971b6014231f8046eca9202840acc6167960057..e7c9f40c1f3294650597dab18d558c998cf8dd95 100644 +index 0971b6014231f8046eca9202840acc6167960057..ccc08280b387952e0df44760672b0dc62d9a3059 100644 --- a/components/sync/engine_impl/cycle/sync_cycle.h +++ b/components/sync/engine_impl/cycle/sync_cycle.h -@@ -80,6 +80,10 @@ class SyncCycle { +@@ -80,6 +80,9 @@ class SyncCycle { // Called when server requests a migration. virtual void OnReceivedMigrationRequest(ModelTypeSet types) = 0; + virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) {} -+ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, -+ base::WaitableEvent* wevent) {} ++ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) {} + protected: virtual ~Delegate() {} diff --git a/patches/components-sync-engine_impl-sync_scheduler.h.patch b/patches/components-sync-engine_impl-sync_scheduler.h.patch index 3e58e6299fc2..ea262edb8c85 100644 --- a/patches/components-sync-engine_impl-sync_scheduler.h.patch +++ b/patches/components-sync-engine_impl-sync_scheduler.h.patch @@ -1,14 +1,13 @@ diff --git a/components/sync/engine_impl/sync_scheduler.h b/components/sync/engine_impl/sync_scheduler.h -index 5628c5b9c3139846cee938dd2ff882623a4e3e76..336055bf5ddd60dd9a717fbfea07dddb5f09fc78 100644 +index 5628c5b9c3139846cee938dd2ff882623a4e3e76..316d661b46e9f11c55195b78da3f535bca0b0ed7 100644 --- a/components/sync/engine_impl/sync_scheduler.h +++ b/components/sync/engine_impl/sync_scheduler.h -@@ -125,6 +125,9 @@ class SyncScheduler : public SyncCycle::Delegate { +@@ -125,6 +125,8 @@ class SyncScheduler : public SyncCycle::Delegate { // Called when the network layer detects a connection status change. virtual void OnConnectionStatusChange( network::mojom::ConnectionType type) = 0; + -+ virtual void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, -+ brave_sync::PollSyncCycleDelegate) {} ++ virtual void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, brave_sync::PollSyncCycleDelegate) {} }; } // namespace syncer diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch index b89871e9dfb4..7e300ba99e05 100644 --- a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch @@ -1,21 +1,19 @@ diff --git a/components/sync/engine_impl/sync_scheduler_impl.h b/components/sync/engine_impl/sync_scheduler_impl.h -index 4bab39098da187109f291f1c0ab03fd0cc34d326..f48cf362f1030fd8b269ad213330255de95ea82c 100644 +index 4bab39098da187109f291f1c0ab03fd0cc34d326..db1bfdfcc4470f1aeb41ae7d37f02dd9271e25f9 100644 --- a/components/sync/engine_impl/sync_scheduler_impl.h +++ b/components/sync/engine_impl/sync_scheduler_impl.h -@@ -79,6 +79,12 @@ class SyncSchedulerImpl : public SyncScheduler { +@@ -79,6 +79,10 @@ class SyncSchedulerImpl : public SyncScheduler { void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override; void OnReceivedMigrationRequest(ModelTypeSet types) override; + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; -+ void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, -+ base::WaitableEvent* wevent) override; -+ void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, -+ brave_sync::PollSyncCycleDelegate) override; ++ void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) override; ++ void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, brave_sync::PollSyncCycleDelegate) override; + bool IsGlobalThrottle() const; bool IsGlobalBackoff() const; -@@ -177,6 +183,7 @@ class SyncSchedulerImpl : public SyncScheduler { +@@ -177,6 +181,7 @@ class SyncSchedulerImpl : public SyncScheduler { // current thread. In the future it will request access token here. void TrySyncCycleJob(); void TrySyncCycleJobImpl(); @@ -23,7 +21,7 @@ index 4bab39098da187109f291f1c0ab03fd0cc34d326..f48cf362f1030fd8b269ad213330255d // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). // This function is for global throttling. -@@ -281,6 +288,9 @@ class SyncSchedulerImpl : public SyncScheduler { +@@ -281,6 +286,9 @@ class SyncSchedulerImpl : public SyncScheduler { // Used to prevent changing nudge delays by the server in integration tests. bool force_short_nudge_delay_for_test_ = false; From 48d6aaf32dea23212592075a341f81d0c5601c87 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 18 Jun 2019 17:20:40 -0700 Subject: [PATCH 40/73] clean up patches --- .../sync/profile_sync_service_factory.cc | 28 +++++++- .../sync/driver/glue/sync_engine_backend.cc | 71 +++++++++++++------ .../sync/driver/glue/sync_engine_backend.h | 16 ----- .../sync/driver/glue/sync_engine_impl.cc | 38 ---------- .../sync/driver/glue/sync_engine_impl.h | 10 ++- .../sync/driver/profile_sync_service.cc | 62 ++++++++++++---- .../sync/driver/profile_sync_service.h | 4 ++ .../components/sync/engine/sync_engine.h | 6 ++ .../components/sync/engine/sync_manager.h | 7 ++ .../components/sync/engine_impl/commit.cc | 5 ++ .../sync/engine_impl/cycle/sync_cycle.h | 6 ++ .../sync/engine_impl/get_updates_processor.cc | 1 + .../sync/engine_impl/get_updates_processor.h | 9 +++ .../sync/engine_impl/sync_manager_impl.cc | 20 +++--- .../sync/engine_impl/sync_scheduler_impl.cc | 20 ++---- .../sync/engine_impl/sync_scheduler_impl.h | 24 +++++++ .../components/sync/engine_impl/syncer.cc | 2 +- .../components/sync/engine_impl/syncer.h | 12 +++- .../sync/engine_impl/syncer_proto_util.cc | 31 -------- .../bookmark_change_processor.cc | 55 ++++++++++---- components/brave_sync/BUILD.gn | 3 +- .../brave_sync/brave_profile_sync_service.cc | 18 ++++- .../brave_sync/brave_profile_sync_service.h | 7 +- ...sync-profile_sync_service_factory.cc.patch | 11 ++- patches/components-sync-BUILD.gn.patch | 4 +- ...ync-driver-data_type_manager_impl.cc.patch | 10 ++- ...c-driver-glue-sync_engine_backend.cc.patch | 4 +- ...nc-driver-glue-sync_engine_backend.h.patch | 16 ----- ...-sync-driver-glue-sync_engine_impl.h.patch | 19 +++-- ...-sync-driver-profile_sync_service.cc.patch | 4 +- ...s-sync-driver-profile_sync_service.h.patch | 24 ++----- ...components-sync-engine-sync_engine.h.patch | 19 ++--- ...nents-sync-engine-sync_engine_host.h.patch | 14 ---- ...omponents-sync-engine-sync_manager.h.patch | 8 +-- ...omponents-sync-engine_impl-commit.cc.patch | 4 +- ...-sync-engine_impl-cycle-sync_cycle.h.patch | 10 ++- ...-engine_impl-get_updates_processor.h.patch | 16 +---- ...ync-engine_impl-sync_manager_impl.cc.patch | 4 +- ...sync-engine_impl-sync_manager_impl.h.patch | 13 ---- ...ts-sync-engine_impl-sync_scheduler.h.patch | 13 ---- ...c-engine_impl-sync_scheduler_impl.cc.patch | 4 +- ...nc-engine_impl-sync_scheduler_impl.h.patch | 27 +------ ...components-sync-engine_impl-syncer.h.patch | 26 ++----- ...ync-engine_impl-syncer_proto_util.cc.patch | 20 ++++++ ...sync-engine_impl-syncer_proto_util.h.patch | 20 ------ .../components-sync_bookmarks-BUILD.gn.patch | 12 ---- ...okmarks-bookmark_change_processor.cc.patch | 31 +++----- ...ookmarks-bookmark_change_processor.h.patch | 13 ---- 48 files changed, 368 insertions(+), 433 deletions(-) delete mode 100644 chromium_src/components/sync/driver/glue/sync_engine_backend.h delete mode 100644 chromium_src/components/sync/driver/glue/sync_engine_impl.cc create mode 100644 chromium_src/components/sync/engine_impl/sync_scheduler_impl.h delete mode 100644 chromium_src/components/sync/engine_impl/syncer_proto_util.cc delete mode 100644 patches/components-sync-driver-glue-sync_engine_backend.h.patch delete mode 100644 patches/components-sync-engine-sync_engine_host.h.patch delete mode 100644 patches/components-sync-engine_impl-sync_manager_impl.h.patch delete mode 100644 patches/components-sync-engine_impl-sync_scheduler.h.patch create mode 100644 patches/components-sync-engine_impl-syncer_proto_util.cc.patch delete mode 100644 patches/components-sync-engine_impl-syncer_proto_util.h.patch delete mode 100644 patches/components-sync_bookmarks-BUILD.gn.patch delete mode 100644 patches/components-sync_bookmarks-bookmark_change_processor.h.patch diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index e4b83154a72e..2a3008439be2 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -3,10 +3,36 @@ * 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" + +class Profile; + +namespace { +std::unique_ptr BraveBuildServiceInstanceFor( + Profile* profile, + syncer::ProfileSyncService::InitParams init_params); +} // namespace + +#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" // NOLINT + #include "brave/components/brave_sync/buildflags/buildflags.h" #if BUILDFLAG(ENABLE_BRAVE_SYNC) #include "brave/components/brave_sync/brave_profile_sync_service.h" using brave_sync::BraveProfileSyncService; #endif -#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" // NOLINT + +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 diff --git a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc index 9d4d89c926ad..50f882ee352f 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc @@ -3,43 +3,70 @@ * 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/glue/sync_engine_backend.cc" // NOLINT - -#include "brave/chromium_src/components/sync/driver/glue/sync_engine_backend.h" - -#include #include +#include "base/memory/weak_ptr.h" +#include "brave/components/brave_sync/brave_profile_sync_service.h" #include "brave/components/brave_sync/jslib_messages.h" +#include "components/sync/driver/glue/sync_engine_impl.h" +#include "components/sync/engine/sync_engine_host.h" + +using brave_sync::BraveProfileSyncService; +using brave_sync::GetRecordsCallback; +using brave_sync::RecordsList; namespace syncer { -void SyncEngineBackend::OnNudgeSyncCycle( - brave_sync::RecordsListPtr records_list) { - host_.Call(FROM_HERE, - &SyncEngineImpl::HandleNudgeSyncCycle, - base::Passed(&records_list)); +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 SyncEngineBackend::OnPollSyncCycle(GetRecordsCallback cb, - base::WaitableEvent* wevent) { - host_.Call(FROM_HERE, - &SyncEngineImpl::HandlePollSyncCycle, cb, wevent); +void OnNudgeSyncCycle(WeakHandle sync_engine_impl, + brave_sync::RecordsListPtr records_list) { + sync_engine_impl.Call(FROM_HERE, + &OnNudgeSyncCycleOnOwnerThread, + base::Passed(&records_list)); } -void SyncEngineBackend::DoDispatchGetRecordsCallback( - GetRecordsCallback cb, std::unique_ptr records) { - cb.Run(std::move(records)); +void OnPollSyncCycleOnOwnerThread(base::WeakPtr sync_engine, + GetRecordsCallback cb, + base::WaitableEvent* wevent) { + if (sync_engine.get()) + static_cast( + BraveGetSyncEngineHost(sync_engine.get()))->OnPollSyncCycle(cb, wevent); } -void SyncEngineBackend::BraveInit(SyncManager::InitArgs* args) { +void OnPollSyncCycle(WeakHandle sync_engine_impl, + GetRecordsCallback cb, + base::WaitableEvent* wevent) { + sync_engine_impl.Call(FROM_HERE, + &OnPollSyncCycleOnOwnerThread, + cb, + wevent); +} + +void BraveInit(WeakHandle sync_engine_impl, + SyncManager::InitArgs* args) { DCHECK(args); args->nudge_sync_cycle_delegate_function = - base::BindRepeating(&SyncEngineBackend::OnNudgeSyncCycle, - weak_ptr_factory_.GetWeakPtr()); + base::BindRepeating(&OnNudgeSyncCycle, + sync_engine_impl); args->poll_sync_cycle_delegate_function = - base::BindRepeating(&SyncEngineBackend::OnPollSyncCycle, - weak_ptr_factory_.GetWeakPtr()); + base::BindRepeating(&OnPollSyncCycle, + sync_engine_impl); } } // 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_backend.h b/chromium_src/components/sync/driver/glue/sync_engine_backend.h deleted file mode 100644 index 0c3b12993f24..000000000000 --- a/chromium_src/components/sync/driver/glue/sync_engine_backend.h +++ /dev/null @@ -1,16 +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_BACKEND_H_ -#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_BACKEND_H_ - -#include "brave/components/brave_sync/jslib_messages_fwd.h" -namespace syncer { -using brave_sync::GetRecordsCallback; -using brave_sync::RecordsList; -} // namespace syncer -#include "../../../../../../components/sync/driver/glue/sync_engine_backend.h" - -#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_BACKEND_H_ // NOLINT diff --git a/chromium_src/components/sync/driver/glue/sync_engine_impl.cc b/chromium_src/components/sync/driver/glue/sync_engine_impl.cc deleted file mode 100644 index c7ff36d04f9d..000000000000 --- a/chromium_src/components/sync/driver/glue/sync_engine_impl.cc +++ /dev/null @@ -1,38 +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/glue/sync_engine_impl.cc" // NOLINT - -#include "brave/chromium_src/components/sync/driver/glue/sync_engine_impl.h" - -#include -#include - -#include "brave/components/brave_sync/jslib_messages.h" - -namespace syncer { - -void SyncEngineImpl::HandleNudgeSyncCycle( - brave_sync::RecordsListPtr records_list) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - host_->OnNudgeSyncCycle(std::move(records_list)); -} - -void SyncEngineImpl::HandlePollSyncCycle( - GetRecordsCallback cb, - base::WaitableEvent* wevent) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - host_->OnPollSyncCycle(cb, wevent); -} - -void SyncEngineImpl::DispatchGetRecordsCallback( - GetRecordsCallback cb, std::unique_ptr records) { - sync_task_runner_->PostTask( - FROM_HERE, - base::BindOnce(&SyncEngineBackend::DoDispatchGetRecordsCallback, backend_, - cb, std::move(records))); -} - -} // namespace syncer diff --git a/chromium_src/components/sync/driver/glue/sync_engine_impl.h b/chromium_src/components/sync/driver/glue/sync_engine_impl.h index ca10bc3f4e53..0753e382b7af 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_impl.h +++ b/chromium_src/components/sync/driver/glue/sync_engine_impl.h @@ -6,11 +6,9 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_IMPL_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_IMPL_H_ -#include "brave/components/brave_sync/jslib_messages_fwd.h" -namespace syncer { -using brave_sync::GetRecordsCallback; -using brave_sync::RecordsList; -} // namespace syncer -#include "../../../../../../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 16ce4b66acb4..9b632128d907 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -5,35 +5,67 @@ #include "brave/chromium_src/components/sync/driver/profile_sync_service.h" -// For use_transport_only_mode -#define IsSyncFeatureEnabled IsBraveSyncEnabled -#include "../../../../components/sync/driver/profile_sync_service.cc" // NOLINT +#include #include "base/bind.h" +#include "base/memory/weak_ptr.h" +#include "brave/components/brave_sync/brave_profile_sync_service.h" #include "brave/components/brave_sync/jslib_messages.h" #include "chrome/browser/sync/chrome_sync_client.h" #include "content/public/browser/browser_thread.h" +using brave_sync::BraveProfileSyncService; + namespace syncer { + const int64_t kBraveDefaultPollIntervalSeconds = 60; -void ProfileSyncService::BraveEngineParamsInit( +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(cb, wevent); + } +} + +void BraveInit( + base::WeakPtr profile_sync_service, + SyncPrefs* sync_prefs, syncer::SyncEngine::InitParams* params) { DCHECK(params); params->nudge_sync_cycle_delegate_function = - base::BindRepeating(&ProfileSyncService::OnNudgeSyncCycle, - sync_enabled_weak_factory_.GetWeakPtr()); + base::BindRepeating(&OnNudgeSyncCycle, + profile_sync_service); params->poll_sync_cycle_delegate_function = - base::BindRepeating(&ProfileSyncService::OnPollSyncCycle, - sync_enabled_weak_factory_.GetWeakPtr()); - - sync_prefs_.SetPollInterval( - base::TimeDelta::FromSeconds( - syncer::kBraveDefaultPollIntervalSeconds)); -} + base::BindRepeating(&OnPollSyncCycle, + profile_sync_service); -bool ProfileSyncService::IsBraveSyncEnabled() const { - return false; + sync_prefs->SetPollInterval( + base::TimeDelta::FromSeconds( + syncer::kBraveDefaultPollIntervalSeconds)); } } // namespace syncer + +// avoid redefining IsSyncFeatureEnabled in header +#include "components/sync/driver/sync_service.h" +// For use_transport_only_mode +#define IsSyncFeatureEnabled() IsBraveSyncEnabled(this) +#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 diff --git a/chromium_src/components/sync/driver/profile_sync_service.h b/chromium_src/components/sync/driver/profile_sync_service.h index 227d63477373..d099d3a4cf3a 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.h +++ b/chromium_src/components/sync/driver/profile_sync_service.h @@ -10,6 +10,10 @@ namespace brave_sync { class BraveProfileSyncService; } // namesapce brave_sync +#define BRAVE_PROFILE_SYNC_SERVICE_H \ +friend class brave_sync::BraveProfileSyncService; + #include "../../../../../components/sync/driver/profile_sync_service.h" +#undef BRAVE_PROFILE_SYNC_SERVICE_H #endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ diff --git a/chromium_src/components/sync/engine/sync_engine.h b/chromium_src/components/sync/engine/sync_engine.h index c18f8c7b41c6..92c28554e131 100644 --- a/chromium_src/components/sync/engine/sync_engine.h +++ b/chromium_src/components/sync/engine/sync_engine.h @@ -7,6 +7,12 @@ #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 index 137e988f3801..64ed58511a41 100644 --- a/chromium_src/components/sync/engine/sync_manager.h +++ b/chromium_src/components/sync/engine/sync_manager.h @@ -7,9 +7,16 @@ #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 index 1675b928a9a7..8929d0a101b7 100644 --- a/chromium_src/components/sync/engine_impl/commit.cc +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -20,7 +20,12 @@ SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message, } // 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_fwd.h" diff --git a/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h b/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h index 7a8c9c9a422e..61aa99fb8f2f 100644 --- a/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h +++ b/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h @@ -7,6 +7,12 @@ #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 index a094867ff2c3..9238359b09b6 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -16,6 +16,7 @@ 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/strings/string_number_conversions.h" diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.h b/chromium_src/components/sync/engine_impl/get_updates_processor.h index 2ef6e40fb3bd..b2815ffaac58 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.h +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.h @@ -7,9 +7,18 @@ #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_ // NOLINT diff --git a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc index 97ab7e4754b2..378a55c9c649 100644 --- a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc +++ b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc @@ -3,15 +3,15 @@ * 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_manager_impl.cc" // NOLINT -#include "brave/components/brave_sync/jslib_messages.h" +#include "components/sync/engine_impl/sync_scheduler_impl.h" -namespace syncer { +#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; -void SyncManagerImpl::BraveInit(InitArgs* args) { - DCHECK(args); - scheduler_->SetNudgeAndPollDelegate(args->nudge_sync_cycle_delegate_function, - args->poll_sync_cycle_delegate_function); -} - -} // namespace syncer +#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 index 5b22dc5e7f7a..dd4dc6e0357b 100644 --- a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc +++ b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc @@ -3,7 +3,7 @@ * 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.cc" // NOLINT +#include "components/sync/engine_impl/sync_scheduler_impl.h" #include "brave/components/brave_sync/jslib_messages.h" @@ -21,18 +21,12 @@ void SyncSchedulerImpl::OnPollSyncCycle(brave_sync::GetRecordsCallback cb, poll_sync_cycle_delegate_function_.Run(cb, wevent); } -void SyncSchedulerImpl::SetNudgeAndPollDelegate( - brave_sync::NudgeSyncCycleDelegate nudge_delegate, - brave_sync::PollSyncCycleDelegate poll_delegate) { - nudge_sync_cycle_delegate_function_ = nudge_delegate; - poll_sync_cycle_delegate_function_ = poll_delegate; -} +} // namespace syncer -void SyncSchedulerImpl::TryBraveSyncCycleJob() { - SyncCycle cycle(cycle_context_, this); - if (mode_ != CONFIGURATION_MODE) { - syncer_->DownloadBraveRecords(&cycle); +#define BRAVE_SYNC_SCHEDULER_IMPL_TRY_SYNC_CYCLE_JOB \ + SyncCycle cycle(cycle_context_, this); \ + if (mode_ != CONFIGURATION_MODE) { \ + syncer_->DownloadBraveRecords(&cycle); \ } -} -} // namespace syncer +#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 new file mode 100644 index 000000000000..f6aa4c585157 --- /dev/null +++ b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.h @@ -0,0 +1,24 @@ +/* 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 \ + public: \ + 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_ // NOLINT diff --git a/chromium_src/components/sync/engine_impl/syncer.cc b/chromium_src/components/sync/engine_impl/syncer.cc index ca196354eab9..6dc178b68085 100644 --- a/chromium_src/components/sync/engine_impl/syncer.cc +++ b/chromium_src/components/sync/engine_impl/syncer.cc @@ -23,7 +23,7 @@ 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::BindRepeating(&Syncer::OnGetRecords, AsWeakPtr()); + base::BindRepeating(&Syncer::OnGetRecords, AsWeakPtr()); base::WaitableEvent wevent; cycle->delegate()->OnPollSyncCycle(on_get_records, &wevent); // Make sure OnGetRecords will be the next task on sync thread diff --git a/chromium_src/components/sync/engine_impl/syncer.h b/chromium_src/components/sync/engine_impl/syncer.h index d7b0b1e999b7..ac6d4fa316c3 100644 --- a/chromium_src/components/sync/engine_impl/syncer.h +++ b/chromium_src/components/sync/engine_impl/syncer.h @@ -9,9 +9,15 @@ #include "base/memory/weak_ptr.h" #include "brave/components/brave_sync/jslib_messages.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" -namespace syncer { -class GetUpdatesProcessor; -} // namespace syncer + +#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/engine_impl/syncer_proto_util.cc b/chromium_src/components/sync/engine_impl/syncer_proto_util.cc deleted file mode 100644 index dd6a434fcec4..000000000000 --- a/chromium_src/components/sync/engine_impl/syncer_proto_util.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/engine_impl/syncer_proto_util.h" -#define AddRequiredFieldsToClientToServerMessage AddRequiredFieldsToClientToServerMessage_ChromiumImpl // NOLINT -#define PostClientToServerMessage PostClientToServerMessage_ChromiumImpl -#include "../../../../../components/sync/engine_impl/syncer_proto_util.cc" // NOLINT -#undef PostClientToServerMessage -#undef AddRequiredFieldsToClientToServerMessage - -namespace syncer { -namespace { -} // namespace - -// static -void SyncerProtoUtil::AddRequiredFieldsToClientToServerMessage( - const SyncCycle* cycle, - sync_pb::ClientToServerMessage* msg) {} - -// static -SyncerError SyncerProtoUtil::PostClientToServerMessage( - const ClientToServerMessage& msg, - ClientToServerResponse* response, - SyncCycle* cycle, - ModelTypeSet* partial_failure_data_types) { - return SyncerError(SyncerError::SYNCER_OK); -} - -} // namespace syncer diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index e0903b5aef78..20c0e8802c39 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -3,14 +3,22 @@ * 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_change_processor.h" + +#include "brave/components/brave_sync/syncer_helper.h" #include "components/bookmarks/browser/bookmark_model.h" +using bookmarks::BookmarkModel; +using bookmarks::BookmarkModelObserver; +using bookmarks::BookmarkNode; +using sync_bookmarks::BookmarkChangeProcessor; + namespace { class ScopedPauseObserver { public: - explicit ScopedPauseObserver(bookmarks::BookmarkModel* model, - bookmarks::BookmarkModelObserver* observer) : + explicit ScopedPauseObserver(BookmarkModel* model, + BookmarkModelObserver* observer) : model_(model), observer_(observer) { DCHECK_NE(observer_, nullptr); DCHECK_NE(model_, nullptr); @@ -21,18 +29,13 @@ class ScopedPauseObserver { } private: - bookmarks::BookmarkModel* model_; // Not owned - bookmarks::BookmarkModelObserver* observer_; + BookmarkModel* model_; // Not owned + BookmarkModelObserver* observer_; // Not owned }; -} // namespace - -#include "brave/components/brave_sync/syncer_helper.h" -#include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" // NOLINT - -namespace sync_bookmarks { - -bool BookmarkChangeProcessor::IsFirstLoadedFavicon(const BookmarkNode* node) { +bool IsFirstLoadedFavicon(BookmarkChangeProcessor* bookmark_change_processor, + BookmarkModel* bookmark_model, + const BookmarkNode* node) { // Avoid sending duplicate records right after applying CREATE records, // BookmarkChangeProcessor::SetBookmarkFavicon, put favicon data into database // BookmarkNode::favicon() and BookmarkNode::icon_url() are available only @@ -44,7 +47,7 @@ bool BookmarkChangeProcessor::IsFirstLoadedFavicon(const BookmarkNode* node) { if (node->GetMetaInfo("FirstLoadedFavicon", &FirstLoadedFavicon)) { if (!node->icon_url()) return true; - ScopedPauseObserver pause(bookmark_model_, this); + ScopedPauseObserver pause(bookmark_model, bookmark_change_processor); BookmarkNode* mutable_node = const_cast(node); mutable_node->DeleteMetaInfo("FirstLoadedFavicon"); return true; @@ -52,4 +55,28 @@ bool BookmarkChangeProcessor::IsFirstLoadedFavicon(const BookmarkNode* node) { return false; } -} // namespace sync_bookmarks +} // namespace + +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED \ + if (IsFirstLoadedFavicon(this, bookmark_model_, node)) return; + +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_1 \ + ScopedPauseObserver pause(bookmark_model_, this); \ + brave_sync::AddBraveMetaInfo(child, model, old_parent != new_parent); \ + SetSyncNodeMetaInfo(child, &sync_node); + +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_2 \ + BookmarkNodeChildrenReordered(model, new_parent); \ + if (old_parent != new_parent) \ + BookmarkNodeChildrenReordered(model, old_parent); + +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED \ + ScopedPauseObserver pause(bookmark_model_, this); \ + brave_sync::AddBraveMetaInfo(child, model, false); \ + SetSyncNodeMetaInfo(child, &sync_child); + +#include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" // NOLINT +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_1 +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_2 +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 97533092ac47..b0901d61c065 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -65,11 +65,12 @@ source_set("prefs") { ] } -source_set("syncer_export") { +source_set("export") { deps = [ ":jslib_messages", "buildflags", "//brave/common:switches", + "//brave/components/brave_sync:core", ] } diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service.cc index 29c80fd86223..9723b9cb622c 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service.cc @@ -176,6 +176,13 @@ void CreateResolveList( } } + +void DoDispatchGetRecordsCallback( + GetRecordsCallback cb, + std::unique_ptr records) { + cb.Run(std::move(records)); +} + } // namespace BraveProfileSyncService::BraveProfileSyncService(Profile* profile, @@ -225,6 +232,9 @@ BraveProfileSyncService::BraveProfileSyncService(Profile* profile, void BraveProfileSyncService::OnNudgeSyncCycle( RecordsListPtr records) { + if (!IsBraveSyncEnabled()) + return; + for (auto& record : *records) { record->deviceId = brave_sync_prefs_->GetThisDeviceId(); } @@ -532,7 +542,10 @@ void BraveProfileSyncService::OnResolvedSyncRecords( } else if (category_name == kBookmarks) { // Send records to syncer if (get_record_cb_) - engine_->DispatchGetRecordsCallback(get_record_cb_, std::move(records)); + sync_thread_->task_runner()->PostTask(FROM_HERE, + base::BindOnce(&DoDispatchGetRecordsCallback, + get_record_cb_, + std::move(records))); SignalWaitableEvent(); } else if (category_name == kHistorySites) { NOTIMPLEMENTED(); @@ -772,6 +785,9 @@ bool BraveProfileSyncService::IsBraveSyncConfigured() const { void BraveProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent) { + if (!IsBraveSyncEnabled()) + return; + if (IsTimeEmpty(brave_sync_prefs_->GetLastFetchTime())) SendCreateDevice(); brave_sync_client_->SendFetchSyncDevices(); diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 389222ec1e40..3058542af762 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -97,16 +97,15 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, BraveSyncClient* GetBraveSyncClient() override; #endif - bool IsBraveSyncEnabled() const override; + bool IsBraveSyncEnabled() const; bool IsBraveSyncInitialized() const; bool IsBraveSyncConfigured() const; syncer::ModelTypeSet GetPreferredDataTypes() const override; - // syncer::SyncEngineHost implementation - void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, - base::WaitableEvent* wevent) override; + base::WaitableEvent* wevent); private: FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkAdded); diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch index afeaf7707ccc..ce12ef69e3c2 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -1,16 +1,13 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc -index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..de1e275ac74060eefd9a340a5528e72cf9b4a931 100644 +index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..5a1093b9bb293fef38afba5dbcb5018cc8737ddd 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc -@@ -263,7 +263,11 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( +@@ -263,7 +263,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( } auto pss = -+#if BUILDFLAG(ENABLE_BRAVE_SYNC) -+ std::make_unique(profile, std::move(init_params)); -+#else - std::make_unique(std::move(init_params)); -+#endif +- std::make_unique(std::move(init_params)); ++ BraveBuildServiceInstanceFor(profile, std::move(init_params)); pss->Initialize(); return pss.release(); } diff --git a/patches/components-sync-BUILD.gn.patch b/patches/components-sync-BUILD.gn.patch index 1e9c91dc7651..ef42a8f51ecc 100644 --- a/patches/components-sync-BUILD.gn.patch +++ b/patches/components-sync-BUILD.gn.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/BUILD.gn b/components/sync/BUILD.gn -index 0606b7e68670877100114732174af25ad0b42f77..a95184ad1613aeca838ec51fc254509878d34f03 100644 +index 0606b7e68670877100114732174af25ad0b42f77..498f8bce320480b54fedd4bf8da1d4821f4cd276 100644 --- a/components/sync/BUILD.gn +++ b/components/sync/BUILD.gn @@ -99,6 +99,7 @@ jumbo_static_library("base") { ] deps = [ "//base:i18n", -+ "//brave/components/brave_sync:syncer_export", ++ "//brave/components/brave_sync:export", "//components/os_crypt", "//components/pref_registry", "//components/prefs", diff --git a/patches/components-sync-driver-data_type_manager_impl.cc.patch b/patches/components-sync-driver-data_type_manager_impl.cc.patch index 86e8c3946808..cf5ffc7f1c42 100644 --- a/patches/components-sync-driver-data_type_manager_impl.cc.patch +++ b/patches/components-sync-driver-data_type_manager_impl.cc.patch @@ -1,15 +1,13 @@ diff --git a/components/sync/driver/data_type_manager_impl.cc b/components/sync/driver/data_type_manager_impl.cc -index f19aeafebc707eaf703b0fa71bf1c2d80dba2596..2b0a2cfe99203e331dabb6ec741649b0af4bf0aa 100644 +index f19aeafebc707eaf703b0fa71bf1c2d80dba2596..2058e0122b7de1206baba6e65a52db9262e5d0e9 100644 --- a/components/sync/driver/data_type_manager_impl.cc +++ b/components/sync/driver/data_type_manager_impl.cc -@@ -542,8 +542,8 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( - types_to_download.PutAll(clean_types); +@@ -543,7 +543,7 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( types_to_download.RemoveAll(ProxyTypes()); types_to_download.RemoveAll(CommitOnlyTypes()); -- if (!types_to_download.Empty()) + if (!types_to_download.Empty()) - types_to_download.Put(NIGORI); -+ // if (!types_to_download.Empty()) -+ // types_to_download.Put(NIGORI); ++ ; // types_to_download.Put(NIGORI); // TODO(sync): crbug.com/137550. // It's dangerous to configure types that have progress markers. Types with diff --git a/patches/components-sync-driver-glue-sync_engine_backend.cc.patch b/patches/components-sync-driver-glue-sync_engine_backend.cc.patch index 0eca29264b48..dc12271d188f 100644 --- a/patches/components-sync-driver-glue-sync_engine_backend.cc.patch +++ b/patches/components-sync-driver-glue-sync_engine_backend.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/driver/glue/sync_engine_backend.cc b/components/sync/driver/glue/sync_engine_backend.cc -index 508c26a99ecb044bcca60f34ef4c787bb06fdc9f..7c88be6e419e2f981181a71f4031a8a564b56f59 100644 +index 508c26a99ecb044bcca60f34ef4c787bb06fdc9f..9be28df383a27491b8410dddb6c7af6385af0165 100644 --- a/components/sync/driver/glue/sync_engine_backend.cc +++ b/components/sync/driver/glue/sync_engine_backend.cc @@ -370,6 +370,7 @@ void SyncEngineBackend::DoInitialize(SyncEngine::InitParams params) { args.cache_guid = params.cache_guid; args.birthday = params.birthday; args.bag_of_chips = params.bag_of_chips; -+ BraveInit(&args); ++ BRAVE_SYNC_ENGINE_BACKEND_DO_INITIALIZE sync_manager_->Init(&args); base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( this, "SyncDirectory", base::ThreadTaskRunnerHandle::Get()); diff --git a/patches/components-sync-driver-glue-sync_engine_backend.h.patch b/patches/components-sync-driver-glue-sync_engine_backend.h.patch deleted file mode 100644 index 5cbaf9703e81..000000000000 --- a/patches/components-sync-driver-glue-sync_engine_backend.h.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff --git a/components/sync/driver/glue/sync_engine_backend.h b/components/sync/driver/glue/sync_engine_backend.h -index 8cc3e5305b1010e025dbaf8a23c6180813fa9ef8..2cb09e7a0dfc52c833f1b47f67a3625f45117590 100644 ---- a/components/sync/driver/glue/sync_engine_backend.h -+++ b/components/sync/driver/glue/sync_engine_backend.h -@@ -177,6 +177,11 @@ class SyncEngineBackend : public base::RefCountedThreadSafe, - - bool HasUnsyncedItemsForTest() const; - -+ void DoDispatchGetRecordsCallback(GetRecordsCallback cb, std::unique_ptr records); -+ void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ void OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent); -+ void BraveInit(SyncManager::InitArgs* args); -+ - private: - friend class base::RefCountedThreadSafe; - diff --git a/patches/components-sync-driver-glue-sync_engine_impl.h.patch b/patches/components-sync-driver-glue-sync_engine_impl.h.patch index d7bc83c0865b..988f6e913421 100644 --- a/patches/components-sync-driver-glue-sync_engine_impl.h.patch +++ b/patches/components-sync-driver-glue-sync_engine_impl.h.patch @@ -1,15 +1,12 @@ diff --git a/components/sync/driver/glue/sync_engine_impl.h b/components/sync/driver/glue/sync_engine_impl.h -index 9fce092e22ca630fa3f5efa0bc1e963a86659625..8663e3c7adebba9f631e42bd8cc966accab81e02 100644 +index 9fce092e22ca630fa3f5efa0bc1e963a86659625..7ca7b912f21558d76eafa9b392fec616b3f4056a 100644 --- a/components/sync/driver/glue/sync_engine_impl.h +++ b/components/sync/driver/glue/sync_engine_impl.h -@@ -102,6 +102,10 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { - std::string GetOwnerName() const override; - void OnInvalidatorClientIdChange(const std::string& client_id) override; +@@ -220,6 +220,7 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { + + base::WeakPtrFactory weak_ptr_factory_; + ++ BRAVE_SYNC_ENGINE_IMPL_H + DISALLOW_COPY_AND_ASSIGN(SyncEngineImpl); + }; -+ void HandleNudgeSyncCycle(brave_sync::RecordsListPtr records_list); -+ void HandlePollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent); -+ void DispatchGetRecordsCallback(GetRecordsCallback cb, std::unique_ptr records) override; -+ - protected: - // The types and functions below are protected so that test - // subclasses can use them. diff --git a/patches/components-sync-driver-profile_sync_service.cc.patch b/patches/components-sync-driver-profile_sync_service.cc.patch index acbd76bd6b8e..8f11b498c498 100644 --- a/patches/components-sync-driver-profile_sync_service.cc.patch +++ b/patches/components-sync-driver-profile_sync_service.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/driver/profile_sync_service.cc b/components/sync/driver/profile_sync_service.cc -index 3dc7667b7fc5a919f2025c53e040265927e6ea23..a0c7a38db6f26403988f3f8d14a8edb5ef7b8c30 100644 +index 3dc7667b7fc5a919f2025c53e040265927e6ea23..94c94eb599416bc8911865939cc2c4765da03ec3 100644 --- a/components/sync/driver/profile_sync_service.cc +++ b/components/sync/driver/profile_sync_service.cc @@ -458,6 +458,7 @@ void ProfileSyncService::StartUpSlowEngineComponents() { params.sync_user_agent = MakeUserAgentForSync(channel_); params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); params.authenticated_account_id = GetAuthenticatedAccountInfo().account_id; -+ if (IsBraveSyncEnabled()) BraveEngineParamsInit(¶ms); ++ BRAVE_PROFILE_SYNC_SERVICE_START_UP_SLOW_ENGINE_COMPONENTS DCHECK(!params.authenticated_account_id.empty() || IsLocalSyncEnabled()); if (!base::FeatureList::IsEnabled(switches::kSyncE2ELatencyMeasurement)) { invalidation::InvalidationService* invalidator = diff --git a/patches/components-sync-driver-profile_sync_service.h.patch b/patches/components-sync-driver-profile_sync_service.h.patch index 6e67cbbffcf1..0a1515aa4543 100644 --- a/patches/components-sync-driver-profile_sync_service.h.patch +++ b/patches/components-sync-driver-profile_sync_service.h.patch @@ -1,24 +1,12 @@ diff --git a/components/sync/driver/profile_sync_service.h b/components/sync/driver/profile_sync_service.h -index 3df5ee21f6ec37c5915607ec9196909c62545572..c7daf0437953e1b795f030cb5a3ccf560d9c1ba3 100644 +index 3df5ee21f6ec37c5915607ec9196909c62545572..1688bb856998a4883e71e6ba4a967d6a90a75078 100644 --- a/components/sync/driver/profile_sync_service.h +++ b/components/sync/driver/profile_sync_service.h -@@ -257,7 +257,10 @@ class ProfileSyncService : public SyncService, +@@ -500,6 +500,7 @@ class ProfileSyncService : public SyncService, - SyncClient* GetSyncClientForTest(); + base::WeakPtrFactory weak_factory_; -+ virtual bool IsBraveSyncEnabled() const; -+ - private: -+ friend class brave_sync::BraveProfileSyncService; - friend class TestProfileSyncService; ++ BRAVE_PROFILE_SYNC_SERVICE_H + DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); + }; - // Passed as an argument to StopImpl to control whether or not the sync -@@ -268,6 +271,8 @@ class ProfileSyncService : public SyncService, - CLEAR_DATA, - }; - -+ void BraveEngineParamsInit(syncer::SyncEngine::InitParams*); -+ - enum UnrecoverableErrorReason { - ERROR_REASON_UNSET, - ERROR_REASON_SYNCER, diff --git a/patches/components-sync-engine-sync_engine.h.patch b/patches/components-sync-engine-sync_engine.h.patch index e79e67bf61e9..7e1891f567ad 100644 --- a/patches/components-sync-engine-sync_engine.h.patch +++ b/patches/components-sync-engine-sync_engine.h.patch @@ -1,23 +1,12 @@ diff --git a/components/sync/engine/sync_engine.h b/components/sync/engine/sync_engine.h -index e4d2ab4d38f6fffd2929277be51ec618180e0086..2a74f799277bd6bdb56875daaef1edf107790e32 100644 +index e4d2ab4d38f6fffd2929277be51ec618180e0086..b0bbfcd58c55917c98a9ce0e36a15c68524339d0 100644 --- a/components/sync/engine/sync_engine.h +++ b/components/sync/engine/sync_engine.h -@@ -87,6 +87,9 @@ class SyncEngine : public ModelTypeConfigurer { +@@ -86,6 +86,7 @@ class SyncEngine : public ModelTypeConfigurer { + // Define the polling interval. Must not be zero. base::TimeDelta poll_interval; ++ BRAVE_SYNC_ENGINE_INIT_PARAMS_H -+ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; -+ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function; -+ private: DISALLOW_COPY_AND_ASSIGN(InitParams); - }; -@@ -199,6 +202,8 @@ class SyncEngine : public ModelTypeConfigurer { - virtual std::unique_ptr - GetNigoriControllerDelegate() = 0; - -+ virtual void DispatchGetRecordsCallback(brave_sync::GetRecordsCallback cb, std::unique_ptr records) {} -+ - private: - DISALLOW_COPY_AND_ASSIGN(SyncEngine); - }; diff --git a/patches/components-sync-engine-sync_engine_host.h.patch b/patches/components-sync-engine-sync_engine_host.h.patch deleted file mode 100644 index 84763492de4d..000000000000 --- a/patches/components-sync-engine-sync_engine_host.h.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/components/sync/engine/sync_engine_host.h b/components/sync/engine/sync_engine_host.h -index c345abb5d7da17554c4a55bcbedd716a9b9c8e0d..3049f6158b70f209871a38d30c3d94fab278a179 100644 ---- a/components/sync/engine/sync_engine_host.h -+++ b/components/sync/engine/sync_engine_host.h -@@ -87,6 +87,9 @@ class SyncEngineHost { - - // Called when the sync cycle returns there is an user actionable error. - virtual void OnActionableError(const SyncProtocolError& error) = 0; -+ -+ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) {} -+ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) {} - }; - - } // namespace syncer diff --git a/patches/components-sync-engine-sync_manager.h.patch b/patches/components-sync-engine-sync_manager.h.patch index 88a806744eda..7b8dd7dc2248 100644 --- a/patches/components-sync-engine-sync_manager.h.patch +++ b/patches/components-sync-engine-sync_manager.h.patch @@ -1,14 +1,12 @@ diff --git a/components/sync/engine/sync_manager.h b/components/sync/engine/sync_manager.h -index 8dfd2480f2a7483062fe57890fd442c9b420c5a0..ae26dd17fe9cbb12298f87ef81a398b9ac239912 100644 +index 8dfd2480f2a7483062fe57890fd442c9b420c5a0..f1ddf57794fa5ca12fd58b41b693fe3cf55520b3 100644 --- a/components/sync/engine/sync_manager.h +++ b/components/sync/engine/sync_manager.h -@@ -254,6 +254,9 @@ class SyncManager { +@@ -254,6 +254,7 @@ class SyncManager { std::string cache_guid; std::string birthday; std::string bag_of_chips; -+ -+ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function; -+ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function; ++ BRAVE_SYNC_MANAGER_INIT_ARGS_H }; // The state of sync the feature. If the user turned on sync explicitly, it diff --git a/patches/components-sync-engine_impl-commit.cc.patch b/patches/components-sync-engine_impl-commit.cc.patch index 751bb5663dcf..92e639bad9fa 100644 --- a/patches/components-sync-engine_impl-commit.cc.patch +++ b/patches/components-sync-engine_impl-commit.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/engine_impl/commit.cc b/components/sync/engine_impl/commit.cc -index 312f59cb0e7126d2c7d3059f3eef8819f993c523..f18e6269e050b2d0f099827095b28573fd7b5d68 100644 +index 312f59cb0e7126d2c7d3059f3eef8819f993c523..7db6e6d7bea2c14847425d44fc5f3a9bfcd372d5 100644 --- a/components/sync/engine_impl/commit.cc +++ b/components/sync/engine_impl/commit.cc @@ -133,6 +133,7 @@ SyncerError Commit::PostAndProcessResponse( sync_pb::ClientToServerResponse response; const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( message_, &response, cycle, nullptr); -+ PostBraveCommit(&message_, &response, cycle); ++ BRAVE_COMMIT_POST_AND_PROCESS_RESPONSE TRACE_EVENT_END0("sync", "PostCommit"); // TODO(rlarocque): Use result that includes errors captured later? diff --git a/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch b/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch index a3e0a05e9183..19818194d25e 100644 --- a/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch +++ b/patches/components-sync-engine_impl-cycle-sync_cycle.h.patch @@ -1,14 +1,12 @@ diff --git a/components/sync/engine_impl/cycle/sync_cycle.h b/components/sync/engine_impl/cycle/sync_cycle.h -index 0971b6014231f8046eca9202840acc6167960057..ccc08280b387952e0df44760672b0dc62d9a3059 100644 +index 0971b6014231f8046eca9202840acc6167960057..6f7adf18b33be49f18469026838cbd9ad64bb8c5 100644 --- a/components/sync/engine_impl/cycle/sync_cycle.h +++ b/components/sync/engine_impl/cycle/sync_cycle.h -@@ -80,6 +80,9 @@ class SyncCycle { +@@ -79,6 +79,7 @@ class SyncCycle { + // Called when server requests a migration. virtual void OnReceivedMigrationRequest(ModelTypeSet types) = 0; ++ BRAVE_SYNC_CYCLE_DELEGATE_H -+ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) {} -+ virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) {} -+ protected: virtual ~Delegate() {} - }; diff --git a/patches/components-sync-engine_impl-get_updates_processor.h.patch b/patches/components-sync-engine_impl-get_updates_processor.h.patch index 763613b80dc5..2382643845b6 100644 --- a/patches/components-sync-engine_impl-get_updates_processor.h.patch +++ b/patches/components-sync-engine_impl-get_updates_processor.h.patch @@ -1,22 +1,12 @@ diff --git a/components/sync/engine_impl/get_updates_processor.h b/components/sync/engine_impl/get_updates_processor.h -index c5560ec8113670c57f80245199031732f5795f23..8097b4954a8b9f595e2c1eb7447770dcd4437d39 100644 +index c5560ec8113670c57f80245199031732f5795f23..f883a3aa1251dab8cd2ae07c467cbe42a1ebd089 100644 --- a/components/sync/engine_impl/get_updates_processor.h +++ b/components/sync/engine_impl/get_updates_processor.h -@@ -49,6 +49,8 @@ class GetUpdatesProcessor { - void ApplyUpdates(const ModelTypeSet& gu_types, - StatusController* status_controller); - -+ void AddBraveRecords(std::unique_ptr records); -+ - private: - // Populates a GetUpdates request message with per-type information. - void PrepareGetUpdates(const ModelTypeSet& gu_types, -@@ -96,6 +98,8 @@ class GetUpdatesProcessor { +@@ -96,6 +96,7 @@ class GetUpdatesProcessor { const GetUpdatesDelegate& delegate_; -+ std::unique_ptr brave_records_; -+ ++ BRAVE_GET_UPDATES_PROCESSOR_H DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessor); }; diff --git a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch index f9ba4e9a2c76..259b13db1434 100644 --- a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch +++ b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync/engine_impl/sync_manager_impl.cc b/components/sync/engine_impl/sync_manager_impl.cc -index 60404b7479d5d5d23b13c2aa969133c927f34ecd..121487690c3279dfad941a8b7b85fbb6099faba3 100644 +index 60404b7479d5d5d23b13c2aa969133c927f34ecd..b0ebd1c63091279c4712dd7c98a1469fd05cfabb 100644 --- a/components/sync/engine_impl/sync_manager_impl.cc +++ b/components/sync/engine_impl/sync_manager_impl.cc @@ -359,8 +359,9 @@ void SyncManagerImpl::Init(InitArgs* args) { @@ -9,7 +9,7 @@ index 60404b7479d5d5d23b13c2aa969133c927f34ecd..121487690c3279dfad941a8b7b85fbb6 - args->enable_local_sync_backend); + true); -+ BraveInit(args); ++ BRAVE_SYNC_MANAGER_IMPL_INIT scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); initialized_ = true; diff --git a/patches/components-sync-engine_impl-sync_manager_impl.h.patch b/patches/components-sync-engine_impl-sync_manager_impl.h.patch deleted file mode 100644 index 2cdc7ab98783..000000000000 --- a/patches/components-sync-engine_impl-sync_manager_impl.h.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/components/sync/engine_impl/sync_manager_impl.h b/components/sync/engine_impl/sync_manager_impl.h -index 10c1a959d084e504f8bcf58b05c047bd6b5ca33d..2b8b6769ae84f10eae4f0b5f01e360282dd497df 100644 ---- a/components/sync/engine_impl/sync_manager_impl.h -+++ b/components/sync/engine_impl/sync_manager_impl.h -@@ -199,6 +199,8 @@ class SyncManagerImpl - - using NotificationInfoMap = std::map; - -+ void BraveInit(InitArgs* args); -+ - // Determine if the parents or predecessors differ between the old and new - // versions of an entry. Note that a node's index may change without its - // UNIQUE_POSITION changing if its sibling nodes were changed. To handle such diff --git a/patches/components-sync-engine_impl-sync_scheduler.h.patch b/patches/components-sync-engine_impl-sync_scheduler.h.patch deleted file mode 100644 index ea262edb8c85..000000000000 --- a/patches/components-sync-engine_impl-sync_scheduler.h.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/components/sync/engine_impl/sync_scheduler.h b/components/sync/engine_impl/sync_scheduler.h -index 5628c5b9c3139846cee938dd2ff882623a4e3e76..316d661b46e9f11c55195b78da3f535bca0b0ed7 100644 ---- a/components/sync/engine_impl/sync_scheduler.h -+++ b/components/sync/engine_impl/sync_scheduler.h -@@ -125,6 +125,8 @@ class SyncScheduler : public SyncCycle::Delegate { - // Called when the network layer detects a connection status change. - virtual void OnConnectionStatusChange( - network::mojom::ConnectionType type) = 0; -+ -+ virtual void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, brave_sync::PollSyncCycleDelegate) {} - }; - - } // namespace syncer diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch index 0462e2958f40..3f5b8d0e4d46 100644 --- a/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/engine_impl/sync_scheduler_impl.cc b/components/sync/engine_impl/sync_scheduler_impl.cc -index 217652eec756c9e4ff4bf7bd74a9cd481672ed1b..1f8066050f62b7d4bc882a5af2c24aec7b6999f2 100644 +index 217652eec756c9e4ff4bf7bd74a9cd481672ed1b..7e153a22dd363213f1a0091e295ec9f2d5120cea 100644 --- a/components/sync/engine_impl/sync_scheduler_impl.cc +++ b/components/sync/engine_impl/sync_scheduler_impl.cc @@ -660,6 +660,7 @@ void SyncSchedulerImpl::TryCanaryJob() { } void SyncSchedulerImpl::TrySyncCycleJob() { -+ TryBraveSyncCycleJob(); ++ BRAVE_SYNC_SCHEDULER_IMPL_TRY_SYNC_CYCLE_JOB // Post call to TrySyncCycleJobImpl on current sequence. Later request for // access token will be here. base::SequencedTaskRunnerHandle::Get()->PostTask( diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch index 7e300ba99e05..daa880d68cff 100644 --- a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch @@ -1,33 +1,12 @@ diff --git a/components/sync/engine_impl/sync_scheduler_impl.h b/components/sync/engine_impl/sync_scheduler_impl.h -index 4bab39098da187109f291f1c0ab03fd0cc34d326..db1bfdfcc4470f1aeb41ae7d37f02dd9271e25f9 100644 +index 4bab39098da187109f291f1c0ab03fd0cc34d326..c29568b405112bab3b74be98a8855d4b5817943c 100644 --- a/components/sync/engine_impl/sync_scheduler_impl.h +++ b/components/sync/engine_impl/sync_scheduler_impl.h -@@ -79,6 +79,10 @@ class SyncSchedulerImpl : public SyncScheduler { - void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override; - void OnReceivedMigrationRequest(ModelTypeSet types) override; - -+ void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; -+ void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) override; -+ void SetNudgeAndPollDelegate(brave_sync::NudgeSyncCycleDelegate, brave_sync::PollSyncCycleDelegate) override; -+ - bool IsGlobalThrottle() const; - bool IsGlobalBackoff() const; - -@@ -177,6 +181,7 @@ class SyncSchedulerImpl : public SyncScheduler { - // current thread. In the future it will request access token here. - void TrySyncCycleJob(); - void TrySyncCycleJobImpl(); -+ void TryBraveSyncCycleJob(); - - // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). - // This function is for global throttling. -@@ -281,6 +286,9 @@ class SyncSchedulerImpl : public SyncScheduler { +@@ -281,6 +281,7 @@ class SyncSchedulerImpl : public SyncScheduler { // Used to prevent changing nudge delays by the server in integration tests. bool force_short_nudge_delay_for_test_ = false; -+ brave_sync::NudgeSyncCycleDelegate nudge_sync_cycle_delegate_function_; -+ brave_sync::PollSyncCycleDelegate poll_sync_cycle_delegate_function_; -+ ++ BRAVE_SYNC_SCHEDULER_IMPL_H SEQUENCE_CHECKER(sequence_checker_); base::WeakPtrFactory weak_ptr_factory_; diff --git a/patches/components-sync-engine_impl-syncer.h.patch b/patches/components-sync-engine_impl-syncer.h.patch index cf0e35bdb86f..e7516cc19b69 100644 --- a/patches/components-sync-engine_impl-syncer.h.patch +++ b/patches/components-sync-engine_impl-syncer.h.patch @@ -1,5 +1,5 @@ diff --git a/components/sync/engine_impl/syncer.h b/components/sync/engine_impl/syncer.h -index 23b389eada81c850c3a8856678d046e599a060da..add8bd72373425029cef6cec03d1e5787afbc2c6 100644 +index 23b389eada81c850c3a8856678d046e599a060da..48654f4c09558ea4d0ac246ebe16178019b30a0e 100644 --- a/components/sync/engine_impl/syncer.h +++ b/components/sync/engine_impl/syncer.h @@ -32,7 +32,7 @@ class SyncCycle; @@ -11,23 +11,11 @@ index 23b389eada81c850c3a8856678d046e599a060da..add8bd72373425029cef6cec03d1e578 public: explicit Syncer(CancelationSignal* cancelation_signal); virtual ~Syncer(); -@@ -69,6 +69,8 @@ class Syncer { - // otherwise. - virtual bool PollSyncShare(ModelTypeSet request_types, SyncCycle* cycle); - -+ void DownloadBraveRecords(SyncCycle* cycle); -+ - private: - bool DownloadAndApplyUpdates(ModelTypeSet* request_types, - SyncCycle* cycle, -@@ -89,6 +91,10 @@ class Syncer { - bool HandleCycleEnd(SyncCycle* cycle, - sync_pb::SyncEnums::GetUpdatesOrigin origin); +@@ -94,6 +94,7 @@ class Syncer { + // Whether the syncer is in the middle of a sync attempt. + bool is_syncing_; -+ void OnGetRecords(std::unique_ptr records); -+ -+ std::unique_ptr brave_records_; -+ - CancelationSignal* const cancelation_signal_; ++ BRAVE_SYNCER_H + DISALLOW_COPY_AND_ASSIGN(Syncer); + }; - // Whether the syncer is in the middle of a sync attempt. diff --git a/patches/components-sync-engine_impl-syncer_proto_util.cc.patch b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch new file mode 100644 index 000000000000..a55502206df5 --- /dev/null +++ b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch @@ -0,0 +1,20 @@ +diff --git a/components/sync/engine_impl/syncer_proto_util.cc b/components/sync/engine_impl/syncer_proto_util.cc +index 6706d0225207d266b1ed74cc712462052b3180a6..0a15430c4ab9ec03b1e3a706de3dd7873da83389 100644 +--- a/components/sync/engine_impl/syncer_proto_util.cc ++++ b/components/sync/engine_impl/syncer_proto_util.cc +@@ -431,6 +431,7 @@ base::TimeDelta SyncerProtoUtil::GetThrottleDelay( + void SyncerProtoUtil::AddRequiredFieldsToClientToServerMessage( + const SyncCycle* cycle, + sync_pb::ClientToServerMessage* msg) { ++ return; + DCHECK(msg); + SetProtocolVersion(msg); + AddRequestBirthday(cycle->context()->directory(), msg); +@@ -447,6 +448,7 @@ SyncerError SyncerProtoUtil::PostClientToServerMessage( + ClientToServerResponse* response, + SyncCycle* cycle, + ModelTypeSet* partial_failure_data_types) { ++ return SyncerError(SyncerError::SYNCER_OK); + DCHECK(response); + DCHECK(msg.has_protocol_version()); + DCHECK(msg.has_store_birthday() || !IsBirthdayRequired(msg)); diff --git a/patches/components-sync-engine_impl-syncer_proto_util.h.patch b/patches/components-sync-engine_impl-syncer_proto_util.h.patch deleted file mode 100644 index 382a315a03db..000000000000 --- a/patches/components-sync-engine_impl-syncer_proto_util.h.patch +++ /dev/null @@ -1,20 +0,0 @@ -diff --git a/components/sync/engine_impl/syncer_proto_util.h b/components/sync/engine_impl/syncer_proto_util.h -index c48993057a9e87c0cc5c025fa2e8756e5d2940d9..09dc6b0f3fc6291708b4716c74f132871f4b3d23 100644 ---- a/components/sync/engine_impl/syncer_proto_util.h -+++ b/components/sync/engine_impl/syncer_proto_util.h -@@ -47,6 +47,7 @@ class SyncerProtoUtil { - static void AddRequiredFieldsToClientToServerMessage( - const SyncCycle* cycle, - sync_pb::ClientToServerMessage* msg); -+ static void AddRequiredFieldsToClientToServerMessage_ChromiumImpl(const SyncCycle*, sync_pb::ClientToServerMessage*); - - // Posts the given message and fills the buffer with the returned value. - // Returns true on success. Also handles store birthday verification: will -@@ -57,6 +58,7 @@ class SyncerProtoUtil { - sync_pb::ClientToServerResponse* response, - SyncCycle* cycle, - ModelTypeSet* partial_failure_data_types); -+ static SyncerError PostClientToServerMessage_ChromiumImpl(const sync_pb::ClientToServerMessage&, sync_pb::ClientToServerResponse*, SyncCycle*, ModelTypeSet*); - - // Specifies where entity's position should be updated from the data in - // GetUpdates message. diff --git a/patches/components-sync_bookmarks-BUILD.gn.patch b/patches/components-sync_bookmarks-BUILD.gn.patch deleted file mode 100644 index 9c00c7ff13f0..000000000000 --- a/patches/components-sync_bookmarks-BUILD.gn.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/sync_bookmarks/BUILD.gn b/components/sync_bookmarks/BUILD.gn -index 3b36cc46b0b67ecd5cd74a3467f1f19398216977..aeb80257436f05d2f864fe24eb18df26fb6e1a06 100644 ---- a/components/sync_bookmarks/BUILD.gn -+++ b/components/sync_bookmarks/BUILD.gn -@@ -32,6 +32,7 @@ static_library("sync_bookmarks") { - - deps = [ - "//base", -+ "//brave/components/brave_sync:core", - "//components/bookmarks/browser", - "//components/favicon/core", - "//components/history/core/browser", diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 2a7447e4bdfd..2cb0642170b5 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..81744cb05711149192d93d0a2e688cf706720248 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..a4ad75b23dd3537867ef4f7df2bf38a417c6054f 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -28,49 +28,40 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..81744cb05711149192d93d0a2e688cf7 } void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, -@@ -416,6 +419,10 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -415,6 +418,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, + error_handler()->OnUnrecoverableError(error); return; } ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_1 -+ ScopedPauseObserver pause(bookmark_model_, this); -+ brave_sync::AddBraveMetaInfo(child, model, old_parent != new_parent); -+ SetSyncNodeMetaInfo(child, &sync_node); -+ if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, model_associator_)) { - syncer::SyncError error(FROM_HERE, -@@ -429,6 +436,10 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -429,6 +433,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, UpdateTransactionVersion(new_version, model, std::vector(1, child)); -+ -+ BookmarkNodeChildrenReordered(model, new_parent); -+ if (old_parent != new_parent) -+ BookmarkNodeChildrenReordered(model, old_parent); ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_2 } void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( -@@ -458,6 +469,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( +@@ -458,6 +463,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( return; } -+ if (IsFirstLoadedFavicon(node)) return; ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED + CreateOrUpdateSyncNode(node); } -@@ -490,6 +503,10 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( +@@ -490,6 +497,7 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( DCHECK_EQ(sync_child.GetParentId(), model_associator_->GetSyncIdFromChromeId(node->id())); -+ ScopedPauseObserver pause(bookmark_model_, this); -+ brave_sync::AddBraveMetaInfo(child, model, false); -+ SetSyncNodeMetaInfo(child, &sync_child); -+ ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -718,10 +735,12 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -718,10 +726,12 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.h.patch b/patches/components-sync_bookmarks-bookmark_change_processor.h.patch deleted file mode 100644 index f2d179201854..000000000000 --- a/patches/components-sync_bookmarks-bookmark_change_processor.h.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/components/sync_bookmarks/bookmark_change_processor.h b/components/sync_bookmarks/bookmark_change_processor.h -index e11a2ddf641edc7098c06433fd22d86467e2aabf..9017b2b0ca991299af08e1341a35efd9a4f61253 100644 ---- a/components/sync_bookmarks/bookmark_change_processor.h -+++ b/components/sync_bookmarks/bookmark_change_processor.h -@@ -238,6 +238,8 @@ class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, - // Returns false if |node| should not be synced. - bool CanSyncNode(const bookmarks::BookmarkNode* node); - -+ bool IsFirstLoadedFavicon(const bookmarks::BookmarkNode* node); -+ - SEQUENCE_CHECKER(sequence_checker_); - - // The bookmark model we are processing changes from. Non-null when From f3f381c35e2984d38589feaa77231227a9d63f77 Mon Sep 17 00:00:00 2001 From: bridiver Date: Wed, 19 Jun 2019 08:40:10 -0700 Subject: [PATCH 41/73] add guards for ENABLE_BRAVE_SYNC --- .../sync/driver/glue/sync_engine_backend.cc | 12 ++++++++++-- .../components/sync/driver/profile_sync_service.cc | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc index 50f882ee352f..23b24a0310da 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc @@ -5,18 +5,23 @@ #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/brave_profile_sync_service.h" #include "brave/components/brave_sync/jslib_messages.h" -#include "components/sync/driver/glue/sync_engine_impl.h" -#include "components/sync/engine/sync_engine_host.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_; } @@ -52,9 +57,11 @@ void OnPollSyncCycle(WeakHandle sync_engine_impl, 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, @@ -62,6 +69,7 @@ void BraveInit(WeakHandle sync_engine_impl, args->poll_sync_cycle_delegate_function = base::BindRepeating(&OnPollSyncCycle, sync_engine_impl); +#endif } } // namespace syncer diff --git a/chromium_src/components/sync/driver/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc index 9b632128d907..e23b7417f596 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -7,6 +7,9 @@ #include +#include "brave/components/brave_sync/buildflags/buildflags.h" + +#if BUILDFLAG(ENABLE_BRAVE_SYNC) #include "base/bind.h" #include "base/memory/weak_ptr.h" #include "brave/components/brave_sync/brave_profile_sync_service.h" @@ -15,9 +18,11 @@ #include "content/public/browser/browser_thread.h" using brave_sync::BraveProfileSyncService; +#endif namespace syncer { +#if BUILDFLAG(ENABLE_BRAVE_SYNC) const int64_t kBraveDefaultPollIntervalSeconds = 60; bool IsBraveSyncEnabled(ProfileSyncService* profile_sync_service) { @@ -41,11 +46,13 @@ void OnPollSyncCycle(base::WeakPtr profile_sync_service, profile_sync_service.get())->OnPollSyncCycle(cb, wevent); } } +#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, @@ -57,6 +64,7 @@ void BraveInit( sync_prefs->SetPollInterval( base::TimeDelta::FromSeconds( syncer::kBraveDefaultPollIntervalSeconds)); +#endif } } // namespace syncer From f4a013bdc67941d0742d15cff4c1ac562bb8728e Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Thu, 20 Jun 2019 20:54:24 +0300 Subject: [PATCH 42/73] Fixed Linux build --- components/brave_sync/BUILD.gn | 1 + .../brave_sync/brave_profile_sync_service.h | 10 ++++--- .../brave_profile_sync_service_exports.h | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 components/brave_sync/brave_profile_sync_service_exports.h diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index b0901d61c065..39618291b5dd 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -7,6 +7,7 @@ import("//tools/grit/repack.gni") if (enable_brave_sync) { source_set("js_sync_lib_impl") { sources = [ + "brave_profile_sync_service_exports.h", "brave_profile_sync_service.cc", "brave_profile_sync_service.h", "client/brave_sync_client.h", diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service.h index 3058542af762..da17616af2bc 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service.h @@ -9,6 +9,7 @@ #include #include +#include "brave/components/brave_sync/brave_profile_sync_service_exports.h" #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" @@ -40,7 +41,8 @@ namespace prefs { class Prefs; } // namespace prefs -class BraveProfileSyncService : public syncer::ProfileSyncService, +class BraveProfileSyncService : public BraveProfileSyncServiceExports, + public syncer::ProfileSyncService, public BraveSyncService, public SyncMessageHandler { public: @@ -97,15 +99,15 @@ class BraveProfileSyncService : public syncer::ProfileSyncService, BraveSyncClient* GetBraveSyncClient() override; #endif - bool IsBraveSyncEnabled() const; + bool IsBraveSyncEnabled() const override; bool IsBraveSyncInitialized() const; bool IsBraveSyncConfigured() const; syncer::ModelTypeSet GetPreferredDataTypes() const override; - void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list); + void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) override; void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, - base::WaitableEvent* wevent); + base::WaitableEvent* wevent) override; private: FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkAdded); diff --git a/components/brave_sync/brave_profile_sync_service_exports.h b/components/brave_sync/brave_profile_sync_service_exports.h new file mode 100644 index 000000000000..d75b5b88310d --- /dev/null +++ b/components/brave_sync/brave_profile_sync_service_exports.h @@ -0,0 +1,27 @@ +/* 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_BRAVE_PROFILE_SYNC_SERVICE_EXPORTS_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_EXPORTS_H_ + +#include "brave/components/brave_sync/jslib_messages_fwd.h" + +namespace base { +class WaitableEvent; +} + +namespace brave_sync { + +class BraveProfileSyncServiceExports { + public: + virtual bool IsBraveSyncEnabled() const = 0; + virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) = 0; + virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, + base::WaitableEvent* wevent) = 0; +}; + +} // namespace brave_sync + +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_EXPORTS_H_ From 60d93e04d25dc3b4c4ea925e8a70409a91707639 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 25 Jun 2019 13:47:44 +0300 Subject: [PATCH 43/73] BraveProfileSyncService => BraveProfileSyncServiceImpl; BraveProfileSyncServiceExports => BraveProfileSyncService --- browser/extensions/api/brave_sync_api.cc | 51 ++++---- browser/ui/webui/sync/sync_ui.cc | 6 +- .../sync/profile_sync_service_factory.cc | 6 +- .../sync/driver/glue/sync_engine_backend.cc | 2 +- .../sync/driver/profile_sync_service.cc | 2 +- .../sync/driver/profile_sync_service.h | 4 +- components/brave_sync/BUILD.gn | 12 +- ....cc => brave_profile_sync_service_impl.cc} | 117 +++++++++--------- ...ce.h => brave_profile_sync_service_impl.h} | 20 +-- .../brave_sync/brave_sync_service_unittest.cc | 10 +- .../brave_profile_sync_service.h} | 17 ++- patches/components-sync-BUILD.gn.patch | 4 +- 12 files changed, 140 insertions(+), 111 deletions(-) rename components/brave_sync/{brave_profile_sync_service.cc => brave_profile_sync_service_impl.cc} (86%) rename components/brave_sync/{brave_profile_sync_service.h => brave_profile_sync_service_impl.h} (92%) rename components/brave_sync/{brave_profile_sync_service_exports.h => public/brave_profile_sync_service.h} (53%) diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index 63133f94ba88..bc41a1a02cc8 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -10,15 +10,17 @@ #include #include "brave/common/extensions/api/brave_sync.h" -#include "brave/components/brave_sync/brave_profile_sync_service.h" +#include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" #include "brave/components/brave_sync/client/client_ext_impl_data.h" +#include "brave/components/brave_sync/public/brave_profile_sync_service.h" #include "brave/components/brave_sync/values_conv.h" #include "brave/components/brave_sync/jslib_messages.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/profile_sync_service_factory.h" using brave_sync::BraveProfileSyncService; +using brave_sync::BraveSyncService; using content::BrowserContext; namespace extensions { @@ -33,14 +35,19 @@ BraveProfileSyncService* GetProfileSyncService( Profile::FromBrowserContext(browser_context))); } +BraveSyncService* GetSyncService( + BrowserContext* browser_context) { + return GetProfileSyncService(browser_context)->GetSyncService(); +} + } // namespace ExtensionFunction::ResponseAction BraveSyncGetInitDataFunction::Run() { std::unique_ptr params( brave_sync::GetInitData::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnGetInitData( params->sync_version); @@ -53,8 +60,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncSetupErrorFunction::Run() { brave_sync::SyncSetupError::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnSyncSetupError( params->error); @@ -67,8 +74,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncDebugFunction::Run() { brave_sync::SyncDebug::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnSyncDebug( params->message); @@ -81,8 +88,8 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { brave_sync::SaveInitData::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnSaveInitData( params->seed ? *params->seed : std::vector(), @@ -92,10 +99,10 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { } ExtensionFunction::ResponseAction BraveSyncSyncReadyFunction::Run() { - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); - sync_service->OnSyncReady(); + sync_service->GetBraveSyncClient()->sync_message_handler()->OnSyncReady(); return RespondNow(NoArguments()); } @@ -108,8 +115,8 @@ ExtensionFunction::ResponseAction BraveSyncGetExistingObjectsFunction::Run() { auto records = std::make_unique>(); ::brave_sync::ConvertSyncRecords(params->records, records.get()); - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler() ->OnGetExistingObjects( @@ -129,8 +136,8 @@ ExtensionFunction::ResponseAction BraveSyncResolvedSyncRecordsFunction::Run() { auto records = std::make_unique>(); ::brave_sync::ConvertSyncRecords(params->records, records.get()); - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler() ->OnResolvedSyncRecords(params->category_name, std::move(records)); @@ -144,8 +151,8 @@ BraveSyncSaveBookmarksBaseOrderFunction::Run() { brave_sync::SaveBookmarksBaseOrder::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler() ->OnSaveBookmarksBaseOrder(params->order); @@ -158,8 +165,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() { brave_sync::SyncWordsPrepared::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler() ->OnSyncWordsPrepared(params->words); @@ -169,8 +176,8 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() { ExtensionFunction::ResponseAction BraveSyncExtensionInitializedFunction::Run() { // Also inform sync client extension started - BraveProfileSyncService* sync_service = - GetProfileSyncService(browser_context()); + BraveSyncService* sync_service = + GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->OnExtensionInitialized(); diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index 1610c4bbb133..c95bb6f8f626 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -11,7 +11,7 @@ #include "base/bind.h" #include "base/memory/weak_ptr.h" #include "brave/common/webui_url_constants.h" -#include "brave/components/brave_sync/brave_profile_sync_service.h" +#include "brave/components/brave_sync/public/brave_profile_sync_service.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_resources.h" @@ -124,10 +124,12 @@ void SyncUIDOMHandler::RegisterMessages() { void SyncUIDOMHandler::Init() { Profile* profile = Profile::FromWebUI(web_ui()); - sync_service_ = + auto* profile_sync_service = static_cast( ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( profile)); + + sync_service_ = profile_sync_service->GetSyncService(); if (sync_service_) sync_service_->AddObserver(this); } diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index 2a3008439be2..e4d35a8a5fee 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -18,8 +18,8 @@ std::unique_ptr BraveBuildServiceInstanceFor( #include "brave/components/brave_sync/buildflags/buildflags.h" #if BUILDFLAG(ENABLE_BRAVE_SYNC) -#include "brave/components/brave_sync/brave_profile_sync_service.h" -using brave_sync::BraveProfileSyncService; +#include "brave/components/brave_sync/brave_profile_sync_service_impl.h" +using brave_sync::BraveProfileSyncServiceImpl; #endif namespace { @@ -28,7 +28,7 @@ std::unique_ptr BraveBuildServiceInstanceFor( Profile* profile, syncer::ProfileSyncService::InitParams init_params) { #if BUILDFLAG(ENABLE_BRAVE_SYNC) - return std::make_unique(profile, + return std::make_unique(profile, std::move(init_params)); #else return std::make_unique(std::move(init_params)); diff --git a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc index 23b24a0310da..af4af385032c 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc @@ -11,8 +11,8 @@ #if BUILDFLAG(ENABLE_BRAVE_SYNC) #include "base/memory/weak_ptr.h" -#include "brave/components/brave_sync/brave_profile_sync_service.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; diff --git a/chromium_src/components/sync/driver/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc index e23b7417f596..ec397d7bc4df 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -12,8 +12,8 @@ #if BUILDFLAG(ENABLE_BRAVE_SYNC) #include "base/bind.h" #include "base/memory/weak_ptr.h" -#include "brave/components/brave_sync/brave_profile_sync_service.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" diff --git a/chromium_src/components/sync/driver/profile_sync_service.h b/chromium_src/components/sync/driver/profile_sync_service.h index d099d3a4cf3a..1a150edfcd15 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.h +++ b/chromium_src/components/sync/driver/profile_sync_service.h @@ -7,11 +7,11 @@ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ namespace brave_sync { -class BraveProfileSyncService; +class BraveProfileSyncServiceImpl; } // namesapce brave_sync #define BRAVE_PROFILE_SYNC_SERVICE_H \ -friend class brave_sync::BraveProfileSyncService; +friend class brave_sync::BraveProfileSyncServiceImpl; #include "../../../../../components/sync/driver/profile_sync_service.h" #undef BRAVE_PROFILE_SYNC_SERVICE_H diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 39618291b5dd..05b778b58c6d 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -7,9 +7,8 @@ import("//tools/grit/repack.gni") if (enable_brave_sync) { source_set("js_sync_lib_impl") { sources = [ - "brave_profile_sync_service_exports.h", - "brave_profile_sync_service.cc", - "brave_profile_sync_service.h", + "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", @@ -20,6 +19,7 @@ if (enable_brave_sync) { ] deps = [ + ":public", "//base", "//components/prefs", "//components/bookmarks/browser", @@ -66,7 +66,11 @@ source_set("prefs") { ] } -source_set("export") { +source_set("public") { + sources = [ + "public/brave_profile_sync_service.h", + ] + deps = [ ":jslib_messages", "buildflags", diff --git a/components/brave_sync/brave_profile_sync_service.cc b/components/brave_sync/brave_profile_sync_service_impl.cc similarity index 86% rename from components/brave_sync/brave_profile_sync_service.cc rename to components/brave_sync/brave_profile_sync_service_impl.cc index 9723b9cb622c..32efaac0ab50 100644 --- a/components/brave_sync/brave_profile_sync_service.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -3,7 +3,7 @@ * 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.h" +#include "brave/components/brave_sync/brave_profile_sync_service_impl.h" #include #include @@ -185,9 +185,9 @@ void DoDispatchGetRecordsCallback( } // namespace -BraveProfileSyncService::BraveProfileSyncService(Profile* profile, +BraveProfileSyncServiceImpl::BraveProfileSyncServiceImpl(Profile* profile, InitParams init_params) : - syncer::ProfileSyncService(std::move(init_params)), + BraveProfileSyncService(std::move(init_params)), brave_sync_client_(BraveSyncClient::Create(this, profile)) { brave_sync_words_ = std::string(); brave_sync_prefs_ = @@ -197,27 +197,27 @@ BraveProfileSyncService::BraveProfileSyncService(Profile* profile, brave_pref_change_registrar_.Init(sync_client_->GetPrefService()); brave_pref_change_registrar_.Add( prefs::kSyncEnabled, - base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Bind(&BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged, base::Unretained(this))); brave_pref_change_registrar_.Add( prefs::kSyncDeviceName, - base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Bind(&BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged, base::Unretained(this))); brave_pref_change_registrar_.Add( prefs::kSyncDeviceList, - base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Bind(&BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged, base::Unretained(this))); brave_pref_change_registrar_.Add( prefs::kSyncBookmarksEnabled, - base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Bind(&BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged, base::Unretained(this))); brave_pref_change_registrar_.Add( prefs::kSyncSiteSettingsEnabled, - base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Bind(&BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged, base::Unretained(this))); brave_pref_change_registrar_.Add( prefs::kSyncHistoryEnabled, - base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Bind(&BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged, base::Unretained(this))); // TODO(darkdh): find another way to obtain bookmark model // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 @@ -230,7 +230,7 @@ BraveProfileSyncService::BraveProfileSyncService(Profile* profile, } } -void BraveProfileSyncService::OnNudgeSyncCycle( +void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( RecordsListPtr records) { if (!IsBraveSyncEnabled()) return; @@ -243,9 +243,9 @@ void BraveProfileSyncService::OnNudgeSyncCycle( jslib_const::SyncRecordType_BOOKMARKS, *records); } -BraveProfileSyncService::~BraveProfileSyncService() {} +BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() {} -void BraveProfileSyncService::OnSetupSyncHaveCode(const std::string& sync_words, +void BraveProfileSyncServiceImpl::OnSetupSyncHaveCode(const std::string& sync_words, const std::string& device_name) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); if (sync_words.empty()) { @@ -273,7 +273,7 @@ void BraveProfileSyncService::OnSetupSyncHaveCode(const std::string& sync_words, brave_sync_words_ = sync_words; } -void BraveProfileSyncService::OnSetupSyncNewToSync( +void BraveProfileSyncServiceImpl::OnSetupSyncNewToSync( const std::string& device_name) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); @@ -301,7 +301,7 @@ void BraveProfileSyncService::OnSetupSyncNewToSync( brave_sync_prefs_->SetSyncEnabled(true); } -void BraveProfileSyncService::OnDeleteDevice(const std::string& device_id) { +void BraveProfileSyncServiceImpl::OnDeleteDevice(const std::string& device_id) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); auto sync_devices = brave_sync_prefs_->GetSyncDevices(); @@ -314,7 +314,7 @@ void BraveProfileSyncService::OnDeleteDevice(const std::string& device_id) { } } -void BraveProfileSyncService::OnResetSync() { +void BraveProfileSyncServiceImpl::OnResetSync() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); auto sync_devices = brave_sync_prefs_->GetSyncDevices(); @@ -330,7 +330,7 @@ void BraveProfileSyncService::OnResetSync() { } } -void BraveProfileSyncService::GetSettingsAndDevices( +void BraveProfileSyncServiceImpl::GetSettingsAndDevices( const GetSettingsAndDevicesCallback& callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); auto settings = brave_sync_prefs_->GetBraveSyncSettings(); @@ -338,23 +338,23 @@ void BraveProfileSyncService::GetSettingsAndDevices( callback.Run(std::move(settings), std::move(devices)); } -void BraveProfileSyncService::GetSyncWords() { +void BraveProfileSyncServiceImpl::GetSyncWords() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); // Ask sync client std::string seed = brave_sync_prefs_->GetSeed(); brave_sync_client_->NeedSyncWords(seed); } -std::string BraveProfileSyncService::GetSeed() { +std::string BraveProfileSyncServiceImpl::GetSeed() { return brave_sync_prefs_->GetSeed(); } -void BraveProfileSyncService::OnSetSyncEnabled(const bool sync_this_device) { +void BraveProfileSyncServiceImpl::OnSetSyncEnabled(const bool sync_this_device) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); brave_sync_prefs_->SetSyncEnabled(sync_this_device); } -void BraveProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { +void BraveProfileSyncServiceImpl::OnSetSyncBookmarks(const bool sync_bookmarks) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); syncer::UserSelectableTypeSet type_set = ProfileSyncService::GetUserSettings()->GetSelectedTypes(); @@ -367,27 +367,27 @@ void BraveProfileSyncService::OnSetSyncBookmarks(const bool sync_bookmarks) { brave_sync_prefs_->SetSyncBookmarksEnabled(sync_bookmarks); } -void BraveProfileSyncService::OnSetSyncBrowsingHistory( +void BraveProfileSyncServiceImpl::OnSetSyncBrowsingHistory( const bool sync_browsing_history) { brave_sync_prefs_->SetSyncHistoryEnabled(sync_browsing_history); } -void BraveProfileSyncService::OnSetSyncSavedSiteSettings( +void BraveProfileSyncServiceImpl::OnSetSyncSavedSiteSettings( const bool sync_saved_site_settings) { brave_sync_prefs_->SetSyncSiteSettingsEnabled(sync_saved_site_settings); } -void BraveProfileSyncService::BackgroundSyncStarted(bool startup) { +void BraveProfileSyncServiceImpl::BackgroundSyncStarted(bool startup) { } -void BraveProfileSyncService::BackgroundSyncStopped(bool shutdown) { +void BraveProfileSyncServiceImpl::BackgroundSyncStopped(bool shutdown) { } -void BraveProfileSyncService::OnSyncDebug(const std::string& message) { +void BraveProfileSyncServiceImpl::OnSyncDebug(const std::string& message) { NotifyLogMessage(message); } -void BraveProfileSyncService::OnSyncSetupError(const std::string& error) { +void BraveProfileSyncServiceImpl::OnSyncSetupError(const std::string& error) { if (brave_sync_initializing_) { brave_sync_prefs_->Clear(); brave_sync_initializing_ = false; @@ -395,7 +395,7 @@ void BraveProfileSyncService::OnSyncSetupError(const std::string& error) { NotifySyncSetupError(error); } -void BraveProfileSyncService::OnGetInitData(const std::string& sync_version) { +void BraveProfileSyncServiceImpl::OnGetInitData(const std::string& sync_version) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); Uint8Array seed; @@ -431,7 +431,7 @@ void BraveProfileSyncService::OnGetInitData(const std::string& sync_version) { brave_sync_words_); } -void BraveProfileSyncService::OnSaveInitData(const Uint8Array& seed, +void BraveProfileSyncServiceImpl::OnSaveInitData(const Uint8Array& seed, const Uint8Array& device_id) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(!brave_sync_initialized_); @@ -470,7 +470,7 @@ void BraveProfileSyncService::OnSaveInitData(const Uint8Array& seed, brave_sync_initializing_ = false; } -void BraveProfileSyncService::OnSyncReady() { +void BraveProfileSyncServiceImpl::OnSyncReady() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); const std::string bookmarks_base_order = brave_sync_prefs_->GetBookmarksBaseOrder(); @@ -501,7 +501,7 @@ void BraveProfileSyncService::OnSyncReady() { } } -syncer::ModelTypeSet BraveProfileSyncService::GetPreferredDataTypes() const { +syncer::ModelTypeSet BraveProfileSyncServiceImpl::GetPreferredDataTypes() const { // Force DEVICE_INFO type to have nudge cycle each time to fetch // Brave sync devices. // Will be picked up by ProfileSyncService::ConfigureDataTypeManager @@ -509,7 +509,7 @@ syncer::ModelTypeSet BraveProfileSyncService::GetPreferredDataTypes() const { { syncer::DEVICE_INFO }); } -void BraveProfileSyncService::OnGetExistingObjects( +void BraveProfileSyncServiceImpl::OnGetExistingObjects( const std::string& category_name, std::unique_ptr records, const base::Time &last_record_time_stamp, @@ -533,7 +533,7 @@ void BraveProfileSyncService::OnGetExistingObjects( } } -void BraveProfileSyncService::OnResolvedSyncRecords( +void BraveProfileSyncServiceImpl::OnResolvedSyncRecords( const std::string& category_name, std::unique_ptr records) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); @@ -552,15 +552,15 @@ void BraveProfileSyncService::OnResolvedSyncRecords( } } -void BraveProfileSyncService::OnDeletedSyncUser() { +void BraveProfileSyncServiceImpl::OnDeletedSyncUser() { NOTIMPLEMENTED(); } -void BraveProfileSyncService::OnDeleteSyncSiteSettings() { +void BraveProfileSyncServiceImpl::OnDeleteSyncSiteSettings() { NOTIMPLEMENTED(); } -void BraveProfileSyncService::OnSaveBookmarksBaseOrder( +void BraveProfileSyncServiceImpl::OnSaveBookmarksBaseOrder( const std::string& order) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(!order.empty()); @@ -568,11 +568,11 @@ void BraveProfileSyncService::OnSaveBookmarksBaseOrder( OnSyncReady(); } -void BraveProfileSyncService::OnSyncWordsPrepared(const std::string& words) { +void BraveProfileSyncServiceImpl::OnSyncWordsPrepared(const std::string& words) { NotifyHaveSyncWords(words); } -int BraveProfileSyncService::GetDisableReasons() const { +int BraveProfileSyncServiceImpl::GetDisableReasons() const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // legacy sync only support bookmark sync so we have to wait for migration @@ -584,39 +584,39 @@ int BraveProfileSyncService::GetDisableReasons() const { return ProfileSyncService::GetDisableReasons(); } -CoreAccountInfo BraveProfileSyncService::GetAuthenticatedAccountInfo() const { +CoreAccountInfo BraveProfileSyncServiceImpl::GetAuthenticatedAccountInfo() const { return GetDummyAccountInfo(); } -bool BraveProfileSyncService::IsAuthenticatedAccountPrimary() const { +bool BraveProfileSyncServiceImpl::IsAuthenticatedAccountPrimary() const { return true; } -void BraveProfileSyncService::Shutdown() { +void BraveProfileSyncServiceImpl::Shutdown() { SignalWaitableEvent(); syncer::ProfileSyncService::Shutdown(); } -void BraveProfileSyncService::NotifySyncSetupError(const std::string& error) { +void BraveProfileSyncServiceImpl::NotifySyncSetupError(const std::string& error) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); for (auto& observer : BraveSyncService::observers_) observer.OnSyncSetupError(this, error); } -void BraveProfileSyncService::NotifySyncStateChanged() { +void BraveProfileSyncServiceImpl::NotifySyncStateChanged() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); for (auto& observer : BraveSyncService::observers_) observer.OnSyncStateChanged(this); } -void BraveProfileSyncService::NotifyHaveSyncWords( +void BraveProfileSyncServiceImpl::NotifyHaveSyncWords( const std::string& sync_words) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); for (auto& observer : BraveSyncService::observers_) observer.OnHaveSyncWords(this, sync_words); } -void BraveProfileSyncService::ResetSyncInternal() { +void BraveProfileSyncServiceImpl::ResetSyncInternal() { brave_sync_prefs_->SetPrevSeed(brave_sync_prefs_->GetSeed()); brave_sync_prefs_->Clear(); @@ -627,7 +627,7 @@ void BraveProfileSyncService::ResetSyncInternal() { brave_sync_prefs_->SetSyncEnabled(false); } -void BraveProfileSyncService::SetPermanentNodesOrder( +void BraveProfileSyncServiceImpl::SetPermanentNodesOrder( const std::string& base_order) { DCHECK(model_); DCHECK(!base_order.empty()); @@ -646,7 +646,7 @@ void BraveProfileSyncService::SetPermanentNodesOrder( } -void BraveProfileSyncService::FetchSyncRecords(const bool bookmarks, +void BraveProfileSyncServiceImpl::FetchSyncRecords(const bool bookmarks, const bool history, const bool preferences, int max_records) { @@ -676,7 +676,7 @@ void BraveProfileSyncService::FetchSyncRecords(const bool bookmarks, max_records); } -void BraveProfileSyncService::SendCreateDevice() { +void BraveProfileSyncServiceImpl::SendCreateDevice() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); std::string device_name = brave_sync_prefs_->GetThisDeviceName(); @@ -691,7 +691,7 @@ void BraveProfileSyncService::SendCreateDevice() { object_id); } -void BraveProfileSyncService::SendDeviceSyncRecord( +void BraveProfileSyncServiceImpl::SendDeviceSyncRecord( const int action, const std::string& device_name, const std::string& device_id, @@ -706,7 +706,7 @@ void BraveProfileSyncService::SendDeviceSyncRecord( SyncRecordType_PREFERENCES, *records); } -void BraveProfileSyncService::OnResolvedPreferences( +void BraveProfileSyncServiceImpl::OnResolvedPreferences( const RecordsList& records) { const std::string this_device_id = brave_sync_prefs_->GetThisDeviceId(); bool this_device_deleted = false; @@ -753,7 +753,7 @@ void BraveProfileSyncService::OnResolvedPreferences( } } -void BraveProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { +void BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged(const std::string& pref) { if (pref == prefs::kSyncEnabled) { brave_sync_client_->OnSyncEnabledChanged(); if (!brave_sync_prefs_->GetSyncEnabled()) { @@ -765,25 +765,25 @@ void BraveProfileSyncService::OnBraveSyncPrefsChanged(const std::string& pref) { } #if BUILDFLAG(ENABLE_EXTENSIONS) -BraveSyncClient* BraveProfileSyncService::GetBraveSyncClient() { +BraveSyncClient* BraveProfileSyncServiceImpl::GetBraveSyncClient() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); return brave_sync_client_.get(); } #endif -bool BraveProfileSyncService::IsBraveSyncEnabled() const { +bool BraveProfileSyncServiceImpl::IsBraveSyncEnabled() const { return brave_sync_prefs_->GetSyncEnabled(); } -bool BraveProfileSyncService::IsBraveSyncInitialized() const { +bool BraveProfileSyncServiceImpl::IsBraveSyncInitialized() const { return brave_sync_initialized_; } -bool BraveProfileSyncService::IsBraveSyncConfigured() const { +bool BraveProfileSyncServiceImpl::IsBraveSyncConfigured() const { return brave_sync_configured_; } -void BraveProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, +void BraveProfileSyncServiceImpl::OnPollSyncCycle(GetRecordsCallback cb, base::WaitableEvent* wevent) { if (!IsBraveSyncEnabled()) return; @@ -806,11 +806,16 @@ void BraveProfileSyncService::OnPollSyncCycle(GetRecordsCallback cb, FetchSyncRecords(bookmarks, history, preferences, 1000); } -void BraveProfileSyncService::SignalWaitableEvent() { +void BraveProfileSyncServiceImpl::SignalWaitableEvent() { if (wevent_) { wevent_->Signal(); wevent_ = nullptr; } } +BraveSyncService* BraveProfileSyncServiceImpl::GetSyncService() const { + return static_cast( + const_cast(this)); +} + } // namespace brave_sync diff --git a/components/brave_sync/brave_profile_sync_service.h b/components/brave_sync/brave_profile_sync_service_impl.h similarity index 92% rename from components/brave_sync/brave_profile_sync_service.h rename to components/brave_sync/brave_profile_sync_service_impl.h index da17616af2bc..e7dd54732ad2 100644 --- a/components/brave_sync/brave_profile_sync_service.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -3,16 +3,16 @@ * 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_BRAVE_PROFILE_SYNC_SERVICE_H_ -#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_IMPL_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_IMPL_H_ #include #include -#include "brave/components/brave_sync/brave_profile_sync_service_exports.h" #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" +#include "brave/components/brave_sync/public/brave_profile_sync_service.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/sync/driver/profile_sync_service.h" @@ -41,14 +41,14 @@ namespace prefs { class Prefs; } // namespace prefs -class BraveProfileSyncService : public BraveProfileSyncServiceExports, - public syncer::ProfileSyncService, +class BraveProfileSyncServiceImpl : public BraveProfileSyncService, + //public syncer::ProfileSyncService, public BraveSyncService, public SyncMessageHandler { public: - explicit BraveProfileSyncService(Profile* profile, InitParams init_params); + explicit BraveProfileSyncServiceImpl(Profile* profile, InitParams init_params); - ~BraveProfileSyncService() override; + ~BraveProfileSyncServiceImpl() override; // BraveSyncService implementation void OnSetupSyncHaveCode(const std::string& sync_words, @@ -109,6 +109,8 @@ class BraveProfileSyncService : public BraveProfileSyncServiceExports, void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) override; + BraveSyncService* GetSyncService() const override; + private: FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkAdded); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, BookmarkDeleted); @@ -175,8 +177,8 @@ class BraveProfileSyncService : public BraveProfileSyncServiceExports, // this object was created on. SEQUENCE_CHECKER(sequence_checker_); - DISALLOW_COPY_AND_ASSIGN(BraveProfileSyncService); + DISALLOW_COPY_AND_ASSIGN(BraveProfileSyncServiceImpl); }; } // namespace brave_sync -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_H_ +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_IMPL_H_ diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 8510fb0ff6cf..72256a8c8e52 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -9,7 +9,7 @@ #include "base/strings/utf_string_conversions.h" #include "brave/components/brave_sync/client/brave_sync_client_impl.h" #include "brave/components/brave_sync/client/client_ext_impl_data.h" -#include "brave/components/brave_sync/brave_profile_sync_service.h" +#include "brave/components/brave_sync/brave_profile_sync_service_impl.h" #include "brave/components/brave_sync/brave_sync_prefs.h" #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/brave_sync_service_observer.h" @@ -93,7 +93,7 @@ using bookmarks::BookmarkModel; using brave_sync::BraveSyncService; -using brave_sync::BraveProfileSyncService; +using brave_sync::BraveProfileSyncServiceImpl; using brave_sync::BraveSyncServiceObserver; using brave_sync::jslib::SyncRecord; using brave_sync::MockBraveSyncClient; @@ -165,7 +165,7 @@ class BraveSyncServiceTest : public testing::Test { sync_client_ = new MockBraveSyncClient(); brave_sync::BraveSyncClientImpl::set_for_testing(sync_client_); - sync_service_ = static_cast( + sync_service_ = static_cast( ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( profile())); @@ -185,7 +185,7 @@ class BraveSyncServiceTest : public testing::Test { } Profile* profile() { return profile_.get(); } - BraveProfileSyncService* sync_service() { return sync_service_; } + BraveProfileSyncServiceImpl* sync_service() { return sync_service_; } MockBraveSyncClient* sync_client() { return sync_client_; } BookmarkModel* model() { return model_; } MockBraveSyncServiceObserver* observer() { return observer_.get(); } @@ -203,7 +203,7 @@ class BraveSyncServiceTest : public testing::Test { content::TestBrowserThreadBundle thread_bundle_; std::unique_ptr profile_; - BraveProfileSyncService* sync_service_; + BraveProfileSyncServiceImpl* sync_service_; MockBraveSyncClient* sync_client_; BookmarkModel* model_; // Not owns std::unique_ptr sync_prefs_; diff --git a/components/brave_sync/brave_profile_sync_service_exports.h b/components/brave_sync/public/brave_profile_sync_service.h similarity index 53% rename from components/brave_sync/brave_profile_sync_service_exports.h rename to components/brave_sync/public/brave_profile_sync_service.h index d75b5b88310d..a233527f8cd9 100644 --- a/components/brave_sync/brave_profile_sync_service_exports.h +++ b/components/brave_sync/public/brave_profile_sync_service.h @@ -3,10 +3,11 @@ * 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_BRAVE_PROFILE_SYNC_SERVICE_EXPORTS_H_ -#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_EXPORTS_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_SYNC_PUBLIC_BRAVE_PROFILE_SYNC_SERVICE_H_ +#define BRAVE_COMPONENTS_BRAVE_SYNC_PUBLIC_BRAVE_PROFILE_SYNC_SERVICE_H_ #include "brave/components/brave_sync/jslib_messages_fwd.h" +#include "components/sync/driver/profile_sync_service.h" namespace base { class WaitableEvent; @@ -14,14 +15,22 @@ class WaitableEvent; namespace brave_sync { -class BraveProfileSyncServiceExports { +class BraveSyncService; + +class BraveProfileSyncService : public syncer::ProfileSyncService { public: + BraveProfileSyncService(InitParams init_params) : + syncer::ProfileSyncService(std::move(init_params)) {} + ~BraveProfileSyncService() override {} + virtual bool IsBraveSyncEnabled() const = 0; virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) = 0; virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) = 0; + + virtual BraveSyncService* GetSyncService() const = 0; }; } // namespace brave_sync -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_EXPORTS_H_ +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_PUBLIC_BRAVE_PROFILE_SYNC_SERVICE_H_ diff --git a/patches/components-sync-BUILD.gn.patch b/patches/components-sync-BUILD.gn.patch index ef42a8f51ecc..ccc7f5b7137e 100644 --- a/patches/components-sync-BUILD.gn.patch +++ b/patches/components-sync-BUILD.gn.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/BUILD.gn b/components/sync/BUILD.gn -index 0606b7e68670877100114732174af25ad0b42f77..498f8bce320480b54fedd4bf8da1d4821f4cd276 100644 +index 0606b7e68670877100114732174af25ad0b42f77..71e92c712f6ec388c0ab6cb8a92e03541aa47387 100644 --- a/components/sync/BUILD.gn +++ b/components/sync/BUILD.gn @@ -99,6 +99,7 @@ jumbo_static_library("base") { ] deps = [ "//base:i18n", -+ "//brave/components/brave_sync:export", ++ "//brave/components/brave_sync:public", "//components/os_crypt", "//components/pref_registry", "//components/prefs", From 3fbacc7b62491e80f936c65d19fb1538b561d5a1 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 25 Jun 2019 17:52:31 +0300 Subject: [PATCH 44/73] Ignore records from ourselves --- components/brave_sync/brave_profile_sync_service_impl.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index 32efaac0ab50..76f3d5fce2be 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -161,7 +161,12 @@ void CreateResolveList( SyncRecordAndExistingList* records_and_existing_objects, bookmarks::BookmarkModel* model, prefs::Prefs* brave_sync_prefs) { + const auto& this_device_id = brave_sync_prefs->GetThisDeviceId(); for (const auto& record : records) { + // Ignore records from ourselves to avoid mess on merge + if (record->deviceId == this_device_id) { + continue; + } auto resolved_record = std::make_unique(); resolved_record->first = SyncRecord::Clone(*record); auto* node = FindByObjectId(model, record->objectId); From 21764642bba28ce728a6ad22f3cfa53b271f958e Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 25 Jun 2019 18:45:23 +0300 Subject: [PATCH 45/73] Send records after at least 30 sec after chain creation --- .../brave_profile_sync_service_impl.cc | 32 ++++++++++++++++--- .../brave_profile_sync_service_impl.h | 5 +++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index 76f3d5fce2be..801f1cc4f0d9 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -243,9 +243,18 @@ void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( for (auto& record : *records) { record->deviceId = brave_sync_prefs_->GetThisDeviceId(); } - if (!records->empty()) + if (!records->empty()) { + if (((!brave_sync::tools::IsTimeEmpty(chain_created_time_) && + (base::Time::Now() - chain_created_time_).InSeconds() < 30u) || + brave_sync_prefs_->GetSyncDevices()->size() < 2)) { + // Store records for now + pending_send_records_.push_back(std::move(records)); + return; + } + SendAndPurgePendingRecords(); brave_sync_client_->SendSyncRecords( jslib_const::SyncRecordType_BOOKMARKS, *records); + } } BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() {} @@ -501,7 +510,9 @@ void BraveProfileSyncServiceImpl::OnSyncReady() { ProfileSyncService::GetUserSettings() ->SetSelectedTypes(false, syncer::UserSelectableTypeSet()); // default enable bookmark - brave_sync_prefs_->SetSyncBookmarksEnabled(true); + // this is important, don't change + // to brave_sync_prefs_->SetSyncBookmarksEnabled(true); + OnSetSyncBookmarks(true); ProfileSyncService::GetUserSettings()->SetSyncRequested(true); } } @@ -743,9 +754,12 @@ void BraveProfileSyncServiceImpl::OnResolvedPreferences( brave_sync_prefs_->SetSyncDevices(*sync_devices); if (old_devices_size < 2 && sync_devices->size() >= 2) { - // Re-enable sync of bookmarks - bool sync_bookmarks = brave_sync_prefs_->GetSyncBookmarksEnabled(); - OnSetSyncBookmarks(sync_bookmarks); + // Save chain creation time to send bookmarks 30 sec after + chain_created_time_ = base::Time::Now(); + } + if (!tools::IsTimeEmpty(chain_created_time_) && + (base::Time::Now() - chain_created_time_).InSeconds() > 30u) { + SendAndPurgePendingRecords(); } if (this_device_deleted) { @@ -823,4 +837,12 @@ BraveSyncService* BraveProfileSyncServiceImpl::GetSyncService() const { const_cast(this)); } +void BraveProfileSyncServiceImpl::SendAndPurgePendingRecords() { + for (const auto& records_to_send : pending_send_records_) { + brave_sync_client_->SendSyncRecords( + jslib_const::SyncRecordType_BOOKMARKS, *records_to_send); + } + pending_send_records_.clear(); +} + } // namespace brave_sync diff --git a/components/brave_sync/brave_profile_sync_service_impl.h b/components/brave_sync/brave_profile_sync_service_impl.h index e7dd54732ad2..b22bbd0de42b 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -150,6 +150,8 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, void SetPermanentNodesOrder(const std::string& base_order); + void SendAndPurgePendingRecords(); + std::unique_ptr brave_sync_prefs_; // True when is in active sync chain bool brave_sync_configured_ = false; @@ -173,6 +175,9 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, std::unique_ptr brave_sync_client_; + base::Time chain_created_time_; + std::vector pending_send_records_; + // Used to ensure that certain operations are performed on the sequence that // this object was created on. SEQUENCE_CHECKER(sequence_checker_); From b0c8c492e76b793b6ceb2952a5be61515201e532 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 25 Jun 2019 18:46:07 +0300 Subject: [PATCH 46/73] Fix tests for send records after at least 30 sec after chain creation --- components/brave_sync/brave_sync_service_unittest.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 72256a8c8e52..28cac656f9e3 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -18,6 +18,7 @@ #include "brave/components/brave_sync/settings.h" #include "brave/components/brave_sync/sync_devices.h" #include "brave/components/brave_sync/test_util.h" +#include "brave/components/brave_sync/tools.h" #include "brave/components/brave_sync/values_conv.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/profiles/profile.h" @@ -657,7 +658,8 @@ TEST_F(BraveSyncServiceTest, StartSyncNonDeviceRecords) { "2", "device2")); EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); sync_service()->OnResolvedPreferences(records); - EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); + EXPECT_TRUE(!brave_sync::tools::IsTimeEmpty( + sync_service()->chain_created_time_)); } TEST_F(BraveSyncServiceTest, OnSyncReadyNewToSync) { @@ -670,7 +672,10 @@ TEST_F(BraveSyncServiceTest, OnSyncReadyNewToSync) { brave_sync::prefs::kSyncBookmarksBaseOrder, "1.1."); sync_service()->OnSyncReady(); EXPECT_TRUE(sync_prefs()->IsSyncRequested()); - EXPECT_FALSE(profile()->GetPrefs() + + // We want to have Chromium syncer bookmarks be enabled from begin to avoid + // reaching BookmarkModelAssociator::AssociateModels + EXPECT_TRUE(profile()->GetPrefs() ->GetBoolean(syncer::prefs::kSyncBookmarks)); } From ee2fbf51c17d9aa9e17ac43f8410cc75a2a7f725 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 25 Jun 2019 18:57:10 +0300 Subject: [PATCH 47/73] Patches for attach/detach behaviour for WriteTransaction --- .../sync/syncable/write_transaction.cc | 16 ++++++++++++++++ .../sync/syncable/write_transaction.h | 19 +++++++++++++++++++ ...s-sync-syncable-write_transaction.cc.patch | 12 ++++++++++++ ...ts-sync-syncable-write_transaction.h.patch | 13 +++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 chromium_src/components/sync/syncable/write_transaction.cc create mode 100644 chromium_src/components/sync/syncable/write_transaction.h create mode 100644 patches/components-sync-syncable-write_transaction.cc.patch create mode 100644 patches/components-sync-syncable-write_transaction.h.patch diff --git a/chromium_src/components/sync/syncable/write_transaction.cc b/chromium_src/components/sync/syncable/write_transaction.cc new file mode 100644 index 000000000000..6a8fbbf3b7d1 --- /dev/null +++ b/chromium_src/components/sync/syncable/write_transaction.cc @@ -0,0 +1,16 @@ +/* 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/syncable/write_transaction.cc" // NOLINT + +namespace syncer { + +WriteTransaction::WriteTransaction(const base::Location& from_here, + UserShare* share, syncable::WriteTransaction* syncable_wr_tr) : + BaseTransaction(share), transaction_(syncable_wr_tr) { + keep_ = true; +} + +} // namespace syncer diff --git a/chromium_src/components/sync/syncable/write_transaction.h b/chromium_src/components/sync/syncable/write_transaction.h new file mode 100644 index 000000000000..6c9d2657414a --- /dev/null +++ b/chromium_src/components/sync/syncable/write_transaction.h @@ -0,0 +1,19 @@ +/* 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_SYNC_ATTACHABLE_WRITE_TRANSACTION_H \ +public: \ + WriteTransaction(const base::Location& from_here, UserShare* share, \ + syncable::WriteTransaction* syncable_wr_tr); \ +private: \ + bool keep_ = false; + +#include "../../../../../components/sync/syncable/write_transaction.h" +#undef BRAVE_SYNC_ATTACHABLE_WRITE_TRANSACTION_H + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SYNCABLE_WRITE_TRANSACTION_H_ diff --git a/patches/components-sync-syncable-write_transaction.cc.patch b/patches/components-sync-syncable-write_transaction.cc.patch new file mode 100644 index 000000000000..49110a8dbae8 --- /dev/null +++ b/patches/components-sync-syncable-write_transaction.cc.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync/syncable/write_transaction.cc b/components/sync/syncable/write_transaction.cc +index 00b248a93830bbafae831d46d1089a0844c57805..2b9a153e9f55b51d22e5568b469add733921b92a 100644 +--- a/components/sync/syncable/write_transaction.cc ++++ b/components/sync/syncable/write_transaction.cc +@@ -28,6 +28,7 @@ WriteTransaction::WriteTransaction(const base::Location& from_here, + } + + WriteTransaction::~WriteTransaction() { ++ if (!keep_) + delete transaction_; + } + diff --git a/patches/components-sync-syncable-write_transaction.h.patch b/patches/components-sync-syncable-write_transaction.h.patch new file mode 100644 index 000000000000..c90f035887a4 --- /dev/null +++ b/patches/components-sync-syncable-write_transaction.h.patch @@ -0,0 +1,13 @@ +diff --git a/components/sync/syncable/write_transaction.h b/components/sync/syncable/write_transaction.h +index 3d0a353ac09b1dcbfab0d5afc3345d78eb4ee8bd..77e5c7acf90a52ccd59ab8ef500dda2673818e99 100644 +--- a/components/sync/syncable/write_transaction.h ++++ b/components/sync/syncable/write_transaction.h +@@ -62,7 +62,7 @@ class WriteTransaction : public BaseTransaction { + void SetTransaction(syncable::WriteTransaction* trans) { + transaction_ = trans; + } +- ++ BRAVE_SYNC_ATTACHABLE_WRITE_TRANSACTION_H + private: + void* operator new(size_t size); // Transaction is meant for stack use only. + From 0aad976abf63cc2aeae203e4e06bbfc606e3f1f9 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 25 Jun 2019 19:10:35 +0300 Subject: [PATCH 48/73] Sort bookmarks in BookmarkChangeProcessor::ApplyChangesFromSyncModel and update corresponding sync nodes --- .../bookmark_change_processor.cc | 61 +++++++++++++++++++ .../bookmark_change_processor.h | 20 ++++++ components/brave_sync/syncer_helper.cc | 35 +++++++++++ components/brave_sync/syncer_helper.h | 4 ++ ...okmarks-bookmark_change_processor.cc.patch | 21 +++++-- ...ookmarks-bookmark_change_processor.h.patch | 12 ++++ 6 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 chromium_src/components/sync_bookmarks/bookmark_change_processor.h create mode 100644 patches/components-sync_bookmarks-bookmark_change_processor.h.patch diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 20c0e8802c39..731e5efc4686 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -7,6 +7,11 @@ #include "brave/components/brave_sync/syncer_helper.h" #include "components/bookmarks/browser/bookmark_model.h" +#include "components/sync/syncable/base_transaction.h" +#include "components/sync/syncable/syncable_base_transaction.h" +#include "components/sync/syncable/syncable_write_transaction.h" +#include "components/sync/syncable/write_node.h" +#include "components/sync/syncable/write_transaction.h" using bookmarks::BookmarkModel; using bookmarks::BookmarkModelObserver; @@ -57,6 +62,58 @@ bool IsFirstLoadedFavicon(BookmarkChangeProcessor* bookmark_change_processor, } // namespace +namespace sync_bookmarks { +syncer::SyncError BookmarkChangeProcessor::UpdateChildrenPositions( + const bookmarks::BookmarkNode* parent_node, + syncer::WriteTransaction* trans) { + for (int i = 0; i < parent_node->child_count(); ++i) { + const bookmarks::BookmarkNode* node = parent_node->GetChild(i); + syncer::WriteNode sync_node(trans); + if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { + syncer::SyncError error(FROM_HERE, + syncer::SyncError::DATATYPE_ERROR, + "Failed to init sync node from chrome node", + syncer::BOOKMARKS); + // TODO(AlexeyBarabash): pull unrecoverable_error_handler_ + // from BookmarkModelAssociator + // unrecoverable_error_handler_->OnUnrecoverableError(error); + DCHECK(false) << "[BraveSync] " << __func__ << + " Failed to init sync node from chrome node"; + return error; + } + if (!PlaceSyncNode(MOVE, parent_node, i, trans, &sync_node, + model_associator_)) { + syncer::SyncError error(FROM_HERE, + syncer::SyncError::DATATYPE_ERROR, + "Failed to place sync node", + syncer::BOOKMARKS); + // unrecoverable_error_handler_->OnUnrecoverableError(error); + DCHECK(false) << "[BraveSync] " << __func__ << + "Failed to place sync node"; + return error; + } + } + return syncer::SyncError(); +} +void BookmarkChangeProcessor::MakeRepositionAndUpdateSyncNodes( + const std::multimap& to_reposition, + const syncer::BaseTransaction* trans) { + brave_sync::RepositionOnApplyChangesFromSyncModel( + bookmark_model_, to_reposition); + // Attach to the transaction as a write transaction. + // Could be broken in next chromium updates, but now it is possible, see calls + // WriteTransaction::NotifyTransactionChangingAndEnding => + // SyncManagerImpl::HandleTransactionEndingChangeEvent + syncer::WriteTransaction write_trans(FROM_HERE, trans->GetUserShare(), + static_cast( + trans->GetWrappedTrans())); + for (auto it = to_reposition.begin(); it != to_reposition.end(); ++it) { + const BookmarkNode* parent = it->second->parent(); + UpdateChildrenPositions(parent, &write_trans); + } +} +} // namespace sync_bookmarks + #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED \ if (IsFirstLoadedFavicon(this, bookmark_model_, node)) return; @@ -75,8 +132,12 @@ bool IsFirstLoadedFavicon(BookmarkChangeProcessor* bookmark_change_processor, brave_sync::AddBraveMetaInfo(child, model, false); \ SetSyncNodeMetaInfo(child, &sync_child); +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL \ + MakeRepositionAndUpdateSyncNodes(to_reposition, trans); + #include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" // NOLINT #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_1 #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_2 #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.h b/chromium_src/components/sync_bookmarks/bookmark_change_processor.h new file mode 100644 index 000000000000..15fe6171d725 --- /dev/null +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.h @@ -0,0 +1,20 @@ +/* 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_BOOKMARKS_BOOKMARKS_CHANGE_PROCESSOR_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARKS_CHANGE_PROCESSOR_H_ + + +#define BRAVE_SYNC_REPOSITION_METHODS \ +syncer::SyncError UpdateChildrenPositions( \ + const bookmarks::BookmarkNode* parent_node, \ + syncer::WriteTransaction* trans); \ +void MakeRepositionAndUpdateSyncNodes( \ + const std::multimap& to_reposition, \ + const syncer::BaseTransaction* trans); + +#include "../../../../../components/sync_bookmarks/bookmark_change_processor.h" + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARKS_CHANGE_PROCESSOR_H_ diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index b19965028bd9..c82cb6875f79 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -55,6 +55,34 @@ uint64_t GetIndexByOrder(const std::string& record_order) { return index; } +uint64_t GetIndexByCompareOrderStartFrom( + const bookmarks::BookmarkNode* parent, + const bookmarks::BookmarkNode* src, + int index) { + std::string src_order; + src->GetMetaInfo("order", &src_order); + DCHECK(!src_order.empty()); + DCHECK(index >= 0); + while (index < parent->child_count()) { + const bookmarks::BookmarkNode* node = parent->GetChild(index); + std::string node_order; + node->GetMetaInfo("order", &node_order); + if (!node_order.empty() && + brave_sync::CompareOrder(src_order, node_order)) { + return index; + } + ++index; + } + return index; +} +// |node| is near the end in parent +void RepositionRespectOrder( + bookmarks::BookmarkModel* bookmark_model, + const bookmarks::BookmarkNode* node) { + const bookmarks::BookmarkNode* parent = node->parent(); + int index = GetIndexByCompareOrderStartFrom(parent, node, 0); + bookmark_model->Move(node, parent, index); +} } // namespace void AddBraveMetaInfo( @@ -113,5 +141,12 @@ uint64_t GetIndex(const bookmarks::BookmarkNode* parent, } return index; } +void RepositionOnApplyChangesFromSyncModel( + bookmarks::BookmarkModel* bookmark_model, + const std::multimap& to_reposition) { + for (auto it = to_reposition.begin(); it != to_reposition.end(); ++it) { + RepositionRespectOrder(bookmark_model, it->second); + } +} } // namespace brave_sync diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h index 795df3430003..034142e70e8d 100644 --- a/components/brave_sync/syncer_helper.h +++ b/components/brave_sync/syncer_helper.h @@ -7,6 +7,7 @@ #define BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ #include +#include namespace bookmarks { class BookmarkModel; @@ -23,6 +24,9 @@ void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, // |src| is the node which is about to be inserted into |parent| uint64_t GetIndex(const bookmarks::BookmarkNode* parent, const bookmarks::BookmarkNode* src); +void RepositionOnApplyChangesFromSyncModel( + bookmarks::BookmarkModel* bookmark_model, + const std::multimap& to_reposition); } // namespace brave_sync diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 2cb0642170b5..02939cafe84b 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..a4ad75b23dd3537867ef4f7df2bf38a417c6054f 100644 +index acb064faac3ee975ec07be4977fc0970309dfb15..d9a74bda83d56c38e98e3952696519339033de1a 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -61,7 +61,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..a4ad75b23dd3537867ef4f7df2bf38a4 if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -718,10 +726,12 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -718,6 +726,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } @@ -69,9 +69,20 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..a4ad75b23dd3537867ef4f7df2bf38a4 model_associator_->Associate(dst, src); } -- to_reposition.insert(std::make_pair(src.GetPositionIndex(), dst)); -+ uint64_t index = brave_sync::GetIndex(dst->parent(), dst); -+ to_reposition.insert(std::make_pair(index, dst)); +@@ -725,6 +734,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( bookmark_model_->SetNodeSyncTransactionVersion(dst, model_version); } ++#if !defined(BRAVE_CHROMIUM_BUILD) + // When we added or updated bookmarks in the previous loop, we placed them to + // the far right position. Now we iterate over all these modified items in + // sync order, left to right, moving them into their proper positions. +@@ -732,6 +742,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( + const BookmarkNode* parent = it->second->parent(); + model->Move(it->second, parent, it->first); + } ++#endif ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL + + // Clean up the temporary node. + if (foster_parent) { diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.h.patch b/patches/components-sync_bookmarks-bookmark_change_processor.h.patch new file mode 100644 index 000000000000..7bd14e8f5000 --- /dev/null +++ b/patches/components-sync_bookmarks-bookmark_change_processor.h.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync_bookmarks/bookmark_change_processor.h b/components/sync_bookmarks/bookmark_change_processor.h +index e11a2ddf641edc7098c06433fd22d86467e2aabf..86629fa7182a9cf893ff9442ec5667924c59f335 100644 +--- a/components/sync_bookmarks/bookmark_change_processor.h ++++ b/components/sync_bookmarks/bookmark_change_processor.h +@@ -238,6 +238,7 @@ class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, + // Returns false if |node| should not be synced. + bool CanSyncNode(const bookmarks::BookmarkNode* node); + ++ BRAVE_SYNC_REPOSITION_METHODS + SEQUENCE_CHECKER(sequence_checker_); + + // The bookmark model we are processing changes from. Non-null when From eb2dd0b722209217f8f2a23335525df88795f0f4 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 25 Jun 2019 19:14:31 +0300 Subject: [PATCH 49/73] Update DEPS to contain "Ignore records from SQS which where seen in S3" --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 1a9ac0302e93..4c85923ae6ee 100644 --- a/DEPS +++ b/DEPS @@ -15,7 +15,7 @@ deps = { "vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@13bb40a215248cfbdd87d0a6b425c8397402e9e6", "vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@e3742ba3e8942eea9e4755d91532491871bd3116", "vendor/bat-native-tweetnacl": "https://github.com/brave-intl/bat-native-tweetnacl.git@1b4362968c8f22720bfb75af6f506d4ecc0f3116", - "components/brave_sync/extension/brave-sync": "https://github.com/brave/sync.git@e97e9e912552cd789cb2c1b1f327c77b32175317", + "components/brave_sync/extension/brave-sync": "https://github.com/brave/sync.git@91a68fdebc8962ca409045177438671f06a3c26a", "components/brave_sync/extension/brave-crypto": "https://github.com/brave/crypto@0231e65ba211b152d742278319c545a83cb13fc0", "vendor/bat-native-usermodel": "https://github.com/brave-intl/bat-native-usermodel.git@a82acda22d8cb255d86ee28734efb8ad886e9a49", "vendor/challenge_bypass_ristretto_ffi": "https://github.com/brave-intl/challenge-bypass-ristretto-ffi.git@f88d942ddfaf61a4a6703355a77c4ef71bc95c35", From 5eecbd2a37f8473b2c731e41b1fab2f55de6cf22 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Mon, 1 Jul 2019 17:43:54 +0300 Subject: [PATCH 50/73] Use title or customeTitle, non empty value --- .../components/sync/engine_impl/get_updates_processor.cc | 5 +++-- components/brave_sync/jslib_messages.cc | 4 ++++ components/brave_sync/jslib_messages.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index 9238359b09b6..af190f39c1f9 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -51,7 +51,8 @@ void AddBookmarkSpecifics(sync_pb::EntitySpecifics* specifics, auto bookmark = record->GetBookmark(); sync_pb::BookmarkSpecifics* bm_specifics = specifics->mutable_bookmark(); bm_specifics->set_url(bookmark.site.location); - bm_specifics->set_title(bookmark.site.title); + + bm_specifics->set_title(bookmark.site.TryGetNonEmptyTitle()); bm_specifics->set_creation_time_us( TimeToProtoTime(bookmark.site.creationTime)); bm_specifics->set_icon_url(bookmark.site.favicon); @@ -171,7 +172,7 @@ void AddBookmarkNode(sync_pb::SyncEntity* entity, const SyncRecord* record) { entity->set_parent_id_string(std::string(kBookmarkBarFolderServerTag)); else entity->set_parent_id_string(std::string(kOtherBookmarksFolderServerTag)); - entity->set_non_unique_name(bookmark_record.site.title); + entity->set_non_unique_name(bookmark_record.site.TryGetNonEmptyTitle()); entity->set_folder(bookmark_record.isFolder); ExtractBookmarkMeta(entity, &specifics, bookmark_record); diff --git a/components/brave_sync/jslib_messages.cc b/components/brave_sync/jslib_messages.cc index 89dca7e14b0b..4e40165d0804 100644 --- a/components/brave_sync/jslib_messages.cc +++ b/components/brave_sync/jslib_messages.cc @@ -31,6 +31,10 @@ std::unique_ptr Site::Clone(const Site& site) { return std::make_unique(site); } +std::string Site::TryGetNonEmptyTitle() const { + return !title.empty() ? title : customTitle; +} + MetaInfo::MetaInfo() = default; MetaInfo::MetaInfo(const MetaInfo& metaInfo) { diff --git a/components/brave_sync/jslib_messages.h b/components/brave_sync/jslib_messages.h index f5f1432fcb60..f2092979f8f3 100644 --- a/components/brave_sync/jslib_messages.h +++ b/components/brave_sync/jslib_messages.h @@ -34,6 +34,8 @@ class Site { ~Site(); static std::unique_ptr Clone(const Site& site); + std::string TryGetNonEmptyTitle() const; + std::string location; std::string title; std::string customTitle; From a04cb32bfeeb4f2ae052b507ceb048615423ba5b Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 9 Jul 2019 15:25:00 +0300 Subject: [PATCH 51/73] Fix for crash with bookmark position from older sync client (android) --- .../components/sync/engine_impl/get_updates_processor.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index af190f39c1f9..da5f56f37e5e 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -19,6 +19,7 @@ SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*, ModelTypeSet*, #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" @@ -115,7 +116,7 @@ void MigrateFromLegacySync(sync_pb::SyncEntity* entity) { entity->set_originator_cache_guid("legacy_originator_cache_guid"); } if (!entity->has_originator_client_item_id()) { - entity->set_originator_client_item_id("legacy_originator_client_item_id"); + entity->set_originator_client_item_id(base::GenerateGUID()); } if (!entity->has_version()) { entity->set_version(1); From 0f79073f95b97f15da1473c53d05935d3ecabaf5 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 15 Jul 2019 16:01:00 -0700 Subject: [PATCH 52/73] Update 76.0.3809.62 patches --- patches/chrome-browser-BUILD.gn.patch | 4 +-- ...sync-profile_sync_service_factory.cc.patch | 10 +++--- patches/components-sync-BUILD.gn.patch | 12 ------- patches/components-sync-base-BUILD.gn.patch | 12 +++++++ .../components-sync-base-model_type.h.patch | 4 +-- ...ync-driver-data_type_manager_impl.cc.patch | 4 +-- ...c-driver-glue-sync_engine_backend.cc.patch | 4 +-- ...-sync-driver-glue-sync_engine_impl.h.patch | 4 +-- ...-sync-driver-profile_sync_service.cc.patch | 4 +-- ...s-sync-driver-profile_sync_service.h.patch | 2 +- ...components-sync-engine-sync_engine.h.patch | 4 +-- ...omponents-sync-engine-sync_manager.h.patch | 4 +-- ...ync-engine_impl-sync_manager_impl.cc.patch | 6 ++-- ...ync-engine_impl-syncer_proto_util.cc.patch | 8 ++--- ...ts-sync-syncable-write_transaction.h.patch | 9 +++--- ...okmarks-bookmark_change_processor.cc.patch | 32 +++++++------------ ...ks-bookmark_local_changes_builder.cc.patch | 12 ------- 17 files changed, 57 insertions(+), 78 deletions(-) delete mode 100644 patches/components-sync-BUILD.gn.patch create mode 100644 patches/components-sync-base-BUILD.gn.patch delete mode 100644 patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch diff --git a/patches/chrome-browser-BUILD.gn.patch b/patches/chrome-browser-BUILD.gn.patch index e31e02ca1a28..ab0a6ad1608f 100644 --- a/patches/chrome-browser-BUILD.gn.patch +++ b/patches/chrome-browser-BUILD.gn.patch @@ -1,8 +1,8 @@ diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn -index 600fe26a3f3537545d683d7fb9712446957d01fb..6d58c95c2ebe78709419b44fb9596cb3de20898c 100644 +index 4f9844f6f8546efe591e679c41c7cd3b43c371a8..0e86b115bef94df9821adeffe944b0d3a63b587c 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn -@@ -2099,6 +2099,7 @@ jumbo_split_static_library("browser") { +@@ -2142,6 +2142,7 @@ jumbo_split_static_library("browser") { "//ui/strings", "//ui/surface", "//ui/web_dialogs", diff --git a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch index ce12ef69e3c2..54447ea55c95 100644 --- a/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch +++ b/patches/chrome-browser-sync-profile_sync_service_factory.cc.patch @@ -1,13 +1,13 @@ diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc -index a1d9f0f8a50a9922d45645a48c235fb0f61d3729..5a1093b9bb293fef38afba5dbcb5018cc8737ddd 100644 +index 5059e39e28bb076eb26cd5fda1f61223591023b7..ef2ecbb8b653663fdf5dbd76adca2a87543fd6e7 100644 --- a/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chrome/browser/sync/profile_sync_service_factory.cc -@@ -263,7 +263,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( +@@ -264,7 +264,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( } auto pss = - std::make_unique(std::move(init_params)); -+ BraveBuildServiceInstanceFor(profile, std::move(init_params)); ++ BraveBuildServiceInstanceFor(profile, std::move(init_params)); pss->Initialize(); - return pss.release(); - } + + // Hook PSS into PersonalDataManager (a circular dependency). diff --git a/patches/components-sync-BUILD.gn.patch b/patches/components-sync-BUILD.gn.patch deleted file mode 100644 index ccc7f5b7137e..000000000000 --- a/patches/components-sync-BUILD.gn.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/sync/BUILD.gn b/components/sync/BUILD.gn -index 0606b7e68670877100114732174af25ad0b42f77..71e92c712f6ec388c0ab6cb8a92e03541aa47387 100644 ---- a/components/sync/BUILD.gn -+++ b/components/sync/BUILD.gn -@@ -99,6 +99,7 @@ jumbo_static_library("base") { - ] - deps = [ - "//base:i18n", -+ "//brave/components/brave_sync:public", - "//components/os_crypt", - "//components/pref_registry", - "//components/prefs", diff --git a/patches/components-sync-base-BUILD.gn.patch b/patches/components-sync-base-BUILD.gn.patch new file mode 100644 index 000000000000..2677aa8e4e2d --- /dev/null +++ b/patches/components-sync-base-BUILD.gn.patch @@ -0,0 +1,12 @@ +diff --git a/components/sync/base/BUILD.gn b/components/sync/base/BUILD.gn +index c36114532adaea827b566f99ce180421d8fcf623..cf243553011cf7a3564f46abac053e5d53e3de25 100644 +--- a/components/sync/base/BUILD.gn ++++ b/components/sync/base/BUILD.gn +@@ -77,6 +77,7 @@ jumbo_static_library("base") { + ] + deps = [ + "//base:i18n", ++ "//brave/components/brave_sync:public", + "//components/os_crypt", + "//components/pref_registry", + "//components/prefs", diff --git a/patches/components-sync-base-model_type.h.patch b/patches/components-sync-base-model_type.h.patch index f4b243990bb9..f6cfd880cfd9 100644 --- a/patches/components-sync-base-model_type.h.patch +++ b/patches/components-sync-base-model_type.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/base/model_type.h b/components/sync/base/model_type.h -index db7e7d7d68eabab6ed7e1a3ccfe125e3e571e382..3bf5bd32c2aa567d16a6f90953556fb5283dc592 100644 +index d751ce7b3c9618cca3bf48e2cc9c640be9fa9d22..3b18b631a8db839c9a0ee820fea9f4b52b2b9890 100644 --- a/components/sync/base/model_type.h +++ b/components/sync/base/model_type.h -@@ -241,6 +241,7 @@ constexpr ModelTypeSet ProxyTypes() { +@@ -244,6 +244,7 @@ constexpr ModelTypeSet ProxyTypes() { // - They support custom update application and conflict resolution logic. // - All change processing occurs on the sync thread (GROUP_PASSIVE). constexpr ModelTypeSet ControlTypes() { diff --git a/patches/components-sync-driver-data_type_manager_impl.cc.patch b/patches/components-sync-driver-data_type_manager_impl.cc.patch index cf5ffc7f1c42..80bffda14a49 100644 --- a/patches/components-sync-driver-data_type_manager_impl.cc.patch +++ b/patches/components-sync-driver-data_type_manager_impl.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/data_type_manager_impl.cc b/components/sync/driver/data_type_manager_impl.cc -index f19aeafebc707eaf703b0fa71bf1c2d80dba2596..2058e0122b7de1206baba6e65a52db9262e5d0e9 100644 +index a8c9a81571950ecf430c6f82fb6baa8057e576fa..0da71d472e253749b6a3561e542183dd12efa0bc 100644 --- a/components/sync/driver/data_type_manager_impl.cc +++ b/components/sync/driver/data_type_manager_impl.cc -@@ -543,7 +543,7 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( +@@ -544,7 +544,7 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( types_to_download.RemoveAll(ProxyTypes()); types_to_download.RemoveAll(CommitOnlyTypes()); if (!types_to_download.Empty()) diff --git a/patches/components-sync-driver-glue-sync_engine_backend.cc.patch b/patches/components-sync-driver-glue-sync_engine_backend.cc.patch index dc12271d188f..8e01a0ce4307 100644 --- a/patches/components-sync-driver-glue-sync_engine_backend.cc.patch +++ b/patches/components-sync-driver-glue-sync_engine_backend.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/glue/sync_engine_backend.cc b/components/sync/driver/glue/sync_engine_backend.cc -index 508c26a99ecb044bcca60f34ef4c787bb06fdc9f..9be28df383a27491b8410dddb6c7af6385af0165 100644 +index f6cdade4a559d1f1e329bc1e4329680407220926..291c26eab481308e05a8eb4f32bd71c2b4d62f0b 100644 --- a/components/sync/driver/glue/sync_engine_backend.cc +++ b/components/sync/driver/glue/sync_engine_backend.cc -@@ -370,6 +370,7 @@ void SyncEngineBackend::DoInitialize(SyncEngine::InitParams params) { +@@ -342,6 +342,7 @@ void SyncEngineBackend::DoInitialize(SyncEngine::InitParams params) { args.cache_guid = params.cache_guid; args.birthday = params.birthday; args.bag_of_chips = params.bag_of_chips; diff --git a/patches/components-sync-driver-glue-sync_engine_impl.h.patch b/patches/components-sync-driver-glue-sync_engine_impl.h.patch index 988f6e913421..f6d7fd2a3c6e 100644 --- a/patches/components-sync-driver-glue-sync_engine_impl.h.patch +++ b/patches/components-sync-driver-glue-sync_engine_impl.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/glue/sync_engine_impl.h b/components/sync/driver/glue/sync_engine_impl.h -index 9fce092e22ca630fa3f5efa0bc1e963a86659625..7ca7b912f21558d76eafa9b392fec616b3f4056a 100644 +index fa18e8241e3b7c3ea4e95b764fea19080e626d0d..f8d2e5a704d7f970ffeee0cd228607056cb6a868 100644 --- a/components/sync/driver/glue/sync_engine_impl.h +++ b/components/sync/driver/glue/sync_engine_impl.h -@@ -220,6 +220,7 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { +@@ -218,6 +218,7 @@ class SyncEngineImpl : public SyncEngine, public InvalidationHandler { base::WeakPtrFactory weak_ptr_factory_; diff --git a/patches/components-sync-driver-profile_sync_service.cc.patch b/patches/components-sync-driver-profile_sync_service.cc.patch index 8f11b498c498..595b6a9f5f60 100644 --- a/patches/components-sync-driver-profile_sync_service.cc.patch +++ b/patches/components-sync-driver-profile_sync_service.cc.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/driver/profile_sync_service.cc b/components/sync/driver/profile_sync_service.cc -index 3dc7667b7fc5a919f2025c53e040265927e6ea23..94c94eb599416bc8911865939cc2c4765da03ec3 100644 +index ead807e7c2810a4e32d738004a3911c1ac954b0d..ec73a7c8c4ad24ea72e734f7f98d664807cf9685 100644 --- a/components/sync/driver/profile_sync_service.cc +++ b/components/sync/driver/profile_sync_service.cc -@@ -458,6 +458,7 @@ void ProfileSyncService::StartUpSlowEngineComponents() { +@@ -463,6 +463,7 @@ void ProfileSyncService::StartUpSlowEngineComponents() { params.sync_user_agent = MakeUserAgentForSync(channel_); params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); params.authenticated_account_id = GetAuthenticatedAccountInfo().account_id; diff --git a/patches/components-sync-driver-profile_sync_service.h.patch b/patches/components-sync-driver-profile_sync_service.h.patch index 0a1515aa4543..915afe8eede5 100644 --- a/patches/components-sync-driver-profile_sync_service.h.patch +++ b/patches/components-sync-driver-profile_sync_service.h.patch @@ -1,5 +1,5 @@ diff --git a/components/sync/driver/profile_sync_service.h b/components/sync/driver/profile_sync_service.h -index 3df5ee21f6ec37c5915607ec9196909c62545572..1688bb856998a4883e71e6ba4a967d6a90a75078 100644 +index eb37180610ac149898aa326dfc391e4dccb4e35c..dcba3d59c7ee0d60768dcc3e684109b2f878beeb 100644 --- a/components/sync/driver/profile_sync_service.h +++ b/components/sync/driver/profile_sync_service.h @@ -500,6 +500,7 @@ class ProfileSyncService : public SyncService, diff --git a/patches/components-sync-engine-sync_engine.h.patch b/patches/components-sync-engine-sync_engine.h.patch index 7e1891f567ad..ce25e1f28ec3 100644 --- a/patches/components-sync-engine-sync_engine.h.patch +++ b/patches/components-sync-engine-sync_engine.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine/sync_engine.h b/components/sync/engine/sync_engine.h -index e4d2ab4d38f6fffd2929277be51ec618180e0086..b0bbfcd58c55917c98a9ce0e36a15c68524339d0 100644 +index 8d53e56f05b9d788d863593c03c8321b0683ea3c..775309aa9b352ebe290141860c3324c5325c4bc3 100644 --- a/components/sync/engine/sync_engine.h +++ b/components/sync/engine/sync_engine.h -@@ -86,6 +86,7 @@ class SyncEngine : public ModelTypeConfigurer { +@@ -82,6 +82,7 @@ class SyncEngine : public ModelTypeConfigurer { // Define the polling interval. Must not be zero. base::TimeDelta poll_interval; diff --git a/patches/components-sync-engine-sync_manager.h.patch b/patches/components-sync-engine-sync_manager.h.patch index 7b8dd7dc2248..db971e4224d4 100644 --- a/patches/components-sync-engine-sync_manager.h.patch +++ b/patches/components-sync-engine-sync_manager.h.patch @@ -1,8 +1,8 @@ diff --git a/components/sync/engine/sync_manager.h b/components/sync/engine/sync_manager.h -index 8dfd2480f2a7483062fe57890fd442c9b420c5a0..f1ddf57794fa5ca12fd58b41b693fe3cf55520b3 100644 +index 9dbc229893be5e6c60a15f7f9ccd5de6fc918f15..cf9e8c2f193f581de17c7b546856ab588e588907 100644 --- a/components/sync/engine/sync_manager.h +++ b/components/sync/engine/sync_manager.h -@@ -254,6 +254,7 @@ class SyncManager { +@@ -251,6 +251,7 @@ class SyncManager { std::string cache_guid; std::string birthday; std::string bag_of_chips; diff --git a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch index 259b13db1434..ce43c0eb0f26 100644 --- a/patches/components-sync-engine_impl-sync_manager_impl.cc.patch +++ b/patches/components-sync-engine_impl-sync_manager_impl.cc.patch @@ -1,9 +1,9 @@ diff --git a/components/sync/engine_impl/sync_manager_impl.cc b/components/sync/engine_impl/sync_manager_impl.cc -index 60404b7479d5d5d23b13c2aa969133c927f34ecd..b0ebd1c63091279c4712dd7c98a1469fd05cfabb 100644 +index 4d43b0de7d7376d13b587b2d5c4d7beac38720c8..114689f853e0b4938ebda84d1dba52cdbac35cb1 100644 --- a/components/sync/engine_impl/sync_manager_impl.cc +++ b/components/sync/engine_impl/sync_manager_impl.cc -@@ -359,8 +359,9 @@ void SyncManagerImpl::Init(InitArgs* args) { - args->invalidator_client_id, args->poll_interval); +@@ -410,8 +410,9 @@ void SyncManagerImpl::Init(InitArgs* args) { + args->poll_interval); scheduler_ = args->engine_components_factory->BuildScheduler( name_, cycle_context_.get(), args->cancelation_signal, - args->enable_local_sync_backend); diff --git a/patches/components-sync-engine_impl-syncer_proto_util.cc.patch b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch index a55502206df5..243bcaa0ef31 100644 --- a/patches/components-sync-engine_impl-syncer_proto_util.cc.patch +++ b/patches/components-sync-engine_impl-syncer_proto_util.cc.patch @@ -1,16 +1,16 @@ diff --git a/components/sync/engine_impl/syncer_proto_util.cc b/components/sync/engine_impl/syncer_proto_util.cc -index 6706d0225207d266b1ed74cc712462052b3180a6..0a15430c4ab9ec03b1e3a706de3dd7873da83389 100644 +index 791e269c8b9933093826991e7a73bb75878f8b1b..e353365024f0338493aff29c48b9140f8f269982 100644 --- a/components/sync/engine_impl/syncer_proto_util.cc +++ b/components/sync/engine_impl/syncer_proto_util.cc -@@ -431,6 +431,7 @@ base::TimeDelta SyncerProtoUtil::GetThrottleDelay( +@@ -394,6 +394,7 @@ base::TimeDelta SyncerProtoUtil::GetThrottleDelay( void SyncerProtoUtil::AddRequiredFieldsToClientToServerMessage( const SyncCycle* cycle, sync_pb::ClientToServerMessage* msg) { + return; DCHECK(msg); SetProtocolVersion(msg); - AddRequestBirthday(cycle->context()->directory(), msg); -@@ -447,6 +448,7 @@ SyncerError SyncerProtoUtil::PostClientToServerMessage( + const std::string birthday = cycle->context()->birthday(); +@@ -413,6 +414,7 @@ SyncerError SyncerProtoUtil::PostClientToServerMessage( ClientToServerResponse* response, SyncCycle* cycle, ModelTypeSet* partial_failure_data_types) { diff --git a/patches/components-sync-syncable-write_transaction.h.patch b/patches/components-sync-syncable-write_transaction.h.patch index c90f035887a4..d06335aefb7c 100644 --- a/patches/components-sync-syncable-write_transaction.h.patch +++ b/patches/components-sync-syncable-write_transaction.h.patch @@ -1,13 +1,12 @@ diff --git a/components/sync/syncable/write_transaction.h b/components/sync/syncable/write_transaction.h -index 3d0a353ac09b1dcbfab0d5afc3345d78eb4ee8bd..77e5c7acf90a52ccd59ab8ef500dda2673818e99 100644 +index 3d0a353ac09b1dcbfab0d5afc3345d78eb4ee8bd..eafebbf205de8691700162151ced152a4d5ba679 100644 --- a/components/sync/syncable/write_transaction.h +++ b/components/sync/syncable/write_transaction.h -@@ -62,7 +62,7 @@ class WriteTransaction : public BaseTransaction { - void SetTransaction(syncable::WriteTransaction* trans) { +@@ -63,6 +63,7 @@ class WriteTransaction : public BaseTransaction { transaction_ = trans; } -- -+ BRAVE_SYNC_ATTACHABLE_WRITE_TRANSACTION_H + ++ BRAVE_SYNC_ATTACHABLE_WRITE_TRANSACTION_H private: void* operator new(size_t size); // Transaction is meant for stack use only. diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 02939cafe84b..f0de9f076882 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index acb064faac3ee975ec07be4977fc0970309dfb15..d9a74bda83d56c38e98e3952696519339033de1a 100644 +index 35a73a07bbcdd8aeba13acf37c6754aadb039768..f00db7611ccf75b66d8f4bf2db20566d45711f60 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -10,25 +10,16 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..d9a74bda83d56c38e98e395269651933 SetSyncNodeMetaInfo(src, dst); } -@@ -244,6 +245,7 @@ void BookmarkChangeProcessor::CreateOrUpdateSyncNode(const BookmarkNode* node) { - // Acquire a scoped write lock via a transaction. - syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); - sync_id = model_associator_->GetSyncIdFromChromeId(node->id()); -+ ScopedPauseObserver pause(bookmark_model_, this); - if (sync_id != syncer::kInvalidId) { - UpdateSyncNode( - node, bookmark_model_, &trans, model_associator_, error_handler()); -@@ -383,7 +385,8 @@ int64_t BookmarkChangeProcessor::UpdateSyncNode( +@@ -383,7 +384,7 @@ int64_t BookmarkChangeProcessor::UpdateSyncNode( void BookmarkChangeProcessor::BookmarkMetaInfoChanged( BookmarkModel* model, const BookmarkNode* node) { - BookmarkNodeChanged(model, node); + // TODO(darkdh): make sure the meta info changed is what we want to sync -+ // BookmarkNodeChanged(model, node); } void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, -@@ -415,6 +418,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -415,6 +416,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, error_handler()->OnUnrecoverableError(error); return; } @@ -36,7 +27,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..d9a74bda83d56c38e98e395269651933 if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, model_associator_)) { -@@ -429,6 +433,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -429,6 +431,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, UpdateTransactionVersion(new_version, model, std::vector(1, child)); @@ -44,24 +35,25 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..d9a74bda83d56c38e98e395269651933 } void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( -@@ -458,6 +463,8 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( +@@ -458,6 +461,7 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( return; } + BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED -+ CreateOrUpdateSyncNode(node); } -@@ -490,6 +497,7 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( +@@ -489,7 +493,8 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( + } DCHECK_EQ(sync_child.GetParentId(), model_associator_->GetSyncIdFromChromeId(node->id())); - +- ++ + BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -718,6 +726,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -718,6 +723,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } @@ -69,7 +61,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..d9a74bda83d56c38e98e395269651933 model_associator_->Associate(dst, src); } -@@ -725,6 +734,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -725,6 +731,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( bookmark_model_->SetNodeSyncTransactionVersion(dst, model_version); } @@ -77,7 +69,7 @@ index acb064faac3ee975ec07be4977fc0970309dfb15..d9a74bda83d56c38e98e395269651933 // When we added or updated bookmarks in the previous loop, we placed them to // the far right position. Now we iterate over all these modified items in // sync order, left to right, moving them into their proper positions. -@@ -732,6 +742,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -732,6 +739,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( const BookmarkNode* parent = it->second->parent(); model->Move(it->second, parent, it->first); } diff --git a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch b/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch deleted file mode 100644 index 7c9822526a76..000000000000 --- a/patches/components-sync_bookmarks-bookmark_local_changes_builder.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/sync_bookmarks/bookmark_local_changes_builder.cc b/components/sync_bookmarks/bookmark_local_changes_builder.cc -index f0b7bc6f9cea4eb3cb2386906bfc57be8bb5f802..5a96ebc0b5a2e3534d513a67b400c6997e786c05 100644 ---- a/components/sync_bookmarks/bookmark_local_changes_builder.cc -+++ b/components/sync_bookmarks/bookmark_local_changes_builder.cc -@@ -66,6 +66,7 @@ syncer::CommitRequestDataList BookmarkLocalChangesBuilder::BuildCommitRequests( - data->specifics = CreateSpecificsFromBookmarkNode( - node, bookmark_model_, /*force_favicon_load=*/true); - data->non_unique_name = data->specifics.bookmark().title(); -+ brave_sync::AddBraveMetaInfo(node, bookmark_model_, true); - } - auto request = std::make_unique(); - request->entity = std::move(data); From 1338103a11ed83e5ab20c2da2cc93f02d76291b3 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 16 Jul 2019 14:04:34 -0700 Subject: [PATCH 53/73] Remove BRAVE_SHOULD_SHOW_SIGNIN_PROMO_SHORT_CIRCUIT_TO_FALSE and lint fix --- ...card_bubble_controller_impl_browsertest.cc | 18 +++++++++- .../save_card_bubble_controller_impl.cc | 12 ------- .../sync/engine_impl/cycle/sync_cycle.h | 3 +- .../sync/syncable/write_transaction.h | 6 ++-- .../bookmark_change_processor.cc | 4 +-- .../bookmark_change_processor.h | 6 ++-- .../brave_profile_sync_service_impl.cc | 34 ++++++++++++------- .../brave_profile_sync_service_impl.h | 9 ++--- .../public/brave_profile_sync_service.h | 18 +++++----- components/brave_sync/syncer_helper.cc | 2 +- ...-save_card_bubble_controller_impl.cc.patch | 12 ------- 11 files changed, 65 insertions(+), 59 deletions(-) delete mode 100644 chromium_src/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc delete mode 100644 patches/chrome-browser-ui-autofill-payments-save_card_bubble_controller_impl.cc.patch diff --git a/chromium_src/chrome/browser/ui/autofill/payments/brave_save_card_bubble_controller_impl_browsertest.cc b/chromium_src/chrome/browser/ui/autofill/payments/brave_save_card_bubble_controller_impl_browsertest.cc index 14352c1eca23..79d69704e269 100644 --- a/chromium_src/chrome/browser/ui/autofill/payments/brave_save_card_bubble_controller_impl_browsertest.cc +++ b/chromium_src/chrome/browser/ui/autofill/payments/brave_save_card_bubble_controller_impl_browsertest.cc @@ -5,11 +5,14 @@ #include #include "base/macros.h" +#include "brave/components/brave_sync/brave_sync_prefs.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" +#include "components/prefs/pref_service.h" #include "testing/gtest/include/gtest/gtest.h" class BraveSaveCardBubbleControllerImplTest : public InProcessBrowserTest { @@ -28,6 +31,11 @@ class BraveSaveCardBubbleControllerImplTest : public InProcessBrowserTest { controller_->ShowBubbleForSignInPromo(); } + void EnableBraveSync(PrefService* pref) { + pref->SetBoolean(brave_sync::prefs::kSyncEnabled, true); + pref->SetInteger(brave_sync::prefs::kSyncMigrateBookmarksVersion, 2); + } + autofill::SaveCardBubbleControllerImpl* controller() { return controller_; } private: @@ -38,7 +46,15 @@ class BraveSaveCardBubbleControllerImplTest : public InProcessBrowserTest { // Tests that requesting to open signin promo bubble doesn't result in the // bubble being shown. -IN_PROC_BROWSER_TEST_F(BraveSaveCardBubbleControllerImplTest, NoSignInPromo) { +IN_PROC_BROWSER_TEST_F(BraveSaveCardBubbleControllerImplTest, + NoSignInPromoBraveSyncDisabled) { + ShowUi(); + EXPECT_EQ(nullptr, controller()->save_card_bubble_view()); +} + +IN_PROC_BROWSER_TEST_F(BraveSaveCardBubbleControllerImplTest, + NoSignInPromoBraveSyncEnabled) { + EnableBraveSync(browser()->profile()->GetPrefs()); ShowUi(); EXPECT_EQ(nullptr, controller()->save_card_bubble_view()); } diff --git a/chromium_src/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc b/chromium_src/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc deleted file mode 100644 index e5fbd0978788..000000000000 --- a/chromium_src/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc +++ /dev/null @@ -1,12 +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 "../../../../../../../chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.h" - -#define BRAVE_SHOULD_SHOW_SIGNIN_PROMO_SHORT_CIRCUIT_TO_FALSE \ -return false; - -#include "../../../../../../../chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc" // NOLINT -#undef BRAVE_SHOULD_SHOW_SIGNIN_PROMO_SHORT_CIRCUIT_TO_FALSE diff --git a/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h b/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h index 61aa99fb8f2f..cf0fd44ffd23 100644 --- a/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h +++ b/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h @@ -10,7 +10,8 @@ #define BRAVE_SYNC_CYCLE_DELEGATE_H \ virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) {} \ -virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) {} +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 diff --git a/chromium_src/components/sync/syncable/write_transaction.h b/chromium_src/components/sync/syncable/write_transaction.h index 6c9d2657414a..8add792f4aa1 100644 --- a/chromium_src/components/sync/syncable/write_transaction.h +++ b/chromium_src/components/sync/syncable/write_transaction.h @@ -8,10 +8,10 @@ #define BRAVE_SYNC_ATTACHABLE_WRITE_TRANSACTION_H \ public: \ - WriteTransaction(const base::Location& from_here, UserShare* share, \ - syncable::WriteTransaction* syncable_wr_tr); \ + WriteTransaction(const base::Location& from_here, UserShare* share, \ + syncable::WriteTransaction* syncable_wr_tr); \ private: \ - bool keep_ = false; + bool keep_ = false; #include "../../../../../components/sync/syncable/write_transaction.h" #undef BRAVE_SYNC_ATTACHABLE_WRITE_TRANSACTION_H diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 731e5efc4686..35e5958a8828 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -74,8 +74,8 @@ syncer::SyncError BookmarkChangeProcessor::UpdateChildrenPositions( syncer::SyncError::DATATYPE_ERROR, "Failed to init sync node from chrome node", syncer::BOOKMARKS); - // TODO(AlexeyBarabash): pull unrecoverable_error_handler_ - // from BookmarkModelAssociator + // TODO(AlexeyBarabash): pull unrecoverable_error_handler_ + // from BookmarkModelAssociator // unrecoverable_error_handler_->OnUnrecoverableError(error); DCHECK(false) << "[BraveSync] " << __func__ << " Failed to init sync node from chrome node"; diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.h b/chromium_src/components/sync_bookmarks/bookmark_change_processor.h index 15fe6171d725..8f3a14e99b79 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.h +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.h @@ -3,8 +3,8 @@ * 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_BOOKMARKS_BOOKMARKS_CHANGE_PROCESSOR_H_ -#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARKS_CHANGE_PROCESSOR_H_ +#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ #define BRAVE_SYNC_REPOSITION_METHODS \ @@ -17,4 +17,4 @@ void MakeRepositionAndUpdateSyncNodes( \ #include "../../../../../components/sync_bookmarks/bookmark_change_processor.h" -#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARKS_CHANGE_PROCESSOR_H_ +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index 801f1cc4f0d9..bb751d3c219a 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -259,8 +259,8 @@ void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() {} -void BraveProfileSyncServiceImpl::OnSetupSyncHaveCode(const std::string& sync_words, - const std::string& device_name) { +void BraveProfileSyncServiceImpl::OnSetupSyncHaveCode( + const std::string& sync_words, const std::string& device_name) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); if (sync_words.empty()) { OnSyncSetupError("ERR_SYNC_WRONG_WORDS"); @@ -363,12 +363,14 @@ std::string BraveProfileSyncServiceImpl::GetSeed() { return brave_sync_prefs_->GetSeed(); } -void BraveProfileSyncServiceImpl::OnSetSyncEnabled(const bool sync_this_device) { +void BraveProfileSyncServiceImpl::OnSetSyncEnabled( + const bool sync_this_device) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); brave_sync_prefs_->SetSyncEnabled(sync_this_device); } -void BraveProfileSyncServiceImpl::OnSetSyncBookmarks(const bool sync_bookmarks) { +void BraveProfileSyncServiceImpl::OnSetSyncBookmarks( + const bool sync_bookmarks) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); syncer::UserSelectableTypeSet type_set = ProfileSyncService::GetUserSettings()->GetSelectedTypes(); @@ -409,7 +411,8 @@ void BraveProfileSyncServiceImpl::OnSyncSetupError(const std::string& error) { NotifySyncSetupError(error); } -void BraveProfileSyncServiceImpl::OnGetInitData(const std::string& sync_version) { +void BraveProfileSyncServiceImpl::OnGetInitData( + const std::string& sync_version) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); Uint8Array seed; @@ -517,7 +520,8 @@ void BraveProfileSyncServiceImpl::OnSyncReady() { } } -syncer::ModelTypeSet BraveProfileSyncServiceImpl::GetPreferredDataTypes() const { +syncer::ModelTypeSet +BraveProfileSyncServiceImpl::GetPreferredDataTypes() const { // Force DEVICE_INFO type to have nudge cycle each time to fetch // Brave sync devices. // Will be picked up by ProfileSyncService::ConfigureDataTypeManager @@ -572,7 +576,7 @@ void BraveProfileSyncServiceImpl::OnDeletedSyncUser() { NOTIMPLEMENTED(); } -void BraveProfileSyncServiceImpl::OnDeleteSyncSiteSettings() { +void BraveProfileSyncServiceImpl::OnDeleteSyncSiteSettings() { NOTIMPLEMENTED(); } @@ -584,7 +588,8 @@ void BraveProfileSyncServiceImpl::OnSaveBookmarksBaseOrder( OnSyncReady(); } -void BraveProfileSyncServiceImpl::OnSyncWordsPrepared(const std::string& words) { +void BraveProfileSyncServiceImpl::OnSyncWordsPrepared( + const std::string& words) { NotifyHaveSyncWords(words); } @@ -596,11 +601,14 @@ int BraveProfileSyncServiceImpl::GetDisableReasons() const { if (IsBraveSyncEnabled() && brave_sync_prefs_->GetMigratedBookmarksVersion() >= 2) return syncer::SyncService::DISABLE_REASON_NONE; - // kSyncManaged is disabled by us + // kSyncManaged is set by Brave, so it will return + // DISABLE_REASON_ENTERPRISE_POLICY and + // SaveCardBubbleControllerImpl::ShouldShowSignInPromo will return false. return ProfileSyncService::GetDisableReasons(); } -CoreAccountInfo BraveProfileSyncServiceImpl::GetAuthenticatedAccountInfo() const { +CoreAccountInfo +BraveProfileSyncServiceImpl::GetAuthenticatedAccountInfo() const { return GetDummyAccountInfo(); } @@ -613,7 +621,8 @@ void BraveProfileSyncServiceImpl::Shutdown() { syncer::ProfileSyncService::Shutdown(); } -void BraveProfileSyncServiceImpl::NotifySyncSetupError(const std::string& error) { +void BraveProfileSyncServiceImpl::NotifySyncSetupError( + const std::string& error) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); for (auto& observer : BraveSyncService::observers_) observer.OnSyncSetupError(this, error); @@ -772,7 +781,8 @@ void BraveProfileSyncServiceImpl::OnResolvedPreferences( } } -void BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged(const std::string& pref) { +void BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged( + const std::string& pref) { if (pref == prefs::kSyncEnabled) { brave_sync_client_->OnSyncEnabledChanged(); if (!brave_sync_prefs_->GetSyncEnabled()) { diff --git a/components/brave_sync/brave_profile_sync_service_impl.h b/components/brave_sync/brave_profile_sync_service_impl.h index b22bbd0de42b..7553b653946d 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -8,6 +8,7 @@ #include #include +#include #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" @@ -42,11 +43,11 @@ class Prefs; } // namespace prefs class BraveProfileSyncServiceImpl : public BraveProfileSyncService, - //public syncer::ProfileSyncService, - public BraveSyncService, - public SyncMessageHandler { + public BraveSyncService, + public SyncMessageHandler { public: - explicit BraveProfileSyncServiceImpl(Profile* profile, InitParams init_params); + explicit BraveProfileSyncServiceImpl(Profile* profile, + InitParams init_params); ~BraveProfileSyncServiceImpl() override; diff --git a/components/brave_sync/public/brave_profile_sync_service.h b/components/brave_sync/public/brave_profile_sync_service.h index a233527f8cd9..71fc942ac1a3 100644 --- a/components/brave_sync/public/brave_profile_sync_service.h +++ b/components/brave_sync/public/brave_profile_sync_service.h @@ -6,6 +6,8 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SYNC_PUBLIC_BRAVE_PROFILE_SYNC_SERVICE_H_ #define BRAVE_COMPONENTS_BRAVE_SYNC_PUBLIC_BRAVE_PROFILE_SYNC_SERVICE_H_ +#include + #include "brave/components/brave_sync/jslib_messages_fwd.h" #include "components/sync/driver/profile_sync_service.h" @@ -19,16 +21,16 @@ class BraveSyncService; class BraveProfileSyncService : public syncer::ProfileSyncService { public: - BraveProfileSyncService(InitParams init_params) : - syncer::ProfileSyncService(std::move(init_params)) {} - ~BraveProfileSyncService() override {} + explicit BraveProfileSyncService(InitParams init_params) : + syncer::ProfileSyncService(std::move(init_params)) {} + ~BraveProfileSyncService() override {} - virtual bool IsBraveSyncEnabled() const = 0; - virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) = 0; - virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, - base::WaitableEvent* wevent) = 0; + virtual bool IsBraveSyncEnabled() const = 0; + virtual void OnNudgeSyncCycle(brave_sync::RecordsListPtr records_list) = 0; + virtual void OnPollSyncCycle(brave_sync::GetRecordsCallback cb, + base::WaitableEvent* wevent) = 0; - virtual BraveSyncService* GetSyncService() const = 0; + virtual BraveSyncService* GetSyncService() const = 0; }; } // namespace brave_sync diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index c82cb6875f79..0e9d355bf67d 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -62,7 +62,7 @@ uint64_t GetIndexByCompareOrderStartFrom( std::string src_order; src->GetMetaInfo("order", &src_order); DCHECK(!src_order.empty()); - DCHECK(index >= 0); + DCHECK_GE(index, 0); while (index < parent->child_count()) { const bookmarks::BookmarkNode* node = parent->GetChild(index); std::string node_order; diff --git a/patches/chrome-browser-ui-autofill-payments-save_card_bubble_controller_impl.cc.patch b/patches/chrome-browser-ui-autofill-payments-save_card_bubble_controller_impl.cc.patch deleted file mode 100644 index 1a40958d1b32..000000000000 --- a/patches/chrome-browser-ui-autofill-payments-save_card_bubble_controller_impl.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc b/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc -index e576d1a0a1f331679c586ef63a17c38063501611..c308f33b68f0f011523798cde65f36f668b187a4 100644 ---- a/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc -+++ b/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc -@@ -437,6 +437,7 @@ bool SaveCardBubbleControllerImpl::ShouldRequestExpirationDateFromUser() const { - } - - bool SaveCardBubbleControllerImpl::ShouldShowSignInPromo() const { -+ BRAVE_SHOULD_SHOW_SIGNIN_PROMO_SHORT_CIRCUIT_TO_FALSE; - if (is_upload_save_) - return false; - From 7fcee9d29bb59e4ed25315fbe19ddadef145be1d Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 17 Jul 2019 11:00:06 -0700 Subject: [PATCH 54/73] Fix enable_brave_sync=false Remove unused code --- ...rave_content_browser_client_browsertest.cc | 5 +++ browser/extensions/BUILD.gn | 11 ++++--- ...ve_component_extension_resource_manager.cc | 10 ++++-- .../ui/brave_browser_command_controller.cc | 3 ++ browser/ui/toolbar/brave_app_menu_model.cc | 29 ++++++++-------- .../brave_app_menu_model_browsertest.cc | 33 ++++++++++++------- .../sync/profile_sync_service_factory.cc | 18 +++++++++- .../sync/driver/profile_sync_service.cc | 6 ++++ .../bookmark_local_changes_builder.cc | 8 ----- common/extensions/api/BUILD.gn | 8 ++++- components/brave_sync/BUILD.gn | 22 +++++++------ .../brave_profile_sync_service_impl.cc | 4 +-- .../brave_sync/client/client_ext_impl_data.cc | 2 -- test/BUILD.gn | 19 ++++++++--- 14 files changed, 116 insertions(+), 62 deletions(-) delete mode 100644 chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc diff --git a/browser/brave_content_browser_client_browsertest.cc b/browser/brave_content_browser_client_browsertest.cc index d29f4076eedc..f4f794208574 100644 --- a/browser/brave_content_browser_client_browsertest.cc +++ b/browser/brave_content_browser_client_browsertest.cc @@ -13,6 +13,7 @@ #include "brave/common/pref_names.h" #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" +#include "brave/components/brave_sync/buildflags/buildflags.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/extension_service.h" @@ -153,7 +154,9 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadCustomBravePages) { #if BUILDFLAG(BRAVE_REWARDS_ENABLED) "rewards", #endif +#if BUILDFLAG(ENABLE_BRAVE_SYNC) chrome::kChromeUISyncHost, +#endif }; std::vector schemes { @@ -205,6 +208,7 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadAboutHost) { } } +#if BUILDFLAG(ENABLE_BRAVE_SYNC) IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, RewriteChromeSyncInternals) { std::vector schemes { @@ -230,6 +234,7 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, "chrome://sync/"); } } +#endif IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, RewriteWelcomeWin10Host) { diff --git a/browser/extensions/BUILD.gn b/browser/extensions/BUILD.gn index fd00c298c175..d20e26091399 100644 --- a/browser/extensions/BUILD.gn +++ b/browser/extensions/BUILD.gn @@ -18,10 +18,6 @@ source_set("extensions") { "api/brave_rewards_api.h", "api/brave_shields_api.cc", "api/brave_shields_api.h", - "api/brave_sync_api.cc", - "api/brave_sync_api.h", - "api/brave_sync_event_router.cc", - "api/brave_sync_event_router.h", "api/brave_theme_api.cc", "api/brave_theme_api.h", "api/settings_private/brave_prefs_util.cc", @@ -82,6 +78,13 @@ source_set("extensions") { ] } if (enable_brave_sync) { + sources += [ + "api/brave_sync_api.cc", + "api/brave_sync_api.h", + "api/brave_sync_event_router.cc", + "api/brave_sync_event_router.h", + ] + deps += [ "//brave/components/brave_sync", "//brave/components/brave_sync:generated_resources", diff --git a/browser/extensions/brave_component_extension_resource_manager.cc b/browser/extensions/brave_component_extension_resource_manager.cc index ce3c61f4fda7..9ab64749374f 100644 --- a/browser/extensions/brave_component_extension_resource_manager.cc +++ b/browser/extensions/brave_component_extension_resource_manager.cc @@ -8,8 +8,7 @@ #include "brave/components/brave_extension/grit/brave_extension_generated_map.h" #include "brave/components/brave_extension/grit/brave_extension_resources_map.h" #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" -#include "brave/components/brave_sync/grit/brave_sync_generated_map.h" -#include "brave/components/brave_sync/grit/brave_sync_resources_map.h" +#include "brave/components/brave_sync/buildflags/buildflags.h" #include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources_map.h" #include "brave/components/brave_webtorrent/grit/brave_webtorrent_generated_map.h" @@ -18,6 +17,11 @@ #include "brave/components/brave_rewards/resources/extension/grit/brave_rewards_panel_generated_map.h" #endif +#if BUILDFLAG(ENABLE_BRAVE_SYNC) +#include "brave/components/brave_sync/grit/brave_sync_generated_map.h" +#include "brave/components/brave_sync/grit/brave_sync_resources_map.h" +#endif + namespace extensions { BraveComponentExtensionResourceManager:: @@ -38,6 +42,7 @@ BraveComponentExtensionResourceManager() { kBraveRewardsPanelGenerated, kBraveRewardsPanelGeneratedSize); #endif +#if BUILDFLAG(ENABLE_BRAVE_SYNC) AddComponentResourceEntries( kBraveSyncResources, kBraveSyncResourcesSize); @@ -45,6 +50,7 @@ BraveComponentExtensionResourceManager() { AddComponentResourceEntries( kBraveSyncGenerated, kBraveSyncGeneratedSize); +#endif AddComponentResourceEntries( kBraveWebtorrentResources, diff --git a/browser/ui/brave_browser_command_controller.cc b/browser/ui/brave_browser_command_controller.cc index 4e91385538f8..ffcec513be07 100644 --- a/browser/ui/brave_browser_command_controller.cc +++ b/browser/ui/brave_browser_command_controller.cc @@ -9,6 +9,7 @@ #include "brave/browser/tor/buildflags.h" #include "brave/browser/ui/brave_pages.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 "brave/browser/ui/browser_commands.h" #include "brave/common/brave_switches.h" @@ -91,8 +92,10 @@ void BraveBrowserCommandController::InitBraveCommandState() { #if BUILDFLAG(BRAVE_WALLET_ENABLED) UpdateCommandForBraveWallet(); #endif +#if BUILDFLAG(ENABLE_BRAVE_SYNC) if (switches::IsBraveSyncAllowedByFlag()) UpdateCommandForBraveSync(); +#endif } UpdateCommandForBraveAdblock(); #if BUILDFLAG(ENABLE_TOR) diff --git a/browser/ui/toolbar/brave_app_menu_model.cc b/browser/ui/toolbar/brave_app_menu_model.cc index 76f6e40fcac9..b287cbc2f219 100644 --- a/browser/ui/toolbar/brave_app_menu_model.cc +++ b/browser/ui/toolbar/brave_app_menu_model.cc @@ -7,7 +7,6 @@ #include "brave/app/brave_command_ids.h" #include "brave/browser/profiles/profile_util.h" -#include "brave/common/brave_switches.h" #include "brave/grit/brave_generated_resources.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/profiles/profile.h" @@ -37,22 +36,20 @@ void BraveAppMenuModel::InsertBraveMenuItems() { GetIndexOfCommandId(IDC_SHOW_DOWNLOADS), IDC_SHOW_BRAVE_REWARDS, IDS_SHOW_BRAVE_REWARDS); - #if BUILDFLAG(BRAVE_WALLET_ENABLED) - InsertItemWithStringIdAt( - GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS), - IDC_SHOW_BRAVE_WALLET, - IDS_SHOW_BRAVE_WALLET); - #endif - if (switches::IsBraveSyncAllowedByFlag()) { +#if BUILDFLAG(BRAVE_WALLET_ENABLED) + InsertItemWithStringIdAt( + GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS), + IDC_SHOW_BRAVE_WALLET, + IDS_SHOW_BRAVE_WALLET); +#endif InsertItemWithStringIdAt( - #if BUILDFLAG(BRAVE_WALLET_ENABLED) - GetIndexOfCommandId(IDC_SHOW_BRAVE_WALLET), - #else - GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS), - #endif - IDC_SHOW_BRAVE_SYNC, - IDS_SHOW_BRAVE_SYNC); - } +#if BUILDFLAG(BRAVE_WALLET_ENABLED) + GetIndexOfCommandId(IDC_SHOW_BRAVE_WALLET), +#else + GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS), +#endif + IDC_SHOW_BRAVE_SYNC, + IDS_SHOW_BRAVE_SYNC); } // Insert Create New Profile item diff --git a/browser/ui/toolbar/brave_app_menu_model_browsertest.cc b/browser/ui/toolbar/brave_app_menu_model_browsertest.cc index 4d37166dbd7b..c8f68ab3bb36 100644 --- a/browser/ui/toolbar/brave_app_menu_model_browsertest.cc +++ b/browser/ui/toolbar/brave_app_menu_model_browsertest.cc @@ -19,6 +19,7 @@ #include "content/public/browser/notification_service.h" #include "content/public/test/test_utils.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" using BraveAppMenuBrowserTest = InProcessBrowserTest; @@ -32,26 +33,30 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, BasicTest) { // -1 means |model| doesn't have passed command id. EXPECT_NE(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS)); EXPECT_NE(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC)); - #if BUILDFLAG(BRAVE_WALLET_ENABLED) +#if BUILDFLAG(BRAVE_WALLET_ENABLED) EXPECT_NE(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_WALLET)); - #else +#else EXPECT_EQ(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_WALLET)); - #endif +#endif auto* command_controller = browser()->command_controller(); - #if BUILDFLAG(BRAVE_REWARDS_ENABLED) +#if BUILDFLAG(BRAVE_REWARDS_ENABLED) EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_REWARDS)); - #else +#else EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_REWARDS)); - #endif +#endif +#if BUILDFLAG(ENABLE_BRAVE_SYNC) 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) +#if BUILDFLAG(BRAVE_WALLET_ENABLED) EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_WALLET)); - #else +#else EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_WALLET)); - #endif +#endif // Create proviate browser. auto* private_browser = CreateIncognitoBrowser(); @@ -67,12 +72,16 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, BasicTest) { EXPECT_NE(-1, private_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC)); command_controller = private_browser->command_controller(); - #if BUILDFLAG(BRAVE_REWARDS_ENABLED) +#if BUILDFLAG(BRAVE_REWARDS_ENABLED) EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_REWARDS)); - #else +#else EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_REWARDS)); - #endif +#endif +#if BUILDFLAG(ENABLE_BRAVE_SYNC) EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC)); +#else + EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC)); +#endif content::WindowedNotificationObserver browser_creation_observer( chrome::NOTIFICATION_BROWSER_OPENED, diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index e4d35a8a5fee..dfb1d85e0c01 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -20,6 +20,22 @@ std::unique_ptr BraveBuildServiceInstanceFor( #if BUILDFLAG(ENABLE_BRAVE_SYNC) #include "brave/components/brave_sync/brave_profile_sync_service_impl.h" using brave_sync::BraveProfileSyncServiceImpl; +#else +namespace { +class BraveProfileSyncService : public syncer::ProfileSyncService { + public: + explicit BraveProfileSyncService(InitParams init_params) : + syncer::ProfileSyncService(std::move(init_params)) {} + ~BraveProfileSyncService() override {} + + // syncer::SyncService implementation + CoreAccountInfo GetAuthenticatedAccountInfo() const override { + AccountInfo account_info; + account_info.account_id = "dummy_account_id"; + return std::move(account_info); + } +}; +} // namespace #endif namespace { @@ -31,7 +47,7 @@ std::unique_ptr BraveBuildServiceInstanceFor( return std::make_unique(profile, std::move(init_params)); #else - return std::make_unique(std::move(init_params)); + return std::make_unique(std::move(init_params)); #endif } diff --git a/chromium_src/components/sync/driver/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc index ec397d7bc4df..91750d28ae84 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -72,8 +72,14 @@ void BraveInit( // 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_bookmarks/bookmark_local_changes_builder.cc b/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc deleted file mode 100644 index 04d81814ca2f..000000000000 --- a/chromium_src/components/sync_bookmarks/bookmark_local_changes_builder.cc +++ /dev/null @@ -1,8 +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/. */ - -// This override is for kSyncUSSBookmarks -#include "brave/components/brave_sync/syncer_helper.h" -#include "../../../../components/sync_bookmarks/bookmark_local_changes_builder.cc" // NOLINT diff --git a/common/extensions/api/BUILD.gn b/common/extensions/api/BUILD.gn index 6ad6de775a0d..b18c7223b851 100644 --- a/common/extensions/api/BUILD.gn +++ b/common/extensions/api/BUILD.gn @@ -1,3 +1,4 @@ +import("//brave/components/brave_sync/buildflags/buildflags.gni") import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni") import("//tools/json_schema_compiler/json_features.gni") import("//tools/json_schema_compiler/json_schema_api.gni") @@ -51,9 +52,14 @@ brave_extensions_api_schema_sources = [ "brave_rewards.json", "brave_theme.json", "rewards_notifications.json", - "brave_sync.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/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 05b778b58c6d..3c19e7c3e71e 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -72,11 +72,17 @@ source_set("public") { ] deps = [ - ":jslib_messages", - "buildflags", - "//brave/common:switches", - "//brave/components/brave_sync:core", + "buildflags", ] + + if (enable_brave_sync) { + deps += [ + ":core", + # For IsBraveSyncAllowedByFlag in + # components/sync/driver/sync_driver_switches.cc + "//brave/common:switches", + ] + } } source_set("core") { @@ -97,6 +103,7 @@ source_set("core") { ":jslib_messages", ":prefs", "//base", + "//components/bookmarks/browser", "//crypto", "//extensions/buildflags", ] @@ -111,11 +118,6 @@ source_set("brave_sync") { ":core", "buildflags", "//base", - "//components/bookmarks/browser", - "//components/keyed_service/content", - "//components/keyed_service/core", - "//components/pref_registry", - "//content/public/browser", ] if (enable_brave_sync) { @@ -169,7 +171,7 @@ repack("resources") { output = "$root_gen_dir/brave/components/brave_sync/brave_sync_resources.pak" } -if (!is_android) { +if (enable_brave_sync) { source_set("testutil") { testonly = true diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index bb751d3c219a..1180dd59a6cf 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -601,8 +601,8 @@ int BraveProfileSyncServiceImpl::GetDisableReasons() const { if (IsBraveSyncEnabled() && brave_sync_prefs_->GetMigratedBookmarksVersion() >= 2) return syncer::SyncService::DISABLE_REASON_NONE; - // kSyncManaged is set by Brave, so it will return - // DISABLE_REASON_ENTERPRISE_POLICY and + // kSyncManaged is set by Brave and GetAuthenticatedAccountInfo is not empty, + // so it will return DISABLE_REASON_ENTERPRISE_POLICY exclusively and // SaveCardBubbleControllerImpl::ShouldShowSignInPromo will return false. return ProfileSyncService::GetDisableReasons(); } diff --git a/components/brave_sync/client/client_ext_impl_data.cc b/components/brave_sync/client/client_ext_impl_data.cc index bdc1d4e88156..74fe25698345 100644 --- a/components/brave_sync/client/client_ext_impl_data.cc +++ b/components/brave_sync/client/client_ext_impl_data.cc @@ -56,7 +56,6 @@ std::unique_ptr FromExtSiteSetting( } CHECK_AND_ASSIGN(zoomLevel, zoom_level); CHECK_AND_ASSIGN(shieldsUp, shields_up); - // DCHECK(false); // site_setting-> = ext_site_setting.ad_control; // site_setting-> = ext_site_setting.cookie_control; CHECK_AND_ASSIGN(safeBrowsing, safe_browsing); @@ -182,7 +181,6 @@ std::unique_ptr FromLibSiteSetting( ext_site_setting->shields_up.reset(new bool (lib_site_setting.shieldsUp)); // ext_site_setting->ad_control = lib_site_setting.adControl; // ext_site_setting->cookie_control = lib_site_setting.cookieControl; - // DCHECK(false); ext_site_setting->safe_browsing.reset( new bool(lib_site_setting.safeBrowsing)); ext_site_setting->no_script.reset(new bool(lib_site_setting.noScript)); diff --git a/test/BUILD.gn b/test/BUILD.gn index 63ccfcb73d8e..4b8185c210ab 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -3,6 +3,7 @@ import("//brave/browser/tor/buildflags/buildflags.gni") import("//brave/browser/translate/buildflags/buildflags.gni") import("//brave/components/brave_ads/browser/buildflags/buildflags.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("//testing/test.gni") import("//third_party/widevine/cdm/widevine.gni") @@ -91,9 +92,6 @@ test("brave_unit_tests") { "//brave/components/brave_shields/browser/ad_block_regional_service_unittest.cc", "//brave/components/brave_shields/browser/brave_shields_util_unittest.cc", "//brave/components/brave_shields/browser/https_everywhere_recently_used_cache_unittest.cpp", - "//brave/components/brave_sync/bookmark_order_util_unittest.cc", - "//brave/components/brave_sync/brave_sync_service_unittest.cc", - "//brave/components/brave_sync/syncer_helper_unittest.cc", "//brave/components/brave_webtorrent/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc", "//brave/components/invalidation/fcm_unittest.cc", "//brave/components/gcm_driver/gcm_unittest.cc", @@ -171,6 +169,14 @@ test("brave_unit_tests") { ] } + if (enable_brave_sync) { + sources += [ + "//brave/components/brave_sync/bookmark_order_util_unittest.cc", + "//brave/components/brave_sync/brave_sync_service_unittest.cc", + "//brave/components/brave_sync/syncer_helper_unittest.cc", + ] + } + if (enable_tor) { sources += [ "//brave/browser/profiles/tor_unittest_profile_manager.cc", @@ -227,7 +233,6 @@ test("brave_unit_tests") { deps = [ "//brave/components/brave_rewards/browser:testutil", "//brave/components/brave_ads/browser:testutil", - "//brave/components/brave_sync:testutil", "//brave/vendor/bat-native-rapidjson", "//brave/vendor/brave_base", "//chrome:browser_dependencies", @@ -258,6 +263,12 @@ test("brave_unit_tests") { configs += [ "//brave/vendor/bat-native-confirmations:internal_config" ] } + if (enable_brave_sync) { + deps += [ + "//brave/components/brave_sync:testutil", + ] + } + if (bundle_widevine_cdm) { sources += [ "//brave/browser/widevine/brave_widevine_bundle_manager_unittest.cc", From c3fc745a3dce7f445a0f0e9b038582a677d09ba9 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 17 Jul 2019 15:44:22 -0700 Subject: [PATCH 55/73] Check DISABLE_REASON_ENTERPRISE_POLICY in ShouldShowSignInPromo and fix GetDisableReasons unittest --- .../sync/profile_sync_service_factory.cc | 18 +----------------- ..._card_bubble_controller_impl_browsertest.cc | 12 ++++++++++++ .../save_card_bubble_controller_impl.cc | 13 +++++++++++++ .../brave_profile_sync_service_impl.cc | 4 ++-- .../brave_sync/brave_sync_service_unittest.cc | 13 +++++++++---- ...s-save_card_bubble_controller_impl.cc.patch | 12 ++++++++++++ 6 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 chromium_src/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc create mode 100644 patches/chrome-browser-ui-autofill-payments-save_card_bubble_controller_impl.cc.patch diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index dfb1d85e0c01..e4d35a8a5fee 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -20,22 +20,6 @@ std::unique_ptr BraveBuildServiceInstanceFor( #if BUILDFLAG(ENABLE_BRAVE_SYNC) #include "brave/components/brave_sync/brave_profile_sync_service_impl.h" using brave_sync::BraveProfileSyncServiceImpl; -#else -namespace { -class BraveProfileSyncService : public syncer::ProfileSyncService { - public: - explicit BraveProfileSyncService(InitParams init_params) : - syncer::ProfileSyncService(std::move(init_params)) {} - ~BraveProfileSyncService() override {} - - // syncer::SyncService implementation - CoreAccountInfo GetAuthenticatedAccountInfo() const override { - AccountInfo account_info; - account_info.account_id = "dummy_account_id"; - return std::move(account_info); - } -}; -} // namespace #endif namespace { @@ -47,7 +31,7 @@ std::unique_ptr BraveBuildServiceInstanceFor( return std::make_unique(profile, std::move(init_params)); #else - return std::make_unique(std::move(init_params)); + return std::make_unique(std::move(init_params)); #endif } diff --git a/chromium_src/chrome/browser/ui/autofill/payments/brave_save_card_bubble_controller_impl_browsertest.cc b/chromium_src/chrome/browser/ui/autofill/payments/brave_save_card_bubble_controller_impl_browsertest.cc index 79d69704e269..e541c493187c 100644 --- a/chromium_src/chrome/browser/ui/autofill/payments/brave_save_card_bubble_controller_impl_browsertest.cc +++ b/chromium_src/chrome/browser/ui/autofill/payments/brave_save_card_bubble_controller_impl_browsertest.cc @@ -13,6 +13,7 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "components/prefs/pref_service.h" +#include "components/sync/base/sync_prefs.h" #include "testing/gtest/include/gtest/gtest.h" class BraveSaveCardBubbleControllerImplTest : public InProcessBrowserTest { @@ -33,9 +34,17 @@ class BraveSaveCardBubbleControllerImplTest : public InProcessBrowserTest { void EnableBraveSync(PrefService* pref) { pref->SetBoolean(brave_sync::prefs::kSyncEnabled, true); + syncer::SyncPrefs sync_prefs(pref); + sync_prefs.SetSyncRequested(true); pref->SetInteger(brave_sync::prefs::kSyncMigrateBookmarksVersion, 2); } + void DisableBraveSync(PrefService* pref) { + pref->SetBoolean(brave_sync::prefs::kSyncEnabled, false); + syncer::SyncPrefs sync_prefs(pref); + sync_prefs.SetSyncRequested(false); + } + autofill::SaveCardBubbleControllerImpl* controller() { return controller_; } private: @@ -57,4 +66,7 @@ IN_PROC_BROWSER_TEST_F(BraveSaveCardBubbleControllerImplTest, EnableBraveSync(browser()->profile()->GetPrefs()); ShowUi(); EXPECT_EQ(nullptr, controller()->save_card_bubble_view()); + DisableBraveSync(browser()->profile()->GetPrefs()); + ShowUi(); + EXPECT_EQ(nullptr, controller()->save_card_bubble_view()); } diff --git a/chromium_src/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc b/chromium_src/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc new file mode 100644 index 000000000000..bf80b25023a3 --- /dev/null +++ b/chromium_src/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc @@ -0,0 +1,13 @@ +/* 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 CHECK_SYNC_POLICY \ + if (sync_service && sync_service->HasDisableReason( \ + syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY)) \ + return false; + +#include "../../../../../../../chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc" // NOLINT +#undef CHECK_SYNC_POLICY + diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index 1180dd59a6cf..a19dc5c1ed3e 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -601,8 +601,8 @@ int BraveProfileSyncServiceImpl::GetDisableReasons() const { if (IsBraveSyncEnabled() && brave_sync_prefs_->GetMigratedBookmarksVersion() >= 2) return syncer::SyncService::DISABLE_REASON_NONE; - // kSyncManaged is set by Brave and GetAuthenticatedAccountInfo is not empty, - // so it will return DISABLE_REASON_ENTERPRISE_POLICY exclusively and + // kSyncManaged is set by Brave so it will contain + // DISABLE_REASON_ENTERPRISE_POLICY and // SaveCardBubbleControllerImpl::ShouldShowSignInPromo will return false. return ProfileSyncService::GetDisableReasons(); } diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 28cac656f9e3..3260572d6a3e 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -663,6 +663,7 @@ TEST_F(BraveSyncServiceTest, StartSyncNonDeviceRecords) { } TEST_F(BraveSyncServiceTest, OnSyncReadyNewToSync) { + sync_prefs()->SetSyncRequested(false); EXPECT_CALL(*observer(), OnSyncStateChanged); EXPECT_CALL(*sync_client(), SendGetBookmarksBaseOrder).Times(1); sync_service()->OnSyncReady(); @@ -763,12 +764,16 @@ TEST_F(BraveSyncServiceTest, GetPreferredDataTypes) { } TEST_F(BraveSyncServiceTest, GetDisableReasons) { - EXPECT_NE(sync_service()->GetDisableReasons(), - syncer::SyncService::DISABLE_REASON_NONE); + sync_prefs()->SetManagedForTest(true); + EXPECT_EQ(sync_service()->GetDisableReasons(), + syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY); sync_service()->OnSetSyncEnabled(true); - EXPECT_NE(sync_service()->GetDisableReasons(), - syncer::SyncService::DISABLE_REASON_NONE); + EXPECT_EQ(sync_service()->GetDisableReasons(), + syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY); brave_sync_prefs()->SetMigratedBookmarksVersion(2); EXPECT_EQ(sync_service()->GetDisableReasons(), syncer::SyncService::DISABLE_REASON_NONE); + sync_service()->OnSetSyncEnabled(false); + EXPECT_TRUE(sync_service()->HasDisableReason( + syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY)); } diff --git a/patches/chrome-browser-ui-autofill-payments-save_card_bubble_controller_impl.cc.patch b/patches/chrome-browser-ui-autofill-payments-save_card_bubble_controller_impl.cc.patch new file mode 100644 index 000000000000..681d3033a713 --- /dev/null +++ b/patches/chrome-browser-ui-autofill-payments-save_card_bubble_controller_impl.cc.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc b/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc +index e576d1a0a1f331679c586ef63a17c38063501611..efc02bac3777f2050c2399987c5522422740fa3d 100644 +--- a/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc ++++ b/chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.cc +@@ -442,6 +442,7 @@ bool SaveCardBubbleControllerImpl::ShouldShowSignInPromo() const { + + const syncer::SyncService* sync_service = + ProfileSyncServiceFactory::GetForProfile(GetProfile()); ++ CHECK_SYNC_POLICY + + return !sync_service || + sync_service->HasDisableReason( From 97d0ecaecc920eaec36d12b0b1d948e0922d3b24 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 22 Jul 2019 20:30:58 -0700 Subject: [PATCH 56/73] Passive resend unconfirmed records --- .../brave_profile_sync_service_impl.cc | 120 ++++++++++++------ .../brave_profile_sync_service_impl.h | 8 ++ components/brave_sync/brave_sync_prefs.cc | 23 ++++ components/brave_sync/brave_sync_prefs.h | 7 + 4 files changed, 119 insertions(+), 39 deletions(-) diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index a19dc5c1ed3e..7fc1e0767ee2 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -105,11 +105,24 @@ const bookmarks::BookmarkNode* FindByObjectId(bookmarks::BookmarkModel* model, return nullptr; } +std::unique_ptr CreateDeleteBookmarkByObjectId( + const prefs::Prefs* brave_sync_prefs, + const std::string& object_id) { + auto record = std::make_unique(); + record->deviceId = brave_sync_prefs->GetThisDeviceId(); + record->objectData = jslib_const::SyncObjectData_BOOKMARK; + record->objectId = object_id; + record->action = jslib::SyncRecord::Action::A_DELETE; + record->syncTimestamp = base::Time::Now(); + auto bookmark = std::make_unique(); + record->SetBookmark(std::move(bookmark)); + return record; +} + std::unique_ptr BookmarkNodeToSyncBookmark( bookmarks::BookmarkModel* model, - prefs::Prefs* brave_sync_prefs, - const bookmarks::BookmarkNode* node, - const SyncRecord::Action& action) { + const prefs::Prefs* brave_sync_prefs, + const bookmarks::BookmarkNode* node) { if (node->is_permanent_node() || !node->parent()) return std::unique_ptr(); @@ -156,32 +169,6 @@ std::unique_ptr BookmarkNodeToSyncBookmark( return record; } -void CreateResolveList( - const std::vector>& records, - SyncRecordAndExistingList* records_and_existing_objects, - bookmarks::BookmarkModel* model, - prefs::Prefs* brave_sync_prefs) { - const auto& this_device_id = brave_sync_prefs->GetThisDeviceId(); - for (const auto& record : records) { - // Ignore records from ourselves to avoid mess on merge - if (record->deviceId == this_device_id) { - continue; - } - auto resolved_record = std::make_unique(); - resolved_record->first = SyncRecord::Clone(*record); - auto* node = FindByObjectId(model, record->objectId); - if (node) { - resolved_record->second = BookmarkNodeToSyncBookmark(model, - brave_sync_prefs, - node, - record->action); - } - - records_and_existing_objects->push_back(std::move(resolved_record)); - } -} - - void DoDispatchGetRecordsCallback( GetRecordsCallback cb, std::unique_ptr records) { @@ -252,9 +239,10 @@ void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( return; } SendAndPurgePendingRecords(); - brave_sync_client_->SendSyncRecords( - jslib_const::SyncRecordType_BOOKMARKS, *records); + SendSyncRecords( + jslib_const::SyncRecordType_BOOKMARKS, std::move(records)); } + ResendSyncRecords(jslib_const::SyncRecordType_BOOKMARKS); } BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() {} @@ -545,9 +533,7 @@ void BraveProfileSyncServiceImpl::OnGetExistingObjects( auto records_and_existing_objects = std::make_unique(); CreateResolveList( - *records.get(), records_and_existing_objects.get(), - model_, - brave_sync_prefs_.get()); + *records.get(), records_and_existing_objects.get()); brave_sync_client_->SendResolveSyncRecords( category_name, std::move(records_and_existing_objects)); } @@ -670,6 +656,28 @@ void BraveProfileSyncServiceImpl::SetPermanentNodesOrder( brave_sync_prefs_->SetMigratedBookmarksVersion(2); } +void BraveProfileSyncServiceImpl::CreateResolveList( + const std::vector>& records, + SyncRecordAndExistingList* records_and_existing_objects) { + const auto& this_device_id = brave_sync_prefs_->GetThisDeviceId(); + for (const auto& record : records) { + // Ignore records from ourselves to avoid mess on merge + if (record->deviceId == this_device_id) { + // Remove Acked sent records + brave_sync_prefs_->RemoveFromRecordsToResend(record->objectId); + continue; + } + auto resolved_record = std::make_unique(); + resolved_record->first = SyncRecord::Clone(*record); + auto* node = FindByObjectId(model_, record->objectId); + if (node) { + resolved_record->second = + BookmarkNodeToSyncBookmark(model_, brave_sync_prefs_.get(), node); + } + + records_and_existing_objects->push_back(std::move(resolved_record)); + } +} void BraveProfileSyncServiceImpl::FetchSyncRecords(const bool bookmarks, const bool history, @@ -727,8 +735,8 @@ void BraveProfileSyncServiceImpl::SendDeviceSyncRecord( object_id, static_cast(action), device_id); - brave_sync_client_->SendSyncRecords( - SyncRecordType_PREFERENCES, *records); + SendSyncRecords( + SyncRecordType_PREFERENCES, std::move(records)); } void BraveProfileSyncServiceImpl::OnResolvedPreferences( @@ -848,11 +856,45 @@ BraveSyncService* BraveProfileSyncServiceImpl::GetSyncService() const { } void BraveProfileSyncServiceImpl::SendAndPurgePendingRecords() { - for (const auto& records_to_send : pending_send_records_) { - brave_sync_client_->SendSyncRecords( - jslib_const::SyncRecordType_BOOKMARKS, *records_to_send); + for (auto& records_to_send : pending_send_records_) { + SendSyncRecords( + jslib_const::SyncRecordType_BOOKMARKS, std::move(records_to_send)); } pending_send_records_.clear(); } +void BraveProfileSyncServiceImpl::SendSyncRecords( + const std::string& category_name, + RecordsListPtr records) { + brave_sync_client_->SendSyncRecords(category_name, *records); + if (category_name == kBookmarks) { + for (auto& record : *records) { + brave_sync_prefs_->AddToRecordsToResend(record->objectId); + } + } +} + +void BraveProfileSyncServiceImpl::ResendSyncRecords( + const std::string& category_name) { + if (category_name == kBookmarks) { + RecordsListPtr records = std::make_unique(); + std::vector records_to_resend = + brave_sync_prefs_->GetRecordsToResend(); + if (records_to_resend.empty()) + return; + for (auto& object_id : records_to_resend) { + auto* node = FindByObjectId(model_, object_id); + if (node) { + records->push_back( + BookmarkNodeToSyncBookmark(model_, brave_sync_prefs_.get(), node)); + } else { + records->push_back( + CreateDeleteBookmarkByObjectId(brave_sync_prefs_.get(), object_id)); + } + } + if (!records->empty()) + brave_sync_client_->SendSyncRecords(category_name, *records); + } +} + } // namespace brave_sync diff --git a/components/brave_sync/brave_profile_sync_service_impl.h b/components/brave_sync/brave_profile_sync_service_impl.h index 7553b653946d..07f5ed4da15e 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -151,8 +151,16 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, void SetPermanentNodesOrder(const std::string& base_order); + void CreateResolveList( + const std::vector>& records, + SyncRecordAndExistingList* records_and_existing_objects); + void SendAndPurgePendingRecords(); + void SendSyncRecords(const std::string& category_name, + RecordsListPtr records); + void ResendSyncRecords(const std::string& category_name); + std::unique_ptr brave_sync_prefs_; // True when is in active sync chain bool brave_sync_configured_ = false; diff --git a/components/brave_sync/brave_sync_prefs.cc b/components/brave_sync/brave_sync_prefs.cc index 2425b91ca53e..3fe6a1d6c67f 100644 --- a/components/brave_sync/brave_sync_prefs.cc +++ b/components/brave_sync/brave_sync_prefs.cc @@ -8,6 +8,7 @@ #include "brave/components/brave_sync/settings.h" #include "brave/components/brave_sync/sync_devices.h" #include "components/prefs/pref_service.h" +#include "components/prefs/scoped_user_pref_update.h" #include "components/pref_registry/pref_registry_syncable.h" namespace brave_sync { @@ -28,6 +29,7 @@ const char kSyncDeviceList[] = "brave_sync.device_list"; const char kSyncApiVersion[] = "brave_sync.api_version"; const char kSyncMigrateBookmarksVersion[] = "brave_sync.migrate_bookmarks_version"; +const char kSyncRecordsToResend[] = "brave_sync_records_to_resend"; Prefs::Prefs(PrefService* pref_service) : pref_service_(pref_service) {} @@ -50,6 +52,8 @@ void Prefs::RegisterProfilePrefs( registry->RegisterStringPref(prefs::kSyncDeviceList, std::string()); registry->RegisterStringPref(prefs::kSyncApiVersion, std::string("0")); registry->RegisterIntegerPref(prefs::kSyncMigrateBookmarksVersion, 0); + + registry->RegisterListPref(prefs::kSyncRecordsToResend); } std::string Prefs::GetSeed() const { @@ -186,6 +190,24 @@ void Prefs::SetMigratedBookmarksVersion(const int migrate_bookmarks) { pref_service_->SetInteger(kSyncMigrateBookmarksVersion, migrate_bookmarks); } +std::vector Prefs::GetRecordsToResend() const { + std::vector result; + const base::Value* records = pref_service_->GetList(kSyncRecordsToResend); + for (const base::Value& record : records->GetList()) { + result.push_back(record.GetString()); + } + return result; +} + +void Prefs::AddToRecordsToResend(const std::string& object_id) { + ListPrefUpdate update(pref_service_, kSyncRecordsToResend); + update->GetList().emplace_back(object_id); +} +void Prefs::RemoveFromRecordsToResend(const std::string& object_id) { + ListPrefUpdate update(pref_service_, kSyncRecordsToResend); + base::Erase(update->GetList(), base::Value(object_id)); +} + void Prefs::Clear() { pref_service_->ClearPref(kSyncDeviceId); pref_service_->ClearPref(kSyncSeed); @@ -200,6 +222,7 @@ void Prefs::Clear() { pref_service_->ClearPref(kSyncDeviceList); pref_service_->ClearPref(kSyncApiVersion); pref_service_->ClearPref(kSyncMigrateBookmarksVersion); + pref_service_->ClearPref(kSyncRecordsToResend); } } // namespace prefs diff --git a/components/brave_sync/brave_sync_prefs.h b/components/brave_sync/brave_sync_prefs.h index b3f7380fc575..f4b47b09c376 100644 --- a/components/brave_sync/brave_sync_prefs.h +++ b/components/brave_sync/brave_sync_prefs.h @@ -8,6 +8,7 @@ #include #include +#include #include "base/macros.h" @@ -61,6 +62,8 @@ extern const char kSyncApiVersion[]; // The version of bookmarks state: 0,1,... . // Current to migrate to is 1. extern const char kSyncMigrateBookmarksVersion[]; +// Cached object_id list for unconfirmed records +extern const char kSyncRecordsToResend[]; class Prefs { public: @@ -104,6 +107,10 @@ class Prefs { int GetMigratedBookmarksVersion(); void SetMigratedBookmarksVersion(const int); + std::vector GetRecordsToResend() const; + void AddToRecordsToResend(const std::string& object_id); + void RemoveFromRecordsToResend(const std::string& object_id); + void Clear(); private: From 91e5d05f57b2aa946dd93b2d097955743bff6a7c Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 31 Jul 2019 16:36:18 -0700 Subject: [PATCH 57/73] Sync reset reenable (#3038) --- .../brave_profile_sync_service_impl.cc | 25 ++++++++-- .../brave_profile_sync_service_impl.h | 10 ++++ .../brave_sync/brave_sync_service_unittest.cc | 47 +++++++++---------- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index 7fc1e0767ee2..cf426a601f95 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -260,11 +260,14 @@ void BraveProfileSyncServiceImpl::OnSetupSyncHaveCode( return; } - if (brave_sync_configured_) { + if (IsBraveSyncConfigured()) { NotifyLogMessage("already configured"); return; } + ForceCompleteReset(); + DCHECK(!brave_sync_prefs_->GetSyncEnabled()); + if (device_name.empty()) brave_sync_prefs_->SetThisDeviceName(GetDeviceName()); else @@ -284,11 +287,14 @@ void BraveProfileSyncServiceImpl::OnSetupSyncNewToSync( return; } - if (brave_sync_configured_) { + if (IsBraveSyncConfigured()) { NotifyLogMessage("already configured"); return; } + ForceCompleteReset(); + DCHECK(!brave_sync_prefs_->GetSyncEnabled()); + // If the previous attempt was connect to sync chain // and failed to receive save-init-data brave_sync_words_.clear(); @@ -329,6 +335,7 @@ void BraveProfileSyncServiceImpl::OnResetSync() { // we can reset it by ResetInternal() const std::string device_id = brave_sync_prefs_->GetThisDeviceId(); OnDeleteDevice(device_id); + reseting_ = true; } } @@ -636,6 +643,14 @@ void BraveProfileSyncServiceImpl::ResetSyncInternal() { brave_sync_initialized_ = false; brave_sync_prefs_->SetSyncEnabled(false); + + reseting_ = false; +} + +void BraveProfileSyncServiceImpl::ForceCompleteReset() { + if (reseting_) { + ResetSyncInternal(); + } } void BraveProfileSyncServiceImpl::SetPermanentNodesOrder( @@ -817,7 +832,11 @@ bool BraveProfileSyncServiceImpl::IsBraveSyncInitialized() const { } bool BraveProfileSyncServiceImpl::IsBraveSyncConfigured() const { - return brave_sync_configured_; + return brave_sync_configured_ && + // When there is 0 or 1 device, it means chain is not completely created, + // so we should give a chance to make force reset in |OnSetupSyncHaveCode| + // or in |OnSetupSyncNewToSync| + (brave_sync_prefs_->GetSyncDevices()->size() >= 2); } void BraveProfileSyncServiceImpl::OnPollSyncCycle(GetRecordsCallback cb, diff --git a/components/brave_sync/brave_profile_sync_service_impl.h b/components/brave_sync/brave_profile_sync_service_impl.h index 07f5ed4da15e..c77e19235c84 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -34,6 +34,8 @@ FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncDebug); FORWARD_DECLARE_TEST(BraveSyncServiceTest, StartSyncNonDeviceRecords); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncReadyNewToSync); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnGetExistingObjects); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, + OnSetupSyncHaveCode_Reset_SetupAgain); class BraveSyncServiceTest; @@ -131,6 +133,8 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, StartSyncNonDeviceRecords); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSyncReadyNewToSync); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetExistingObjects); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, + OnSetupSyncHaveCode_Reset_SetupAgain); friend class ::BraveSyncServiceTest; void SignalWaitableEvent(); @@ -148,6 +152,10 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, void NotifyHaveSyncWords(const std::string& sync_words); void ResetSyncInternal(); + void ForceCompleteReset(); + bool GetResettingForTest() const { + return reseting_; + } void SetPermanentNodesOrder(const std::string& base_order); @@ -172,6 +180,8 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, // while being initializing bool brave_sync_initializing_ = false; + bool reseting_ = false; + std::string brave_sync_words_; brave_sync::GetRecordsCallback get_record_cb_; diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index 3260572d6a3e..acc067248fe3 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -690,6 +690,27 @@ TEST_F(BraveSyncServiceTest, OnGetExistingObjects) { false); } +TEST_F(BraveSyncServiceTest, GetPreferredDataTypes) { + // Make sure GetPreferredDataTypes contains DEVICE_INFO which is needed for + // brave device record polling + EXPECT_TRUE(sync_service()->GetPreferredDataTypes().Has(syncer::DEVICE_INFO)); +} + +TEST_F(BraveSyncServiceTest, GetDisableReasons) { + sync_prefs()->SetManagedForTest(true); + EXPECT_EQ(sync_service()->GetDisableReasons(), + syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY); + sync_service()->OnSetSyncEnabled(true); + EXPECT_EQ(sync_service()->GetDisableReasons(), + syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY); + brave_sync_prefs()->SetMigratedBookmarksVersion(2); + EXPECT_EQ(sync_service()->GetDisableReasons(), + syncer::SyncService::DISABLE_REASON_NONE); + sync_service()->OnSetSyncEnabled(false); + EXPECT_TRUE(sync_service()->HasDisableReason( + syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY)); +} + TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { EXPECT_FALSE(sync_service()->GetResettingForTest()); EXPECT_CALL(*sync_client(), OnSyncEnabledChanged).Times(1); @@ -702,9 +723,6 @@ TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { brave_sync::Uint8Array seed = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; brave_sync::Uint8Array device_id = {0}; - // These settings are changed: - // bookmarks_enabled, site_settings_enabled, history_enabled - EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(3); sync_service()->OnSaveInitData(seed, device_id); RecordsList records; @@ -714,7 +732,7 @@ TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); sync_service()->OnResolvedPreferences(records); - auto devices = sync_service()->sync_prefs_->GetSyncDevices(); + auto devices = brave_sync_prefs()->GetSyncDevices(); ASSERT_EQ(devices->size(), 1u); EXPECT_TRUE(DevicesContains(devices.get(), "0", "this_device")); @@ -756,24 +774,3 @@ TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncEnabled)); } - -TEST_F(BraveSyncServiceTest, GetPreferredDataTypes) { - // Make sure GetPreferredDataTypes contains DEVICE_INFO which is needed for - // brave device record polling - EXPECT_TRUE(sync_service()->GetPreferredDataTypes().Has(syncer::DEVICE_INFO)); -} - -TEST_F(BraveSyncServiceTest, GetDisableReasons) { - sync_prefs()->SetManagedForTest(true); - EXPECT_EQ(sync_service()->GetDisableReasons(), - syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY); - sync_service()->OnSetSyncEnabled(true); - EXPECT_EQ(sync_service()->GetDisableReasons(), - syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY); - brave_sync_prefs()->SetMigratedBookmarksVersion(2); - EXPECT_EQ(sync_service()->GetDisableReasons(), - syncer::SyncService::DISABLE_REASON_NONE); - sync_service()->OnSetSyncEnabled(false); - EXPECT_TRUE(sync_service()->HasDisableReason( - syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY)); -} From 9677876f5bd07a62e7141109192e8abdf6203ed6 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 8 Aug 2019 15:37:11 -0700 Subject: [PATCH 58/73] Exponentials resend periods (#2986) Resend meta shouldn't use metainfo from node (delete record doesn't have a node) --- .../brave_profile_sync_service_impl.cc | 57 ++++++++- .../brave_profile_sync_service_impl.h | 8 ++ components/brave_sync/brave_sync_prefs.cc | 39 +++++- components/brave_sync/brave_sync_prefs.h | 10 +- .../brave_sync/brave_sync_service_unittest.cc | 121 ++++++++++++++++++ components/brave_sync/test_util.cc | 5 +- components/brave_sync/test_util.h | 3 +- 7 files changed, 232 insertions(+), 11 deletions(-) diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index cf426a601f95..e33fbcf18729 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -40,6 +40,11 @@ using jslib_const::SyncRecordType_PREFERENCES; using jslib::Device; using tools::IsTimeEmpty; +const std::vector + BraveProfileSyncServiceImpl::kExponentialWaits = {10, 20, 40, 80}; +const int BraveProfileSyncServiceImpl::kMaxSendRetries = + BraveProfileSyncServiceImpl::kExponentialWaits.size() - 1; + namespace { @@ -242,7 +247,6 @@ void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( SendSyncRecords( jslib_const::SyncRecordType_BOOKMARKS, std::move(records)); } - ResendSyncRecords(jslib_const::SyncRecordType_BOOKMARKS); } BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() {} @@ -860,6 +864,7 @@ void BraveProfileSyncServiceImpl::OnPollSyncCycle(GetRecordsCallback cb, const bool history = brave_sync_prefs_->GetSyncHistoryEnabled(); const bool preferences = brave_sync_prefs_->GetSyncSiteSettingsEnabled(); FetchSyncRecords(bookmarks, history, preferences, 1000); + ResendSyncRecords(jslib_const::SyncRecordType_BOOKMARKS); } void BraveProfileSyncServiceImpl::SignalWaitableEvent() { @@ -888,7 +893,12 @@ void BraveProfileSyncServiceImpl::SendSyncRecords( brave_sync_client_->SendSyncRecords(category_name, *records); if (category_name == kBookmarks) { for (auto& record : *records) { - brave_sync_prefs_->AddToRecordsToResend(record->objectId); + std::unique_ptr meta = + std::make_unique(); + meta->SetInteger("send_retry_number", 0); + meta->SetDouble("sync_timestamp", record->syncTimestamp.ToJsTime()); + brave_sync_prefs_->AddToRecordsToResend(record->objectId, + std::move(meta)); } } } @@ -903,6 +913,32 @@ void BraveProfileSyncServiceImpl::ResendSyncRecords( return; for (auto& object_id : records_to_resend) { auto* node = FindByObjectId(model_, object_id); + + // Check resend interval + const base::DictionaryValue* meta = + brave_sync_prefs_->GetRecordToResendMeta(object_id); + DCHECK(meta); + int current_retry_number = kMaxSendRetries; + meta->GetInteger("send_retry_number", ¤t_retry_number); + DCHECK_GE(current_retry_number, 0); + double sync_timestamp = 0; + meta->GetDouble("sync_timestamp", &sync_timestamp); + DCHECK(!base::Time::FromJsTime(sync_timestamp).is_null()); + + if ((base::Time::Now() - + base::Time::FromJsTime(sync_timestamp)) < + GetRetryExponentialWaitAmount(current_retry_number)) + continue; + + // Increase retry number + if (++current_retry_number > kMaxSendRetries) + current_retry_number = kMaxSendRetries; + std::unique_ptr new_meta = + base::DictionaryValue::From( + std::make_unique(meta->Clone())); + new_meta->SetInteger("send_retry_number", current_retry_number); + brave_sync_prefs_->SetRecordToResendMeta(object_id, std::move(new_meta)); + if (node) { records->push_back( BookmarkNodeToSyncBookmark(model_, brave_sync_prefs_.get(), node)); @@ -916,4 +952,21 @@ void BraveProfileSyncServiceImpl::ResendSyncRecords( } } +// static +base::TimeDelta BraveProfileSyncServiceImpl::GetRetryExponentialWaitAmount( + int retry_number) { + DCHECK_LE(retry_number, kMaxSendRetries); + + if (retry_number > kMaxSendRetries) { + retry_number = kMaxSendRetries; + } + return base::TimeDelta::FromMinutes(kExponentialWaits[retry_number]); +} + +// static +std::vector +BraveProfileSyncServiceImpl::GetExponentialWaitsForTests() { + return kExponentialWaits; +} + } // namespace brave_sync diff --git a/components/brave_sync/brave_profile_sync_service_impl.h b/components/brave_sync/brave_profile_sync_service_impl.h index c77e19235c84..8eff44c02a43 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -36,6 +36,7 @@ FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSyncReadyNewToSync); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnGetExistingObjects); FORWARD_DECLARE_TEST(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain); +FORWARD_DECLARE_TEST(BraveSyncServiceTest, ExponentialResend); class BraveSyncServiceTest; @@ -135,6 +136,7 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnGetExistingObjects); FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain); + FRIEND_TEST_ALL_PREFIXES(::BraveSyncServiceTest, ExponentialResend); friend class ::BraveSyncServiceTest; void SignalWaitableEvent(); @@ -169,6 +171,12 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, RecordsListPtr records); void ResendSyncRecords(const std::string& category_name); + + static base::TimeDelta GetRetryExponentialWaitAmount(int retry_number); + static std::vector GetExponentialWaitsForTests(); + static const std::vector kExponentialWaits; + static const int kMaxSendRetries; + std::unique_ptr brave_sync_prefs_; // True when is in active sync chain bool brave_sync_configured_ = false; diff --git a/components/brave_sync/brave_sync_prefs.cc b/components/brave_sync/brave_sync_prefs.cc index 3fe6a1d6c67f..f51876d050c5 100644 --- a/components/brave_sync/brave_sync_prefs.cc +++ b/components/brave_sync/brave_sync_prefs.cc @@ -5,6 +5,8 @@ #include "brave/components/brave_sync/brave_sync_prefs.h" +#include + #include "brave/components/brave_sync/settings.h" #include "brave/components/brave_sync/sync_devices.h" #include "components/prefs/pref_service.h" @@ -30,6 +32,7 @@ const char kSyncApiVersion[] = "brave_sync.api_version"; const char kSyncMigrateBookmarksVersion[] = "brave_sync.migrate_bookmarks_version"; const char kSyncRecordsToResend[] = "brave_sync_records_to_resend"; +const char kSyncRecordsToResendMeta[] = "brave_sync_records_to_resend_meta"; Prefs::Prefs(PrefService* pref_service) : pref_service_(pref_service) {} @@ -54,6 +57,7 @@ void Prefs::RegisterProfilePrefs( registry->RegisterIntegerPref(prefs::kSyncMigrateBookmarksVersion, 0); registry->RegisterListPref(prefs::kSyncRecordsToResend); + registry->RegisterDictionaryPref(prefs::kSyncRecordsToResendMeta); } std::string Prefs::GetSeed() const { @@ -186,6 +190,7 @@ void Prefs::SetApiVersion(const std::string& api_version) { int Prefs::GetMigratedBookmarksVersion() { return pref_service_->GetInteger(kSyncMigrateBookmarksVersion); } + void Prefs::SetMigratedBookmarksVersion(const int migrate_bookmarks) { pref_service_->SetInteger(kSyncMigrateBookmarksVersion, migrate_bookmarks); } @@ -199,13 +204,36 @@ std::vector Prefs::GetRecordsToResend() const { return result; } -void Prefs::AddToRecordsToResend(const std::string& object_id) { - ListPrefUpdate update(pref_service_, kSyncRecordsToResend); - update->GetList().emplace_back(object_id); +void Prefs::AddToRecordsToResend(const std::string& object_id, + std::unique_ptr meta) { + ListPrefUpdate list_update(pref_service_, kSyncRecordsToResend); + list_update->GetList().emplace_back(object_id); + SetRecordToResendMeta(object_id, std::move(meta)); } + void Prefs::RemoveFromRecordsToResend(const std::string& object_id) { - ListPrefUpdate update(pref_service_, kSyncRecordsToResend); - base::Erase(update->GetList(), base::Value(object_id)); + ListPrefUpdate list_update(pref_service_, kSyncRecordsToResend); + base::Erase(list_update->GetList(), base::Value(object_id)); + DictionaryPrefUpdate dict_update(pref_service_, kSyncRecordsToResendMeta); + dict_update->RemoveKey(object_id); +} + +const base::DictionaryValue* +Prefs::GetRecordToResendMeta(const std::string& object_id) const { + const base::DictionaryValue* dict = + pref_service_->GetDictionary(kSyncRecordsToResendMeta); + const base::DictionaryValue* meta = nullptr; + const base::Value* meta_value = dict->FindDictKey(object_id); + if (meta_value) { + meta_value->GetAsDictionary(&meta); + } + return meta; +} + +void Prefs::SetRecordToResendMeta(const std::string& object_id, + std::unique_ptr meta) { + DictionaryPrefUpdate dict_update(pref_service_, kSyncRecordsToResendMeta); + dict_update->SetDictionary(object_id, std::move(meta)); } void Prefs::Clear() { @@ -223,6 +251,7 @@ void Prefs::Clear() { pref_service_->ClearPref(kSyncApiVersion); pref_service_->ClearPref(kSyncMigrateBookmarksVersion); pref_service_->ClearPref(kSyncRecordsToResend); + pref_service_->ClearPref(kSyncRecordsToResendMeta); } } // namespace prefs diff --git a/components/brave_sync/brave_sync_prefs.h b/components/brave_sync/brave_sync_prefs.h index f4b47b09c376..387fa1ddd596 100644 --- a/components/brave_sync/brave_sync_prefs.h +++ b/components/brave_sync/brave_sync_prefs.h @@ -11,6 +11,7 @@ #include #include "base/macros.h" +#include "base/values.h" class PrefService; class Profile; @@ -64,6 +65,8 @@ extern const char kSyncApiVersion[]; extern const char kSyncMigrateBookmarksVersion[]; // Cached object_id list for unconfirmed records extern const char kSyncRecordsToResend[]; +// Meta info of kSyncRecordsToResend +extern const char kSyncRecordsToResendMeta[]; class Prefs { public: @@ -108,8 +111,13 @@ class Prefs { void SetMigratedBookmarksVersion(const int); std::vector GetRecordsToResend() const; - void AddToRecordsToResend(const std::string& object_id); + void AddToRecordsToResend(const std::string& object_id, + std::unique_ptr meta); void RemoveFromRecordsToResend(const std::string& object_id); + const base::DictionaryValue* + GetRecordToResendMeta(const std::string& object_id) const; + void SetRecordToResendMeta(const std::string& object_id, + std::unique_ptr meta); void Clear(); diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index acc067248fe3..a0e73f52198c 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -3,7 +3,9 @@ * 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 +#include #include "base/files/scoped_temp_dir.h" #include "base/strings/utf_string_conversions.h" @@ -99,10 +101,23 @@ using brave_sync::BraveSyncServiceObserver; using brave_sync::jslib::SyncRecord; using brave_sync::MockBraveSyncClient; using brave_sync::RecordsList; +using brave_sync::SimpleBookmarkSyncRecord; using brave_sync::SimpleDeviceRecord; using testing::_; using testing::AtLeast; +namespace { + +const bookmarks::BookmarkNode* GetSingleNodeByUrl( + bookmarks::BookmarkModel* model, const std::string& url) { + std::vector nodes; + model->GetNodesByURL(GURL(url), &nodes); + size_t nodes_size = nodes.size(); + CHECK_EQ(nodes_size, 1u); + const bookmarks::BookmarkNode* node = nodes.at(0); + return node; +} + bool DevicesContains(brave_sync::SyncDevices* devices, const std::string& id, const std::string& name) { DCHECK(devices); @@ -128,6 +143,24 @@ MATCHER_P2(ContainsDeviceRecord, action, name, return false; } +size_t g_overridden_minutes = 0; +base::Time g_overridden_now; +std::unique_ptr OverrideForMinutes( + int overridden_minutes, + const base::Time& now = base::subtle::TimeNowIgnoringOverride()) { + g_overridden_minutes = overridden_minutes; + g_overridden_now = now; + return std::make_unique( + []() { + return g_overridden_now + + base::TimeDelta::FromMinutes(g_overridden_minutes); + }, + nullptr, + nullptr); +} + +} // namespace + class MockBraveSyncServiceObserver : public BraveSyncServiceObserver { public: MockBraveSyncServiceObserver() {} @@ -774,3 +807,91 @@ TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncEnabled)); } + +TEST_F(BraveSyncServiceTest, ExponentialResend) { + bookmarks::AddIfNotBookmarked(model(), + GURL("https://a.com/"), + base::ASCIIToUTF16("A.com")); + // Explicitly set sync_timestamp, object_id and order because it is supposed + // to be set in syncer + auto* node = GetSingleNodeByUrl(model(), "https://a.com/"); + model()->SetNodeMetaInfo(node, "sync_timestamp", + std::to_string(base::Time::Now().ToJsTime())); + const char* record_a_object_id = + "121, 194, 37, 61, 199, 11, 166, 234, " + "214, 197, 45, 215, 241, 206, 219, 130"; + model()->SetNodeMetaInfo(node, "object_id", record_a_object_id); + const char* record_a_order = "1.1.1.1"; + model()->SetNodeMetaInfo(node, "order", record_a_order); + + brave_sync_prefs()->SetThisDeviceId("1"); + std::unique_ptr records = std::make_unique(); + records->push_back(SimpleBookmarkSyncRecord( + SyncRecord::Action::A_CREATE, + record_a_object_id, + "https://a.com/", + "A.com - title", + record_a_order, "", brave_sync_prefs()->GetThisDeviceId())); + + EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(1); + sync_service()->SendSyncRecords("BOOKMARKS", std::move(records)); + + EXPECT_EQ(brave_sync_prefs()->GetRecordsToResend().size(), 1u); + const base::DictionaryValue* meta = + brave_sync_prefs()->GetRecordToResendMeta(record_a_object_id); + int send_retry_number = -1; + meta->GetInteger("send_retry_number", &send_retry_number); + EXPECT_EQ(send_retry_number, 0); + double sync_timestamp = -1; + meta->GetDouble("sync_timestamp", &sync_timestamp); + EXPECT_NE(sync_timestamp, -1); + + int expected_send_retry_number = 0; + + static const std::vector exponential_waits = + brave_sync::BraveProfileSyncServiceImpl::GetExponentialWaitsForTests(); + const int max_send_retries = exponential_waits.size() - 1; + std::set should_sent_at; + for (size_t j = 0; j < exponential_waits.size(); ++j) { + should_sent_at.insert(exponential_waits[j]); + } + auto contains = [](const std::set& set, int val) { + return set.find(val) != set.end(); + }; + for (size_t i = 0; i <= exponential_waits.back(); ++i) { + auto time_override = + OverrideForMinutes(i, base::Time::FromJsTime(sync_timestamp)); + bool is_send_expected = contains(should_sent_at, i); + int expect_call_times = is_send_expected ? 1 : 0; + EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times( + expect_call_times); + sync_service()->ResendSyncRecords("BOOKMARKS"); + + if (is_send_expected) { + if (++expected_send_retry_number > max_send_retries) + expected_send_retry_number = max_send_retries; + send_retry_number = -1; + meta = brave_sync_prefs()->GetRecordToResendMeta(record_a_object_id); + meta->GetInteger("send_retry_number", &send_retry_number); + EXPECT_EQ(send_retry_number, expected_send_retry_number); + } + } + + // resolve to confirm records + RecordsList records_to_resolve; + records_to_resolve.push_back(SimpleBookmarkSyncRecord( + SyncRecord::Action::A_CREATE, + record_a_object_id, + "https://a.com/", + "A.com", + "1.1.1.1", "", brave_sync_prefs()->GetThisDeviceId())); + auto timestamp_resolve = base::Time::Now(); + records_to_resolve.at(0)->syncTimestamp = timestamp_resolve; + brave_sync::SyncRecordAndExistingList records_and_existing_objects; + sync_service()->CreateResolveList(records_to_resolve, + &records_and_existing_objects); + + EXPECT_EQ(brave_sync_prefs()->GetRecordsToResend().size(), 0u); + EXPECT_EQ(brave_sync_prefs()->GetRecordToResendMeta(record_a_object_id), + nullptr); +} diff --git a/components/brave_sync/test_util.cc b/components/brave_sync/test_util.cc index b9bb4dea356d..3cd73acf6b13 100644 --- a/components/brave_sync/test_util.cc +++ b/components/brave_sync/test_util.cc @@ -58,14 +58,15 @@ SyncRecordPtr SimpleBookmarkSyncRecord( const std::string& location, const std::string& title, const std::string& order, - const std::string& parent_object_id) { + const std::string& parent_object_id, + const std::string& device_id) { auto record = std::make_unique(); record->action = ConvertEnum(action, brave_sync::jslib::SyncRecord::Action::A_MIN, brave_sync::jslib::SyncRecord::Action::A_MAX, brave_sync::jslib::SyncRecord::Action::A_INVALID); - record->deviceId = "3"; + record->deviceId = device_id; record->objectId = object_id.empty() ? tools::GenerateObjectId() : object_id; record->objectData = "bookmark"; diff --git a/components/brave_sync/test_util.h b/components/brave_sync/test_util.h index afc756a5d79e..4e55dd2c30d0 100644 --- a/components/brave_sync/test_util.h +++ b/components/brave_sync/test_util.h @@ -68,7 +68,8 @@ SyncRecordPtr SimpleBookmarkSyncRecord( const std::string& location, const std::string& title, const std::string& order, - const std::string& parent_object_id); + const std::string& parent_object_id, + const std::string& device_id = "3"); SyncRecordPtr SimpleFolderSyncRecord( const int action, From 4b2b835cc5329245059f744b2a888799a161adf2 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Wed, 24 Jul 2019 16:32:15 +0300 Subject: [PATCH 59/73] Native code for bookmark order calculations Improved processing of GetOrder('2.5.6.3', '2.5.7.8.2') Simplified GetOrder --- components/brave_sync/bookmark_order_util.cc | 150 ++++++++++++++++++- components/brave_sync/bookmark_order_util.h | 14 +- 2 files changed, 151 insertions(+), 13 deletions(-) diff --git a/components/brave_sync/bookmark_order_util.cc b/components/brave_sync/bookmark_order_util.cc index 8c65a5984235..e035925dd21c 100644 --- a/components/brave_sync/bookmark_order_util.cc +++ b/components/brave_sync/bookmark_order_util.cc @@ -1,6 +1,7 @@ -/* 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/. */ +/* 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" @@ -9,6 +10,17 @@ 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, @@ -21,20 +33,142 @@ std::vector OrderToIntVect(const std::string& s) { int output = 0; bool b = base::StringToInt(vec_s[i], &output); CHECK(b); - CHECK(output >= 0); + 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 use C++ stdlib + // Split each and compare as int vectors std::vector vec_left = OrderToIntVect(left); std::vector vec_right = OrderToIntVect(right); - return std::lexicographical_compare(vec_left.begin(), vec_left.end(), - vec_right.begin(), vec_right.end()); + 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 +} // namespace brave_sync diff --git a/components/brave_sync/bookmark_order_util.h b/components/brave_sync/bookmark_order_util.h index e7f7197b4ecb..b47248eeb287 100644 --- a/components/brave_sync/bookmark_order_util.h +++ b/components/brave_sync/bookmark_order_util.h @@ -1,6 +1,7 @@ -/* 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/. */ +/* 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_ @@ -11,8 +12,11 @@ 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 +} // namespace brave_sync -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BOOKMARK_ORDER_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BOOKMARK_ORDER_UTIL_H_ From 1c2ba0a178bd0de82169b51f4a024110b081f0a6 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Wed, 24 Jul 2019 16:32:59 +0300 Subject: [PATCH 60/73] Testcases for native bookmark order calculations Test for improved processing of GetOrder('2.5.6.3', '2.5.7.8.2') Updated and expanded tests for simplified GetOrder --- .../bookmark_order_util_unittest.cc | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/components/brave_sync/bookmark_order_util_unittest.cc b/components/brave_sync/bookmark_order_util_unittest.cc index 29f5b45ae9c0..54d6e2907b2e 100644 --- a/components/brave_sync/bookmark_order_util_unittest.cc +++ b/components/brave_sync/bookmark_order_util_unittest.cc @@ -39,6 +39,13 @@ TEST(BookmarkOrderUtilTest, OrderToIntVect_SemiWrongValue) { 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")); @@ -53,6 +60,55 @@ TEST(BookmarkOrderUtilTest, CompareOrder) { 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 From 412e408e6bf3ad813f312ee46989fd7a6e2e8efb Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Wed, 24 Jul 2019 16:41:37 +0300 Subject: [PATCH 61/73] Bookmarks positioning by order strings --- .../bookmark_change_processor.cc | 4 +- .../brave_profile_sync_service_impl.cc | 1 + components/brave_sync/syncer_helper.cc | 58 +++++++++---------- components/brave_sync/syncer_helper.h | 4 +- ...okmarks-bookmark_change_processor.cc.patch | 10 ++-- 5 files changed, 34 insertions(+), 43 deletions(-) diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 35e5958a8828..5e7bff7f6cae 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -119,7 +119,7 @@ void BookmarkChangeProcessor::MakeRepositionAndUpdateSyncNodes( #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_1 \ ScopedPauseObserver pause(bookmark_model_, this); \ - brave_sync::AddBraveMetaInfo(child, model, old_parent != new_parent); \ + brave_sync::AddBraveMetaInfo(child, model); \ SetSyncNodeMetaInfo(child, &sync_node); #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_2 \ @@ -129,7 +129,7 @@ void BookmarkChangeProcessor::MakeRepositionAndUpdateSyncNodes( #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED \ ScopedPauseObserver pause(bookmark_model_, this); \ - brave_sync::AddBraveMetaInfo(child, model, false); \ + brave_sync::AddBraveMetaInfo(child, model); \ SetSyncNodeMetaInfo(child, &sync_child); #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL \ diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index e33fbcf18729..95f0eac4dcf6 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -601,6 +601,7 @@ int BraveProfileSyncServiceImpl::GetDisableReasons() const { // kSyncManaged is set by Brave so it will contain // DISABLE_REASON_ENTERPRISE_POLICY and // SaveCardBubbleControllerImpl::ShouldShowSignInPromo will return false. + // kSyncManaged is disabled by us return ProfileSyncService::GetDisableReasons(); } diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index 0e9d355bf67d..52efb8d275ff 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -13,34 +13,33 @@ namespace brave_sync { namespace { -void ClearOrder(const bookmarks::BookmarkNode* leaf) { - bookmarks::BookmarkNode* node = const_cast(leaf); - while (!node->is_permanent_node()) { - node->DeleteMetaInfo("order"); - node = node->parent(); - } -} - void SetOrder(bookmarks::BookmarkModel* model, const bookmarks::BookmarkNode* node, const std::string& parent_order) { DCHECK(!parent_order.empty()); int index = node->parent()->GetIndexOf(node); - std::string order = parent_order + "." + base::NumberToString(index + 1); - model->SetNodeMetaInfo(node, "order", order); -} -void ReCalculateOrder(bookmarks::BookmarkModel* model, - const bookmarks::BookmarkNode* node) { - DCHECK(!node->is_permanent_node()); - std::string parent_order; - const bookmarks::BookmarkNode* parent = node->parent(); - parent->GetMetaInfo("order", &parent_order); - if (parent_order.empty()) { - ReCalculateOrder(model, node->parent()); - parent->GetMetaInfo("order", &parent_order); - } - SetOrder(model, node, parent_order); + bookmarks::BookmarkNode* parent = const_cast( + node->parent()); + + auto* prev_node = index == 0 ? + nullptr : + parent->GetChild(index - 1); + auto* next_node = index == parent->child_count() - 1 ? + nullptr : + parent->GetChild(index + 1); + + std::string prev_order; + std::string next_order; + if (prev_node) + prev_node->GetMetaInfo("order", &prev_order); + + if (next_node) + next_node->GetMetaInfo("order", &next_order); + + std::string order = brave_sync::GetOrder(prev_order, + next_order, parent_order); + model->SetNodeMetaInfo(node, "order", order); } uint64_t GetIndexByOrder(const std::string& record_order) { @@ -87,16 +86,11 @@ void RepositionRespectOrder( void AddBraveMetaInfo( const bookmarks::BookmarkNode* node, - bookmarks::BookmarkModel* model, - bool has_new_parent) { - if (has_new_parent) { - ClearOrder(node); - ReCalculateOrder(model, node); - } else { - std::string parent_order; - node->parent()->GetMetaInfo("order", &parent_order); - SetOrder(model, node, parent_order); - } + bookmarks::BookmarkModel* model) { + + std::string parent_order; + node->parent()->GetMetaInfo("order", &parent_order); + SetOrder(model, node, parent_order); std::string object_id; node->GetMetaInfo("object_id", &object_id); diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h index 034142e70e8d..e0fc4b127306 100644 --- a/components/brave_sync/syncer_helper.h +++ b/components/brave_sync/syncer_helper.h @@ -17,9 +17,7 @@ class BookmarkNode; namespace brave_sync { void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, - bookmarks::BookmarkModel* bookmark_model, - bool has_new_parent); - + bookmarks::BookmarkModel* bookmark_model); // |src| is the node which is about to be inserted into |parent| uint64_t GetIndex(const bookmarks::BookmarkNode* parent, diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index f0de9f076882..807dcca03309 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index 35a73a07bbcdd8aeba13acf37c6754aadb039768..f00db7611ccf75b66d8f4bf2db20566d45711f60 100644 +index 35a73a07bbcdd8aeba13acf37c6754aadb039768..52483687b7929da553b10f26423486597b1ed240 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( bookmark_specifics.set_creation_time_us(src->date_added().ToInternalValue()); dst->SetBookmarkSpecifics(bookmark_specifics); SetSyncNodeFavicon(src, model, dst); -+ brave_sync::AddBraveMetaInfo(src, model, false); ++ brave_sync::AddBraveMetaInfo(src, model); SetSyncNodeMetaInfo(src, dst); } @@ -43,12 +43,10 @@ index 35a73a07bbcdd8aeba13acf37c6754aadb039768..f00db7611ccf75b66d8f4bf2db20566d CreateOrUpdateSyncNode(node); } -@@ -489,7 +493,8 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( - } +@@ -490,6 +494,7 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( DCHECK_EQ(sync_child.GetParentId(), model_associator_->GetSyncIdFromChromeId(node->id())); -- -+ + + BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { From e1104e261786d473743b5c0e7eb5edebab00aac9 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Wed, 24 Jul 2019 16:46:15 +0300 Subject: [PATCH 62/73] Updated testcases for positioning by orders --- .../brave_sync/syncer_helper_unittest.cc | 76 ++++++++++++------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/components/brave_sync/syncer_helper_unittest.cc b/components/brave_sync/syncer_helper_unittest.cc index ccf0ea6aad77..466fe6b734a2 100644 --- a/components/brave_sync/syncer_helper_unittest.cc +++ b/components/brave_sync/syncer_helper_unittest.cc @@ -84,7 +84,7 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoCreateOrUpdate) { std::string sync_timestamp; const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 0, base::ASCIIToUTF16("Folder1")); - AddBraveMetaInfo(folder1, model(), false); + AddBraveMetaInfo(folder1, model()); folder1->GetMetaInfo("order", &order); EXPECT_EQ(order, "1.0.1.1"); std::string folder1_id; @@ -101,7 +101,7 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoCreateOrUpdate) { GURL("https://a.com/")); order.clear(); sync_timestamp.clear(); - AddBraveMetaInfo(node_a, model(), false); + AddBraveMetaInfo(node_a, model()); node_a->GetMetaInfo("order", &order); EXPECT_EQ(order, "1.0.1.1.1"); std::string node_a_id; @@ -118,7 +118,7 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoCreateOrUpdate) { node_a_id.clear(); node_a_parent_id.clear(); model()->SetURL(node_a, GURL("https://a-m.com/")); - AddBraveMetaInfo(node_a, model(), false); + AddBraveMetaInfo(node_a, model()); node_a->GetMetaInfo("order", &order); EXPECT_EQ(order, "1.0.1.1.1"); node_a->GetMetaInfo("object_id", &node_a_id); @@ -133,13 +133,13 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoCreateOrUpdate) { TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeMoved) { const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 0, base::ASCIIToUTF16("Folder1")); - AddBraveMetaInfo(folder1, model(), false); + AddBraveMetaInfo(folder1, model()); const auto *node_a = model()->AddURL(folder1, 0, base::ASCIIToUTF16("A.com - title"), GURL("https://a.com/")); - AddBraveMetaInfo(node_a, model(), false); + AddBraveMetaInfo(node_a, model()); model()->Move(node_a, model()->bookmark_bar_node(), 1); - AddBraveMetaInfo(node_a, model(), true); + AddBraveMetaInfo(node_a, model()); std::string order; node_a->GetMetaInfo("order", &order); @@ -159,15 +159,22 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeChildrenReordered) { const auto *node_a = model()->AddURL(model()->bookmark_bar_node(), 0, base::ASCIIToUTF16("A.com - title"), GURL("https://a.com/")); - AddBraveMetaInfo(node_a, model(), false); + AddBraveMetaInfo(node_a, model()); const auto *node_b = model()->AddURL(model()->bookmark_bar_node(), 1, base::ASCIIToUTF16("B.com - title"), GURL("https://b.com/")); - AddBraveMetaInfo(node_b, model(), false); + AddBraveMetaInfo(node_b, model()); const auto *node_c = model()->AddURL(model()->bookmark_bar_node(), 2, base::ASCIIToUTF16("C.com - title"), GURL("https://c.com/")); - AddBraveMetaInfo(node_c, model(), false); + AddBraveMetaInfo(node_c, model()); + + // Expecting to have initially: + // 'Bookmarks Bar' 1.0.1 + // |-A.com 1.0.1.1 + // |-B.com 1.0.1.2 + // |-C.com 1.0.1.3 + std::string order_a; std::string order_b; std::string order_c; @@ -179,38 +186,49 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeChildrenReordered) { EXPECT_EQ(order_c, "1.0.1.3"); model()->Move(node_c, model()->bookmark_bar_node(), 0); - AddBraveMetaInfo(node_a, model(), false); - AddBraveMetaInfo(node_b, model(), false); - AddBraveMetaInfo(node_c, model(), false); + AddBraveMetaInfo(node_c, model()); + + // After move to have: + // 'Bookmarks Bar' 1.0.1 + // |-C.com 1.0.1.0.1 + // |-A.com 1.0.1.1 + // |-B.com 1.0.1.2 order_a.clear(); order_b.clear(); order_c.clear(); node_a->GetMetaInfo("order", &order_a); - EXPECT_EQ(order_a, "1.0.1.2"); + EXPECT_EQ(order_a, "1.0.1.1"); node_b->GetMetaInfo("order", &order_b); - EXPECT_EQ(order_b, "1.0.1.3"); + EXPECT_EQ(order_b, "1.0.1.2"); node_c->GetMetaInfo("order", &order_c); - EXPECT_EQ(order_c, "1.0.1.1"); + EXPECT_EQ(order_c, "1.0.1.0.1"); } TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeMovedReordered) { const auto *node_a = model()->AddURL(model()->bookmark_bar_node(), 0, base::ASCIIToUTF16("A.com - title"), GURL("https://a.com/")); - AddBraveMetaInfo(node_a, model(), false); + AddBraveMetaInfo(node_a, model()); const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 1, base::ASCIIToUTF16("Folder1")); - AddBraveMetaInfo(folder1, model(), false); + AddBraveMetaInfo(folder1, model()); const auto *node_b = model()->AddURL(folder1, 0, base::ASCIIToUTF16("B.com - title"), GURL("https://b.com/")); - AddBraveMetaInfo(node_b, model(), false); + AddBraveMetaInfo(node_b, model()); const auto *node_c = model()->AddURL(folder1, 1, base::ASCIIToUTF16("C.com - title"), GURL("https://c.com/")); - AddBraveMetaInfo(node_c, model(), false); + AddBraveMetaInfo(node_c, model()); + + // Expecting here to have: + // 'Bookmarks Bar' 1.0.1 + // |-A.com 1.0.1.1 + // |-Folder1 1.0.1.2 + // |-B.com 1.0.1.2.1 + // |-C.com 1.0.1.2.2 std::string order_a; std::string order_b; @@ -226,24 +244,28 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeMovedReordered) { EXPECT_EQ(order_folder1, "1.0.1.2"); model()->Move(node_a, folder1, 0); - AddBraveMetaInfo(node_a, model(), true); - AddBraveMetaInfo(folder1, model(), false); - AddBraveMetaInfo(node_b, model(), false); - AddBraveMetaInfo(node_c, model(), false); + AddBraveMetaInfo(node_a, model()); order_a.clear(); order_b.clear(); order_c.clear(); order_folder1.clear(); + // After move expecting have: + // 'Bookmarks Bar' 1.0.1 (kept) + // |-Folder1 1.0.1.2 (kept) + // |-A.com 1.0.1.2.0.1 (re-calculated) + // |-B.com 1.0.1.2.1 (kept) + // |-C.com 1.0.1.2.2 (kept) + node_a->GetMetaInfo("order", &order_a); - EXPECT_EQ(order_a, "1.0.1.1.1"); + EXPECT_EQ(order_a, "1.0.1.2.0.1"); node_b->GetMetaInfo("order", &order_b); - EXPECT_EQ(order_b, "1.0.1.1.2"); + EXPECT_EQ(order_b, "1.0.1.2.1"); node_c->GetMetaInfo("order", &order_c); - EXPECT_EQ(order_c, "1.0.1.1.3"); + EXPECT_EQ(order_c, "1.0.1.2.2"); folder1->GetMetaInfo("order", &order_folder1); - EXPECT_EQ(order_folder1, "1.0.1.1"); + EXPECT_EQ(order_folder1, "1.0.1.2"); } TEST_F(SyncerHelperTest, GetIndexInPermanentNodes) { From 5cab8ba73f9e70ad93fd9d082253064ce52e94fb Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 6 Aug 2019 12:57:31 +0300 Subject: [PATCH 63/73] In case of equal orders use object_id --- components/brave_sync/syncer_helper.cc | 40 ++++++++++++++++++++++---- components/brave_sync/syncer_helper.h | 10 +++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index 52efb8d275ff..846e9cf18223 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -54,6 +54,8 @@ uint64_t GetIndexByOrder(const std::string& record_order) { return index; } +} // namespace + uint64_t GetIndexByCompareOrderStartFrom( const bookmarks::BookmarkNode* parent, const bookmarks::BookmarkNode* src, @@ -62,18 +64,46 @@ uint64_t GetIndexByCompareOrderStartFrom( src->GetMetaInfo("order", &src_order); DCHECK(!src_order.empty()); DCHECK_GE(index, 0); + bool use_order = true; // If false use object_id + std::string src_object_id; while (index < parent->child_count()) { const bookmarks::BookmarkNode* node = parent->GetChild(index); - std::string node_order; - node->GetMetaInfo("order", &node_order); - if (!node_order.empty() && - brave_sync::CompareOrder(src_order, node_order)) { + if (src->id() == node->id()) { + // We reached ourselves, no sense to go further, because we know all + // unsorted elements are in the end return index; } + + if (use_order) { + std::string node_order; + node->GetMetaInfo("order", &node_order); + if (!node_order.empty() && + brave_sync::CompareOrder(src_order, node_order)) { + return index; + } + + if (src_order == node_order) { + use_order = false; + } + } + + if (!use_order) { + if (src_object_id.empty()) { + src->GetMetaInfo("object_id", &src_object_id); + } + + std::string node_object_id; + node->GetMetaInfo("object_id", &node_object_id); + + if (src_object_id < node_object_id) { + return index; + } + } ++index; } return index; } + // |node| is near the end in parent void RepositionRespectOrder( bookmarks::BookmarkModel* bookmark_model, @@ -82,7 +112,6 @@ void RepositionRespectOrder( int index = GetIndexByCompareOrderStartFrom(parent, node, 0); bookmark_model->Move(node, parent, index); } -} // namespace void AddBraveMetaInfo( const bookmarks::BookmarkNode* node, @@ -135,6 +164,7 @@ uint64_t GetIndex(const bookmarks::BookmarkNode* parent, } return index; } + void RepositionOnApplyChangesFromSyncModel( bookmarks::BookmarkModel* bookmark_model, const std::multimap& to_reposition) { diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h index e0fc4b127306..22755e3fedb5 100644 --- a/components/brave_sync/syncer_helper.h +++ b/components/brave_sync/syncer_helper.h @@ -26,6 +26,16 @@ void RepositionOnApplyChangesFromSyncModel( bookmarks::BookmarkModel* bookmark_model, const std::multimap& to_reposition); +// Exported for test only +void RepositionRespectOrder( + bookmarks::BookmarkModel* bookmark_model, + const bookmarks::BookmarkNode* node); + +uint64_t GetIndexByCompareOrderStartFrom( + const bookmarks::BookmarkNode* parent, + const bookmarks::BookmarkNode* src, + int index); + } // namespace brave_sync #endif // BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ From 4969766ef6198bfd590eb8f2b08635c265d52d8b Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 6 Aug 2019 13:00:10 +0300 Subject: [PATCH 64/73] Test case for use object_id when orders are equal --- .../brave_sync/syncer_helper_unittest.cc | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/components/brave_sync/syncer_helper_unittest.cc b/components/brave_sync/syncer_helper_unittest.cc index 466fe6b734a2..a5a771cf1644 100644 --- a/components/brave_sync/syncer_helper_unittest.cc +++ b/components/brave_sync/syncer_helper_unittest.cc @@ -329,4 +329,112 @@ TEST_F(SyncerHelperTest, GetIndexInFolder) { EXPECT_EQ(GetIndex(folder1, &node), 1u); } +TEST_F(SyncerHelperTest, SameOrderBookmarksSordetByObjectIdFull3) { + // This test emulates folowing STR + // 1. on device A create bookmarks A1.com and A2.com + // 2. on device B create bookmarks B1.com and B2.com + // 3. create sync chain on device A and connect device B with a codephrase + // 4. wait for bookmarks will be synchromized between device A and B + // 5. on device A in Add bookmark dialog enter Name A3.com, URL A3.com, + // but dont press Save button + // 6. repeat pt 5 on device B, for B3.com + // 7. press Save button on devices A and B + // Expected bookmarks on devices A and B are sorted in the same way + const auto* node_a1 = model()->AddURL(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("A1.com"), + GURL("https://a1.com/")); + AddBraveMetaInfo(node_a1, model()); + const auto* node_a2 = model()->AddURL(model()->bookmark_bar_node(), 1, + base::ASCIIToUTF16("A2.com"), + GURL("https://a2.com/")); + AddBraveMetaInfo(node_a2, model()); + const auto* node_b1 = model()->AddURL(model()->bookmark_bar_node(), 2, + base::ASCIIToUTF16("B1.com"), + GURL("https://b1.com/")); + AddBraveMetaInfo(node_b1, model()); + const auto* node_b2 = model()->AddURL(model()->bookmark_bar_node(), 3, + base::ASCIIToUTF16("B2.com"), + GURL("https://b2.com/")); + AddBraveMetaInfo(node_b2, model()); + + // Expect b1 and b2 no need to move + uint64_t index_to_move_b1 = GetIndexByCompareOrderStartFrom( + model()->bookmark_bar_node(), + node_b1, + 0); + EXPECT_EQ(index_to_move_b1, 2u); + + uint64_t index_to_move_b2 = GetIndexByCompareOrderStartFrom( + model()->bookmark_bar_node(), + node_b2, + 0); + EXPECT_EQ(index_to_move_b2, 3u); + + const auto* node_a3 = model()->AddURL(model()->bookmark_bar_node(), 4, + base::ASCIIToUTF16("A3.com"), + GURL("https://a3.com/")); + AddBraveMetaInfo(node_a3, model()); + const auto* node_b3 = model()->AddURL(model()->bookmark_bar_node(), 5, + base::ASCIIToUTF16("B3.com"), + GURL("https://b3.com/")); + AddBraveMetaInfo(node_b3, model()); + const auto* node_c3 = model()->AddURL(model()->bookmark_bar_node(), 6, + base::ASCIIToUTF16("C3.com"), + GURL("https://c3.com/")); + AddBraveMetaInfo(node_c3, model()); + + std::string a3_order; + node_a3->GetMetaInfo("order", &a3_order); + EXPECT_TRUE(!a3_order.empty()); + + std::string a3_object_id; + node_a3->GetMetaInfo("object_id", &a3_object_id); + EXPECT_TRUE(!a3_object_id.empty()); + + // Emulating nodes a3, b3, and c3 have the same order + const_cast(node_b3)->SetMetaInfo("order", a3_order); + const_cast(node_c3)->SetMetaInfo("order", a3_order); + + // Expecting sorting of same order bookmarks by object_id + // object_id is 16 comma and spaces separated values of 16 uint8 + // Will assign these object ids to make RepositionRespectOrder do sorting: + // C3 A3 B3 + // "..." < 1,2,3 < "@@@" + ASSERT_TRUE("..." < a3_object_id && a3_object_id < "@@@"); + const_cast(node_b3)->SetMetaInfo("object_id", "@@@"); + const_cast(node_c3)->SetMetaInfo("object_id", "..."); + + // 0 1 2 3 4 5 6 + // A1 A2 B1 B2 A3(1,2,3) B3(@@@) C3(...) + auto title_at_4 = model()->bookmark_bar_node()->GetChild(4)->GetTitle(); + EXPECT_EQ(title_at_4, base::ASCIIToUTF16("A3.com")); + auto title_at_5 = model()->bookmark_bar_node()->GetChild(5)->GetTitle(); + EXPECT_EQ(title_at_5, base::ASCIIToUTF16("B3.com")); + auto title_at_6 = model()->bookmark_bar_node()->GetChild(6)->GetTitle(); + EXPECT_EQ(title_at_6, base::ASCIIToUTF16("C3.com")); + + RepositionRespectOrder(model(), node_b3); + // 0 1 2 3 4 5 6 + // A1 A2 B1 B2 A3(1,2,3) B3(@@@) C3(...) + // node B3 hadn't moved because it reached itself + title_at_4 = model()->bookmark_bar_node()->GetChild(4)->GetTitle(); + EXPECT_EQ(title_at_4, base::ASCIIToUTF16("A3.com")); + title_at_5 = model()->bookmark_bar_node()->GetChild(5)->GetTitle(); + EXPECT_EQ(title_at_5, base::ASCIIToUTF16("B3.com")); + title_at_6 = model()->bookmark_bar_node()->GetChild(6)->GetTitle(); + EXPECT_EQ(title_at_6, base::ASCIIToUTF16("C3.com")); + + RepositionRespectOrder(model(), node_c3); + // 0 1 2 3 4 5 6 + // A1 A2 B1 B2 C3(...) A3(1,2,3) B3(@@@) + // node C3 moved to the correct position, so B3 is on the right place now + + title_at_4 = model()->bookmark_bar_node()->GetChild(4)->GetTitle(); + EXPECT_EQ(title_at_4, base::ASCIIToUTF16("C3.com")); + title_at_5 = model()->bookmark_bar_node()->GetChild(5)->GetTitle(); + EXPECT_EQ(title_at_5, base::ASCIIToUTF16("A3.com")); + title_at_6 = model()->bookmark_bar_node()->GetChild(6)->GetTitle(); + EXPECT_EQ(title_at_6, base::ASCIIToUTF16("B3.com")); +} + } // namespace brave_sync From 6eef9c29bf1420c45a45e420a7cb6f4bb137b793 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 6 Aug 2019 18:24:41 +0300 Subject: [PATCH 65/73] Ignore move events during extensive changes --- ...-resources-bookmarks-api_listener.js.patch | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 patches/chrome-browser-resources-bookmarks-api_listener.js.patch diff --git a/patches/chrome-browser-resources-bookmarks-api_listener.js.patch b/patches/chrome-browser-resources-bookmarks-api_listener.js.patch new file mode 100644 index 000000000000..d80d1c1cb827 --- /dev/null +++ b/patches/chrome-browser-resources-bookmarks-api_listener.js.patch @@ -0,0 +1,20 @@ +diff --git a/chrome/browser/resources/bookmarks/api_listener.js b/chrome/browser/resources/bookmarks/api_listener.js +index 7bc20ec28e9faebc14dba26c277ea07db0940ed7..b1bafab103435383bbfa27338b8064aae38c1c44 100644 +--- a/chrome/browser/resources/bookmarks/api_listener.js ++++ b/chrome/browser/resources/bookmarks/api_listener.js +@@ -135,6 +135,7 @@ cr.define('bookmarks.ApiListener', function() { + */ + function onImportBegan() { + chrome.bookmarks.onCreated.removeListener(onBookmarkCreated); ++ chrome.bookmarks.onMoved.removeListener(onBookmarkMoved); + } + + function onImportEnded() { +@@ -143,6 +144,7 @@ cr.define('bookmarks.ApiListener', function() { + bookmarks.util.normalizeNodes(results[0]))); + }); + chrome.bookmarks.onCreated.addListener(onBookmarkCreated); ++ chrome.bookmarks.onMoved.addListener(onBookmarkMoved); + } + + /** From 6636c1d640d5618bff9259f207584cf464c4e6a2 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 12 Aug 2019 18:13:28 -0700 Subject: [PATCH 66/73] Network changes and Reset handling --- .../brave_profile_sync_service_impl.cc | 22 ++++++++++++++----- .../brave_profile_sync_service_impl.h | 12 +++++++--- ...vice_info-device_info_sync_bridge.cc.patch | 13 +++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 patches/components-sync_device_info-device_info_sync_bridge.cc.patch diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index 95f0eac4dcf6..d63a6fe2abc5 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -225,6 +225,7 @@ BraveProfileSyncServiceImpl::BraveProfileSyncServiceImpl(Profile* profile, !brave_sync_prefs_->GetThisDeviceName().empty()) { brave_sync_configured_ = true; } + network_connection_tracker_->AddNetworkConnectionObserver(this); } void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( @@ -249,7 +250,9 @@ void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( } } -BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() {} +BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() { + network_connection_tracker_->RemoveNetworkConnectionObserver(this); +} void BraveProfileSyncServiceImpl::OnSetupSyncHaveCode( const std::string& sync_words, const std::string& device_name) { @@ -601,7 +604,6 @@ int BraveProfileSyncServiceImpl::GetDisableReasons() const { // kSyncManaged is set by Brave so it will contain // DISABLE_REASON_ENTERPRISE_POLICY and // SaveCardBubbleControllerImpl::ShouldShowSignInPromo will return false. - // kSyncManaged is disabled by us return ProfileSyncService::GetDisableReasons(); } @@ -614,6 +616,12 @@ bool BraveProfileSyncServiceImpl::IsAuthenticatedAccountPrimary() const { return true; } +void BraveProfileSyncServiceImpl::OnConnectionChanged( + network::mojom::ConnectionType type) { + if (type == network::mojom::ConnectionType::CONNECTION_NONE) + SignalWaitableEvent(); +} + void BraveProfileSyncServiceImpl::Shutdown() { SignalWaitableEvent(); syncer::ProfileSyncService::Shutdown(); @@ -648,6 +656,12 @@ void BraveProfileSyncServiceImpl::ResetSyncInternal() { brave_sync_initialized_ = false; brave_sync_prefs_->SetSyncEnabled(false); + ProfileSyncService::GetUserSettings()->SetSyncRequested(false); + + // brave sync doesn't support pause sync so treating every new sync chain as + // first time setup + syncer::SyncPrefs sync_prefs(sync_client_->GetPrefService()); + sync_prefs.SetLastSyncedTime(base::Time()); reseting_ = false; } @@ -813,10 +827,6 @@ void BraveProfileSyncServiceImpl::OnBraveSyncPrefsChanged( const std::string& pref) { if (pref == prefs::kSyncEnabled) { brave_sync_client_->OnSyncEnabledChanged(); - if (!brave_sync_prefs_->GetSyncEnabled()) { - brave_sync_initialized_ = false; - ProfileSyncService::GetUserSettings()->SetSyncRequested(false); - } } NotifySyncStateChanged(); } diff --git a/components/brave_sync/brave_profile_sync_service_impl.h b/components/brave_sync/brave_profile_sync_service_impl.h index 8eff44c02a43..90f63e707598 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -16,6 +16,7 @@ #include "brave/components/brave_sync/public/brave_profile_sync_service.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/sync/driver/profile_sync_service.h" +#include "services/network/public/cpp/network_connection_tracker.h" FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkAdded); FORWARD_DECLARE_TEST(BraveSyncServiceTest, BookmarkDeleted); @@ -45,9 +46,11 @@ namespace prefs { class Prefs; } // namespace prefs -class BraveProfileSyncServiceImpl : public BraveProfileSyncService, - public BraveSyncService, - public SyncMessageHandler { +class BraveProfileSyncServiceImpl + : public BraveProfileSyncService, + public BraveSyncService, + public network::NetworkConnectionTracker::NetworkConnectionObserver, + public SyncMessageHandler { public: explicit BraveProfileSyncServiceImpl(Profile* profile, InitParams init_params); @@ -95,6 +98,9 @@ class BraveProfileSyncServiceImpl : public BraveProfileSyncService, CoreAccountInfo GetAuthenticatedAccountInfo() const override; bool IsAuthenticatedAccountPrimary() const override; + // NetworkConnectionTracker::NetworkConnectionObserver implementation. + void OnConnectionChanged(network::mojom::ConnectionType type) override; + // KeyedService implementation. This must be called exactly // once (before this object is destroyed). void Shutdown() override; diff --git a/patches/components-sync_device_info-device_info_sync_bridge.cc.patch b/patches/components-sync_device_info-device_info_sync_bridge.cc.patch new file mode 100644 index 000000000000..50efba228a9a --- /dev/null +++ b/patches/components-sync_device_info-device_info_sync_bridge.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/sync_device_info/device_info_sync_bridge.cc b/components/sync_device_info/device_info_sync_bridge.cc +index a809fd09ea04d28b7293d1554f29f0c83dd648a3..c0066b8ab45e9956a7d094d9bd9ddd45d5e674c3 100644 +--- a/components/sync_device_info/device_info_sync_bridge.cc ++++ b/components/sync_device_info/device_info_sync_bridge.cc +@@ -254,7 +254,7 @@ std::string DeviceInfoSyncBridge::GetStorageKey(const EntityData& entity_data) { + void DeviceInfoSyncBridge::ApplyStopSyncChanges( + std::unique_ptr delete_metadata_change_list) { + if (!delete_metadata_change_list) { +- return; ++ // return; + } + + // Sync is being disabled, so the local DeviceInfo is no longer valid and From b376e3ff0ccbd1c2cfc37f58f628e6229da7f595 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 13 Aug 2019 20:56:11 -0700 Subject: [PATCH 67/73] Using UniquePosition for bookmark order by position_in_parent 1. legacy order will still be sent for compatibility 2. legacy order will be used when there is no position_in_parent (legacy sync) during applying remote changes --- .../components/sync/engine_impl/commit.cc | 4 + .../sync/engine_impl/get_updates_processor.cc | 11 ++- .../bookmark_change_processor.cc | 83 +++++++------------ .../bookmark_change_processor.h | 8 +- components/brave_sync/syncer_helper.cc | 17 ---- components/brave_sync/syncer_helper.h | 8 -- .../brave_sync/syncer_helper_unittest.cc | 13 +++ ...okmarks-bookmark_change_processor.cc.patch | 35 ++------ 8 files changed, 66 insertions(+), 113 deletions(-) diff --git a/chromium_src/components/sync/engine_impl/commit.cc b/chromium_src/components/sync/engine_impl/commit.cc index 8929d0a101b7..d65a19c3e9bf 100644 --- a/chromium_src/components/sync/engine_impl/commit.cc +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -150,6 +150,10 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, metaInfo.value = std::to_string(entity.ctime()); bookmark->metaInfo.push_back(metaInfo); + metaInfo.key = "position_in_parent"; + metaInfo.value = std::to_string(entity.position_in_parent()); + bookmark->metaInfo.push_back(metaInfo); + if (bm_specifics.has_favicon()) { std::string icon_base64; base::Base64Encode(bm_specifics.favicon(), &icon_base64); diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index da5f56f37e5e..8390ec5435d8 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -103,6 +103,11 @@ void ExtractBookmarkMeta(sync_pb::SyncEntity* entity, bool result = base::StringToInt64(metaInfo.value, &ctime); DCHECK(result); entity->set_ctime(ctime); + } 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); } else if (metaInfo.key == "icon_data") { std::string icon_data_decoded; base::Base64Decode(metaInfo.value, &icon_data_decoded); @@ -121,6 +126,9 @@ void MigrateFromLegacySync(sync_pb::SyncEntity* entity) { if (!entity->has_version()) { entity->set_version(1); } + if (!entity->has_position_in_parent()) { + entity->set_position_in_parent(0); + } } void AddRootForType(sync_pb::SyncEntity* entity, ModelType type) { @@ -180,9 +188,6 @@ void AddBookmarkNode(sync_pb::SyncEntity* entity, const SyncRecord* record) { MigrateFromLegacySync(entity); - // Position will be calculated later by order comparison - // TODO(darkdh): dealing with USS remote changes handler - entity->set_position_in_parent(0); if (record->action == SyncRecord::Action::A_DELETE) entity->set_deleted(true); else diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 5e7bff7f6cae..87e1ca91f2ac 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -63,81 +63,60 @@ bool IsFirstLoadedFavicon(BookmarkChangeProcessor* bookmark_change_processor, } // namespace namespace sync_bookmarks { -syncer::SyncError BookmarkChangeProcessor::UpdateChildrenPositions( - const bookmarks::BookmarkNode* parent_node, - syncer::WriteTransaction* trans) { - for (int i = 0; i < parent_node->child_count(); ++i) { - const bookmarks::BookmarkNode* node = parent_node->GetChild(i); - syncer::WriteNode sync_node(trans); - if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { - syncer::SyncError error(FROM_HERE, - syncer::SyncError::DATATYPE_ERROR, - "Failed to init sync node from chrome node", - syncer::BOOKMARKS); - // TODO(AlexeyBarabash): pull unrecoverable_error_handler_ - // from BookmarkModelAssociator - // unrecoverable_error_handler_->OnUnrecoverableError(error); - DCHECK(false) << "[BraveSync] " << __func__ << - " Failed to init sync node from chrome node"; - return error; - } - if (!PlaceSyncNode(MOVE, parent_node, i, trans, &sync_node, - model_associator_)) { - syncer::SyncError error(FROM_HERE, - syncer::SyncError::DATATYPE_ERROR, - "Failed to place sync node", - syncer::BOOKMARKS); - // unrecoverable_error_handler_->OnUnrecoverableError(error); - DCHECK(false) << "[BraveSync] " << __func__ << - "Failed to place sync node"; - return error; - } - } - return syncer::SyncError(); -} -void BookmarkChangeProcessor::MakeRepositionAndUpdateSyncNodes( - const std::multimap& to_reposition, + +void BookmarkChangeProcessor::MoveSyncNode( + int index, + const bookmarks::BookmarkNode* node, const syncer::BaseTransaction* trans) { - brave_sync::RepositionOnApplyChangesFromSyncModel( - bookmark_model_, to_reposition); - // Attach to the transaction as a write transaction. - // Could be broken in next chromium updates, but now it is possible, see calls - // WriteTransaction::NotifyTransactionChangingAndEnding => - // SyncManagerImpl::HandleTransactionEndingChangeEvent syncer::WriteTransaction write_trans(FROM_HERE, trans->GetUserShare(), static_cast( trans->GetWrappedTrans())); - for (auto it = to_reposition.begin(); it != to_reposition.end(); ++it) { - const BookmarkNode* parent = it->second->parent(); - UpdateChildrenPositions(parent, &write_trans); + syncer::WriteNode sync_node(&write_trans); + if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { + syncer::SyncError error(FROM_HERE, + syncer::SyncError::DATATYPE_ERROR, + "Failed to init sync node from chrome node", + syncer::BOOKMARKS); + error_handler()->OnUnrecoverableError(error); + return; + } + + if (!PlaceSyncNode(MOVE, node->parent(), index, &write_trans, &sync_node, + model_associator_)) { + syncer::SyncError error(FROM_HERE, + syncer::SyncError::DATATYPE_ERROR, + "Failed to place sync node", + syncer::BOOKMARKS); + error_handler()->OnUnrecoverableError(error); + return; } } + } // namespace sync_bookmarks #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED \ if (IsFirstLoadedFavicon(this, bookmark_model_, node)) return; -#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_1 \ +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED \ ScopedPauseObserver pause(bookmark_model_, this); \ brave_sync::AddBraveMetaInfo(child, model); \ SetSyncNodeMetaInfo(child, &sync_node); -#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_2 \ - BookmarkNodeChildrenReordered(model, new_parent); \ - if (old_parent != new_parent) \ - BookmarkNodeChildrenReordered(model, old_parent); - #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED \ ScopedPauseObserver pause(bookmark_model_, this); \ brave_sync::AddBraveMetaInfo(child, model); \ SetSyncNodeMetaInfo(child, &sync_child); #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL \ - MakeRepositionAndUpdateSyncNodes(to_reposition, trans); + int new_index = brave_sync::GetIndexByCompareOrderStartFrom(dst->parent(), \ + dst, 0); \ + if (src.GetPositionIndex() != new_index) { \ + to_reposition.insert(std::make_pair(new_index, dst)); \ + MoveSyncNode(new_index, dst, trans); \ + } else // NOLINT #include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" // NOLINT #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED -#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_1 -#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_2 +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.h b/chromium_src/components/sync_bookmarks/bookmark_change_processor.h index 8f3a14e99b79..845468bd088b 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.h +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.h @@ -8,11 +8,9 @@ #define BRAVE_SYNC_REPOSITION_METHODS \ -syncer::SyncError UpdateChildrenPositions( \ - const bookmarks::BookmarkNode* parent_node, \ - syncer::WriteTransaction* trans); \ -void MakeRepositionAndUpdateSyncNodes( \ - const std::multimap& to_reposition, \ +void MoveSyncNode( \ + int index, \ + const bookmarks::BookmarkNode* node, \ const syncer::BaseTransaction* trans); #include "../../../../../components/sync_bookmarks/bookmark_change_processor.h" diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index 846e9cf18223..6f324bcd759b 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -104,15 +104,6 @@ uint64_t GetIndexByCompareOrderStartFrom( return index; } -// |node| is near the end in parent -void RepositionRespectOrder( - bookmarks::BookmarkModel* bookmark_model, - const bookmarks::BookmarkNode* node) { - const bookmarks::BookmarkNode* parent = node->parent(); - int index = GetIndexByCompareOrderStartFrom(parent, node, 0); - bookmark_model->Move(node, parent, index); -} - void AddBraveMetaInfo( const bookmarks::BookmarkNode* node, bookmarks::BookmarkModel* model) { @@ -165,12 +156,4 @@ uint64_t GetIndex(const bookmarks::BookmarkNode* parent, return index; } -void RepositionOnApplyChangesFromSyncModel( - bookmarks::BookmarkModel* bookmark_model, - const std::multimap& to_reposition) { - for (auto it = to_reposition.begin(); it != to_reposition.end(); ++it) { - RepositionRespectOrder(bookmark_model, it->second); - } -} - } // namespace brave_sync diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h index 22755e3fedb5..0874b9f28b32 100644 --- a/components/brave_sync/syncer_helper.h +++ b/components/brave_sync/syncer_helper.h @@ -22,14 +22,6 @@ void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, // |src| is the node which is about to be inserted into |parent| uint64_t GetIndex(const bookmarks::BookmarkNode* parent, const bookmarks::BookmarkNode* src); -void RepositionOnApplyChangesFromSyncModel( - bookmarks::BookmarkModel* bookmark_model, - const std::multimap& to_reposition); - -// Exported for test only -void RepositionRespectOrder( - bookmarks::BookmarkModel* bookmark_model, - const bookmarks::BookmarkNode* node); uint64_t GetIndexByCompareOrderStartFrom( const bookmarks::BookmarkNode* parent, diff --git a/components/brave_sync/syncer_helper_unittest.cc b/components/brave_sync/syncer_helper_unittest.cc index a5a771cf1644..c9fbf1912c9a 100644 --- a/components/brave_sync/syncer_helper_unittest.cc +++ b/components/brave_sync/syncer_helper_unittest.cc @@ -33,6 +33,19 @@ using bookmarks::BookmarkNode; namespace brave_sync { +namespace { + +// |node| is near the end in parent +void RepositionRespectOrder( + bookmarks::BookmarkModel* bookmark_model, + const bookmarks::BookmarkNode* node) { + const bookmarks::BookmarkNode* parent = node->parent(); + int index = GetIndexByCompareOrderStartFrom(parent, node, 0); + bookmark_model->Move(node, parent, index); +} + +} // namespace + class SyncerHelperTest : public testing::Test { public: SyncerHelperTest() {} diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 807dcca03309..92d3996e0323 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,5 +1,5 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index 35a73a07bbcdd8aeba13acf37c6754aadb039768..52483687b7929da553b10f26423486597b1ed240 100644 +index 35a73a07bbcdd8aeba13acf37c6754aadb039768..ac7ebcbda6bc1de634b81be44ce98c2c3656b3ac 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( @@ -23,19 +23,11 @@ index 35a73a07bbcdd8aeba13acf37c6754aadb039768..52483687b7929da553b10f2642348659 error_handler()->OnUnrecoverableError(error); return; } -+ BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_1 ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, model_associator_)) { -@@ -429,6 +431,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, - - UpdateTransactionVersion(new_version, model, - std::vector(1, child)); -+ BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED_2 - } - - void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( -@@ -458,6 +461,7 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( +@@ -458,6 +460,7 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( return; } @@ -43,7 +35,7 @@ index 35a73a07bbcdd8aeba13acf37c6754aadb039768..52483687b7929da553b10f2642348659 CreateOrUpdateSyncNode(node); } -@@ -490,6 +494,7 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( +@@ -490,6 +493,7 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( DCHECK_EQ(sync_child.GetParentId(), model_associator_->GetSyncIdFromChromeId(node->id())); @@ -51,7 +43,7 @@ index 35a73a07bbcdd8aeba13acf37c6754aadb039768..52483687b7929da553b10f2642348659 if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -718,6 +723,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -718,9 +722,11 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } @@ -59,20 +51,7 @@ index 35a73a07bbcdd8aeba13acf37c6754aadb039768..52483687b7929da553b10f2642348659 model_associator_->Associate(dst, src); } -@@ -725,6 +731,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL + to_reposition.insert(std::make_pair(src.GetPositionIndex(), dst)); bookmark_model_->SetNodeSyncTransactionVersion(dst, model_version); } - -+#if !defined(BRAVE_CHROMIUM_BUILD) - // When we added or updated bookmarks in the previous loop, we placed them to - // the far right position. Now we iterate over all these modified items in - // sync order, left to right, moving them into their proper positions. -@@ -732,6 +739,8 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( - const BookmarkNode* parent = it->second->parent(); - model->Move(it->second, parent, it->first); - } -+#endif -+ BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL - - // Clean up the temporary node. - if (foster_parent) { From ce62ff90289249eaf1ac1424cfa6360d70cb7700 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 15 Aug 2019 15:18:40 -0700 Subject: [PATCH 68/73] Maintain SyncEntityInfo in bookmark node's meta info for legacy sync compatibility --- .../sync/engine_impl/get_updates_processor.cc | 17 +- .../brave_profile_sync_service_impl.cc | 171 ++++++++++++------ .../brave_profile_sync_service_impl.h | 7 + 3 files changed, 134 insertions(+), 61 deletions(-) diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index 8390ec5435d8..636a0d427e17 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -78,21 +78,24 @@ void ExtractBookmarkMeta(sync_pb::SyncEntity* entity, const Bookmark& bookmark) { sync_pb::BookmarkSpecifics* bm_specifics = specifics->mutable_bookmark(); for (const auto metaInfo : bookmark.metaInfo) { - if (metaInfo.key == "originator_cache_guid") { - entity->set_originator_cache_guid(metaInfo.value); + // version need to be incremented + if (metaInfo.key != "version") { sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info(); - meta_info->set_key("originator_cache_guid"); + meta_info->set_key(metaInfo.key); meta_info->set_value(metaInfo.value); + } + if (metaInfo.key == "originator_cache_guid") { + entity->set_originator_cache_guid(metaInfo.value); } else if (metaInfo.key == "originator_client_item_id") { entity->set_originator_client_item_id(metaInfo.value); - sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info(); - meta_info->set_key("originator_client_item_id"); - meta_info->set_value(metaInfo.value); } else if (metaInfo.key == "version") { int64_t version; bool result = base::StringToInt64(metaInfo.value, &version); DCHECK(result); - entity->set_version(version + 1); + 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 == "mtime") { int64_t mtime; bool result = base::StringToInt64(metaInfo.value, &mtime); diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index d63a6fe2abc5..bcd1b000b16e 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -9,6 +9,7 @@ #include #include "base/bind.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "brave/components/brave_sync/values_conv.h" #include "brave/components/brave_sync/brave_sync_prefs.h" @@ -31,6 +32,7 @@ namespace brave_sync { using browser_sync::ChromeSyncClient; +using jslib::MetaInfo; using jslib::SyncRecord; using jslib_const::kBookmarks; using jslib_const::kHistorySites; @@ -124,62 +126,24 @@ std::unique_ptr CreateDeleteBookmarkByObjectId( return record; } -std::unique_ptr BookmarkNodeToSyncBookmark( - bookmarks::BookmarkModel* model, - const prefs::Prefs* brave_sync_prefs, - const bookmarks::BookmarkNode* node) { - if (node->is_permanent_node() || !node->parent()) - return std::unique_ptr(); - - auto record = std::make_unique(); - record->deviceId = brave_sync_prefs->GetThisDeviceId(); - record->objectData = jslib_const::SyncObjectData_BOOKMARK; - - auto bookmark = std::make_unique(); - bookmark->site.location = node->url().spec(); - bookmark->site.title = base::UTF16ToUTF8(node->GetTitledUrlNodeTitle()); - bookmark->site.customTitle = base::UTF16ToUTF8(node->GetTitle()); - // bookmark->site.lastAccessedTime - ignored - bookmark->site.creationTime = node->date_added(); - bookmark->site.favicon = node->icon_url() ? node->icon_url()->spec() : ""; - // Url may have type OTHER_NODE if it is in Deleted Bookmarks - bookmark->isFolder = (node->type() != bookmarks::BookmarkNode::URL && - node->type() != bookmarks::BookmarkNode::OTHER_NODE); - bookmark->hideInToolbar = - node->parent() != model->bookmark_bar_node(); - - std::string object_id; - node->GetMetaInfo("object_id", &object_id); - record->objectId = object_id; - - std::string parent_object_id; - node->parent()->GetMetaInfo("object_id", &parent_object_id); - bookmark->parentFolderObjectId = parent_object_id; - - std::string order; - node->GetMetaInfo("order", &order); - DCHECK(!order.empty()); - bookmark->order = order; - - std::string sync_timestamp; - node->GetMetaInfo("sync_timestamp", &sync_timestamp); - DCHECK(!sync_timestamp.empty()); - - record->syncTimestamp = base::Time::FromJsTime(std::stod(sync_timestamp)); - - record->action = jslib::SyncRecord::Action::A_UPDATE; - - record->SetBookmark(std::move(bookmark)); - - return record; -} - void DoDispatchGetRecordsCallback( GetRecordsCallback cb, std::unique_ptr records) { cb.Run(std::move(records)); } +void AddSyncEntityInfo(jslib::Bookmark* bookmark, + const bookmarks::BookmarkNode* node, + const std::string& key) { + std::string value; + if (node->GetMetaInfo(key, &value)) { + MetaInfo metaInfo; + metaInfo.key = key; + metaInfo.value = value; + bookmark->metaInfo.push_back(metaInfo); + } +} + } // namespace BraveProfileSyncServiceImpl::BraveProfileSyncServiceImpl(Profile* profile, @@ -560,6 +524,9 @@ void BraveProfileSyncServiceImpl::OnResolvedSyncRecords( if (category_name == jslib_const::kPreferences) { OnResolvedPreferences(*records.get()); } else if (category_name == kBookmarks) { + for (auto& record : *records) { + LoadSyncEntityInfo(record.get()); + } // Send records to syncer if (get_record_cb_) sync_thread_->task_runner()->PostTask(FROM_HERE, @@ -690,6 +657,103 @@ void BraveProfileSyncServiceImpl::SetPermanentNodesOrder( brave_sync_prefs_->SetMigratedBookmarksVersion(2); } +std::unique_ptr +BraveProfileSyncServiceImpl::BookmarkNodeToSyncBookmark( + const bookmarks::BookmarkNode* node) { + if (node->is_permanent_node() || !node->parent()) + return std::unique_ptr(); + + auto record = std::make_unique(); + record->deviceId = brave_sync_prefs_->GetThisDeviceId(); + record->objectData = jslib_const::SyncObjectData_BOOKMARK; + + auto bookmark = std::make_unique(); + bookmark->site.location = node->url().spec(); + bookmark->site.title = base::UTF16ToUTF8(node->GetTitledUrlNodeTitle()); + bookmark->site.customTitle = base::UTF16ToUTF8(node->GetTitle()); + // bookmark->site.lastAccessedTime - ignored + bookmark->site.creationTime = node->date_added(); + bookmark->site.favicon = node->icon_url() ? node->icon_url()->spec() : ""; + // Url may have type OTHER_NODE if it is in Deleted Bookmarks + bookmark->isFolder = (node->type() != bookmarks::BookmarkNode::URL && + node->type() != bookmarks::BookmarkNode::OTHER_NODE); + bookmark->hideInToolbar = + node->parent() != model_->bookmark_bar_node(); + + std::string object_id; + node->GetMetaInfo("object_id", &object_id); + record->objectId = object_id; + + std::string parent_object_id; + node->parent()->GetMetaInfo("object_id", &parent_object_id); + bookmark->parentFolderObjectId = parent_object_id; + + std::string order; + node->GetMetaInfo("order", &order); + DCHECK(!order.empty()); + bookmark->order = order; + + std::string sync_timestamp; + node->GetMetaInfo("sync_timestamp", &sync_timestamp); + DCHECK(!sync_timestamp.empty()); + + record->syncTimestamp = base::Time::FromJsTime(std::stod(sync_timestamp)); + + record->action = jslib::SyncRecord::Action::A_UPDATE; + + AddSyncEntityInfo(bookmark.get(), node, "originator_cache_guid"); + AddSyncEntityInfo(bookmark.get(), node, "originator_client_item_id"); + AddSyncEntityInfo(bookmark.get(), node, "version"); + AddSyncEntityInfo(bookmark.get(), node, "mtime"); + AddSyncEntityInfo(bookmark.get(), node, "ctime"); + AddSyncEntityInfo(bookmark.get(), node, "position_in_parent"); + AddSyncEntityInfo(bookmark.get(), node, "icon_data"); + + record->SetBookmark(std::move(bookmark)); + + return record; +} + +void BraveProfileSyncServiceImpl::SaveSyncEntityInfo( + const jslib::SyncRecord* record) { + auto* node = FindByObjectId(model_, record->objectId); + // no need to save for DELETE + if (node) { + auto& bookmark = record->GetBookmark(); + for (auto& meta_info : bookmark.metaInfo) { + model_->SetNodeMetaInfo(node, meta_info.key, meta_info.value); + } + } +} + +void BraveProfileSyncServiceImpl::LoadSyncEntityInfo( + jslib::SyncRecord* record) { + auto* node = FindByObjectId(model_, record->objectId); + if (node) { + auto* bookmark = record->mutable_bookmark(); + if (!bookmark->metaInfo.empty()) + return; + AddSyncEntityInfo(bookmark, node, "originator_cache_guid"); + AddSyncEntityInfo(bookmark, node, "originator_client_item_id"); + AddSyncEntityInfo(bookmark, node, "mtime"); + AddSyncEntityInfo(bookmark, node, "ctime"); + AddSyncEntityInfo(bookmark, node, "position_in_parent"); + AddSyncEntityInfo(bookmark, node, "icon_data"); + std::string s_version; + // Version needs to be incremented by 1 for legacy sync to emulate + // GetUpdateProcessor behavior + if (node->GetMetaInfo("version", &s_version)) { + int64_t version; + bool result = base::StringToInt64(s_version, &version); + DCHECK(result); + MetaInfo metaInfo; + metaInfo.key = "version"; + metaInfo.value = std::to_string(++version); + bookmark->metaInfo.push_back(metaInfo); + } + } +} + void BraveProfileSyncServiceImpl::CreateResolveList( const std::vector>& records, SyncRecordAndExistingList* records_and_existing_objects) { @@ -705,8 +769,7 @@ void BraveProfileSyncServiceImpl::CreateResolveList( resolved_record->first = SyncRecord::Clone(*record); auto* node = FindByObjectId(model_, record->objectId); if (node) { - resolved_record->second = - BookmarkNodeToSyncBookmark(model_, brave_sync_prefs_.get(), node); + resolved_record->second = BookmarkNodeToSyncBookmark(node); } records_and_existing_objects->push_back(std::move(resolved_record)); @@ -904,6 +967,7 @@ void BraveProfileSyncServiceImpl::SendSyncRecords( brave_sync_client_->SendSyncRecords(category_name, *records); if (category_name == kBookmarks) { for (auto& record : *records) { + SaveSyncEntityInfo(record.get()); std::unique_ptr meta = std::make_unique(); meta->SetInteger("send_retry_number", 0); @@ -951,8 +1015,7 @@ void BraveProfileSyncServiceImpl::ResendSyncRecords( brave_sync_prefs_->SetRecordToResendMeta(object_id, std::move(new_meta)); if (node) { - records->push_back( - BookmarkNodeToSyncBookmark(model_, brave_sync_prefs_.get(), node)); + records->push_back(BookmarkNodeToSyncBookmark(node)); } else { records->push_back( CreateDeleteBookmarkByObjectId(brave_sync_prefs_.get(), object_id)); diff --git a/components/brave_sync/brave_profile_sync_service_impl.h b/components/brave_sync/brave_profile_sync_service_impl.h index 90f63e707598..5f230982cb99 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -167,6 +167,13 @@ class BraveProfileSyncServiceImpl void SetPermanentNodesOrder(const std::string& base_order); + std::unique_ptr BookmarkNodeToSyncBookmark( + const bookmarks::BookmarkNode* node); + // These SyncEntityInfo is for legacy device who doesn't send meta info for + // sync entity + void SaveSyncEntityInfo(const jslib::SyncRecord* record); + void LoadSyncEntityInfo(jslib::SyncRecord* record); + void CreateResolveList( const std::vector>& records, SyncRecordAndExistingList* records_and_existing_objects); From 99b97f5d4a13f6c0ce6a6a3b0d713ee18efdbbef Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 15 Aug 2019 22:13:59 -0700 Subject: [PATCH 69/73] Review Feedback (1) 1. Patch standardization 2. Apply clang-format --- ...e_autocomplete_provider_client_unittest.cc | 4 +- ...rave_content_browser_client_browsertest.cc | 4 +- browser/brave_profile_prefs.cc | 2 +- browser/extensions/BUILD.gn | 24 +-- browser/extensions/api/brave_sync_api.cc | 66 +++--- .../extensions/api/brave_sync_event_router.cc | 2 +- .../extensions/api/brave_sync_event_router.h | 10 +- ...ve_component_extension_resource_manager.cc | 2 +- browser/profiles/BUILD.gn | 6 +- browser/ui/BUILD.gn | 42 ++-- .../ui/brave_browser_command_controller.cc | 4 +- browser/ui/toolbar/brave_app_menu_model.cc | 11 +- .../brave_app_menu_model_browsertest.cc | 6 +- .../webui/brave_web_ui_controller_factory.cc | 2 +- browser/ui/webui/sync/sync_ui.cc | 14 +- .../sync/profile_sync_service_factory.cc | 2 +- .../sync/driver/glue/sync_engine_backend.cc | 32 ++- .../sync/driver/glue/sync_engine_impl.h | 6 +- .../sync/driver/profile_sync_service.cc | 34 ++- .../sync/driver/profile_sync_service.h | 6 +- .../sync/driver/sync_driver_switches.cc | 2 +- .../components/sync/engine/sync_engine.h | 8 +- .../components/sync/engine/sync_manager.h | 10 +- .../components/sync/engine_impl/commit.cc | 37 ++-- .../sync/engine_impl/cycle/sync_cycle.h | 10 +- .../sync/engine_impl/get_updates_processor.cc | 24 ++- .../sync/engine_impl/get_updates_processor.h | 9 +- .../sync/engine_impl/sync_manager_impl.cc | 10 +- .../sync/engine_impl/sync_scheduler_impl.cc | 6 +- .../sync/engine_impl/sync_scheduler_impl.h | 18 +- .../components/sync/engine_impl/syncer.cc | 3 +- .../components/sync/engine_impl/syncer.h | 11 +- .../sync/syncable/write_transaction.cc | 11 +- .../sync/syncable/write_transaction.h | 12 +- .../bookmark_change_processor.cc | 69 +++--- .../bookmark_change_processor.h | 10 +- common/extensions/api/BUILD.gn | 15 +- components/brave_sync/BUILD.gn | 53 +++-- components/brave_sync/bookmark_order_util.cc | 22 +- components/brave_sync/bookmark_order_util.h | 9 +- .../bookmark_order_util_unittest.cc | 5 +- .../brave_profile_sync_service_impl.cc | 196 ++++++++---------- .../brave_profile_sync_service_impl.h | 31 ++- components/brave_sync/brave_sync_prefs.cc | 13 +- components/brave_sync/brave_sync_prefs.h | 6 +- .../brave_sync/brave_sync_service_unittest.cc | 122 +++++------ .../client/brave_sync_client_impl.h | 4 +- .../brave_sync/client/client_ext_impl_data.cc | 38 ++-- .../brave_sync/client/client_ext_impl_data.h | 14 +- components/brave_sync/jslib_messages.cc | 10 +- components/brave_sync/jslib_messages.h | 12 +- components/brave_sync/jslib_messages_fwd.h | 9 +- .../public/brave_profile_sync_service.h | 4 +- components/brave_sync/syncer_helper.cc | 35 ++-- components/brave_sync/syncer_helper.h | 13 +- .../brave_sync/syncer_helper_unittest.cc | 115 +++++----- components/brave_sync/test_util.cc | 17 +- components/brave_sync/test_util.h | 20 +- ...nc-engine_impl-sync_scheduler_impl.h.patch | 16 +- ...s-sync-syncable-write_transaction.cc.patch | 4 +- ...ts-sync-syncable-write_transaction.h.patch | 14 +- ...okmarks-bookmark_change_processor.cc.patch | 19 +- ...ookmarks-bookmark_change_processor.h.patch | 14 +- 63 files changed, 640 insertions(+), 719 deletions(-) diff --git a/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc b/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc index f4a0a2698e5e..7f2565d0467e 100644 --- a/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc +++ b/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc @@ -50,7 +50,7 @@ class BraveAutocompleteProviderClientUnitTest : public testing::Test { TEST_F(BraveAutocompleteProviderClientUnitTest, SyncURLSuggestedNotSyncInternal) { - ASSERT_FALSE(BuiltinExists( - base::ASCIIToUTF16(chrome::kChromeUISyncInternalsHost))); + ASSERT_FALSE( + BuiltinExists(base::ASCIIToUTF16(chrome::kChromeUISyncInternalsHost))); ASSERT_TRUE(BuiltinExists(base::ASCIIToUTF16(kBraveUISyncHost))); } diff --git a/browser/brave_content_browser_client_browsertest.cc b/browser/brave_content_browser_client_browsertest.cc index f4f794208574..fbde5e1fda3b 100644 --- a/browser/brave_content_browser_client_browsertest.cc +++ b/browser/brave_content_browser_client_browsertest.cc @@ -152,10 +152,10 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadCustomBravePages) { std::vector pages { "adblock", #if BUILDFLAG(BRAVE_REWARDS_ENABLED) - "rewards", + "rewards", #endif #if BUILDFLAG(ENABLE_BRAVE_SYNC) - chrome::kChromeUISyncHost, + chrome::kChromeUISyncHost, #endif }; diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 40a2ba95204c..342b3020017f 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -7,8 +7,8 @@ #include "brave/common/pref_names.h" #include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h" -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" #include "brave/components/brave_sync/brave_sync_prefs.h" +#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" #include "chrome/browser/net/prediction_options.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/common/pref_names.h" diff --git a/browser/extensions/BUILD.gn b/browser/extensions/BUILD.gn index d20e26091399..c6b09fe0da68 100644 --- a/browser/extensions/BUILD.gn +++ b/browser/extensions/BUILD.gn @@ -1,6 +1,6 @@ import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni") -import("//brave/components/brave_wallet/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_webtorrent/browser/buildflags/buildflags.gni") import("//build/config/features.gni") @@ -10,8 +10,6 @@ declare_args() { source_set("extensions") { sources = [ - "api/rewards_notifications_api.cc", - "api/rewards_notifications_api.h", "api/brave_extensions_api_client.cc", "api/brave_extensions_api_client.h", "api/brave_rewards_api.cc", @@ -20,14 +18,14 @@ source_set("extensions") { "api/brave_shields_api.h", "api/brave_theme_api.cc", "api/brave_theme_api.h", + "api/rewards_notifications_api.cc", + "api/rewards_notifications_api.h", "api/settings_private/brave_prefs_util.cc", "api/settings_private/brave_prefs_util.h", "brave_component_extension_resource_manager.cc", "brave_component_extension_resource_manager.h", "brave_component_loader.cc", "brave_component_loader.h", - "brave_extensions_browser_api_provider.cc", - "brave_extensions_browser_api_provider.h", "brave_extension_install_prompt.cc", "brave_extension_install_prompt.h", "brave_extension_management.cc", @@ -36,12 +34,14 @@ source_set("extensions") { "brave_extension_provider.h", "brave_extension_service.cc", "brave_extension_service.h", + "brave_extensions_browser_api_provider.cc", + "brave_extensions_browser_api_provider.h", "brave_theme_event_router.cc", "brave_theme_event_router.h", "brave_tor_client_updater.cc", "brave_tor_client_updater.h", "updater/brave_update_client_config.cc", - "updater/brave_update_client_config.h" + "updater/brave_update_client_config.h", ] if (brave_wallet_enabled) { @@ -60,8 +60,8 @@ source_set("extensions") { "//brave/common:pref_names", "//brave/common/extensions/api", "//brave/components/brave_component_updater/browser", - "//brave/components/brave_extension:static_resources", "//brave/components/brave_extension:generated_resources", + "//brave/components/brave_extension:static_resources", "//components/prefs", "//components/update_client:patch_impl", "//components/update_client:unzip_impl", @@ -86,9 +86,9 @@ source_set("extensions") { ] deps += [ - "//brave/components/brave_sync", - "//brave/components/brave_sync:generated_resources", - "//brave/components/brave_sync:static_resources", + "//brave/components/brave_sync", + "//brave/components/brave_sync:generated_resources", + "//brave/components/brave_sync:static_resources", ] } if (enable_brave_webtorrent) { @@ -100,7 +100,5 @@ source_set("extensions") { } config("infura_config") { - defines = [ - "BRAVE_INFURA_PROJECT_ID=\"$brave_infura_project_id\"" - ] + defines = [ "BRAVE_INFURA_PROJECT_ID=\"$brave_infura_project_id\"" ] } diff --git a/browser/extensions/api/brave_sync_api.cc b/browser/extensions/api/brave_sync_api.cc index bc41a1a02cc8..d7e3448ede32 100644 --- a/browser/extensions/api/brave_sync_api.cc +++ b/browser/extensions/api/brave_sync_api.cc @@ -13,9 +13,9 @@ #include "brave/components/brave_sync/brave_sync_service.h" #include "brave/components/brave_sync/client/brave_sync_client.h" #include "brave/components/brave_sync/client/client_ext_impl_data.h" +#include "brave/components/brave_sync/jslib_messages.h" #include "brave/components/brave_sync/public/brave_profile_sync_service.h" #include "brave/components/brave_sync/values_conv.h" -#include "brave/components/brave_sync/jslib_messages.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/profile_sync_service_factory.h" @@ -31,12 +31,11 @@ namespace { BraveProfileSyncService* GetProfileSyncService( BrowserContext* browser_context) { return static_cast( - ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( - Profile::FromBrowserContext(browser_context))); + ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( + Profile::FromBrowserContext(browser_context))); } -BraveSyncService* GetSyncService( - BrowserContext* browser_context) { +BraveSyncService* GetSyncService(BrowserContext* browser_context) { return GetProfileSyncService(browser_context)->GetSyncService(); } @@ -46,8 +45,7 @@ ExtensionFunction::ResponseAction BraveSyncGetInitDataFunction::Run() { brave_sync::GetInitData::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnGetInitData( params->sync_version); @@ -60,8 +58,7 @@ ExtensionFunction::ResponseAction BraveSyncSyncSetupErrorFunction::Run() { brave_sync::SyncSetupError::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnSyncSetupError( params->error); @@ -74,8 +71,7 @@ ExtensionFunction::ResponseAction BraveSyncSyncDebugFunction::Run() { brave_sync::SyncDebug::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnSyncDebug( params->message); @@ -88,8 +84,7 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { brave_sync::SaveInitData::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnSaveInitData( params->seed ? *params->seed : std::vector(), @@ -99,8 +94,7 @@ ExtensionFunction::ResponseAction BraveSyncSaveInitDataFunction::Run() { } ExtensionFunction::ResponseAction BraveSyncSyncReadyFunction::Run() { - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->sync_message_handler()->OnSyncReady(); @@ -115,15 +109,14 @@ ExtensionFunction::ResponseAction BraveSyncGetExistingObjectsFunction::Run() { auto records = std::make_unique>(); ::brave_sync::ConvertSyncRecords(params->records, records.get()); - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetBraveSyncClient()->sync_message_handler() - ->OnGetExistingObjects( - params->category_name, - std::move(records), - base::Time::FromJsTime(params->last_record_timestamp), - params->is_truncated); + sync_service->GetBraveSyncClient() + ->sync_message_handler() + ->OnGetExistingObjects( + params->category_name, std::move(records), + base::Time::FromJsTime(params->last_record_timestamp), + params->is_truncated); return RespondNow(NoArguments()); } @@ -136,11 +129,11 @@ ExtensionFunction::ResponseAction BraveSyncResolvedSyncRecordsFunction::Run() { auto records = std::make_unique>(); ::brave_sync::ConvertSyncRecords(params->records, records.get()); - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetBraveSyncClient()->sync_message_handler() - ->OnResolvedSyncRecords(params->category_name, std::move(records)); + sync_service->GetBraveSyncClient() + ->sync_message_handler() + ->OnResolvedSyncRecords(params->category_name, std::move(records)); return RespondNow(NoArguments()); } @@ -151,11 +144,11 @@ BraveSyncSaveBookmarksBaseOrderFunction::Run() { brave_sync::SaveBookmarksBaseOrder::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetBraveSyncClient()->sync_message_handler() - ->OnSaveBookmarksBaseOrder(params->order); + sync_service->GetBraveSyncClient() + ->sync_message_handler() + ->OnSaveBookmarksBaseOrder(params->order); return RespondNow(NoArguments()); } @@ -165,19 +158,18 @@ ExtensionFunction::ResponseAction BraveSyncSyncWordsPreparedFunction::Run() { brave_sync::SyncWordsPrepared::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); - sync_service->GetBraveSyncClient()->sync_message_handler() - ->OnSyncWordsPrepared(params->words); + sync_service->GetBraveSyncClient() + ->sync_message_handler() + ->OnSyncWordsPrepared(params->words); return RespondNow(NoArguments()); } ExtensionFunction::ResponseAction BraveSyncExtensionInitializedFunction::Run() { // Also inform sync client extension started - BraveSyncService* sync_service = - GetSyncService(browser_context()); + BraveSyncService* sync_service = GetSyncService(browser_context()); DCHECK(sync_service); sync_service->GetBraveSyncClient()->OnExtensionInitialized(); diff --git a/browser/extensions/api/brave_sync_event_router.cc b/browser/extensions/api/brave_sync_event_router.cc index f84d3b4533d0..57582e37adfe 100644 --- a/browser/extensions/api/brave_sync_event_router.cc +++ b/browser/extensions/api/brave_sync_event_router.cc @@ -146,4 +146,4 @@ void BraveSyncEventRouter::LoadClient() { event_router_->BroadcastEvent(std::move(event)); } -} // namespace extensions +} // namespace extensions diff --git a/browser/extensions/api/brave_sync_event_router.h b/browser/extensions/api/brave_sync_event_router.h index e9b19e55b35f..7ad61e285d26 100644 --- a/browser/extensions/api/brave_sync_event_router.h +++ b/browser/extensions/api/brave_sync_event_router.h @@ -18,9 +18,9 @@ namespace brave_sync { struct SyncRecord; struct Config; struct RecordAndExistingObject; -} // namespace brave_sync -} // namespace api -} // namespace extensions +} // namespace brave_sync +} // namespace api +} // namespace extensions using extensions::api::brave_sync::RecordAndExistingObject; @@ -65,6 +65,6 @@ class BraveSyncEventRouter { EventRouter* event_router_; }; -} // namespace extensions +} // namespace extensions -#endif // BRAVE_BROWSER_EXTENSIONS_API_BRAVE_SYNC_EVENT_ROUTER_H_ +#endif // BRAVE_BROWSER_EXTENSIONS_API_BRAVE_SYNC_EVENT_ROUTER_H_ diff --git a/browser/extensions/brave_component_extension_resource_manager.cc b/browser/extensions/brave_component_extension_resource_manager.cc index 9ab64749374f..a034b38ca85d 100644 --- a/browser/extensions/brave_component_extension_resource_manager.cc +++ b/browser/extensions/brave_component_extension_resource_manager.cc @@ -9,8 +9,8 @@ #include "brave/components/brave_extension/grit/brave_extension_resources_map.h" #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" #include "brave/components/brave_sync/buildflags/buildflags.h" -#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources_map.h" #include "brave/components/brave_webtorrent/grit/brave_webtorrent_generated_map.h" +#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources_map.h" #if BUILDFLAG(BRAVE_REWARDS_ENABLED) #include "brave/components/brave_rewards/resources/extension/grit/brave_rewards_extension_resources_map.h" diff --git a/browser/profiles/BUILD.gn b/browser/profiles/BUILD.gn index a323388ff924..41d2b04ee18e 100644 --- a/browser/profiles/BUILD.gn +++ b/browser/profiles/BUILD.gn @@ -7,13 +7,13 @@ source_set("profiles") { ] deps = [ "//base", - "//chrome/common", - "//content/public/common", "//brave/browser/tor", - "//brave/content:browser", "//brave/common/tor", "//brave/components/brave_ads/browser", "//brave/components/brave_rewards/browser", + "//brave/content:browser", + "//chrome/common", + "//content/public/common", "//ui/base", ] } diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index bbf5e5f43931..a273291a89d2 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -1,9 +1,9 @@ -import("//brave/build/config.gni") -import("//build/config/features.gni") 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_wallet/browser/buildflags/buildflags.gni") import("//brave/components/brave_sync/buildflags/buildflags.gni") +import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni") +import("//build/config/features.gni") import("//chrome/common/features.gni") source_set("ui") { @@ -65,8 +65,8 @@ source_set("ui") { if (enable_sparkle) { sources += [ - "webui/settings/brave_relaunch_handler_mac.mm", "webui/settings/brave_relaunch_handler_mac.h", + "webui/settings/brave_relaunch_handler_mac.mm", ] } } @@ -89,8 +89,8 @@ source_set("ui") { if (enable_sparkle) { sources += [ - "views/update_recommended_message_box_mac.mm", "views/update_recommended_message_box_mac.h", + "views/update_recommended_message_box_mac.mm", ] } @@ -136,9 +136,13 @@ source_set("ui") { deps = [ "//base", "//brave/app:command_ids", - "//brave/app/theme:brave_unscaled_resources", "//brave/app/theme:brave_theme_resources", + "//brave/app/theme:brave_unscaled_resources", "//brave/app/vector_icons:vector_icons", + "//brave/browser:sparkle_buildflags", + "//brave/browser/devtools", + "//brave/browser/resources/settings:resources", + "//brave/browser/tor", "//brave/common", "//brave/components/brave_adblock_ui:generated_resources", "//brave/components/brave_new_tab_ui:generated_resources", @@ -146,10 +150,6 @@ source_set("ui") { "//brave/components/brave_rewards/resources", "//brave/components/brave_shields/browser", "//brave/components/brave_welcome_ui:generated_resources", - "//brave/browser:sparkle_buildflags", - "//brave/browser/devtools", - "//brave/browser/tor", - "//brave/browser/resources/settings:resources", "//chrome/app:command_ids", "//chrome/common", "//components/prefs", @@ -158,22 +158,20 @@ source_set("ui") { "//skia", "//ui/accessibility", "//ui/base", - "//ui/resources", "//ui/gfx", + "//ui/resources", ] if (enable_brave_sync) { deps += [ "//brave/components/brave_sync", - "//brave/components/brave_sync:static_resources", "//brave/components/brave_sync:generated_resources", + "//brave/components/brave_sync:static_resources", ] } if (!is_android) { - deps += [ - "//brave/app:brave_generated_resources_grit", - ] + deps += [ "//brave/app:brave_generated_resources_grit" ] } if (enable_extensions) { @@ -206,8 +204,8 @@ source_set("ui") { deps += [ "//brave/browser/resources/extensions:resources", - "//brave/components/brave_extension:static_resources", "//brave/components/brave_extension:generated_resources", + "//brave/components/brave_extension:static_resources", "//chrome/browser/extensions", "//extensions/browser", ] @@ -223,14 +221,14 @@ source_set("ui") { if (brave_rewards_enabled) { sources += [ - "webui/brave_tip_ui.cc", - "webui/brave_tip_ui.h", - "webui/brave_rewards_source.cc", - "webui/brave_rewards_source.h", "webui/brave_rewards_internals_ui.cc", "webui/brave_rewards_internals_ui.h", + "webui/brave_rewards_source.cc", + "webui/brave_rewards_source.h", "webui/brave_rewards_ui.cc", "webui/brave_rewards_ui.h", + "webui/brave_tip_ui.cc", + "webui/brave_tip_ui.h", ] deps += [ @@ -244,8 +242,6 @@ source_set("ui") { "webui/brave_wallet_ui.cc", "webui/brave_wallet_ui.h", ] - deps += [ - "//brave/components/brave_wallet_ui:generated_resources", - ] + deps += [ "//brave/components/brave_wallet_ui:generated_resources" ] } } diff --git a/browser/ui/brave_browser_command_controller.cc b/browser/ui/brave_browser_command_controller.cc index ffcec513be07..cc9b5720ccba 100644 --- a/browser/ui/brave_browser_command_controller.cc +++ b/browser/ui/brave_browser_command_controller.cc @@ -8,11 +8,11 @@ #include "brave/app/brave_command_ids.h" #include "brave/browser/tor/buildflags.h" #include "brave/browser/ui/brave_pages.h" +#include "brave/browser/ui/browser_commands.h" +#include "brave/common/brave_switches.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 "brave/browser/ui/browser_commands.h" -#include "brave/common/brave_switches.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" diff --git a/browser/ui/toolbar/brave_app_menu_model.cc b/browser/ui/toolbar/brave_app_menu_model.cc index b287cbc2f219..06eaf152b8d5 100644 --- a/browser/ui/toolbar/brave_app_menu_model.cc +++ b/browser/ui/toolbar/brave_app_menu_model.cc @@ -37,19 +37,16 @@ void BraveAppMenuModel::InsertBraveMenuItems() { IDC_SHOW_BRAVE_REWARDS, IDS_SHOW_BRAVE_REWARDS); #if BUILDFLAG(BRAVE_WALLET_ENABLED) - InsertItemWithStringIdAt( - GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS), - IDC_SHOW_BRAVE_WALLET, - IDS_SHOW_BRAVE_WALLET); + InsertItemWithStringIdAt(GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS), + IDC_SHOW_BRAVE_WALLET, IDS_SHOW_BRAVE_WALLET); #endif - InsertItemWithStringIdAt( + InsertItemWithStringIdAt( #if BUILDFLAG(BRAVE_WALLET_ENABLED) GetIndexOfCommandId(IDC_SHOW_BRAVE_WALLET), #else GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS), #endif - IDC_SHOW_BRAVE_SYNC, - IDS_SHOW_BRAVE_SYNC); + IDC_SHOW_BRAVE_SYNC, IDS_SHOW_BRAVE_SYNC); } // Insert Create New Profile item diff --git a/browser/ui/toolbar/brave_app_menu_model_browsertest.cc b/browser/ui/toolbar/brave_app_menu_model_browsertest.cc index c8f68ab3bb36..fd0a6b06bf5b 100644 --- a/browser/ui/toolbar/brave_app_menu_model_browsertest.cc +++ b/browser/ui/toolbar/brave_app_menu_model_browsertest.cc @@ -9,6 +9,9 @@ #include "brave/app/brave_command_ids.h" #include "brave/browser/ui/brave_browser_command_controller.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/chrome_notification_types.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_window.h" @@ -18,9 +21,6 @@ #include "chrome/test/base/in_process_browser_test.h" #include "content/public/browser/notification_service.h" #include "content/public/test/test_utils.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" using BraveAppMenuBrowserTest = InProcessBrowserTest; diff --git a/browser/ui/webui/brave_web_ui_controller_factory.cc b/browser/ui/webui/brave_web_ui_controller_factory.cc index 50432e835eb2..37e80ea9c8ad 100644 --- a/browser/ui/webui/brave_web_ui_controller_factory.cc +++ b/browser/ui/webui/brave_web_ui_controller_factory.cc @@ -106,7 +106,7 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, url.host_piece() == chrome::kChromeUIWelcomeURL || #if BUILDFLAG(ENABLE_BRAVE_SYNC) (url.host_piece() == kBraveUISyncHost && - switches::IsBraveSyncAllowedByFlag()) || + switches::IsBraveSyncAllowedByFlag()) || #endif url.host_piece() == chrome::kChromeUINewTabHost || url.host_piece() == chrome::kChromeUISettingsHost) { diff --git a/browser/ui/webui/sync/sync_ui.cc b/browser/ui/webui/sync/sync_ui.cc index c95bb6f8f626..71022a4d0181 100644 --- a/browser/ui/webui/sync/sync_ui.cc +++ b/browser/ui/webui/sync/sync_ui.cc @@ -11,13 +11,13 @@ #include "base/bind.h" #include "base/memory/weak_ptr.h" #include "brave/common/webui_url_constants.h" -#include "brave/components/brave_sync/public/brave_profile_sync_service.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_resources.h" #include "brave/components/brave_sync/grit/brave_sync_generated_map.h" -#include "brave/components/brave_sync/sync_devices.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" @@ -125,9 +125,9 @@ void SyncUIDOMHandler::RegisterMessages() { void SyncUIDOMHandler::Init() { Profile* profile = Profile::FromWebUI(web_ui()); auto* profile_sync_service = - static_cast( - ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( - profile)); + static_cast( + ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( + profile)); sync_service_ = profile_sync_service->GetSyncService(); if (sync_service_) @@ -255,7 +255,7 @@ void SyncUIDOMHandler::OnHaveSyncWords( "sync_ui_exports.haveSyncWords", base::Value(sync_words)); } -} // namespace +} // namespace SyncUI::SyncUI(content::WebUI* web_ui, const std::string& name) : BasicUI(web_ui, name, diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index e4d35a8a5fee..5a792435a624 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -29,7 +29,7 @@ std::unique_ptr BraveBuildServiceInstanceFor( syncer::ProfileSyncService::InitParams init_params) { #if BUILDFLAG(ENABLE_BRAVE_SYNC) return std::make_unique(profile, - std::move(init_params)); + std::move(init_params)); #else return std::make_unique(std::move(init_params)); #endif diff --git a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc index af4af385032c..4694fafe13a3 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc @@ -27,35 +27,32 @@ SyncEngineHost* BraveGetSyncEngineHost(SyncEngineImpl* sync_engine) { } void OnNudgeSyncCycleOnOwnerThread(base::WeakPtr sync_engine, - brave_sync::RecordsListPtr records_list) { + brave_sync::RecordsListPtr records_list) { if (sync_engine.get()) static_cast( - BraveGetSyncEngineHost(sync_engine.get()))->OnNudgeSyncCycle( - std::move(records_list)); + 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, + sync_engine_impl.Call(FROM_HERE, &OnNudgeSyncCycleOnOwnerThread, base::Passed(&records_list)); } void OnPollSyncCycleOnOwnerThread(base::WeakPtr sync_engine, - GetRecordsCallback cb, - base::WaitableEvent* wevent) { + GetRecordsCallback cb, + base::WaitableEvent* wevent) { if (sync_engine.get()) static_cast( - BraveGetSyncEngineHost(sync_engine.get()))->OnPollSyncCycle(cb, wevent); + BraveGetSyncEngineHost(sync_engine.get())) + ->OnPollSyncCycle(cb, wevent); } void OnPollSyncCycle(WeakHandle sync_engine_impl, GetRecordsCallback cb, base::WaitableEvent* wevent) { - sync_engine_impl.Call(FROM_HERE, - &OnPollSyncCycleOnOwnerThread, - cb, - wevent); + sync_engine_impl.Call(FROM_HERE, &OnPollSyncCycleOnOwnerThread, cb, wevent); } #endif @@ -64,17 +61,14 @@ void BraveInit(WeakHandle sync_engine_impl, #if BUILDFLAG(ENABLE_BRAVE_SYNC) DCHECK(args); args->nudge_sync_cycle_delegate_function = - base::BindRepeating(&OnNudgeSyncCycle, - sync_engine_impl); + base::BindRepeating(&OnNudgeSyncCycle, sync_engine_impl); args->poll_sync_cycle_delegate_function = - base::BindRepeating(&OnPollSyncCycle, - sync_engine_impl); + base::BindRepeating(&OnPollSyncCycle, sync_engine_impl); #endif } } // namespace syncer -#define BRAVE_SYNC_ENGINE_BACKEND_DO_INITIALIZE \ -BraveInit(host_, &args); +#define BRAVE_SYNC_ENGINE_BACKEND_DO_INITIALIZE BraveInit(host_, &args); -#include "../../../../../../components/sync/driver/glue/sync_engine_backend.cc" // NOLINT +#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 index 0753e382b7af..98a3c9aa9129 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_impl.h +++ b/chromium_src/components/sync/driver/glue/sync_engine_impl.h @@ -7,8 +7,8 @@ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_GLUE_SYNC_ENGINE_IMPL_H_ #define BRAVE_SYNC_ENGINE_IMPL_H \ -friend SyncEngineHost* BraveGetSyncEngineHost(SyncEngineImpl*); + friend SyncEngineHost* BraveGetSyncEngineHost(SyncEngineImpl*); -#include "../../../../../../components/sync/driver/glue/sync_engine_impl.h" // NOLINT +#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_ +#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 91750d28ae84..6685e97e30f7 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -26,15 +26,15 @@ namespace syncer { const int64_t kBraveDefaultPollIntervalSeconds = 60; bool IsBraveSyncEnabled(ProfileSyncService* profile_sync_service) { - return static_cast( - profile_sync_service)->IsBraveSyncEnabled(); + 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)); + static_cast(profile_sync_service.get()) + ->OnNudgeSyncCycle(std::move(records_list)); } } @@ -42,32 +42,28 @@ 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(cb, wevent); + static_cast(profile_sync_service.get()) + ->OnPollSyncCycle(cb, wevent); } } #endif -void BraveInit( - base::WeakPtr profile_sync_service, - SyncPrefs* sync_prefs, - syncer::SyncEngine::InitParams* params) { +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); + base::BindRepeating(&OnNudgeSyncCycle, profile_sync_service); params->poll_sync_cycle_delegate_function = - base::BindRepeating(&OnPollSyncCycle, - profile_sync_service); + base::BindRepeating(&OnPollSyncCycle, profile_sync_service); sync_prefs->SetPollInterval( - base::TimeDelta::FromSeconds( - syncer::kBraveDefaultPollIntervalSeconds)); + base::TimeDelta::FromSeconds(syncer::kBraveDefaultPollIntervalSeconds)); #endif } -} // namespace syncer +} // namespace syncer // avoid redefining IsSyncFeatureEnabled in header #include "components/sync/driver/sync_service.h" @@ -76,9 +72,9 @@ void BraveInit( #define IsSyncFeatureEnabled() IsBraveSyncEnabled(this) #endif #define BRAVE_PROFILE_SYNC_SERVICE_START_UP_SLOW_ENGINE_COMPONENTS \ -BraveInit(sync_enabled_weak_factory_.GetWeakPtr(), &sync_prefs_, ¶ms); + BraveInit(sync_enabled_weak_factory_.GetWeakPtr(), &sync_prefs_, ¶ms); -#include "../../../../components/sync/driver/profile_sync_service.cc" // NOLINT +#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 diff --git a/chromium_src/components/sync/driver/profile_sync_service.h b/chromium_src/components/sync/driver/profile_sync_service.h index 1a150edfcd15..e516f8872b60 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.h +++ b/chromium_src/components/sync/driver/profile_sync_service.h @@ -8,12 +8,12 @@ namespace brave_sync { class BraveProfileSyncServiceImpl; -} // namesapce brave_sync +} // namespace brave_sync #define BRAVE_PROFILE_SYNC_SERVICE_H \ -friend class brave_sync::BraveProfileSyncServiceImpl; + friend class brave_sync::BraveProfileSyncServiceImpl; #include "../../../../../components/sync/driver/profile_sync_service.h" #undef BRAVE_PROFILE_SYNC_SERVICE_H -#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ diff --git a/chromium_src/components/sync/driver/sync_driver_switches.cc b/chromium_src/components/sync/driver/sync_driver_switches.cc index 1b656e72e96d..09f3e10dd165 100644 --- a/chromium_src/components/sync/driver/sync_driver_switches.cc +++ b/chromium_src/components/sync/driver/sync_driver_switches.cc @@ -15,4 +15,4 @@ bool IsSyncAllowedByFlag() { return IsSyncAllowedByFlag_ChromiumImpl() && IsBraveSyncAllowedByFlag(); } -} // namespace switches +} // namespace switches diff --git a/chromium_src/components/sync/engine/sync_engine.h b/chromium_src/components/sync/engine/sync_engine.h index 92c28554e131..2b27b9836498 100644 --- a/chromium_src/components/sync/engine/sync_engine.h +++ b/chromium_src/components/sync/engine/sync_engine.h @@ -8,11 +8,11 @@ #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; +#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_ +#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 index 64ed58511a41..cd0a9e821e36 100644 --- a/chromium_src/components/sync/engine/sync_manager.h +++ b/chromium_src/components/sync/engine/sync_manager.h @@ -10,13 +10,13 @@ namespace syncer { class Syncer; -} // namespace 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; +#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_ +#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 index d65a19c3e9bf..3f67bb572e0a 100644 --- a/chromium_src/components/sync/engine_impl/commit.cc +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -18,25 +18,25 @@ SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message, SyncCycle* cycle); } -} // namespace syncer +} // namespace syncer #define BRAVE_COMMIT_POST_AND_PROCESS_RESPONSE \ -PostBraveCommit(&message_, &response, cycle); + PostBraveCommit(&message_, &response, cycle); -#include "../../../../../components/sync/engine_impl/commit.cc" // NOLINT +#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_fwd.h" #include "brave/components/brave_sync/jslib_messages.h" +#include "brave/components/brave_sync/jslib_messages_fwd.h" #include "components/sync/base/time.h" #include "components/sync/base/unique_position.h" namespace syncer { namespace { -using brave_sync::jslib::SyncRecord; using brave_sync::jslib::MetaInfo; +using brave_sync::jslib::SyncRecord; const char kBookmarkBarTag[] = "bookmark_bar"; void CreateSuccessfulCommitResponse( @@ -54,19 +54,19 @@ void CreateSuccessfulCommitResponse( response->set_id_string(new_object_id); } -brave_sync::RecordsListPtr -ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, - sync_pb::ClientToServerResponse* response) { +brave_sync::RecordsListPtr ConvertCommitsToBraveRecords( + sync_pb::ClientToServerMessage* message, + sync_pb::ClientToServerResponse* response) { brave_sync::RecordsListPtr record_list = - std::make_unique(); + std::make_unique(); const sync_pb::CommitMessage& commit_message = message->commit(); - const std::string cache_guid = commit_message.cache_guid(); + const std::string cache_guid = commit_message.cache_guid(); 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(); + entity.specifics().bookmark(); auto record = std::make_unique(); record->objectData = brave_sync::jslib_const::SyncObjectData_BOOKMARK; @@ -76,7 +76,7 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, bookmark->site.customTitle = bm_specifics.title(); // bookmark->site.lastAccessedTime - ignored bookmark->site.creationTime = - ProtoTimeToTime(bm_specifics.creation_time_us()); + ProtoTimeToTime(bm_specifics.creation_time_us()); bookmark->site.favicon = bm_specifics.icon_url(); bookmark->isFolder = entity.folder(); // only mattters for direct children of permanent nodes @@ -84,7 +84,7 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, std::string originator_cache_guid; std::string originator_client_item_id; - bool skip_record = false; + 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(); @@ -94,8 +94,7 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, 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())); + std::stod(bm_specifics.meta_info(i).value())); } else if (bm_specifics.meta_info(i).key() == "originator_cache_guid") { originator_cache_guid = bm_specifics.meta_info(i).value(); } else if (bm_specifics.meta_info(i).key() == @@ -166,7 +165,7 @@ ConvertCommitsToBraveRecords(sync_pb::ClientToServerMessage* message, record_list->push_back(std::move(record)); } sync_pb::CommitResponse_EntryResponse* entry_response = - response->mutable_commit()->add_entryresponse(); + response->mutable_commit()->add_entryresponse(); CreateSuccessfulCommitResponse(entity, entry_response, new_object_id); } return record_list; @@ -176,11 +175,11 @@ SyncerError PostBraveCommit(sync_pb::ClientToServerMessage* message, sync_pb::ClientToServerResponse* response, SyncCycle* cycle) { brave_sync::RecordsListPtr records_list = - ConvertCommitsToBraveRecords(message, response); + ConvertCommitsToBraveRecords(message, response); cycle->delegate()->OnNudgeSyncCycle(std::move(records_list)); return SyncerError(SyncerError::SYNCER_OK); } -} // namespace -} // namespace syncer +} // 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 index cf0fd44ffd23..2437341a63cc 100644 --- a/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h +++ b/chromium_src/components/sync/engine_impl/cycle/sync_cycle.h @@ -8,12 +8,12 @@ #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) {} +#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_ +#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 index 636a0d427e17..df3fd4542a0d 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -12,12 +12,13 @@ namespace syncer { namespace { -SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*, ModelTypeSet*, +SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*, + ModelTypeSet*, std::unique_ptr); -} // namespace -} // namespace syncer +} // namespace +} // namespace syncer -#include "../../../../../components/sync/engine_impl/get_updates_processor.cc" // NOLINT +#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" @@ -26,8 +27,8 @@ SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*, ModelTypeSet*, #include "brave/components/brave_sync/jslib_messages.h" #include "components/sync/base/hash_util.h" #include "components/sync/base/time.h" -#include "components/sync/syncable/syncable_proto_util.h" #include "components/sync/engine_impl/loopback_server/loopback_server_entity.h" +#include "components/sync/syncable/syncable_proto_util.h" #include "url/gurl.h" namespace syncer { @@ -55,9 +56,9 @@ void AddBookmarkSpecifics(sync_pb::EntitySpecifics* specifics, bm_specifics->set_title(bookmark.site.TryGetNonEmptyTitle()); bm_specifics->set_creation_time_us( - TimeToProtoTime(bookmark.site.creationTime)); + TimeToProtoTime(bookmark.site.creationTime)); bm_specifics->set_icon_url(bookmark.site.favicon); - // base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds()); + // 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); @@ -150,7 +151,8 @@ void AddRootForType(sync_pb::SyncEntity* entity, ModelType type) { entity->mutable_specifics()->CopyFrom(specifics); } -void AddPermanentNode(sync_pb::SyncEntity* entity, const std::string& name, +void AddPermanentNode(sync_pb::SyncEntity* entity, + const std::string& name, const std::string& tag) { DCHECK(entity); sync_pb::EntitySpecifics specifics; @@ -205,7 +207,7 @@ void ConstructUpdateResponse(sync_pb::GetUpdatesResponse* gu_response, DCHECK(request_types); for (ModelType type : *request_types) { sync_pb::DataTypeProgressMarker* marker = - gu_response->add_new_progress_marker(); + gu_response->add_new_progress_marker(); marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); marker->set_token("token"); if (type == BOOKMARKS) { @@ -241,11 +243,11 @@ SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse* update_response, return SyncerError(SyncerError::SYNCER_OK); } -} // namespace +} // namespace void GetUpdatesProcessor::AddBraveRecords( std::unique_ptr records) { brave_records_ = std::move(records); } -} // namespace syncer +} // 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 index b2815ffaac58..e70f42654ad1 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.h +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.h @@ -12,13 +12,14 @@ namespace syncer { using brave_sync::RecordsList; } // namespace syncer -#define BRAVE_GET_UPDATES_PROCESSOR_H \ - public: \ +#define BRAVE_GET_UPDATES_PROCESSOR_H \ + public: \ void AddBraveRecords(std::unique_ptr records); \ - private: \ + \ + 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_ // NOLINT +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_GET_UPDATES_PROCESSOR_H_ diff --git a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc index 378a55c9c649..3c3fafb9487f 100644 --- a/chromium_src/components/sync/engine_impl/sync_manager_impl.cc +++ b/chromium_src/components/sync/engine_impl/sync_manager_impl.cc @@ -5,13 +5,13 @@ #include "components/sync/engine_impl/sync_scheduler_impl.h" -#define BRAVE_SYNC_MANAGER_IMPL_INIT \ +#define BRAVE_SYNC_MANAGER_IMPL_INIT \ static_cast(scheduler_.get()) \ - ->nudge_sync_cycle_delegate_function_ = \ - args->nudge_sync_cycle_delegate_function; \ + ->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; + ->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 index dd4dc6e0357b..eb33fca3db21 100644 --- a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc +++ b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc @@ -24,9 +24,9 @@ void SyncSchedulerImpl::OnPollSyncCycle(brave_sync::GetRecordsCallback cb, } // namespace syncer #define BRAVE_SYNC_SCHEDULER_IMPL_TRY_SYNC_CYCLE_JOB \ - SyncCycle cycle(cycle_context_, this); \ - if (mode_ != CONFIGURATION_MODE) { \ - syncer_->DownloadBraveRecords(&cycle); \ + 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 index f6aa4c585157..8870a48224bf 100644 --- a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.h +++ b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.h @@ -8,17 +8,17 @@ #include "brave/components/brave_sync/jslib_messages_fwd.h" -#define BRAVE_SYNC_SCHEDULER_IMPL_H \ - public: \ +#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_; \ + 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 +#undef BRAVE_SYNC_SCHEDULER_IMPL_H_ -#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_ // NOLINT +#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 index 6dc178b68085..1142f60ae2ce 100644 --- a/chromium_src/components/sync/engine_impl/syncer.cc +++ b/chromium_src/components/sync/engine_impl/syncer.cc @@ -8,7 +8,7 @@ #include #include -#include "../../../../../components/sync/engine_impl/syncer.cc" // NOLINT +#include "../../../../../components/sync/engine_impl/syncer.cc" // NOLINT namespace syncer { @@ -31,4 +31,3 @@ void Syncer::DownloadBraveRecords(SyncCycle* cycle) { } } // namespace syncer - diff --git a/chromium_src/components/sync/engine_impl/syncer.h b/chromium_src/components/sync/engine_impl/syncer.h index ac6d4fa316c3..a1c19f527701 100644 --- a/chromium_src/components/sync/engine_impl/syncer.h +++ b/chromium_src/components/sync/engine_impl/syncer.h @@ -10,14 +10,15 @@ #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: \ +#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_ +#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 index 6a8fbbf3b7d1..77492bb22fa5 100644 --- a/chromium_src/components/sync/syncable/write_transaction.cc +++ b/chromium_src/components/sync/syncable/write_transaction.cc @@ -3,14 +3,17 @@ * 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/syncable/write_transaction.cc" // NOLINT +#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) { - keep_ = true; + 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 index 8add792f4aa1..b96064e243a2 100644 --- a/chromium_src/components/sync/syncable/write_transaction.h +++ b/chromium_src/components/sync/syncable/write_transaction.h @@ -6,14 +6,14 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SYNCABLE_WRITE_TRANSACTION_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_SYNCABLE_WRITE_TRANSACTION_H_ -#define BRAVE_SYNC_ATTACHABLE_WRITE_TRANSACTION_H \ -public: \ +#define BRAVE_WRITE_TRANSACTION_H_ \ WriteTransaction(const base::Location& from_here, UserShare* share, \ - syncable::WriteTransaction* syncable_wr_tr); \ -private: \ - bool keep_ = false; + syncable::WriteTransaction* syncable_wr_tr); \ + \ + private: \ + bool close_transaction_ = true; #include "../../../../../components/sync/syncable/write_transaction.h" -#undef BRAVE_SYNC_ATTACHABLE_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_change_processor.cc b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc index 87e1ca91f2ac..fa42153a7542 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.cc @@ -23,18 +23,16 @@ namespace { class ScopedPauseObserver { public: explicit ScopedPauseObserver(BookmarkModel* model, - BookmarkModelObserver* observer) : - model_(model), observer_(observer) { + BookmarkModelObserver* observer) + : model_(model), observer_(observer) { DCHECK_NE(observer_, nullptr); DCHECK_NE(model_, nullptr); model_->RemoveObserver(observer_); } - ~ScopedPauseObserver() { - model_->AddObserver(observer_); - } + ~ScopedPauseObserver() { model_->AddObserver(observer_); } private: - BookmarkModel* model_; // Not owned + BookmarkModel* model_; // Not owned BookmarkModelObserver* observer_; // Not owned }; @@ -60,7 +58,7 @@ bool IsFirstLoadedFavicon(BookmarkChangeProcessor* bookmark_change_processor, return false; } -} // namespace +} // namespace namespace sync_bookmarks { @@ -68,13 +66,13 @@ void BookmarkChangeProcessor::MoveSyncNode( int index, const bookmarks::BookmarkNode* node, const syncer::BaseTransaction* trans) { - syncer::WriteTransaction write_trans(FROM_HERE, trans->GetUserShare(), + syncer::WriteTransaction write_trans( + FROM_HERE, trans->GetUserShare(), static_cast( trans->GetWrappedTrans())); syncer::WriteNode sync_node(&write_trans); if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { - syncer::SyncError error(FROM_HERE, - syncer::SyncError::DATATYPE_ERROR, + syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "Failed to init sync node from chrome node", syncer::BOOKMARKS); error_handler()->OnUnrecoverableError(error); @@ -83,40 +81,47 @@ void BookmarkChangeProcessor::MoveSyncNode( if (!PlaceSyncNode(MOVE, node->parent(), index, &write_trans, &sync_node, model_associator_)) { - syncer::SyncError error(FROM_HERE, - syncer::SyncError::DATATYPE_ERROR, - "Failed to place sync node", - syncer::BOOKMARKS); + syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, + "Failed to place sync node", syncer::BOOKMARKS); error_handler()->OnUnrecoverableError(error); return; } } -} // namespace sync_bookmarks +} // namespace sync_bookmarks #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED \ - if (IsFirstLoadedFavicon(this, bookmark_model_, node)) return; + if (IsFirstLoadedFavicon(this, bookmark_model_, node)) \ + return; + +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_UPDATE_SYNC_NODE_PROPERTIES \ + brave_sync::AddBraveMetaInfo(src, model); #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED \ - ScopedPauseObserver pause(bookmark_model_, this); \ - brave_sync::AddBraveMetaInfo(child, model); \ + ScopedPauseObserver pause(bookmark_model_, this); \ + brave_sync::AddBraveMetaInfo(child, model); \ SetSyncNodeMetaInfo(child, &sync_node); #define BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED \ - ScopedPauseObserver pause(bookmark_model_, this); \ - brave_sync::AddBraveMetaInfo(child, model); \ - SetSyncNodeMetaInfo(child, &sync_child); - -#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL \ - int new_index = brave_sync::GetIndexByCompareOrderStartFrom(dst->parent(), \ - dst, 0); \ - if (src.GetPositionIndex() != new_index) { \ - to_reposition.insert(std::make_pair(new_index, dst)); \ - MoveSyncNode(new_index, dst, trans); \ - } else // NOLINT - -#include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" // NOLINT + ScopedPauseObserver pause(bookmark_model_, this); \ + brave_sync::AddBraveMetaInfo(child, model); \ + SetSyncNodeMetaInfo(child, &sync_child); + +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL_1 \ + bookmark_model_->SetNodeMetaInfo(dst, "FirstLoadedFavicon", "true"); + +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL_2 \ + int new_index = \ + brave_sync::GetIndexByCompareOrderStartFrom(dst->parent(), dst, 0); \ + if (src.GetPositionIndex() != new_index) { \ + to_reposition.insert(std::make_pair(new_index, dst)); \ + MoveSyncNode(new_index, dst, trans); \ + } else // NOLINT + +#include "../../../../components/sync_bookmarks/bookmark_change_processor.cc" // NOLINT #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_FAVICON_CHANGED +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_UPDATE_SYNC_NODE_PROPERTIES #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_BOOKMARK_NODE_MOVED #undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_CHILDREN_REORDERED -#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL_1 +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL_2 diff --git a/chromium_src/components/sync_bookmarks/bookmark_change_processor.h b/chromium_src/components/sync_bookmarks/bookmark_change_processor.h index 845468bd088b..6d20851c5a68 100644 --- a/chromium_src/components/sync_bookmarks/bookmark_change_processor.h +++ b/chromium_src/components/sync_bookmarks/bookmark_change_processor.h @@ -6,13 +6,11 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ - -#define BRAVE_SYNC_REPOSITION_METHODS \ -void MoveSyncNode( \ - int index, \ - const bookmarks::BookmarkNode* node, \ - const syncer::BaseTransaction* trans); +#define BRAVE_BOOKMARK_CHANGE_PROCESSOR_H_ \ + void MoveSyncNode(int index, const bookmarks::BookmarkNode* node, \ + const syncer::BaseTransaction* trans); #include "../../../../../components/sync_bookmarks/bookmark_change_processor.h" +#undef BRAVE_BOOKMARK_CHANGE_PROCESSOR_H_ #endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_CHANGE_PROCESSOR_H_ diff --git a/common/extensions/api/BUILD.gn b/common/extensions/api/BUILD.gn index b18c7223b851..171a3b8c23c5 100644 --- a/common/extensions/api/BUILD.gn +++ b/common/extensions/api/BUILD.gn @@ -1,8 +1,8 @@ import("//brave/components/brave_sync/buildflags/buildflags.gni") import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni") +import("//tools/grit/grit_rule.gni") import("//tools/json_schema_compiler/json_features.gni") import("//tools/json_schema_compiler/json_schema_api.gni") -import("//tools/grit/grit_rule.gni") json_features("api_features") { feature_type = "APIFeature" method_name = "AddBraveAPIFeatures" @@ -13,9 +13,7 @@ json_features("api_features") { ] if (brave_wallet_enabled) { - sources += [ - "_brave_wallet_api_features.json", - ] + sources += [ "_brave_wallet_api_features.json" ] } } @@ -55,15 +53,11 @@ brave_extensions_api_schema_sources = [ ] if (enable_brave_sync) { - brave_extensions_api_schema_sources += [ - "brave_sync.json", - ] + brave_extensions_api_schema_sources += [ "brave_sync.json" ] } if (brave_wallet_enabled) { - brave_extensions_api_schema_sources += [ - "brave_wallet.json" - ] + brave_extensions_api_schema_sources += [ "brave_wallet.json" ] } brave_extensions_api_uncompiled_sources = [] @@ -104,7 +98,6 @@ function_registration("generated_api_registration") { visibility = [ ":api" ] } - generated_json_strings("generated_api_json_strings") { sources = brave_extensions_api_schema_sources + brave_extensions_api_uncompiled_sources diff --git a/components/brave_sync/BUILD.gn b/components/brave_sync/BUILD.gn index 3c19e7c3e71e..eef6eee0a4e3 100644 --- a/components/brave_sync/BUILD.gn +++ b/components/brave_sync/BUILD.gn @@ -1,8 +1,8 @@ -import("buildflags/buildflags.gni") import("//brave/components/common/typescript.gni") import("//build/config/features.gni") import("//tools/grit/grit_rule.gni") import("//tools/grit/repack.gni") +import("buildflags/buildflags.gni") if (enable_brave_sync) { source_set("js_sync_lib_impl") { @@ -12,26 +12,26 @@ if (enable_brave_sync) { "client/brave_sync_client.h", "client/brave_sync_client_impl.cc", "client/brave_sync_client_impl.h", - "client/client_ext_impl_data.cc", - "client/client_ext_impl_data.h", "client/client_data.cc", "client/client_data.h", + "client/client_ext_impl_data.cc", + "client/client_ext_impl_data.h", ] deps = [ ":public", "//base", - "//components/prefs", "//components/bookmarks/browser", "//components/bookmarks/common", "//components/keyed_service/content", "//components/keyed_service/core", - "//components/prefs", "//components/pref_registry", + "//components/prefs", + "//components/prefs", "//content/public/browser", "//extensions/browser", - "//services/network/public/cpp", "//net", + "//services/network/public/cpp", "//ui/base", ] } @@ -72,12 +72,13 @@ source_set("public") { ] deps = [ - "buildflags", + "buildflags", ] if (enable_brave_sync) { deps += [ ":core", + # For IsBraveSyncAllowedByFlag in # components/sync/driver/sync_driver_switches.cc "//brave/common:switches", @@ -121,9 +122,7 @@ source_set("brave_sync") { ] if (enable_brave_sync) { - deps += [ - ":js_sync_lib_impl", - ] + deps += [ ":js_sync_lib_impl" ] } } @@ -131,7 +130,7 @@ pack_web_resources("generated_resources") { resource_name = "brave_sync" output_dir = "$root_gen_dir/brave/components/brave_sync" deps = [ - "ui" + "ui", ] } @@ -159,33 +158,33 @@ grit("static_resources") { repack("resources") { deps = [ - ":static_resources", ":generated_resources", + ":static_resources", ] sources = [ - "$root_gen_dir/brave/components/brave_sync/brave_sync_static.pak", "$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 + source_set("testutil") { + testonly = true - deps = [ - ":brave_sync", - "//base", - "//content/public/browser", - "//chrome/test:test_support", - "//testing/gtest", - ] + deps = [ + ":brave_sync", + "//base", + "//chrome/test:test_support", + "//content/public/browser", + "//testing/gtest", + ] - sources = [ - "test_util.cc", - "test_util.h", - ] -} + 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 index e035925dd21c..30fa629f9c88 100644 --- a/components/brave_sync/bookmark_order_util.cc +++ b/components/brave_sync/bookmark_order_util.cc @@ -13,10 +13,10 @@ namespace brave_sync { namespace { bool CompareOrder(const std::vector& vec_left, - const std::vector& vec_right) { + const std::vector& vec_right) { // Use C++ stdlib return std::lexicographical_compare(vec_left.begin(), vec_left.end(), - vec_right.begin(), vec_right.end()); + vec_right.begin(), vec_right.end()); } } // namespace @@ -39,7 +39,7 @@ std::vector OrderToIntVect(const std::string& s) { return vec_int; } -std::string ToOrderString(const std::vector &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) { @@ -94,8 +94,9 @@ std::string GetPrevOrderFromNextOrder(std::vector* 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) { +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"; @@ -160,13 +161,14 @@ std::string GetOrder(const std::string& prev, const std::string& next, } } - NOTREACHED() << "[BraveSync] " << __func__ << " prev=" << prev << - " next=" << next << " terminated with " << 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(); + NOTREACHED() << "[BraveSync] " << __func__ + << " condition is not handled prev.empty()=" << prev.empty() + << " next.empty()=" << next.empty(); return ""; } diff --git a/components/brave_sync/bookmark_order_util.h b/components/brave_sync/bookmark_order_util.h index b47248eeb287..6a9d9504f695 100644 --- a/components/brave_sync/bookmark_order_util.h +++ b/components/brave_sync/bookmark_order_util.h @@ -12,11 +12,12 @@ namespace brave_sync { std::vector OrderToIntVect(const std::string& s); - std::string ToOrderString(const std::vector &vec_int); + 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); + std::string GetOrder(const std::string& prev, + const std::string& next, + const std::string& parent); -} // namespace brave_sync + } // 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 index 54d6e2907b2e..98a911177262 100644 --- a/components/brave_sync/bookmark_order_util_unittest.cc +++ b/components/brave_sync/bookmark_order_util_unittest.cc @@ -81,7 +81,8 @@ TEST(BookmarkOrderUtilTest, CompareOrder) { } TEST(BookmarkOrderUtilTest, GetOrder) { - // Ported from https://github.com/brave/sync/blob/staging/test/client/bookmarkUtil.js + // 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"); @@ -111,4 +112,4 @@ TEST(BookmarkOrderUtilTest, GetOrder) { EXPECT_EQ(GetOrder("1.1.1.2.1", "1.1.1.3", ""), "1.1.1.2.2"); } -} // namespace brave_sync +} // 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 index bcd1b000b16e..c75f2c964add 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -11,16 +11,16 @@ #include "base/bind.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" -#include "brave/components/brave_sync/values_conv.h" #include "brave/components/brave_sync/brave_sync_prefs.h" #include "brave/components/brave_sync/brave_sync_service_observer.h" #include "brave/components/brave_sync/client/brave_sync_client_impl.h" #include "brave/components/brave_sync/jslib_const.h" #include "brave/components/brave_sync/jslib_messages.h" #include "brave/components/brave_sync/settings.h" -#include "brave/components/brave_sync/syncer_helper.h" #include "brave/components/brave_sync/sync_devices.h" +#include "brave/components/brave_sync/syncer_helper.h" #include "brave/components/brave_sync/tools.h" +#include "brave/components/brave_sync/values_conv.h" #include "chrome/browser/sync/chrome_sync_client.h" #include "components/bookmarks/browser/bookmark_model.h" #include "components/signin/core/browser/account_info.h" @@ -32,6 +32,7 @@ namespace brave_sync { using browser_sync::ChromeSyncClient; +using jslib::Device; using jslib::MetaInfo; using jslib::SyncRecord; using jslib_const::kBookmarks; @@ -39,15 +40,13 @@ using jslib_const::kHistorySites; using jslib_const::kPreferences; using jslib_const::SyncObjectData_DEVICE; using jslib_const::SyncRecordType_PREFERENCES; -using jslib::Device; using tools::IsTimeEmpty; -const std::vector - BraveProfileSyncServiceImpl::kExponentialWaits = {10, 20, 40, 80}; +const std::vector BraveProfileSyncServiceImpl::kExponentialWaits = { + 10, 20, 40, 80}; const int BraveProfileSyncServiceImpl::kMaxSendRetries = BraveProfileSyncServiceImpl::kExponentialWaits.size() - 1; - namespace { AccountInfo GetDummyAccountInfo() { @@ -70,15 +69,15 @@ std::string GetDeviceName() { #elif defined(OS_WIN) hostname = std::string("Windows Desktop"); #endif - } + } return hostname; } RecordsListPtr CreateDeviceCreationRecordExtension( - const std::string& deviceName, - const std::string& objectId, - const SyncRecord::Action &action, - const std::string& deviceId) { + const std::string& deviceName, + const std::string& objectId, + const SyncRecord::Action& action, + const std::string& deviceId) { RecordsListPtr records = std::make_unique(); SyncRecordPtr record = std::make_unique(); @@ -98,9 +97,9 @@ RecordsListPtr CreateDeviceCreationRecordExtension( } const bookmarks::BookmarkNode* FindByObjectId(bookmarks::BookmarkModel* model, - const std::string& object_id) { - ui::TreeNodeIterator - iterator(model->root_node()); + const std::string& object_id) { + ui::TreeNodeIterator iterator( + model->root_node()); while (iterator.has_next()) { const bookmarks::BookmarkNode* node = iterator.Next(); std::string node_object_id; @@ -144,15 +143,15 @@ void AddSyncEntityInfo(jslib::Bookmark* bookmark, } } -} // namespace +} // namespace BraveProfileSyncServiceImpl::BraveProfileSyncServiceImpl(Profile* profile, - InitParams init_params) : - BraveProfileSyncService(std::move(init_params)), - brave_sync_client_(BraveSyncClient::Create(this, profile)) { + InitParams init_params) + : BraveProfileSyncService(std::move(init_params)), + brave_sync_client_(BraveSyncClient::Create(this, profile)) { brave_sync_words_ = std::string(); brave_sync_prefs_ = - std::make_unique(sync_client_->GetPrefService()); + std::make_unique(sync_client_->GetPrefService()); // Moniter syncs prefs required in GetSettingsAndDevices brave_pref_change_registrar_.Init(sync_client_->GetPrefService()); @@ -182,8 +181,8 @@ BraveProfileSyncServiceImpl::BraveProfileSyncServiceImpl(Profile* profile, base::Unretained(this))); // TODO(darkdh): find another way to obtain bookmark model // change introduced in 83b9663e3814ef7e53af5009d10033b89955db44 - model_ = static_cast(sync_client_.get()) - ->GetBookmarkModel(); + model_ = + static_cast(sync_client_.get())->GetBookmarkModel(); if (!brave_sync_prefs_->GetSeed().empty() && !brave_sync_prefs_->GetThisDeviceName().empty()) { @@ -192,8 +191,7 @@ BraveProfileSyncServiceImpl::BraveProfileSyncServiceImpl(Profile* profile, network_connection_tracker_->AddNetworkConnectionObserver(this); } -void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( - RecordsListPtr records) { +void BraveProfileSyncServiceImpl::OnNudgeSyncCycle(RecordsListPtr records) { if (!IsBraveSyncEnabled()) return; @@ -202,15 +200,14 @@ void BraveProfileSyncServiceImpl::OnNudgeSyncCycle( } if (!records->empty()) { if (((!brave_sync::tools::IsTimeEmpty(chain_created_time_) && - (base::Time::Now() - chain_created_time_).InSeconds() < 30u) || - brave_sync_prefs_->GetSyncDevices()->size() < 2)) { + (base::Time::Now() - chain_created_time_).InSeconds() < 30u) || + brave_sync_prefs_->GetSyncDevices()->size() < 2)) { // Store records for now pending_send_records_.push_back(std::move(records)); return; } SendAndPurgePendingRecords(); - SendSyncRecords( - jslib_const::SyncRecordType_BOOKMARKS, std::move(records)); + SendSyncRecords(jslib_const::SyncRecordType_BOOKMARKS, std::move(records)); } } @@ -219,7 +216,8 @@ BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() { } void BraveProfileSyncServiceImpl::OnSetupSyncHaveCode( - const std::string& sync_words, const std::string& device_name) { + const std::string& sync_words, + const std::string& device_name) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); if (sync_words.empty()) { OnSyncSetupError("ERR_SYNC_WRONG_WORDS"); @@ -284,12 +282,12 @@ void BraveProfileSyncServiceImpl::OnDeleteDevice(const std::string& device_id) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); auto sync_devices = brave_sync_prefs_->GetSyncDevices(); - const SyncDevice *device = sync_devices->GetByDeviceId(device_id); + const SyncDevice* device = sync_devices->GetByDeviceId(device_id); if (device) { const std::string device_name = device->name_; const std::string object_id = device->object_id_; - SendDeviceSyncRecord( - SyncRecord::Action::A_DELETE, device_name, device_id, object_id); + SendDeviceSyncRecord(SyncRecord::Action::A_DELETE, device_name, device_id, + object_id); } } @@ -339,7 +337,7 @@ void BraveProfileSyncServiceImpl::OnSetSyncBookmarks( const bool sync_bookmarks) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); syncer::UserSelectableTypeSet type_set = - ProfileSyncService::GetUserSettings()->GetSelectedTypes(); + ProfileSyncService::GetUserSettings()->GetSelectedTypes(); if (sync_bookmarks) type_set.Put(syncer::UserSelectableType::kBookmarks); else @@ -359,11 +357,9 @@ void BraveProfileSyncServiceImpl::OnSetSyncSavedSiteSettings( brave_sync_prefs_->SetSyncSiteSettingsEnabled(sync_saved_site_settings); } -void BraveProfileSyncServiceImpl::BackgroundSyncStarted(bool startup) { -} +void BraveProfileSyncServiceImpl::BackgroundSyncStarted(bool startup) {} -void BraveProfileSyncServiceImpl::BackgroundSyncStopped(bool shutdown) { -} +void BraveProfileSyncServiceImpl::BackgroundSyncStopped(bool shutdown) {} void BraveProfileSyncServiceImpl::OnSyncDebug(const std::string& message) { NotifyLogMessage(message); @@ -394,8 +390,8 @@ void BraveProfileSyncServiceImpl::OnGetInitData( Uint8Array device_id; if (!brave_sync_prefs_->GetThisDeviceId().empty()) { device_id = Uint8ArrayFromString(brave_sync_prefs_->GetThisDeviceId()); - VLOG(1) << "[Brave Sync] Init device id from prefs: " << - StrFromUint8Array(device_id); + VLOG(1) << "[Brave Sync] Init device id from prefs: " + << StrFromUint8Array(device_id); } else { VLOG(1) << "[Brave Sync] Init empty device id"; } @@ -411,11 +407,11 @@ void BraveProfileSyncServiceImpl::OnGetInitData( config.server_url = "https://sync.brave.com"; config.debug = true; brave_sync_client_->SendGotInitData(seed, device_id, config, - brave_sync_words_); + brave_sync_words_); } void BraveProfileSyncServiceImpl::OnSaveInitData(const Uint8Array& seed, - const Uint8Array& device_id) { + const Uint8Array& device_id) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(!brave_sync_initialized_); // If we are here and brave_sync_initializing_ is false, we have came @@ -456,12 +452,11 @@ void BraveProfileSyncServiceImpl::OnSaveInitData(const Uint8Array& seed, void BraveProfileSyncServiceImpl::OnSyncReady() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); const std::string bookmarks_base_order = - brave_sync_prefs_->GetBookmarksBaseOrder(); + brave_sync_prefs_->GetBookmarksBaseOrder(); if (bookmarks_base_order.empty()) { std::string platform = tools::GetPlatformName(); brave_sync_client_->SendGetBookmarksBaseOrder( - brave_sync_prefs_->GetThisDeviceId(), - platform); + brave_sync_prefs_->GetThisDeviceId(), platform); // OnSyncReady will be called by OnSaveBookmarksBaseOrder return; } @@ -476,8 +471,8 @@ void BraveProfileSyncServiceImpl::OnSyncReady() { syncer::SyncPrefs sync_prefs(sync_client_->GetPrefService()); // first time setup sync or migrated from legacy sync if (sync_prefs.GetLastSyncedTime().is_null()) { - ProfileSyncService::GetUserSettings() - ->SetSelectedTypes(false, syncer::UserSelectableTypeSet()); + ProfileSyncService::GetUserSettings()->SetSelectedTypes( + false, syncer::UserSelectableTypeSet()); // default enable bookmark // this is important, don't change // to brave_sync_prefs_->SetSyncBookmarksEnabled(true); @@ -486,19 +481,19 @@ void BraveProfileSyncServiceImpl::OnSyncReady() { } } -syncer::ModelTypeSet -BraveProfileSyncServiceImpl::GetPreferredDataTypes() const { +syncer::ModelTypeSet BraveProfileSyncServiceImpl::GetPreferredDataTypes() + const { // Force DEVICE_INFO type to have nudge cycle each time to fetch // Brave sync devices. // Will be picked up by ProfileSyncService::ConfigureDataTypeManager return Union(ProfileSyncService::GetPreferredDataTypes(), - { syncer::DEVICE_INFO }); + {syncer::DEVICE_INFO}); } void BraveProfileSyncServiceImpl::OnGetExistingObjects( const std::string& category_name, std::unique_ptr records, - const base::Time &last_record_time_stamp, + const base::Time& last_record_time_stamp, const bool is_truncated) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); // TODO(bridiver) - what do we do with is_truncated ? @@ -510,8 +505,7 @@ void BraveProfileSyncServiceImpl::OnGetExistingObjects( if (category_name == kBookmarks) { auto records_and_existing_objects = std::make_unique(); - CreateResolveList( - *records.get(), records_and_existing_objects.get()); + CreateResolveList(*records.get(), records_and_existing_objects.get()); brave_sync_client_->SendResolveSyncRecords( category_name, std::move(records_and_existing_objects)); } @@ -529,10 +523,9 @@ void BraveProfileSyncServiceImpl::OnResolvedSyncRecords( } // Send records to syncer if (get_record_cb_) - sync_thread_->task_runner()->PostTask(FROM_HERE, - base::BindOnce(&DoDispatchGetRecordsCallback, - get_record_cb_, - std::move(records))); + sync_thread_->task_runner()->PostTask( + FROM_HERE, base::BindOnce(&DoDispatchGetRecordsCallback, + get_record_cb_, std::move(records))); SignalWaitableEvent(); } else if (category_name == kHistorySites) { NOTIMPLEMENTED(); @@ -574,8 +567,8 @@ int BraveProfileSyncServiceImpl::GetDisableReasons() const { return ProfileSyncService::GetDisableReasons(); } -CoreAccountInfo -BraveProfileSyncServiceImpl::GetAuthenticatedAccountInfo() const { +CoreAccountInfo BraveProfileSyncServiceImpl::GetAuthenticatedAccountInfo() + const { return GetDummyAccountInfo(); } @@ -676,9 +669,8 @@ BraveProfileSyncServiceImpl::BookmarkNodeToSyncBookmark( bookmark->site.favicon = node->icon_url() ? node->icon_url()->spec() : ""; // Url may have type OTHER_NODE if it is in Deleted Bookmarks bookmark->isFolder = (node->type() != bookmarks::BookmarkNode::URL && - node->type() != bookmarks::BookmarkNode::OTHER_NODE); - bookmark->hideInToolbar = - node->parent() != model_->bookmark_bar_node(); + node->type() != bookmarks::BookmarkNode::OTHER_NODE); + bookmark->hideInToolbar = node->parent() != model_->bookmark_bar_node(); std::string object_id; node->GetMetaInfo("object_id", &object_id); @@ -777,9 +769,9 @@ void BraveProfileSyncServiceImpl::CreateResolveList( } void BraveProfileSyncServiceImpl::FetchSyncRecords(const bool bookmarks, - const bool history, - const bool preferences, - int max_records) { + const bool history, + const bool preferences, + int max_records) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(bookmarks || history || preferences); if (!(bookmarks || history || preferences)) { @@ -791,7 +783,7 @@ void BraveProfileSyncServiceImpl::FetchSyncRecords(const bool bookmarks, category_names.push_back(kHistorySites); // "HISTORY_SITES"; } if (bookmarks) { - category_names.push_back(kBookmarks); // "BOOKMARKS"; + category_names.push_back(kBookmarks); // "BOOKMARKS"; } if (preferences) { category_names.push_back(kPreferences); // "PREFERENCES"; @@ -800,10 +792,8 @@ void BraveProfileSyncServiceImpl::FetchSyncRecords(const bool bookmarks, brave_sync_prefs_->SetLastFetchTime(base::Time::Now()); base::Time start_at_time = brave_sync_prefs_->GetLatestRecordTime(); - brave_sync_client_->SendFetchSyncRecords( - category_names, - start_at_time, - max_records); + brave_sync_client_->SendFetchSyncRecords(category_names, start_at_time, + max_records); } void BraveProfileSyncServiceImpl::SendCreateDevice() { @@ -814,11 +804,8 @@ void BraveProfileSyncServiceImpl::SendCreateDevice() { std::string device_id = brave_sync_prefs_->GetThisDeviceId(); CHECK(!device_id.empty()); - SendDeviceSyncRecord( - SyncRecord::Action::A_CREATE, - device_name, - device_id, - object_id); + SendDeviceSyncRecord(SyncRecord::Action::A_CREATE, device_name, device_id, + object_id); } void BraveProfileSyncServiceImpl::SendDeviceSyncRecord( @@ -828,12 +815,9 @@ void BraveProfileSyncServiceImpl::SendDeviceSyncRecord( const std::string& object_id) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); RecordsListPtr records = CreateDeviceCreationRecordExtension( - device_name, - object_id, - static_cast(action), + device_name, object_id, static_cast(action), device_id); - SendSyncRecords( - SyncRecordType_PREFERENCES, std::move(records)); + SendSyncRecords(SyncRecordType_PREFERENCES, std::move(records)); } void BraveProfileSyncServiceImpl::OnResolvedPreferences( @@ -844,24 +828,21 @@ void BraveProfileSyncServiceImpl::OnResolvedPreferences( auto sync_devices = brave_sync_prefs_->GetSyncDevices(); auto old_devices_size = sync_devices->size(); - for (const auto &record : records) { + for (const auto& record : records) { DCHECK(record->has_device() || record->has_sitesetting()); if (record->has_device()) { bool actually_merged = false; sync_devices->Merge( - SyncDevice(record->GetDevice().name, - record->objectId, - record->deviceId, - record->syncTimestamp.ToJsTime()), - record->action, - &actually_merged); - this_device_deleted = this_device_deleted || - (record->deviceId == this_device_id && - record->action == SyncRecord::Action::A_DELETE && - actually_merged); - contains_only_one_device = sync_devices->size() < 2 && - record->action == SyncRecord::Action::A_DELETE && - actually_merged; + SyncDevice(record->GetDevice().name, record->objectId, + record->deviceId, record->syncTimestamp.ToJsTime()), + record->action, &actually_merged); + this_device_deleted = + this_device_deleted || + (record->deviceId == this_device_id && + record->action == SyncRecord::Action::A_DELETE && actually_merged); + contains_only_one_device = + sync_devices->size() < 2 && + record->action == SyncRecord::Action::A_DELETE && actually_merged; } } // for each device @@ -911,14 +892,14 @@ bool BraveProfileSyncServiceImpl::IsBraveSyncInitialized() const { bool BraveProfileSyncServiceImpl::IsBraveSyncConfigured() const { return brave_sync_configured_ && - // When there is 0 or 1 device, it means chain is not completely created, - // so we should give a chance to make force reset in |OnSetupSyncHaveCode| - // or in |OnSetupSyncNewToSync| - (brave_sync_prefs_->GetSyncDevices()->size() >= 2); + // When there is 0 or 1 device, it means chain is not completely + // created, so we should give a chance to make force reset in + // |OnSetupSyncHaveCode| or in |OnSetupSyncNewToSync| + (brave_sync_prefs_->GetSyncDevices()->size() >= 2); } void BraveProfileSyncServiceImpl::OnPollSyncCycle(GetRecordsCallback cb, - base::WaitableEvent* wevent) { + base::WaitableEvent* wevent) { if (!IsBraveSyncEnabled()) return; @@ -955,8 +936,8 @@ BraveSyncService* BraveProfileSyncServiceImpl::GetSyncService() const { void BraveProfileSyncServiceImpl::SendAndPurgePendingRecords() { for (auto& records_to_send : pending_send_records_) { - SendSyncRecords( - jslib_const::SyncRecordType_BOOKMARKS, std::move(records_to_send)); + SendSyncRecords(jslib_const::SyncRecordType_BOOKMARKS, + std::move(records_to_send)); } pending_send_records_.clear(); } @@ -969,7 +950,7 @@ void BraveProfileSyncServiceImpl::SendSyncRecords( for (auto& record : *records) { SaveSyncEntityInfo(record.get()); std::unique_ptr meta = - std::make_unique(); + std::make_unique(); meta->SetInteger("send_retry_number", 0); meta->SetDouble("sync_timestamp", record->syncTimestamp.ToJsTime()); brave_sync_prefs_->AddToRecordsToResend(record->objectId, @@ -983,7 +964,7 @@ void BraveProfileSyncServiceImpl::ResendSyncRecords( if (category_name == kBookmarks) { RecordsListPtr records = std::make_unique(); std::vector records_to_resend = - brave_sync_prefs_->GetRecordsToResend(); + brave_sync_prefs_->GetRecordsToResend(); if (records_to_resend.empty()) return; for (auto& object_id : records_to_resend) { @@ -991,7 +972,7 @@ void BraveProfileSyncServiceImpl::ResendSyncRecords( // Check resend interval const base::DictionaryValue* meta = - brave_sync_prefs_->GetRecordToResendMeta(object_id); + brave_sync_prefs_->GetRecordToResendMeta(object_id); DCHECK(meta); int current_retry_number = kMaxSendRetries; meta->GetInteger("send_retry_number", ¤t_retry_number); @@ -1000,8 +981,7 @@ void BraveProfileSyncServiceImpl::ResendSyncRecords( meta->GetDouble("sync_timestamp", &sync_timestamp); DCHECK(!base::Time::FromJsTime(sync_timestamp).is_null()); - if ((base::Time::Now() - - base::Time::FromJsTime(sync_timestamp)) < + if ((base::Time::Now() - base::Time::FromJsTime(sync_timestamp)) < GetRetryExponentialWaitAmount(current_retry_number)) continue; @@ -1009,8 +989,8 @@ void BraveProfileSyncServiceImpl::ResendSyncRecords( if (++current_retry_number > kMaxSendRetries) current_retry_number = kMaxSendRetries; std::unique_ptr new_meta = - base::DictionaryValue::From( - std::make_unique(meta->Clone())); + base::DictionaryValue::From( + std::make_unique(meta->Clone())); new_meta->SetInteger("send_retry_number", current_retry_number); brave_sync_prefs_->SetRecordToResendMeta(object_id, std::move(new_meta)); @@ -1018,7 +998,7 @@ void BraveProfileSyncServiceImpl::ResendSyncRecords( records->push_back(BookmarkNodeToSyncBookmark(node)); } else { records->push_back( - CreateDeleteBookmarkByObjectId(brave_sync_prefs_.get(), object_id)); + CreateDeleteBookmarkByObjectId(brave_sync_prefs_.get(), object_id)); } } if (!records->empty()) @@ -1043,4 +1023,4 @@ BraveProfileSyncServiceImpl::GetExponentialWaitsForTests() { return kExponentialWaits; } -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/brave_profile_sync_service_impl.h b/components/brave_sync/brave_profile_sync_service_impl.h index 5f230982cb99..35d65b6c6da8 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.h +++ b/components/brave_sync/brave_profile_sync_service_impl.h @@ -44,13 +44,13 @@ class BraveSyncServiceTest; namespace brave_sync { namespace prefs { class Prefs; -} // namespace prefs +} // namespace prefs class BraveProfileSyncServiceImpl - : public BraveProfileSyncService, - public BraveSyncService, - public network::NetworkConnectionTracker::NetworkConnectionObserver, - public SyncMessageHandler { + : public BraveProfileSyncService, + public BraveSyncService, + public network::NetworkConnectionTracker::NetworkConnectionObserver, + public SyncMessageHandler { public: explicit BraveProfileSyncServiceImpl(Profile* profile, InitParams init_params); @@ -83,7 +83,7 @@ class BraveProfileSyncServiceImpl void OnSyncReady() override; void OnGetExistingObjects(const std::string& category_name, std::unique_ptr records, - const base::Time &last_record_time_stamp, + const base::Time& last_record_time_stamp, const bool is_truncated) override; void OnResolvedSyncRecords( const std::string& category_name, @@ -146,8 +146,10 @@ class BraveProfileSyncServiceImpl friend class ::BraveSyncServiceTest; void SignalWaitableEvent(); - void FetchSyncRecords(const bool bookmarks, const bool history, - const bool preferences, int max_records); + void FetchSyncRecords(const bool bookmarks, + const bool history, + const bool preferences, + int max_records); void SendCreateDevice(); void SendDeviceSyncRecord(const int action, const std::string& device_name, @@ -161,22 +163,20 @@ class BraveProfileSyncServiceImpl void ResetSyncInternal(); void ForceCompleteReset(); - bool GetResettingForTest() const { - return reseting_; - } + bool GetResettingForTest() const { return reseting_; } void SetPermanentNodesOrder(const std::string& base_order); std::unique_ptr BookmarkNodeToSyncBookmark( - const bookmarks::BookmarkNode* node); + const bookmarks::BookmarkNode* node); // These SyncEntityInfo is for legacy device who doesn't send meta info for // sync entity void SaveSyncEntityInfo(const jslib::SyncRecord* record); void LoadSyncEntityInfo(jslib::SyncRecord* record); void CreateResolveList( - const std::vector>& records, - SyncRecordAndExistingList* records_and_existing_objects); + const std::vector>& records, + SyncRecordAndExistingList* records_and_existing_objects); void SendAndPurgePendingRecords(); @@ -184,7 +184,6 @@ class BraveProfileSyncServiceImpl RecordsListPtr records); void ResendSyncRecords(const std::string& category_name); - static base::TimeDelta GetRetryExponentialWaitAmount(int retry_number); static std::vector GetExponentialWaitsForTests(); static const std::vector kExponentialWaits; @@ -224,6 +223,6 @@ class BraveProfileSyncServiceImpl DISALLOW_COPY_AND_ASSIGN(BraveProfileSyncServiceImpl); }; -} // namespace brave_sync +} // namespace brave_sync #endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_PROFILE_SYNC_SERVICE_IMPL_H_ diff --git a/components/brave_sync/brave_sync_prefs.cc b/components/brave_sync/brave_sync_prefs.cc index f51876d050c5..ff5402bb90b3 100644 --- a/components/brave_sync/brave_sync_prefs.cc +++ b/components/brave_sync/brave_sync_prefs.cc @@ -9,9 +9,9 @@ #include "brave/components/brave_sync/settings.h" #include "brave/components/brave_sync/sync_devices.h" +#include "components/pref_registry/pref_registry_syncable.h" #include "components/prefs/pref_service.h" #include "components/prefs/scoped_user_pref_update.h" -#include "components/pref_registry/pref_registry_syncable.h" namespace brave_sync { namespace prefs { @@ -36,8 +36,7 @@ const char kSyncRecordsToResendMeta[] = "brave_sync_records_to_resend_meta"; Prefs::Prefs(PrefService* pref_service) : pref_service_(pref_service) {} -void Prefs::RegisterProfilePrefs( - user_prefs::PrefRegistrySyncable* registry) { +void Prefs::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterStringPref(prefs::kSyncDeviceId, std::string()); registry->RegisterStringPref(prefs::kSyncSeed, std::string()); registry->RegisterStringPref(prefs::kSyncPrevSeed, std::string()); @@ -218,14 +217,14 @@ void Prefs::RemoveFromRecordsToResend(const std::string& object_id) { dict_update->RemoveKey(object_id); } -const base::DictionaryValue* -Prefs::GetRecordToResendMeta(const std::string& object_id) const { +const base::DictionaryValue* Prefs::GetRecordToResendMeta( + const std::string& object_id) const { const base::DictionaryValue* dict = - pref_service_->GetDictionary(kSyncRecordsToResendMeta); + pref_service_->GetDictionary(kSyncRecordsToResendMeta); const base::DictionaryValue* meta = nullptr; const base::Value* meta_value = dict->FindDictKey(object_id); if (meta_value) { - meta_value->GetAsDictionary(&meta); + meta_value->GetAsDictionary(&meta); } return meta; } diff --git a/components/brave_sync/brave_sync_prefs.h b/components/brave_sync/brave_sync_prefs.h index 387fa1ddd596..3efd75cef486 100644 --- a/components/brave_sync/brave_sync_prefs.h +++ b/components/brave_sync/brave_sync_prefs.h @@ -6,8 +6,8 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_PREFS_H_ #define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_PREFS_H_ -#include #include +#include #include #include "base/macros.h" @@ -114,8 +114,8 @@ class Prefs { void AddToRecordsToResend(const std::string& object_id, std::unique_ptr meta); void RemoveFromRecordsToResend(const std::string& object_id); - const base::DictionaryValue* - GetRecordToResendMeta(const std::string& object_id) const; + const base::DictionaryValue* GetRecordToResendMeta( + const std::string& object_id) const; void SetRecordToResendMeta(const std::string& object_id, std::unique_ptr meta); diff --git a/components/brave_sync/brave_sync_service_unittest.cc b/components/brave_sync/brave_sync_service_unittest.cc index a0e73f52198c..459f6f9cbeeb 100644 --- a/components/brave_sync/brave_sync_service_unittest.cc +++ b/components/brave_sync/brave_sync_service_unittest.cc @@ -9,12 +9,12 @@ #include "base/files/scoped_temp_dir.h" #include "base/strings/utf_string_conversions.h" -#include "brave/components/brave_sync/client/brave_sync_client_impl.h" -#include "brave/components/brave_sync/client/client_ext_impl_data.h" #include "brave/components/brave_sync/brave_profile_sync_service_impl.h" #include "brave/components/brave_sync/brave_sync_prefs.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/client/brave_sync_client_impl.h" +#include "brave/components/brave_sync/client/client_ext_impl_data.h" #include "brave/components/brave_sync/jslib_const.h" #include "brave/components/brave_sync/jslib_messages.h" #include "brave/components/brave_sync/settings.h" @@ -95,21 +95,22 @@ // OnBraveSyncPrefsChanged | + using bookmarks::BookmarkModel; -using brave_sync::BraveSyncService; using brave_sync::BraveProfileSyncServiceImpl; +using brave_sync::BraveSyncService; using brave_sync::BraveSyncServiceObserver; -using brave_sync::jslib::SyncRecord; using brave_sync::MockBraveSyncClient; using brave_sync::RecordsList; using brave_sync::SimpleBookmarkSyncRecord; using brave_sync::SimpleDeviceRecord; +using brave_sync::jslib::SyncRecord; using testing::_; using testing::AtLeast; namespace { const bookmarks::BookmarkNode* GetSingleNodeByUrl( - bookmarks::BookmarkModel* model, const std::string& url) { + bookmarks::BookmarkModel* model, + const std::string& url) { std::vector nodes; model->GetNodesByURL(GURL(url), &nodes); size_t nodes_size = nodes.size(); @@ -118,8 +119,9 @@ const bookmarks::BookmarkNode* GetSingleNodeByUrl( return node; } -bool DevicesContains(brave_sync::SyncDevices* devices, const std::string& id, - const std::string& name) { +bool DevicesContains(brave_sync::SyncDevices* devices, + const std::string& id, + const std::string& name) { DCHECK(devices); for (const auto& device : devices->devices_) { if (device.device_id_ == id && device.name_ == name) { @@ -129,13 +131,14 @@ bool DevicesContains(brave_sync::SyncDevices* devices, const std::string& id, return false; } -MATCHER_P2(ContainsDeviceRecord, action, name, - "contains device sync record with params") { +MATCHER_P2(ContainsDeviceRecord, + action, + name, + "contains device sync record with params") { for (const auto& record : arg) { if (record->has_device()) { const auto& device = record->GetDevice(); - if (record->action == action && - device.name == name) { + if (record->action == action && device.name == name) { return true; } } @@ -151,12 +154,11 @@ std::unique_ptr OverrideForMinutes( g_overridden_minutes = overridden_minutes; g_overridden_now = now; return std::make_unique( - []() { - return g_overridden_now + - base::TimeDelta::FromMinutes(g_overridden_minutes); - }, - nullptr, - nullptr); + []() { + return g_overridden_now + + base::TimeDelta::FromMinutes(g_overridden_minutes); + }, + nullptr, nullptr); } } // namespace @@ -200,8 +202,8 @@ class BraveSyncServiceTest : public testing::Test { brave_sync::BraveSyncClientImpl::set_for_testing(sync_client_); sync_service_ = static_cast( - ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( - profile())); + ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile( + profile())); EXPECT_EQ(sync_client_, sync_service_->GetBraveSyncClient()); @@ -226,9 +228,7 @@ class BraveSyncServiceTest : public testing::Test { brave_sync::prefs::Prefs* brave_sync_prefs() { return sync_service_->brave_sync_prefs_.get(); } - syncer::SyncPrefs* sync_prefs() { - return sync_prefs_.get(); - } + syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } private: // Need this as a very first member to run tests in UI thread @@ -550,9 +550,11 @@ TEST_F(BraveSyncServiceTest, OnResetSync) { EXPECT_TRUE(DevicesContains(devices.get(), "0", "this_device")); EXPECT_TRUE(DevicesContains(devices.get(), "1", "device1")); - EXPECT_CALL(*sync_client(), SendSyncRecords("PREFERENCES", - ContainsDeviceRecord(SyncRecord::Action::A_DELETE, - "this_device"))).Times(1); + EXPECT_CALL(*sync_client(), + SendSyncRecords("PREFERENCES", + ContainsDeviceRecord(SyncRecord::Action::A_DELETE, + "this_device"))) + .Times(1); sync_service()->OnResetSync(); RecordsList resolved_records; @@ -594,8 +596,8 @@ TEST_F(BraveSyncServiceTest, OnResetSync) { EXPECT_FALSE(sync_service()->IsBraveSyncConfigured()); EXPECT_FALSE(sync_prefs()->IsSyncRequested()); - EXPECT_FALSE(profile()->GetPrefs() - ->GetBoolean(syncer::prefs::kSyncBookmarks)); + EXPECT_FALSE( + profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); } TEST_F(BraveSyncServiceTest, OnSetSyncBookmarks) { @@ -603,16 +605,15 @@ TEST_F(BraveSyncServiceTest, OnSetSyncBookmarks) { brave_sync::prefs::kSyncBookmarksEnabled)); EXPECT_CALL(*observer(), OnSyncStateChanged).Times(1); sync_service()->OnSetSyncBookmarks(true); - EXPECT_TRUE(profile()->GetPrefs() - ->GetBoolean(syncer::prefs::kSyncBookmarks)); + EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncBookmarksEnabled)); EXPECT_CALL(*observer(), OnSyncStateChanged).Times(1); sync_service()->OnSetSyncBookmarks(false); EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( brave_sync::prefs::kSyncBookmarksEnabled)); - EXPECT_FALSE(profile()->GetPrefs() - ->GetBoolean(syncer::prefs::kSyncBookmarks)); + EXPECT_FALSE( + profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); EXPECT_CALL(*observer(), OnSyncStateChanged).Times(0); sync_service()->OnSetSyncBookmarks(false); } @@ -677,22 +678,20 @@ TEST_F(BraveSyncServiceTest, StartSyncNonDeviceRecords) { sync_service()->OnSetSyncEnabled(true); profile()->GetPrefs()->SetString( brave_sync::prefs::kSyncBookmarksBaseOrder, "1.1."); - profile()->GetPrefs()->SetBoolean( - brave_sync::prefs::kSyncBookmarksEnabled, true); - EXPECT_FALSE(profile()->GetPrefs()->GetBoolean( - syncer::prefs::kSyncBookmarks)); + profile()->GetPrefs()->SetBoolean(brave_sync::prefs::kSyncBookmarksEnabled, + true); + EXPECT_FALSE( + profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); brave_sync_prefs()->SetThisDeviceId("1"); RecordsList records; - records.push_back(SimpleDeviceRecord( - SyncRecord::Action::A_CREATE, - "1", "device1")); - records.push_back(SimpleDeviceRecord( - SyncRecord::Action::A_CREATE, - "2", "device2")); + records.push_back( + SimpleDeviceRecord(SyncRecord::Action::A_CREATE, "1", "device1")); + records.push_back( + SimpleDeviceRecord(SyncRecord::Action::A_CREATE, "2", "device2")); EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); sync_service()->OnResolvedPreferences(records); - EXPECT_TRUE(!brave_sync::tools::IsTimeEmpty( - sync_service()->chain_created_time_)); + EXPECT_TRUE( + !brave_sync::tools::IsTimeEmpty(sync_service()->chain_created_time_)); } TEST_F(BraveSyncServiceTest, OnSyncReadyNewToSync) { @@ -702,15 +701,14 @@ TEST_F(BraveSyncServiceTest, OnSyncReadyNewToSync) { sync_service()->OnSyncReady(); // simulate OnSaveBookmarksBaseOrder - profile()->GetPrefs()->SetString( - brave_sync::prefs::kSyncBookmarksBaseOrder, "1.1."); + profile()->GetPrefs()->SetString(brave_sync::prefs::kSyncBookmarksBaseOrder, + "1.1."); sync_service()->OnSyncReady(); EXPECT_TRUE(sync_prefs()->IsSyncRequested()); // We want to have Chromium syncer bookmarks be enabled from begin to avoid // reaching BookmarkModelAssociator::AssociateModels - EXPECT_TRUE(profile()->GetPrefs() - ->GetBoolean(syncer::prefs::kSyncBookmarks)); + EXPECT_TRUE(profile()->GetPrefs()->GetBoolean(syncer::prefs::kSyncBookmarks)); } TEST_F(BraveSyncServiceTest, OnGetExistingObjects) { @@ -741,7 +739,7 @@ TEST_F(BraveSyncServiceTest, GetDisableReasons) { syncer::SyncService::DISABLE_REASON_NONE); sync_service()->OnSetSyncEnabled(false); EXPECT_TRUE(sync_service()->HasDisableReason( - syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY)); + syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY)); } TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { @@ -809,8 +807,7 @@ TEST_F(BraveSyncServiceTest, OnSetupSyncHaveCode_Reset_SetupAgain) { } TEST_F(BraveSyncServiceTest, ExponentialResend) { - bookmarks::AddIfNotBookmarked(model(), - GURL("https://a.com/"), + bookmarks::AddIfNotBookmarked(model(), GURL("https://a.com/"), base::ASCIIToUTF16("A.com")); // Explicitly set sync_timestamp, object_id and order because it is supposed // to be set in syncer @@ -827,18 +824,16 @@ TEST_F(BraveSyncServiceTest, ExponentialResend) { brave_sync_prefs()->SetThisDeviceId("1"); std::unique_ptr records = std::make_unique(); records->push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_a_object_id, - "https://a.com/", - "A.com - title", - record_a_order, "", brave_sync_prefs()->GetThisDeviceId())); + SyncRecord::Action::A_CREATE, record_a_object_id, "https://a.com/", + "A.com - title", record_a_order, "", + brave_sync_prefs()->GetThisDeviceId())); EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times(1); sync_service()->SendSyncRecords("BOOKMARKS", std::move(records)); EXPECT_EQ(brave_sync_prefs()->GetRecordsToResend().size(), 1u); const base::DictionaryValue* meta = - brave_sync_prefs()->GetRecordToResendMeta(record_a_object_id); + brave_sync_prefs()->GetRecordToResendMeta(record_a_object_id); int send_retry_number = -1; meta->GetInteger("send_retry_number", &send_retry_number); EXPECT_EQ(send_retry_number, 0); @@ -860,11 +855,11 @@ TEST_F(BraveSyncServiceTest, ExponentialResend) { }; for (size_t i = 0; i <= exponential_waits.back(); ++i) { auto time_override = - OverrideForMinutes(i, base::Time::FromJsTime(sync_timestamp)); + OverrideForMinutes(i, base::Time::FromJsTime(sync_timestamp)); bool is_send_expected = contains(should_sent_at, i); int expect_call_times = is_send_expected ? 1 : 0; - EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)).Times( - expect_call_times); + EXPECT_CALL(*sync_client(), SendSyncRecords("BOOKMARKS", _)) + .Times(expect_call_times); sync_service()->ResendSyncRecords("BOOKMARKS"); if (is_send_expected) { @@ -880,11 +875,8 @@ TEST_F(BraveSyncServiceTest, ExponentialResend) { // resolve to confirm records RecordsList records_to_resolve; records_to_resolve.push_back(SimpleBookmarkSyncRecord( - SyncRecord::Action::A_CREATE, - record_a_object_id, - "https://a.com/", - "A.com", - "1.1.1.1", "", brave_sync_prefs()->GetThisDeviceId())); + SyncRecord::Action::A_CREATE, record_a_object_id, "https://a.com/", + "A.com", "1.1.1.1", "", brave_sync_prefs()->GetThisDeviceId())); auto timestamp_resolve = base::Time::Now(); records_to_resolve.at(0)->syncTimestamp = timestamp_resolve; brave_sync::SyncRecordAndExistingList records_and_existing_objects; @@ -893,5 +885,5 @@ TEST_F(BraveSyncServiceTest, ExponentialResend) { EXPECT_EQ(brave_sync_prefs()->GetRecordsToResend().size(), 0u); EXPECT_EQ(brave_sync_prefs()->GetRecordToResendMeta(record_a_object_id), - nullptr); + nullptr); } diff --git a/components/brave_sync/client/brave_sync_client_impl.h b/components/brave_sync/client/brave_sync_client_impl.h index ea6c376046d5..6ea122757428 100644 --- a/components/brave_sync/client/brave_sync_client_impl.h +++ b/components/brave_sync/client/brave_sync_client_impl.h @@ -96,6 +96,6 @@ class BraveSyncClientImpl : public BraveSyncClient, DISALLOW_COPY_AND_ASSIGN(BraveSyncClientImpl); }; -} // namespace brave_sync +} // namespace brave_sync -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BRAVE_SYNC_CLIENT_IMPL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_BRAVE_SYNC_CLIENT_IMPL_H_ diff --git a/components/brave_sync/client/client_ext_impl_data.cc b/components/brave_sync/client/client_ext_impl_data.cc index 74fe25698345..f55986a77e38 100644 --- a/components/brave_sync/client/client_ext_impl_data.cc +++ b/components/brave_sync/client/client_ext_impl_data.cc @@ -15,8 +15,8 @@ namespace brave_sync { -void ConvertConfig(const brave_sync::client_data::Config &config, - extensions::api::brave_sync::Config* config_extension) { +void ConvertConfig(const brave_sync::client_data::Config& config, + extensions::api::brave_sync::Config* config_extension) { DCHECK(config_extension); config_extension->api_version = config.api_version; config_extension->server_url = config.server_url; @@ -70,7 +70,7 @@ std::unique_ptr FromExtSiteSetting( } std::unique_ptr> FromExtMetaInfo( - const std::vector& ext_meta_info) { + const std::vector& ext_meta_info) { auto meta_info = std::make_unique>(); for (auto& ext_meta : ext_meta_info) { @@ -117,8 +117,8 @@ std::unique_ptr FromLibSite( ext_site->location = lib_site.location; ext_site->title = lib_site.title; ext_site->custom_title = lib_site.customTitle; - ext_site->last_accessed_time = 0; // lib_site.lastAccessedTime.ToJsTime(); - ext_site->creation_time = 0; // lib_site.creationTime.ToJsTime(); + ext_site->last_accessed_time = 0; // lib_site.lastAccessedTime.ToJsTime(); + ext_site->creation_time = 0; // lib_site.creationTime.ToJsTime(); ext_site->favicon = lib_site.favicon; return ext_site; @@ -127,7 +127,7 @@ std::unique_ptr FromLibSite( std::unique_ptr> FromLibMetaInfo(const std::vector& lib_metaInfo) { auto ext_meta_info = - std::make_unique>(); + std::make_unique>(); for (auto& metaInfo : lib_metaInfo) { auto meta_info = std::make_unique(); @@ -208,10 +208,9 @@ std::unique_ptr FromLibDevice( } std::unique_ptr FromLibSyncRecord( - const brave_sync::SyncRecordPtr &lib_record) { + const brave_sync::SyncRecordPtr& lib_record) { DCHECK(lib_record); - std::unique_ptr ext_record = - std::make_unique(); + std::unique_ptr ext_record = std::make_unique(); ext_record->action = static_cast(lib_record->action); ext_record->device_id = UCharVecFromString(lib_record->deviceId); @@ -238,16 +237,14 @@ std::unique_ptr FromLibSyncRecord( return ext_record; } -brave_sync::SyncRecordPtr FromExtSyncRecord( - const SyncRecord &ext_record) { +brave_sync::SyncRecordPtr FromExtSyncRecord(const SyncRecord& ext_record) { brave_sync::SyncRecordPtr record = - std::make_unique(); + std::make_unique(); record->action = ConvertEnum( - ext_record.action, - brave_sync::jslib::SyncRecord::Action::A_MIN, - brave_sync::jslib::SyncRecord::Action::A_MAX, - brave_sync::jslib::SyncRecord::Action::A_INVALID); + ext_record.action, brave_sync::jslib::SyncRecord::Action::A_MIN, + brave_sync::jslib::SyncRecord::Action::A_MAX, + brave_sync::jslib::SyncRecord::Action::A_INVALID); record->deviceId = StrFromUnsignedCharArray(ext_record.device_id); record->objectId = StrFromUnsignedCharArray(ext_record.object_id); @@ -293,11 +290,11 @@ brave_sync::SyncRecordPtr FromExtSyncRecord( void ConvertSyncRecords( const std::vector& ext_records, - std::vector* records) { + std::vector* records) { DCHECK(records); DCHECK(records->empty()); - for (const auto &ext_record : ext_records) { + for (const auto& ext_record : ext_records) { brave_sync::SyncRecordPtr record = FromExtSyncRecord(ext_record); records->emplace_back(std::move(record)); } @@ -331,10 +328,9 @@ void ConvertSyncRecordsFromLibToExt( DCHECK(records_extension->empty()); for (const brave_sync::SyncRecordPtr &src : records) { - std::unique_ptr dest = - FromLibSyncRecord(src); + std::unique_ptr dest = FromLibSyncRecord(src); records_extension->emplace_back(std::move(*dest)); } } -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/client/client_ext_impl_data.h b/components/brave_sync/client/client_ext_impl_data.h index f8a02aeabea7..2e5beaeef119 100644 --- a/components/brave_sync/client/client_ext_impl_data.h +++ b/components/brave_sync/client/client_ext_impl_data.h @@ -29,23 +29,23 @@ class Config; namespace brave_sync { -using extensions::api::brave_sync::SyncRecord; using extensions::api::brave_sync::RecordAndExistingObject; +using extensions::api::brave_sync::SyncRecord; -void ConvertConfig(const brave_sync::client_data::Config &config, +void ConvertConfig(const brave_sync::client_data::Config& config, extensions::api::brave_sync::Config* config_extension); -void ConvertSyncRecords(const std::vector &records_extension, +void ConvertSyncRecords(const std::vector& records_extension, std::vector* records); void ConvertResolvedPairs( - const SyncRecordAndExistingList &records_and_existing_objects, + const SyncRecordAndExistingList& records_and_existing_objects, std::vector* records_and_existing_objects_ext); void ConvertSyncRecordsFromLibToExt( - const std::vector &records, + const std::vector& records, std::vector* records_extension); -} // namespace brave_sync +} // namespace brave_sync -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_CLIENT_EXT_IMPL_DATA_H_ +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_CLIENT_CLIENT_EXT_IMPL_DATA_H_ diff --git a/components/brave_sync/jslib_messages.cc b/components/brave_sync/jslib_messages.cc index 4e40165d0804..8f8af5771c10 100644 --- a/components/brave_sync/jslib_messages.cc +++ b/components/brave_sync/jslib_messages.cc @@ -90,7 +90,7 @@ std::unique_ptr SiteSetting::Clone( ret_val->ledgerPayments = site_setting.ledgerPayments; ret_val->ledgerPaymentsShown = site_setting.ledgerPaymentsShown; ret_val->fields = site_setting.fields; - return ret_val; + return ret_val; } Device::Device() = default; @@ -100,7 +100,7 @@ Device::~Device() = default; std::unique_ptr Device::Clone(const Device& device) { auto ret_val = std::make_unique(); ret_val->name = device.name; - return ret_val; + return ret_val; } SyncRecord::SyncRecord() : action(SyncRecord::Action::A_INVALID) {} @@ -126,7 +126,7 @@ std::unique_ptr SyncRecord::Clone(const SyncRecord& record) { ret_val->syncTimestamp = record.syncTimestamp; - return ret_val; + return ret_val; } bool SyncRecord::has_bookmark() const { @@ -194,6 +194,6 @@ void SyncRecord::SetDevice(std::unique_ptr device) { device_ = std::move(device); } -} // namespace jslib +} // namespace jslib -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/jslib_messages.h b/components/brave_sync/jslib_messages.h index f2092979f8f3..4e96013d3003 100644 --- a/components/brave_sync/jslib_messages.h +++ b/components/brave_sync/jslib_messages.h @@ -64,7 +64,7 @@ class Bookmark { Site site; bool isFolder; - std::string parentFolderObjectId; // bytes + std::string parentFolderObjectId; // bytes std::vector fields; bool hideInToolbar; std::string order; @@ -133,8 +133,8 @@ class SyncRecord { }; Action action; - std::string deviceId; // bytes - std::string objectId; // bytes + std::string deviceId; // bytes + std::string objectId; // bytes std::string objectData; @@ -162,8 +162,8 @@ class SyncRecord { std::unique_ptr device_; }; -} // namespace jslib +} // namespace jslib -} // namespace brave_sync +} // namespace brave_sync -#endif // BRAVE_COMPONENTS_BRAVE_SYNC_JSLIB_MESSAGES_H_ +#endif // BRAVE_COMPONENTS_BRAVE_SYNC_JSLIB_MESSAGES_H_ diff --git a/components/brave_sync/jslib_messages_fwd.h b/components/brave_sync/jslib_messages_fwd.h index 6bd18820f48c..4c5ad71aac62 100644 --- a/components/brave_sync/jslib_messages_fwd.h +++ b/components/brave_sync/jslib_messages_fwd.h @@ -27,7 +27,7 @@ class SyncRecord; namespace syncer { class Syncer; -} // namespace syncer +} // namespace syncer namespace brave_sync { @@ -40,11 +40,10 @@ typedef std::vector SyncRecordAndExistingList; using Uint8Array = std::vector; using GetRecordsCallback = - base::RepeatingCallback)>; -using NudgeSyncCycleDelegate = - base::Callback; + base::RepeatingCallback)>; +using NudgeSyncCycleDelegate = base::Callback; using PollSyncCycleDelegate = - base::Callback; + base::Callback; } // namespace brave_sync diff --git a/components/brave_sync/public/brave_profile_sync_service.h b/components/brave_sync/public/brave_profile_sync_service.h index 71fc942ac1a3..983b424b1ff8 100644 --- a/components/brave_sync/public/brave_profile_sync_service.h +++ b/components/brave_sync/public/brave_profile_sync_service.h @@ -21,8 +21,8 @@ class BraveSyncService; class BraveProfileSyncService : public syncer::ProfileSyncService { public: - explicit BraveProfileSyncService(InitParams init_params) : - syncer::ProfileSyncService(std::move(init_params)) {} + explicit BraveProfileSyncService(InitParams init_params) + : syncer::ProfileSyncService(std::move(init_params)) {} ~BraveProfileSyncService() override {} virtual bool IsBraveSyncEnabled() const = 0; diff --git a/components/brave_sync/syncer_helper.cc b/components/brave_sync/syncer_helper.cc index 6f324bcd759b..fd3450c12b7c 100644 --- a/components/brave_sync/syncer_helper.cc +++ b/components/brave_sync/syncer_helper.cc @@ -19,15 +19,13 @@ void SetOrder(bookmarks::BookmarkModel* model, DCHECK(!parent_order.empty()); int index = node->parent()->GetIndexOf(node); - bookmarks::BookmarkNode* parent = const_cast( - node->parent()); + bookmarks::BookmarkNode* parent = + const_cast(node->parent()); - auto* prev_node = index == 0 ? - nullptr : - parent->GetChild(index - 1); - auto* next_node = index == parent->child_count() - 1 ? - nullptr : - parent->GetChild(index + 1); + auto* prev_node = index == 0 ? nullptr : parent->GetChild(index - 1); + auto* next_node = index == parent->child_count() - 1 + ? nullptr + : parent->GetChild(index + 1); std::string prev_order; std::string next_order; @@ -37,8 +35,8 @@ void SetOrder(bookmarks::BookmarkModel* model, if (next_node) next_node->GetMetaInfo("order", &next_order); - std::string order = brave_sync::GetOrder(prev_order, - next_order, parent_order); + std::string order = + brave_sync::GetOrder(prev_order, next_order, parent_order); model->SetNodeMetaInfo(node, "order", order); } @@ -54,12 +52,11 @@ uint64_t GetIndexByOrder(const std::string& record_order) { return index; } -} // namespace +} // namespace -uint64_t GetIndexByCompareOrderStartFrom( - const bookmarks::BookmarkNode* parent, - const bookmarks::BookmarkNode* src, - int index) { +uint64_t GetIndexByCompareOrderStartFrom(const bookmarks::BookmarkNode* parent, + const bookmarks::BookmarkNode* src, + int index) { std::string src_order; src->GetMetaInfo("order", &src_order); DCHECK(!src_order.empty()); @@ -104,10 +101,8 @@ uint64_t GetIndexByCompareOrderStartFrom( return index; } -void AddBraveMetaInfo( - const bookmarks::BookmarkNode* node, - bookmarks::BookmarkModel* model) { - +void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, + bookmarks::BookmarkModel* model) { std::string parent_order; node->parent()->GetMetaInfo("order", &parent_order); SetOrder(model, node, parent_order); @@ -156,4 +151,4 @@ uint64_t GetIndex(const bookmarks::BookmarkNode* parent, return index; } -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/syncer_helper.h b/components/brave_sync/syncer_helper.h index 0874b9f28b32..24a288dff0b2 100644 --- a/components/brave_sync/syncer_helper.h +++ b/components/brave_sync/syncer_helper.h @@ -6,13 +6,13 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ #define BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ -#include #include +#include namespace bookmarks { class BookmarkModel; class BookmarkNode; -} // namespace bookmarks +} // namespace bookmarks namespace brave_sync { @@ -23,11 +23,10 @@ void AddBraveMetaInfo(const bookmarks::BookmarkNode* node, uint64_t GetIndex(const bookmarks::BookmarkNode* parent, const bookmarks::BookmarkNode* src); -uint64_t GetIndexByCompareOrderStartFrom( - const bookmarks::BookmarkNode* parent, - const bookmarks::BookmarkNode* src, - int index); +uint64_t GetIndexByCompareOrderStartFrom(const bookmarks::BookmarkNode* parent, + const bookmarks::BookmarkNode* src, + int index); -} // namespace brave_sync +} // namespace brave_sync #endif // BRAVE_COMPONENTS_BRAVE_SYNC_SYNCER_HELPER_H_ diff --git a/components/brave_sync/syncer_helper_unittest.cc b/components/brave_sync/syncer_helper_unittest.cc index c9fbf1912c9a..edeb4d2e1d13 100644 --- a/components/brave_sync/syncer_helper_unittest.cc +++ b/components/brave_sync/syncer_helper_unittest.cc @@ -3,9 +3,9 @@ * 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 #include +#include #include #include "base/files/scoped_temp_dir.h" @@ -36,15 +36,14 @@ namespace brave_sync { namespace { // |node| is near the end in parent -void RepositionRespectOrder( - bookmarks::BookmarkModel* bookmark_model, - const bookmarks::BookmarkNode* node) { +void RepositionRespectOrder(bookmarks::BookmarkModel* bookmark_model, + const bookmarks::BookmarkNode* node) { const bookmarks::BookmarkNode* parent = node->parent(); int index = GetIndexByCompareOrderStartFrom(parent, node, 0); bookmark_model->Move(node, parent, index); } -} // namespace +} // namespace class SyncerHelperTest : public testing::Test { public: @@ -59,8 +58,7 @@ class SyncerHelperTest : public testing::Test { EXPECT_TRUE(profile_.get() != NULL); BookmarkModelFactory::GetInstance()->SetTestingFactory( - profile_.get(), - base::BindRepeating(&BuildFakeBookmarkModelForTests)); + profile_.get(), base::BindRepeating(&BuildFakeBookmarkModelForTests)); model_ = BookmarkModelFactory::GetForBrowserContext( Profile::FromBrowserContext(profile_.get())); @@ -74,9 +72,7 @@ class SyncerHelperTest : public testing::Test { model_->SetNodeMetaInfo(model_->other_node(), "order", "1.0.2"); } - void TearDown() override { - profile_.reset(); - } + void TearDown() override { profile_.reset(); } BookmarkClient* bookmark_client() { return model_->client(); } BookmarkModel* model() { return model_; } @@ -109,9 +105,8 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoCreateOrUpdate) { folder1->GetMetaInfo("sync_timestamp", &sync_timestamp); EXPECT_TRUE(!sync_timestamp.empty()); - const auto *node_a = model()->AddURL(folder1, 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); + const auto* node_a = model()->AddURL( + folder1, 0, base::ASCIIToUTF16("A.com - title"), GURL("https://a.com/")); order.clear(); sync_timestamp.clear(); AddBraveMetaInfo(node_a, model()); @@ -147,9 +142,8 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeMoved) { const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 0, base::ASCIIToUTF16("Folder1")); AddBraveMetaInfo(folder1, model()); - const auto *node_a = model()->AddURL(folder1, 0, - base::ASCIIToUTF16("A.com - title"), - GURL("https://a.com/")); + const auto* node_a = model()->AddURL( + folder1, 0, base::ASCIIToUTF16("A.com - title"), GURL("https://a.com/")); AddBraveMetaInfo(node_a, model()); model()->Move(node_a, model()->bookmark_bar_node(), 1); AddBraveMetaInfo(node_a, model()); @@ -169,15 +163,15 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeMoved) { } TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeChildrenReordered) { - const auto *node_a = model()->AddURL(model()->bookmark_bar_node(), 0, + const auto* node_a = model()->AddURL(model()->bookmark_bar_node(), 0, base::ASCIIToUTF16("A.com - title"), GURL("https://a.com/")); AddBraveMetaInfo(node_a, model()); - const auto *node_b = model()->AddURL(model()->bookmark_bar_node(), 1, + const auto* node_b = model()->AddURL(model()->bookmark_bar_node(), 1, base::ASCIIToUTF16("B.com - title"), GURL("https://b.com/")); AddBraveMetaInfo(node_b, model()); - const auto *node_c = model()->AddURL(model()->bookmark_bar_node(), 2, + const auto* node_c = model()->AddURL(model()->bookmark_bar_node(), 2, base::ASCIIToUTF16("C.com - title"), GURL("https://c.com/")); AddBraveMetaInfo(node_c, model()); @@ -220,20 +214,18 @@ TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeChildrenReordered) { } TEST_F(SyncerHelperTest, AddBraveMetaInfoNodeMovedReordered) { - const auto *node_a = model()->AddURL(model()->bookmark_bar_node(), 0, + const auto* node_a = model()->AddURL(model()->bookmark_bar_node(), 0, base::ASCIIToUTF16("A.com - title"), GURL("https://a.com/")); AddBraveMetaInfo(node_a, model()); const auto* folder1 = model()->AddFolder(model()->bookmark_bar_node(), 1, base::ASCIIToUTF16("Folder1")); AddBraveMetaInfo(folder1, model()); - const auto *node_b = model()->AddURL(folder1, 0, - base::ASCIIToUTF16("B.com - title"), - GURL("https://b.com/")); + const auto* node_b = model()->AddURL( + folder1, 0, base::ASCIIToUTF16("B.com - title"), GURL("https://b.com/")); AddBraveMetaInfo(node_b, model()); - const auto *node_c = model()->AddURL(folder1, 1, - base::ASCIIToUTF16("C.com - title"), - GURL("https://c.com/")); + const auto* node_c = model()->AddURL( + folder1, 1, base::ASCIIToUTF16("C.com - title"), GURL("https://c.com/")); AddBraveMetaInfo(node_c, model()); // Expecting here to have: @@ -289,9 +281,9 @@ TEST_F(SyncerHelperTest, GetIndexInPermanentNodes) { node.SetMetaInfo("order", "1.0.2.1"); EXPECT_EQ(GetIndex(model()->other_node(), &node), 0u); - const auto* node_a = model()->AddURL(model()->bookmark_bar_node(), 0, - base::ASCIIToUTF16("a.com"), - GURL("https://a.com/")); + const auto* node_a = + model()->AddURL(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("a.com"), GURL("https://a.com/")); // compare device id model()->SetNodeMetaInfo(node_a, "order", "1.1.1.1"); node.SetMetaInfo("order", "1.0.1.1"); @@ -311,9 +303,9 @@ TEST_F(SyncerHelperTest, GetIndexInPermanentNodes) { TEST_F(SyncerHelperTest, GetIndexMoreChildren) { for (int i = 0; i < 10; ++i) { - const auto* node_a = model()->AddURL(model()->bookmark_bar_node(), i, - base::ASCIIToUTF16("a.com"), - GURL("https://a.com/")); + const auto* node_a = + model()->AddURL(model()->bookmark_bar_node(), i, + base::ASCIIToUTF16("a.com"), GURL("https://a.com/")); std::string order = "1.1.1." + base::NumberToString(i); model()->SetNodeMetaInfo(node_a, "order", order); } @@ -334,8 +326,7 @@ TEST_F(SyncerHelperTest, GetIndexInFolder) { EXPECT_EQ(GetIndex(folder1, &node), 0u); // appended at the end - const auto* node_a = model()->AddURL(folder1, 0, - base::ASCIIToUTF16("a.com"), + const auto* node_a = model()->AddURL(folder1, 0, base::ASCIIToUTF16("a.com"), GURL("https://a.com/")); model()->SetNodeMetaInfo(node_a, "order", "1.0.1.1.1"); node.SetMetaInfo("order", "1.0.1.1.2"); @@ -353,47 +344,43 @@ TEST_F(SyncerHelperTest, SameOrderBookmarksSordetByObjectIdFull3) { // 6. repeat pt 5 on device B, for B3.com // 7. press Save button on devices A and B // Expected bookmarks on devices A and B are sorted in the same way - const auto* node_a1 = model()->AddURL(model()->bookmark_bar_node(), 0, - base::ASCIIToUTF16("A1.com"), - GURL("https://a1.com/")); + const auto* node_a1 = + model()->AddURL(model()->bookmark_bar_node(), 0, + base::ASCIIToUTF16("A1.com"), GURL("https://a1.com/")); AddBraveMetaInfo(node_a1, model()); - const auto* node_a2 = model()->AddURL(model()->bookmark_bar_node(), 1, - base::ASCIIToUTF16("A2.com"), - GURL("https://a2.com/")); + const auto* node_a2 = + model()->AddURL(model()->bookmark_bar_node(), 1, + base::ASCIIToUTF16("A2.com"), GURL("https://a2.com/")); AddBraveMetaInfo(node_a2, model()); - const auto* node_b1 = model()->AddURL(model()->bookmark_bar_node(), 2, - base::ASCIIToUTF16("B1.com"), - GURL("https://b1.com/")); + const auto* node_b1 = + model()->AddURL(model()->bookmark_bar_node(), 2, + base::ASCIIToUTF16("B1.com"), GURL("https://b1.com/")); AddBraveMetaInfo(node_b1, model()); - const auto* node_b2 = model()->AddURL(model()->bookmark_bar_node(), 3, - base::ASCIIToUTF16("B2.com"), - GURL("https://b2.com/")); + const auto* node_b2 = + model()->AddURL(model()->bookmark_bar_node(), 3, + base::ASCIIToUTF16("B2.com"), GURL("https://b2.com/")); AddBraveMetaInfo(node_b2, model()); // Expect b1 and b2 no need to move - uint64_t index_to_move_b1 = GetIndexByCompareOrderStartFrom( - model()->bookmark_bar_node(), - node_b1, - 0); + uint64_t index_to_move_b1 = + GetIndexByCompareOrderStartFrom(model()->bookmark_bar_node(), node_b1, 0); EXPECT_EQ(index_to_move_b1, 2u); - uint64_t index_to_move_b2 = GetIndexByCompareOrderStartFrom( - model()->bookmark_bar_node(), - node_b2, - 0); + uint64_t index_to_move_b2 = + GetIndexByCompareOrderStartFrom(model()->bookmark_bar_node(), node_b2, 0); EXPECT_EQ(index_to_move_b2, 3u); - const auto* node_a3 = model()->AddURL(model()->bookmark_bar_node(), 4, - base::ASCIIToUTF16("A3.com"), - GURL("https://a3.com/")); + const auto* node_a3 = + model()->AddURL(model()->bookmark_bar_node(), 4, + base::ASCIIToUTF16("A3.com"), GURL("https://a3.com/")); AddBraveMetaInfo(node_a3, model()); - const auto* node_b3 = model()->AddURL(model()->bookmark_bar_node(), 5, - base::ASCIIToUTF16("B3.com"), - GURL("https://b3.com/")); + const auto* node_b3 = + model()->AddURL(model()->bookmark_bar_node(), 5, + base::ASCIIToUTF16("B3.com"), GURL("https://b3.com/")); AddBraveMetaInfo(node_b3, model()); - const auto* node_c3 = model()->AddURL(model()->bookmark_bar_node(), 6, - base::ASCIIToUTF16("C3.com"), - GURL("https://c3.com/")); + const auto* node_c3 = + model()->AddURL(model()->bookmark_bar_node(), 6, + base::ASCIIToUTF16("C3.com"), GURL("https://c3.com/")); AddBraveMetaInfo(node_c3, model()); std::string a3_order; @@ -450,4 +437,4 @@ TEST_F(SyncerHelperTest, SameOrderBookmarksSordetByObjectIdFull3) { EXPECT_EQ(title_at_6, base::ASCIIToUTF16("B3.com")); } -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/test_util.cc b/components/brave_sync/test_util.cc index 3cd73acf6b13..8d64a654654a 100644 --- a/components/brave_sync/test_util.cc +++ b/components/brave_sync/test_util.cc @@ -52,14 +52,13 @@ std::unique_ptr BuildFakeBookmarkModelForTests( return model; } -SyncRecordPtr SimpleBookmarkSyncRecord( - const int action, - const std::string& object_id, - const std::string& location, - const std::string& title, - const std::string& order, - const std::string& parent_object_id, - const std::string& device_id) { +SyncRecordPtr SimpleBookmarkSyncRecord(const int action, + const std::string& object_id, + const std::string& location, + const std::string& title, + const std::string& order, + const std::string& parent_object_id, + const std::string& device_id) { auto record = std::make_unique(); record->action = ConvertEnum(action, brave_sync::jslib::SyncRecord::Action::A_MIN, @@ -143,4 +142,4 @@ SyncRecordPtr SimpleDeviceRecord( return record; } -} // namespace brave_sync +} // namespace brave_sync diff --git a/components/brave_sync/test_util.h b/components/brave_sync/test_util.h index 4e55dd2c30d0..fa60e3bfa5bf 100644 --- a/components/brave_sync/test_util.h +++ b/components/brave_sync/test_util.h @@ -44,8 +44,9 @@ class MockBraveSyncClient : public BraveSyncClient { MOCK_METHOD0(SendFetchSyncDevices, void()); MOCK_METHOD2(SendResolveSyncRecords, void(const std::string& category_name, std::unique_ptr list)); - MOCK_METHOD2(SendSyncRecords, void(const std::string& category_name, - const RecordsList& records)); + MOCK_METHOD2(SendSyncRecords, + void(const std::string& category_name, + const RecordsList& records)); MOCK_METHOD0(SendDeleteSyncUser, void()); MOCK_METHOD1(SendDeleteSyncCategory, void(const std::string& category_name)); MOCK_METHOD2(SendGetBookmarksBaseOrder, void(const std::string& device_id, @@ -62,14 +63,13 @@ std::unique_ptr CreateBraveSyncProfile(const base::FilePath& path); std::unique_ptr BuildFakeBookmarkModelForTests( content::BrowserContext* context); -SyncRecordPtr SimpleBookmarkSyncRecord( - const int action, - const std::string& object_id, - const std::string& location, - const std::string& title, - const std::string& order, - const std::string& parent_object_id, - const std::string& device_id = "3"); +SyncRecordPtr SimpleBookmarkSyncRecord(const int action, + const std::string& object_id, + const std::string& location, + const std::string& title, + const std::string& order, + const std::string& parent_object_id, + const std::string& device_id = "3"); SyncRecordPtr SimpleFolderSyncRecord( const int action, diff --git a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch index daa880d68cff..a86ef8eedd44 100644 --- a/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch +++ b/patches/components-sync-engine_impl-sync_scheduler_impl.h.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/engine_impl/sync_scheduler_impl.h b/components/sync/engine_impl/sync_scheduler_impl.h -index 4bab39098da187109f291f1c0ab03fd0cc34d326..c29568b405112bab3b74be98a8855d4b5817943c 100644 +index 4bab39098da187109f291f1c0ab03fd0cc34d326..8cca9aedd53f4a6f636adb168bad115ff68ec5af 100644 --- a/components/sync/engine_impl/sync_scheduler_impl.h +++ b/components/sync/engine_impl/sync_scheduler_impl.h -@@ -281,6 +281,7 @@ class SyncSchedulerImpl : public SyncScheduler { - // Used to prevent changing nudge delays by the server in integration tests. - bool force_short_nudge_delay_for_test_ = false; +@@ -87,6 +87,7 @@ class SyncSchedulerImpl : public SyncScheduler { + // tests. + void ForceShortNudgeDelayForTest(); -+ BRAVE_SYNC_SCHEDULER_IMPL_H - SEQUENCE_CHECKER(sequence_checker_); - - base::WeakPtrFactory weak_ptr_factory_; ++ BRAVE_SYNC_SCHEDULER_IMPL_H_ + private: + enum JobPriority { + // Non-canary jobs respect exponential backoff. diff --git a/patches/components-sync-syncable-write_transaction.cc.patch b/patches/components-sync-syncable-write_transaction.cc.patch index 49110a8dbae8..4b25c62fbfe2 100644 --- a/patches/components-sync-syncable-write_transaction.cc.patch +++ b/patches/components-sync-syncable-write_transaction.cc.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/syncable/write_transaction.cc b/components/sync/syncable/write_transaction.cc -index 00b248a93830bbafae831d46d1089a0844c57805..2b9a153e9f55b51d22e5568b469add733921b92a 100644 +index 00b248a93830bbafae831d46d1089a0844c57805..f2dfcd72d90ec73d84180fd91a8db6c0270fb033 100644 --- a/components/sync/syncable/write_transaction.cc +++ b/components/sync/syncable/write_transaction.cc @@ -28,6 +28,7 @@ WriteTransaction::WriteTransaction(const base::Location& from_here, } WriteTransaction::~WriteTransaction() { -+ if (!keep_) ++ BRAVE_WRITE_TRANSACTION delete transaction_; } diff --git a/patches/components-sync-syncable-write_transaction.h.patch b/patches/components-sync-syncable-write_transaction.h.patch index d06335aefb7c..fd11ad582ffc 100644 --- a/patches/components-sync-syncable-write_transaction.h.patch +++ b/patches/components-sync-syncable-write_transaction.h.patch @@ -1,12 +1,12 @@ diff --git a/components/sync/syncable/write_transaction.h b/components/sync/syncable/write_transaction.h -index 3d0a353ac09b1dcbfab0d5afc3345d78eb4ee8bd..eafebbf205de8691700162151ced152a4d5ba679 100644 +index 3d0a353ac09b1dcbfab0d5afc3345d78eb4ee8bd..b53e56bc0c43a43da32bd736eb86368e3bebec87 100644 --- a/components/sync/syncable/write_transaction.h +++ b/components/sync/syncable/write_transaction.h -@@ -63,6 +63,7 @@ class WriteTransaction : public BaseTransaction { - transaction_ = trans; - } +@@ -56,6 +56,7 @@ class WriteTransaction : public BaseTransaction { + SyncChangeProcessor::ContextRefreshStatus refresh_status, + const std::string& context); -+ BRAVE_SYNC_ATTACHABLE_WRITE_TRANSACTION_H - private: - void* operator new(size_t size); // Transaction is meant for stack use only. ++ BRAVE_WRITE_TRANSACTION_H_ + protected: + WriteTransaction() {} diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch index 92d3996e0323..26849c4a51df 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.cc.patch @@ -1,25 +1,24 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.cc b/components/sync_bookmarks/bookmark_change_processor.cc -index 35a73a07bbcdd8aeba13acf37c6754aadb039768..ac7ebcbda6bc1de634b81be44ce98c2c3656b3ac 100644 +index 35a73a07bbcdd8aeba13acf37c6754aadb039768..67cb25e20a9c2eb1f70661de4e03c956b7a6a6bc 100644 --- a/components/sync_bookmarks/bookmark_change_processor.cc +++ b/components/sync_bookmarks/bookmark_change_processor.cc @@ -87,6 +87,7 @@ void BookmarkChangeProcessor::UpdateSyncNodeProperties( bookmark_specifics.set_creation_time_us(src->date_added().ToInternalValue()); dst->SetBookmarkSpecifics(bookmark_specifics); SetSyncNodeFavicon(src, model, dst); -+ brave_sync::AddBraveMetaInfo(src, model); ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_UPDATE_SYNC_NODE_PROPERTIES SetSyncNodeMetaInfo(src, dst); } -@@ -383,7 +384,7 @@ int64_t BookmarkChangeProcessor::UpdateSyncNode( +@@ -383,7 +384,6 @@ int64_t BookmarkChangeProcessor::UpdateSyncNode( void BookmarkChangeProcessor::BookmarkMetaInfoChanged( BookmarkModel* model, const BookmarkNode* node) { - BookmarkNodeChanged(model, node); -+ // TODO(darkdh): make sure the meta info changed is what we want to sync } void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, -@@ -415,6 +416,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, +@@ -415,6 +415,7 @@ void BookmarkChangeProcessor::BookmarkNodeMoved(BookmarkModel* model, error_handler()->OnUnrecoverableError(error); return; } @@ -27,7 +26,7 @@ index 35a73a07bbcdd8aeba13acf37c6754aadb039768..ac7ebcbda6bc1de634b81be44ce98c2c if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, model_associator_)) { -@@ -458,6 +460,7 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( +@@ -458,6 +459,7 @@ void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( return; } @@ -35,7 +34,7 @@ index 35a73a07bbcdd8aeba13acf37c6754aadb039768..ac7ebcbda6bc1de634b81be44ce98c2c CreateOrUpdateSyncNode(node); } -@@ -490,6 +493,7 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( +@@ -490,6 +492,7 @@ void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( DCHECK_EQ(sync_child.GetParentId(), model_associator_->GetSyncIdFromChromeId(node->id())); @@ -43,15 +42,15 @@ index 35a73a07bbcdd8aeba13acf37c6754aadb039768..ac7ebcbda6bc1de634b81be44ce98c2c if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, model_associator_)) { syncer::SyncError error(FROM_HERE, -@@ -718,9 +722,11 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( +@@ -718,9 +721,11 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( << src.GetBookmarkSpecifics().url(); continue; } -+ bookmark_model_->SetNodeMetaInfo(dst, "FirstLoadedFavicon", "true"); ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL_1 model_associator_->Associate(dst, src); } -+ BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_APPLY_CHANGES_FROM_SYNC_MODEL_2 to_reposition.insert(std::make_pair(src.GetPositionIndex(), dst)); bookmark_model_->SetNodeSyncTransactionVersion(dst, model_version); } diff --git a/patches/components-sync_bookmarks-bookmark_change_processor.h.patch b/patches/components-sync_bookmarks-bookmark_change_processor.h.patch index 7bd14e8f5000..b28c03036cc2 100644 --- a/patches/components-sync_bookmarks-bookmark_change_processor.h.patch +++ b/patches/components-sync_bookmarks-bookmark_change_processor.h.patch @@ -1,12 +1,12 @@ diff --git a/components/sync_bookmarks/bookmark_change_processor.h b/components/sync_bookmarks/bookmark_change_processor.h -index e11a2ddf641edc7098c06433fd22d86467e2aabf..86629fa7182a9cf893ff9442ec5667924c59f335 100644 +index e11a2ddf641edc7098c06433fd22d86467e2aabf..d29059927ef563fb6e0a365da740d50ba8360bfd 100644 --- a/components/sync_bookmarks/bookmark_change_processor.h +++ b/components/sync_bookmarks/bookmark_change_processor.h -@@ -238,6 +238,7 @@ class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, - // Returns false if |node| should not be synced. - bool CanSyncNode(const bookmarks::BookmarkNode* node); +@@ -172,6 +172,7 @@ class BookmarkChangeProcessor : public bookmarks::BookmarkModelObserver, + bookmarks::BookmarkModel* model, + const std::vector& nodes); -+ BRAVE_SYNC_REPOSITION_METHODS - SEQUENCE_CHECKER(sequence_checker_); ++ BRAVE_BOOKMARK_CHANGE_PROCESSOR_H_ + protected: + void StartImpl() override; - // The bookmark model we are processing changes from. Non-null when From 220d6042e1ffe25f5f02d8e8aef3211b1a952ed6 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 16 Aug 2019 11:54:51 -0700 Subject: [PATCH 70/73] Review Feedback (2) 1. Remvoe weak_ptr for syncer and make sure get_record_cb_ won't get called when sync_thread is not running 2. Remove unnecessary forward declaration --- .../browser/sync/profile_sync_service_factory.cc | 15 ++++----------- .../sync/driver/glue/sync_engine_backend.cc | 5 +++-- .../sync/driver/profile_sync_service.cc | 2 +- .../sync/engine_impl/sync_scheduler_impl.cc | 2 +- .../components/sync/engine_impl/syncer.cc | 6 ++++-- chromium_src/components/sync/engine_impl/syncer.h | 1 - .../brave_sync/brave_profile_sync_service_impl.cc | 13 ++++++++----- components/brave_sync/jslib_messages_fwd.h | 7 ++++--- .../components-sync-engine_impl-syncer.h.patch | 11 +---------- 9 files changed, 26 insertions(+), 36 deletions(-) diff --git a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc index 5a792435a624..3c5a62c9e770 100644 --- a/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -4,17 +4,6 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "components/sync/driver/profile_sync_service.h" - -class Profile; - -namespace { -std::unique_ptr BraveBuildServiceInstanceFor( - Profile* profile, - syncer::ProfileSyncService::InitParams init_params); -} // namespace - -#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" // NOLINT - #include "brave/components/brave_sync/buildflags/buildflags.h" #if BUILDFLAG(ENABLE_BRAVE_SYNC) @@ -22,6 +11,8 @@ std::unique_ptr BraveBuildServiceInstanceFor( using brave_sync::BraveProfileSyncServiceImpl; #endif +class Profile; + namespace { std::unique_ptr BraveBuildServiceInstanceFor( @@ -36,3 +27,5 @@ std::unique_ptr BraveBuildServiceInstanceFor( } } // namespace + +#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" // NOLINT diff --git a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc index 4694fafe13a3..3dd9346e6a27 100644 --- a/chromium_src/components/sync/driver/glue/sync_engine_backend.cc +++ b/chromium_src/components/sync/driver/glue/sync_engine_backend.cc @@ -46,13 +46,14 @@ void OnPollSyncCycleOnOwnerThread(base::WeakPtr sync_engine, if (sync_engine.get()) static_cast( BraveGetSyncEngineHost(sync_engine.get())) - ->OnPollSyncCycle(cb, wevent); + ->OnPollSyncCycle(std::move(cb), wevent); } void OnPollSyncCycle(WeakHandle sync_engine_impl, GetRecordsCallback cb, base::WaitableEvent* wevent) { - sync_engine_impl.Call(FROM_HERE, &OnPollSyncCycleOnOwnerThread, cb, wevent); + sync_engine_impl.Call(FROM_HERE, &OnPollSyncCycleOnOwnerThread, + base::Passed(&cb), wevent); } #endif diff --git a/chromium_src/components/sync/driver/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc index 6685e97e30f7..5b995a855e87 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -43,7 +43,7 @@ void OnPollSyncCycle(base::WeakPtr profile_sync_service, base::WaitableEvent* wevent) { if (profile_sync_service.get()) { static_cast(profile_sync_service.get()) - ->OnPollSyncCycle(cb, wevent); + ->OnPollSyncCycle(std::move(cb), wevent); } } #endif diff --git a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc index eb33fca3db21..beab44e2497a 100644 --- a/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc +++ b/chromium_src/components/sync/engine_impl/sync_scheduler_impl.cc @@ -18,7 +18,7 @@ void SyncSchedulerImpl::OnNudgeSyncCycle( void SyncSchedulerImpl::OnPollSyncCycle(brave_sync::GetRecordsCallback cb, base::WaitableEvent* wevent) { DCHECK(poll_sync_cycle_delegate_function_); - poll_sync_cycle_delegate_function_.Run(cb, wevent); + poll_sync_cycle_delegate_function_.Run(std::move(cb), wevent); } } // namespace syncer diff --git a/chromium_src/components/sync/engine_impl/syncer.cc b/chromium_src/components/sync/engine_impl/syncer.cc index 1142f60ae2ce..3d08e61a497c 100644 --- a/chromium_src/components/sync/engine_impl/syncer.cc +++ b/chromium_src/components/sync/engine_impl/syncer.cc @@ -8,6 +8,8 @@ #include #include +#include "base/bind.h" + #include "../../../../../components/sync/engine_impl/syncer.cc" // NOLINT namespace syncer { @@ -23,9 +25,9 @@ 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::BindRepeating(&Syncer::OnGetRecords, AsWeakPtr()); + base::BindOnce(&Syncer::OnGetRecords, base::Unretained(this)); base::WaitableEvent wevent; - cycle->delegate()->OnPollSyncCycle(on_get_records, &wevent); + cycle->delegate()->OnPollSyncCycle(std::move(on_get_records), &wevent); // Make sure OnGetRecords will be the next task on sync thread wevent.Wait(); } diff --git a/chromium_src/components/sync/engine_impl/syncer.h b/chromium_src/components/sync/engine_impl/syncer.h index a1c19f527701..e0170fe93c2d 100644 --- a/chromium_src/components/sync/engine_impl/syncer.h +++ b/chromium_src/components/sync/engine_impl/syncer.h @@ -6,7 +6,6 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ -#include "base/memory/weak_ptr.h" #include "brave/components/brave_sync/jslib_messages.h" #include "brave/components/brave_sync/jslib_messages_fwd.h" diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index c75f2c964add..31196ff04be3 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -128,7 +128,7 @@ std::unique_ptr CreateDeleteBookmarkByObjectId( void DoDispatchGetRecordsCallback( GetRecordsCallback cb, std::unique_ptr records) { - cb.Run(std::move(records)); + std::move(cb).Run(std::move(records)); } void AddSyncEntityInfo(jslib::Bookmark* bookmark, @@ -301,7 +301,7 @@ void BraveProfileSyncServiceImpl::OnResetSync() { ResetSyncInternal(); } else { // We have to send delete record and wait for library deleted response then - // we can reset it by ResetInternal() + // we can reset it by ResetSyncInternal() const std::string device_id = brave_sync_prefs_->GetThisDeviceId(); OnDeleteDevice(device_id); reseting_ = true; @@ -524,8 +524,9 @@ void BraveProfileSyncServiceImpl::OnResolvedSyncRecords( // Send records to syncer if (get_record_cb_) sync_thread_->task_runner()->PostTask( - FROM_HERE, base::BindOnce(&DoDispatchGetRecordsCallback, - get_record_cb_, std::move(records))); + FROM_HERE, + base::BindOnce(&DoDispatchGetRecordsCallback, + std::move(get_record_cb_), std::move(records))); SignalWaitableEvent(); } else if (category_name == kHistorySites) { NOTIMPLEMENTED(); @@ -608,6 +609,7 @@ void BraveProfileSyncServiceImpl::NotifyHaveSyncWords( } void BraveProfileSyncServiceImpl::ResetSyncInternal() { + SignalWaitableEvent(); brave_sync_prefs_->SetPrevSeed(brave_sync_prefs_->GetSeed()); brave_sync_prefs_->Clear(); @@ -912,7 +914,7 @@ void BraveProfileSyncServiceImpl::OnPollSyncCycle(GetRecordsCallback cb, return; } - get_record_cb_ = cb; + get_record_cb_ = std::move(cb); wevent_ = wevent; const bool bookmarks = brave_sync_prefs_->GetSyncBookmarksEnabled(); @@ -923,6 +925,7 @@ void BraveProfileSyncServiceImpl::OnPollSyncCycle(GetRecordsCallback cb, } void BraveProfileSyncServiceImpl::SignalWaitableEvent() { + std::move(get_record_cb_); if (wevent_) { wevent_->Signal(); wevent_ = nullptr; diff --git a/components/brave_sync/jslib_messages_fwd.h b/components/brave_sync/jslib_messages_fwd.h index 4c5ad71aac62..181848bcbf06 100644 --- a/components/brave_sync/jslib_messages_fwd.h +++ b/components/brave_sync/jslib_messages_fwd.h @@ -40,10 +40,11 @@ typedef std::vector SyncRecordAndExistingList; using Uint8Array = std::vector; using GetRecordsCallback = - base::RepeatingCallback)>; -using NudgeSyncCycleDelegate = base::Callback; + base::OnceCallback)>; +using NudgeSyncCycleDelegate = base::RepeatingCallback; using PollSyncCycleDelegate = - base::Callback; + base::RepeatingCallback; } // namespace brave_sync diff --git a/patches/components-sync-engine_impl-syncer.h.patch b/patches/components-sync-engine_impl-syncer.h.patch index e7516cc19b69..a11771dfb757 100644 --- a/patches/components-sync-engine_impl-syncer.h.patch +++ b/patches/components-sync-engine_impl-syncer.h.patch @@ -1,16 +1,7 @@ diff --git a/components/sync/engine_impl/syncer.h b/components/sync/engine_impl/syncer.h -index 23b389eada81c850c3a8856678d046e599a060da..48654f4c09558ea4d0ac246ebe16178019b30a0e 100644 +index 23b389eada81c850c3a8856678d046e599a060da..30ce667ae1e00e51bf4f227084da8f4ca30f8dc2 100644 --- a/components/sync/engine_impl/syncer.h +++ b/components/sync/engine_impl/syncer.h -@@ -32,7 +32,7 @@ class SyncCycle; - // A Syncer instance expects to run on a dedicated thread. Calls to SyncShare() - // may take an unbounded amount of time because it may block on network I/O, on - // lock contention, or on tasks posted to other threads. --class Syncer { -+class Syncer : public base::SupportsWeakPtr { - public: - explicit Syncer(CancelationSignal* cancelation_signal); - virtual ~Syncer(); @@ -94,6 +94,7 @@ class Syncer { // Whether the syncer is in the middle of a sync attempt. bool is_syncing_; From 99f29b69cbeff30d234074f1e32ac51eb8793dee Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 16 Aug 2019 14:02:19 -0700 Subject: [PATCH 71/73] Use WaitableEvent::TimedWait as fail-safe --- chromium_src/components/sync/engine_impl/syncer.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chromium_src/components/sync/engine_impl/syncer.cc b/chromium_src/components/sync/engine_impl/syncer.cc index 3d08e61a497c..c3376cebe95e 100644 --- a/chromium_src/components/sync/engine_impl/syncer.cc +++ b/chromium_src/components/sync/engine_impl/syncer.cc @@ -9,6 +9,7 @@ #include #include "base/bind.h" +#include "base/time/time.h" #include "../../../../../components/sync/engine_impl/syncer.cc" // NOLINT @@ -29,7 +30,11 @@ void Syncer::DownloadBraveRecords(SyncCycle* cycle) { base::WaitableEvent wevent; cycle->delegate()->OnPollSyncCycle(std::move(on_get_records), &wevent); // Make sure OnGetRecords will be the next task on sync thread - wevent.Wait(); + // it will timeout in 3 mins to prevent sync thread from being blocked as + // fail-safe + bool result = wevent.TimedWait(base::TimeDelta::FromMinutes(3)); + if (!result) + LOG(WARNING) << "WaitableEvent timed out"; } } // namespace syncer From 8b243105857f5ab4dfe363f86129442467a9fbf2 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 16 Aug 2019 17:30:53 -0700 Subject: [PATCH 72/73] Review feedback (3) 1. Generate fake NIGORI entity when apply update 2. Set dummy encryption key for every update_response --- .../sync/engine_impl/get_updates_processor.cc | 32 ++++++++++++++++++- .../components-sync-base-model_type.h.patch | 12 ------- ...ync-driver-data_type_manager_impl.cc.patch | 13 -------- ...engine_impl-get_updates_processor.cc.patch | 12 ++----- 4 files changed, 33 insertions(+), 36 deletions(-) delete mode 100644 patches/components-sync-base-model_type.h.patch delete mode 100644 patches/components-sync-driver-data_type_manager_impl.cc.patch diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index df3fd4542a0d..6ff28a51b96f 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -26,8 +26,10 @@ SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse*, #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/nigori/cryptographer.h" #include "components/sync/syncable/syncable_proto_util.h" #include "url/gurl.h" @@ -225,11 +227,39 @@ void ConstructUpdateResponse(sync_pb::GetUpdatesResponse* gu_response, 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::SystemEncryptor encryptor; + syncer::Cryptographer cryptographer(&encryptor); + 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->set_changes_remaining(0); + gu_response->add_encryption_keys("dummy_encryption_key"); } SyncerError ApplyBraveRecords(sync_pb::ClientToServerResponse* update_response, diff --git a/patches/components-sync-base-model_type.h.patch b/patches/components-sync-base-model_type.h.patch deleted file mode 100644 index f6cfd880cfd9..000000000000 --- a/patches/components-sync-base-model_type.h.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/sync/base/model_type.h b/components/sync/base/model_type.h -index d751ce7b3c9618cca3bf48e2cc9c640be9fa9d22..3b18b631a8db839c9a0ee820fea9f4b52b2b9890 100644 ---- a/components/sync/base/model_type.h -+++ b/components/sync/base/model_type.h -@@ -244,6 +244,7 @@ constexpr ModelTypeSet ProxyTypes() { - // - They support custom update application and conflict resolution logic. - // - All change processing occurs on the sync thread (GROUP_PASSIVE). - constexpr ModelTypeSet ControlTypes() { -+ return ModelTypeSet(UNSPECIFIED); - return ModelTypeSet(NIGORI); - } - diff --git a/patches/components-sync-driver-data_type_manager_impl.cc.patch b/patches/components-sync-driver-data_type_manager_impl.cc.patch deleted file mode 100644 index 80bffda14a49..000000000000 --- a/patches/components-sync-driver-data_type_manager_impl.cc.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/components/sync/driver/data_type_manager_impl.cc b/components/sync/driver/data_type_manager_impl.cc -index a8c9a81571950ecf430c6f82fb6baa8057e576fa..0da71d472e253749b6a3561e542183dd12efa0bc 100644 ---- a/components/sync/driver/data_type_manager_impl.cc -+++ b/components/sync/driver/data_type_manager_impl.cc -@@ -544,7 +544,7 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( - types_to_download.RemoveAll(ProxyTypes()); - types_to_download.RemoveAll(CommitOnlyTypes()); - if (!types_to_download.Empty()) -- types_to_download.Put(NIGORI); -+ ; // types_to_download.Put(NIGORI); - - // TODO(sync): crbug.com/137550. - // It's dangerous to configure types that have progress markers. Types with diff --git a/patches/components-sync-engine_impl-get_updates_processor.cc.patch b/patches/components-sync-engine_impl-get_updates_processor.cc.patch index 7ecefc86ff8e..772c3bee380d 100644 --- a/patches/components-sync-engine_impl-get_updates_processor.cc.patch +++ b/patches/components-sync-engine_impl-get_updates_processor.cc.patch @@ -1,16 +1,8 @@ diff --git a/components/sync/engine_impl/get_updates_processor.cc b/components/sync/engine_impl/get_updates_processor.cc -index faeff075cf940e8c1db7941f4c3dca27bf63f580..98992f1553a4622fe2a3918108fb8a89ac7bc5ff 100644 +index faeff075cf940e8c1db7941f4c3dca27bf63f580..af6143ed5625e060ca17e5ebf93fbbd4a85061d2 100644 --- a/components/sync/engine_impl/get_updates_processor.cc +++ b/components/sync/engine_impl/get_updates_processor.cc -@@ -36,6 +36,7 @@ bool ShouldRequestEncryptionKey(SyncCycleContext* context) { - SyncerError HandleGetEncryptionKeyResponse( - const sync_pb::ClientToServerResponse& update_response, - SyncCycleContext* context) { -+ return SyncerError(SyncerError::SYNCER_OK); - bool success = false; - if (update_response.get_updates().encryption_keys_size() == 0) { - LOG(ERROR) << "Failed to receive encryption key from server."; -@@ -225,6 +226,7 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( +@@ -225,6 +225,7 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates( SyncerError result = SyncerProtoUtil::PostClientToServerMessage( *msg, &update_response, cycle, &partial_failure_data_types); From 42c5c3190177eceb6e8cae9d184112a43f6738f1 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 19 Aug 2019 12:34:54 -0700 Subject: [PATCH 73/73] Do not send meta info until all platforms support necessary chromium sync protocol like "version" and "UniquePosition", ...etc --- .../components/sync/engine_impl/commit.cc | 15 --------------- .../sync/engine_impl/get_updates_processor.cc | 14 -------------- .../brave_sync/brave_profile_sync_service_impl.cc | 6 ------ components/brave_sync/extension/background.js | 6 ++++++ 4 files changed, 6 insertions(+), 35 deletions(-) diff --git a/chromium_src/components/sync/engine_impl/commit.cc b/chromium_src/components/sync/engine_impl/commit.cc index 3f67bb572e0a..5c61637db9f2 100644 --- a/chromium_src/components/sync/engine_impl/commit.cc +++ b/chromium_src/components/sync/engine_impl/commit.cc @@ -141,25 +141,10 @@ brave_sync::RecordsListPtr ConvertCommitsToBraveRecords( metaInfo.value = std::to_string(version); bookmark->metaInfo.push_back(metaInfo); - metaInfo.key = "mtime"; - metaInfo.value = std::to_string(entity.mtime()); - bookmark->metaInfo.push_back(metaInfo); - - metaInfo.key = "ctime"; - metaInfo.value = std::to_string(entity.ctime()); - bookmark->metaInfo.push_back(metaInfo); - metaInfo.key = "position_in_parent"; metaInfo.value = std::to_string(entity.position_in_parent()); bookmark->metaInfo.push_back(metaInfo); - if (bm_specifics.has_favicon()) { - std::string icon_base64; - base::Base64Encode(bm_specifics.favicon(), &icon_base64); - metaInfo.key = "icon_data"; - metaInfo.value = icon_base64; - bookmark->metaInfo.push_back(metaInfo); - } record->SetBookmark(std::move(bookmark)); if (!skip_record) record_list->push_back(std::move(record)); diff --git a/chromium_src/components/sync/engine_impl/get_updates_processor.cc b/chromium_src/components/sync/engine_impl/get_updates_processor.cc index 6ff28a51b96f..77d6097e44cf 100644 --- a/chromium_src/components/sync/engine_impl/get_updates_processor.cc +++ b/chromium_src/components/sync/engine_impl/get_updates_processor.cc @@ -99,25 +99,11 @@ void ExtractBookmarkMeta(sync_pb::SyncEntity* entity, 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 == "mtime") { - int64_t mtime; - bool result = base::StringToInt64(metaInfo.value, &mtime); - DCHECK(result); - entity->set_mtime(mtime); - } else if (metaInfo.key == "ctime") { - int64_t ctime; - bool result = base::StringToInt64(metaInfo.value, &ctime); - DCHECK(result); - entity->set_ctime(ctime); } 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); - } else if (metaInfo.key == "icon_data") { - std::string icon_data_decoded; - base::Base64Decode(metaInfo.value, &icon_data_decoded); - bm_specifics->set_favicon(icon_data_decoded); } } } diff --git a/components/brave_sync/brave_profile_sync_service_impl.cc b/components/brave_sync/brave_profile_sync_service_impl.cc index 31196ff04be3..b74054202244 100644 --- a/components/brave_sync/brave_profile_sync_service_impl.cc +++ b/components/brave_sync/brave_profile_sync_service_impl.cc @@ -698,10 +698,7 @@ BraveProfileSyncServiceImpl::BookmarkNodeToSyncBookmark( AddSyncEntityInfo(bookmark.get(), node, "originator_cache_guid"); AddSyncEntityInfo(bookmark.get(), node, "originator_client_item_id"); AddSyncEntityInfo(bookmark.get(), node, "version"); - AddSyncEntityInfo(bookmark.get(), node, "mtime"); - AddSyncEntityInfo(bookmark.get(), node, "ctime"); AddSyncEntityInfo(bookmark.get(), node, "position_in_parent"); - AddSyncEntityInfo(bookmark.get(), node, "icon_data"); record->SetBookmark(std::move(bookmark)); @@ -729,10 +726,7 @@ void BraveProfileSyncServiceImpl::LoadSyncEntityInfo( return; AddSyncEntityInfo(bookmark, node, "originator_cache_guid"); AddSyncEntityInfo(bookmark, node, "originator_client_item_id"); - AddSyncEntityInfo(bookmark, node, "mtime"); - AddSyncEntityInfo(bookmark, node, "ctime"); AddSyncEntityInfo(bookmark, node, "position_in_parent"); - AddSyncEntityInfo(bookmark, node, "icon_data"); std::string s_version; // Version needs to be incremented by 1 for legacy sync to emulate // GetUpdateProcessor behavior diff --git a/components/brave_sync/extension/background.js b/components/brave_sync/extension/background.js index 70ee291ff96d..5fabc8824137 100644 --- a/components/brave_sync/extension/background.js +++ b/components/brave_sync/extension/background.js @@ -48,6 +48,12 @@ chrome.braveSync.onSendSyncRecords.addListener(function(category_name, records) // Fixup ids for (var i = 0; i < records.length; ++i) { fixupSyncRecordBrowserToExt(records[i]); + // delete meta info for now until all platforms can support + // "Version" and "UniquePosition" of chromium sync proto + if ('bookmark' in records[i]) { + if ('metaInfo' in records[i].bookmark) + delete records[i].bookmark.metaInfo; + } } console.log(`"send-sync-records" category_name=${JSON.stringify(category_name)} records=${JSON.stringify(records)}`); callbackList["send-sync-records"](null, category_name, records);