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
9namespace syncer {
10
11using syncable::BASE_VERSION;
12using syncable::IS_UNAPPLIED_UPDATE;
13using syncable::IS_UNSYNCED;
14using syncable::SERVER_VERSION;
15
16using syncable::MutableEntry;
17
18namespace conflict_util {
19
20// Allow the server's changes to take precedence.
21// This will take effect during the next ApplyUpdates step.
22void IgnoreLocalChanges(MutableEntry* entry) {
23  DCHECK(entry->GetIsUnsynced());
24  DCHECK(entry->GetIsUnappliedUpdate());
25  entry->PutIsUnsynced(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.
31void OverwriteServerChanges(MutableEntry* entry) {
32  DCHECK(entry->GetIsUnsynced());
33  DCHECK(entry->GetIsUnappliedUpdate());
34  entry->PutBaseVersion(entry->GetServerVersion());
35  entry->PutIsUnappliedUpdate(false);
36}
37
38// Having determined that everything matches, we ignore the non-conflict.
39void 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->GetIsUnsynced());
47  DCHECK(entry->GetIsUnappliedUpdate());
48  entry->PutBaseVersion(entry->GetServerVersion());
49  entry->PutIsUnappliedUpdate(false);
50  entry->PutIsUnsynced(false);
51}
52
53}  // namespace conflict_util
54}  // namespace syncer
55