| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/internal_api/public/delete_journal.h" | 5 #include "components/sync/core/delete_journal.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "sync/internal_api/public/base_transaction.h" | 12 #include "components/sync/core/base_transaction.h" |
| 13 #include "sync/syncable/directory.h" | 13 #include "components/sync/syncable/directory.h" |
| 14 #include "sync/syncable/syncable_base_transaction.h" | 14 #include "components/sync/syncable/syncable_base_transaction.h" |
| 15 | 15 |
| 16 namespace syncer { | 16 namespace syncer { |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 void DeleteJournal::GetBookmarkDeleteJournals( | 19 void DeleteJournal::GetBookmarkDeleteJournals( |
| 20 BaseTransaction* trans, BookmarkDeleteJournalList *delete_journal_list) { | 20 BaseTransaction* trans, |
| 21 BookmarkDeleteJournalList* delete_journal_list) { |
| 21 syncer::syncable::EntryKernelSet deleted_entries; | 22 syncer::syncable::EntryKernelSet deleted_entries; |
| 22 trans->GetDirectory()->delete_journal()->GetDeleteJournals( | 23 trans->GetDirectory()->delete_journal()->GetDeleteJournals( |
| 23 trans->GetWrappedTrans(), BOOKMARKS, &deleted_entries); | 24 trans->GetWrappedTrans(), BOOKMARKS, &deleted_entries); |
| 24 std::set<int64_t> undecryptable_journal; | 25 std::set<int64_t> undecryptable_journal; |
| 25 for (syncer::syncable::EntryKernelSet::const_iterator i = | 26 for (syncer::syncable::EntryKernelSet::const_iterator i = |
| 26 deleted_entries.begin(); i != deleted_entries.end(); ++i) { | 27 deleted_entries.begin(); |
| 28 i != deleted_entries.end(); ++i) { |
| 27 delete_journal_list->push_back(BookmarkDeleteJournal()); | 29 delete_journal_list->push_back(BookmarkDeleteJournal()); |
| 28 delete_journal_list->back().id = (*i)->ref(syncer::syncable::META_HANDLE); | 30 delete_journal_list->back().id = (*i)->ref(syncer::syncable::META_HANDLE); |
| 29 delete_journal_list->back().external_id = | 31 delete_journal_list->back().external_id = |
| 30 (*i)->ref(syncer::syncable::LOCAL_EXTERNAL_ID); | 32 (*i)->ref(syncer::syncable::LOCAL_EXTERNAL_ID); |
| 31 delete_journal_list->back().is_folder = (*i)->ref(syncer::syncable::IS_DIR); | 33 delete_journal_list->back().is_folder = (*i)->ref(syncer::syncable::IS_DIR); |
| 32 | 34 |
| 33 const sync_pb::EntitySpecifics& specifics = (*i)->ref( | 35 const sync_pb::EntitySpecifics& specifics = |
| 34 syncer::syncable::SPECIFICS); | 36 (*i)->ref(syncer::syncable::SPECIFICS); |
| 35 if (!specifics.has_encrypted()) { | 37 if (!specifics.has_encrypted()) { |
| 36 delete_journal_list->back().specifics = specifics; | 38 delete_journal_list->back().specifics = specifics; |
| 37 } else { | 39 } else { |
| 38 std::string plaintext_data = trans->GetCryptographer()->DecryptToString( | 40 std::string plaintext_data = |
| 39 specifics.encrypted()); | 41 trans->GetCryptographer()->DecryptToString(specifics.encrypted()); |
| 40 sync_pb::EntitySpecifics unencrypted_data; | 42 sync_pb::EntitySpecifics unencrypted_data; |
| 41 if (plaintext_data.length() == 0 || | 43 if (plaintext_data.length() == 0 || |
| 42 !unencrypted_data.ParseFromString(plaintext_data)) { | 44 !unencrypted_data.ParseFromString(plaintext_data)) { |
| 43 // Fail to decrypt, Add this delete journal to purge. | 45 // Fail to decrypt, Add this delete journal to purge. |
| 44 undecryptable_journal.insert(delete_journal_list->back().id); | 46 undecryptable_journal.insert(delete_journal_list->back().id); |
| 45 delete_journal_list->pop_back(); | 47 delete_journal_list->pop_back(); |
| 46 } else { | 48 } else { |
| 47 delete_journal_list->back().specifics = unencrypted_data; | 49 delete_journal_list->back().specifics = unencrypted_data; |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 52 if (!undecryptable_journal.empty()) { | 54 if (!undecryptable_journal.empty()) { |
| 53 trans->GetDirectory()->delete_journal()->PurgeDeleteJournals( | 55 trans->GetDirectory()->delete_journal()->PurgeDeleteJournals( |
| 54 trans->GetWrappedTrans(), undecryptable_journal); | 56 trans->GetWrappedTrans(), undecryptable_journal); |
| 55 } | 57 } |
| 56 } | 58 } |
| 57 | 59 |
| 58 // static | 60 // static |
| 59 void DeleteJournal::PurgeDeleteJournals(BaseTransaction* trans, | 61 void DeleteJournal::PurgeDeleteJournals(BaseTransaction* trans, |
| 60 const std::set<int64_t>& ids) { | 62 const std::set<int64_t>& ids) { |
| 61 trans->GetDirectory()->delete_journal()->PurgeDeleteJournals( | 63 trans->GetDirectory()->delete_journal()->PurgeDeleteJournals( |
| 62 trans->GetWrappedTrans(), ids); | 64 trans->GetWrappedTrans(), ids); |
| 63 } | 65 } |
| 64 | 66 |
| 65 } // namespace syncer | 67 } // namespace syncer |
| OLD | NEW |