Skip to content

Commit

Permalink
Merge pull request #6200 from brave/sync-setup-in-progress
Browse files Browse the repository at this point in the history
Sync setup in progress
  • Loading branch information
darkdh authored Jul 27, 2020
2 parents 32958b7 + 62ed79a commit 87e6d0e
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -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"
41 changes: 0 additions & 41 deletions chromium_src/components/sync/driver/profile_sync_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 4 additions & 16 deletions chromium_src/components/sync/driver/profile_sync_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
62 changes: 62 additions & 0 deletions components/sync/driver/brave_sync_profile_sync_service.cc
Original file line number Diff line number Diff line change
@@ -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 <utility>

#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<BraveSyncAuthManager*>(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
37 changes: 37 additions & 0 deletions components/sync/driver/brave_sync_profile_sync_service.h
Original file line number Diff line number Diff line change
@@ -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 <string>

#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_
2 changes: 2 additions & 0 deletions components/sync/driver/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
13 changes: 13 additions & 0 deletions patches/chrome-browser-sync-profile_sync_service_factory.cc.patch
Original file line number Diff line number Diff line change
@@ -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<syncer::ProfileSyncService>(std::move(init_params));
+ std::make_unique<syncer::BraveProfileSyncService>(std::move(init_params));

#if defined(OS_WIN)
if (!local_sync_backend_enabled)
20 changes: 0 additions & 20 deletions patches/components-sync-driver-profile_sync_service.cc.patch

This file was deleted.

0 comments on commit 87e6d0e

Please sign in to comment.