The current initialization sequence is:
1) the factory of the model runs:
processor_factory_callback =
base::BindRepeating(&ModelTypeChangeProcessor::Create, ...);
bridge_ = std::make_unique<ModelXYZSyncBridge>
(processor_factory_callback, ...);
2) the bridge runs:
processor_ = processor_factory_callback.Run(this, ...);
3) after all the initialization of the model is done, the bridge calls
processor_->ModelReadyToSync(...);
We propose the following sequence
1) the factory of the model runs
processor = ModelTypeChangeProcessor::Create(...);
bridge_ = std::make_unique<ModelXYZSyncBridge>
(std::move(processor), ...);
2) after all the initialization of the model is done, the bridge calls
processor_->ModelReadyToSync(this, ...);
This way, the API is safer and the state space of the processor is simpler as the processor simply cannot call the bridge before the model is ready.
The only caveat is that currently, the bridge resets the processor whenever sync gets disabled (using the provided repeated "factory" callback). We would need to introduce
virtual void ModelTypeChangeProcessor::Reset();
that resets the internal state of the processor (apart from the pointer to the bridge).
Comment 1 by mastiz@chromium.org
, Jan 31 2018