OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_BROWSER_LEVELDB_WRAPPER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_LEVELDB_WRAPPER_IMPL_H_ |
6 #define CONTENT_BROWSER_LEVELDB_WRAPPER_IMPL_H_ | 6 #define CONTENT_BROWSER_LEVELDB_WRAPPER_IMPL_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "content/common/leveldb_wrapper.mojom.h" | 10 #include "content/common/leveldb_wrapper.mojom.h" |
11 #include "mojo/public/cpp/bindings/binding_set.h" | 11 #include "mojo/public/cpp/bindings/binding_set.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 // This is a wrapper around a leveldb::LevelDBDatabase. It adds a couple of | 15 // This is a wrapper around a leveldb::LevelDBDatabase. It adds a couple of |
16 // features: | 16 // features: |
17 // 1) Adds the given prefix, if any, to all keys. This allows the sharing of one | 17 // 1) Adds the given prefix, if any, to all keys. This allows the sharing of one |
18 // database across many, possibly untrusted, consumers and ensuring that they | 18 // database across many, possibly untrusted, consumers and ensuring that they |
19 // can't access each other's values. | 19 // can't access each other's values. |
20 // 2) Informs an observer when the given prefix' values are modified by another | 20 // 2) Informs an observer when the given prefix' values are modified by another |
21 // process. | 21 // process. |
22 // 3) Throttles requests to avoid overwhelming the disk. | 22 // 3) Throttles requests to avoid overwhelming the disk. |
23 class LevelDBWrapperImpl : public LevelDBWrapper { | 23 class LevelDBWrapperImpl : public LevelDBWrapper { |
24 public: | 24 public: |
25 // |no_bindings_callback| will be called when this object has no more | 25 // |no_bindings_callback| will be called when this object has no more |
26 // bindings. | 26 // bindings. |
27 LevelDBWrapperImpl(const std::string& prefix, | 27 LevelDBWrapperImpl(leveldb::LevelDBDatabase* database, |
| 28 const std::string& prefix, |
28 const base::Closure& no_bindings_callback); | 29 const base::Closure& no_bindings_callback); |
29 ~LevelDBWrapperImpl() override; | 30 ~LevelDBWrapperImpl() override; |
30 | 31 |
31 void Bind(mojo::InterfaceRequest<LevelDBWrapper> request); | 32 void Bind(mojo::InterfaceRequest<LevelDBWrapper> request); |
32 | 33 |
33 private: | 34 private: |
34 // LevelDBWrapperImpl: | 35 // LevelDBWrapperImpl: |
35 void Put(mojo::Array<uint8_t> key, | 36 void Put(mojo::Array<uint8_t> key, |
36 mojo::Array<uint8_t> value, | 37 mojo::Array<uint8_t> value, |
37 const mojo::String& source, | 38 const mojo::String& source, |
38 const PutCallback& callback) override; | 39 const PutCallback& callback) override; |
39 void Delete(mojo::Array<uint8_t> key, | 40 void Delete(mojo::Array<uint8_t> key, |
40 const mojo::String& source, | 41 const mojo::String& source, |
41 const DeleteCallback& callback) override; | 42 const DeleteCallback& callback) override; |
42 void DeleteAll(LevelDBObserverPtr observer, | 43 void DeleteAll(LevelDBObserverPtr observer, |
43 const mojo::String& source, | 44 const mojo::String& source, |
44 const DeleteAllCallback& callback) override; | 45 const DeleteAllCallback& callback) override; |
45 void Get(mojo::Array<uint8_t> key, const GetCallback& callback) override; | 46 void Get(mojo::Array<uint8_t> key, const GetCallback& callback) override; |
46 void GetAll(LevelDBObserverPtr observer, | 47 void GetAll(LevelDBObserverPtr observer, |
47 const GetAllCallback& callback) override; | 48 const GetAllCallback& callback) override; |
48 | 49 |
49 void OnConnectionError(); | 50 void OnConnectionError(); |
50 | 51 |
51 std::string prefix_; | 52 std::string prefix_; |
52 mojo::BindingSet<LevelDBWrapper> bindings_; | 53 mojo::BindingSet<LevelDBWrapper> bindings_; |
53 base::Closure no_bindings_callback_; | 54 base::Closure no_bindings_callback_; |
| 55 leveldb::LevelDBDatabase* database_; |
54 | 56 |
55 DISALLOW_COPY_AND_ASSIGN(LevelDBWrapperImpl); | 57 DISALLOW_COPY_AND_ASSIGN(LevelDBWrapperImpl); |
56 }; | 58 }; |
57 | 59 |
58 } // namespace content | 60 } // namespace content |
59 | 61 |
60 #endif // CONTENT_BROWSER_LEVELDB_WRAPPER_IMPL_H_ | 62 #endif // CONTENT_BROWSER_LEVELDB_WRAPPER_IMPL_H_ |
OLD | NEW |