| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // A class that watches the syncer and attempts to resolve any conflicts that | 5 // A class that watches the syncer and attempts to resolve any conflicts that |
| 6 // occur. | 6 // occur. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_ | 8 #ifndef CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_ |
| 9 #define CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_ | 9 #define CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_ |
| 10 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "chrome/browser/sync/engine/syncer_types.h" | 18 #include "chrome/browser/sync/engine/syncer_types.h" |
| 19 | 19 |
| 20 namespace syncable { | 20 namespace syncable { |
| 21 class BaseTransaction; | 21 class BaseTransaction; |
| 22 class Id; | 22 class Id; |
| 23 class MutableEntry; | 23 class MutableEntry; |
| 24 class ScopedDirLookup; | 24 class ScopedDirLookup; |
| 25 class WriteTransaction; | 25 class WriteTransaction; |
| 26 } // namespace syncable | 26 } // namespace syncable |
| 27 | 27 |
| 28 namespace browser_sync { | 28 namespace browser_sync { |
| 29 |
| 29 namespace sessions { | 30 namespace sessions { |
| 31 class ConflictProgress; |
| 30 class StatusController; | 32 class StatusController; |
| 31 } | 33 } // namespace sessions |
| 32 | 34 |
| 33 class ConflictResolver { | 35 class ConflictResolver { |
| 34 friend class SyncerTest; | 36 friend class SyncerTest; |
| 35 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 37 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
| 36 ConflictResolverMergeOverwritesLocalEntry); | 38 ConflictResolverMergeOverwritesLocalEntry); |
| 37 public: | 39 public: |
| 38 ConflictResolver(); | 40 ConflictResolver(); |
| 39 ~ConflictResolver(); | 41 ~ConflictResolver(); |
| 40 // Called by the syncer at the end of a update/commit cycle. | 42 // Called by the syncer at the end of a update/commit cycle. |
| 41 // Returns true if the syncer should try to apply its updates again. | 43 // Returns true if the syncer should try to apply its updates again. |
| 42 bool ResolveConflicts(const syncable::ScopedDirLookup& dir, | 44 bool ResolveConflicts(const syncable::ScopedDirLookup& dir, |
| 45 const sessions::ConflictProgress& progress, |
| 43 sessions::StatusController* status); | 46 sessions::StatusController* status); |
| 44 | 47 |
| 45 private: | 48 private: |
| 46 // We keep a map to record how often we've seen each conflict set. We use this | 49 // We keep a map to record how often we've seen each conflict set. We use this |
| 47 // to screen out false positives caused by transient server or client states, | 50 // to screen out false positives caused by transient server or client states, |
| 48 // and to allow us to try to make smaller changes to fix situations before | 51 // and to allow us to try to make smaller changes to fix situations before |
| 49 // moving onto more drastic solutions. | 52 // moving onto more drastic solutions. |
| 50 typedef std::string ConflictSetCountMapKey; | 53 typedef std::string ConflictSetCountMapKey; |
| 51 typedef std::map<ConflictSetCountMapKey, int> ConflictSetCountMap; | 54 typedef std::map<ConflictSetCountMapKey, int> ConflictSetCountMap; |
| 52 typedef std::map<syncable::Id, int> SimpleConflictCountMap; | 55 typedef std::map<syncable::Id, int> SimpleConflictCountMap; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 void IgnoreLocalChanges(syncable::MutableEntry* entry); | 66 void IgnoreLocalChanges(syncable::MutableEntry* entry); |
| 64 void OverwriteServerChanges(syncable::WriteTransaction* trans, | 67 void OverwriteServerChanges(syncable::WriteTransaction* trans, |
| 65 syncable::MutableEntry* entry); | 68 syncable::MutableEntry* entry); |
| 66 | 69 |
| 67 ProcessSimpleConflictResult ProcessSimpleConflict( | 70 ProcessSimpleConflictResult ProcessSimpleConflict( |
| 68 syncable::WriteTransaction* trans, | 71 syncable::WriteTransaction* trans, |
| 69 const syncable::Id& id, | 72 const syncable::Id& id, |
| 70 sessions::StatusController* status); | 73 sessions::StatusController* status); |
| 71 | 74 |
| 72 bool ResolveSimpleConflicts(const syncable::ScopedDirLookup& dir, | 75 bool ResolveSimpleConflicts(const syncable::ScopedDirLookup& dir, |
| 76 const sessions::ConflictProgress& progress, |
| 73 sessions::StatusController* status); | 77 sessions::StatusController* status); |
| 74 | 78 |
| 75 bool ProcessConflictSet(syncable::WriteTransaction* trans, | 79 bool ProcessConflictSet(syncable::WriteTransaction* trans, |
| 76 ConflictSet* conflict_set, | 80 ConflictSet* conflict_set, |
| 77 int conflict_count); | 81 int conflict_count); |
| 78 | 82 |
| 79 // Returns true if we're stuck. | 83 // Returns true if we're stuck. |
| 80 template <typename InputIt> | 84 template <typename InputIt> |
| 81 bool LogAndSignalIfConflictStuck(syncable::BaseTransaction* trans, | 85 bool LogAndSignalIfConflictStuck(syncable::BaseTransaction* trans, |
| 82 int attempt_count, | 86 int attempt_count, |
| 83 InputIt start, InputIt end, | 87 InputIt start, InputIt end, |
| 84 sessions::StatusController* status); | 88 sessions::StatusController* status); |
| 85 | 89 |
| 86 ConflictSetCountMap conflict_set_count_map_; | 90 ConflictSetCountMap conflict_set_count_map_; |
| 87 SimpleConflictCountMap simple_conflict_count_map_; | 91 SimpleConflictCountMap simple_conflict_count_map_; |
| 88 | 92 |
| 89 DISALLOW_COPY_AND_ASSIGN(ConflictResolver); | 93 DISALLOW_COPY_AND_ASSIGN(ConflictResolver); |
| 90 }; | 94 }; |
| 91 | 95 |
| 92 } // namespace browser_sync | 96 } // namespace browser_sync |
| 93 | 97 |
| 94 #endif // CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_ | 98 #endif // CHROME_BROWSER_SYNC_ENGINE_CONFLICT_RESOLVER_H_ |
| OLD | NEW |