Chromium Code Reviews| 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: |
| 42 enum class IteratorState { ACTIVE, EVICTED_AND_VALID, EVICTED_AND_INVALID }; | |
| 43 | |
| 32 void CheckStatus(); | 44 void CheckStatus(); |
| 33 | 45 |
| 46 void WillUseDBIterator(); | |
|
jsbell
2017/03/27 15:35:34
Add comment.
dmurph
2017/03/27 21:32:05
Done.
| |
| 47 | |
| 34 friend class IndexedDBClassFactory; | 48 friend class IndexedDBClassFactory; |
| 35 friend class MockBrowserTestIndexedDBClassFactory; | 49 friend class MockBrowserTestIndexedDBClassFactory; |
| 36 | 50 |
| 37 std::unique_ptr<leveldb::Iterator> iterator_; | 51 std::unique_ptr<leveldb::Iterator> iterator_; |
| 38 | 52 |
| 53 // Variables to facilitate memory purging. | |
|
pwnall
2017/03/27 17:08:04
I'd prefer "state used by" -- I think that variabl
dmurph
2017/03/27 21:32:05
Done.
| |
| 54 LevelDBDatabase* db_; | |
| 55 IteratorState iterator_state_ = IteratorState::ACTIVE; | |
| 56 std::string key_before_eviction_; | |
| 57 const leveldb::Snapshot* snapshot_; | |
| 58 | |
| 39 DISALLOW_COPY_AND_ASSIGN(LevelDBIteratorImpl); | 59 DISALLOW_COPY_AND_ASSIGN(LevelDBIteratorImpl); |
| 40 }; | 60 }; |
| 41 | 61 |
| 42 } // namespace content | 62 } // namespace content |
| 43 | 63 |
| 44 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_ITERATOR_IMPL_H_ | 64 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_ITERATOR_IMPL_H_ |
| OLD | NEW |