Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: chrome/browser/sync/engine/conflict_resolver.h

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 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 CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_
9 #define CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_
10
11 #include <list>
12 #include <vector>
13
14 #include "base/basictypes.h"
15 #include "chrome/browser/sync/engine/conflict_resolution_view.h"
16 #include "chrome/browser/sync/engine/syncer_session.h"
17 #include "chrome/browser/sync/engine/syncer_status.h"
18 #include "chrome/browser/sync/engine/syncer_types.h"
19 #include "chrome/browser/sync/util/event_sys.h"
20 #include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST
21
22 namespace syncable {
23 class BaseTransaction;
24 class Id;
25 class MutableEntry;
26 class ScopedDirLookup;
27 class WriteTransaction;
28 } // namespace syncable
29
30 namespace browser_sync {
31
32 class ConflictResolver {
33 friend class SyncerTest;
34 FRIEND_TEST(SyncerTest, ConflictResolverMergeOverwritesLocalEntry);
35 public:
36 ConflictResolver();
37 ~ConflictResolver();
38 // Called by the syncer at the end of a update/commit cycle.
39 // Returns true if the syncer should try to apply its updates again.
40 bool ResolveConflicts(const syncable::ScopedDirLookup& dir,
41 ConflictResolutionView* view,
42 SyncerSession *session);
idana 2009/09/10 05:44:37 nit: "SyncerSession *session" -> "SyncerSession* s
43
44 // Called by ProcessServerClientNameClash. Returns true if it's merged the
45 // items, false otherwise. Does not re-check preconditions covered in
46 // ProcessServerClientNameClash (i.e. it assumes a name clash).
47 bool AttemptItemMerge(syncable::WriteTransaction* trans,
48 syncable::MutableEntry* local_entry,
49 syncable::MutableEntry* server_entry);
50
51 private:
52 // We keep a map to record how often we've seen each conflict set. We use this
53 // to screen out false positives caused by transient server or client states,
54 // and to allow us to try to make smaller changes to fix situations before
55 // moving onto more drastic solutions.
56 typedef std::string ConflictSetCountMapKey;
57 typedef std::map<ConflictSetCountMapKey, int> ConflictSetCountMap;
58 typedef std::map<syncable::Id, int> SimpleConflictCountMap;
59
60 enum ProcessSimpleConflictResult {
61 NO_SYNC_PROGRESS, // No changes to advance syncing made.
62 SYNC_PROGRESS, // Progress made.
63 };
64
65 enum ServerClientNameClashReturn {
66 NO_CLASH,
67 SOLUTION_DEFERRED,
68 SOLVED,
69 BOGUS_SET,
70 };
71
72 // Get a key for the given set. NB: May reorder set contents.
73 // The key is currently not very efficient, but will ease debugging.
74 ConflictSetCountMapKey GetSetKey(ConflictSet* conflict_set);
75
76 void IgnoreLocalChanges(syncable::MutableEntry * entry);
77 void OverwriteServerChanges(syncable::WriteTransaction* trans,
78 syncable::MutableEntry* entry);
79
80 ProcessSimpleConflictResult ProcessSimpleConflict(
81 syncable::WriteTransaction* trans,
82 syncable::Id id,
83 SyncerSession* session);
84
85 bool ResolveSimpleConflicts(const syncable::ScopedDirLookup& dir,
86 ConflictResolutionView* view,
87 SyncerSession* session);
88
89 bool ProcessConflictSet(syncable::WriteTransaction* trans,
90 ConflictSet* conflict_set,
91 int conflict_count,
92 SyncerSession* session);
93
94 // Gives any unsynced entries in the given set new names if possible.
95 bool RenameUnsyncedEntries(syncable::WriteTransaction* trans,
96 ConflictSet* conflict_set);
97
98 ServerClientNameClashReturn ProcessServerClientNameClash(
99 syncable::WriteTransaction* trans,
100 syncable::MutableEntry* locally_named,
101 syncable::MutableEntry* server_named,
102 SyncerSession* session);
103 ServerClientNameClashReturn ProcessNameClashesInSet(
104 syncable::WriteTransaction* trans,
105 ConflictSet* conflict_set,
106 SyncerSession* session);
107
108 // Returns true if we're stuck
109 template <typename InputIt>
110 bool LogAndSignalIfConflictStuck(syncable::BaseTransaction* trans,
111 int attempt_count,
112 InputIt start, InputIt end,
113 ConflictResolutionView* view);
114
115 ConflictSetCountMap conflict_set_count_map_;
116 SimpleConflictCountMap simple_conflict_count_map_;
117
118 // Contains the ids of uncommitted items that are children of entries merged
119 // in the previous cycle. This is used to speed up the merge resolution of
120 // deep trees. Used to happen in store refresh.
121 // TODO(chron): Can we get rid of this optimization?
122 std::set<syncable::Id> children_of_merged_dirs_;
123
124 DISALLOW_COPY_AND_ASSIGN(ConflictResolver);
125 };
126
127 } // namespace browser_sync
128
129 #endif // CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698