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..d430f74aefa4 --- /dev/null +++ b/chromium_src/chrome/browser/sync/profile_sync_service_factory.cc @@ -0,0 +1,8 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/sync/driver/brave_sync_profile_sync_service.h" + +#include "../../../../../chrome/browser/sync/profile_sync_service_factory.cc" diff --git a/chromium_src/components/sync/driver/profile_sync_service.cc b/chromium_src/components/sync/driver/profile_sync_service.cc index 9a2a3a298b1c..d0566ba4d91a 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.cc +++ b/chromium_src/components/sync/driver/profile_sync_service.cc @@ -3,54 +3,13 @@ * 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/prefs/pref_service.h" - #include "brave/components/sync/driver/brave_sync_auth_manager.h" #include "brave/components/sync/driver/brave_sync_stopped_reporter.h" -#define BRAVE_PROFILE_SYNC_SERVICE \ - brave_sync_prefs_change_registrar_.Init(sync_client_->GetPrefService()); \ - brave_sync_prefs_change_registrar_.Add( \ - brave_sync::Prefs::GetSeedPath(), \ - base::Bind(&ProfileSyncService::OnBraveSyncPrefsChanged, \ - base::Unretained(this))); \ - brave_sync::Prefs brave_sync_prefs(sync_client_->GetPrefService()); \ - auth_manager_->DeriveSigningKeys(brave_sync_prefs.GetSeed()); \ - if (!brave_sync_prefs.IsSyncV1Migrated()) { \ - StopImpl(CLEAR_DATA); \ - brave_sync_prefs.SetSyncV1Migrated(true); \ - } - -#define BRAVE_D_PROFILE_SYNC_SERVICE \ - brave_sync_prefs_change_registrar_.RemoveAll(); - #define SyncAuthManager BraveSyncAuthManager #define SyncStoppedReporter BraveSyncStoppedReporter #include "../../../../../components/sync/driver/profile_sync_service.cc" -#undef BRAVE_PROFILE_SYNC_SERVICE -#undef BRAVE_D_PROFILE_SYNC_SERVICE #undef SyncAuthManager #undef SyncStoppedReporter - -namespace syncer { -void ProfileSyncService::OnBraveSyncPrefsChanged(const std::string& path) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (path == brave_sync::Prefs::GetSeedPath()) { - brave_sync::Prefs brave_sync_prefs(sync_client_->GetPrefService()); - const std::string seed = brave_sync_prefs.GetSeed(); - if (!seed.empty()) { - auth_manager_->DeriveSigningKeys(seed); - // Default enabled types: Bookmarks - syncer::UserSelectableTypeSet selected_types; - selected_types.Put(UserSelectableType::kBookmarks); - GetUserSettings()->SetSelectedTypes(false, selected_types); - } else { - VLOG(1) << "Brave sync seed cleared"; - auth_manager_->ResetKeys(); - } - } -} -} // namespace syncer diff --git a/chromium_src/components/sync/driver/profile_sync_service.h b/chromium_src/components/sync/driver/profile_sync_service.h index a7f0d9d209cc..a1506da31397 100644 --- a/chromium_src/components/sync/driver/profile_sync_service.h +++ b/chromium_src/components/sync/driver/profile_sync_service.h @@ -6,24 +6,12 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ -#include "components/prefs/pref_change_registrar.h" -// Header guard to prevent Initialize from getting overriden in it -// ============================================================================ -#include "components/sync/base/sync_prefs.h" -#include "components/sync/driver/sync_service_crypto.h" -// ============================================================================ - - -#define BRAVE_PROFILE_SYNC_SERVICE_H_ \ - private: \ - PrefChangeRegistrar brave_sync_prefs_change_registrar_; - -#define Initialize \ - OnBraveSyncPrefsChanged(const std::string& path); \ - void Initialize +#define BRAVE_PROFILE_SYNC_SERVICE_H_ \ + private: \ + friend class BraveProfileSyncService; #include "../../../../../components/sync/driver/profile_sync_service.h" #undef BRAVE_PROFILE_SYNC_SERVICE_H_ -#undef Initialize + #endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_DRIVER_PROFILE_SYNC_SERVICE_H_ diff --git a/components/sync/driver/brave_sync_profile_sync_service.cc b/components/sync/driver/brave_sync_profile_sync_service.cc new file mode 100644 index 000000000000..a8c3c2d8e0e5 --- /dev/null +++ b/components/sync/driver/brave_sync_profile_sync_service.cc @@ -0,0 +1,62 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/sync/driver/brave_sync_profile_sync_service.h" + +#include + +#include "base/logging.h" +#include "brave/components/brave_sync/brave_sync_prefs.h" +#include "brave/components/sync/driver/brave_sync_auth_manager.h" +#include "components/prefs/pref_service.h" + +namespace syncer { + +BraveProfileSyncService::BraveProfileSyncService(InitParams init_params) + : ProfileSyncService(std::move(init_params)) { + brave_sync_prefs_change_registrar_.Init(sync_client_->GetPrefService()); + brave_sync_prefs_change_registrar_.Add( + brave_sync::Prefs::GetSeedPath(), + base::Bind(&BraveProfileSyncService::OnBraveSyncPrefsChanged, + base::Unretained(this))); + brave_sync::Prefs brave_sync_prefs(sync_client_->GetPrefService()); + GetBraveSyncAuthManager()->DeriveSigningKeys(brave_sync_prefs.GetSeed()); + if (!brave_sync_prefs.IsSyncV1Migrated()) { + StopImpl(CLEAR_DATA); + brave_sync_prefs.SetSyncV1Migrated(true); + } +} + +BraveProfileSyncService::~BraveProfileSyncService() { + brave_sync_prefs_change_registrar_.RemoveAll(); +} + +bool BraveProfileSyncService::IsSetupInProgress() const { + return ProfileSyncService::IsSetupInProgress() && + !user_settings_->IsFirstSetupComplete(); +} + +BraveSyncAuthManager* BraveProfileSyncService::GetBraveSyncAuthManager() { + return static_cast(auth_manager_.get()); +} + +void BraveProfileSyncService::OnBraveSyncPrefsChanged(const std::string& path) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + if (path == brave_sync::Prefs::GetSeedPath()) { + brave_sync::Prefs brave_sync_prefs(sync_client_->GetPrefService()); + const std::string seed = brave_sync_prefs.GetSeed(); + if (!seed.empty()) { + GetBraveSyncAuthManager()->DeriveSigningKeys(seed); + // Default enabled types: Bookmarks + syncer::UserSelectableTypeSet selected_types; + selected_types.Put(UserSelectableType::kBookmarks); + GetUserSettings()->SetSelectedTypes(false, selected_types); + } else { + VLOG(1) << "Brave sync seed cleared"; + GetBraveSyncAuthManager()->ResetKeys(); + } + } +} +} // namespace syncer diff --git a/components/sync/driver/brave_sync_profile_sync_service.h b/components/sync/driver/brave_sync_profile_sync_service.h new file mode 100644 index 000000000000..8f9447fc9fb8 --- /dev/null +++ b/components/sync/driver/brave_sync_profile_sync_service.h @@ -0,0 +1,37 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_SYNC_DRIVER_BRAVE_SYNC_PROFILE_SYNC_SERVICE_H_ +#define BRAVE_COMPONENTS_SYNC_DRIVER_BRAVE_SYNC_PROFILE_SYNC_SERVICE_H_ + +#include + +#include "components/prefs/pref_change_registrar.h" +#include "components/sync/driver/profile_sync_service.h" + +namespace syncer { + +class BraveSyncAuthManager; + +class BraveProfileSyncService : public ProfileSyncService { + public: + explicit BraveProfileSyncService(InitParams init_params); + ~BraveProfileSyncService() override; + + // SyncService implementation + bool IsSetupInProgress() const override; + + private: + BraveSyncAuthManager* GetBraveSyncAuthManager(); + + void OnBraveSyncPrefsChanged(const std::string& path); + + PrefChangeRegistrar brave_sync_prefs_change_registrar_; + + DISALLOW_COPY_AND_ASSIGN(BraveProfileSyncService); +}; +} // namespace syncer + +#endif // BRAVE_COMPONENTS_SYNC_DRIVER_BRAVE_SYNC_PROFILE_SYNC_SERVICE_H_ diff --git a/components/sync/driver/sources.gni b/components/sync/driver/sources.gni index 0a2644602202..0f1688fc6f76 100644 --- a/components/sync/driver/sources.gni +++ b/components/sync/driver/sources.gni @@ -6,6 +6,8 @@ brave_components_sync_driver_sources = [ "//brave/components/sync/driver/brave_sync_auth_manager.cc", "//brave/components/sync/driver/brave_sync_auth_manager.h", + "//brave/components/sync/driver/brave_sync_profile_sync_service.cc", + "//brave/components/sync/driver/brave_sync_profile_sync_service.h", "//brave/components/sync/driver/brave_sync_stopped_reporter.cc", "//brave/components/sync/driver/brave_sync_stopped_reporter.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..18a7ffbd4ffb --- /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 dca006daae56b4c31d838304a5b0493b92cd05ec..6bda62f4894b5939939d47774bc9563c3b2133b3 100644 +--- a/chrome/browser/sync/profile_sync_service_factory.cc ++++ b/chrome/browser/sync/profile_sync_service_factory.cc +@@ -269,7 +269,7 @@ KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( + } + + auto pss = +- std::make_unique(std::move(init_params)); ++ std::make_unique(std::move(init_params)); + + #if defined(OS_WIN) + if (!local_sync_backend_enabled) diff --git a/patches/components-sync-driver-profile_sync_service.cc.patch b/patches/components-sync-driver-profile_sync_service.cc.patch deleted file mode 100644 index 0d172d4e7b54..000000000000 --- a/patches/components-sync-driver-profile_sync_service.cc.patch +++ /dev/null @@ -1,30 +0,0 @@ -diff --git a/components/sync/driver/profile_sync_service.cc b/components/sync/driver/profile_sync_service.cc -index 1b03c062de472bf55aad26d7b840fd72104c23d1..935789b9af4340493db1e37a0428c6e436c35dd0 100644 ---- a/components/sync/driver/profile_sync_service.cc -+++ b/components/sync/driver/profile_sync_service.cc -@@ -259,6 +259,7 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(sync_client_); - DCHECK(IsLocalSyncEnabled() || identity_manager_ != nullptr); -+ BRAVE_PROFILE_SYNC_SERVICE - - // If Sync is disabled via command line flag, then ProfileSyncService - // shouldn't be instantiated. -@@ -293,6 +294,7 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) - - ProfileSyncService::~ProfileSyncService() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); -+ BRAVE_D_PROFILE_SYNC_SERVICE - if (identity_manager_) - identity_manager_->RemoveObserver(this); - sync_prefs_.RemoveSyncPrefObserver(this); -@@ -1212,7 +1214,8 @@ void ProfileSyncService::OnConfigureStart() { - - bool ProfileSyncService::IsSetupInProgress() const { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); -- return outstanding_setup_in_progress_handles_ > 0; -+ return outstanding_setup_in_progress_handles_ > 0 && -+ !user_settings_->IsFirstSetupComplete(); - } - - bool ProfileSyncService::QueryDetailedSyncStatusForDebugging(