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