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 3 // found in the LICENSE file. 4 5 #include "sync/engine/conflict_util.h" 6 7 #include "sync/syncable/mutable_entry.h" 8 9 namespace syncer { 10 11 using syncable::BASE_VERSION; 12 using syncable::IS_UNAPPLIED_UPDATE; 13 using syncable::IS_UNSYNCED; 14 using syncable::SERVER_VERSION; 15 16 using syncable::MutableEntry; 17 18 namespace conflict_util { 19 20 // Allow the server's changes to take precedence. 21 // This will take effect during the next ApplyUpdates step. 22 void IgnoreLocalChanges(MutableEntry* entry) { 23 DCHECK(entry->Get(IS_UNSYNCED)); 24 DCHECK(entry->Get(IS_UNAPPLIED_UPDATE)); 25 entry->Put(IS_UNSYNCED, false); 26 } 27 28 // Overwrite the server with our own value. 29 // We will commit our local data, overwriting the server, at the next 30 // opportunity. 31 void OverwriteServerChanges(MutableEntry* entry) { 32 DCHECK(entry->Get(IS_UNSYNCED)); 33 DCHECK(entry->Get(IS_UNAPPLIED_UPDATE)); 34 entry->Put(BASE_VERSION, entry->Get(SERVER_VERSION)); 35 entry->Put(IS_UNAPPLIED_UPDATE, false); 36 } 37 38 // Having determined that everything matches, we ignore the non-conflict. 39 void IgnoreConflict(MutableEntry* entry) { 40 // If we didn't also unset IS_UNAPPLIED_UPDATE, then we would lose unsynced 41 // positional data from adjacent entries when the server update gets applied 42 // and the item is re-inserted into the PREV_ID/NEXT_ID linked list. This is 43 // primarily an issue because we commit after applying updates, and is most 44 // commonly seen when positional changes are made while a passphrase is 45 // required (and hence there will be many encryption conflicts). 46 DCHECK(entry->Get(IS_UNSYNCED)); 47 DCHECK(entry->Get(IS_UNAPPLIED_UPDATE)); 48 entry->Put(BASE_VERSION, entry->Get(SERVER_VERSION)); 49 entry->Put(IS_UNAPPLIED_UPDATE, false); 50 entry->Put(IS_UNSYNCED, false); 51 } 52 53 } // namespace conflict_util 54 } // namespace syncer 55