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_LEVEL_DB_WRAPPER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_LEVEL_DB_WRAPPER_IMPL_H_ |
6 #define CONTENT_BROWSER_LEVEL_DB_WRAPPER_IMPL_H_ | 6 #define CONTENT_BROWSER_LEVEL_DB_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 { |
michaeln
2016/02/27 00:59:03
Hey, why isn't this class part in component/leveld
| |
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 LevelDBObserverPtr observer); | 33 LevelDBObserverPtr observer); |
33 | 34 |
34 private: | 35 private: |
35 // LevelDBWrapperImpl: | 36 // LevelDBWrapperImpl: |
36 void Put(mojo::Array<uint8_t> key, | 37 void Put(mojo::Array<uint8_t> key, |
37 mojo::Array<uint8_t> value, | 38 mojo::Array<uint8_t> value, |
38 const mojo::String& source, | 39 const mojo::String& source, |
39 const PutCallback& callback) override; | 40 const PutCallback& callback) override; |
40 void Delete(mojo::Array<uint8_t> key, | 41 void Delete(mojo::Array<uint8_t> key, |
41 const mojo::String& source, | 42 const mojo::String& source, |
42 const DeleteCallback& callback) override; | 43 const DeleteCallback& callback) override; |
43 void DeleteAll(const mojo::String& source, | 44 void DeleteAll(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(const GetAllCallback& callback) override; | 47 void GetAll(const GetAllCallback& callback) override; |
47 | 48 |
48 void OnConnectionError(); | 49 void OnConnectionError(); |
49 | 50 |
50 std::string prefix_; | 51 std::string prefix_; |
51 mojo::BindingSet<LevelDBWrapper> bindings_; | 52 mojo::BindingSet<LevelDBWrapper> bindings_; |
52 base::Closure no_bindings_callback_; | 53 base::Closure no_bindings_callback_; |
54 leveldb::LevelDBDatabase* database_; | |
53 | 55 |
54 DISALLOW_COPY_AND_ASSIGN(LevelDBWrapperImpl); | 56 DISALLOW_COPY_AND_ASSIGN(LevelDBWrapperImpl); |
55 }; | 57 }; |
56 | 58 |
57 } // namespace content | 59 } // namespace content |
58 | 60 |
59 #endif // CONTENT_BROWSER_LEVEL_DB_WRAPPER_IMPL_H_ | 61 #endif // CONTENT_BROWSER_LEVEL_DB_WRAPPER_IMPL_H_ |
OLD | NEW |