OLD | NEW |
| (Empty) |
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 // An UpdateApplicator is used to iterate over a number of unapplied updates, | |
6 // applying them to the client using the given syncer session. | |
7 // | |
8 // UpdateApplicator might resemble an iterator, but it actually keeps retrying | |
9 // failed updates until no remaining updates can be successfully applied. | |
10 | |
11 #ifndef CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ | |
12 #define CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ | |
13 #pragma once | |
14 | |
15 #include <vector> | |
16 | |
17 #include "base/basictypes.h" | |
18 #include "base/port.h" | |
19 #include "chrome/browser/sync/engine/model_safe_worker.h" | |
20 #include "chrome/browser/sync/syncable/syncable.h" | |
21 | |
22 namespace browser_sync { | |
23 | |
24 namespace sessions { | |
25 class ConflictProgress; | |
26 class UpdateProgress; | |
27 } | |
28 | |
29 class ConflictResolver; | |
30 class Cryptographer; | |
31 | |
32 class UpdateApplicator { | |
33 public: | |
34 typedef syncable::Directory::UnappliedUpdateMetaHandles::iterator | |
35 UpdateIterator; | |
36 | |
37 UpdateApplicator(ConflictResolver* resolver, | |
38 Cryptographer* cryptographer, | |
39 const UpdateIterator& begin, | |
40 const UpdateIterator& end, | |
41 const ModelSafeRoutingInfo& routes, | |
42 ModelSafeGroup group_filter); | |
43 ~UpdateApplicator(); | |
44 | |
45 // returns true if there's more we can do. | |
46 bool AttemptOneApplication(syncable::WriteTransaction* trans); | |
47 // return true if we've applied all updates. | |
48 bool AllUpdatesApplied() const; | |
49 | |
50 // This class does not automatically save its progress into the | |
51 // SyncSession -- to get that to happen, call this method after update | |
52 // application is finished (i.e., when AttemptOneAllocation stops returning | |
53 // true). | |
54 void SaveProgressIntoSessionState( | |
55 sessions::ConflictProgress* conflict_progress, | |
56 sessions::UpdateProgress* update_progress); | |
57 | |
58 private: | |
59 // Track the status of all applications. | |
60 class ResultTracker { | |
61 public: | |
62 explicit ResultTracker(size_t num_results); | |
63 virtual ~ResultTracker(); | |
64 void AddSimpleConflict(syncable::Id); | |
65 void AddEncryptionConflict(syncable::Id); | |
66 void AddHierarchyConflict(syncable::Id); | |
67 void AddSuccess(syncable::Id); | |
68 void SaveProgress(sessions::ConflictProgress* conflict_progress, | |
69 sessions::UpdateProgress* update_progress); | |
70 void ClearConflicts(); | |
71 | |
72 // Returns true iff conflicting_ids_ is empty. Does not check | |
73 // encryption_conflict_ids_. | |
74 bool no_conflicts() const; | |
75 private: | |
76 std::vector<syncable::Id> conflicting_ids_; | |
77 std::vector<syncable::Id> successful_ids_; | |
78 std::vector<syncable::Id> encryption_conflict_ids_; | |
79 std::vector<syncable::Id> hierarchy_conflict_ids_; | |
80 }; | |
81 | |
82 // If true, AttemptOneApplication will skip over |entry| and return true. | |
83 bool SkipUpdate(const syncable::Entry& entry); | |
84 | |
85 // Adjusts the UpdateIterator members to move ahead by one update. | |
86 void Advance(); | |
87 | |
88 // Used to resolve conflicts when trying to apply updates. | |
89 ConflictResolver* const resolver_; | |
90 | |
91 // Used to decrypt sensitive sync nodes. | |
92 Cryptographer* cryptographer_; | |
93 | |
94 UpdateIterator const begin_; | |
95 UpdateIterator end_; | |
96 UpdateIterator pointer_; | |
97 ModelSafeGroup group_filter_; | |
98 bool progress_; | |
99 | |
100 const ModelSafeRoutingInfo routing_info_; | |
101 | |
102 // Track the result of the attempts to update applications. | |
103 ResultTracker application_results_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(UpdateApplicator); | |
106 }; | |
107 | |
108 } // namespace browser_sync | |
109 | |
110 #endif // CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ | |
OLD | NEW |