OLD | NEW |
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_ENGINE_IMPL_MODEL_TYPE_WORKER_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_WORKER_H_ |
6 #define COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_WORKER_H_ | 6 #define COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_WORKER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "components/sync/engine_impl/commit_contributor.h" | 21 #include "components/sync/engine_impl/commit_contributor.h" |
22 #include "components/sync/engine_impl/nudge_handler.h" | 22 #include "components/sync/engine_impl/nudge_handler.h" |
23 #include "components/sync/engine_impl/update_handler.h" | 23 #include "components/sync/engine_impl/update_handler.h" |
24 #include "components/sync/protocol/data_type_state.pb.h" | 24 #include "components/sync/protocol/data_type_state.pb.h" |
25 #include "components/sync/protocol/sync.pb.h" | 25 #include "components/sync/protocol/sync.pb.h" |
26 | 26 |
27 namespace base { | 27 namespace base { |
28 class SingleThreadTaskRunner; | 28 class SingleThreadTaskRunner; |
29 } | 29 } |
30 | 30 |
31 namespace syncer { | 31 namespace syncer_v2 { |
32 | 32 |
33 class ModelTypeProcessor; | 33 class ModelTypeProcessor; |
34 class WorkerEntityTracker; | 34 class WorkerEntityTracker; |
35 | 35 |
36 // A smart cache for sync types that use message passing (rather than | 36 // A smart cache for sync types that use message passing (rather than |
37 // transactions and the syncable::Directory) to communicate with the sync | 37 // transactions and the syncable::Directory) to communicate with the sync |
38 // thread. | 38 // thread. |
39 // | 39 // |
40 // When the non-blocking sync type wants to talk with the sync server, it will | 40 // When the non-blocking sync type wants to talk with the sync server, it will |
41 // send a message from its thread to this object on the sync thread. This | 41 // send a message from its thread to this object on the sync thread. This |
42 // object ensures the appropriate sync server communication gets scheduled and | 42 // object ensures the appropriate sync server communication gets scheduled and |
43 // executed. The response, if any, will be returned to the non-blocking sync | 43 // executed. The response, if any, will be returned to the non-blocking sync |
44 // type's thread eventually. | 44 // type's thread eventually. |
45 // | 45 // |
46 // This object also has a role to play in communications in the opposite | 46 // This object also has a role to play in communications in the opposite |
47 // direction. Sometimes the sync thread will receive changes from the sync | 47 // direction. Sometimes the sync thread will receive changes from the sync |
48 // server and deliver them here. This object will post this information back to | 48 // server and deliver them here. This object will post this information back to |
49 // the appropriate component on the model type's thread. | 49 // the appropriate component on the model type's thread. |
50 // | 50 // |
51 // This object does more than just pass along messages. It understands the sync | 51 // This object does more than just pass along messages. It understands the sync |
52 // protocol, and it can make decisions when it sees conflicting messages. For | 52 // protocol, and it can make decisions when it sees conflicting messages. For |
53 // example, if the sync server sends down an update for a sync entity that is | 53 // example, if the sync server sends down an update for a sync entity that is |
54 // currently pending for commit, this object will detect this condition and | 54 // currently pending for commit, this object will detect this condition and |
55 // cancel the pending commit. | 55 // cancel the pending commit. |
56 class ModelTypeWorker : public UpdateHandler, | 56 class ModelTypeWorker : public syncer::UpdateHandler, |
57 public CommitContributor, | 57 public syncer::CommitContributor, |
58 public CommitQueue { | 58 public CommitQueue { |
59 public: | 59 public: |
60 ModelTypeWorker(ModelType type, | 60 ModelTypeWorker(syncer::ModelType type, |
61 const sync_pb::DataTypeState& initial_state, | 61 const sync_pb::DataTypeState& initial_state, |
62 std::unique_ptr<Cryptographer> cryptographer, | 62 std::unique_ptr<syncer::Cryptographer> cryptographer, |
63 NudgeHandler* nudge_handler, | 63 syncer::NudgeHandler* nudge_handler, |
64 std::unique_ptr<ModelTypeProcessor> model_type_processor); | 64 std::unique_ptr<ModelTypeProcessor> model_type_processor); |
65 ~ModelTypeWorker() override; | 65 ~ModelTypeWorker() override; |
66 | 66 |
67 ModelType GetModelType() const; | 67 syncer::ModelType GetModelType() const; |
68 | 68 |
69 void UpdateCryptographer(std::unique_ptr<Cryptographer> cryptographer); | 69 void UpdateCryptographer( |
| 70 std::unique_ptr<syncer::Cryptographer> cryptographer); |
70 | 71 |
71 // UpdateHandler implementation. | 72 // UpdateHandler implementation. |
72 bool IsInitialSyncEnded() const override; | 73 bool IsInitialSyncEnded() const override; |
73 void GetDownloadProgress( | 74 void GetDownloadProgress( |
74 sync_pb::DataTypeProgressMarker* progress_marker) const override; | 75 sync_pb::DataTypeProgressMarker* progress_marker) const override; |
75 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override; | 76 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override; |
76 SyncerError ProcessGetUpdatesResponse( | 77 syncer::SyncerError ProcessGetUpdatesResponse( |
77 const sync_pb::DataTypeProgressMarker& progress_marker, | 78 const sync_pb::DataTypeProgressMarker& progress_marker, |
78 const sync_pb::DataTypeContext& mutated_context, | 79 const sync_pb::DataTypeContext& mutated_context, |
79 const SyncEntityList& applicable_updates, | 80 const SyncEntityList& applicable_updates, |
80 StatusController* status) override; | 81 syncer::StatusController* status) override; |
81 void ApplyUpdates(StatusController* status) override; | 82 void ApplyUpdates(syncer::StatusController* status) override; |
82 void PassiveApplyUpdates(StatusController* status) override; | 83 void PassiveApplyUpdates(syncer::StatusController* status) override; |
83 | 84 |
84 // CommitQueue implementation. | 85 // CommitQueue implementation. |
85 void EnqueueForCommit(const CommitRequestDataList& request_list) override; | 86 void EnqueueForCommit(const CommitRequestDataList& request_list) override; |
86 | 87 |
87 // CommitContributor implementation. | 88 // CommitContributor implementation. |
88 std::unique_ptr<CommitContribution> GetContribution( | 89 std::unique_ptr<syncer::CommitContribution> GetContribution( |
89 size_t max_entries) override; | 90 size_t max_entries) override; |
90 | 91 |
91 // Callback for when our contribution gets a response. | 92 // Callback for when our contribution gets a response. |
92 void OnCommitResponse(CommitResponseDataList* response_list); | 93 void OnCommitResponse(CommitResponseDataList* response_list); |
93 | 94 |
94 base::WeakPtr<ModelTypeWorker> AsWeakPtr(); | 95 base::WeakPtr<ModelTypeWorker> AsWeakPtr(); |
95 | 96 |
96 private: | 97 private: |
97 using EntityMap = std::map<std::string, std::unique_ptr<WorkerEntityTracker>>; | 98 using EntityMap = std::map<std::string, std::unique_ptr<WorkerEntityTracker>>; |
98 | 99 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Returns the entity tracker for the given |tag_hash|, or nullptr. | 136 // Returns the entity tracker for the given |tag_hash|, or nullptr. |
136 WorkerEntityTracker* GetEntityTracker(const std::string& tag_hash); | 137 WorkerEntityTracker* GetEntityTracker(const std::string& tag_hash); |
137 | 138 |
138 // Creates an entity tracker in the map using the given |data| and returns a | 139 // Creates an entity tracker in the map using the given |data| and returns a |
139 // pointer to it. Requires that one doesn't exist for data.client_tag_hash. | 140 // pointer to it. Requires that one doesn't exist for data.client_tag_hash. |
140 WorkerEntityTracker* CreateEntityTracker(const EntityData& data); | 141 WorkerEntityTracker* CreateEntityTracker(const EntityData& data); |
141 | 142 |
142 // Gets the entity tracker for |data| or creates one if it doesn't exist. | 143 // Gets the entity tracker for |data| or creates one if it doesn't exist. |
143 WorkerEntityTracker* GetOrCreateEntityTracker(const EntityData& data); | 144 WorkerEntityTracker* GetOrCreateEntityTracker(const EntityData& data); |
144 | 145 |
145 ModelType type_; | 146 syncer::ModelType type_; |
146 | 147 |
147 // State that applies to the entire model type. | 148 // State that applies to the entire model type. |
148 sync_pb::DataTypeState data_type_state_; | 149 sync_pb::DataTypeState data_type_state_; |
149 | 150 |
150 // Pointer to the ModelTypeProcessor associated with this worker. Never null. | 151 // Pointer to the ModelTypeProcessor associated with this worker. Never null. |
151 std::unique_ptr<ModelTypeProcessor> model_type_processor_; | 152 std::unique_ptr<ModelTypeProcessor> model_type_processor_; |
152 | 153 |
153 // A private copy of the most recent cryptographer known to sync. | 154 // A private copy of the most recent cryptographer known to sync. |
154 // Initialized at construction time and updated with UpdateCryptographer(). | 155 // Initialized at construction time and updated with UpdateCryptographer(). |
155 // NULL if encryption is not enabled for this type. | 156 // NULL if encryption is not enabled for this type. |
156 std::unique_ptr<Cryptographer> cryptographer_; | 157 std::unique_ptr<syncer::Cryptographer> cryptographer_; |
157 | 158 |
158 // Interface used to access and send nudges to the sync scheduler. Not owned. | 159 // Interface used to access and send nudges to the sync scheduler. Not owned. |
159 NudgeHandler* nudge_handler_; | 160 syncer::NudgeHandler* nudge_handler_; |
160 | 161 |
161 // A map of per-entity information, keyed by client_tag_hash. | 162 // A map of per-entity information, keyed by client_tag_hash. |
162 // | 163 // |
163 // When commits are pending, their information is stored here. This | 164 // When commits are pending, their information is stored here. This |
164 // information is dropped from memory when the commit succeeds or gets | 165 // information is dropped from memory when the commit succeeds or gets |
165 // cancelled. | 166 // cancelled. |
166 // | 167 // |
167 // This also stores some information related to received server state in | 168 // This also stores some information related to received server state in |
168 // order to implement reflection blocking and conflict detection. This | 169 // order to implement reflection blocking and conflict detection. This |
169 // information is kept in memory indefinitely. | 170 // information is kept in memory indefinitely. |
170 EntityMap entities_; | 171 EntityMap entities_; |
171 | 172 |
172 // Accumulates all the updates from a single GetUpdates cycle in memory so | 173 // Accumulates all the updates from a single GetUpdates cycle in memory so |
173 // they can all be sent to the processor at once. | 174 // they can all be sent to the processor at once. |
174 UpdateResponseDataList pending_updates_; | 175 UpdateResponseDataList pending_updates_; |
175 | 176 |
176 base::ThreadChecker thread_checker_; | 177 base::ThreadChecker thread_checker_; |
177 base::WeakPtrFactory<ModelTypeWorker> weak_ptr_factory_; | 178 base::WeakPtrFactory<ModelTypeWorker> weak_ptr_factory_; |
178 }; | 179 }; |
179 | 180 |
180 } // namespace syncer | 181 } // namespace syncer_v2 |
181 | 182 |
182 #endif // COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_WORKER_H_ | 183 #endif // COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_WORKER_H_ |
OLD | NEW |