Chromium Code Reviews| 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 class 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 class DeleteJournal { | |
| 26 public: | |
| 27 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, ManageDeleteJournals); | |
| 28 | |
| 29 // Initialize |delete_journals_| using |intitial_journal|, whose content is | |
| 30 // destroyed during initialization. | |
| 31 DeleteJournal(JournalIndex& initial_journal); | |
|
tim (not reviewing)
2012/12/21 03:30:40
Single argument constructors should be marked expl
haitaol1
2013/01/03 19:40:49
scoped_ptr is probably an overkill. Changed to poi
| |
| 32 ~DeleteJournal(); | |
| 33 | |
| 34 size_t GetDeleteJournalSize() const; | |
| 35 | |
| 36 // Add/remove |entry| to/from |delete_journals_| according to its | |
| 37 // SERVER_IS_DEL field and |was_deleted|. | |
| 38 void UpdateDeleteJournalForServerDelete(BaseTransaction* trans, | |
| 39 bool was_deleted, | |
| 40 const EntryKernel& entry); | |
| 41 | |
| 42 // Return entries of specified type in |delete_journals_|. This should be | |
| 43 // called ONCE in model association. |deleted_entries| can be used to | |
| 44 // detect deleted sync data that's not persisted in native model to | |
| 45 // prevent back-from-dead problem. |deleted_entries| are only valid during | |
| 46 // lifetime of |trans|. |type| is added to |passive_delete_journal_types_| to | |
| 47 // enable periodically saving/clearing of delete journals of |type| because | |
| 48 // new journals added later are not needed until next model association. | |
| 49 void GetDeleteJournals(BaseTransaction* trans, ModelType type, | |
| 50 EntryKernelSet* deleted_entries); | |
| 51 | |
| 52 // Purge entries of specified type in |delete_journals_| if their handles are | |
| 53 // in |to_purge|. This should be called after model association and | |
| 54 // |to_purge| should contain handles of the entries whose deletions are | |
| 55 // confirmed in native model. | |
| 56 void PurgeDeleteJournals(BaseTransaction* trans, | |
| 57 const MetahandleSet& to_purge); | |
| 58 | |
| 59 // Move entries in |delete_journals_| whose types are in | |
| 60 // |passive_delete_journal_types_| to |journal_entries|. Move handles in | |
| 61 // |delete_journals_to_purge_| to |journals_to_purge|. | |
| 62 void TakeSnapshotAndClear(EntryKernelSet* journal_entries, | |
| 63 MetahandleSet* journals_to_purge); | |
| 64 | |
| 65 // Add |entries| to |delete_journals_| regardless of their SERVER_IS_DEL | |
| 66 // value. This is used to: | |
| 67 // * restore delete journals from snapshot if snapshot failed to save. | |
| 68 // * batch add entries of a data type with unrecoverable error to delete | |
| 69 // journal before purging them. | |
| 70 void AddJournals(BaseTransaction* trans, const EntryKernelSet& entries); | |
| 71 | |
| 72 // Return true if delete journals of |type| are maintained. | |
| 73 static bool IsDeleteJournalEnabled(ModelType type); | |
| 74 | |
| 75 private: | |
| 76 // Contains deleted entries that may not be persisted in native models. And | |
| 77 // in case of unrecoverable error, all purged entries are moved here for | |
| 78 // bookkeeping to prevent back-from-dead entries that are deleted elsewhere | |
| 79 // when sync's down. | |
| 80 JournalIndex delete_journals_; | |
| 81 | |
| 82 // Contains meta handles of deleted entries that have been persisted or | |
| 83 // undeleted, thus can be removed from database. | |
| 84 MetahandleSet delete_journals_to_purge_; | |
| 85 | |
| 86 // Delete journals of these types can be cleared from memory after being | |
| 87 // saved to database. | |
| 88 ModelTypeSet passive_delete_journal_types_; | |
| 89 | |
| 90 // To protect access to journal index. | |
|
tim (not reviewing)
2012/12/21 03:30:40
Can you add class comments and method comments exp
haitaol1
2013/01/03 19:40:49
Done.
| |
| 91 base::Lock journal_lock_; | |
| 92 }; | |
| 93 | |
| 94 } // namespace syncable | |
| 95 } // namespace syncer | |
| 96 | |
| 97 #endif // SYNC_SYNCABLE_DELETE_JOURNAL_H_ | |
| OLD | NEW |