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

Side by Side Diff: components/sync/syncable/syncable_delete_journal.cc

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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/syncable/syncable_delete_journal.h" 5 #include "components/sync/syncable/syncable_delete_journal.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "sync/internal_api/public/base/model_type.h" 11 #include "components/sync/base/model_type.h"
12 12
13 namespace syncer { 13 namespace syncer {
14 namespace syncable { 14 namespace syncable {
15 15
16 DeleteJournal::DeleteJournal(JournalIndex* initial_journal) { 16 DeleteJournal::DeleteJournal(JournalIndex* initial_journal) {
17 CHECK(initial_journal); 17 CHECK(initial_journal);
18 delete_journals_.swap(*initial_journal); 18 delete_journals_.swap(*initial_journal);
19 } 19 }
20 20
21 DeleteJournal::~DeleteJournal() { 21 DeleteJournal::~DeleteJournal() {
22 STLDeleteElements(&delete_journals_); 22 STLDeleteElements(&delete_journals_);
23 } 23 }
24 24
25 size_t DeleteJournal::GetDeleteJournalSize(BaseTransaction* trans) const { 25 size_t DeleteJournal::GetDeleteJournalSize(BaseTransaction* trans) const {
26 DCHECK(trans); 26 DCHECK(trans);
27 return delete_journals_.size(); 27 return delete_journals_.size();
28 } 28 }
29 29
30 void DeleteJournal::UpdateDeleteJournalForServerDelete( 30 void DeleteJournal::UpdateDeleteJournalForServerDelete(
31 BaseTransaction* trans, bool was_deleted, const EntryKernel& entry) { 31 BaseTransaction* trans,
32 bool was_deleted,
33 const EntryKernel& entry) {
32 DCHECK(trans); 34 DCHECK(trans);
33 35
34 // Should be sufficient to check server type only but check for local 36 // Should be sufficient to check server type only but check for local
35 // type too because of incomplete test setup. 37 // type too because of incomplete test setup.
36 if (!(IsDeleteJournalEnabled(entry.GetServerModelType()) || 38 if (!(IsDeleteJournalEnabled(entry.GetServerModelType()) ||
37 IsDeleteJournalEnabled( 39 IsDeleteJournalEnabled(
38 GetModelTypeFromSpecifics(entry.ref(SPECIFICS))))) { 40 GetModelTypeFromSpecifics(entry.ref(SPECIFICS))))) {
39 return; 41 return;
40 } 42 }
41 43
42 JournalIndex::iterator it = delete_journals_.find(&entry); 44 JournalIndex::iterator it = delete_journals_.find(&entry);
43 45
44 if (entry.ref(SERVER_IS_DEL)) { 46 if (entry.ref(SERVER_IS_DEL)) {
45 if (it == delete_journals_.end()) { 47 if (it == delete_journals_.end()) {
46 // New delete. 48 // New delete.
47 EntryKernel* t = new EntryKernel(entry); 49 EntryKernel* t = new EntryKernel(entry);
48 delete_journals_.insert(t); 50 delete_journals_.insert(t);
(...skipping 16 matching lines...) Expand all
65 delete_journals_to_purge_.insert(entry.ref(META_HANDLE)); 67 delete_journals_to_purge_.insert(entry.ref(META_HANDLE));
66 } 68 }
67 } 69 }
68 } 70 }
69 71
70 void DeleteJournal::GetDeleteJournals(BaseTransaction* trans, 72 void DeleteJournal::GetDeleteJournals(BaseTransaction* trans,
71 ModelType type, 73 ModelType type,
72 EntryKernelSet* deleted_entries) { 74 EntryKernelSet* deleted_entries) {
73 DCHECK(trans); 75 DCHECK(trans);
74 for (JournalIndex::const_iterator it = delete_journals_.begin(); 76 for (JournalIndex::const_iterator it = delete_journals_.begin();
75 it != delete_journals_.end(); ++it) { 77 it != delete_journals_.end(); ++it) {
76 if ((*it)->GetServerModelType() == type || 78 if ((*it)->GetServerModelType() == type ||
77 GetModelTypeFromSpecifics((*it)->ref(SPECIFICS)) == type) { 79 GetModelTypeFromSpecifics((*it)->ref(SPECIFICS)) == type) {
78 deleted_entries->insert(*it); 80 deleted_entries->insert(*it);
79 } 81 }
80 } 82 }
81 passive_delete_journal_types_.Put(type); 83 passive_delete_journal_types_.Put(type);
82 } 84 }
83 85
84 void DeleteJournal::PurgeDeleteJournals(BaseTransaction* trans, 86 void DeleteJournal::PurgeDeleteJournals(BaseTransaction* trans,
85 const MetahandleSet& to_purge) { 87 const MetahandleSet& to_purge) {
(...skipping 13 matching lines...) Expand all
99 101
100 void DeleteJournal::TakeSnapshotAndClear(BaseTransaction* trans, 102 void DeleteJournal::TakeSnapshotAndClear(BaseTransaction* trans,
101 EntryKernelSet* journal_entries, 103 EntryKernelSet* journal_entries,
102 MetahandleSet* journals_to_purge) { 104 MetahandleSet* journals_to_purge) {
103 DCHECK(trans); 105 DCHECK(trans);
104 // Move passive delete journals to snapshot. Will copy back if snapshot fails 106 // Move passive delete journals to snapshot. Will copy back if snapshot fails
105 // to save. 107 // to save.
106 JournalIndex::iterator it = delete_journals_.begin(); 108 JournalIndex::iterator it = delete_journals_.begin();
107 while (it != delete_journals_.end()) { 109 while (it != delete_journals_.end()) {
108 if (passive_delete_journal_types_.Has((*it)->GetServerModelType()) || 110 if (passive_delete_journal_types_.Has((*it)->GetServerModelType()) ||
109 passive_delete_journal_types_.Has(GetModelTypeFromSpecifics( 111 passive_delete_journal_types_.Has(
110 (*it)->ref(SPECIFICS)))) { 112 GetModelTypeFromSpecifics((*it)->ref(SPECIFICS)))) {
111 journal_entries->insert(*it); 113 journal_entries->insert(*it);
112 delete_journals_.erase(it++); 114 delete_journals_.erase(it++);
113 } else { 115 } else {
114 ++it; 116 ++it;
115 } 117 }
116 } 118 }
117 *journals_to_purge = delete_journals_to_purge_; 119 *journals_to_purge = delete_journals_to_purge_;
118 delete_journals_to_purge_.clear(); 120 delete_journals_to_purge_.clear();
119 } 121 }
120 122
121 void DeleteJournal::AddJournalBatch(BaseTransaction* trans, 123 void DeleteJournal::AddJournalBatch(BaseTransaction* trans,
122 const EntryKernelSet& entries) { 124 const EntryKernelSet& entries) {
123 DCHECK(trans); 125 DCHECK(trans);
124 EntryKernel needle; 126 EntryKernel needle;
125 for (EntryKernelSet::const_iterator i = entries.begin(); 127 for (EntryKernelSet::const_iterator i = entries.begin(); i != entries.end();
126 i != entries.end(); ++i) { 128 ++i) {
127 needle.put(ID, (*i)->ref(ID)); 129 needle.put(ID, (*i)->ref(ID));
128 if (delete_journals_.find(&needle) == delete_journals_.end()) { 130 if (delete_journals_.find(&needle) == delete_journals_.end()) {
129 delete_journals_.insert(new EntryKernel(**i)); 131 delete_journals_.insert(new EntryKernel(**i));
130 } 132 }
131 delete_journals_to_purge_.erase((*i)->ref(META_HANDLE)); 133 delete_journals_to_purge_.erase((*i)->ref(META_HANDLE));
132 } 134 }
133 } 135 }
134 136
135 /* static */ 137 /* static */
136 bool DeleteJournal::IsDeleteJournalEnabled(ModelType type) { 138 bool DeleteJournal::IsDeleteJournalEnabled(ModelType type) {
137 switch (type) { 139 switch (type) {
138 case BOOKMARKS: 140 case BOOKMARKS:
139 return true; 141 return true;
140 default: 142 default:
141 return false; 143 return false;
142 } 144 }
143 } 145 }
144 146
145 } // namespace syncable 147 } // namespace syncable
146 } // namespace syncer 148 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/syncable_delete_journal.h ('k') | components/sync/syncable/syncable_enum_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698