Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SYNC_API_MODEL_TYPE_SERVICE_H_ | 5 #ifndef SYNC_API_MODEL_TYPE_SERVICE_H_ |
| 6 #define SYNC_API_MODEL_TYPE_SERVICE_H_ | 6 #define SYNC_API_MODEL_TYPE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "sync/api/entity_change.h" | 13 #include "sync/api/entity_change.h" |
| 14 #include "sync/api/entity_data.h" | 14 #include "sync/api/entity_data.h" |
| 15 #include "sync/api/model_type_change_processor.h" | 15 #include "sync/api/model_type_change_processor.h" |
| 16 #include "sync/api/sync_error.h" | 16 #include "sync/api/sync_error.h" |
| 17 #include "sync/base/sync_export.h" | 17 #include "sync/base/sync_export.h" |
| 18 #include "sync/internal_api/public/activation_context.h" | |
| 18 | 19 |
| 19 namespace syncer_v2 { | 20 namespace syncer_v2 { |
| 20 | 21 |
| 21 class DataBatch; | 22 class DataBatch; |
| 22 class MetadataChangeList; | 23 class MetadataChangeList; |
| 24 class SharedModelTypeProcessor; | |
| 23 | 25 |
| 24 // Interface implemented by model types to receive updates from sync via the | 26 // Interface implemented by model types to receive updates from sync via the |
| 25 // SharedModelTypeProcessor. Provides a way for sync to update the data and | 27 // SharedModelTypeProcessor. Provides a way for sync to update the data and |
| 26 // metadata for entities, as well as the model type state. | 28 // metadata for entities, as well as the model type state. |
| 27 class SYNC_EXPORT ModelTypeService { | 29 class SYNC_EXPORT ModelTypeService { |
| 28 public: | 30 public: |
| 29 typedef base::Callback<void(syncer::SyncError, scoped_ptr<DataBatch>)> | 31 typedef base::Callback<void(syncer::SyncError, scoped_ptr<DataBatch>)> |
| 30 DataCallback; | 32 DataCallback; |
| 31 typedef std::vector<std::string> ClientTagList; | 33 typedef std::vector<std::string> ClientTagList; |
| 34 typedef base::Callback<scoped_ptr<ModelTypeChangeProcessor>( | |
| 35 syncer::ModelType, | |
|
skym
2016/03/22 15:56:26
Can you curry the model type before it gets to the
| |
| 36 ModelTypeService* service)> | |
| 37 SharedProcessorFactory; | |
|
skym
2016/03/22 15:56:26
I like that you named this callback XxFactory.
Gang Wu
2016/03/22 17:47:51
Done.
| |
| 38 typedef base::Callback<void(syncer::SyncError, scoped_ptr<ActivationContext>)> | |
| 39 StartCallback; | |
| 32 | 40 |
| 33 ModelTypeService(); | 41 ModelTypeService(const SharedProcessorFactory& shared_processor_factory); |
| 34 | 42 |
| 35 virtual ~ModelTypeService(); | 43 virtual ~ModelTypeService(); |
| 36 | 44 |
| 37 // Creates an object used to communicate changes in the sync metadata to the | 45 // Creates an object used to communicate changes in the sync metadata to the |
| 38 // model type store. | 46 // model type store. |
| 39 virtual scoped_ptr<MetadataChangeList> CreateMetadataChangeList() = 0; | 47 virtual scoped_ptr<MetadataChangeList> CreateMetadataChangeList() = 0; |
| 40 | 48 |
| 41 // Perform the initial merge between local and sync data. This should only be | 49 // Perform the initial merge between local and sync data. This should only be |
| 42 // called when a data type is first enabled to start syncing, and there is no | 50 // called when a data type is first enabled to start syncing, and there is no |
| 43 // sync metadata. Best effort should be made to match local and sync data. The | 51 // sync metadata. Best effort should be made to match local and sync data. The |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 71 virtual void GetAllData(DataCallback callback) = 0; | 79 virtual void GetAllData(DataCallback callback) = 0; |
| 72 | 80 |
| 73 // Get or generate a client tag for |entity_data|. | 81 // Get or generate a client tag for |entity_data|. |
| 74 virtual std::string GetClientTag(const EntityData& entity_data) = 0; | 82 virtual std::string GetClientTag(const EntityData& entity_data) = 0; |
| 75 | 83 |
| 76 // Overridable notification for when the processor is set. This is typically | 84 // Overridable notification for when the processor is set. This is typically |
| 77 // when the service should start loading metadata and then subsequently giving | 85 // when the service should start loading metadata and then subsequently giving |
| 78 // it to the processor. | 86 // it to the processor. |
| 79 virtual void OnChangeProcessorSet() = 0; | 87 virtual void OnChangeProcessorSet() = 0; |
| 80 | 88 |
| 89 // Model type for this service. | |
| 90 virtual syncer::ModelType type() const = 0; | |
|
skym
2016/03/22 15:56:26
I'm not convinced you need this.
| |
| 91 | |
| 81 // TODO(skym): See crbug/547087, do we need all these accessors? | 92 // TODO(skym): See crbug/547087, do we need all these accessors? |
| 82 ModelTypeChangeProcessor* change_processor() const; | 93 ModelTypeChangeProcessor* change_processor(); |
|
skym
2016/03/22 15:56:26
Why remove const?
Gang Wu
2016/03/22 17:47:51
Done.
| |
| 83 | |
| 84 void set_change_processor( | |
| 85 scoped_ptr<ModelTypeChangeProcessor> change_processor); | |
| 86 | 94 |
| 87 void clear_change_processor(); | 95 void clear_change_processor(); |
| 88 | 96 |
| 97 void OnSyncStarting(StartCallback callback); | |
|
skym
2016/03/22 15:56:26
Typically we pass around callbacks as const refs.
Gang Wu
2016/03/22 17:47:51
Done.
| |
| 98 | |
| 99 protected: | |
| 100 ModelTypeChangeProcessor* create_change_processor(); | |
| 101 | |
| 89 private: | 102 private: |
| 90 // Recieves ownership in set_change_processor(...). | |
| 91 scoped_ptr<ModelTypeChangeProcessor> change_processor_; | 103 scoped_ptr<ModelTypeChangeProcessor> change_processor_; |
| 104 | |
| 105 SharedProcessorFactory shared_processor_factory_; | |
| 92 }; | 106 }; |
| 93 | 107 |
| 94 } // namespace syncer_v2 | 108 } // namespace syncer_v2 |
| 95 | 109 |
| 96 #endif // SYNC_API_MODEL_TYPE_SERVICE_H_ | 110 #endif // SYNC_API_MODEL_TYPE_SERVICE_H_ |
| OLD | NEW |