OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <list> | 7 #include <list> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // same are supported due to the predecessor->successor ordering. In this | 133 // same are supported due to the predecessor->successor ordering. In this |
134 // case, from the first item onward, we unset the UNSYNCED/UNAPPLIED bits as | 134 // case, from the first item onward, we unset the UNSYNCED/UNAPPLIED bits as |
135 // we decide that nothing changed. The subsequent item's server prev id will | 135 // we decide that nothing changed. The subsequent item's server prev id will |
136 // accurately match the local prev id because the predecessor is no longer | 136 // accurately match the local prev id because the predecessor is no longer |
137 // UNSYNCED/UNAPPLIED. | 137 // UNSYNCED/UNAPPLIED. |
138 // TODO(zea): simplify all this once we can directly compare server position | 138 // TODO(zea): simplify all this once we can directly compare server position |
139 // to client position. | 139 // to client position. |
140 syncable::Id server_prev_id = entry.ComputePrevIdFromServerPosition( | 140 syncable::Id server_prev_id = entry.ComputePrevIdFromServerPosition( |
141 entry.Get(syncable::SERVER_PARENT_ID)); | 141 entry.Get(syncable::SERVER_PARENT_ID)); |
142 bool needs_reinsertion = !parent_matches || | 142 bool needs_reinsertion = !parent_matches || |
143 server_prev_id != entry.Get(syncable::PREV_ID); | 143 server_prev_id != entry.GetPredecessorId(); |
144 DVLOG_IF(1, needs_reinsertion) << "Insertion needed, server prev id " | 144 DVLOG_IF(1, needs_reinsertion) << "Insertion needed, server prev id " |
145 << " is " << server_prev_id << ", local prev id is " | 145 << " is " << server_prev_id << ", local prev id is " |
146 << entry.Get(syncable::PREV_ID); | 146 << entry.GetPredecessorId(); |
147 const sync_pb::EntitySpecifics& specifics = | 147 const sync_pb::EntitySpecifics& specifics = |
148 entry.Get(syncable::SPECIFICS); | 148 entry.Get(syncable::SPECIFICS); |
149 const sync_pb::EntitySpecifics& server_specifics = | 149 const sync_pb::EntitySpecifics& server_specifics = |
150 entry.Get(syncable::SERVER_SPECIFICS); | 150 entry.Get(syncable::SERVER_SPECIFICS); |
151 const sync_pb::EntitySpecifics& base_server_specifics = | 151 const sync_pb::EntitySpecifics& base_server_specifics = |
152 entry.Get(syncable::BASE_SERVER_SPECIFICS); | 152 entry.Get(syncable::BASE_SERVER_SPECIFICS); |
153 std::string decrypted_specifics, decrypted_server_specifics; | 153 std::string decrypted_specifics, decrypted_server_specifics; |
154 bool specifics_match = false; | 154 bool specifics_match = false; |
155 bool server_encrypted_with_default_key = false; | 155 bool server_encrypted_with_default_key = false; |
156 if (specifics.has_encrypted()) { | 156 if (specifics.has_encrypted()) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 // backwards through all continuous conflicting predecessors, building a | 281 // backwards through all continuous conflicting predecessors, building a |
282 // stack of items to resolve in predecessor->successor order, then process | 282 // stack of items to resolve in predecessor->successor order, then process |
283 // each item individually. | 283 // each item individually. |
284 list<Id> predecessors; | 284 list<Id> predecessors; |
285 Id prev_id = id; | 285 Id prev_id = id; |
286 do { | 286 do { |
287 predecessors.push_back(prev_id); | 287 predecessors.push_back(prev_id); |
288 Entry entry(trans, syncable::GET_BY_ID, prev_id); | 288 Entry entry(trans, syncable::GET_BY_ID, prev_id); |
289 // Any entry in conflict must be valid. | 289 // Any entry in conflict must be valid. |
290 CHECK(entry.good()); | 290 CHECK(entry.good()); |
291 Id new_prev_id = entry.Get(syncable::PREV_ID); | 291 Id new_prev_id = entry.GetPredecessorId(); |
292 if (new_prev_id == prev_id) | 292 if (new_prev_id == prev_id) |
293 break; | 293 break; |
294 prev_id = new_prev_id; | 294 prev_id = new_prev_id; |
295 } while (processed_items.count(prev_id) == 0 && | 295 } while (processed_items.count(prev_id) == 0 && |
296 simple_conflict_ids.count(prev_id) > 0); // Excludes root. | 296 simple_conflict_ids.count(prev_id) > 0); // Excludes root. |
297 while (!predecessors.empty()) { | 297 while (!predecessors.empty()) { |
298 id = predecessors.back(); | 298 id = predecessors.back(); |
299 predecessors.pop_back(); | 299 predecessors.pop_back(); |
300 ProcessSimpleConflict(trans, id, cryptographer, status); | 300 ProcessSimpleConflict(trans, id, cryptographer, status); |
301 processed_items.insert(id); | 301 processed_items.insert(id); |
302 } | 302 } |
303 } | 303 } |
304 return; | 304 return; |
305 } | 305 } |
306 | 306 |
307 } // namespace syncer | 307 } // namespace syncer |
OLD | NEW |