Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: content/browser/leveldb_wrapper_impl.h

Issue 1837883003: Some fleshing out the mojo based localstorage implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "mojo/public/cpp/bindings/interface_ptr_set.h"
12 13
13 namespace content { 14 namespace content {
14 15
15 // This is a wrapper around a leveldb::LevelDBDatabase. It adds a couple of 16 // This is a wrapper around a leveldb::LevelDBDatabase. It adds a couple of
16 // features: 17 // features:
17 // 1) Adds the given prefix, if any, to all keys. This allows the sharing of one 18 // 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 // database across many, possibly untrusted, consumers and ensuring that they
19 // can't access each other's values. 20 // can't access each other's values.
20 // 2) Informs an observer when the given prefix' values are modified by another 21 // 2) Enforces a max_size constraint.
21 // process. 22 // 3) Informs an observer when the given prefix' values are modified.
22 // 3) Throttles requests to avoid overwhelming the disk. 23 // 4) Throttles requests to avoid overwhelming the disk.
23 class LevelDBWrapperImpl : public mojom::LevelDBWrapper { 24 class LevelDBWrapperImpl : public mojom::LevelDBWrapper {
24 public: 25 public:
25 // |no_bindings_callback| will be called when this object has no more 26 // |no_bindings_callback| will be called when this object has no more
26 // bindings. 27 // bindings.
27 LevelDBWrapperImpl(leveldb::LevelDBDatabase* database, 28 LevelDBWrapperImpl(leveldb::LevelDBDatabase* database,
28 const std::string& prefix, 29 const std::string& prefix,
30 size_t max_size,
29 const base::Closure& no_bindings_callback); 31 const base::Closure& no_bindings_callback);
30 ~LevelDBWrapperImpl() override; 32 ~LevelDBWrapperImpl() override;
31 33
32 void Bind(mojom::LevelDBWrapperRequest request); 34 void Bind(mojom::LevelDBWrapperRequest request);
35 void AddObserver(mojom::LevelDBObserverPtr observer);
33 36
34 private: 37 private:
35 // LevelDBWrapperImpl: 38 // LevelDBWrapperImpl:
36 void Put(mojo::Array<uint8_t> key, 39 void Put(mojo::Array<uint8_t> key,
37 mojo::Array<uint8_t> value, 40 mojo::Array<uint8_t> value,
38 const mojo::String& source, 41 const mojo::String& source,
39 const PutCallback& callback) override; 42 const PutCallback& callback) override;
40 void Delete(mojo::Array<uint8_t> key, 43 void Delete(mojo::Array<uint8_t> key,
41 const mojo::String& source, 44 const mojo::String& source,
42 const DeleteCallback& callback) override; 45 const DeleteCallback& callback) override;
43 void DeleteAll(mojom::LevelDBObserverPtr observer, 46 void DeleteAll(const mojo::String& source,
44 const mojo::String& source,
45 const DeleteAllCallback& callback) override; 47 const DeleteAllCallback& callback) override;
46 void Get(mojo::Array<uint8_t> key, const GetCallback& callback) override; 48 void Get(mojo::Array<uint8_t> key, const GetCallback& callback) override;
47 void GetAll(mojom::LevelDBObserverPtr observer, 49 void GetAll(const mojo::String& source,
48 const GetAllCallback& callback) override; 50 const GetAllCallback& callback) override;
49 51
50 void OnConnectionError(); 52 void OnConnectionError();
51 53
52 std::string prefix_; 54 std::string prefix_;
53 mojo::BindingSet<mojom::LevelDBWrapper> bindings_; 55 mojo::BindingSet<mojom::LevelDBWrapper> bindings_;
56 mojo::InterfacePtrSet<mojom::LevelDBObserver> observers_;
54 base::Closure no_bindings_callback_; 57 base::Closure no_bindings_callback_;
55 leveldb::LevelDBDatabase* database_; 58 leveldb::LevelDBDatabase* database_;
59 std::map<mojo::Array<uint8_t>, mojo::Array<uint8_t>> map_;
60 size_t bytes_used_;
61 size_t max_size_;
56 62
57 DISALLOW_COPY_AND_ASSIGN(LevelDBWrapperImpl); 63 DISALLOW_COPY_AND_ASSIGN(LevelDBWrapperImpl);
58 }; 64 };
59 65
60 } // namespace content 66 } // namespace content
61 67
62 #endif // CONTENT_BROWSER_LEVELDB_WRAPPER_IMPL_H_ 68 #endif // CONTENT_BROWSER_LEVELDB_WRAPPER_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_wrapper.cc ('k') | content/browser/leveldb_wrapper_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698