Skip to content

Commit

Permalink
Using MigratedBookmarksVersion >= 2 to check legacy sync migration st…
Browse files Browse the repository at this point in the history
…atus so

that sync engine only starts after OnSyncReady
  • Loading branch information
darkdh committed May 9, 2019
1 parent b250f59 commit c00e256
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 46 deletions.
5 changes: 0 additions & 5 deletions chromium_src/components/browser_sync/profile_sync_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
41 changes: 15 additions & 26 deletions components/brave_sync/brave_profile_sync_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -621,6 +627,7 @@ void BraveProfileSyncService::SetPermanentNodesOrder(
const_cast<bookmarks::BookmarkNode*>(model_->other_node());
model_->SetNodeMetaInfo(mutable_other_node, "order", base_order + "2");
}
brave_sync_prefs_->SetMigratedBookmarksVersion(2);
}


Expand Down Expand Up @@ -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();
Expand All @@ -740,24 +747,6 @@ BraveSyncClient* BraveProfileSyncService::GetBraveSyncClient() {
return ProfileSyncService::GetSyncClient()->GetBraveSyncClient();
}

void BraveProfileSyncService::OnEngineInitialized(
syncer::ModelTypeSet initial_types,
const syncer::WeakHandle<syncer::JsBackend>& js_backend,
const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
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();
}
Expand Down
11 changes: 0 additions & 11 deletions components/brave_sync/brave_profile_sync_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<syncer::JsBackend>& js_backend,
const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
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;
Expand Down
7 changes: 3 additions & 4 deletions patches/components-browser_sync-profile_sync_service.h.patch
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
};

Expand Down

0 comments on commit c00e256

Please sign in to comment.