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

Side by Side Diff: components/sync/core/shared_model_type_processor.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_CORE_SHARED_MODEL_TYPE_PROCESSOR_H_ 5 #ifndef COMPONENTS_SYNC_CORE_SHARED_MODEL_TYPE_PROCESSOR_H_
6 #define COMPONENTS_SYNC_CORE_SHARED_MODEL_TYPE_PROCESSOR_H_ 6 #define COMPONENTS_SYNC_CORE_SHARED_MODEL_TYPE_PROCESSOR_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <unordered_set> 11 #include <unordered_set>
12 12
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "components/sync/api/data_batch.h" 15 #include "components/sync/api/data_batch.h"
16 #include "components/sync/api/data_type_error_handler.h" 16 #include "components/sync/api/data_type_error_handler.h"
17 #include "components/sync/api/metadata_batch.h" 17 #include "components/sync/api/metadata_batch.h"
18 #include "components/sync/api/metadata_change_list.h" 18 #include "components/sync/api/metadata_change_list.h"
19 #include "components/sync/api/model_type_change_processor.h" 19 #include "components/sync/api/model_type_change_processor.h"
20 #include "components/sync/api/model_type_service.h" 20 #include "components/sync/api/model_type_service.h"
21 #include "components/sync/api/sync_error.h" 21 #include "components/sync/api/sync_error.h"
22 #include "components/sync/base/model_type.h" 22 #include "components/sync/base/model_type.h"
23 #include "components/sync/core/model_type_processor.h" 23 #include "components/sync/core/model_type_processor.h"
24 #include "components/sync/core/non_blocking_sync_common.h" 24 #include "components/sync/core/non_blocking_sync_common.h"
25 #include "components/sync/protocol/data_type_state.pb.h" 25 #include "components/sync/protocol/data_type_state.pb.h"
26 #include "components/sync/protocol/sync.pb.h" 26 #include "components/sync/protocol/sync.pb.h"
27 27
28 namespace syncer_v2 { 28 namespace syncer {
29 struct ActivationContext; 29 struct ActivationContext;
30 class CommitQueue; 30 class CommitQueue;
31 class ProcessorEntityTracker; 31 class ProcessorEntityTracker;
32 32
33 // A sync component embedded on the synced type's thread that helps to handle 33 // A sync component embedded on the synced type's thread that helps to handle
34 // communication between sync and model type threads. 34 // communication between sync and model type threads.
35 class SharedModelTypeProcessor : public ModelTypeProcessor, 35 class SharedModelTypeProcessor : public ModelTypeProcessor,
36 public ModelTypeChangeProcessor, 36 public ModelTypeChangeProcessor,
37 base::NonThreadSafe { 37 base::NonThreadSafe {
38 public: 38 public:
39 SharedModelTypeProcessor(syncer::ModelType type, ModelTypeService* service); 39 SharedModelTypeProcessor(ModelType type, ModelTypeService* service);
40 ~SharedModelTypeProcessor() override; 40 ~SharedModelTypeProcessor() override;
41 41
42 // An easily bound function that constructs a SharedModelTypeProcessor. 42 // An easily bound function that constructs a SharedModelTypeProcessor.
43 static std::unique_ptr<ModelTypeChangeProcessor> CreateAsChangeProcessor( 43 static std::unique_ptr<ModelTypeChangeProcessor> CreateAsChangeProcessor(
44 syncer::ModelType type, 44 ModelType type,
45 ModelTypeService* service); 45 ModelTypeService* service);
46 46
47 // Whether the processor is allowing changes to its model type. If this is 47 // Whether the processor is allowing changes to its model type. If this is
48 // false, the service should not allow any changes to its data. 48 // false, the service should not allow any changes to its data.
49 bool IsAllowingChanges() const; 49 bool IsAllowingChanges() const;
50 50
51 // Returns true if the handshake with sync thread is complete. 51 // Returns true if the handshake with sync thread is complete.
52 bool IsConnected() const; 52 bool IsConnected() const;
53 53
54 // Returns a ListValue representing all nodes for data type |type| through 54 // Returns a ListValue representing all nodes for data type |type| through
55 // |callback| on this thread. 55 // |callback| on this thread.
56 // Used for populating nodes in Sync Node Browser of chrome://sync-internals. 56 // Used for populating nodes in Sync Node Browser of chrome://sync-internals.
57 // TODO(gangwu): GetAllNodes could be in a helper class. 57 // TODO(gangwu): GetAllNodes could be in a helper class.
58 void GetAllNodes( 58 void GetAllNodes(
59 const scoped_refptr<base::TaskRunner>& task_runner, 59 const scoped_refptr<base::TaskRunner>& task_runner,
60 const base::Callback<void(const syncer::ModelType type, 60 const base::Callback<void(const ModelType type,
61 std::unique_ptr<base::ListValue>)>& callback); 61 std::unique_ptr<base::ListValue>)>& callback);
62 62
63 // ModelTypeChangeProcessor implementation. 63 // ModelTypeChangeProcessor implementation.
64 void Put(const std::string& storage_key, 64 void Put(const std::string& storage_key,
65 std::unique_ptr<EntityData> entity_data, 65 std::unique_ptr<EntityData> entity_data,
66 MetadataChangeList* metadata_change_list) override; 66 MetadataChangeList* metadata_change_list) override;
67 void Delete(const std::string& storage_key, 67 void Delete(const std::string& storage_key,
68 MetadataChangeList* metadata_change_list) override; 68 MetadataChangeList* metadata_change_list) override;
69 void OnMetadataLoaded(syncer::SyncError error, 69 void OnMetadataLoaded(SyncError error,
70 std::unique_ptr<MetadataBatch> batch) override; 70 std::unique_ptr<MetadataBatch> batch) override;
71 void OnSyncStarting( 71 void OnSyncStarting(std::unique_ptr<DataTypeErrorHandler> error_handler,
72 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler, 72 const StartCallback& callback) override;
73 const StartCallback& callback) override;
74 void DisableSync() override; 73 void DisableSync() override;
75 syncer::SyncError CreateAndUploadError( 74 SyncError CreateAndUploadError(const tracked_objects::Location& location,
76 const tracked_objects::Location& location, 75 const std::string& message) override;
77 const std::string& message) override;
78 76
79 // ModelTypeProcessor implementation. 77 // ModelTypeProcessor implementation.
80 void ConnectSync(std::unique_ptr<CommitQueue> worker) override; 78 void ConnectSync(std::unique_ptr<CommitQueue> worker) override;
81 void DisconnectSync() override; 79 void DisconnectSync() override;
82 void OnCommitCompleted(const sync_pb::DataTypeState& type_state, 80 void OnCommitCompleted(const sync_pb::DataTypeState& type_state,
83 const CommitResponseDataList& response_list) override; 81 const CommitResponseDataList& response_list) override;
84 void OnUpdateReceived(const sync_pb::DataTypeState& type_state, 82 void OnUpdateReceived(const sync_pb::DataTypeState& type_state,
85 const UpdateResponseDataList& updates) override; 83 const UpdateResponseDataList& updates) override;
86 84
87 private: 85 private:
(...skipping 19 matching lines...) Expand all
107 105
108 // Recommit all entities for encryption except those in |already_updated|. 106 // Recommit all entities for encryption except those in |already_updated|.
109 void RecommitAllForEncryption(std::unordered_set<std::string> already_updated, 107 void RecommitAllForEncryption(std::unordered_set<std::string> already_updated,
110 MetadataChangeList* metadata_changes); 108 MetadataChangeList* metadata_changes);
111 109
112 // Handle the first update received from the server after being enabled. 110 // Handle the first update received from the server after being enabled.
113 void OnInitialUpdateReceived(const sync_pb::DataTypeState& type_state, 111 void OnInitialUpdateReceived(const sync_pb::DataTypeState& type_state,
114 const UpdateResponseDataList& updates); 112 const UpdateResponseDataList& updates);
115 113
116 // ModelTypeService::GetData() callback for initial pending commit data. 114 // ModelTypeService::GetData() callback for initial pending commit data.
117 void OnInitialPendingDataLoaded(syncer::SyncError error, 115 void OnInitialPendingDataLoaded(SyncError error,
118 std::unique_ptr<DataBatch> data_batch); 116 std::unique_ptr<DataBatch> data_batch);
119 117
120 // ModelTypeService::GetData() callback for re-encryption commit data. 118 // ModelTypeService::GetData() callback for re-encryption commit data.
121 void OnDataLoadedForReEncryption(syncer::SyncError error, 119 void OnDataLoadedForReEncryption(SyncError error,
122 std::unique_ptr<DataBatch> data_batch); 120 std::unique_ptr<DataBatch> data_batch);
123 121
124 // Caches EntityData from the |data_batch| in the entity trackers. 122 // Caches EntityData from the |data_batch| in the entity trackers.
125 void ConsumeDataBatch(std::unique_ptr<DataBatch> data_batch); 123 void ConsumeDataBatch(std::unique_ptr<DataBatch> data_batch);
126 124
127 // Sends all commit requests that are due to be sent to the sync thread. 125 // Sends all commit requests that are due to be sent to the sync thread.
128 void FlushPendingCommitRequests(); 126 void FlushPendingCommitRequests();
129 127
130 // Computes the client tag hash for the given client |tag|. 128 // Computes the client tag hash for the given client |tag|.
131 std::string GetHashForTag(const std::string& tag); 129 std::string GetHashForTag(const std::string& tag);
(...skipping 17 matching lines...) Expand all
149 ProcessorEntityTracker* CreateEntity(const std::string& storage_key, 147 ProcessorEntityTracker* CreateEntity(const std::string& storage_key,
150 const EntityData& data); 148 const EntityData& data);
151 149
152 // Version of the above that generates a tag for |data|. 150 // Version of the above that generates a tag for |data|.
153 ProcessorEntityTracker* CreateEntity(const EntityData& data); 151 ProcessorEntityTracker* CreateEntity(const EntityData& data);
154 152
155 // This is callback function for ModelTypeService::GetAllData. This function 153 // This is callback function for ModelTypeService::GetAllData. This function
156 // will merge real data |batch| with metadata, then pass to |callback|. 154 // will merge real data |batch| with metadata, then pass to |callback|.
157 void MergeDataWithMetadata( 155 void MergeDataWithMetadata(
158 const scoped_refptr<base::TaskRunner>& task_runner, 156 const scoped_refptr<base::TaskRunner>& task_runner,
159 const base::Callback<void(const syncer::ModelType, 157 const base::Callback<void(const ModelType,
160 std::unique_ptr<base::ListValue>)>& callback, 158 std::unique_ptr<base::ListValue>)>& callback,
161 syncer::SyncError error, 159 SyncError error,
162 std::unique_ptr<DataBatch> batch); 160 std::unique_ptr<DataBatch> batch);
163 161
164 const syncer::ModelType type_; 162 const ModelType type_;
165 sync_pb::DataTypeState data_type_state_; 163 sync_pb::DataTypeState data_type_state_;
166 164
167 // Stores the start callback in between OnSyncStarting() and ReadyToConnect(). 165 // Stores the start callback in between OnSyncStarting() and ReadyToConnect().
168 StartCallback start_callback_; 166 StartCallback start_callback_;
169 167
170 // A cache for any error that may occur during startup and should be passed 168 // A cache for any error that may occur during startup and should be passed
171 // into the |start_callback_|. 169 // into the |start_callback_|.
172 syncer::SyncError start_error_; 170 SyncError start_error_;
173 171
174 // Indicates whether the metadata has finished loading. 172 // Indicates whether the metadata has finished loading.
175 bool is_metadata_loaded_; 173 bool is_metadata_loaded_;
176 174
177 // Indicates whether data for any initial pending commits has been loaded. 175 // Indicates whether data for any initial pending commits has been loaded.
178 bool is_initial_pending_data_loaded_; 176 bool is_initial_pending_data_loaded_;
179 177
180 // Reference to the CommitQueue. 178 // Reference to the CommitQueue.
181 // 179 //
182 // The interface hides the posting of tasks across threads as well as the 180 // The interface hides the posting of tasks across threads as well as the
(...skipping 12 matching lines...) Expand all
195 // client tag hash. The other direction can use |entities_|. 193 // client tag hash. The other direction can use |entities_|.
196 std::map<std::string, std::string> storage_key_to_tag_hash_; 194 std::map<std::string, std::string> storage_key_to_tag_hash_;
197 195
198 // ModelTypeService linked to this processor. 196 // ModelTypeService linked to this processor.
199 // The service owns this processor instance so the pointer should never 197 // The service owns this processor instance so the pointer should never
200 // become invalid. 198 // become invalid.
201 ModelTypeService* const service_; 199 ModelTypeService* const service_;
202 200
203 // The object used for informing sync of errors; will be non-null after 201 // The object used for informing sync of errors; will be non-null after
204 // OnSyncStarting has been called. This pointer is not owned. 202 // OnSyncStarting has been called. This pointer is not owned.
205 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler_; 203 std::unique_ptr<DataTypeErrorHandler> error_handler_;
206 204
207 // WeakPtrFactory for this processor which will be sent to sync thread. 205 // WeakPtrFactory for this processor which will be sent to sync thread.
208 base::WeakPtrFactory<SharedModelTypeProcessor> weak_ptr_factory_; 206 base::WeakPtrFactory<SharedModelTypeProcessor> weak_ptr_factory_;
209 }; 207 };
210 208
211 } // namespace syncer_v2 209 } // namespace syncer
212 210
213 #endif // COMPONENTS_SYNC_CORE_SHARED_MODEL_TYPE_PROCESSOR_H_ 211 #endif // COMPONENTS_SYNC_CORE_SHARED_MODEL_TYPE_PROCESSOR_H_
OLDNEW
« no previous file with comments | « components/sync/core/processor_entity_tracker_unittest.cc ('k') | components/sync/core/shared_model_type_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698