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

Side by Side Diff: sync/engine/commit_queue_impl.h

Issue 1325453003: [Sync] rename USS processor / worker interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 SYNC_ENGINE_MODEL_TYPE_SYNC_WORKER_IMPL_H_ 5 #ifndef SYNC_ENGINE_COMMIT_QUEUE_IMPL_H_
6 #define SYNC_ENGINE_MODEL_TYPE_SYNC_WORKER_IMPL_H_ 6 #define SYNC_ENGINE_COMMIT_QUEUE_IMPL_H_
7 7
8 #include "base/containers/scoped_ptr_map.h" 8 #include "base/containers/scoped_ptr_map.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/non_thread_safe.h" 11 #include "base/threading/non_thread_safe.h"
12 #include "sync/base/sync_export.h" 12 #include "sync/base/sync_export.h"
13 #include "sync/engine/commit_contributor.h" 13 #include "sync/engine/commit_contributor.h"
14 #include "sync/engine/model_type_sync_worker.h" 14 #include "sync/engine/commit_queue.h"
15 #include "sync/engine/nudge_handler.h" 15 #include "sync/engine/nudge_handler.h"
16 #include "sync/engine/update_handler.h" 16 #include "sync/engine/update_handler.h"
17 #include "sync/internal_api/public/base/model_type.h" 17 #include "sync/internal_api/public/base/model_type.h"
18 #include "sync/internal_api/public/non_blocking_sync_common.h" 18 #include "sync/internal_api/public/non_blocking_sync_common.h"
19 #include "sync/internal_api/public/sync_encryption_handler.h" 19 #include "sync/internal_api/public/sync_encryption_handler.h"
20 #include "sync/protocol/sync.pb.h" 20 #include "sync/protocol/sync.pb.h"
21 #include "sync/util/cryptographer.h" 21 #include "sync/util/cryptographer.h"
22 22
23 namespace base { 23 namespace base {
24 class SingleThreadTaskRunner; 24 class SingleThreadTaskRunner;
25 } 25 }
26 26
27 namespace syncer_v2 { 27 namespace syncer_v2 {
28 28
29 class ModelTypeSyncProxy; 29 class ModelTypeProcessor;
30 class EntityTracker; 30 class EntityTracker;
31 31
32 // A smart cache for sync types that use message passing (rather than 32 // A smart cache for sync types that use message passing (rather than
33 // transactions and the syncable::Directory) to communicate with the sync 33 // transactions and the syncable::Directory) to communicate with the sync
34 // thread. 34 // thread.
35 // 35 //
36 // When the non-blocking sync type wants to talk with the sync server, it will 36 // When the non-blocking sync type wants to talk with the sync server, it will
37 // send a message from its thread to this object on the sync thread. This 37 // send a message from its thread to this object on the sync thread. This
38 // object ensures the appropriate sync server communication gets scheduled and 38 // object ensures the appropriate sync server communication gets scheduled and
39 // executed. The response, if any, will be returned to the non-blocking sync 39 // executed. The response, if any, will be returned to the non-blocking sync
40 // type's thread eventually. 40 // type's thread eventually.
41 // 41 //
42 // This object also has a role to play in communications in the opposite 42 // This object also has a role to play in communications in the opposite
43 // direction. Sometimes the sync thread will receive changes from the sync 43 // direction. Sometimes the sync thread will receive changes from the sync
44 // server and deliver them here. This object will post this information back to 44 // server and deliver them here. This object will post this information back to
45 // the appropriate component on the model type's thread. 45 // the appropriate component on the model type's thread.
46 // 46 //
47 // This object does more than just pass along messages. It understands the sync 47 // This object does more than just pass along messages. It understands the sync
48 // protocol, and it can make decisions when it sees conflicting messages. For 48 // protocol, and it can make decisions when it sees conflicting messages. For
49 // example, if the sync server sends down an update for a sync entity that is 49 // example, if the sync server sends down an update for a sync entity that is
50 // currently pending for commit, this object will detect this condition and 50 // currently pending for commit, this object will detect this condition and
51 // cancel the pending commit. 51 // cancel the pending commit.
52 class SYNC_EXPORT ModelTypeSyncWorkerImpl : public syncer::UpdateHandler, 52 class SYNC_EXPORT CommitQueueImpl : public syncer::UpdateHandler,
stanisc 2015/08/29 00:10:00 Not the right name. This is ModelTypeWorker since
Gang Wu 2015/08/29 05:03:02 Done.
53 public syncer::CommitContributor, 53 public syncer::CommitContributor,
54 public ModelTypeSyncWorker, 54 public CommitQueue,
55 public base::NonThreadSafe { 55 public base::NonThreadSafe {
56 public: 56 public:
57 ModelTypeSyncWorkerImpl(syncer::ModelType type, 57 CommitQueueImpl(syncer::ModelType type,
58 const DataTypeState& initial_state, 58 const DataTypeState& initial_state,
59 const UpdateResponseDataList& saved_pending_updates, 59 const UpdateResponseDataList& saved_pending_updates,
60 scoped_ptr<syncer::Cryptographer> cryptographer, 60 scoped_ptr<syncer::Cryptographer> cryptographer,
61 syncer::NudgeHandler* nudge_handler, 61 syncer::NudgeHandler* nudge_handler,
62 scoped_ptr<ModelTypeSyncProxy> type_sync_proxy); 62 scoped_ptr<ModelTypeProcessor> type_sync_proxy);
63 ~ModelTypeSyncWorkerImpl() override; 63 ~CommitQueueImpl() override;
64 64
65 syncer::ModelType GetModelType() const; 65 syncer::ModelType GetModelType() const;
66 66
67 bool IsEncryptionRequired() const; 67 bool IsEncryptionRequired() const;
68 void UpdateCryptographer(scoped_ptr<syncer::Cryptographer> cryptographer); 68 void UpdateCryptographer(scoped_ptr<syncer::Cryptographer> cryptographer);
69 69
70 // UpdateHandler implementation. 70 // UpdateHandler implementation.
71 void GetDownloadProgress( 71 void GetDownloadProgress(
72 sync_pb::DataTypeProgressMarker* progress_marker) const override; 72 sync_pb::DataTypeProgressMarker* progress_marker) const override;
73 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override; 73 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override;
74 syncer::SyncerError ProcessGetUpdatesResponse( 74 syncer::SyncerError ProcessGetUpdatesResponse(
75 const sync_pb::DataTypeProgressMarker& progress_marker, 75 const sync_pb::DataTypeProgressMarker& progress_marker,
76 const sync_pb::DataTypeContext& mutated_context, 76 const sync_pb::DataTypeContext& mutated_context,
77 const SyncEntityList& applicable_updates, 77 const SyncEntityList& applicable_updates,
78 syncer::sessions::StatusController* status) override; 78 syncer::sessions::StatusController* status) override;
79 void ApplyUpdates(syncer::sessions::StatusController* status) override; 79 void ApplyUpdates(syncer::sessions::StatusController* status) override;
80 void PassiveApplyUpdates(syncer::sessions::StatusController* status) override; 80 void PassiveApplyUpdates(syncer::sessions::StatusController* status) override;
81 81
82 // ModelTypeSyncWorker implementation. 82 // CommitQueue implementation.
83 void EnqueueForCommit(const CommitRequestDataList& request_list) override; 83 void EnqueueForCommit(const CommitRequestDataList& request_list) override;
84 84
85 // CommitContributor implementation. 85 // CommitContributor implementation.
86 scoped_ptr<syncer::CommitContribution> GetContribution( 86 scoped_ptr<syncer::CommitContribution> GetContribution(
87 size_t max_entries) override; 87 size_t max_entries) override;
88 88
89 // Callback for when our contribution gets a response. 89 // Callback for when our contribution gets a response.
90 void OnCommitResponse(const CommitResponseDataList& response_list); 90 void OnCommitResponse(const CommitResponseDataList& response_list);
91 91
92 base::WeakPtr<ModelTypeSyncWorkerImpl> AsWeakPtr(); 92 base::WeakPtr<CommitQueueImpl> AsWeakPtr();
93 93
94 private: 94 private:
95 typedef base::ScopedPtrMap<std::string, scoped_ptr<EntityTracker>> EntityMap; 95 typedef base::ScopedPtrMap<std::string, scoped_ptr<EntityTracker>> EntityMap;
96 96
97 // Stores a single commit request in this object's internal state. 97 // Stores a single commit request in this object's internal state.
98 void StorePendingCommit(const CommitRequestData& request); 98 void StorePendingCommit(const CommitRequestData& request);
99 99
100 // Returns true if this type has successfully fetched all available updates 100 // Returns true if this type has successfully fetched all available updates
101 // from the server at least once. Our state may or may not be stale, but at 101 // from the server at least once. Our state may or may not be stale, but at
102 // least we know that it was valid at some point in the past. 102 // least we know that it was valid at some point in the past.
(...skipping 27 matching lines...) Expand all
130 // failure case is an attempt to be defensive against bad input. 130 // failure case is an attempt to be defensive against bad input.
131 static bool DecryptSpecifics(syncer::Cryptographer* cryptographer, 131 static bool DecryptSpecifics(syncer::Cryptographer* cryptographer,
132 const sync_pb::EntitySpecifics& in, 132 const sync_pb::EntitySpecifics& in,
133 sync_pb::EntitySpecifics* out); 133 sync_pb::EntitySpecifics* out);
134 134
135 syncer::ModelType type_; 135 syncer::ModelType type_;
136 136
137 // State that applies to the entire model type. 137 // State that applies to the entire model type.
138 DataTypeState data_type_state_; 138 DataTypeState data_type_state_;
139 139
140 // Pointer to the ModelTypeSyncProxy associated with this worker. 140 // Pointer to the ModelTypeProcessor associated with this worker.
141 // This is NULL when no proxy is connected.. 141 // This is NULL when no proxy is connected..
142 scoped_ptr<ModelTypeSyncProxy> type_sync_proxy_; 142 scoped_ptr<ModelTypeProcessor> type_sync_proxy_;
143 143
144 // A private copy of the most recent cryptographer known to sync. 144 // A private copy of the most recent cryptographer known to sync.
145 // Initialized at construction time and updated with UpdateCryptographer(). 145 // Initialized at construction time and updated with UpdateCryptographer().
146 // NULL if encryption is not enabled for this type. 146 // NULL if encryption is not enabled for this type.
147 scoped_ptr<syncer::Cryptographer> cryptographer_; 147 scoped_ptr<syncer::Cryptographer> cryptographer_;
148 148
149 // Interface used to access and send nudges to the sync scheduler. Not owned. 149 // Interface used to access and send nudges to the sync scheduler. Not owned.
150 syncer::NudgeHandler* nudge_handler_; 150 syncer::NudgeHandler* nudge_handler_;
151 151
152 // A map of per-entity information known to this object. 152 // A map of per-entity information known to this object.
153 // 153 //
154 // When commits are pending, their information is stored here. This 154 // When commits are pending, their information is stored here. This
155 // information is dropped from memory when the commit succeeds or gets 155 // information is dropped from memory when the commit succeeds or gets
156 // cancelled. 156 // cancelled.
157 // 157 //
158 // This also stores some information related to received server state in 158 // This also stores some information related to received server state in
159 // order to implement reflection blocking and conflict detection. This 159 // order to implement reflection blocking and conflict detection. This
160 // information is kept in memory indefinitely. With a bit more coordination 160 // information is kept in memory indefinitely. With a bit more coordination
161 // with the model thread, we could optimize this to reduce memory usage in 161 // with the model thread, we could optimize this to reduce memory usage in
162 // the steady state. 162 // the steady state.
163 EntityMap entities_; 163 EntityMap entities_;
164 164
165 base::WeakPtrFactory<ModelTypeSyncWorkerImpl> weak_ptr_factory_; 165 base::WeakPtrFactory<CommitQueueImpl> weak_ptr_factory_;
166 }; 166 };
167 167
168 } // namespace syncer 168 } // namespace syncer
169 169
170 #endif // SYNC_ENGINE_MODEL_TYPE_SYNC_WORKER_IMPL_H_ 170 #endif // SYNC_ENGINE_COMMIT_QUEUE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698