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

Side by Side Diff: components/leveldb_proto/proto_database.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 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 LoadKeysCallback =
31 base::Callback<void(bool success,
32 std::unique_ptr<std::vector<std::string>>)>;
30 using GetCallback = base::Callback<void(bool success, std::unique_ptr<T>)>; 33 using GetCallback = base::Callback<void(bool success, std::unique_ptr<T>)>;
31 using DestroyCallback = base::Callback<void(bool success)>; 34 using DestroyCallback = base::Callback<void(bool success)>;
32 35
33 // A list of key-value (string, T) tuples. 36 // A list of key-value (string, T) tuples.
34 using KeyEntryVector = std::vector<std::pair<std::string, T>>; 37 using KeyEntryVector = std::vector<std::pair<std::string, T>>;
35 38
36 virtual ~ProtoDatabase() {} 39 virtual ~ProtoDatabase() {}
37 40
38 // Asynchronously initializes the object. |callback| will be invoked on the 41 // Asynchronously initializes the object. |callback| will be invoked on the
39 // calling thread when complete. 42 // calling thread when complete.
40 virtual void Init(const char* client_name, 43 virtual void Init(const char* client_name,
41 const base::FilePath& database_dir, 44 const base::FilePath& database_dir,
42 const InitCallback& callback) = 0; 45 const InitCallback& callback) = 0;
43 46
44 // Asynchronously saves |entries_to_save| and deletes entries from 47 // Asynchronously saves |entries_to_save| and deletes entries from
45 // |keys_to_remove| from the database. |callback| will be invoked on the 48 // |keys_to_remove| from the database. |callback| will be invoked on the
46 // calling thread when complete. 49 // calling thread when complete.
47 virtual void UpdateEntries( 50 virtual void UpdateEntries(
48 std::unique_ptr<KeyEntryVector> entries_to_save, 51 std::unique_ptr<KeyEntryVector> entries_to_save,
49 std::unique_ptr<std::vector<std::string>> keys_to_remove, 52 std::unique_ptr<std::vector<std::string>> keys_to_remove,
50 const UpdateCallback& callback) = 0; 53 const UpdateCallback& callback) = 0;
51 54
52 // Asynchronously loads all entries from the database and invokes |callback| 55 // Asynchronously loads all entries from the database and invokes |callback|
53 // when complete. 56 // when complete.
54 virtual void LoadEntries(const LoadCallback& callback) = 0; 57 virtual void LoadEntries(const LoadCallback& callback) = 0;
55 58
59 // Asynchronously loads all keys from the database and invokes |callback| with
60 // those keys when complete.
61 virtual void LoadKeys(const LoadKeysCallback& callback) = 0;
62
56 // Asynchronously loads a single entry, identified by |key|, from the database 63 // Asynchronously loads a single entry, identified by |key|, from the database
57 // and invokes |callback| when complete. If no entry with |key| is found, 64 // 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. 65 // a nullptr is passed to the callback, but the success flag is still true.
59 virtual void GetEntry(const std::string& key, 66 virtual void GetEntry(const std::string& key,
60 const GetCallback& callback) = 0; 67 const GetCallback& callback) = 0;
61 68
62 // Asynchronously destroys the database. 69 // Asynchronously destroys the database.
63 virtual void Destroy(const DestroyCallback& callback) = 0; 70 virtual void Destroy(const DestroyCallback& callback) = 0;
64 }; 71 };
65 72
66 } // namespace leveldb_proto 73 } // namespace leveldb_proto
67 74
68 #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_ 75 #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