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