OLD | NEW |
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 <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 virtual leveldb::Status Next() OVERRIDE; | 73 virtual leveldb::Status Next() OVERRIDE; |
74 virtual leveldb::Status Prev() OVERRIDE; | 74 virtual leveldb::Status Prev() OVERRIDE; |
75 virtual base::StringPiece Key() const OVERRIDE; | 75 virtual base::StringPiece Key() const OVERRIDE; |
76 virtual base::StringPiece Value() const OVERRIDE; | 76 virtual base::StringPiece Value() const OVERRIDE; |
77 bool IsDeleted() const; | 77 bool IsDeleted() const; |
78 | 78 |
79 private: | 79 private: |
80 explicit DataIterator(LevelDBTransaction* transaction); | 80 explicit DataIterator(LevelDBTransaction* transaction); |
81 DataType* data_; | 81 DataType* data_; |
82 DataType::iterator iterator_; | 82 DataType::iterator iterator_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(DataIterator); |
83 }; | 85 }; |
84 | 86 |
85 class TransactionIterator : public LevelDBIterator { | 87 class TransactionIterator : public LevelDBIterator { |
86 public: | 88 public: |
87 virtual ~TransactionIterator(); | 89 virtual ~TransactionIterator(); |
88 static scoped_ptr<TransactionIterator> Create( | 90 static scoped_ptr<TransactionIterator> Create( |
89 scoped_refptr<LevelDBTransaction> transaction); | 91 scoped_refptr<LevelDBTransaction> transaction); |
90 | 92 |
91 virtual bool IsValid() const OVERRIDE; | 93 virtual bool IsValid() const OVERRIDE; |
92 virtual leveldb::Status SeekToLast() OVERRIDE; | 94 virtual leveldb::Status SeekToLast() OVERRIDE; |
(...skipping 18 matching lines...) Expand all Loading... |
111 mutable scoped_ptr<DataIterator> data_iterator_; | 113 mutable scoped_ptr<DataIterator> data_iterator_; |
112 scoped_ptr<LevelDBIterator> db_iterator_; | 114 scoped_ptr<LevelDBIterator> db_iterator_; |
113 LevelDBIterator* current_; | 115 LevelDBIterator* current_; |
114 | 116 |
115 enum Direction { | 117 enum Direction { |
116 FORWARD, | 118 FORWARD, |
117 REVERSE | 119 REVERSE |
118 }; | 120 }; |
119 Direction direction_; | 121 Direction direction_; |
120 mutable bool data_changed_; | 122 mutable bool data_changed_; |
| 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(TransactionIterator); |
121 }; | 125 }; |
122 | 126 |
123 void Set(const base::StringPiece& key, std::string* value, bool deleted); | 127 void Set(const base::StringPiece& key, std::string* value, bool deleted); |
124 void Clear(); | 128 void Clear(); |
125 void RegisterIterator(TransactionIterator* iterator); | 129 void RegisterIterator(TransactionIterator* iterator); |
126 void UnregisterIterator(TransactionIterator* iterator); | 130 void UnregisterIterator(TransactionIterator* iterator); |
127 void NotifyIterators(); | 131 void NotifyIterators(); |
128 | 132 |
129 LevelDBDatabase* db_; | 133 LevelDBDatabase* db_; |
130 const LevelDBSnapshot snapshot_; | 134 const LevelDBSnapshot snapshot_; |
131 const LevelDBComparator* comparator_; | 135 const LevelDBComparator* comparator_; |
132 Comparator data_comparator_; | 136 Comparator data_comparator_; |
133 DataType data_; | 137 DataType data_; |
134 bool finished_; | 138 bool finished_; |
135 std::set<TransactionIterator*> iterators_; | 139 std::set<TransactionIterator*> iterators_; |
| 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(LevelDBTransaction); |
136 }; | 142 }; |
137 | 143 |
138 // Reads go straight to the database, ignoring any writes cached in | 144 // Reads go straight to the database, ignoring any writes cached in |
139 // write_batch_, and writes are write-through, without consolidation. | 145 // write_batch_, and writes are write-through, without consolidation. |
140 class LevelDBDirectTransaction { | 146 class LevelDBDirectTransaction { |
141 public: | 147 public: |
142 static scoped_ptr<LevelDBDirectTransaction> Create(LevelDBDatabase* db); | 148 static scoped_ptr<LevelDBDirectTransaction> Create(LevelDBDatabase* db); |
143 | 149 |
144 ~LevelDBDirectTransaction(); | 150 ~LevelDBDirectTransaction(); |
145 void Put(const base::StringPiece& key, const std::string* value); | 151 void Put(const base::StringPiece& key, const std::string* value); |
146 leveldb::Status Get(const base::StringPiece& key, | 152 leveldb::Status Get(const base::StringPiece& key, |
147 std::string* value, | 153 std::string* value, |
148 bool* found); | 154 bool* found); |
149 void Remove(const base::StringPiece& key); | 155 void Remove(const base::StringPiece& key); |
150 leveldb::Status Commit(); | 156 leveldb::Status Commit(); |
151 | 157 |
152 private: | 158 private: |
153 explicit LevelDBDirectTransaction(LevelDBDatabase* db); | 159 explicit LevelDBDirectTransaction(LevelDBDatabase* db); |
154 | 160 |
155 LevelDBDatabase* db_; | 161 LevelDBDatabase* db_; |
156 scoped_ptr<LevelDBWriteBatch> write_batch_; | 162 scoped_ptr<LevelDBWriteBatch> write_batch_; |
157 bool finished_; | 163 bool finished_; |
| 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(LevelDBDirectTransaction); |
158 }; | 166 }; |
159 | 167 |
160 } // namespace content | 168 } // namespace content |
161 | 169 |
162 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_ | 170 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_ |
OLD | NEW |