Add ability to load keys/entries at same time in LevelDB/ProtoDB.

Keys and entries can currently be loaded separately, but never at the
same time, meaning it requires separate calls to LoadKeys/LoadEntries
to get keys and entries. Some users of ProtoDatabase have resorted to
storing the keys in the entries to get around this.

This CL adds LoadKeysAndEntries(WithFilter) that returns both at the
same time. ProtoDatabase's new LoadKeysAndEntriesCallback gives back a
vector of string/proto pairs.

Bug: 883409
Change-Id: Id624bbdeb356395c6ce679528d85c1f934a9772e
Reviewed-on: https://chromium-review.googlesource.com/1228305
Commit-Queue: Troy Hildebrandt <[email protected]>
Reviewed-by: Tommy Nyquist <[email protected]>
Reviewed-by: David Trainor <[email protected]>
Cr-Commit-Position: refs/heads/master@{#595175}
diff --git a/components/leveldb_proto/proto_database.h b/components/leveldb_proto/proto_database.h
index 1d0e543..b62bd4f 100644
--- a/components/leveldb_proto/proto_database.h
+++ b/components/leveldb_proto/proto_database.h
@@ -5,6 +5,7 @@
 #ifndef COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_
 #define COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_
 
+#include <map>
 #include <memory>
 #include <string>
 #include <utility>
@@ -32,6 +33,9 @@
   using LoadKeysCallback =
       base::OnceCallback<void(bool success,
                               std::unique_ptr<std::vector<std::string>>)>;
+  using LoadKeysAndEntriesCallback =
+      base::OnceCallback<void(bool success,
+                              std::unique_ptr<std::map<std::string, T>>)>;
   using GetCallback =
       base::OnceCallback<void(bool success, std::unique_ptr<T>)>;
   using DestroyCallback = base::OnceCallback<void(bool success)>;
@@ -79,6 +83,17 @@
                                      const std::string& target_prefix,
                                      LoadCallback callback) = 0;
 
+  virtual void LoadKeysAndEntries(
+      typename ProtoDatabase<T>::LoadKeysAndEntriesCallback callback) = 0;
+  virtual void LoadKeysAndEntriesWithFilter(
+      const LevelDB::KeyFilter& filter,
+      typename ProtoDatabase<T>::LoadKeysAndEntriesCallback callback) = 0;
+  virtual void LoadKeysAndEntriesWithFilter(
+      const LevelDB::KeyFilter& filter,
+      const leveldb::ReadOptions& options,
+      const std::string& target_prefix,
+      typename ProtoDatabase<T>::LoadKeysAndEntriesCallback callback) = 0;
+
   // Asynchronously loads all keys from the database and invokes |callback| with
   // those keys when complete.
   virtual void LoadKeys(LoadKeysCallback callback) = 0;