Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: components/sync/api/model_type_service.h

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 COMPONENTS_SYNC_API_MODEL_TYPE_SERVICE_H_ 5 #ifndef COMPONENTS_SYNC_API_MODEL_TYPE_SERVICE_H_
6 #define COMPONENTS_SYNC_API_MODEL_TYPE_SERVICE_H_ 6 #define COMPONENTS_SYNC_API_MODEL_TYPE_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "components/sync/api/conflict_resolution.h" 14 #include "components/sync/api/conflict_resolution.h"
15 #include "components/sync/api/data_type_error_handler.h" 15 #include "components/sync/api/data_type_error_handler.h"
16 #include "components/sync/api/entity_change.h" 16 #include "components/sync/api/entity_change.h"
17 #include "components/sync/api/entity_data.h" 17 #include "components/sync/api/entity_data.h"
18 #include "components/sync/api/model_type_change_processor.h" 18 #include "components/sync/api/model_type_change_processor.h"
19 #include "components/sync/api/sync_error.h" 19 #include "components/sync/api/sync_error.h"
20 #include "components/sync/core/activation_context.h" 20 #include "components/sync/core/activation_context.h"
21 21
22 namespace syncer_v2 { 22 namespace syncer {
23 23
24 class DataBatch; 24 class DataBatch;
25 class MetadataChangeList; 25 class MetadataChangeList;
26 26
27 // Interface implemented by model types to receive updates from sync via the 27 // Interface implemented by model types to receive updates from sync via the
28 // SharedModelTypeProcessor. Provides a way for sync to update the data and 28 // SharedModelTypeProcessor. Provides a way for sync to update the data and
29 // metadata for entities, as well as the model type state. 29 // metadata for entities, as well as the model type state.
30 class ModelTypeService : public base::SupportsWeakPtr<ModelTypeService> { 30 class ModelTypeService : public base::SupportsWeakPtr<ModelTypeService> {
31 public: 31 public:
32 typedef base::Callback<void(syncer::SyncError, std::unique_ptr<DataBatch>)> 32 typedef base::Callback<void(SyncError, std::unique_ptr<DataBatch>)>
33 DataCallback; 33 DataCallback;
34 typedef std::vector<std::string> StorageKeyList; 34 typedef std::vector<std::string> StorageKeyList;
35 typedef base::Callback<std::unique_ptr<ModelTypeChangeProcessor>( 35 typedef base::Callback<std::unique_ptr<ModelTypeChangeProcessor>(
36 syncer::ModelType type, 36 ModelType type,
37 ModelTypeService* service)> 37 ModelTypeService* service)>
38 ChangeProcessorFactory; 38 ChangeProcessorFactory;
39 39
40 ModelTypeService(const ChangeProcessorFactory& change_processor_factory, 40 ModelTypeService(const ChangeProcessorFactory& change_processor_factory,
41 syncer::ModelType type); 41 ModelType type);
42 42
43 virtual ~ModelTypeService(); 43 virtual ~ModelTypeService();
44 44
45 // 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
46 // model type store. 46 // model type store.
47 virtual std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() = 0; 47 virtual std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() = 0;
48 48
49 // 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
50 // 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
51 // 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
52 // keys in the |entity_data_map| will have been created via GetClientTag(...), 52 // keys in the |entity_data_map| will have been created via GetClientTag(...),
53 // and if a local and sync data should match/merge but disagree on tags, the 53 // and if a local and sync data should match/merge but disagree on tags, the
54 // service should use the sync data's tag. Any local pieces of data that are 54 // service should use the sync data's tag. Any local pieces of data that are
55 // not present in sync should immediately be Put(...) to the processor before 55 // not present in sync should immediately be Put(...) to the processor before
56 // returning. The same MetadataChangeList that was passed into this function 56 // returning. The same MetadataChangeList that was passed into this function
57 // can be passed to Put(...) calls. Delete(...) can also be called but should 57 // can be passed to Put(...) calls. Delete(...) can also be called but should
58 // not be needed for most model types. Durable storage writes, if not able to 58 // not be needed for most model types. Durable storage writes, if not able to
59 // combine all change atomically, should save the metadata after the data 59 // combine all change atomically, should save the metadata after the data
60 // changes, so that this merge will be re-driven by sync if is not completely 60 // changes, so that this merge will be re-driven by sync if is not completely
61 // saved during the current run. 61 // saved during the current run.
62 virtual syncer::SyncError MergeSyncData( 62 virtual SyncError MergeSyncData(
63 std::unique_ptr<MetadataChangeList> metadata_change_list, 63 std::unique_ptr<MetadataChangeList> metadata_change_list,
64 EntityDataMap entity_data_map) = 0; 64 EntityDataMap entity_data_map) = 0;
65 65
66 // Apply changes from the sync server locally. 66 // Apply changes from the sync server locally.
67 // Please note that |entity_changes| might have fewer entries than 67 // Please note that |entity_changes| might have fewer entries than
68 // |metadata_change_list| in case when some of the data changes are filtered 68 // |metadata_change_list| in case when some of the data changes are filtered
69 // out, or even be empty in case when a commit confirmation is processed and 69 // out, or even be empty in case when a commit confirmation is processed and
70 // only the metadata needs to persisted. 70 // only the metadata needs to persisted.
71 virtual syncer::SyncError ApplySyncChanges( 71 virtual SyncError ApplySyncChanges(
72 std::unique_ptr<MetadataChangeList> metadata_change_list, 72 std::unique_ptr<MetadataChangeList> metadata_change_list,
73 EntityChangeList entity_changes) = 0; 73 EntityChangeList entity_changes) = 0;
74 74
75 // Asynchronously retrieve the corresponding sync data for |storage_keys|. 75 // Asynchronously retrieve the corresponding sync data for |storage_keys|.
76 virtual void GetData(StorageKeyList storage_keys, DataCallback callback) = 0; 76 virtual void GetData(StorageKeyList storage_keys, DataCallback callback) = 0;
77 77
78 // Asynchronously retrieve all of the local sync data. 78 // Asynchronously retrieve all of the local sync data.
79 virtual void GetAllData(DataCallback callback) = 0; 79 virtual void GetAllData(DataCallback callback) = 0;
80 80
81 // Get or generate a client tag for |entity_data|. This must be the same tag 81 // Get or generate a client tag for |entity_data|. This must be the same tag
(...skipping 21 matching lines...) Expand all
103 // Resolve a conflict between the client and server versions of data. They are 103 // Resolve a conflict between the client and server versions of data. They are
104 // guaranteed not to match (both be deleted or have identical specifics). A 104 // guaranteed not to match (both be deleted or have identical specifics). A
105 // default implementation chooses the server data unless it is a deletion. 105 // default implementation chooses the server data unless it is a deletion.
106 virtual ConflictResolution ResolveConflict( 106 virtual ConflictResolution ResolveConflict(
107 const EntityData& local_data, 107 const EntityData& local_data,
108 const EntityData& remote_data) const; 108 const EntityData& remote_data) const;
109 109
110 // Called by the DataTypeController to gather additional information needed 110 // Called by the DataTypeController to gather additional information needed
111 // before the processor can be connected to a sync worker. Once the 111 // before the processor can be connected to a sync worker. Once the
112 // metadata has been loaded, the info is collected and given to |callback|. 112 // metadata has been loaded, the info is collected and given to |callback|.
113 void OnSyncStarting( 113 void OnSyncStarting(std::unique_ptr<DataTypeErrorHandler> error_handler,
114 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler, 114 const ModelTypeChangeProcessor::StartCallback& callback);
115 const ModelTypeChangeProcessor::StartCallback& callback);
116 115
117 // Indicates that we no longer want to do any sync-related things for this 116 // Indicates that we no longer want to do any sync-related things for this
118 // data type. Severs all ties to the sync thread, deletes all local sync 117 // data type. Severs all ties to the sync thread, deletes all local sync
119 // metadata, and then destroys the change processor. 118 // metadata, and then destroys the change processor.
120 // TODO(crbug.com/584365): This needs to be called from DataTypeController. 119 // TODO(crbug.com/584365): This needs to be called from DataTypeController.
121 void DisableSync(); 120 void DisableSync();
122 121
123 ModelTypeChangeProcessor* change_processor() const; 122 ModelTypeChangeProcessor* change_processor() const;
124 123
125 protected: 124 protected:
126 void CreateChangeProcessor(); 125 void CreateChangeProcessor();
127 126
128 void clear_change_processor(); 127 void clear_change_processor();
129 128
130 private: 129 private:
131 std::unique_ptr<ModelTypeChangeProcessor> change_processor_; 130 std::unique_ptr<ModelTypeChangeProcessor> change_processor_;
132 131
133 ChangeProcessorFactory change_processor_factory_; 132 ChangeProcessorFactory change_processor_factory_;
134 133
135 const syncer::ModelType type_; 134 const ModelType type_;
136 }; 135 };
137 136
138 } // namespace syncer_v2 137 } // namespace syncer
139 138
140 #endif // COMPONENTS_SYNC_API_MODEL_TYPE_SERVICE_H_ 139 #endif // COMPONENTS_SYNC_API_MODEL_TYPE_SERVICE_H_
OLDNEW
« no previous file with comments | « components/sync/api/model_type_change_processor.cc ('k') | components/sync/api/model_type_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698