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