Index: components/leveldb_proto/proto_database_impl.h |
diff --git a/components/leveldb_proto/proto_database_impl.h b/components/leveldb_proto/proto_database_impl.h |
index da02eed13876f266f1a45fc883aeae95c061039f..2e04ffff5d596960b1c29fbe67c49f263bec16d8 100644 |
--- a/components/leveldb_proto/proto_database_impl.h |
+++ b/components/leveldb_proto/proto_database_impl.h |
@@ -53,6 +53,8 @@ class ProtoDatabaseImpl : 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; |
@@ -94,12 +96,20 @@ void RunUpdateCallback( |
template <typename T> |
void RunLoadCallback(const typename ProtoDatabase<T>::LoadCallback& callback, |
- const bool* success, |
+ bool* success, |
std::unique_ptr<std::vector<T>> entries) { |
callback.Run(*success, std::move(entries)); |
} |
template <typename T> |
+void RunLoadKeysCallback( |
+ const typename ProtoDatabase<T>::LoadKeysCallback& callback, |
+ std::unique_ptr<bool> success, |
+ std::unique_ptr<std::vector<std::string>> keys) { |
+ callback.Run(*success, std::move(keys)); |
+} |
+ |
+template <typename T> |
void RunGetCallback(const typename ProtoDatabase<T>::GetCallback& callback, |
const bool* success, |
const bool* found, |
@@ -171,6 +181,15 @@ void LoadEntriesFromTaskRunner(LevelDB* database, |
} |
} |
+void LoadKeysFromTaskRunner(LevelDB* database, |
+ std::vector<std::string>* keys, |
+ bool* success) { |
+ DCHECK(success); |
+ DCHECK(keys); |
+ keys->clear(); |
+ *success = database->LoadKeys(keys); |
+} |
+ |
template <typename T> |
void GetEntryFromTaskRunner(LevelDB* database, |
const std::string& key, |
@@ -286,6 +305,22 @@ void ProtoDatabaseImpl<T>::LoadEntries( |
} |
template <typename T> |
+void ProtoDatabaseImpl<T>::LoadKeys( |
+ const typename ProtoDatabase<T>::LoadKeysCallback& callback) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ std::unique_ptr<bool> success(new bool(false)); |
+ std::unique_ptr<std::vector<std::string>> keys( |
+ new std::vector<std::string>()); |
nyquist
2016/10/03 21:46:42
Nit: Can these not use MakeUnique?
tschumann
2016/10/04 09:41:38
Changed to not repeat the types anymore. I think i
nyquist
2016/10/04 14:22:45
Agreed. I think this looks very clean.
|
+ auto load_task = |
+ base::Bind(LoadKeysFromTaskRunner, base::Unretained(db_.get()), |
+ keys.get(), success.get()); |
+ task_runner_->PostTaskAndReply( |
+ FROM_HERE, load_task, |
+ base::Bind(RunLoadKeysCallback<T>, callback, base::Passed(&success), |
+ base::Passed(&keys))); |
+} |
+ |
+template <typename T> |
void ProtoDatabaseImpl<T>::GetEntry( |
const std::string& key, |
const typename ProtoDatabase<T>::GetCallback& callback) { |