Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: sync/syncable/delete_journal.h

Issue 11441026: [Sync] Add support for loading, updating and querying delete journals in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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.
tim (not reviewing) 2013/01/04 18:54:14 Heh, sorry for the back-and-forth, but update comm
haitaol1 2013/01/04 19:06:14 Done.
26 class DeleteJournal {
27 public:
28 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, ManageDeleteJournals);
29
30 // Initialize |delete_journals_| using |intitial_journal|, whose content is
31 // destroyed during initialization.
32 explicit DeleteJournal(JournalIndex* initial_journal);
33 ~DeleteJournal();
34
35 // For testing only
tim (not reviewing) 2013/01/04 18:54:14 nit - end comment with period.
haitaol1 2013/01/04 19:06:14 Done.
36 size_t GetDeleteJournalSize(BaseTransaction* trans) const;
37
38 // Add/remove |entry| to/from |delete_journals_| according to its
39 // SERVER_IS_DEL field and |was_deleted|. Called on sync thread.
40 void UpdateDeleteJournalForServerDelete(BaseTransaction* trans,
41 bool was_deleted,
42 const EntryKernel& entry);
43
44 // Return entries of specified type in |delete_journals_|. This should be
45 // called ONCE in model association. |deleted_entries| can be used to
46 // detect deleted sync data that's not persisted in native model to
47 // prevent back-from-dead problem. |deleted_entries| are only valid during
48 // lifetime of |trans|. |type| is added to |passive_delete_journal_types_| to
49 // enable periodically saving/clearing of delete journals of |type| because
50 // new journals added later are not needed until next model association.
51 // Can be called on any thread.
52 void GetDeleteJournals(BaseTransaction* trans, ModelType type,
53 EntryKernelSet* deleted_entries);
54
55 // Purge entries of specified type in |delete_journals_| if their handles are
56 // in |to_purge|. This should be called after model association and
57 // |to_purge| should contain handles of the entries whose deletions are
58 // confirmed in native model. Can be called on any thread.
59 void PurgeDeleteJournals(BaseTransaction* trans,
60 const MetahandleSet& to_purge);
61
62 // Move entries in |delete_journals_| whose types are in
63 // |passive_delete_journal_types_| to |journal_entries|. Move handles in
64 // |delete_journals_to_purge_| to |journals_to_purge|. Called on sync thread.
65 void TakeSnapshotAndClear(BaseTransaction* trans,
66 EntryKernelSet* journal_entries,
67 MetahandleSet* journals_to_purge);
68
69 // Add |entries| to |delete_journals_| regardless of their SERVER_IS_DEL
70 // value. This is used to:
71 // * restore delete journals from snapshot if snapshot failed to save.
72 // * batch add entries of a data type with unrecoverable error to delete
73 // journal before purging them.
74 // Called on sync thread.
75 void AddJournalBatch(BaseTransaction* trans, const EntryKernelSet& entries);
76
77 // Return true if delete journals of |type| are maintained.
78 static bool IsDeleteJournalEnabled(ModelType type);
79
80 private:
81 // Contains deleted entries that may not be persisted in native models. And
82 // in case of unrecoverable error, all purged entries are moved here for
83 // bookkeeping to prevent back-from-dead entries that are deleted elsewhere
84 // when sync's down.
85 JournalIndex delete_journals_;
86
87 // Contains meta handles of deleted entries that have been persisted or
88 // undeleted, thus can be removed from database.
89 MetahandleSet delete_journals_to_purge_;
90
91 // Delete journals of these types can be cleared from memory after being
92 // saved to database.
93 ModelTypeSet passive_delete_journal_types_;
tim (not reviewing) 2013/01/04 18:54:14 style nit - add DISALLOW_COPY_AND_ASSIGN
haitaol1 2013/01/04 19:06:14 Done.
94 };
95
96 } // namespace syncable
97 } // namespace syncer
98
99 #endif // SYNC_SYNCABLE_DELETE_JOURNAL_H_
OLDNEW
« no previous file with comments | « sync/sync.gyp ('k') | sync/syncable/delete_journal.cc » ('j') | sync/syncable/delete_journal.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698