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

Side by Side Diff: chrome/browser/sync/sessions/status_controller.cc

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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 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 #include "chrome/browser/sync/sessions/status_controller.h"
6
7 #include "base/basictypes.h"
8
9 namespace browser_sync {
10 namespace sessions {
11
12 StatusController::StatusController()
13 : transient_(new Dirtyable<TransientState>()) {}
14
15 void StatusController::ResetTransientState() {
16 transient_.reset(new Dirtyable<TransientState>());
17 syncer_status_.value()->over_quota = false;
18 }
19
20 // Helper to set the 'dirty' bit in the container of the field being
21 // mutated.
22 template <typename FieldType, typename DirtyableContainer>
23 void SetAndMarkDirtyIfChanged(FieldType* old_value,
24 const FieldType& new_value, DirtyableContainer* container) {
25 if (new_value != *old_value)
26 container->set_dirty();
27 *old_value = new_value;
28 }
29
30 template <typename T>
31 bool StatusController::Dirtyable<T>::TestAndClearIsDirty() {
32 bool dirty = dirty_;
33 dirty_ = false;
34 return dirty;
35 }
36
37 bool StatusController::TestAndClearIsDirty() {
38 bool is_dirty = change_progress_.TestAndClearIsDirty() ||
39 syncer_status_.TestAndClearIsDirty() ||
40 error_counters_.TestAndClearIsDirty() ||
41 transient_->TestAndClearIsDirty() ||
42 conflict_progress_.progress_changed();
43 conflict_progress_.reset_progress_changed();
44 return is_dirty;
45 }
46 void StatusController::set_num_conflicting_commits(int value) {
47 SetAndMarkDirtyIfChanged(&error_counters_.value()->num_conflicting_commits,
48 value, &error_counters_);
49 }
50
51 void StatusController::set_num_consecutive_problem_get_updates(int value) {
52 SetAndMarkDirtyIfChanged(
53 &error_counters_.value()->consecutive_problem_get_updates, value,
54 &error_counters_);
55 }
56
57 void StatusController::set_num_consecutive_problem_commits(int value) {
58 SetAndMarkDirtyIfChanged(
59 &error_counters_.value()->consecutive_problem_commits, value,
60 &error_counters_);
61 }
62
63 void StatusController::set_num_consecutive_transient_error_commits(int value) {
64 SetAndMarkDirtyIfChanged(
65 &error_counters_.value()->consecutive_transient_error_commits, value,
66 &error_counters_);
67 }
68
69 void StatusController::increment_num_consecutive_transient_error_commits_by(
70 int value) {
71 set_num_consecutive_transient_error_commits(
72 error_counters_.value()->consecutive_transient_error_commits + value);
73 }
74
75 void StatusController::set_num_consecutive_errors(int value) {
76 SetAndMarkDirtyIfChanged(&error_counters_.value()->consecutive_errors, value,
77 &error_counters_);
78 }
79
80 void StatusController::set_current_sync_timestamp(int64 current_timestamp) {
81 SetAndMarkDirtyIfChanged(&change_progress_.value()->current_sync_timestamp,
82 current_timestamp, &change_progress_);
83 }
84
85 void StatusController::set_num_server_changes_remaining(
86 int64 changes_remaining) {
87 SetAndMarkDirtyIfChanged(
88 &change_progress_.value()->num_server_changes_remaining,
89 changes_remaining, &change_progress_);
90 }
91
92 void StatusController::set_over_quota(bool over_quota) {
93 SetAndMarkDirtyIfChanged(&syncer_status_.value()->over_quota, over_quota,
94 &syncer_status_);
95 }
96
97 void StatusController::set_invalid_store(bool invalid_store) {
98 SetAndMarkDirtyIfChanged(&syncer_status_.value()->invalid_store,
99 invalid_store, &syncer_status_);
100 }
101
102 void StatusController::set_syncer_stuck(bool syncer_stuck) {
103 SetAndMarkDirtyIfChanged(&syncer_status_.value()->syncer_stuck, syncer_stuck,
104 &syncer_status_);
105 }
106
107 void StatusController::set_syncing(bool syncing) {
108 SetAndMarkDirtyIfChanged(&syncer_status_.value()->syncing, syncing,
109 &syncer_status_);
110 }
111
112 void StatusController::set_num_successful_commits(int value) {
113 SetAndMarkDirtyIfChanged(&syncer_status_.value()->num_successful_commits,
114 value, &syncer_status_);
115 }
116
117 void StatusController::set_unsynced_handles(
118 const std::vector<int64>& unsynced_handles) {
119 SetAndMarkDirtyIfChanged(&transient_->value()->unsynced_handles,
120 unsynced_handles, transient_.get());
121 }
122
123 void StatusController::increment_num_consecutive_problem_get_updates() {
124 set_num_consecutive_problem_get_updates(
125 error_counters_.value()->consecutive_problem_get_updates + 1);
126 }
127
128 void StatusController::increment_num_consecutive_problem_commits() {
129 set_num_consecutive_problem_commits(
130 error_counters_.value()->consecutive_problem_commits + 1);
131 }
132
133 void StatusController::increment_num_consecutive_errors() {
134 set_num_consecutive_errors(error_counters_.value()->consecutive_errors + 1);
135 }
136
137
138 void StatusController::increment_num_consecutive_errors_by(int value) {
139 set_num_consecutive_errors(error_counters_.value()->consecutive_errors +
140 value);
141 }
142
143 void StatusController::increment_num_successful_commits() {
144 set_num_successful_commits(
145 syncer_status_.value()->num_successful_commits + 1);
146 }
147
148 // These setters don't affect the dirtiness of TransientState.
149 void StatusController::set_commit_ids(
150 const std::vector<syncable::Id>& commit_ids) {
151 transient_->value()->commit_ids = commit_ids;
152 }
153
154 void StatusController::set_conflict_sets_built(bool built) {
155 transient_->value()->conflict_sets_built = built;
156 }
157 void StatusController::set_conflicts_resolved(bool resolved) {
158 transient_->value()->conflicts_resolved = resolved;
159 }
160 void StatusController::set_items_committed(bool items_committed) {
161 transient_->value()->items_committed = items_committed;
162 }
163 void StatusController::set_timestamp_dirty(bool dirty) {
164 transient_->value()->timestamp_dirty = dirty;
165 }
166
167 // Returns the number of updates received from the sync server.
168 int64 StatusController::CountUpdates() const {
169 const ClientToServerResponse& updates =
170 transient_->value()->updates_response;
171 if (updates.has_get_updates()) {
172 return updates.get_updates().entries().size();
173 } else {
174 return 0;
175 }
176 }
177
178 } // namespace sessions
179 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/status_controller.h ('k') | chrome/browser/sync/sessions/status_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698