| 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 |
| 11 #ifndef SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 11 #ifndef SYNC_ENGINE_UPDATE_APPLICATOR_H_ |
| 12 #define SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 12 #define SYNC_ENGINE_UPDATE_APPLICATOR_H_ |
| 13 | 13 |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/port.h" | 17 #include "base/port.h" |
| 18 #include "sync/internal_api/public/engine/model_safe_worker.h" | 18 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 19 #include "sync/syncable/syncable_id.h" | 19 #include "sync/syncable/syncable_id.h" |
| 20 #include "sync/sessions/status_controller.h" |
| 20 | 21 |
| 21 namespace syncer { | 22 namespace syncer { |
| 22 | 23 |
| 23 namespace sessions { | 24 namespace sessions { |
| 24 class ConflictProgress; | 25 class StatusController; |
| 25 class UpdateProgress; | |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace syncable { | 28 namespace syncable { |
| 29 class WriteTransaction; | 29 class WriteTransaction; |
| 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 std::vector<int64> to_apply, |
| 51 bool AllUpdatesApplied() const; | 48 std::set<syncable::Id>* simple_conflict_ids); |
| 52 | 49 |
| 53 // This class does not automatically save its progress into the | 50 // Save our internal stat counters to the StatusController. |
| 54 // SyncSession -- to get that to happen, call this method after update | 51 void SaveStats(sessions::StatusController* status); |
| 55 // application is finished (i.e., when AttemptOneAllocation stops returning | |
| 56 // true). | |
| 57 void SaveProgressIntoSessionState( | |
| 58 sessions::ConflictProgress* conflict_progress, | |
| 59 sessions::UpdateProgress* update_progress); | |
| 60 | 52 |
| 61 private: | 53 private: |
| 62 // Track the status of all applications. | |
| 63 class ResultTracker { | |
| 64 public: | |
| 65 explicit ResultTracker(size_t num_results); | |
| 66 virtual ~ResultTracker(); | |
| 67 void AddSimpleConflict(syncable::Id); | |
| 68 void AddEncryptionConflict(syncable::Id); | |
| 69 void AddHierarchyConflict(syncable::Id); | |
| 70 void AddSuccess(syncable::Id); | |
| 71 void SaveProgress(sessions::ConflictProgress* conflict_progress, | |
| 72 sessions::UpdateProgress* update_progress); | |
| 73 void ClearConflicts(); | |
| 74 | |
| 75 // Returns true iff conflicting_ids_ is empty. Does not check | |
| 76 // encryption_conflict_ids_. | |
| 77 bool no_conflicts() const; | |
| 78 private: | |
| 79 std::vector<syncable::Id> conflicting_ids_; | |
| 80 std::vector<syncable::Id> successful_ids_; | |
| 81 std::vector<syncable::Id> encryption_conflict_ids_; | |
| 82 std::vector<syncable::Id> hierarchy_conflict_ids_; | |
| 83 }; | |
| 84 | |
| 85 // If true, AttemptOneApplication will skip over |entry| and return true. | 54 // If true, AttemptOneApplication will skip over |entry| and return true. |
| 86 bool SkipUpdate(const syncable::Entry& entry); | 55 bool SkipUpdate(const syncable::Entry& entry); |
| 87 | 56 |
| 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. | 57 // Used to decrypt sensitive sync nodes. |
| 95 Cryptographer* cryptographer_; | 58 Cryptographer* cryptographer_; |
| 96 | 59 |
| 97 UpdateIterator const begin_; | |
| 98 UpdateIterator end_; | |
| 99 UpdateIterator pointer_; | |
| 100 ModelSafeGroup group_filter_; | 60 ModelSafeGroup group_filter_; |
| 101 bool progress_; | |
| 102 | 61 |
| 103 const ModelSafeRoutingInfo routing_info_; | 62 const ModelSafeRoutingInfo routing_info_; |
| 104 | 63 |
| 105 // Track the result of the attempts to update applications. | 64 DISALLOW_COPY_AND_ASSIGN(UpdateApplicator); |
| 106 ResultTracker application_results_; | |
| 107 | 65 |
| 108 DISALLOW_COPY_AND_ASSIGN(UpdateApplicator); | 66 int updates_applied_; |
| 67 int encryption_conflicts_; |
| 68 int hierarchy_conflicts_; |
| 109 }; | 69 }; |
| 110 | 70 |
| 111 } // namespace syncer | 71 } // namespace syncer |
| 112 | 72 |
| 113 #endif // SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 73 #endif // SYNC_ENGINE_UPDATE_APPLICATOR_H_ |
| OLD | NEW |