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

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

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

Powered by Google App Engine
This is Rietveld 408576698