| 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 "base/memory/scoped_ptr.h" |
| 9 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 9 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
| 10 #include "mojo/public/cpp/bindings/interface_request.h" | 10 #include "mojo/public/cpp/bindings/interface_request.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 void Delete(mojo::Array<uint8_t> key, | 30 void Delete(mojo::Array<uint8_t> key, |
| 31 const DeleteCallback& callback) override; | 31 const DeleteCallback& callback) override; |
| 32 void Write(mojo::Array<BatchedOperationPtr> operations, | 32 void Write(mojo::Array<BatchedOperationPtr> operations, |
| 33 const WriteCallback& callback) override; | 33 const WriteCallback& callback) override; |
| 34 void Get(mojo::Array<uint8_t> key, const GetCallback& callback) override; | 34 void Get(mojo::Array<uint8_t> key, const GetCallback& callback) override; |
| 35 void GetSnapshot(const GetSnapshotCallback& callback) override; | 35 void GetSnapshot(const GetSnapshotCallback& callback) override; |
| 36 void ReleaseSnapshot(uint64_t snapshot_id) override; | 36 void ReleaseSnapshot(uint64_t snapshot_id) override; |
| 37 void GetFromSnapshot(uint64_t snapshot_id, | 37 void GetFromSnapshot(uint64_t snapshot_id, |
| 38 mojo::Array<uint8_t> key, | 38 mojo::Array<uint8_t> key, |
| 39 const GetCallback& callback) override; | 39 const GetCallback& callback) override; |
| 40 void NewIterator(const NewIteratorCallback& callback) override; |
| 41 void NewIteratorFromSnapshot(uint64_t snapshot_id, |
| 42 const NewIteratorCallback& callback) override; |
| 43 void ReleaseIterator(uint64_t iterator_id) override; |
| 44 void IteratorSeekToFirst( |
| 45 uint64_t iterator_id, |
| 46 const IteratorSeekToFirstCallback& callback) override; |
| 47 void IteratorSeekToLast(uint64_t iterator_id, |
| 48 const IteratorSeekToLastCallback& callback) override; |
| 49 void IteratorSeek(uint64_t iterator_id, |
| 50 mojo::Array<uint8_t> target, |
| 51 const IteratorSeekToLastCallback& callback) override; |
| 52 void IteratorNext(uint64_t iterator_id, |
| 53 const IteratorNextCallback& callback) override; |
| 54 void IteratorPrev(uint64_t iterator_id, |
| 55 const IteratorPrevCallback& callback) override; |
| 40 | 56 |
| 41 private: | 57 private: |
| 58 // 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 // directly reference the underlying type in case of bindings change. |
| 61 void ReplyToIteratorMessage(leveldb::Iterator* it, |
| 62 const IteratorSeekToFirstCallback& callback); |
| 63 |
| 42 mojo::StrongBinding<LevelDBDatabase> binding_; | 64 mojo::StrongBinding<LevelDBDatabase> binding_; |
| 43 scoped_ptr<leveldb::Env> environment_; | 65 scoped_ptr<leveldb::Env> environment_; |
| 44 scoped_ptr<leveldb::DB> db_; | 66 scoped_ptr<leveldb::DB> db_; |
| 45 | 67 |
| 46 std::map<uint64_t, const Snapshot*> snapshot_map_; | 68 std::map<uint64_t, const Snapshot*> snapshot_map_; |
| 47 | 69 |
| 48 // TODO(erg): If we have an existing iterator which depends on a snapshot, | 70 // TODO(erg): If we have an existing iterator which depends on a snapshot, |
| 49 // and delete the snapshot from the client side, that shouldn't delete the | 71 // and delete the snapshot from the client side, that shouldn't delete the |
| 50 // snapshot maybe? At worse it's a DDoS if there's multiple users of the | 72 // snapshot maybe? At worse it's a DDoS if there's multiple users of the |
| 51 // system, but this maybe should be fixed... | 73 // system, but this maybe should be fixed... |
| 52 | 74 |
| 53 std::map<uint64_t, Iterator*> iterator_map_; | 75 std::map<uint64_t, Iterator*> iterator_map_; |
| 54 | 76 |
| 55 DISALLOW_COPY_AND_ASSIGN(LevelDBDatabaseImpl); | 77 DISALLOW_COPY_AND_ASSIGN(LevelDBDatabaseImpl); |
| 56 }; | 78 }; |
| 57 | 79 |
| 58 } // namespace leveldb | 80 } // namespace leveldb |
| 59 | 81 |
| 60 #endif // COMPONENTS_LEVELDB_LEVELDB_DATABASE_IMPL_H_ | 82 #endif // COMPONENTS_LEVELDB_LEVELDB_DATABASE_IMPL_H_ |
| OLD | NEW |