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

Side by Side Diff: components/sync/engine_impl/model_type_worker.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_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
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_v2 { 31 namespace syncer {
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 syncer::UpdateHandler, 56 class ModelTypeWorker : public UpdateHandler,
57 public syncer::CommitContributor, 57 public CommitContributor,
58 public CommitQueue { 58 public CommitQueue {
59 public: 59 public:
60 ModelTypeWorker(syncer::ModelType type, 60 ModelTypeWorker(ModelType type,
61 const sync_pb::DataTypeState& initial_state, 61 const sync_pb::DataTypeState& initial_state,
62 std::unique_ptr<syncer::Cryptographer> cryptographer, 62 std::unique_ptr<Cryptographer> cryptographer,
63 syncer::NudgeHandler* nudge_handler, 63 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 syncer::ModelType GetModelType() const; 67 ModelType GetModelType() const;
68 68
69 void UpdateCryptographer( 69 void UpdateCryptographer(std::unique_ptr<Cryptographer> cryptographer);
70 std::unique_ptr<syncer::Cryptographer> cryptographer);
71 70
72 // UpdateHandler implementation. 71 // UpdateHandler implementation.
73 bool IsInitialSyncEnded() const override; 72 bool IsInitialSyncEnded() const override;
74 void GetDownloadProgress( 73 void GetDownloadProgress(
75 sync_pb::DataTypeProgressMarker* progress_marker) const override; 74 sync_pb::DataTypeProgressMarker* progress_marker) const override;
76 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override; 75 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override;
77 syncer::SyncerError ProcessGetUpdatesResponse( 76 SyncerError ProcessGetUpdatesResponse(
78 const sync_pb::DataTypeProgressMarker& progress_marker, 77 const sync_pb::DataTypeProgressMarker& progress_marker,
79 const sync_pb::DataTypeContext& mutated_context, 78 const sync_pb::DataTypeContext& mutated_context,
80 const SyncEntityList& applicable_updates, 79 const SyncEntityList& applicable_updates,
81 syncer::StatusController* status) override; 80 StatusController* status) override;
82 void ApplyUpdates(syncer::StatusController* status) override; 81 void ApplyUpdates(StatusController* status) override;
83 void PassiveApplyUpdates(syncer::StatusController* status) override; 82 void PassiveApplyUpdates(StatusController* status) override;
84 83
85 // CommitQueue implementation. 84 // CommitQueue implementation.
86 void EnqueueForCommit(const CommitRequestDataList& request_list) override; 85 void EnqueueForCommit(const CommitRequestDataList& request_list) override;
87 86
88 // CommitContributor implementation. 87 // CommitContributor implementation.
89 std::unique_ptr<syncer::CommitContribution> GetContribution( 88 std::unique_ptr<CommitContribution> GetContribution(
90 size_t max_entries) override; 89 size_t max_entries) override;
91 90
92 // Callback for when our contribution gets a response. 91 // Callback for when our contribution gets a response.
93 void OnCommitResponse(CommitResponseDataList* response_list); 92 void OnCommitResponse(CommitResponseDataList* response_list);
94 93
95 base::WeakPtr<ModelTypeWorker> AsWeakPtr(); 94 base::WeakPtr<ModelTypeWorker> AsWeakPtr();
96 95
97 private: 96 private:
98 using EntityMap = std::map<std::string, std::unique_ptr<WorkerEntityTracker>>; 97 using EntityMap = std::map<std::string, std::unique_ptr<WorkerEntityTracker>>;
99 98
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Returns the entity tracker for the given |tag_hash|, or nullptr. 135 // Returns the entity tracker for the given |tag_hash|, or nullptr.
137 WorkerEntityTracker* GetEntityTracker(const std::string& tag_hash); 136 WorkerEntityTracker* GetEntityTracker(const std::string& tag_hash);
138 137
139 // Creates an entity tracker in the map using the given |data| and returns a 138 // Creates an entity tracker in the map using the given |data| and returns a
140 // pointer to it. Requires that one doesn't exist for data.client_tag_hash. 139 // pointer to it. Requires that one doesn't exist for data.client_tag_hash.
141 WorkerEntityTracker* CreateEntityTracker(const EntityData& data); 140 WorkerEntityTracker* CreateEntityTracker(const EntityData& data);
142 141
143 // Gets the entity tracker for |data| or creates one if it doesn't exist. 142 // Gets the entity tracker for |data| or creates one if it doesn't exist.
144 WorkerEntityTracker* GetOrCreateEntityTracker(const EntityData& data); 143 WorkerEntityTracker* GetOrCreateEntityTracker(const EntityData& data);
145 144
146 syncer::ModelType type_; 145 ModelType type_;
147 146
148 // State that applies to the entire model type. 147 // State that applies to the entire model type.
149 sync_pb::DataTypeState data_type_state_; 148 sync_pb::DataTypeState data_type_state_;
150 149
151 // Pointer to the ModelTypeProcessor associated with this worker. Never null. 150 // Pointer to the ModelTypeProcessor associated with this worker. Never null.
152 std::unique_ptr<ModelTypeProcessor> model_type_processor_; 151 std::unique_ptr<ModelTypeProcessor> model_type_processor_;
153 152
154 // A private copy of the most recent cryptographer known to sync. 153 // A private copy of the most recent cryptographer known to sync.
155 // Initialized at construction time and updated with UpdateCryptographer(). 154 // Initialized at construction time and updated with UpdateCryptographer().
156 // NULL if encryption is not enabled for this type. 155 // NULL if encryption is not enabled for this type.
157 std::unique_ptr<syncer::Cryptographer> cryptographer_; 156 std::unique_ptr<Cryptographer> cryptographer_;
158 157
159 // Interface used to access and send nudges to the sync scheduler. Not owned. 158 // Interface used to access and send nudges to the sync scheduler. Not owned.
160 syncer::NudgeHandler* nudge_handler_; 159 NudgeHandler* nudge_handler_;
161 160
162 // A map of per-entity information, keyed by client_tag_hash. 161 // A map of per-entity information, keyed by client_tag_hash.
163 // 162 //
164 // When commits are pending, their information is stored here. This 163 // When commits are pending, their information is stored here. This
165 // information is dropped from memory when the commit succeeds or gets 164 // information is dropped from memory when the commit succeeds or gets
166 // cancelled. 165 // cancelled.
167 // 166 //
168 // This also stores some information related to received server state in 167 // This also stores some information related to received server state in
169 // order to implement reflection blocking and conflict detection. This 168 // order to implement reflection blocking and conflict detection. This
170 // information is kept in memory indefinitely. 169 // information is kept in memory indefinitely.
171 EntityMap entities_; 170 EntityMap entities_;
172 171
173 // Accumulates all the updates from a single GetUpdates cycle in memory so 172 // Accumulates all the updates from a single GetUpdates cycle in memory so
174 // they can all be sent to the processor at once. 173 // they can all be sent to the processor at once.
175 UpdateResponseDataList pending_updates_; 174 UpdateResponseDataList pending_updates_;
176 175
177 base::ThreadChecker thread_checker_; 176 base::ThreadChecker thread_checker_;
178 base::WeakPtrFactory<ModelTypeWorker> weak_ptr_factory_; 177 base::WeakPtrFactory<ModelTypeWorker> weak_ptr_factory_;
179 }; 178 };
180 179
181 } // namespace syncer_v2 180 } // namespace syncer
182 181
183 #endif // COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_WORKER_H_ 182 #endif // COMPONENTS_SYNC_ENGINE_IMPL_MODEL_TYPE_WORKER_H_
OLDNEW
« no previous file with comments | « components/sync/engine_impl/model_type_registry_unittest.cc ('k') | components/sync/engine_impl/model_type_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698