OLD | NEW |
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 <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.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, scoped_ptr<std::vector<T>>)>; | 29 base::Callback<void(bool success, scoped_ptr<std::vector<T>>)>; |
| 30 using DestroyCallback = base::Callback<void(bool success)>; |
30 | 31 |
31 // A list of key-value (string, T) tuples. | 32 // A list of key-value (string, T) tuples. |
32 using KeyEntryVector = std::vector<std::pair<std::string, T>>; | 33 using KeyEntryVector = std::vector<std::pair<std::string, T>>; |
33 | 34 |
34 virtual ~ProtoDatabase() {} | 35 virtual ~ProtoDatabase() {} |
35 | 36 |
36 // Asynchronously initializes the object. |callback| will be invoked on the | 37 // Asynchronously initializes the object. |callback| will be invoked on the |
37 // calling thread when complete. | 38 // calling thread when complete. |
38 virtual void Init(const char* client_name, | 39 virtual void Init(const char* client_name, |
39 const base::FilePath& database_dir, | 40 const base::FilePath& database_dir, |
40 const InitCallback& callback) = 0; | 41 const InitCallback& callback) = 0; |
41 | 42 |
42 // Asynchronously saves |entries_to_save| and deletes entries from | 43 // Asynchronously saves |entries_to_save| and deletes entries from |
43 // |keys_to_remove| from the database. |callback| will be invoked on the | 44 // |keys_to_remove| from the database. |callback| will be invoked on the |
44 // calling thread when complete. | 45 // calling thread when complete. |
45 virtual void UpdateEntries( | 46 virtual void UpdateEntries( |
46 scoped_ptr<KeyEntryVector> entries_to_save, | 47 scoped_ptr<KeyEntryVector> entries_to_save, |
47 scoped_ptr<std::vector<std::string>> keys_to_remove, | 48 scoped_ptr<std::vector<std::string>> keys_to_remove, |
48 const UpdateCallback& callback) = 0; | 49 const UpdateCallback& callback) = 0; |
49 | 50 |
50 // Asynchronously loads all entries from the database and invokes |callback| | 51 // Asynchronously loads all entries from the database and invokes |callback| |
51 // when complete. | 52 // when complete. |
52 virtual void LoadEntries(const LoadCallback& callback) = 0; | 53 virtual void LoadEntries(const LoadCallback& callback) = 0; |
| 54 |
| 55 // Asynchronously destroys the database. |
| 56 virtual void Destroy(const DestroyCallback& callback) = 0; |
53 }; | 57 }; |
54 | 58 |
55 } // namespace leveldb_proto | 59 } // namespace leveldb_proto |
56 | 60 |
57 #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_ | 61 #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_ |
OLD | NEW |