Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: content/browser/indexed_db/leveldb/leveldb_transaction.h

Issue 2760163002: [IndexedDB] Pool and evict leveldb iterators, to save memory (Closed)
Patch Set: comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_TRANSACTION_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_
6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
17 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" 17 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h"
18 #include "content/browser/indexed_db/leveldb/leveldb_database.h" 18 #include "content/browser/indexed_db/leveldb/leveldb_database.h"
19 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" 19 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h"
20 20
21 namespace content { 21 namespace content {
22
23 class LevelDBTransactionRangeTest;
24 class LevelDBWriteBatch; 22 class LevelDBWriteBatch;
25 23
26 class CONTENT_EXPORT LevelDBTransaction 24 class CONTENT_EXPORT LevelDBTransaction
27 : public base::RefCounted<LevelDBTransaction> { 25 : public base::RefCounted<LevelDBTransaction> {
28 public: 26 public:
29 void Put(const base::StringPiece& key, std::string* value); 27 void Put(const base::StringPiece& key, std::string* value);
30 28
31 void Remove(const base::StringPiece& key); 29 void Remove(const base::StringPiece& key);
32 30
33 leveldb::Status RemoveRange(const base::StringPiece& begin, 31 leveldb::Status RemoveRange(const base::StringPiece& begin,
34 const base::StringPiece& end, 32 const base::StringPiece& end,
35 bool upper_open); 33 bool upper_open);
36 34
37 virtual leveldb::Status Get(const base::StringPiece& key, 35 virtual leveldb::Status Get(const base::StringPiece& key,
38 std::string* value, 36 std::string* value,
39 bool* found); 37 bool* found);
40 virtual leveldb::Status Commit(); 38 virtual leveldb::Status Commit();
41 void Rollback(); 39 void Rollback();
42 40
43 std::unique_ptr<LevelDBIterator> CreateIterator(); 41 std::unique_ptr<LevelDBIterator> CreateIterator();
44 42
45 protected: 43 protected:
46 virtual ~LevelDBTransaction(); 44 virtual ~LevelDBTransaction();
47 explicit LevelDBTransaction(LevelDBDatabase* db); 45 explicit LevelDBTransaction(LevelDBDatabase* db);
48 friend class IndexedDBClassFactory; 46 friend class IndexedDBClassFactory;
49 47
50 private: 48 private:
51 friend class base::RefCounted<LevelDBTransaction>; 49 friend class base::RefCounted<LevelDBTransaction>;
52 friend class content::LevelDBTransactionRangeTest; 50 friend class LevelDBTransactionRangeTest;
51 friend class LevelDBTransactionTest;
53 FRIEND_TEST_ALL_PREFIXES(LevelDBTransactionTest, GetAndPut); 52 FRIEND_TEST_ALL_PREFIXES(LevelDBTransactionTest, GetAndPut);
54 FRIEND_TEST_ALL_PREFIXES(LevelDBTransactionTest, Commit); 53 FRIEND_TEST_ALL_PREFIXES(LevelDBTransactionTest, Commit);
55 FRIEND_TEST_ALL_PREFIXES(LevelDBTransactionTest, Iterator); 54 FRIEND_TEST_ALL_PREFIXES(LevelDBTransactionTest, Iterator);
56 55
57 struct Record { 56 struct Record {
58 Record(); 57 Record();
59 ~Record(); 58 ~Record();
60 std::string key; 59 std::string key;
61 std::string value; 60 std::string value;
62 bool deleted = false; 61 bool deleted = false;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 static std::unique_ptr<TransactionIterator> Create( 115 static std::unique_ptr<TransactionIterator> Create(
117 scoped_refptr<LevelDBTransaction> transaction); 116 scoped_refptr<LevelDBTransaction> transaction);
118 117
119 bool IsValid() const override; 118 bool IsValid() const override;
120 leveldb::Status SeekToLast() override; 119 leveldb::Status SeekToLast() override;
121 leveldb::Status Seek(const base::StringPiece& target) override; 120 leveldb::Status Seek(const base::StringPiece& target) override;
122 leveldb::Status Next() override; 121 leveldb::Status Next() override;
123 leveldb::Status Prev() override; 122 leveldb::Status Prev() override;
124 base::StringPiece Key() const override; 123 base::StringPiece Key() const override;
125 base::StringPiece Value() const override; 124 base::StringPiece Value() const override;
125 // Exposed for testing.
126 bool IsDetached() const override;
126 void DataChanged(); 127 void DataChanged();
127 128
128 // Mark the current record as deleted. If an existing record 129 // Mark the current record as deleted. If an existing record
129 // is present in the uncommitted data this will convert it to 130 // is present in the uncommitted data this will convert it to
130 // a deletion record, otherwise it will insert a new one. 131 // a deletion record, otherwise it will insert a new one.
131 void Delete(); 132 void Delete();
132 133
133 private: 134 private:
134 enum Direction { FORWARD, REVERSE }; 135 enum Direction { FORWARD, REVERSE };
135 136
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 LevelDBDatabase* db_; 190 LevelDBDatabase* db_;
190 std::unique_ptr<LevelDBWriteBatch> write_batch_; 191 std::unique_ptr<LevelDBWriteBatch> write_batch_;
191 bool finished_ = false; 192 bool finished_ = false;
192 193
193 DISALLOW_COPY_AND_ASSIGN(LevelDBDirectTransaction); 194 DISALLOW_COPY_AND_ASSIGN(LevelDBDirectTransaction);
194 }; 195 };
195 196
196 } // namespace content 197 } // namespace content
197 198
198 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_ 199 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_iterator_impl.cc ('k') | content/browser/indexed_db/leveldb/leveldb_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698