Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(672)

Unified Diff: components/leveldb_proto/testing/fake_db.h

Issue 2379113002: Extended the ProtoDatabase to provide LoadKeys() functionality. (Closed)
Patch Set: Garbage Collect orphaned images on service start-up. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/leveldb_proto/testing/fake_db.h
diff --git a/components/leveldb_proto/testing/fake_db.h b/components/leveldb_proto/testing/fake_db.h
index e67ceba7a8ccc238a4af9027b91725ac297c2ac5..bd9efb571a465f4e3b05d4b98e63d073d3ca6498 100644
--- a/components/leveldb_proto/testing/fake_db.h
+++ b/components/leveldb_proto/testing/fake_db.h
@@ -39,6 +39,8 @@ class FakeDB : public ProtoDatabase<T> {
const typename ProtoDatabase<T>::UpdateCallback& callback) override;
void LoadEntries(
const typename ProtoDatabase<T>::LoadCallback& callback) override;
+ void LoadKeys(
+ const typename ProtoDatabase<T>::LoadKeysCallback& callback) override;
void GetEntry(
const std::string& key,
const typename ProtoDatabase<T>::GetCallback& callback) override;
@@ -51,6 +53,8 @@ class FakeDB : public ProtoDatabase<T> {
void LoadCallback(bool success);
+ void LoadKeysCallback(bool success);
+
void GetCallback(bool success);
void UpdateCallback(bool success);
@@ -63,6 +67,11 @@ class FakeDB : public ProtoDatabase<T> {
std::unique_ptr<typename std::vector<T>> entries,
bool success);
+ static void RunLoadKeysCallback(
+ const typename ProtoDatabase<T>::LoadKeysCallback& callback,
+ std::unique_ptr<std::vector<std::string>> keys,
+ bool success);
+
static void RunGetCallback(
const typename ProtoDatabase<T>::GetCallback& callback,
std::unique_ptr<T> entry,
@@ -73,6 +82,7 @@ class FakeDB : public ProtoDatabase<T> {
Callback init_callback_;
Callback load_callback_;
+ Callback load_keys_callback_;
Callback get_callback_;
Callback update_callback_;
};
@@ -118,6 +128,18 @@ void FakeDB<T>::LoadEntries(
}
template <typename T>
+void FakeDB<T>::LoadKeys(
+ const typename ProtoDatabase<T>::LoadKeysCallback& callback) {
+ std::unique_ptr<std::vector<std::string>> keys(
+ new std::vector<std::string>());
+ for (const auto& pair : *db_)
+ keys->push_back(pair.first);
+
+ load_keys_callback_ =
+ base::Bind(RunLoadKeysCallback, callback, base::Passed(&keys));
+}
+
+template <typename T>
void FakeDB<T>::GetEntry(
const std::string& key,
const typename ProtoDatabase<T>::GetCallback& callback) {
@@ -152,6 +174,12 @@ void FakeDB<T>::LoadCallback(bool success) {
}
template <typename T>
+void FakeDB<T>::LoadKeysCallback(bool success) {
+ load_keys_callback_.Run(success);
+ load_keys_callback_.Reset();
+}
+
+template <typename T>
void FakeDB<T>::GetCallback(bool success) {
get_callback_.Run(success);
get_callback_.Reset();
@@ -174,6 +202,15 @@ void FakeDB<T>::RunLoadCallback(
// static
template <typename T>
+void FakeDB<T>::RunLoadKeysCallback(
+ const typename ProtoDatabase<T>::LoadKeysCallback& callback,
+ std::unique_ptr<std::vector<std::string>> keys,
+ bool success) {
+ callback.Run(success, std::move(keys));
+}
+
+// static
+template <typename T>
void FakeDB<T>::RunGetCallback(
const typename ProtoDatabase<T>::GetCallback& callback,
std::unique_ptr<T> entry,
« no previous file with comments | « components/leveldb_proto/proto_database_impl_unittest.cc ('k') | components/ntp_snippets/remote/ntp_snippets_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698