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

Side by Side Diff: chrome/browser/sync/engine/sync_cycle_state.h

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 //
6 // The sync process consists of a sequence of sync cycles, each of which
7 // (hopefully) moves the client into closer synchronization with the server.
8 // This class holds state that is pertinent to a single sync cycle.
9 //
10 // THIS CLASS PROVIDES NO SYNCHRONIZATION GUARANTEES.
11
12 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNC_CYCLE_STATE_H_
13 #define CHROME_BROWSER_SYNC_ENGINE_SYNC_CYCLE_STATE_H_
14
15 #include <utility>
16 #include <vector>
17
18 #include "base/basictypes.h"
19 #include "chrome/browser/sync/engine/syncer_types.h"
20 #include "chrome/browser/sync/engine/syncproto.h"
21 #include "chrome/browser/sync/util/event_sys.h"
22 #include "chrome/browser/sync/util/pthread_helpers.h"
23
24 namespace syncable {
25 class WriteTransaction;
26 class Id;
27 } // namespace syncable
28
29 namespace browser_sync {
30
31 typedef std::pair<VerifyResult, sync_pb::SyncEntity> VerifiedUpdate;
32 typedef std::pair<UpdateAttemptResponse, syncable::Id> AppliedUpdate;
33
34 // This is the type declaration for the eventsys channel that the syncer
35 // uses to send events to other system components.
36 struct SyncerEvent;
37
38 // SyncCycleState holds the entire state of a single sync cycle;
39 // GetUpdates, Commit, and Conflict Resolution. After said cycle, the
40 // State may contain items that were unable to be processed because of
41 // errors.
42 class SyncCycleState {
43 public:
44 SyncCycleState()
45 : write_transaction_(NULL),
46 conflict_sets_built_(false),
47 conflicts_resolved_(false),
48 items_committed_(false),
49 over_quota_(false),
50 dirty_(true),
51 timestamp_dirty_(false) {}
52
53 void set_update_response(const ClientToServerResponse& update_response) {
54 update_response_.CopyFrom(update_response);
55 }
56
57 const ClientToServerResponse& update_response() const {
58 return update_response_;
59 }
60
61 void set_commit_response(const ClientToServerResponse& commit_response) {
62 commit_response_.CopyFrom(commit_response);
63 }
64
65 const ClientToServerResponse& commit_response() const {
66 return commit_response_;
67 }
68
69 void AddVerifyResult(const VerifyResult& verify_result,
70 const sync_pb::SyncEntity& entity) {
71 verified_updates_.push_back(std::make_pair(verify_result, entity));
72 }
73
74 bool HasVerifiedUpdates() const {
75 return !verified_updates_.empty();
76 }
77
78 // Log a successful or failing update attempt.
79 void AddAppliedUpdate(const UpdateAttemptResponse& response,
80 const syncable::Id& id) {
81 applied_updates_.push_back(std::make_pair(response, id));
82 }
83
84 bool HasAppliedUpdates() const {
85 return !applied_updates_.empty();
86 }
87
88 std::vector<AppliedUpdate>::iterator AppliedUpdatesBegin() {
89 return applied_updates_.begin();
90 }
91
92 std::vector<VerifiedUpdate>::iterator VerifiedUpdatesBegin() {
93 return verified_updates_.begin();
94 }
95
96 std::vector<AppliedUpdate>::iterator AppliedUpdatesEnd() {
97 return applied_updates_.end();
98 }
99
100 std::vector<VerifiedUpdate>::iterator VerifiedUpdatesEnd() {
101 return verified_updates_.end();
102 }
103
104 // Returns the number of update application attempts. This includes
105 // both failures and successes.
106 int AppliedUpdatesSize() const {
107 return applied_updates_.size();
108 }
109
110 // Count the number of successful update applications that have happend
111 // this cycle. Note that if an item is successfully applied twice,
112 // it will be double counted here.
113 int SuccessfullyAppliedUpdateCount() const {
114 int count = 0;
115 for (std::vector<AppliedUpdate>::const_iterator it =
116 applied_updates_.begin();
117 it != applied_updates_.end();
118 ++it) {
119 if (it->first == SUCCESS)
120 count++;
121 }
122 return count;
123 }
124
125 int VerifiedUpdatesSize() const {
126 return verified_updates_.size();
127 }
128
129 const std::vector<int64>& unsynced_handles() const {
130 return unsynced_handles_;
131 }
132
133 void set_unsynced_handles(const std::vector<int64>& unsynced_handles) {
134 UpdateDirty(unsynced_handles != unsynced_handles_);
135 unsynced_handles_ = unsynced_handles;
136 }
137
138 int64 unsynced_count() const { return unsynced_handles_.size(); }
139
140 const std::vector<syncable::Id>& commit_ids() const { return commit_ids_; }
141
142 void set_commit_ids(const std::vector<syncable::Id>& commit_ids) {
143 commit_ids_ = commit_ids;
144 }
145
146 bool commit_ids_empty() const { return commit_ids_.empty(); }
147
148 // The write transaction must be deleted by the caller of this function.
149 void set_write_transaction(syncable::WriteTransaction* write_transaction) {
150 DCHECK(!write_transaction_) << "Forgot to clear the write transaction.";
151 write_transaction_ = write_transaction;
152 }
153
154 syncable::WriteTransaction* write_transaction() const {
155 return write_transaction_;
156 }
157
158 bool has_open_write_transaction() { return write_transaction_ != NULL; }
159
160 // sets the write transaction to null, but doesn't free the memory.
161 void ClearWriteTransaction() { write_transaction_ = NULL; }
162
163 ClientToServerMessage* commit_message() { return &commit_message_; }
164
165 void set_commit_message(ClientToServerMessage message) {
166 commit_message_ = message;
167 }
168
169 void set_conflict_sets_built(bool b) {
170 conflict_sets_built_ = b;
171 }
172
173 bool conflict_sets_built() const {
174 return conflict_sets_built_;
175 }
176
177 void set_conflicts_resolved(bool b) {
178 conflicts_resolved_ = b;
179 }
180
181 bool conflicts_resolved() const {
182 return conflicts_resolved_;
183 }
184
185 void set_over_quota(bool b) {
186 UpdateDirty(b != over_quota_);
187 over_quota_ = b;
188 }
189
190 bool over_quota() const {
191 return over_quota_;
192 }
193
194 void set_items_committed(bool b) { items_committed_ = b; }
195
196 void set_item_committed() { items_committed_ |= true; }
197
198 bool items_committed() const { return items_committed_; }
199
200
201 // Returns true if this object has been modified since last SetClean() call
202 bool IsDirty() const { return dirty_; }
203
204 // Call to tell this status object that its new state has been seen
205 void SetClean() { dirty_ = false; }
206
207 // Indicate that we've made a change to directory timestamp.
208 void set_timestamp_dirty() {
209 timestamp_dirty_ = true;
210 }
211
212 bool is_timestamp_dirty() const {
213 return timestamp_dirty_;
214 }
215
216
idana 2009/09/10 05:44:37 Extra blank line.
217 private:
218 void UpdateDirty(bool new_info) { dirty_ |= new_info; }
219
220 // download updates supplies:
221 ClientToServerResponse update_response_;
222 ClientToServerResponse commit_response_;
223 ClientToServerMessage commit_message_;
224
225 syncable::WriteTransaction* write_transaction_;
226 std::vector<int64> unsynced_handles_;
227 std::vector<syncable::Id> commit_ids_;
228
229 // At a certain point during the sync process we'll want to build the
230 // conflict sets. This variable tracks whether or not that has happened.
231 bool conflict_sets_built_;
232 bool conflicts_resolved_;
233 bool items_committed_;
234 bool over_quota_;
235
236 // If we've set the timestamp to a new value during this cycle.
237 bool timestamp_dirty_;
238
239 bool dirty_;
240
241 // some container for updates that failed verification
242 std::vector<VerifiedUpdate> verified_updates_;
243
244 // Stores the result of the various ApplyUpdate attempts we've made.
245 // May contain duplicate entries.
246 std::vector<AppliedUpdate> applied_updates_;
247
248 DISALLOW_COPY_AND_ASSIGN(SyncCycleState);
249 };
250
251 } // namespace browser_sync
252
253 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNC_CYCLE_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698