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

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

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
« no previous file with comments | « sync/syncable/delete_journal.h ('k') | sync/syncable/directory.h » ('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 (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 #include "sync/syncable/delete_journal.h"
6
7 #include "base/stl_util.h"
8 #include "sync/internal_api/public/base/model_type.h"
9
10 namespace syncer {
11 namespace syncable {
12
13 DeleteJournal::DeleteJournal(JournalIndex* initial_journal) {
14 CHECK(initial_journal);
15 delete_journals_.swap(*initial_journal);
16 }
17
18 DeleteJournal::~DeleteJournal() {
19 STLDeleteElements(&delete_journals_);
20 }
21
22 size_t DeleteJournal::GetDeleteJournalSize(BaseTransaction* trans) const {
23 DCHECK(trans);
24 return delete_journals_.size();
25 }
26
27 void DeleteJournal::UpdateDeleteJournalForServerDelete(
28 BaseTransaction* trans, bool was_deleted, const EntryKernel& entry) {
29 DCHECK(trans);
30
31 // Should be sufficient to check server type only but check for local
32 // type too because of incomplete test setup.
33 if (!(IsDeleteJournalEnabled(entry.GetServerModelType()) ||
34 IsDeleteJournalEnabled(
35 GetModelTypeFromSpecifics(entry.ref(SPECIFICS))))) {
36 return;
37 }
38
39 JournalIndex::iterator it = delete_journals_.find(&entry);
40
41 if (entry.ref(SERVER_IS_DEL)) {
42 if (it == delete_journals_.end()) {
43 // New delete.
44 EntryKernel* t = new EntryKernel(entry);
45 delete_journals_.insert(t);
46 delete_journals_to_purge_.erase(t->ref(META_HANDLE));
47 }
48 } else {
49 // Undelete. This could happen in two cases:
50 // * An entry was deleted then undeleted, i.e. server delete was
51 // overwritten because of entry has unsynced data locally.
52 // * A data type was broken, i.e. encountered unrecoverable error, in last
53 // sync session and all its entries were duplicated in delete journals.
54 // On restart, entries are recreated from downloads and recreation calls
55 // UpdateDeleteJournals() to remove live entries from delete journals,
56 // thus only deleted entries remain in journals.
57 if (it != delete_journals_.end()) {
58 delete_journals_to_purge_.insert((*it)->ref(META_HANDLE));
59 delete *it;
60 delete_journals_.erase(it);
61 } else if (was_deleted) {
62 delete_journals_to_purge_.insert(entry.ref(META_HANDLE));
63 }
64 }
65 }
66
67 void DeleteJournal::GetDeleteJournals(BaseTransaction* trans,
68 ModelType type,
69 EntryKernelSet* deleted_entries) {
70 DCHECK(trans);
71 DCHECK(!passive_delete_journal_types_.Has(type));
72 for (JournalIndex::const_iterator it = delete_journals_.begin();
73 it != delete_journals_.end(); ++it) {
74 if ((*it)->GetServerModelType() == type ||
75 GetModelTypeFromSpecifics((*it)->ref(SPECIFICS)) == type) {
76 deleted_entries->insert(*it);
77 }
78 }
79 passive_delete_journal_types_.Put(type);
80 }
81
82 void DeleteJournal::PurgeDeleteJournals(BaseTransaction* trans,
83 const MetahandleSet& to_purge) {
84 DCHECK(trans);
85 JournalIndex::iterator it = delete_journals_.begin();
86 while (it != delete_journals_.end()) {
87 int64 handle = (*it)->ref(META_HANDLE);
88 if (to_purge.count(handle)) {
89 delete *it;
90 delete_journals_.erase(it++);
91 } else {
92 ++it;
93 }
94 }
95 delete_journals_to_purge_.insert(to_purge.begin(), to_purge.end());
96 }
97
98 void DeleteJournal::TakeSnapshotAndClear(BaseTransaction* trans,
99 EntryKernelSet* journal_entries,
100 MetahandleSet* journals_to_purge) {
101 DCHECK(trans);
102 // Move passive delete journals to snapshot. Will copy back if snapshot fails
103 // to save.
104 JournalIndex::iterator it = delete_journals_.begin();
105 while (it != delete_journals_.end()) {
106 if (passive_delete_journal_types_.Has((*it)->GetServerModelType()) ||
107 passive_delete_journal_types_.Has(GetModelTypeFromSpecifics(
108 (*it)->ref(SPECIFICS)))) {
109 journal_entries->insert(*it);
110 delete_journals_.erase(it++);
111 } else {
112 ++it;
113 }
114 }
115 *journals_to_purge = delete_journals_to_purge_;
116 delete_journals_to_purge_.clear();
117 }
118
119 void DeleteJournal::AddJournalBatch(BaseTransaction* trans,
120 const EntryKernelSet& entries) {
121 DCHECK(trans);
122 EntryKernel needle;
123 for (EntryKernelSet::const_iterator i = entries.begin();
124 i != entries.end(); ++i) {
125 needle.put(ID, (*i)->ref(ID));
126 if (delete_journals_.find(&needle) == delete_journals_.end()) {
127 delete_journals_.insert(new EntryKernel(**i));
128 }
129 delete_journals_to_purge_.erase((*i)->ref(META_HANDLE));
130 }
131 }
132
133 /* static */
134 bool DeleteJournal::IsDeleteJournalEnabled(ModelType type) {
135 switch (type) {
136 case BOOKMARKS:
137 return true;
138 default:
139 return false;
140 }
141 }
142
143 } // namespace syncable
144 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/delete_journal.h ('k') | sync/syncable/directory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698