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