OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_ITERATOR_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_ITERATOR_IMPL_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_ITERATOR_IMPL_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_ITERATOR_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
| 9 #include <string> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 12 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
13 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" | 14 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" |
14 | 15 |
| 16 namespace leveldb { |
| 17 class Snapshot; |
| 18 } |
| 19 |
15 namespace content { | 20 namespace content { |
| 21 class LevelDBDatabase; |
16 | 22 |
17 class CONTENT_EXPORT LevelDBIteratorImpl : public content::LevelDBIterator { | 23 class CONTENT_EXPORT LevelDBIteratorImpl : public content::LevelDBIterator { |
18 public: | 24 public: |
19 ~LevelDBIteratorImpl() override; | 25 ~LevelDBIteratorImpl() override; |
20 bool IsValid() const override; | 26 bool IsValid() const override; |
21 leveldb::Status SeekToLast() override; | 27 leveldb::Status SeekToLast() override; |
22 leveldb::Status Seek(const base::StringPiece& target) override; | 28 leveldb::Status Seek(const base::StringPiece& target) override; |
23 leveldb::Status Next() override; | 29 leveldb::Status Next() override; |
24 leveldb::Status Prev() override; | 30 leveldb::Status Prev() override; |
25 base::StringPiece Key() const override; | 31 base::StringPiece Key() const override; |
26 base::StringPiece Value() const override; | 32 base::StringPiece Value() const override; |
| 33 void Detach() override; |
| 34 bool IsDetached() const override; |
27 | 35 |
28 protected: | 36 protected: |
29 explicit LevelDBIteratorImpl(std::unique_ptr<leveldb::Iterator> iterator); | 37 explicit LevelDBIteratorImpl(std::unique_ptr<leveldb::Iterator> iterator, |
| 38 LevelDBDatabase* db, |
| 39 const leveldb::Snapshot* snapshot); |
30 | 40 |
31 private: | 41 private: |
32 void CheckStatus(); | 42 enum class IteratorState { ACTIVE, EVICTED_AND_VALID, EVICTED_AND_INVALID }; |
| 43 |
| 44 leveldb::Status CheckStatus(); |
| 45 |
| 46 // Notifies the database of iterator usage and recreates iterator if needed. |
| 47 void WillUseDBIterator(); |
33 | 48 |
34 friend class IndexedDBClassFactory; | 49 friend class IndexedDBClassFactory; |
35 friend class MockBrowserTestIndexedDBClassFactory; | 50 friend class MockBrowserTestIndexedDBClassFactory; |
36 | 51 |
37 std::unique_ptr<leveldb::Iterator> iterator_; | 52 std::unique_ptr<leveldb::Iterator> iterator_; |
38 | 53 |
| 54 // State used to facilitate memory purging. |
| 55 LevelDBDatabase* db_; |
| 56 IteratorState iterator_state_ = IteratorState::ACTIVE; |
| 57 std::string key_before_eviction_; |
| 58 const leveldb::Snapshot* snapshot_; |
| 59 |
39 DISALLOW_COPY_AND_ASSIGN(LevelDBIteratorImpl); | 60 DISALLOW_COPY_AND_ASSIGN(LevelDBIteratorImpl); |
40 }; | 61 }; |
41 | 62 |
42 } // namespace content | 63 } // namespace content |
43 | 64 |
44 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_ITERATOR_IMPL_H_ | 65 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_ITERATOR_IMPL_H_ |
OLD | NEW |