Commit c24d99c8 authored by Maksim Moskvitin's avatar Maksim Moskvitin Committed by Commit Bot

[Sync:USS] Support BackendMigrator logic for USS Nigori

BackendMigrator logic requires resetting sync metadata for specific
datatype. For regular datatypes, corresponding logic lives inside
ModelAssociationManager and DataTypeManager, which don't have access
to Nigori's ModelTypeController. For Directory implementation of Nigori
this logic implemented through Directory::PurgeEntiesWithTypeIn().

We can detect required migration, because call of
Directory::PurgeEntiesWithTypeIn() plumbed through SyncEngineBackend.
We just restart ModelTypeController for Nigori and this triggers call
of NigoriSyncBridge::ApplyDisableSyncChanges().

We keep in-memory state of explicit passphrase key loaded from the
prefs, because we need it for future support of BackendMigrator for USS
Nigori. It's safe, because if we stop due to disabling sync, we will
also clear corresponding pref and we should not worry about in-memory
state of the bridge, since we won't continue use the same instance.

This is not perfect solution, and we need to try a better one. But for
now all alternatives too intrusive (getting rid of ModelTypeController
for Nigori or moving it into the UI thread).

This CL allows passing Migration*ClientTest with enabled USS
implementation of Nigori.

Bug: 922900
Change-Id: I9f7b218dec46ebfcc21ad8093b73e3c019fd438f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1784606
Commit-Queue: Maksim Moskvitin <mmoskvitin@google.com>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693822}
parent 9dc52654
......@@ -139,21 +139,7 @@ void SyncEngineBackend::OnInitializationComplete(
if (nigori_controller_) {
// Having non-null |nigori_controller_| means that USS implementation of
// Nigori is enabled.
// The controller for Nigori is not exposed to the UI thread or the
// DataTypeManager, so we need to start it here manually.
ConfigureContext configure_context;
configure_context.authenticated_account_id = authenticated_account_id_;
configure_context.cache_guid = sync_manager_->cache_guid();
// TODO(crbug.com/922900): investigate whether we want to use
// STORAGE_IN_MEMORY in Butter mode.
configure_context.storage_option = STORAGE_ON_DISK;
configure_context.configuration_start_time = base::Time::Now();
nigori_controller_->LoadModels(configure_context, base::DoNothing());
DCHECK_EQ(nigori_controller_->state(), DataTypeController::MODEL_LOADED);
// TODO(crbug.com/922900): Do we need to call RegisterNonBlockingType() for
// Nigori?
model_type_connector->ConnectNonBlockingType(
NIGORI, nigori_controller_->ActivateManuallyForNigori());
LoadAndConnectNigoriController();
} else {
// Control types don't have DataTypeControllers, but they need to have
// update handlers registered in ModelTypeRegistry.
......@@ -552,6 +538,16 @@ void SyncEngineBackend::DoPurgeDisabledTypes(const ModelTypeSet& to_purge,
const ModelTypeSet& to_unapply) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
sync_manager_->PurgeDisabledTypes(to_purge, to_journal, to_unapply);
if (to_purge.Has(NIGORI) && nigori_controller_) {
// We are using USS implementation of Nigori and someone asked us to purge
// it's data. For regular datatypes it's controlled DataTypeManager, but
// for Nigori we need to do it here.
// TODO(crbug.com/922900): try to find better way to implement this logic,
// it's likely happen only due to BackendMigrator.
sync_manager_->GetModelTypeConnector()->DisconnectNonBlockingType(NIGORI);
nigori_controller_->Stop(ShutdownReason::DISABLE_SYNC, base::DoNothing());
LoadAndConnectNigoriController();
}
}
void SyncEngineBackend::DoConfigureSyncer(
......@@ -680,4 +676,22 @@ bool SyncEngineBackend::HasUnsyncedItemsForTest() const {
return sync_manager_->HasUnsyncedItemsForTest();
}
void SyncEngineBackend::LoadAndConnectNigoriController() {
// The controller for Nigori is not exposed to the UI thread or the
// DataTypeManager, so we need to start it here manually.
ConfigureContext configure_context;
configure_context.authenticated_account_id = authenticated_account_id_;
configure_context.cache_guid = sync_manager_->cache_guid();
// TODO(crbug.com/922900): investigate whether we want to use
// STORAGE_IN_MEMORY in Butter mode.
configure_context.storage_option = STORAGE_ON_DISK;
configure_context.configuration_start_time = base::Time::Now();
nigori_controller_->LoadModels(configure_context, base::DoNothing());
DCHECK_EQ(nigori_controller_->state(), DataTypeController::MODEL_LOADED);
// TODO(crbug.com/922900): Do we need to call RegisterNonBlockingType() for
// Nigori?
sync_manager_->GetModelTypeConnector()->ConnectNonBlockingType(
NIGORI, nigori_controller_->ActivateManuallyForNigori());
}
} // namespace syncer
......@@ -197,6 +197,8 @@ class SyncEngineBackend : public base::RefCountedThreadSafe<SyncEngineBackend>,
// be run on; the host's |registrar_->sync_thread()|.
void StartSavingChanges();
void LoadAndConnectNigoriController();
// Name used for debugging.
const std::string name_;
......
......@@ -977,9 +977,17 @@ ConflictResolution NigoriSyncBridgeImpl::ResolveConflict(
void NigoriSyncBridgeImpl::ApplyDisableSyncChanges() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// The user intended to disable sync, so we need to clear all the data.
// The user intended to disable sync, so we need to clear all the data,
// except |serialized_explicit_passphrase_key_| in memory, because this
// function can be called due to BackendMigrator. It's safe even if this
// function called due to actual disabling sync, since we remove the
// persisted key by clearing sync prefs explicitly, and don't reuse current
// instance of the bridge after that.
// TODO(crbug.com/922900): idea with keeping
// |serialized_explicit_passphrase_key_| will become not working, once we
// clean up storing explicit passphrase key in prefs, we need to find better
// solution.
storage_->ClearData();
serialized_explicit_passphrase_key_ = "";
keystore_keys_.clear();
cryptographer_.CopyFrom(Cryptographer());
passphrase_type_ = NigoriSpecifics::UNKNOWN;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment