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

Side by Side Diff: components/leveldb_proto/proto_database.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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_ 5 #ifndef COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_
6 #define COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_ 6 #define COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 14
15 namespace base { 15 namespace base {
16 class FilePath; 16 class FilePath;
17 } 17 }
18 18
19 namespace leveldb_proto { 19 namespace leveldb_proto {
20 20
21 // Interface for classes providing persistent storage of Protocol Buffer 21 // Interface for classes providing persistent storage of Protocol Buffer
22 // entries (T must be a Proto type extending MessageLite). 22 // entries (T must be a Proto type extending MessageLite).
23 template <typename T> 23 template <typename T>
24 class ProtoDatabase { 24 class ProtoDatabase {
25 public: 25 public:
26 using InitCallback = base::Callback<void(bool success)>; 26 using InitCallback = base::Callback<void(bool success)>;
27 using UpdateCallback = base::Callback<void(bool success)>; 27 using UpdateCallback = base::Callback<void(bool success)>;
28 using LoadCallback = 28 using LoadCallback =
29 base::Callback<void(bool success, std::unique_ptr<std::vector<T>>)>; 29 base::Callback<void(bool success, std::unique_ptr<std::vector<T>>)>;
30 using GetCallback = base::Callback<void(bool success, std::unique_ptr<T>)>;
30 using DestroyCallback = base::Callback<void(bool success)>; 31 using DestroyCallback = base::Callback<void(bool success)>;
31 32
32 // A list of key-value (string, T) tuples. 33 // A list of key-value (string, T) tuples.
33 using KeyEntryVector = std::vector<std::pair<std::string, T>>; 34 using KeyEntryVector = std::vector<std::pair<std::string, T>>;
34 35
35 virtual ~ProtoDatabase() {} 36 virtual ~ProtoDatabase() {}
36 37
37 // Asynchronously initializes the object. |callback| will be invoked on the 38 // Asynchronously initializes the object. |callback| will be invoked on the
38 // calling thread when complete. 39 // calling thread when complete.
39 virtual void Init(const char* client_name, 40 virtual void Init(const char* client_name,
40 const base::FilePath& database_dir, 41 const base::FilePath& database_dir,
41 const InitCallback& callback) = 0; 42 const InitCallback& callback) = 0;
42 43
43 // Asynchronously saves |entries_to_save| and deletes entries from 44 // Asynchronously saves |entries_to_save| and deletes entries from
44 // |keys_to_remove| from the database. |callback| will be invoked on the 45 // |keys_to_remove| from the database. |callback| will be invoked on the
45 // calling thread when complete. 46 // calling thread when complete.
46 virtual void UpdateEntries( 47 virtual void UpdateEntries(
47 std::unique_ptr<KeyEntryVector> entries_to_save, 48 std::unique_ptr<KeyEntryVector> entries_to_save,
48 std::unique_ptr<std::vector<std::string>> keys_to_remove, 49 std::unique_ptr<std::vector<std::string>> keys_to_remove,
49 const UpdateCallback& callback) = 0; 50 const UpdateCallback& callback) = 0;
50 51
51 // Asynchronously loads all entries from the database and invokes |callback| 52 // Asynchronously loads all entries from the database and invokes |callback|
52 // when complete. 53 // when complete.
53 virtual void LoadEntries(const LoadCallback& callback) = 0; 54 virtual void LoadEntries(const LoadCallback& callback) = 0;
54 55
56 // Asynchronously loads a single entry, identified by |key|, from the database
57 // and invokes |callback| when complete. If no entry with |key| is found,
58 // a nullptr is passed to the callback, but the success flag is still true.
59 virtual void GetEntry(const std::string& key,
60 const GetCallback& callback) = 0;
61
55 // Asynchronously destroys the database. 62 // Asynchronously destroys the database.
56 virtual void Destroy(const DestroyCallback& callback) = 0; 63 virtual void Destroy(const DestroyCallback& callback) = 0;
57 }; 64 };
58 65
59 } // namespace leveldb_proto 66 } // namespace leveldb_proto
60 67
61 #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_ 68 #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_
OLDNEW
« no previous file with comments | « components/leveldb_proto/leveldb_database.cc ('k') | components/leveldb_proto/proto_database_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698