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

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

Issue 11314008: sync: Follow-up to conflict resolution refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 8 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
« no previous file with comments | « sync/sessions/status_controller.h ('k') | sync/sessions/status_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "sync/sessions/status_controller.h" 5 #include "sync/sessions/status_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "sync/internal_api/public/base/model_type.h" 10 #include "sync/internal_api/public/base/model_type.h"
11 #include "sync/protocol/sync_protocol_error.h" 11 #include "sync/protocol/sync_protocol_error.h"
12 12
13 namespace syncer { 13 namespace syncer {
14 namespace sessions { 14 namespace sessions {
15 15
16 StatusController::StatusController(const ModelSafeRoutingInfo& routes) 16 StatusController::StatusController(const ModelSafeRoutingInfo& routes)
17 : per_model_group_deleter_(&per_model_group_), 17 : group_restriction_in_effect_(false),
18 group_restriction_in_effect_(false),
19 group_restriction_(GROUP_PASSIVE), 18 group_restriction_(GROUP_PASSIVE),
20 routing_info_(routes) { 19 routing_info_(routes) {
21 } 20 }
22 21
23 StatusController::~StatusController() {} 22 StatusController::~StatusController() {}
24 23
25 const std::set<syncable::Id>* StatusController::simple_conflict_ids() const {
26 const PerModelSafeGroupState* state =
27 GetModelSafeGroupState(true, group_restriction_);
28 return state ? &state->simple_conflict_ids : NULL;
29 }
30
31 std::set<syncable::Id>* StatusController::mutable_simple_conflict_ids() {
32 return &GetOrCreateModelSafeGroupState(
33 true, group_restriction_)->simple_conflict_ids;
34 }
35
36 const std::set<syncable::Id>*
37 StatusController::GetUnrestrictedSimpleConflictIds(
38 ModelSafeGroup group) const {
39 const PerModelSafeGroupState* state = GetModelSafeGroupState(false, group);
40 return state ? &state->simple_conflict_ids : NULL;
41 }
42
43 const PerModelSafeGroupState* StatusController::GetModelSafeGroupState(
44 bool restrict, ModelSafeGroup group) const {
45 DCHECK_EQ(restrict, group_restriction_in_effect_);
46 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it =
47 per_model_group_.find(group);
48 return (it == per_model_group_.end()) ? NULL : it->second;
49 }
50
51 PerModelSafeGroupState* StatusController::GetOrCreateModelSafeGroupState(
52 bool restrict, ModelSafeGroup group) {
53 DCHECK_EQ(restrict, group_restriction_in_effect_);
54 std::map<ModelSafeGroup, PerModelSafeGroupState*>::iterator it =
55 per_model_group_.find(group);
56 if (it == per_model_group_.end()) {
57 PerModelSafeGroupState* state = new PerModelSafeGroupState();
58 it = per_model_group_.insert(std::make_pair(group, state)).first;
59 }
60 return it->second;
61 }
62
63 void StatusController::increment_num_updates_downloaded_by(int value) { 24 void StatusController::increment_num_updates_downloaded_by(int value) {
64 model_neutral_.num_updates_downloaded_total += value; 25 model_neutral_.num_updates_downloaded_total += value;
65 } 26 }
66 27
67 void StatusController::set_types_needing_local_migration(ModelTypeSet types) { 28 void StatusController::set_types_needing_local_migration(ModelTypeSet types) {
68 model_neutral_.types_needing_local_migration = types; 29 model_neutral_.types_needing_local_migration = types;
69 } 30 }
70 31
71 void StatusController::increment_num_tombstone_updates_downloaded_by( 32 void StatusController::increment_num_tombstone_updates_downloaded_by(
72 int value) { 33 int value) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 99 }
139 100
140 void StatusController::set_commit_result(const SyncerError result) { 101 void StatusController::set_commit_result(const SyncerError result) {
141 model_neutral_.commit_result = result; 102 model_neutral_.commit_result = result;
142 } 103 }
143 104
144 SyncerError StatusController::last_get_key_result() const { 105 SyncerError StatusController::last_get_key_result() const {
145 return model_neutral_.last_get_key_result; 106 return model_neutral_.last_get_key_result;
146 } 107 }
147 108
148 void StatusController::update_conflicts_resolved(bool resolved) {
149 model_neutral_.conflicts_resolved |= resolved;
150 }
151 void StatusController::reset_conflicts_resolved() {
152 model_neutral_.conflicts_resolved = false;
153 }
154
155 // Returns the number of updates received from the sync server. 109 // Returns the number of updates received from the sync server.
156 int64 StatusController::CountUpdates() const { 110 int64 StatusController::CountUpdates() const {
157 const sync_pb::ClientToServerResponse& updates = 111 const sync_pb::ClientToServerResponse& updates =
158 model_neutral_.updates_response; 112 model_neutral_.updates_response;
159 if (updates.has_get_updates()) { 113 if (updates.has_get_updates()) {
160 return updates.get_updates().entries().size(); 114 return updates.get_updates().entries().size();
161 } else { 115 } else {
162 return 0; 116 return 0;
163 } 117 }
164 } 118 }
165 119
166 bool StatusController::HasConflictingUpdates() const {
167 return TotalNumConflictingItems() > 0;
168 }
169
170 int StatusController::num_updates_applied() const { 120 int StatusController::num_updates_applied() const {
171 return model_neutral_.num_updates_applied; 121 return model_neutral_.num_updates_applied;
172 } 122 }
173 123
174 int StatusController::num_server_overwrites() const { 124 int StatusController::num_server_overwrites() const {
175 return model_neutral_.num_server_overwrites; 125 return model_neutral_.num_server_overwrites;
176 } 126 }
177 127
178 int StatusController::num_encryption_conflicts() const { 128 int StatusController::num_encryption_conflicts() const {
179 return model_neutral_.num_encryption_conflicts; 129 return model_neutral_.num_encryption_conflicts;
180 } 130 }
181 131
182 int StatusController::num_hierarchy_conflicts() const { 132 int StatusController::num_hierarchy_conflicts() const {
183 DCHECK(!group_restriction_in_effect_) 133 DCHECK(!group_restriction_in_effect_)
184 << "num_hierarchy_conflicts applies to all ModelSafeGroups"; 134 << "num_hierarchy_conflicts applies to all ModelSafeGroups";
185 return model_neutral_.num_hierarchy_conflicts; 135 return model_neutral_.num_hierarchy_conflicts;
186 } 136 }
187 137
188 int StatusController::num_simple_conflicts() const {
189 DCHECK(!group_restriction_in_effect_)
190 << "num_simple_conflicts applies to all ModelSafeGroups";
191 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it =
192 per_model_group_.begin();
193 int sum = 0;
194 for (; it != per_model_group_.end(); ++it) {
195 sum += it->second->simple_conflict_ids.size();
196 }
197 return sum;
198 }
199
200 int StatusController::num_server_conflicts() const { 138 int StatusController::num_server_conflicts() const {
201 DCHECK(!group_restriction_in_effect_) 139 DCHECK(!group_restriction_in_effect_)
202 << "num_server_conflicts applies to all ModelSafeGroups"; 140 << "num_server_conflicts applies to all ModelSafeGroups";
203 return model_neutral_.num_server_conflicts; 141 return model_neutral_.num_server_conflicts;
204 } 142 }
205 143
206 int StatusController::TotalNumConflictingItems() const { 144 int StatusController::TotalNumConflictingItems() const {
207 DCHECK(!group_restriction_in_effect_) 145 DCHECK(!group_restriction_in_effect_)
208 << "TotalNumConflictingItems applies to all ModelSafeGroups"; 146 << "TotalNumConflictingItems applies to all ModelSafeGroups";
209 int sum = 0; 147 int sum = 0;
210 sum += num_simple_conflicts();
211 sum += num_encryption_conflicts(); 148 sum += num_encryption_conflicts();
212 sum += num_hierarchy_conflicts(); 149 sum += num_hierarchy_conflicts();
213 sum += num_server_conflicts(); 150 sum += num_server_conflicts();
214 return sum; 151 return sum;
215 } 152 }
216 153
217 bool StatusController::ServerSaysNothingMoreToDownload() const { 154 bool StatusController::ServerSaysNothingMoreToDownload() const {
218 if (!download_updates_succeeded()) 155 if (!download_updates_succeeded())
219 return false; 156 return false;
220 157
221 if (!updates_response().get_updates().has_changes_remaining()) { 158 if (!updates_response().get_updates().has_changes_remaining()) {
222 NOTREACHED(); // Server should always send changes remaining. 159 NOTREACHED(); // Server should always send changes remaining.
223 return false; // Avoid looping forever. 160 return false; // Avoid looping forever.
224 } 161 }
225 // Changes remaining is an estimate, but if it's estimated to be 162 // Changes remaining is an estimate, but if it's estimated to be
226 // zero, that's firm and we don't have to ask again. 163 // zero, that's firm and we don't have to ask again.
227 return updates_response().get_updates().changes_remaining() == 0; 164 return updates_response().get_updates().changes_remaining() == 0;
228 } 165 }
229 166
230 void StatusController::set_debug_info_sent() { 167 void StatusController::set_debug_info_sent() {
231 model_neutral_.debug_info_sent = true; 168 model_neutral_.debug_info_sent = true;
232 } 169 }
233 170
234 bool StatusController::debug_info_sent() const { 171 bool StatusController::debug_info_sent() const {
235 return model_neutral_.debug_info_sent; 172 return model_neutral_.debug_info_sent;
236 } 173 }
237 174
238 } // namespace sessions 175 } // namespace sessions
239 } // namespace syncer 176 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/status_controller.h ('k') | sync/sessions/status_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698