| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 11 #ifndef CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ |
| 12 #define CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 12 #define CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ |
| 13 | 13 |
| 14 #include <set> | 14 #include <set> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/port.h" | 18 #include "base/port.h" |
| 19 | 19 #include "chrome/browser/sync/syncable/syncable.h" |
| 20 namespace syncable { | |
| 21 class Id; | |
| 22 class WriteTransaction; | |
| 23 } // namespace syncable | |
| 24 | 20 |
| 25 namespace browser_sync { | 21 namespace browser_sync { |
| 26 | 22 |
| 23 class ConflictResolver; |
| 27 class SyncerSession; | 24 class SyncerSession; |
| 28 | 25 |
| 29 class UpdateApplicator { | 26 class UpdateApplicator { |
| 30 public: | 27 public: |
| 31 typedef std::vector<int64>::iterator vi64iter; | 28 typedef syncable::Directory::UnappliedUpdateMetaHandles::iterator |
| 29 UpdateIterator; |
| 32 | 30 |
| 33 UpdateApplicator(SyncerSession* session, const vi64iter& begin, | 31 UpdateApplicator(ConflictResolver* resolver, |
| 34 const vi64iter& end); | 32 const UpdateIterator& begin, |
| 33 const UpdateIterator& end); |
| 34 |
| 35 // returns true if there's more we can do. | 35 // returns true if there's more we can do. |
| 36 bool AttemptOneApplication(syncable::WriteTransaction* trans); | 36 bool AttemptOneApplication(syncable::WriteTransaction* trans); |
| 37 // return true if we've applied all updates. | 37 // return true if we've applied all updates. |
| 38 bool AllUpdatesApplied() const; | 38 bool AllUpdatesApplied() const; |
| 39 | 39 |
| 40 // This class does not automatically save its progress into the | 40 // This class does not automatically save its progress into the |
| 41 // SyncerSession -- to get that to happen, call this method after update | 41 // SyncerSession -- to get that to happen, call this method after update |
| 42 // application is finished (i.e., when AttemptOneAllocation stops returning | 42 // application is finished (i.e., when AttemptOneAllocation stops returning |
| 43 // true). | 43 // true). |
| 44 void SaveProgressIntoSessionState(); | 44 void SaveProgressIntoSessionState(SyncerSession* session); |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 SyncerSession* const session_; | 47 // Used to resolve conflicts when trying to apply updates. |
| 48 vi64iter const begin_; | 48 ConflictResolver* const resolver_; |
| 49 vi64iter end_; | 49 |
| 50 vi64iter pointer_; | 50 UpdateIterator const begin_; |
| 51 UpdateIterator end_; |
| 52 UpdateIterator pointer_; |
| 51 bool progress_; | 53 bool progress_; |
| 52 | 54 |
| 53 // Track the result of the various items. | 55 // Track the result of the various items. |
| 54 std::vector<syncable::Id> conflicting_ids_; | 56 std::vector<syncable::Id> conflicting_ids_; |
| 55 std::vector<syncable::Id> blocked_ids_; | 57 std::vector<syncable::Id> blocked_ids_; |
| 56 std::vector<syncable::Id> successful_ids_; | 58 std::vector<syncable::Id> successful_ids_; |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 } // namespace browser_sync | 61 } // namespace browser_sync |
| 60 | 62 |
| 61 #endif // CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 63 #endif // CHROME_BROWSER_SYNC_ENGINE_UPDATE_APPLICATOR_H_ |
| OLD | NEW |