summaryrefslogtreecommitdiffstats
path: root/sync/internal_api
diff options
context:
space:
mode:
authorhaitaol@chromium.org <haitaol@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-22 23:53:56 +0000
committerhaitaol@chromium.org <haitaol@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-22 23:53:56 +0000
commit95a083fa27868960efe258e099aa49488260edd8 (patch)
tree4e382e00534d63fd35370683d00084a5941809cf /sync/internal_api
parent1d5617b5e88655c275a4e0b4606138fbeb6d1416 (diff)
downloadchromium_src-95a083fa27868960efe258e099aa49488260edd8.zip
chromium_src-95a083fa27868960efe258e099aa49488260edd8.tar.gz
chromium_src-95a083fa27868960efe258e099aa49488260edd8.tar.bz2
Use delete journal to remove bookmarks that are already deleted in sync model
before assocating bookmark model and sync model. BUG=121928 Review URL: https://chromiumcodereview.appspot.com/11533008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178157 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api')
-rw-r--r--sync/internal_api/delete_journal.cc58
-rw-r--r--sync/internal_api/public/delete_journal.h43
-rw-r--r--sync/internal_api/public/test/test_user_share.h5
-rw-r--r--sync/internal_api/test/test_user_share.cc21
4 files changed, 127 insertions, 0 deletions
diff --git a/sync/internal_api/delete_journal.cc b/sync/internal_api/delete_journal.cc
new file mode 100644
index 0000000..ebeb5a7
--- /dev/null
+++ b/sync/internal_api/delete_journal.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/internal_api/public/delete_journal.h"
+
+#include "sync/internal_api/public/base_transaction.h"
+#include "sync/syncable/directory.h"
+#include "sync/syncable/syncable_base_transaction.h"
+
+namespace syncer {
+
+// static
+void DeleteJournal::GetBookmarkDeleteJournals(
+ BaseTransaction* trans, BookmarkDeleteJournalList *delete_journal_list) {
+ syncer::syncable::EntryKernelSet deleted_entries;
+ trans->GetDirectory()->delete_journal()->GetDeleteJournals(
+ trans->GetWrappedTrans(), BOOKMARKS, &deleted_entries);
+ std::set<int64> undecryptable_journal;
+ for (syncer::syncable::EntryKernelSet::const_iterator i =
+ deleted_entries.begin(); i != deleted_entries.end(); ++i) {
+ delete_journal_list->push_back(BookmarkDeleteJournal());
+ delete_journal_list->back().id = (*i)->ref(syncer::syncable::META_HANDLE);
+ delete_journal_list->back().is_folder = (*i)->ref(syncer::syncable::IS_DIR);
+
+ const sync_pb::EntitySpecifics& specifics = (*i)->ref(
+ syncer::syncable::SPECIFICS);
+ if (!specifics.has_encrypted()) {
+ delete_journal_list->back().specifics = specifics;
+ } else {
+ std::string plaintext_data = trans->GetCryptographer()->DecryptToString(
+ specifics.encrypted());
+ sync_pb::EntitySpecifics unencrypted_data;
+ if (plaintext_data.length() == 0 ||
+ !unencrypted_data.ParseFromString(plaintext_data)) {
+ // Fail to decrypt, Add this delete journal to purge.
+ undecryptable_journal.insert(delete_journal_list->back().id);
+ delete_journal_list->pop_back();
+ } else {
+ delete_journal_list->back().specifics = unencrypted_data;
+ }
+ }
+ }
+
+ if (!undecryptable_journal.empty()) {
+ trans->GetDirectory()->delete_journal()->PurgeDeleteJournals(
+ trans->GetWrappedTrans(), undecryptable_journal);
+ }
+}
+
+// static
+void DeleteJournal::PurgeDeleteJournals(BaseTransaction* trans,
+ const std::set<int64>& ids) {
+ trans->GetDirectory()->delete_journal()->PurgeDeleteJournals(
+ trans->GetWrappedTrans(), ids);
+}
+
+} // namespace syncer
diff --git a/sync/internal_api/public/delete_journal.h b/sync/internal_api/public/delete_journal.h
new file mode 100644
index 0000000..1e66b3c
--- /dev/null
+++ b/sync/internal_api/public/delete_journal.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_INTERNAL_API_PUBLIC_DELETE_JOURNAL_H_
+#define SYNC_INTERNAL_API_PUBLIC_DELETE_JOURNAL_H_
+
+#include <vector>
+
+#include "sync/internal_api/public/base/model_type.h"
+#include "sync/protocol/sync.pb.h"
+
+namespace syncer {
+
+class BaseTransaction;
+
+struct BookmarkDeleteJournal {
+ int64 id; // Metahandle of delete journal entry.
+ bool is_folder;
+ sync_pb::EntitySpecifics specifics;
+};
+typedef std::vector<BookmarkDeleteJournal> BookmarkDeleteJournalList;
+
+// Static APIs for passing delete journals between syncer::syncable namspace
+// and syncer namespace.
+class DeleteJournal {
+ public:
+ // Return info about deleted bookmark entries stored in the delete journal
+ // of |trans|'s directory.
+ // TODO(haitaol): remove this after SyncData supports bookmarks and
+ // all types of delete journals can be returned as
+ // SyncDataList.
+ static void GetBookmarkDeleteJournals(
+ BaseTransaction* trans, BookmarkDeleteJournalList *delete_journals);
+
+ // Purge delete journals of given IDs from |trans|'s directory.
+ static void PurgeDeleteJournals(BaseTransaction* trans,
+ const std::set<int64>& ids);
+};
+
+} // namespace syncer
+
+#endif // SYNC_INTERNAL_API_PUBLIC_DELETE_JOURNAL_H_
diff --git a/sync/internal_api/public/test/test_user_share.h b/sync/internal_api/public/test/test_user_share.h
index 6588945..2823fed 100644
--- a/sync/internal_api/public/test/test_user_share.h
+++ b/sync/internal_api/public/test/test_user_share.h
@@ -58,6 +58,9 @@ class TestUserShare {
// on the user share's directory.
void TearDown();
+ // Save and reload Directory to clear out temporary data in memory.
+ bool Reload();
+
// Non-NULL iff called between a call to SetUp() and TearDown().
UserShare* user_share();
@@ -73,6 +76,8 @@ class TestUserShare {
static bool CreateRoot(syncer::ModelType model_type,
syncer::UserShare* service);
+ size_t GetDeleteJournalSize() const;
+
private:
scoped_ptr<TestDirectorySetterUpper> dir_maker_;
scoped_ptr<UserShare> user_share_;
diff --git a/sync/internal_api/test/test_user_share.cc b/sync/internal_api/test/test_user_share.cc
index 2057eac..9434617 100644
--- a/sync/internal_api/test/test_user_share.cc
+++ b/sync/internal_api/test/test_user_share.cc
@@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/mutable_entry.h"
+#include "sync/syncable/syncable_read_transaction.h"
#include "sync/syncable/syncable_write_transaction.h"
#include "sync/test/engine/test_directory_setter_upper.h"
#include "sync/test/engine/test_id_factory.h"
@@ -39,6 +40,21 @@ void TestUserShare::TearDown() {
dir_maker_->TearDown();
}
+bool TestUserShare::Reload() {
+ if (!user_share_->directory->SaveChanges())
+ return false;
+
+ syncer::syncable::DirectoryBackingStore* saved_store =
+ user_share_->directory->store_.release();
+
+ // Ensure the scoped_ptr doesn't delete the memory we don't own.
+ ignore_result(user_share_->directory.release());
+ user_share_.reset(new UserShare());
+ dir_maker_->SetUpWith(saved_store);
+ user_share_->directory.reset(dir_maker_->directory());
+ return true;
+}
+
UserShare* TestUserShare::user_share() {
return user_share_.get();
}
@@ -59,4 +75,9 @@ bool TestUserShare::CreateRoot(ModelType model_type, UserShare* user_share) {
return true;
}
+size_t TestUserShare::GetDeleteJournalSize() const {
+ syncable::ReadTransaction trans(FROM_HERE, user_share_->directory.get());
+ return user_share_->directory->delete_journal()->GetDeleteJournalSize(&trans);
+}
+
} // namespace syncer