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

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

Issue 386030: Relieve SyncerSession,SyncCycleState, SyncProcessState, SyncerSession, Syncer... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
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 // The sync process consists of a sequence of sync cycles, each of which
6 // (hopefully) moves the client into closer synchronization with the server.
7 // While SyncCycleState holds state that is pertinent to a single sync cycle,
8 // this data structure holds state that must be passed from cycle to cycle.
9 //
10 // THIS CLASS PROVIDES NO SYNCHRONIZATION GUARANTEES.
11
12 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNC_PROCESS_STATE_H_
13 #define CHROME_BROWSER_SYNC_ENGINE_SYNC_PROCESS_STATE_H_
14
15 #include <map>
16 #include <set>
17 #include <string>
18 #include <utility> // for pair<>
19
20 #include "base/atomicops.h"
21 #include "base/basictypes.h"
22 #include "base/port.h"
23 #include "base/time.h"
24 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
25 #include "chrome/browser/sync/engine/syncer_types.h"
26 #include "chrome/browser/sync/syncable/syncable_id.h"
27 #include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST
28
29 namespace browser_sync {
30
31 class ConflictResolver;
32 class ModelSafeWorker;
33
34 class SyncProcessState {
35 FRIEND_TEST(SyncerSyncProcessState, MergeSetsTest);
36 FRIEND_TEST(SyncerTest, CopySyncProcessState);
37 public:
38 ~SyncProcessState();
39 SyncProcessState(
40 syncable::DirectoryManager* dirman,
41 std::string account_name,
42 ServerConnectionManager* connection_manager,
43 ConflictResolver* const resolver,
44 SyncerEventChannel* syncer_event_channel,
45 ModelSafeWorker* model_safe_worker);
46
47 // Intentionally not 'explicit' b/c it's a copy ctor:
48 SyncProcessState(const SyncProcessState& counts);
49 SyncProcessState& operator=(const SyncProcessState& that);
50
51 std::string account_name() const { return account_name_; }
52
53 syncable::DirectoryManager* dirman() const { return dirman_; }
54
55 ServerConnectionManager* connection_manager() const {
56 return connection_manager_;
57 }
58
59 ConflictResolver* resolver() const { return resolver_; }
60
61 ModelSafeWorker* model_safe_worker() { return model_safe_worker_; }
62
63 SyncerEventChannel* syncer_event_channel() const {
64 return syncer_event_channel_;
65 }
66
67 // Functions that deal with conflict set stuff.
68 IdToConflictSetMap::const_iterator IdToConflictSetFind(
69 const syncable::Id& the_id) const {
70 return id_to_conflict_set_.find(the_id);
71 }
72
73 IdToConflictSetMap::const_iterator IdToConflictSetBegin() const {
74 return id_to_conflict_set_.begin();
75 }
76
77 IdToConflictSetMap::const_iterator IdToConflictSetEnd() const {
78 return id_to_conflict_set_.end();
79 }
80
81 IdToConflictSetMap::size_type IdToConflictSetSize() const {
82 return id_to_conflict_set_.size();
83 }
84
85 const ConflictSet* IdToConflictSetGet(const syncable::Id& the_id) {
86 return id_to_conflict_set_[the_id];
87 }
88
89 std::set<ConflictSet*>::const_iterator ConflictSetsBegin() const {
90 return conflict_sets_.begin();
91 }
92
93 std::set<ConflictSet*>::const_iterator ConflictSetsEnd() const {
94 return conflict_sets_.end();
95 }
96
97 std::set<ConflictSet*>::size_type ConflictSetsSize() const {
98 return conflict_sets_.size();
99 }
100
101 void MergeSets(const syncable::Id& set1, const syncable::Id& set2);
102
103 void CleanupSets();
104 // END conflict set functions
105
106 // Item id set manipulation functions.
107 bool HasConflictingItems() const {
108 return !conflicting_item_ids_.empty();
109 }
110
111 int ConflictingItemsSize() const {
112 return conflicting_item_ids_.size();
113 }
114
115 void AddConflictingItem(const syncable::Id& the_id) {
116 std::pair<std::set<syncable::Id>::iterator, bool> ret =
117 conflicting_item_ids_.insert(the_id);
118 UpdateDirty(ret.second);
119 }
120
121 void EraseConflictingItem(std::set<syncable::Id>::iterator it) {
122 UpdateDirty(true);
123 conflicting_item_ids_.erase(it);
124 }
125
126 void EraseConflictingItem(const syncable::Id& the_id) {
127 int items_erased = conflicting_item_ids_.erase(the_id);
128 UpdateDirty(0 != items_erased);
129 }
130
131 std::set<syncable::Id>::iterator ConflictingItemsBegin() {
132 return conflicting_item_ids_.begin();
133 }
134
135 std::set<syncable::Id>::iterator ConflictingItemsEnd() {
136 return conflicting_item_ids_.end();
137 }
138
139 // END item id set manipulation functions
140
141 // Assorted other state info.
142 // DEPRECATED: USE ConflictingItemsSize.
143 int conflicting_updates() const { return conflicting_item_ids_.size(); }
144
145 base::TimeTicks silenced_until() const { return silenced_until_; }
146 void set_silenced_until(const base::TimeTicks& val);
147
148 // Info that is tracked purely for status reporting.
149
150 // During inital sync these two members can be used to measure sync progress.
151 int64 current_sync_timestamp() const { return current_sync_timestamp_; }
152
153 int64 num_server_changes_remaining() const { return num_server_changes_remaini ng_; }
154
155 void set_current_sync_timestamp(const int64 val);
156
157 void set_num_server_changes_remaining(const int64 val);
158
159 bool invalid_store() const { return invalid_store_; }
160
161 void set_invalid_store(const bool val);
162
163 bool syncer_stuck() const { return syncer_stuck_; }
164
165 void set_syncer_stuck(const bool val);
166
167 bool syncing() const { return syncing_; }
168
169 void set_syncing(const bool val);
170
171 bool IsShareUsable() const;
172
173 int conflicting_commits() const { return conflicting_commits_; }
174
175 void set_conflicting_commits(const int val);
176
177 // WEIRD COUNTER manipulation functions.
178 int consecutive_problem_get_updates() const {
179 return consecutive_problem_get_updates_;
180 }
181
182 void increment_consecutive_problem_get_updates();
183
184 void zero_consecutive_problem_get_updates();
185
186 int consecutive_problem_commits() const {
187 return consecutive_problem_commits_;
188 }
189
190 void increment_consecutive_problem_commits();
191
192 void zero_consecutive_problem_commits();
193
194 int consecutive_transient_error_commits() const {
195 return consecutive_transient_error_commits_;
196 }
197
198 void increment_consecutive_transient_error_commits_by(int value);
199
200 void zero_consecutive_transient_error_commits();
201
202 int consecutive_errors() const { return consecutive_errors_; }
203
204 void increment_consecutive_errors_by(int value);
205
206 void zero_consecutive_errors();
207
208 int successful_commits() const { return successful_commits_; }
209
210 void increment_successful_commits();
211
212 void zero_successful_commits();
213 // end WEIRD COUNTER manipulation functions.
214
215 // Methods for tracking authentication state.
216 void AuthFailed();
217
218 // Returns true if this object has been modified since last SetClean() call.
219 bool IsDirty() const { return dirty_; }
220
221 // Call to tell this status object that its new state has been seen.
222 void SetClean() { dirty_ = false; }
223
224 // Returns true if auth status has been modified since last SetClean() call.
225 bool IsAuthDirty() const { return auth_dirty_; }
226
227 // Call to tell this status object that its auth state has been seen.
228 void SetAuthClean() { auth_dirty_ = false; }
229
230 private:
231 // For testing.
232 SyncProcessState()
233 : connection_manager_(NULL),
234 account_name_(PSTR("")),
235 dirman_(NULL),
236 resolver_(NULL),
237 model_safe_worker_(NULL),
238 syncer_event_channel_(NULL),
239 current_sync_timestamp_(0),
240 num_server_changes_remaining_(0),
241 syncing_(false),
242 invalid_store_(false),
243 syncer_stuck_(false),
244 conflicting_commits_(0),
245 consecutive_problem_get_updates_(0),
246 consecutive_problem_commits_(0),
247 consecutive_transient_error_commits_(0),
248 consecutive_errors_(0),
249 successful_commits_(0),
250 dirty_(false),
251 auth_dirty_(false),
252 auth_failed_(false) {}
253
254 ServerConnectionManager* connection_manager_;
255 const std::string account_name_;
256 syncable::DirectoryManager* const dirman_;
257 ConflictResolver* const resolver_;
258 ModelSafeWorker* const model_safe_worker_;
259
260 // For sending notifications from sync commands out to observers of the
261 // Syncer.
262 SyncerEventChannel* syncer_event_channel_;
263
264 // TODO(sync): move away from sets if it makes more sense.
265 std::set<syncable::Id> conflicting_item_ids_;
266 std::map<syncable::Id, ConflictSet*> id_to_conflict_set_;
267 std::set<ConflictSet*> conflict_sets_;
268
269 // When we're over bandwidth quota, we don't update until past this time.
270 base::TimeTicks silenced_until_;
271
272 // Status information, as opposed to state info that may also be exposed for
273 // status reporting purposes.
274 int64 current_sync_timestamp_; // During inital sync these two members
275 int64 num_server_changes_remaining_; // Can be used to measure sync progress.
276
277 // There remains sync state updating in:
278 // CommitUnsyncedEntries
279 bool syncing_;
280
281 // True when we get such an INVALID_STORE error from the server.
282 bool invalid_store_;
283 // True iff we're stuck. User should contact support.
284 bool syncer_stuck_;
285 // counts of various commit return values.
286 int error_commits_;
287 int conflicting_commits_;
288
289 // WEIRD COUNTERS
290 // Two variables that track the # on consecutive problem requests.
291 // consecutive_problem_get_updates_ resets when we get any updates (not on
292 // pings) and increments whenever the request fails.
293 int consecutive_problem_get_updates_;
294 // consecutive_problem_commits_ resets whenever we commit any number of items
295 // and increments whenever all commits fail for any reason.
296 int consecutive_problem_commits_;
297 // number of commits hitting transient errors since the last successful
298 // commit.
299 int consecutive_transient_error_commits_;
300 // Incremented when get_updates fails, commit fails, and when hitting
301 // transient errors. When any of these succeed, this counter is reset.
302 // TODO(chron): Reduce number of weird counters we use.
303 int consecutive_errors_;
304 int successful_commits_;
305
306 bool dirty_;
307 bool auth_dirty_;
308 bool auth_failed_;
309
310 void UpdateDirty(bool new_info) { dirty_ |= new_info; }
311
312 void UpdateAuthDirty(bool new_info) { auth_dirty_ |= new_info; }
313 };
314
315 } // namespace browser_sync
316
317 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNC_PROCESS_STATE_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/sync_cycle_state.h ('k') | chrome/browser/sync/engine/sync_process_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698