Commit b2d9f5f0 authored by Marc Treib's avatar Marc Treib Committed by Chromium LUCI CQ

DataTypeManagerImpl: Replace "download" with "configure"

Many parts of DataTypeManagerImpl that talked about "downloading"
actually had little to do with downloading (mainly, it was about calling
ModelTypeConfigurer::ConfigureDataTypes(), which does the actual
downloading).
This CL replaces "download" with "configuration" in those places, to
make clearer what's going on. In particular, StartNextDownload is
renamed to StartNextConfiguration, and DownloadCompleted to
ConfigurationCompleted.

Bug: 1102837
Change-Id: Ibcdb85f9f1177689e05e915d597b4241576f3b32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2570370
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833305}
parent 4229dc16
...@@ -320,7 +320,7 @@ void DataTypeManagerImpl::Restart() { ...@@ -320,7 +320,7 @@ void DataTypeManagerImpl::Restart() {
if (old_state == STOPPED || old_state == CONFIGURED) if (old_state == STOPPED || old_state == CONFIGURED)
NotifyStart(); NotifyStart();
download_types_queue_ = PrioritizeTypes(last_enabled_types_); configuration_types_queue_ = PrioritizeTypes(last_enabled_types_);
association_types_info_.reset(); association_types_info_.reset();
model_load_manager_.Initialize( model_load_manager_.Initialize(
...@@ -330,12 +330,12 @@ void DataTypeManagerImpl::Restart() { ...@@ -330,12 +330,12 @@ void DataTypeManagerImpl::Restart() {
void DataTypeManagerImpl::OnAllDataTypesReadyForConfigure() { void DataTypeManagerImpl::OnAllDataTypesReadyForConfigure() {
// TODO(crbug.com/1102837): Should we handle |needs_reconfigure_| here, // TODO(crbug.com/1102837): Should we handle |needs_reconfigure_| here,
// before even starting the downloads? // before even starting the configuration?
// TODO(pavely): By now some of datatypes in |download_types_queue_| could // TODO(pavely): By now some of datatypes in |configuration_types_queue_|
// have failed loading and should be excluded from configuration. I need to // could have failed loading and should be excluded from configuration. I need
// adjust |download_types_queue_| for such types. // to adjust |configuration_types_queue_| for such types.
ActivateDataTypes(); ActivateDataTypes();
StartNextDownload(/*high_priority_types_before=*/ModelTypeSet()); StartNextConfiguration(/*higher_priority_types_before=*/ModelTypeSet());
} }
ModelTypeSet DataTypeManagerImpl::GetPriorityTypes() const { ModelTypeSet DataTypeManagerImpl::GetPriorityTypes() const {
...@@ -344,7 +344,7 @@ ModelTypeSet DataTypeManagerImpl::GetPriorityTypes() const { ...@@ -344,7 +344,7 @@ ModelTypeSet DataTypeManagerImpl::GetPriorityTypes() const {
base::queue<ModelTypeSet> DataTypeManagerImpl::PrioritizeTypes( base::queue<ModelTypeSet> DataTypeManagerImpl::PrioritizeTypes(
const ModelTypeSet& types) { const ModelTypeSet& types) {
// Control types are usually downloaded before all other types during // Control types are usually configured before all other types during
// initialization of sync engine even before data type manager gets // initialization of sync engine even before data type manager gets
// constructed. However, listing control types here with the highest priority // constructed. However, listing control types here with the highest priority
// makes the behavior consistent also for various flows for restarting sync // makes the behavior consistent also for various flows for restarting sync
...@@ -427,8 +427,8 @@ void DataTypeManagerImpl::ProcessReconfigure() { ...@@ -427,8 +427,8 @@ void DataTypeManagerImpl::ProcessReconfigure() {
return; return;
} }
// Wait for current download to finish. // Wait for current configuration to finish.
if (!download_types_queue_.empty()) { if (!configuration_types_queue_.empty()) {
return; return;
} }
...@@ -452,12 +452,12 @@ void DataTypeManagerImpl::ProcessReconfigure() { ...@@ -452,12 +452,12 @@ void DataTypeManagerImpl::ProcessReconfigure() {
ConfigureImpl(last_requested_types_, last_requested_context_); ConfigureImpl(last_requested_types_, last_requested_context_);
} }
void DataTypeManagerImpl::DownloadCompleted( void DataTypeManagerImpl::ConfigurationCompleted(
ModelTypeSet downloaded_types, ModelTypeSet configured_types,
ModelTypeSet succeeded_configuration_types, ModelTypeSet succeeded_configuration_types,
ModelTypeSet failed_configuration_types) { ModelTypeSet failed_configuration_types) {
// Note: |downloaded_types| are the types we requested to download, but some // Note: |configured_types| are the types we requested to configure. Some of
// of them might have been downloaded already. |succeeded_configuration_types| // them might have been downloaded already. |succeeded_configuration_types|
// are the ones that were actually downloaded just now. // are the ones that were actually downloaded just now.
DCHECK_EQ(CONFIGURING, state_); DCHECK_EQ(CONFIGURING, state_);
...@@ -465,24 +465,24 @@ void DataTypeManagerImpl::DownloadCompleted( ...@@ -465,24 +465,24 @@ void DataTypeManagerImpl::DownloadCompleted(
DataTypeStatusTable::TypeErrorMap errors; DataTypeStatusTable::TypeErrorMap errors;
for (ModelType type : failed_configuration_types) { for (ModelType type : failed_configuration_types) {
SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR,
"Backend failed to download type.", type); "Backend failed to download and configure type.", type);
errors[type] = error; errors[type] = error;
} }
data_type_status_table_.UpdateFailedDataTypes(errors); data_type_status_table_.UpdateFailedDataTypes(errors);
needs_reconfigure_ = true; needs_reconfigure_ = true;
} }
// If a reconfigure was requested while this download was ongoing, process it // If a reconfigure was requested while this configuration was ongoing,
// now. // process it now.
if (needs_reconfigure_) { if (needs_reconfigure_) {
download_types_queue_ = base::queue<ModelTypeSet>(); configuration_types_queue_ = base::queue<ModelTypeSet>();
ProcessReconfigure(); ProcessReconfigure();
return; return;
} }
DCHECK(!download_types_queue_.empty()); DCHECK(!configuration_types_queue_.empty());
DCHECK(download_types_queue_.front() == downloaded_types); DCHECK(configuration_types_queue_.front() == configured_types);
download_types_queue_.pop(); configuration_types_queue_.pop();
if (association_types_info_) { if (association_types_info_) {
// A non-empty |association_types_info_| means there were actually types // A non-empty |association_types_info_| means there were actually types
...@@ -493,23 +493,36 @@ void DataTypeManagerImpl::DownloadCompleted( ...@@ -493,23 +493,36 @@ void DataTypeManagerImpl::DownloadCompleted(
} }
DCHECK(!association_types_info_); DCHECK(!association_types_info_);
if (download_types_queue_.empty()) { if (configuration_types_queue_.empty()) {
state_ = CONFIGURED; state_ = CONFIGURED;
NotifyDone(ConfigureResult(OK, last_requested_types_)); NotifyDone(ConfigureResult(OK, last_requested_types_));
return; return;
} }
StartNextDownload(/*high_priority_types_before=*/downloaded_types); StartNextConfiguration(/*higher_priority_types_before=*/configured_types);
} }
void DataTypeManagerImpl::StartNextDownload( void DataTypeManagerImpl::StartNextConfiguration(
ModelTypeSet high_priority_types_before) { ModelTypeSet higher_priority_types_before) {
if (download_types_queue_.empty()) if (configuration_types_queue_.empty())
return; return;
ModelTypeConfigurer::ConfigureParams config_params; ModelTypeConfigurer::ConfigureParams config_params;
ModelTypeSet ready_types = PrepareConfigureParams(&config_params); ModelTypeSet ready_types = PrepareConfigureParams(&config_params);
DCHECK(!association_types_info_);
association_types_info_ = AssociationTypesInfo();
association_types_info_->types = configuration_types_queue_.front();
association_types_info_->ready_types = ready_types;
association_types_info_->download_start_time = base::Time::Now();
association_types_info_->higher_priority_types_before =
higher_priority_types_before;
// Record stats for the types that are already downloaded. The remaining types
// will be handled once their download finishes (which happens as part of
// ConfigureDataTypes).
RecordConfigurationStats(ready_types);
// The engine's state was initially derived from the types detected to have // The engine's state was initially derived from the types detected to have
// been downloaded in the database. Afterwards it is modified only by this // been downloaded in the database. Afterwards it is modified only by this
// function. We expect |downloaded_types_| to remain consistent because // function. We expect |downloaded_types_| to remain consistent because
...@@ -522,19 +535,6 @@ void DataTypeManagerImpl::StartNextDownload( ...@@ -522,19 +535,6 @@ void DataTypeManagerImpl::StartNextDownload(
// through the DataTypeManager, and we are careful to never send a new // through the DataTypeManager, and we are careful to never send a new
// configure request until the current request succeeds. // configure request until the current request succeeds.
configurer_->ConfigureDataTypes(std::move(config_params)); configurer_->ConfigureDataTypes(std::move(config_params));
DCHECK(!association_types_info_);
association_types_info_ = AssociationTypesInfo();
association_types_info_->types = download_types_queue_.front();
association_types_info_->ready_types = ready_types;
association_types_info_->download_start_time = base::Time::Now();
association_types_info_->high_priority_types_before =
high_priority_types_before;
// Record stats for the types that are already downloaded. The remaining types
// will be handled once their download finishes (which happens as part of
// ConfigureDataTypes).
RecordConfigurationStats(ready_types);
} }
ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams(
...@@ -547,7 +547,7 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( ...@@ -547,7 +547,7 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams(
// - Everything else (enabled types and already disabled types) is not // - Everything else (enabled types and already disabled types) is not
// touched. // touched.
const DataTypeConfigStateMap config_state_map = const DataTypeConfigStateMap config_state_map =
BuildDataTypeConfigStateMap(download_types_queue_.front()); BuildDataTypeConfigStateMap(configuration_types_queue_.front());
const ModelTypeSet fatal_types = GetDataTypesInState(FATAL, config_state_map); const ModelTypeSet fatal_types = GetDataTypesInState(FATAL, config_state_map);
const ModelTypeSet crypto_types = const ModelTypeSet crypto_types =
GetDataTypesInState(CRYPTO, config_state_map); GetDataTypesInState(CRYPTO, config_state_map);
...@@ -628,9 +628,9 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams( ...@@ -628,9 +628,9 @@ ModelTypeSet DataTypeManagerImpl::PrepareConfigureParams(
params->enabled_types = enabled_types; params->enabled_types = enabled_types;
params->to_download = types_to_download; params->to_download = types_to_download;
params->to_purge = types_to_purge; params->to_purge = types_to_purge;
params->ready_task = base::BindOnce(&DataTypeManagerImpl::DownloadCompleted, params->ready_task = base::BindOnce(
weak_ptr_factory_.GetWeakPtr(), &DataTypeManagerImpl::ConfigurationCompleted,
download_types_queue_.front()); weak_ptr_factory_.GetWeakPtr(), configuration_types_queue_.front());
params->is_sync_feature_enabled = params->is_sync_feature_enabled =
last_requested_context_.sync_mode == SyncMode::kFull; last_requested_context_.sync_mode == SyncMode::kFull;
...@@ -700,7 +700,7 @@ void DataTypeManagerImpl::RecordConfigurationStatsImpl(ModelType type) { ...@@ -700,7 +700,7 @@ void DataTypeManagerImpl::RecordConfigurationStatsImpl(ModelType type) {
info.download_ready_time - info.download_start_time; info.download_ready_time - info.download_start_time;
} }
configuration_stats_[type].high_priority_types_configured_before = configuration_stats_[type].high_priority_types_configured_before =
info.high_priority_types_before; info.higher_priority_types_before;
configuration_stats_[type].same_priority_types_configured_before = configuration_stats_[type].same_priority_types_configured_before =
info.configured_types; info.configured_types;
info.configured_types.Put(type); info.configured_types.Put(type);
...@@ -733,7 +733,7 @@ void DataTypeManagerImpl::Abort(ConfigureStatus status) { ...@@ -733,7 +733,7 @@ void DataTypeManagerImpl::Abort(ConfigureStatus status) {
void DataTypeManagerImpl::StopImpl(ShutdownReason reason) { void DataTypeManagerImpl::StopImpl(ShutdownReason reason) {
state_ = STOPPING; state_ = STOPPING;
// Invalidate weak pointer to drop download callbacks. // Invalidate weak pointer to drop configuration callbacks.
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
// Stop all data types. // Stop all data types.
......
...@@ -111,7 +111,7 @@ class DataTypeManagerImpl : public DataTypeManager, ...@@ -111,7 +111,7 @@ class DataTypeManagerImpl : public DataTypeManager,
// was an actual change. // was an actual change.
bool UpdatePreconditionError(ModelType type); bool UpdatePreconditionError(ModelType type);
// Starts a reconfiguration if it's required and no downloads are running. // Starts a reconfiguration if it's required and no configuration is running.
void ProcessReconfigure(); void ProcessReconfigure();
// Programmatically force reconfiguration of all data types (if needed). // Programmatically force reconfiguration of all data types (if needed).
...@@ -119,10 +119,6 @@ class DataTypeManagerImpl : public DataTypeManager, ...@@ -119,10 +119,6 @@ class DataTypeManagerImpl : public DataTypeManager,
void Restart(); void Restart();
void DownloadCompleted(ModelTypeSet downloaded_types,
ModelTypeSet succeeded_configuration_types,
ModelTypeSet failed_configuration_types);
void NotifyStart(); void NotifyStart();
void NotifyDone(const ConfigureResult& result); void NotifyDone(const ConfigureResult& result);
...@@ -135,25 +131,26 @@ class DataTypeManagerImpl : public DataTypeManager, ...@@ -135,25 +131,26 @@ class DataTypeManagerImpl : public DataTypeManager,
DataTypeConfigStateMap BuildDataTypeConfigStateMap( DataTypeConfigStateMap BuildDataTypeConfigStateMap(
const ModelTypeSet& types_being_configured) const; const ModelTypeSet& types_being_configured) const;
// Start download of next set of types in |download_types_queue_| (if // Start configuration of next set of types in |configuration_types_queue_|
// any exist, does nothing otherwise). // (if any exist, does nothing otherwise).
// Will kick off configuration of any new ready types. void StartNextConfiguration(ModelTypeSet higher_priority_types_before);
void StartNextDownload(ModelTypeSet high_priority_types_before); void ConfigurationCompleted(ModelTypeSet configured_types,
ModelTypeSet succeeded_configuration_types,
ModelTypeSet failed_configuration_types);
void RecordConfigurationStats(ModelTypeSet types); void RecordConfigurationStats(ModelTypeSet types);
void RecordConfigurationStatsImpl(ModelType type); void RecordConfigurationStatsImpl(ModelType type);
void StopImpl(ShutdownReason reason); void StopImpl(ShutdownReason reason);
// Returns the currently enabled types.
ModelTypeSet GetEnabledTypes() const; ModelTypeSet GetEnabledTypes() const;
ModelTypeConfigurer* configurer_; ModelTypeConfigurer* const configurer_;
// Map of all data type controllers that are available for sync. // Map of all data type controllers that are available for sync.
// This list is determined at startup by various command line flags. // This list is determined at startup by various command line flags.
const DataTypeController::TypeMap* controllers_; const DataTypeController::TypeMap* const controllers_;
State state_; State state_;
// Types that requested in current configuration cycle. // Types that requested in current configuration cycle.
...@@ -196,8 +193,8 @@ class DataTypeManagerImpl : public DataTypeManager, ...@@ -196,8 +193,8 @@ class DataTypeManagerImpl : public DataTypeManager,
// configuring backend. // configuring backend.
DataTypeStatusTable data_type_status_table_; DataTypeStatusTable data_type_status_table_;
// Types waiting to be downloaded. // Types waiting to be configured, prioritized (highest priority first).
base::queue<ModelTypeSet> download_types_queue_; base::queue<ModelTypeSet> configuration_types_queue_;
// Pending types and related time tracking info. // Pending types and related time tracking info.
struct AssociationTypesInfo { struct AssociationTypesInfo {
...@@ -206,7 +203,7 @@ class DataTypeManagerImpl : public DataTypeManager, ...@@ -206,7 +203,7 @@ class DataTypeManagerImpl : public DataTypeManager,
~AssociationTypesInfo(); ~AssociationTypesInfo();
// Pending types. This is generally the same as // Pending types. This is generally the same as
// |download_types_queue_.front()|. // |configuration_types_queue_.front()|.
ModelTypeSet types; ModelTypeSet types;
// Types that have just been downloaded. This includes types that had // Types that have just been downloaded. This includes types that had
// previously encountered an error and had to be purged. // previously encountered an error and had to be purged.
...@@ -220,7 +217,7 @@ class DataTypeManagerImpl : public DataTypeManager, ...@@ -220,7 +217,7 @@ class DataTypeManagerImpl : public DataTypeManager,
base::Time download_ready_time; base::Time download_ready_time;
// The set of types that are higher priority, and were therefore blocking // The set of types that are higher priority, and were therefore blocking
// the download of |types|. // the download of |types|.
ModelTypeSet high_priority_types_before; ModelTypeSet higher_priority_types_before;
// The subset of |types| that were successfully configured. Populated // The subset of |types| that were successfully configured. Populated
// one-by-one as types finish configuring. // one-by-one as types finish configuring.
ModelTypeSet configured_types; ModelTypeSet configured_types;
......
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