• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // A class that watches the syncer and attempts to resolve any conflicts that
6 // occur.
7 
8 #ifndef SYNC_ENGINE_CONFLICT_RESOLVER_H_
9 #define SYNC_ENGINE_CONFLICT_RESOLVER_H_
10 
11 #include <set>
12 
13 #include "base/basictypes.h"
14 #include "base/gtest_prod_util.h"
15 #include "sync/engine/syncer_types.h"
16 
17 namespace syncer {
18 
19 namespace syncable {
20 class Id;
21 class WriteTransaction;
22 }  // namespace syncable
23 
24 class Cryptographer;
25 
26 namespace sessions {
27 class StatusController;
28 }  // namespace sessions
29 
30 class ConflictResolver {
31   friend class SyncerTest;
32   FRIEND_TEST_ALL_PREFIXES(SyncerTest,
33                            ConflictResolverMergeOverwritesLocalEntry);
34  public:
35   // Enumeration of different conflict resolutions. Used for histogramming.
36   enum SimpleConflictResolutions {
37     OVERWRITE_LOCAL,           // Resolved by overwriting local changes.
38     OVERWRITE_SERVER,          // Resolved by overwriting server changes.
39     UNDELETE,                  // Resolved by undeleting local item.
40     IGNORE_ENCRYPTION,         // Resolved by ignoring an encryption-only server
41                                // change.
42     NIGORI_MERGE,              // Resolved by merging nigori nodes.
43     CHANGES_MATCH,             // Resolved by ignoring both local and server
44                                // changes because they matched.
45     CONFLICT_RESOLUTION_SIZE,
46   };
47 
48   ConflictResolver();
49   ~ConflictResolver();
50   // Called by the syncer at the end of a update/commit cycle.
51   // Returns true if the syncer should try to apply its updates again.
52   void ResolveConflicts(syncable::WriteTransaction* trans,
53                         const Cryptographer* cryptographer,
54                         const std::set<syncable::Id>& simple_conflict_ids,
55                         sessions::StatusController* status);
56 
57  private:
58   void ProcessSimpleConflict(
59       syncable::WriteTransaction* trans,
60       const syncable::Id& id,
61       const Cryptographer* cryptographer,
62       sessions::StatusController* status);
63 
64   DISALLOW_COPY_AND_ASSIGN(ConflictResolver);
65 };
66 
67 }  // namespace syncer
68 
69 #endif  // SYNC_ENGINE_CONFLICT_RESOLVER_H_
70