| 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 "sync/engine/conflict_resolver.h" |    5 #include "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> | 
|   11  |   11  | 
|   12 #include "base/location.h" |   12 #include "base/location.h" | 
|   13 #include "base/metrics/histogram.h" |   13 #include "base/metrics/histogram.h" | 
|   14 #include "sync/engine/conflict_util.h" |   14 #include "sync/engine/conflict_util.h" | 
|   15 #include "sync/engine/syncer.h" |   15 #include "sync/engine/syncer.h" | 
|   16 #include "sync/engine/syncer_util.h" |   16 #include "sync/engine/syncer_util.h" | 
|   17 #include "sync/sessions/status_controller.h" |   17 #include "sync/sessions/status_controller.h" | 
|   18 #include "sync/syncable/directory.h" |   18 #include "sync/syncable/directory.h" | 
|   19 #include "sync/syncable/mutable_entry.h" |   19 #include "sync/syncable/mutable_entry.h" | 
|   20 #include "sync/syncable/nigori_handler.h" |   20 #include "sync/syncable/nigori_handler.h" | 
|   21 #include "sync/syncable/write_transaction.h" |   21 #include "sync/syncable/write_transaction.h" | 
|   22 #include "sync/util/cryptographer.h" |   22 #include "sync/util/cryptographer.h" | 
|   23  |   23  | 
|   24 using std::list; |   24 using std::list; | 
|   25 using std::map; |   25 using std::map; | 
|   26 using std::set; |   26 using std::set; | 
|   27  |   27  | 
|   28 namespace syncer { |   28 namespace syncer { | 
|   29  |   29  | 
|   30 using sessions::ConflictProgress; |  | 
|   31 using sessions::StatusController; |   30 using sessions::StatusController; | 
|   32 using syncable::BaseTransaction; |   31 using syncable::BaseTransaction; | 
|   33 using syncable::Directory; |   32 using syncable::Directory; | 
|   34 using syncable::Entry; |   33 using syncable::Entry; | 
|   35 using syncable::Id; |   34 using syncable::Id; | 
|   36 using syncable::MutableEntry; |   35 using syncable::MutableEntry; | 
|   37 using syncable::WriteTransaction; |   36 using syncable::WriteTransaction; | 
|   38  |   37  | 
|   39 namespace { |   38 namespace { | 
|   40  |   39  | 
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  284             entry.Get(syncable::META_HANDLE)) |  283             entry.Get(syncable::META_HANDLE)) | 
|  285           << server_update << entry; |  284           << server_update << entry; | 
|  286       UMA_HISTOGRAM_ENUMERATION("Sync.ResolveSimpleConflict", |  285       UMA_HISTOGRAM_ENUMERATION("Sync.ResolveSimpleConflict", | 
|  287                                 UNDELETE, |  286                                 UNDELETE, | 
|  288                                 CONFLICT_RESOLUTION_SIZE); |  287                                 CONFLICT_RESOLUTION_SIZE); | 
|  289     } |  288     } | 
|  290     return SYNC_PROGRESS; |  289     return SYNC_PROGRESS; | 
|  291   } |  290   } | 
|  292 } |  291 } | 
|  293  |  292  | 
|  294 bool ConflictResolver::ResolveConflicts(syncable::WriteTransaction* trans, |  293 bool ConflictResolver::ResolveConflicts( | 
|  295                                         const Cryptographer* cryptographer, |  294     syncable::WriteTransaction* trans, | 
|  296                                         const ConflictProgress& progress, |  295     const Cryptographer* cryptographer, | 
|  297                                         sessions::StatusController* status) { |  296     const std::set<syncable::Id>& simple_conflict_ids, | 
 |  297     sessions::StatusController* status) { | 
|  298   bool forward_progress = false; |  298   bool forward_progress = false; | 
|  299   // Iterate over simple conflict items. |  299   // Iterate over simple conflict items. | 
|  300   set<Id>::const_iterator conflicting_item_it; |  300   set<Id>::const_iterator conflicting_item_it; | 
|  301   set<Id> processed_items; |  301   set<Id> processed_items; | 
|  302   for (conflicting_item_it = progress.SimpleConflictingItemsBegin(); |  302   for (conflicting_item_it = simple_conflict_ids.begin(); | 
|  303        conflicting_item_it != progress.SimpleConflictingItemsEnd(); |  303        conflicting_item_it != simple_conflict_ids.end(); | 
|  304        ++conflicting_item_it) { |  304        ++conflicting_item_it) { | 
|  305     Id id = *conflicting_item_it; |  305     Id id = *conflicting_item_it; | 
|  306     if (processed_items.count(id) > 0) |  306     if (processed_items.count(id) > 0) | 
|  307       continue; |  307       continue; | 
|  308  |  308  | 
|  309     // We don't resolve conflicts for control types here. |  309     // We don't resolve conflicts for control types here. | 
|  310     Entry conflicting_node(trans, syncable::GET_BY_ID, id); |  310     Entry conflicting_node(trans, syncable::GET_BY_ID, id); | 
|  311     CHECK(conflicting_node.good()); |  311     CHECK(conflicting_node.good()); | 
|  312     if (IsControlType( |  312     if (IsControlType( | 
|  313         GetModelTypeFromSpecifics(conflicting_node.Get(syncable::SPECIFICS)))) { |  313         GetModelTypeFromSpecifics(conflicting_node.Get(syncable::SPECIFICS)))) { | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  324     do { |  324     do { | 
|  325       predecessors.push_back(prev_id); |  325       predecessors.push_back(prev_id); | 
|  326       Entry entry(trans, syncable::GET_BY_ID, prev_id); |  326       Entry entry(trans, syncable::GET_BY_ID, prev_id); | 
|  327       // Any entry in conflict must be valid. |  327       // Any entry in conflict must be valid. | 
|  328       CHECK(entry.good()); |  328       CHECK(entry.good()); | 
|  329       Id new_prev_id = entry.Get(syncable::PREV_ID); |  329       Id new_prev_id = entry.Get(syncable::PREV_ID); | 
|  330       if (new_prev_id == prev_id) |  330       if (new_prev_id == prev_id) | 
|  331         break; |  331         break; | 
|  332       prev_id = new_prev_id; |  332       prev_id = new_prev_id; | 
|  333     } while (processed_items.count(prev_id) == 0 && |  333     } while (processed_items.count(prev_id) == 0 && | 
|  334              progress.HasSimpleConflictItem(prev_id));  // Excludes root. |  334              simple_conflict_ids.count(prev_id) > 0);  // Excludes root. | 
|  335     while (!predecessors.empty()) { |  335     while (!predecessors.empty()) { | 
|  336       id = predecessors.back(); |  336       id = predecessors.back(); | 
|  337       predecessors.pop_back(); |  337       predecessors.pop_back(); | 
|  338       switch (ProcessSimpleConflict(trans, id, cryptographer, status)) { |  338       switch (ProcessSimpleConflict(trans, id, cryptographer, status)) { | 
|  339         case NO_SYNC_PROGRESS: |  339         case NO_SYNC_PROGRESS: | 
|  340           break; |  340           break; | 
|  341         case SYNC_PROGRESS: |  341         case SYNC_PROGRESS: | 
|  342           forward_progress = true; |  342           forward_progress = true; | 
|  343           break; |  343           break; | 
|  344       } |  344       } | 
|  345       processed_items.insert(id); |  345       processed_items.insert(id); | 
|  346     } |  346     } | 
|  347   } |  347   } | 
|  348   return forward_progress; |  348   return forward_progress; | 
|  349 } |  349 } | 
|  350  |  350  | 
|  351 }  // namespace syncer |  351 }  // namespace syncer | 
| OLD | NEW |