Chromium Code Reviews| Index: sync/syncable/delete_journal.h |
| diff --git a/sync/syncable/delete_journal.h b/sync/syncable/delete_journal.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..abdd69ac8cc7cebe9500df4b9413153946fa3f78 |
| --- /dev/null |
| +++ b/sync/syncable/delete_journal.h |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SYNC_SYNCABLE_DELETE_JOURNAL_H_ |
| +#define SYNC_SYNCABLE_DELETE_JOURNAL_H_ |
| + |
| +#include <set> |
| + |
| +#include "base/gtest_prod_util.h" |
| +#include "base/synchronization/lock.h" |
| +#include "sync/syncable/metahandle_set.h" |
| +#include "sync/syncable/syncable-inl.h" |
| + |
| +namespace syncer { |
| +namespace syncable { |
| + |
| +class BaseTransaction; |
| +class EntryKernel; |
| + |
| +typedef std::set<const EntryKernel*, LessField<IdField, ID> > JournalIndex; |
| + |
| +// DeleteJournal manages deleted entries that are not in sync directory until |
| +// it's safe to drop them after the deletion is confirmed with native models. |
| +class DeleteJournal { |
| + public: |
| + FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, ManageDeleteJournals); |
| + |
| + // Initialize |delete_journals_| using |intitial_journal|, whose content is |
| + // destroyed during initialization. |
| + 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
|
| + ~DeleteJournal(); |
| + |
| + size_t GetDeleteJournalSize() const; |
| + |
| + // Add/remove |entry| to/from |delete_journals_| according to its |
| + // SERVER_IS_DEL field and |was_deleted|. |
| + void UpdateDeleteJournalForServerDelete(BaseTransaction* trans, |
| + bool was_deleted, |
| + const EntryKernel& entry); |
| + |
| + // Return entries of specified type in |delete_journals_|. This should be |
| + // called ONCE in model association. |deleted_entries| can be used to |
| + // detect deleted sync data that's not persisted in native model to |
| + // prevent back-from-dead problem. |deleted_entries| are only valid during |
| + // lifetime of |trans|. |type| is added to |passive_delete_journal_types_| to |
| + // enable periodically saving/clearing of delete journals of |type| because |
| + // new journals added later are not needed until next model association. |
| + void GetDeleteJournals(BaseTransaction* trans, ModelType type, |
| + EntryKernelSet* deleted_entries); |
| + |
| + // Purge entries of specified type in |delete_journals_| if their handles are |
| + // in |to_purge|. This should be called after model association and |
| + // |to_purge| should contain handles of the entries whose deletions are |
| + // confirmed in native model. |
| + void PurgeDeleteJournals(BaseTransaction* trans, |
| + const MetahandleSet& to_purge); |
| + |
| + // Move entries in |delete_journals_| whose types are in |
| + // |passive_delete_journal_types_| to |journal_entries|. Move handles in |
| + // |delete_journals_to_purge_| to |journals_to_purge|. |
| + void TakeSnapshotAndClear(EntryKernelSet* journal_entries, |
| + MetahandleSet* journals_to_purge); |
| + |
| + // Add |entries| to |delete_journals_| regardless of their SERVER_IS_DEL |
| + // value. This is used to: |
| + // * restore delete journals from snapshot if snapshot failed to save. |
| + // * batch add entries of a data type with unrecoverable error to delete |
| + // journal before purging them. |
| + void AddJournals(BaseTransaction* trans, const EntryKernelSet& entries); |
| + |
| + // Return true if delete journals of |type| are maintained. |
| + static bool IsDeleteJournalEnabled(ModelType type); |
| + |
| + private: |
| + // Contains deleted entries that may not be persisted in native models. And |
| + // in case of unrecoverable error, all purged entries are moved here for |
| + // bookkeeping to prevent back-from-dead entries that are deleted elsewhere |
| + // when sync's down. |
| + JournalIndex delete_journals_; |
| + |
| + // Contains meta handles of deleted entries that have been persisted or |
| + // undeleted, thus can be removed from database. |
| + MetahandleSet delete_journals_to_purge_; |
| + |
| + // Delete journals of these types can be cleared from memory after being |
| + // saved to database. |
| + ModelTypeSet passive_delete_journal_types_; |
| + |
| + // 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.
|
| + base::Lock journal_lock_; |
| +}; |
| + |
| +} // namespace syncable |
| +} // namespace syncer |
| + |
| +#endif // SYNC_SYNCABLE_DELETE_JOURNAL_H_ |