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 COMPONENTS_LEVELDB_LEVELDB_DATABASE_IMPL_H_ | 5 #ifndef COMPONENTS_LEVELDB_LEVELDB_DATABASE_IMPL_H_ |
6 #define COMPONENTS_LEVELDB_LEVELDB_DATABASE_IMPL_H_ | 6 #define COMPONENTS_LEVELDB_LEVELDB_DATABASE_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 10 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
11 #include "mojo/public/cpp/bindings/interface_request.h" | 11 #include "mojo/public/cpp/bindings/interface_request.h" |
12 #include "mojo/public/cpp/bindings/strong_binding.h" | |
13 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 12 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
14 | 13 |
15 namespace leveldb { | 14 namespace leveldb { |
16 | 15 |
17 class MojoEnv; | 16 class MojoEnv; |
18 | 17 |
19 // The backing to a database object that we pass to our called. | 18 // The backing to a database object that we pass to our called. |
20 class LevelDBDatabaseImpl : public mojom::LevelDBDatabase { | 19 class LevelDBDatabaseImpl : public mojom::LevelDBDatabase { |
21 public: | 20 public: |
22 LevelDBDatabaseImpl(leveldb::mojom::LevelDBDatabaseRequest request, | 21 LevelDBDatabaseImpl(std::unique_ptr<leveldb::Env> environment, |
23 std::unique_ptr<leveldb::Env> environment, | |
24 std::unique_ptr<leveldb::DB> db); | 22 std::unique_ptr<leveldb::DB> db); |
25 ~LevelDBDatabaseImpl() override; | 23 ~LevelDBDatabaseImpl() override; |
26 | 24 |
27 // Overridden from LevelDBDatabase: | 25 // Overridden from LevelDBDatabase: |
28 void Put(const std::vector<uint8_t>& key, | 26 void Put(const std::vector<uint8_t>& key, |
29 const std::vector<uint8_t>& value, | 27 const std::vector<uint8_t>& value, |
30 const PutCallback& callback) override; | 28 const PutCallback& callback) override; |
31 void Delete(const std::vector<uint8_t>& key, | 29 void Delete(const std::vector<uint8_t>& key, |
32 const DeleteCallback& callback) override; | 30 const DeleteCallback& callback) override; |
33 void DeletePrefixed(const std::vector<uint8_t>& key_prefix, | 31 void DeletePrefixed(const std::vector<uint8_t>& key_prefix, |
(...skipping 29 matching lines...) Expand all Loading... |
63 private: | 61 private: |
64 // Returns the state of |it| to a caller. Note: This assumes that all the | 62 // Returns the state of |it| to a caller. Note: This assumes that all the |
65 // iterator movement methods have the same callback signature. We don't | 63 // iterator movement methods have the same callback signature. We don't |
66 // directly reference the underlying type in case of bindings change. | 64 // directly reference the underlying type in case of bindings change. |
67 void ReplyToIteratorMessage(leveldb::Iterator* it, | 65 void ReplyToIteratorMessage(leveldb::Iterator* it, |
68 const IteratorSeekToFirstCallback& callback); | 66 const IteratorSeekToFirstCallback& callback); |
69 | 67 |
70 leveldb::Status DeletePrefixedHelper(const leveldb::Slice& key_prefix, | 68 leveldb::Status DeletePrefixedHelper(const leveldb::Slice& key_prefix, |
71 leveldb::WriteBatch* batch); | 69 leveldb::WriteBatch* batch); |
72 | 70 |
73 mojo::StrongBinding<mojom::LevelDBDatabase> binding_; | |
74 std::unique_ptr<leveldb::Env> environment_; | 71 std::unique_ptr<leveldb::Env> environment_; |
75 std::unique_ptr<leveldb::DB> db_; | 72 std::unique_ptr<leveldb::DB> db_; |
76 | 73 |
77 std::map<uint64_t, const Snapshot*> snapshot_map_; | 74 std::map<uint64_t, const Snapshot*> snapshot_map_; |
78 | 75 |
79 // TODO(erg): If we have an existing iterator which depends on a snapshot, | 76 // TODO(erg): If we have an existing iterator which depends on a snapshot, |
80 // and delete the snapshot from the client side, that shouldn't delete the | 77 // and delete the snapshot from the client side, that shouldn't delete the |
81 // snapshot maybe? At worse it's a DDoS if there's multiple users of the | 78 // snapshot maybe? At worse it's a DDoS if there's multiple users of the |
82 // system, but this maybe should be fixed... | 79 // system, but this maybe should be fixed... |
83 | 80 |
84 std::map<uint64_t, Iterator*> iterator_map_; | 81 std::map<uint64_t, Iterator*> iterator_map_; |
85 | 82 |
86 DISALLOW_COPY_AND_ASSIGN(LevelDBDatabaseImpl); | 83 DISALLOW_COPY_AND_ASSIGN(LevelDBDatabaseImpl); |
87 }; | 84 }; |
88 | 85 |
89 } // namespace leveldb | 86 } // namespace leveldb |
90 | 87 |
91 #endif // COMPONENTS_LEVELDB_LEVELDB_DATABASE_IMPL_H_ | 88 #endif // COMPONENTS_LEVELDB_LEVELDB_DATABASE_IMPL_H_ |
OLD | NEW |