Chromium Code Reviews| OLD | NEW |
|---|---|
| (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() const { | |
| 23 return delete_journals_.size(); | |
|
tim (not reviewing)
2013/01/04 15:35:46
Shouldn't you be using journal_lock_ here?
haitaol1
2013/01/04 18:49:20
Require a transaction param now.
On 2013/01/04 15
| |
| 24 } | |
| 25 | |
| 26 void DeleteJournal::UpdateDeleteJournalForServerDelete( | |
| 27 BaseTransaction* trans, bool was_deleted, const EntryKernel& entry) { | |
| 28 // Should be sufficient to check server type only but check for local | |
| 29 // type too because of incomplete test setup. | |
| 30 if (!(IsDeleteJournalEnabled(entry.GetServerModelType()) || | |
| 31 IsDeleteJournalEnabled( | |
| 32 GetModelTypeFromSpecifics(entry.ref(SPECIFICS))))) { | |
| 33 return; | |
| 34 } | |
| 35 | |
| 36 base::AutoLock lock(journal_lock_); | |
|
tim (not reviewing)
2013/01/04 15:35:46
It looks like we're trying to acquire a lock while
haitaol1
2013/01/04 18:49:20
Done.
| |
| 37 JournalIndex::const_iterator it = delete_journals_.find(&entry); | |
| 38 | |
| 39 if (entry.ref(SERVER_IS_DEL)) { | |
| 40 if (it == delete_journals_.end()) { | |
| 41 // New delete. | |
| 42 EntryKernel* t = new EntryKernel(entry); | |
| 43 delete_journals_.insert(t); | |
| 44 delete_journals_to_purge_.erase(t->ref(META_HANDLE)); | |
| 45 } | |
| 46 } else { | |
| 47 // Undelete. This could happen in two cases: | |
| 48 // * An entry was deleted then undeleted, i.e. server delete was | |
| 49 // overwritten because of entry has unsynced data locally. | |
| 50 // * A data type was broken, i.e. encountered unrecoverable error, in last | |
| 51 // sync session and all its entries were duplicated in delete journals. | |
| 52 // On restart, entries are recreated from downloads and recreation calls | |
| 53 // UpdateDeleteJournals() to remove live entries from delete journals, | |
| 54 // thus only deleted entries remain in journals. | |
| 55 if (it != delete_journals_.end()) { | |
| 56 delete_journals_to_purge_.insert((*it)->ref(META_HANDLE)); | |
| 57 delete *it; | |
| 58 delete_journals_.erase(it); | |
| 59 } else if (was_deleted) { | |
| 60 delete_journals_to_purge_.insert(entry.ref(META_HANDLE)); | |
| 61 } | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void DeleteJournal::GetDeleteJournals(BaseTransaction* trans, | |
| 66 ModelType type, | |
| 67 EntryKernelSet* deleted_entries) { | |
| 68 base::AutoLock lock(journal_lock_); | |
| 69 DCHECK(!passive_delete_journal_types_.Has(type)); | |
| 70 for (JournalIndex::const_iterator it = delete_journals_.begin(); | |
| 71 it != delete_journals_.end(); ++it) { | |
| 72 if ((*it)->GetServerModelType() == type || | |
| 73 GetModelTypeFromSpecifics((*it)->ref(SPECIFICS)) == type) { | |
| 74 deleted_entries->insert(*it); | |
| 75 } | |
| 76 } | |
| 77 passive_delete_journal_types_.Put(type); | |
| 78 } | |
| 79 | |
| 80 void DeleteJournal::PurgeDeleteJournals(BaseTransaction* trans, | |
| 81 const MetahandleSet& to_purge) { | |
| 82 base::AutoLock lock(journal_lock_); | |
| 83 JournalIndex::const_iterator it = delete_journals_.begin(); | |
| 84 while (it != delete_journals_.end()) { | |
| 85 int64 handle = (*it)->ref(META_HANDLE); | |
| 86 if (to_purge.count(handle)) { | |
| 87 delete *it; | |
| 88 delete_journals_.erase(it++); | |
| 89 } else { | |
| 90 ++it; | |
| 91 } | |
| 92 } | |
| 93 delete_journals_to_purge_.insert(to_purge.begin(), to_purge.end()); | |
| 94 } | |
| 95 | |
| 96 void DeleteJournal::TakeSnapshotAndClear(EntryKernelSet* journal_entries, | |
| 97 MetahandleSet* journals_to_purge) { | |
| 98 base::AutoLock lock(journal_lock_); | |
| 99 | |
| 100 // Move passive delete journals to snapshot. Will copy back if snapshot fails | |
| 101 // to save. | |
| 102 JournalIndex::const_iterator it = delete_journals_.begin(); | |
| 103 while (it != delete_journals_.end()) { | |
| 104 if (passive_delete_journal_types_.Has((*it)->GetServerModelType()) || | |
| 105 passive_delete_journal_types_.Has(GetModelTypeFromSpecifics( | |
| 106 (*it)->ref(SPECIFICS)))) { | |
| 107 journal_entries->insert(*it); | |
| 108 delete_journals_.erase(it++); | |
| 109 } else { | |
| 110 ++it; | |
| 111 } | |
| 112 } | |
| 113 *journals_to_purge = delete_journals_to_purge_; | |
| 114 delete_journals_to_purge_.clear(); | |
| 115 } | |
| 116 | |
| 117 void DeleteJournal::AddJournals(BaseTransaction* trans, | |
|
tim (not reviewing)
2013/01/04 15:35:46
I think AddJournalBatch would be a better / more s
haitaol1
2013/01/04 18:49:20
Done.
| |
| 118 const EntryKernelSet& entries) { | |
| 119 base::AutoLock lock(journal_lock_); | |
| 120 EntryKernel needle; | |
| 121 for (EntryKernelSet::const_iterator i = entries.begin(); | |
| 122 i != entries.end(); ++i) { | |
| 123 needle.put(ID, (*i)->ref(ID)); | |
| 124 if (delete_journals_.find(&needle) == delete_journals_.end()) { | |
| 125 delete_journals_.insert(new EntryKernel(**i)); | |
| 126 } | |
| 127 delete_journals_to_purge_.erase((*i)->ref(META_HANDLE)); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 /* static */ | |
| 132 bool DeleteJournal::IsDeleteJournalEnabled(ModelType type) { | |
| 133 switch (type) { | |
| 134 case BOOKMARKS: | |
| 135 return true; | |
| 136 default: | |
| 137 return false; | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 } // namespace syncable | |
| 142 } // namespace syncer | |
| OLD | NEW |