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

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: rebase and update 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.
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
36 size_t GetDeleteJournalSize() 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(EntryKernelSet* journal_entries,
66 MetahandleSet* journals_to_purge);
67
68 // Add |entries| to |delete_journals_| regardless of their SERVER_IS_DEL
69 // value. This is used to:
70 // * restore delete journals from snapshot if snapshot failed to save.
71 // * batch add entries of a data type with unrecoverable error to delete
72 // journal before purging them.
73 // Called on sync thread.
74 void AddJournals(BaseTransaction* trans, const EntryKernelSet& entries);
75
76 // Return true if delete journals of |type| are maintained.
77 static bool IsDeleteJournalEnabled(ModelType type);
78
79 private:
80 // Contains deleted entries that may not be persisted in native models. And
81 // in case of unrecoverable error, all purged entries are moved here for
82 // bookkeeping to prevent back-from-dead entries that are deleted elsewhere
83 // when sync's down.
84 JournalIndex delete_journals_;
85
86 // Contains meta handles of deleted entries that have been persisted or
87 // undeleted, thus can be removed from database.
88 MetahandleSet delete_journals_to_purge_;
89
90 // Delete journals of these types can be cleared from memory after being
91 // saved to database.
92 ModelTypeSet passive_delete_journal_types_;
93
94 // To synchronize accesses to variables above.
95 base::Lock journal_lock_;
tim (not reviewing) 2013/01/04 15:35:46 I read through this CL, CL 11533008, and 11578017,
haitaol1 2013/01/04 18:49:20 Good point. Added transaction paramenter to GetDel
96 };
97
98 } // namespace syncable
99 } // namespace syncer
100
101 #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