Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / leveldb_proto / proto_database.h
blob119ff5dbfe5e209828a51dadedd3aa4f986d8384
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_
6 #define COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/callback_forward.h"
13 #include "base/memory/scoped_ptr.h"
15 namespace base {
16 class FilePath;
19 namespace leveldb_proto {
21 // Interface for classes providing persistent storage of Protocol Buffer
22 // entries (T must be a Proto type extending MessageLite).
23 template <typename T>
24 class ProtoDatabase {
25 public:
26 using InitCallback = base::Callback<void(bool success)>;
27 using UpdateCallback = base::Callback<void(bool success)>;
28 using LoadCallback =
29 base::Callback<void(bool success, scoped_ptr<std::vector<T>>)>;
31 // A list of key-value (string, T) tuples.
32 using KeyEntryVector = std::vector<std::pair<std::string, T>>;
34 virtual ~ProtoDatabase() {}
36 // Asynchronously initializes the object. |callback| will be invoked on the
37 // calling thread when complete.
38 virtual void Init(const base::FilePath& database_dir,
39 const InitCallback& callback) = 0;
41 // Asynchronously saves |entries_to_save| and deletes entries from
42 // |keys_to_remove| from the database. |callback| will be invoked on the
43 // calling thread when complete.
44 virtual void UpdateEntries(
45 scoped_ptr<KeyEntryVector> entries_to_save,
46 scoped_ptr<std::vector<std::string>> keys_to_remove,
47 const UpdateCallback& callback) = 0;
49 // Asynchronously loads all entries from the database and invokes |callback|
50 // when complete.
51 virtual void LoadEntries(const LoadCallback& callback) = 0;
54 } // namespace leveldb_proto
56 #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_H_