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 <memory> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "sync/api/conflict_resolution.h" | 13 #include "sync/api/conflict_resolution.h" |
14 #include "sync/api/entity_change.h" | 14 #include "sync/api/entity_change.h" |
15 #include "sync/api/entity_data.h" | 15 #include "sync/api/entity_data.h" |
16 #include "sync/api/model_type_change_processor.h" | 16 #include "sync/api/model_type_change_processor.h" |
17 #include "sync/api/sync_error.h" | 17 #include "sync/api/sync_error.h" |
18 #include "sync/base/sync_export.h" | 18 #include "sync/base/sync_export.h" |
19 #include "sync/internal_api/public/activation_context.h" | 19 #include "sync/internal_api/public/activation_context.h" |
20 | 20 |
21 namespace syncer_v2 { | 21 namespace syncer_v2 { |
22 | 22 |
23 class DataBatch; | 23 class DataBatch; |
24 class MetadataChangeList; | 24 class MetadataChangeList; |
25 | 25 |
26 // 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 |
27 // SharedModelTypeProcessor. Provides a way for sync to update the data and | 27 // SharedModelTypeProcessor. Provides a way for sync to update the data and |
28 // metadata for entities, as well as the model type state. | 28 // metadata for entities, as well as the model type state. |
29 class SYNC_EXPORT ModelTypeService { | 29 class SYNC_EXPORT ModelTypeService { |
30 public: | 30 public: |
31 typedef base::Callback<void(syncer::SyncError, scoped_ptr<DataBatch>)> | 31 typedef base::Callback<void(syncer::SyncError, std::unique_ptr<DataBatch>)> |
32 DataCallback; | 32 DataCallback; |
33 typedef std::vector<std::string> ClientTagList; | 33 typedef std::vector<std::string> ClientTagList; |
34 typedef base::Callback<scoped_ptr<ModelTypeChangeProcessor>( | 34 typedef base::Callback<std::unique_ptr<ModelTypeChangeProcessor>( |
35 syncer::ModelType type, | 35 syncer::ModelType type, |
36 ModelTypeService* service)> | 36 ModelTypeService* service)> |
37 ChangeProcessorFactory; | 37 ChangeProcessorFactory; |
38 | 38 |
39 ModelTypeService(const ChangeProcessorFactory& change_processor_factory, | 39 ModelTypeService(const ChangeProcessorFactory& change_processor_factory, |
40 syncer::ModelType type); | 40 syncer::ModelType type); |
41 | 41 |
42 virtual ~ModelTypeService(); | 42 virtual ~ModelTypeService(); |
43 | 43 |
44 // Creates an object used to communicate changes in the sync metadata to the | 44 // Creates an object used to communicate changes in the sync metadata to the |
45 // model type store. | 45 // model type store. |
46 virtual scoped_ptr<MetadataChangeList> CreateMetadataChangeList() = 0; | 46 virtual std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() = 0; |
47 | 47 |
48 // Perform the initial merge between local and sync data. This should only be | 48 // Perform the initial merge between local and sync data. This should only be |
49 // called when a data type is first enabled to start syncing, and there is no | 49 // called when a data type is first enabled to start syncing, and there is no |
50 // sync metadata. Best effort should be made to match local and sync data. The | 50 // sync metadata. Best effort should be made to match local and sync data. The |
51 // keys in the |entity_data_map| will have been created via GetClientTag(...), | 51 // keys in the |entity_data_map| will have been created via GetClientTag(...), |
52 // and if a local and sync data should match/merge but disagree on tags, the | 52 // and if a local and sync data should match/merge but disagree on tags, the |
53 // service should use the sync data's tag. Any local pieces of data that are | 53 // service should use the sync data's tag. Any local pieces of data that are |
54 // not present in sync should immediately be Put(...) to the processor before | 54 // not present in sync should immediately be Put(...) to the processor before |
55 // returning. The same MetadataChangeList that was passed into this function | 55 // returning. The same MetadataChangeList that was passed into this function |
56 // can be passed to Put(...) calls. Delete(...) can also be called but should | 56 // can be passed to Put(...) calls. Delete(...) can also be called but should |
57 // not be needed for most model types. Durable storage writes, if not able to | 57 // not be needed for most model types. Durable storage writes, if not able to |
58 // combine all change atomically, should save the metadata after the data | 58 // combine all change atomically, should save the metadata after the data |
59 // changes, so that this merge will be re-driven by sync if is not completely | 59 // changes, so that this merge will be re-driven by sync if is not completely |
60 // saved during the current run. | 60 // saved during the current run. |
61 virtual syncer::SyncError MergeSyncData( | 61 virtual syncer::SyncError MergeSyncData( |
62 scoped_ptr<MetadataChangeList> metadata_change_list, | 62 std::unique_ptr<MetadataChangeList> metadata_change_list, |
63 EntityDataMap entity_data_map) = 0; | 63 EntityDataMap entity_data_map) = 0; |
64 | 64 |
65 // Apply changes from the sync server locally. | 65 // Apply changes from the sync server locally. |
66 // Please note that |entity_changes| might have fewer entries than | 66 // Please note that |entity_changes| might have fewer entries than |
67 // |metadata_change_list| in case when some of the data changes are filtered | 67 // |metadata_change_list| in case when some of the data changes are filtered |
68 // out, or even be empty in case when a commit confirmation is processed and | 68 // out, or even be empty in case when a commit confirmation is processed and |
69 // only the metadata needs to persisted. | 69 // only the metadata needs to persisted. |
70 virtual syncer::SyncError ApplySyncChanges( | 70 virtual syncer::SyncError ApplySyncChanges( |
71 scoped_ptr<MetadataChangeList> metadata_change_list, | 71 std::unique_ptr<MetadataChangeList> metadata_change_list, |
72 EntityChangeList entity_changes) = 0; | 72 EntityChangeList entity_changes) = 0; |
73 | 73 |
74 // Asynchronously retrieve the corresponding sync data for |client_tags|. | 74 // Asynchronously retrieve the corresponding sync data for |client_tags|. |
75 virtual void GetData(ClientTagList client_tags, DataCallback callback) = 0; | 75 virtual void GetData(ClientTagList client_tags, DataCallback callback) = 0; |
76 | 76 |
77 // Asynchronously retrieve all of the local sync data. | 77 // Asynchronously retrieve all of the local sync data. |
78 virtual void GetAllData(DataCallback callback) = 0; | 78 virtual void GetAllData(DataCallback callback) = 0; |
79 | 79 |
80 // Get or generate a client tag for |entity_data|. | 80 // Get or generate a client tag for |entity_data|. |
81 virtual std::string GetClientTag(const EntityData& entity_data) = 0; | 81 virtual std::string GetClientTag(const EntityData& entity_data) = 0; |
(...skipping 17 matching lines...) Expand all Loading... |
99 protected: | 99 protected: |
100 // TODO(skym): See crbug/547087, do we need all these accessors? | 100 // TODO(skym): See crbug/547087, do we need all these accessors? |
101 ModelTypeChangeProcessor* change_processor() const; | 101 ModelTypeChangeProcessor* change_processor() const; |
102 | 102 |
103 ModelTypeChangeProcessor* GetOrCreateChangeProcessor(); | 103 ModelTypeChangeProcessor* GetOrCreateChangeProcessor(); |
104 | 104 |
105 // Model type for this service. | 105 // Model type for this service. |
106 syncer::ModelType type() const; | 106 syncer::ModelType type() const; |
107 | 107 |
108 private: | 108 private: |
109 scoped_ptr<ModelTypeChangeProcessor> change_processor_; | 109 std::unique_ptr<ModelTypeChangeProcessor> change_processor_; |
110 | 110 |
111 ChangeProcessorFactory change_processor_factory_; | 111 ChangeProcessorFactory change_processor_factory_; |
112 | 112 |
113 const syncer::ModelType type_; | 113 const syncer::ModelType type_; |
114 }; | 114 }; |
115 | 115 |
116 } // namespace syncer_v2 | 116 } // namespace syncer_v2 |
117 | 117 |
118 #endif // SYNC_API_MODEL_TYPE_SERVICE_H_ | 118 #endif // SYNC_API_MODEL_TYPE_SERVICE_H_ |
OLD | NEW |