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; |
23 | 24 |
24 // Interface implemented by model types to receive updates from sync via the | 25 // Interface implemented by model types to receive updates from sync via the |
25 // SharedModelTypeProcessor. Provides a way for sync to update the data and | 26 // SharedModelTypeProcessor. Provides a way for sync to update the data and |
26 // metadata for entities, as well as the model type state. | 27 // metadata for entities, as well as the model type state. |
27 class SYNC_EXPORT ModelTypeService { | 28 class SYNC_EXPORT ModelTypeService { |
28 public: | 29 public: |
29 typedef base::Callback<void(syncer::SyncError, scoped_ptr<DataBatch>)> | 30 typedef base::Callback<void(syncer::SyncError, scoped_ptr<DataBatch>)> |
30 DataCallback; | 31 DataCallback; |
31 typedef std::vector<std::string> ClientTagList; | 32 typedef std::vector<std::string> ClientTagList; |
33 typedef base::Callback<scoped_ptr<ModelTypeChangeProcessor>( | |
34 syncer::ModelType, | |
35 ModelTypeService* service)> | |
36 ChangeProcessorFactory; | |
32 | 37 |
33 ModelTypeService(); | 38 ModelTypeService(const ChangeProcessorFactory& change_processor_factory, |
39 syncer::ModelType type); | |
34 | 40 |
35 virtual ~ModelTypeService(); | 41 virtual ~ModelTypeService(); |
36 | 42 |
37 // Creates an object used to communicate changes in the sync metadata to the | 43 // Creates an object used to communicate changes in the sync metadata to the |
38 // model type store. | 44 // model type store. |
39 virtual scoped_ptr<MetadataChangeList> CreateMetadataChangeList() = 0; | 45 virtual scoped_ptr<MetadataChangeList> CreateMetadataChangeList() = 0; |
40 | 46 |
41 // Perform the initial merge between local and sync data. This should only be | 47 // 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 | 48 // 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 | 49 // 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; | 77 virtual void GetAllData(DataCallback callback) = 0; |
72 | 78 |
73 // Get or generate a client tag for |entity_data|. | 79 // Get or generate a client tag for |entity_data|. |
74 virtual std::string GetClientTag(const EntityData& entity_data) = 0; | 80 virtual std::string GetClientTag(const EntityData& entity_data) = 0; |
75 | 81 |
76 // Overridable notification for when the processor is set. This is typically | 82 // Overridable notification for when the processor is set. This is typically |
77 // when the service should start loading metadata and then subsequently giving | 83 // when the service should start loading metadata and then subsequently giving |
78 // it to the processor. | 84 // it to the processor. |
79 virtual void OnChangeProcessorSet() = 0; | 85 virtual void OnChangeProcessorSet() = 0; |
80 | 86 |
87 // Model type for this service. | |
88 syncer::ModelType type() const; | |
maxbogue
2016/03/25 17:32:41
I think you can just remove this method entirely n
Gang Wu
2016/03/25 18:08:33
Done.
| |
89 | |
90 void clear_change_processor(); | |
91 | |
92 ModelTypeChangeProcessor* OnSyncStarting( | |
93 const ModelTypeChangeProcessor::StartCallback& callback); | |
94 | |
95 protected: | |
81 // TODO(skym): See crbug/547087, do we need all these accessors? | 96 // TODO(skym): See crbug/547087, do we need all these accessors? |
82 ModelTypeChangeProcessor* change_processor() const; | 97 ModelTypeChangeProcessor* change_processor() const; |
83 | 98 |
84 void set_change_processor( | 99 ModelTypeChangeProcessor* GetOrCreateChangeProcessor(); |
85 scoped_ptr<ModelTypeChangeProcessor> change_processor); | |
86 | |
87 void clear_change_processor(); | |
88 | 100 |
89 private: | 101 private: |
90 // Recieves ownership in set_change_processor(...). | |
91 scoped_ptr<ModelTypeChangeProcessor> change_processor_; | 102 scoped_ptr<ModelTypeChangeProcessor> change_processor_; |
103 | |
104 ChangeProcessorFactory change_processor_factory_; | |
105 | |
106 const syncer::ModelType type_; | |
92 }; | 107 }; |
93 | 108 |
94 } // namespace syncer_v2 | 109 } // namespace syncer_v2 |
95 | 110 |
96 #endif // SYNC_API_MODEL_TYPE_SERVICE_H_ | 111 #endif // SYNC_API_MODEL_TYPE_SERVICE_H_ |
OLD | NEW |