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