OLD | NEW |
---|---|
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 "chrome/browser/sync/sessions/session_state.h" | 5 #include "chrome/browser/sync/sessions/session_state.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 const SyncerStatus& syncer_status, | 112 const SyncerStatus& syncer_status, |
113 const ErrorCounters& errors, | 113 const ErrorCounters& errors, |
114 int64 num_server_changes_remaining, | 114 int64 num_server_changes_remaining, |
115 bool is_share_usable, | 115 bool is_share_usable, |
116 syncable::ModelTypeSet initial_sync_ended, | 116 syncable::ModelTypeSet initial_sync_ended, |
117 const std::string | 117 const std::string |
118 (&download_progress_markers)[syncable::MODEL_TYPE_COUNT], | 118 (&download_progress_markers)[syncable::MODEL_TYPE_COUNT], |
119 bool more_to_sync, | 119 bool more_to_sync, |
120 bool is_silenced, | 120 bool is_silenced, |
121 int64 unsynced_count, | 121 int64 unsynced_count, |
122 int num_blocking_conflicting_updates, | 122 int num_blocking_conflicting_updates, |
Nicolas Zea
2012/02/02 21:53:41
num_resolvable (here and below)
rlarocque
2012/02/03 22:31:15
See above comment.
| |
123 int num_conflicting_updates, | 123 int num_conflicting_updates, |
124 bool did_commit_items, | 124 bool did_commit_items, |
125 const SyncSourceInfo& source, | 125 const SyncSourceInfo& source, |
126 size_t num_entries, | 126 size_t num_entries, |
127 base::Time sync_start_time, | 127 base::Time sync_start_time, |
128 bool retry_scheduled) | 128 bool retry_scheduled) |
129 : syncer_status(syncer_status), | 129 : syncer_status(syncer_status), |
130 errors(errors), | 130 errors(errors), |
131 num_server_changes_remaining(num_server_changes_remaining), | 131 num_server_changes_remaining(num_server_changes_remaining), |
132 is_share_usable(is_share_usable), | 132 is_share_usable(is_share_usable), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 return value; | 177 return value; |
178 } | 178 } |
179 | 179 |
180 std::string SyncSessionSnapshot::ToString() const { | 180 std::string SyncSessionSnapshot::ToString() const { |
181 scoped_ptr<DictionaryValue> value(ToValue()); | 181 scoped_ptr<DictionaryValue> value(ToValue()); |
182 std::string json; | 182 std::string json; |
183 base::JSONWriter::Write(value.get(), true, &json); | 183 base::JSONWriter::Write(value.get(), true, &json); |
184 return json; | 184 return json; |
185 } | 185 } |
186 | 186 |
187 ConflictProgress::ConflictProgress(bool* dirty_flag) : dirty_(dirty_flag) {} | 187 ConflictProgress::ConflictProgress(bool* dirty_flag) |
188 : num_server_conflicting_items(0), num_hierarchy_conflicting_items(0), | |
189 num_encryption_conflicting_items(0), dirty_(dirty_flag) { | |
190 } | |
188 | 191 |
189 ConflictProgress::~ConflictProgress() { | 192 ConflictProgress::~ConflictProgress() { |
190 CleanupSets(); | |
191 } | 193 } |
192 | 194 |
193 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const { | 195 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const { |
194 return conflicting_item_ids_.count(id) > 0 && | 196 return simple_conflicting_item_ids_.count(id) > 0; |
195 (IdToConflictSetFind(id) == IdToConflictSetEnd()); | |
196 } | |
197 | |
198 IdToConflictSetMap::const_iterator ConflictProgress::IdToConflictSetFind( | |
199 const syncable::Id& the_id) const { | |
200 return id_to_conflict_set_.find(the_id); | |
201 } | |
202 | |
203 IdToConflictSetMap::const_iterator | |
204 ConflictProgress::IdToConflictSetBegin() const { | |
205 return id_to_conflict_set_.begin(); | |
206 } | |
207 | |
208 IdToConflictSetMap::const_iterator | |
209 ConflictProgress::IdToConflictSetEnd() const { | |
210 return id_to_conflict_set_.end(); | |
211 } | |
212 | |
213 IdToConflictSetMap::size_type ConflictProgress::IdToConflictSetSize() const { | |
214 return id_to_conflict_set_.size(); | |
215 } | |
216 | |
217 const ConflictSet* ConflictProgress::IdToConflictSetGet( | |
218 const syncable::Id& the_id) { | |
219 return id_to_conflict_set_[the_id]; | |
220 } | |
221 | |
222 std::set<ConflictSet*>::const_iterator | |
223 ConflictProgress::ConflictSetsBegin() const { | |
224 return conflict_sets_.begin(); | |
225 } | |
226 | |
227 std::set<ConflictSet*>::const_iterator | |
228 ConflictProgress::ConflictSetsEnd() const { | |
229 return conflict_sets_.end(); | |
230 } | |
231 | |
232 std::set<ConflictSet*>::size_type | |
233 ConflictProgress::ConflictSetsSize() const { | |
234 return conflict_sets_.size(); | |
235 } | 197 } |
236 | 198 |
237 std::set<syncable::Id>::const_iterator | 199 std::set<syncable::Id>::const_iterator |
238 ConflictProgress::ConflictingItemsBegin() const { | 200 ConflictProgress::SimpleConflictingItemsBegin() const { |
239 return conflicting_item_ids_.begin(); | 201 return simple_conflicting_item_ids_.begin(); |
240 } | 202 } |
241 std::set<syncable::Id>::const_iterator | 203 std::set<syncable::Id>::const_iterator |
242 ConflictProgress::ConflictingItemsEnd() const { | 204 ConflictProgress::SimpleConflictingItemsEnd() const { |
243 return conflicting_item_ids_.end(); | 205 return simple_conflicting_item_ids_.end(); |
244 } | 206 } |
245 | 207 |
246 void ConflictProgress::AddConflictingItemById(const syncable::Id& the_id) { | 208 void ConflictProgress::AddSimpleConflictingItemById( |
209 const syncable::Id& the_id) { | |
247 std::pair<std::set<syncable::Id>::iterator, bool> ret = | 210 std::pair<std::set<syncable::Id>::iterator, bool> ret = |
248 conflicting_item_ids_.insert(the_id); | 211 simple_conflicting_item_ids_.insert(the_id); |
249 if (ret.second) | 212 if (ret.second) |
250 *dirty_ = true; | 213 *dirty_ = true; |
251 } | 214 } |
252 | 215 |
253 void ConflictProgress::EraseConflictingItemById(const syncable::Id& the_id) { | 216 void ConflictProgress::EraseSimpleConflictingItemById( |
254 int items_erased = conflicting_item_ids_.erase(the_id); | 217 const syncable::Id& the_id) { |
218 int items_erased = simple_conflicting_item_ids_.erase(the_id); | |
255 if (items_erased != 0) | 219 if (items_erased != 0) |
256 *dirty_ = true; | 220 *dirty_ = true; |
257 } | 221 } |
258 | 222 |
259 void ConflictProgress::AddNonblockingConflictingItemById( | 223 void ConflictProgress::AddEncryptionConflictingItemById( |
260 const syncable::Id& the_id) { | 224 const syncable::Id& the_id) { |
261 std::pair<std::set<syncable::Id>::iterator, bool> ret = | 225 std::pair<std::set<syncable::Id>::iterator, bool> ret = |
262 nonblocking_conflicting_item_ids_.insert(the_id); | 226 unresolvable_conflicting_item_ids_.insert(the_id); |
263 if (ret.second) | 227 if (ret.second) { |
228 num_encryption_conflicting_items++; | |
264 *dirty_ = true; | 229 *dirty_ = true; |
230 } | |
265 } | 231 } |
266 | 232 |
267 void ConflictProgress::EraseNonblockingConflictingItemById( | 233 void ConflictProgress::AddHierarchyConflictingItemById( |
268 const syncable::Id& the_id) { | 234 const syncable::Id& the_id) { |
269 int items_erased = nonblocking_conflicting_item_ids_.erase(the_id); | 235 std::pair<std::set<syncable::Id>::iterator, bool> ret = |
270 if (items_erased != 0) | 236 unresolvable_conflicting_item_ids_.insert(the_id); |
237 if (ret.second) { | |
238 num_hierarchy_conflicting_items++; | |
271 *dirty_ = true; | 239 *dirty_ = true; |
240 } | |
272 } | 241 } |
273 | 242 |
274 void ConflictProgress::MergeSets(const syncable::Id& id1, | 243 void ConflictProgress::AddServerConflictingItemById( |
275 const syncable::Id& id2) { | 244 const syncable::Id& the_id) { |
276 // There are no single item sets, we just leave those entries == 0 | 245 std::pair<std::set<syncable::Id>::iterator, bool> ret = |
277 vector<syncable::Id>* set1 = id_to_conflict_set_[id1]; | 246 unresolvable_conflicting_item_ids_.insert(the_id); |
278 vector<syncable::Id>* set2 = id_to_conflict_set_[id2]; | 247 if (ret.second) { |
279 vector<syncable::Id>* rv = 0; | 248 num_server_conflicting_items++; |
280 if (0 == set1 && 0 == set2) { | 249 *dirty_ = true; |
281 // Neither item currently has a set so we build one. | |
282 rv = new vector<syncable::Id>(); | |
283 rv->push_back(id1); | |
284 if (id1 != id2) { | |
285 rv->push_back(id2); | |
286 } else { | |
287 LOG(WARNING) << "[BUG] Attempting to merge two identical conflict ids."; | |
288 } | |
289 conflict_sets_.insert(rv); | |
290 } else if (0 == set1) { | |
291 // Add the item to the existing set. | |
292 rv = set2; | |
293 rv->push_back(id1); | |
294 } else if (0 == set2) { | |
295 // Add the item to the existing set. | |
296 rv = set1; | |
297 rv->push_back(id2); | |
298 } else if (set1 == set2) { | |
299 // It's the same set already. | |
300 return; | |
301 } else { | |
302 // Merge the two sets. | |
303 rv = set1; | |
304 // Point all the second sets id's back to the first. | |
305 vector<syncable::Id>::iterator i; | |
306 for (i = set2->begin() ; i != set2->end() ; ++i) { | |
307 id_to_conflict_set_[*i] = rv; | |
308 } | |
309 // Copy the second set to the first. | |
310 rv->insert(rv->end(), set2->begin(), set2->end()); | |
311 conflict_sets_.erase(set2); | |
312 delete set2; | |
313 } | 250 } |
314 id_to_conflict_set_[id1] = id_to_conflict_set_[id2] = rv; | |
315 } | |
316 | |
317 void ConflictProgress::CleanupSets() { | |
318 // Clean up all the sets. | |
319 set<ConflictSet*>::iterator i; | |
320 for (i = conflict_sets_.begin(); i != conflict_sets_.end(); i++) { | |
321 delete *i; | |
322 } | |
323 conflict_sets_.clear(); | |
324 id_to_conflict_set_.clear(); | |
325 } | 251 } |
326 | 252 |
327 UpdateProgress::UpdateProgress() {} | 253 UpdateProgress::UpdateProgress() {} |
328 | 254 |
329 UpdateProgress::~UpdateProgress() {} | 255 UpdateProgress::~UpdateProgress() {} |
330 | 256 |
331 void UpdateProgress::AddVerifyResult(const VerifyResult& verify_result, | 257 void UpdateProgress::AddVerifyResult(const VerifyResult& verify_result, |
332 const sync_pb::SyncEntity& entity) { | 258 const sync_pb::SyncEntity& entity) { |
333 verified_updates_.push_back(std::make_pair(verify_result, entity)); | 259 verified_updates_.push_back(std::make_pair(verify_result, entity)); |
334 } | 260 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 count++; | 293 count++; |
368 } | 294 } |
369 return count; | 295 return count; |
370 } | 296 } |
371 | 297 |
372 // Returns true if at least one update application failed due to a conflict | 298 // Returns true if at least one update application failed due to a conflict |
373 // during this sync cycle. | 299 // during this sync cycle. |
374 bool UpdateProgress::HasConflictingUpdates() const { | 300 bool UpdateProgress::HasConflictingUpdates() const { |
375 std::vector<AppliedUpdate>::const_iterator it; | 301 std::vector<AppliedUpdate>::const_iterator it; |
376 for (it = applied_updates_.begin(); it != applied_updates_.end(); ++it) { | 302 for (it = applied_updates_.begin(); it != applied_updates_.end(); ++it) { |
377 if (it->first == CONFLICT) { | 303 if (it->first != SUCCESS) { |
378 return true; | 304 return true; |
379 } | 305 } |
380 } | 306 } |
381 return false; | 307 return false; |
382 } | 308 } |
383 | 309 |
384 AllModelTypeState::AllModelTypeState(bool* dirty_flag) | 310 AllModelTypeState::AllModelTypeState(bool* dirty_flag) |
385 : unsynced_handles(dirty_flag), | 311 : unsynced_handles(dirty_flag), |
386 syncer_status(dirty_flag), | 312 syncer_status(dirty_flag), |
387 error(dirty_flag), | 313 error(dirty_flag), |
388 num_server_changes_remaining(dirty_flag, 0), | 314 num_server_changes_remaining(dirty_flag, 0), |
389 commit_set(ModelSafeRoutingInfo()) { | 315 commit_set(ModelSafeRoutingInfo()) { |
390 } | 316 } |
391 | 317 |
392 AllModelTypeState::~AllModelTypeState() {} | 318 AllModelTypeState::~AllModelTypeState() {} |
393 | 319 |
394 PerModelSafeGroupState::PerModelSafeGroupState(bool* dirty_flag) | 320 PerModelSafeGroupState::PerModelSafeGroupState(bool* dirty_flag) |
395 : conflict_progress(dirty_flag) { | 321 : conflict_progress(dirty_flag) { |
396 } | 322 } |
397 | 323 |
398 PerModelSafeGroupState::~PerModelSafeGroupState() { | 324 PerModelSafeGroupState::~PerModelSafeGroupState() { |
399 } | 325 } |
400 | 326 |
401 } // namespace sessions | 327 } // namespace sessions |
402 } // namespace browser_sync | 328 } // namespace browser_sync |
OLD | NEW |