Adding myself to authors file
[chromium-blink-merge.git] / sync / internal_api / delete_journal.cc
blobedd10ae888450ed1156be589c936764d4c4b8e22
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.
5 #include "sync/internal_api/public/delete_journal.h"
7 #include "sync/internal_api/public/base_transaction.h"
8 #include "sync/syncable/directory.h"
9 #include "sync/syncable/syncable_base_transaction.h"
11 namespace syncer {
13 // static
14 void DeleteJournal::GetBookmarkDeleteJournals(
15 BaseTransaction* trans, BookmarkDeleteJournalList *delete_journal_list) {
16 syncer::syncable::EntryKernelSet deleted_entries;
17 trans->GetDirectory()->delete_journal()->GetDeleteJournals(
18 trans->GetWrappedTrans(), BOOKMARKS, &deleted_entries);
19 std::set<int64> undecryptable_journal;
20 for (syncer::syncable::EntryKernelSet::const_iterator i =
21 deleted_entries.begin(); i != deleted_entries.end(); ++i) {
22 delete_journal_list->push_back(BookmarkDeleteJournal());
23 delete_journal_list->back().id = (*i)->ref(syncer::syncable::META_HANDLE);
24 delete_journal_list->back().external_id =
25 (*i)->ref(syncer::syncable::LOCAL_EXTERNAL_ID);
26 delete_journal_list->back().is_folder = (*i)->ref(syncer::syncable::IS_DIR);
28 const sync_pb::EntitySpecifics& specifics = (*i)->ref(
29 syncer::syncable::SPECIFICS);
30 if (!specifics.has_encrypted()) {
31 delete_journal_list->back().specifics = specifics;
32 } else {
33 std::string plaintext_data = trans->GetCryptographer()->DecryptToString(
34 specifics.encrypted());
35 sync_pb::EntitySpecifics unencrypted_data;
36 if (plaintext_data.length() == 0 ||
37 !unencrypted_data.ParseFromString(plaintext_data)) {
38 // Fail to decrypt, Add this delete journal to purge.
39 undecryptable_journal.insert(delete_journal_list->back().id);
40 delete_journal_list->pop_back();
41 } else {
42 delete_journal_list->back().specifics = unencrypted_data;
47 if (!undecryptable_journal.empty()) {
48 trans->GetDirectory()->delete_journal()->PurgeDeleteJournals(
49 trans->GetWrappedTrans(), undecryptable_journal);
53 // static
54 void DeleteJournal::PurgeDeleteJournals(BaseTransaction* trans,
55 const std::set<int64>& ids) {
56 trans->GetDirectory()->delete_journal()->PurgeDeleteJournals(
57 trans->GetWrappedTrans(), ids);
60 } // namespace syncer