diff options
Diffstat (limited to 'sync/api')
-rw-r--r-- | sync/api/model_type_change_processor.h | 10 | ||||
-rw-r--r-- | sync/api/model_type_service.cc | 31 | ||||
-rw-r--r-- | sync/api/model_type_service.h | 25 |
3 files changed, 55 insertions, 11 deletions
diff --git a/sync/api/model_type_change_processor.h b/sync/api/model_type_change_processor.h index 5578db7..91f7380 100644 --- a/sync/api/model_type_change_processor.h +++ b/sync/api/model_type_change_processor.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "sync/api/entity_data.h" #include "sync/base/sync_export.h" +#include "sync/internal_api/public/activation_context.h" namespace syncer { class SyncError; @@ -24,6 +25,9 @@ class MetadataChangeList; // changes. class SYNC_EXPORT ModelTypeChangeProcessor { public: + typedef base::Callback<void(syncer::SyncError, scoped_ptr<ActivationContext>)> + StartCallback; + ModelTypeChangeProcessor(); virtual ~ModelTypeChangeProcessor(); @@ -42,6 +46,12 @@ class SYNC_EXPORT ModelTypeChangeProcessor { // Accept the initial sync metadata loaded by the service. This should be // called as soon as the metadata is available to the service. virtual void OnMetadataLoaded(scoped_ptr<MetadataBatch> batch) = 0; + + // Called by the DataTypeController to gather additional information needed + // before a CommitQueue object can be created for this model type. Once the + // metadata has been loaded, the info is collected and given to |callback|. + // Once called, this can only be called again if sync is disconnected. + virtual void OnSyncStarting(const StartCallback& callback) = 0; }; } // namespace syncer_v2 diff --git a/sync/api/model_type_service.cc b/sync/api/model_type_service.cc index 87df14b..a8c7933 100644 --- a/sync/api/model_type_service.cc +++ b/sync/api/model_type_service.cc @@ -4,9 +4,14 @@ #include "sync/api/model_type_service.h" +#include "sync/api/model_type_change_processor.h" + namespace syncer_v2 { -ModelTypeService::ModelTypeService() {} +ModelTypeService::ModelTypeService( + const ChangeProcessorFactory& change_processor_factory, + syncer::ModelType type) + : change_processor_factory_(change_processor_factory), type_(type) {} ModelTypeService::~ModelTypeService() {} @@ -14,15 +19,29 @@ ModelTypeChangeProcessor* ModelTypeService::change_processor() const { return change_processor_.get(); } -void ModelTypeService::set_change_processor( - scoped_ptr<ModelTypeChangeProcessor> change_processor) { - DCHECK(!change_processor_); - change_processor_.swap(change_processor); - OnChangeProcessorSet(); +ModelTypeChangeProcessor* ModelTypeService::GetOrCreateChangeProcessor() { + if (!change_processor_) { + change_processor_ = change_processor_factory_.Run(type(), this); + DCHECK(change_processor_); + OnChangeProcessorSet(); + } + return change_processor_.get(); } void ModelTypeService::clear_change_processor() { change_processor_.reset(); } +ModelTypeChangeProcessor* ModelTypeService::OnSyncStarting( + const ModelTypeChangeProcessor::StartCallback& start_callback) { + ModelTypeChangeProcessor* processor = GetOrCreateChangeProcessor(); + DCHECK(processor); + processor->OnSyncStarting(start_callback); + return processor; +} + +syncer::ModelType ModelTypeService::type() const { + return type_; +} + } // namespace syncer_v2 diff --git a/sync/api/model_type_service.h b/sync/api/model_type_service.h index bba4211..59579ad 100644 --- a/sync/api/model_type_service.h +++ b/sync/api/model_type_service.h @@ -15,6 +15,7 @@ #include "sync/api/model_type_change_processor.h" #include "sync/api/sync_error.h" #include "sync/base/sync_export.h" +#include "sync/internal_api/public/activation_context.h" namespace syncer_v2 { @@ -29,8 +30,13 @@ class SYNC_EXPORT ModelTypeService { typedef base::Callback<void(syncer::SyncError, scoped_ptr<DataBatch>)> DataCallback; typedef std::vector<std::string> ClientTagList; + typedef base::Callback<scoped_ptr<ModelTypeChangeProcessor>( + syncer::ModelType, + ModelTypeService* service)> + ChangeProcessorFactory; - ModelTypeService(); + ModelTypeService(const ChangeProcessorFactory& change_processor_factory, + syncer::ModelType type); virtual ~ModelTypeService(); @@ -78,17 +84,26 @@ class SYNC_EXPORT ModelTypeService { // it to the processor. virtual void OnChangeProcessorSet() = 0; + void clear_change_processor(); + + ModelTypeChangeProcessor* OnSyncStarting( + const ModelTypeChangeProcessor::StartCallback& callback); + + protected: // TODO(skym): See crbug/547087, do we need all these accessors? ModelTypeChangeProcessor* change_processor() const; - void set_change_processor( - scoped_ptr<ModelTypeChangeProcessor> change_processor); + ModelTypeChangeProcessor* GetOrCreateChangeProcessor(); - void clear_change_processor(); + // Model type for this service. + syncer::ModelType type() const; private: - // Recieves ownership in set_change_processor(...). scoped_ptr<ModelTypeChangeProcessor> change_processor_; + + ChangeProcessorFactory change_processor_factory_; + + const syncer::ModelType type_; }; } // namespace syncer_v2 |