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/engine/conflict_resolver.h" | 5 #include "chrome/browser/sync/engine/conflict_resolver.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 entry.Get(syncable::META_HANDLE)) | 354 entry.Get(syncable::META_HANDLE)) |
355 << server_update << entry; | 355 << server_update << entry; |
356 UMA_HISTOGRAM_ENUMERATION("Sync.ResolveSimpleConflict", | 356 UMA_HISTOGRAM_ENUMERATION("Sync.ResolveSimpleConflict", |
357 UNDELETE, | 357 UNDELETE, |
358 CONFLICT_RESOLUTION_SIZE); | 358 CONFLICT_RESOLUTION_SIZE); |
359 } | 359 } |
360 return SYNC_PROGRESS; | 360 return SYNC_PROGRESS; |
361 } | 361 } |
362 } | 362 } |
363 | 363 |
364 bool ConflictResolver::ResolveSimpleConflicts( | 364 bool ConflictResolver::ResolveConflicts(syncable::WriteTransaction* trans, |
Nicolas Zea
2012/02/01 19:16:19
I think it would be good to have a comment above h
rlarocque
2012/02/02 00:32:56
I'm trying to remove the concept of conflict sets
| |
365 syncable::WriteTransaction* trans, | 365 const Cryptographer* cryptographer, |
366 const Cryptographer* cryptographer, | 366 const ConflictProgress& progress, |
367 const ConflictProgress& progress, | 367 sessions::StatusController* status) { |
368 sessions::StatusController* status) { | |
369 bool forward_progress = false; | 368 bool forward_progress = false; |
370 // First iterate over simple conflict items (those that belong to no set). | 369 // First iterate over simple conflict items. |
Nicolas Zea
2012/02/01 19:16:19
Remove first
rlarocque
2012/02/02 00:32:56
Done.
| |
371 set<Id>::const_iterator conflicting_item_it; | 370 set<Id>::const_iterator conflicting_item_it; |
372 set<Id> processed_items; | 371 set<Id> processed_items; |
373 for (conflicting_item_it = progress.ConflictingItemsBegin(); | 372 for (conflicting_item_it = progress.ConflictingItemsBegin(); |
374 conflicting_item_it != progress.ConflictingItemsEnd(); | 373 conflicting_item_it != progress.ConflictingItemsEnd(); |
375 ++conflicting_item_it) { | 374 ++conflicting_item_it) { |
376 Id id = *conflicting_item_it; | 375 Id id = *conflicting_item_it; |
377 if (processed_items.count(id) > 0) | 376 if (processed_items.count(id) > 0) |
378 continue; | 377 continue; |
379 map<Id, ConflictSet*>::const_iterator item_set_it = | 378 |
380 progress.IdToConflictSetFind(id); | 379 // We have a simple conflict. In order check if positions have changed, |
rlarocque
2012/01/31 19:12:17
There are lots of indentation changes because I re
| |
381 if (item_set_it == progress.IdToConflictSetEnd() || | 380 // we need to process conflicting predecessors before successors. Traverse |
382 0 == item_set_it->second) { | 381 // backwards through all continuous conflicting predecessors, building a |
383 // We have a simple conflict. In order check if positions have changed, | 382 // stack of items to resolve in predecessor->successor order, then process |
384 // we need to process conflicting predecessors before successors. Traverse | 383 // each item individually. |
385 // backwards through all continuous conflicting predecessors, building a | 384 list<Id> predecessors; |
386 // stack of items to resolve in predecessor->successor order, then process | 385 Id prev_id = id; |
387 // each item individually. | 386 do { |
388 list<Id> predecessors; | 387 predecessors.push_back(prev_id); |
389 Id prev_id = id; | 388 Entry entry(trans, syncable::GET_BY_ID, prev_id); |
390 do { | 389 // Any entry in conflict must be valid. |
391 predecessors.push_back(prev_id); | 390 CHECK(entry.good()); |
392 Entry entry(trans, syncable::GET_BY_ID, prev_id); | 391 Id new_prev_id = entry.Get(syncable::PREV_ID); |
393 // Any entry in conflict must be valid. | 392 if (new_prev_id == prev_id) |
394 CHECK(entry.good()); | 393 break; |
395 Id new_prev_id = entry.Get(syncable::PREV_ID); | 394 prev_id = new_prev_id; |
396 if (new_prev_id == prev_id) | 395 } while (processed_items.count(prev_id) == 0 && |
396 progress.HasSimpleConflictItem(prev_id)); // Excludes root. | |
397 while (!predecessors.empty()) { | |
398 id = predecessors.back(); | |
399 predecessors.pop_back(); | |
400 switch (ProcessSimpleConflict(trans, id, cryptographer, status)) { | |
401 case NO_SYNC_PROGRESS: | |
397 break; | 402 break; |
398 prev_id = new_prev_id; | 403 case SYNC_PROGRESS: |
399 } while (processed_items.count(prev_id) == 0 && | 404 forward_progress = true; |
400 progress.HasSimpleConflictItem(prev_id)); // Excludes root. | 405 break; |
401 while (!predecessors.empty()) { | |
402 id = predecessors.back(); | |
403 predecessors.pop_back(); | |
404 switch (ProcessSimpleConflict(trans, id, cryptographer, status)) { | |
405 case NO_SYNC_PROGRESS: | |
406 break; | |
407 case SYNC_PROGRESS: | |
408 forward_progress = true; | |
409 break; | |
410 } | |
411 processed_items.insert(id); | |
412 } | 406 } |
407 processed_items.insert(id); | |
413 } | 408 } |
414 } | 409 } |
415 return forward_progress; | 410 return forward_progress; |
416 } | 411 } |
417 | 412 |
418 bool ConflictResolver::ResolveConflicts(syncable::WriteTransaction* trans, | |
419 const Cryptographer* cryptographer, | |
420 const ConflictProgress& progress, | |
421 sessions::StatusController* status) { | |
422 // TODO(rlarocque): A good amount of code related to the resolution of | |
423 // conflict sets has been deleted here. This was done because the code had | |
424 // not been used in years. An unrelated bug fix accidentally re-enabled the | |
425 // code, forcing us to make a decision about what we should do with the code. | |
426 // We decided to do the safe thing and delete it for now. This restores the | |
427 // behaviour we've relied on for quite some time. We should think about what | |
428 // that code was trying to do and consider re-enabling parts of it. | |
429 | |
430 if (progress.ConflictSetsSize() > 0) { | |
431 DVLOG(1) << "Detected " << progress.IdToConflictSetSize() | |
432 << " non-simple conflicting entries in " << progress.ConflictSetsSize() | |
433 << " unprocessed conflict sets."; | |
434 } | |
435 | |
436 return ResolveSimpleConflicts(trans, cryptographer, progress, status); | |
437 } | |
438 | |
439 } // namespace browser_sync | 413 } // namespace browser_sync |
OLD | NEW |