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 #ifndef SYNC_SYNCABLE_DELETE_JOURNAL_H_ |
| 6 #define SYNC_SYNCABLE_DELETE_JOURNAL_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/synchronization/lock.h" |
| 12 #include "sync/syncable/metahandle_set.h" |
| 13 #include "sync/syncable/syncable-inl.h" |
| 14 |
| 15 namespace syncer { |
| 16 namespace syncable { |
| 17 |
| 18 class BaseTransaction; |
| 19 struct EntryKernel; |
| 20 |
| 21 typedef std::set<const EntryKernel*, LessField<IdField, ID> > JournalIndex; |
| 22 |
| 23 // DeleteJournal manages deleted entries that are not in sync directory until |
| 24 // it's safe to drop them after the deletion is confirmed with native models. |
| 25 // DeleteJournal is thread-safe and can be accessed on any thread. Has to hold |
| 26 // a valid transaction object when calling methods of DeleteJournal, thus each |
| 27 // method requires a non-null |trans| parameter. |
| 28 class DeleteJournal { |
| 29 public: |
| 30 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, ManageDeleteJournals); |
| 31 |
| 32 // Initialize |delete_journals_| using |intitial_journal|, whose content is |
| 33 // destroyed during initialization. |
| 34 explicit DeleteJournal(JournalIndex* initial_journal); |
| 35 ~DeleteJournal(); |
| 36 |
| 37 // For testing only. |
| 38 size_t GetDeleteJournalSize(BaseTransaction* trans) const; |
| 39 |
| 40 // Add/remove |entry| to/from |delete_journals_| according to its |
| 41 // SERVER_IS_DEL field and |was_deleted|. Called on sync thread. |
| 42 void UpdateDeleteJournalForServerDelete(BaseTransaction* trans, |
| 43 bool was_deleted, |
| 44 const EntryKernel& entry); |
| 45 |
| 46 // Return entries of specified type in |delete_journals_|. This should be |
| 47 // called ONCE in model association. |deleted_entries| can be used to |
| 48 // detect deleted sync data that's not persisted in native model to |
| 49 // prevent back-from-dead problem. |deleted_entries| are only valid during |
| 50 // lifetime of |trans|. |type| is added to |passive_delete_journal_types_| to |
| 51 // enable periodically saving/clearing of delete journals of |type| because |
| 52 // new journals added later are not needed until next model association. |
| 53 // Can be called on any thread. |
| 54 void GetDeleteJournals(BaseTransaction* trans, ModelType type, |
| 55 EntryKernelSet* deleted_entries); |
| 56 |
| 57 // Purge entries of specified type in |delete_journals_| if their handles are |
| 58 // in |to_purge|. This should be called after model association and |
| 59 // |to_purge| should contain handles of the entries whose deletions are |
| 60 // confirmed in native model. Can be called on any thread. |
| 61 void PurgeDeleteJournals(BaseTransaction* trans, |
| 62 const MetahandleSet& to_purge); |
| 63 |
| 64 // Move entries in |delete_journals_| whose types are in |
| 65 // |passive_delete_journal_types_| to |journal_entries|. Move handles in |
| 66 // |delete_journals_to_purge_| to |journals_to_purge|. Called on sync thread. |
| 67 void TakeSnapshotAndClear(BaseTransaction* trans, |
| 68 EntryKernelSet* journal_entries, |
| 69 MetahandleSet* journals_to_purge); |
| 70 |
| 71 // Add |entries| to |delete_journals_| regardless of their SERVER_IS_DEL |
| 72 // value. This is used to: |
| 73 // * restore delete journals from snapshot if snapshot failed to save. |
| 74 // * batch add entries of a data type with unrecoverable error to delete |
| 75 // journal before purging them. |
| 76 // Called on sync thread. |
| 77 void AddJournalBatch(BaseTransaction* trans, const EntryKernelSet& entries); |
| 78 |
| 79 // Return true if delete journals of |type| are maintained. |
| 80 static bool IsDeleteJournalEnabled(ModelType type); |
| 81 |
| 82 private: |
| 83 // Contains deleted entries that may not be persisted in native models. And |
| 84 // in case of unrecoverable error, all purged entries are moved here for |
| 85 // bookkeeping to prevent back-from-dead entries that are deleted elsewhere |
| 86 // when sync's down. |
| 87 JournalIndex delete_journals_; |
| 88 |
| 89 // Contains meta handles of deleted entries that have been persisted or |
| 90 // undeleted, thus can be removed from database. |
| 91 MetahandleSet delete_journals_to_purge_; |
| 92 |
| 93 // Delete journals of these types can be cleared from memory after being |
| 94 // saved to database. |
| 95 ModelTypeSet passive_delete_journal_types_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(DeleteJournal); |
| 98 }; |
| 99 |
| 100 } // namespace syncable |
| 101 } // namespace syncer |
| 102 |
| 103 #endif // SYNC_SYNCABLE_DELETE_JOURNAL_H_ |
OLD | NEW |