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