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

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

Issue 2049573003: Implement ProtoDatabase::GetEntry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: not found vs error Created 4 years, 6 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
« no previous file with comments | « components/leveldb_proto/proto_database_impl_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4ff6b43ca1bbce349f7da07d1a8266207eb1cbbd..e67ceba7a8ccc238a4af9027b91725ac297c2ac5 100644
--- a/components/leveldb_proto/testing/fake_db.h
+++ b/components/leveldb_proto/testing/fake_db.h
@@ -39,6 +39,9 @@ class FakeDB : public ProtoDatabase<T> {
const typename ProtoDatabase<T>::UpdateCallback& callback) override;
void LoadEntries(
const typename ProtoDatabase<T>::LoadCallback& callback) override;
+ void GetEntry(
+ const std::string& key,
+ const typename ProtoDatabase<T>::GetCallback& callback) override;
void Destroy(
const typename ProtoDatabase<T>::DestroyCallback& callback) override;
@@ -48,6 +51,8 @@ class FakeDB : public ProtoDatabase<T> {
void LoadCallback(bool success);
+ void GetCallback(bool success);
+
void UpdateCallback(bool success);
static base::FilePath DirectoryForTestDB();
@@ -58,11 +63,17 @@ class FakeDB : public ProtoDatabase<T> {
std::unique_ptr<typename std::vector<T>> entries,
bool success);
+ static void RunGetCallback(
+ const typename ProtoDatabase<T>::GetCallback& callback,
+ std::unique_ptr<T> entry,
+ bool success);
+
base::FilePath dir_;
EntryMap* db_;
Callback init_callback_;
Callback load_callback_;
+ Callback get_callback_;
Callback update_callback_;
};
@@ -107,6 +118,18 @@ void FakeDB<T>::LoadEntries(
}
template <typename T>
+void FakeDB<T>::GetEntry(
+ const std::string& key,
+ const typename ProtoDatabase<T>::GetCallback& callback) {
+ std::unique_ptr<T> entry;
+ auto it = db_->find(key);
+ if (it != db_->end())
+ entry.reset(new T(it->second));
+
+ get_callback_ = base::Bind(RunGetCallback, callback, base::Passed(&entry));
+}
+
+template <typename T>
void FakeDB<T>::Destroy(
const typename ProtoDatabase<T>::DestroyCallback& callback) {
}
@@ -129,6 +152,12 @@ void FakeDB<T>::LoadCallback(bool success) {
}
template <typename T>
+void FakeDB<T>::GetCallback(bool success) {
+ get_callback_.Run(success);
+ get_callback_.Reset();
+}
+
+template <typename T>
void FakeDB<T>::UpdateCallback(bool success) {
update_callback_.Run(success);
update_callback_.Reset();
@@ -145,6 +174,15 @@ void FakeDB<T>::RunLoadCallback(
// static
template <typename T>
+void FakeDB<T>::RunGetCallback(
+ const typename ProtoDatabase<T>::GetCallback& callback,
+ std::unique_ptr<T> entry,
+ bool success) {
+ callback.Run(success, std::move(entry));
+}
+
+// static
+template <typename T>
base::FilePath FakeDB<T>::DirectoryForTestDB() {
return base::FilePath(FILE_PATH_LITERAL("/fake/path"));
}
« no previous file with comments | « components/leveldb_proto/proto_database_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698