OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE entry. | 3 // found in the LICENSE entry. |
4 | 4 |
5 #include "chrome/browser/sync/engine/conflict_resolver.h" | 5 #include "chrome/browser/sync/engine/conflict_resolver.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "chrome/browser/sync/engine/syncer.h" | 10 #include "chrome/browser/sync/engine/syncer.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 date.append(IntToPathString(now->tm_mday)); | 58 date.append(IntToPathString(now->tm_mday)); |
59 return base + PSTR(" (Edited on ") + date + PSTR(")"); | 59 return base + PSTR(" (Edited on ") + date + PSTR(")"); |
60 } | 60 } |
61 | 61 |
62 // TODO(ncarter): Remove title/path conflicts and the code to resolve them. | 62 // TODO(ncarter): Remove title/path conflicts and the code to resolve them. |
63 Name FindNewName(BaseTransaction* trans, | 63 Name FindNewName(BaseTransaction* trans, |
64 Id parent_id, | 64 Id parent_id, |
65 const SyncName& original_name) { | 65 const SyncName& original_name) { |
66 const PathString name = original_name.value(); | 66 const PathString name = original_name.value(); |
67 // 255 is defined in our spec. | 67 // 255 is defined in our spec. |
68 const int allowed_length = kSyncProtocolMaxNameLengthBytes; | 68 const size_t allowed_length = kSyncProtocolMaxNameLengthBytes; |
69 // TODO(sync): How do we get length on other platforms? The limit is | 69 // TODO(sync): How do we get length on other platforms? The limit is |
70 // checked in java on the server, so it's not the number of glyphs its the | 70 // checked in java on the server, so it's not the number of glyphs its the |
71 // number of 16 bit characters in the UTF-16 representation. | 71 // number of 16 bit characters in the UTF-16 representation. |
72 | 72 |
73 // 10 characters for 32 bit numbers + 2 characters for brackets means 12 | 73 // 10 characters for 32 bit numbers + 2 characters for brackets means 12 |
74 // characters should be more than enough for the name. Doubling this ensures | 74 // characters should be more than enough for the name. Doubling this ensures |
75 // that we will have enough space. | 75 // that we will have enough space. |
76 COMPILE_ASSERT(kSyncProtocolMaxNameLengthBytes >= 24, | 76 COMPILE_ASSERT(kSyncProtocolMaxNameLengthBytes >= 24, |
77 maximum_name_too_short); | 77 maximum_name_too_short); |
78 CHECK(name.length() <= allowed_length); | 78 CHECK(name.length() <= allowed_length); |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 Id id = *conflicting_item_it; | 657 Id id = *conflicting_item_it; |
658 map<Id, ConflictSet*>::const_iterator item_set_it = | 658 map<Id, ConflictSet*>::const_iterator item_set_it = |
659 view->IdToConflictSetFind(id); | 659 view->IdToConflictSetFind(id); |
660 if (item_set_it == view->IdToConflictSetEnd() || | 660 if (item_set_it == view->IdToConflictSetEnd() || |
661 0 == item_set_it->second) { | 661 0 == item_set_it->second) { |
662 // We have a simple conflict. | 662 // We have a simple conflict. |
663 switch(ProcessSimpleConflict(&trans, id, session)) { | 663 switch(ProcessSimpleConflict(&trans, id, session)) { |
664 case NO_SYNC_PROGRESS: | 664 case NO_SYNC_PROGRESS: |
665 { | 665 { |
666 int conflict_count = (simple_conflict_count_map_[id] += 2); | 666 int conflict_count = (simple_conflict_count_map_[id] += 2); |
667 bool stuck = LogAndSignalIfConflictStuck(&trans, conflict_count, | 667 LogAndSignalIfConflictStuck(&trans, conflict_count, |
668 &id, &id + 1, view); | 668 &id, &id + 1, view); |
669 break; | 669 break; |
670 } | 670 } |
671 case SYNC_PROGRESS: | 671 case SYNC_PROGRESS: |
672 forward_progress = true; | 672 forward_progress = true; |
673 break; | 673 break; |
674 } | 674 } |
675 } | 675 } |
676 } | 676 } |
677 // Reduce the simple_conflict_count for each item currently tracked. | 677 // Reduce the simple_conflict_count for each item currently tracked. |
678 SimpleConflictCountMap::iterator i = simple_conflict_count_map_.begin(); | 678 SimpleConflictCountMap::iterator i = simple_conflict_count_map_.begin(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 conflict_set->begin(), | 717 conflict_set->begin(), |
718 conflict_set->end())) { | 718 conflict_set->end())) { |
719 LOG(INFO) << "Accelerating resolution for hierarchical merge."; | 719 LOG(INFO) << "Accelerating resolution for hierarchical merge."; |
720 conflict_count += 2; | 720 conflict_count += 2; |
721 } | 721 } |
722 // See if we should process this set. | 722 // See if we should process this set. |
723 if (ProcessConflictSet(&trans, conflict_set, conflict_count, session)) { | 723 if (ProcessConflictSet(&trans, conflict_set, conflict_count, session)) { |
724 rv = true; | 724 rv = true; |
725 } | 725 } |
726 SyncerStatus status(session); | 726 SyncerStatus status(session); |
727 bool stuck = LogAndSignalIfConflictStuck(&trans, conflict_count, | 727 LogAndSignalIfConflictStuck(&trans, conflict_count, |
728 conflict_set->begin(), | 728 conflict_set->begin(), |
729 conflict_set->end(), view); | 729 conflict_set->end(), view); |
730 } | 730 } |
731 if (rv) { | 731 if (rv) { |
732 // This code means we don't signal that syncing is stuck when any conflict | 732 // This code means we don't signal that syncing is stuck when any conflict |
733 // resolution has occured. | 733 // resolution has occured. |
734 // TODO(sync): As this will also reduce our sensitivity to problem | 734 // TODO(sync): As this will also reduce our sensitivity to problem |
735 // conditions and increase the time for cascading resolutions we may have to | 735 // conditions and increase the time for cascading resolutions we may have to |
736 // revisit this code later, doing something more intelligent. | 736 // revisit this code later, doing something more intelligent. |
737 conflict_set_count_map_.clear(); | 737 conflict_set_count_map_.clear(); |
738 simple_conflict_count_map_.clear(); | 738 simple_conflict_count_map_.clear(); |
739 } | 739 } |
740 ConflictSetCountMap::iterator i = conflict_set_count_map_.begin(); | 740 ConflictSetCountMap::iterator i = conflict_set_count_map_.begin(); |
741 while (i != conflict_set_count_map_.end()) { | 741 while (i != conflict_set_count_map_.end()) { |
742 if (0 == --i->second) { | 742 if (0 == --i->second) { |
743 conflict_set_count_map_.erase(i++); | 743 conflict_set_count_map_.erase(i++); |
744 // METRIC self resolved conflict sets ++. | 744 // METRIC self resolved conflict sets ++. |
745 } else { | 745 } else { |
746 ++i; | 746 ++i; |
747 } | 747 } |
748 } | 748 } |
749 return rv; | 749 return rv; |
750 } | 750 } |
751 | 751 |
752 } // namespace browser_sync | 752 } // namespace browser_sync |
OLD | NEW |