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

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

Issue 19117005: IndexedDB: Coding conventions and cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" 5 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/indexed_db/leveldb/leveldb_database.h" 8 #include "content/browser/indexed_db/leveldb/leveldb_database.h"
9 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" 9 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h"
10 #include "third_party/leveldatabase/src/include/leveldb/db.h" 10 #include "third_party/leveldatabase/src/include/leveldb/db.h"
11 11
12 using base::StringPiece; 12 using base::StringPiece;
13 13
14 namespace content { 14 namespace content {
15 15
16 scoped_refptr<LevelDBTransaction> LevelDBTransaction::Create(
17 LevelDBDatabase* db) {
18 return make_scoped_refptr(new LevelDBTransaction(db));
19 }
20
21 LevelDBTransaction::LevelDBTransaction(LevelDBDatabase* db) 16 LevelDBTransaction::LevelDBTransaction(LevelDBDatabase* db)
22 : db_(db), snapshot_(db), comparator_(db->Comparator()), finished_(false) { 17 : db_(db), snapshot_(db), comparator_(db->Comparator()), finished_(false) {
23 tree_.abstractor().comparator_ = comparator_; 18 tree_.abstractor().comparator_ = comparator_;
24 } 19 }
25 20
26 LevelDBTransaction::AVLTreeNode::AVLTreeNode() {} 21 LevelDBTransaction::AVLTreeNode::AVLTreeNode() {}
27 LevelDBTransaction::AVLTreeNode::~AVLTreeNode() {} 22 LevelDBTransaction::AVLTreeNode::~AVLTreeNode() {}
28 23
29 void LevelDBTransaction::ClearTree() { 24 void LevelDBTransaction::ClearTree() {
30 TreeType::Iterator iterator; 25 TreeType::Iterator iterator;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 245 }
251 246
252 void LevelDBTransaction::TransactionIterator::Next() { 247 void LevelDBTransaction::TransactionIterator::Next() {
253 DCHECK(IsValid()); 248 DCHECK(IsValid());
254 if (tree_changed_) 249 if (tree_changed_)
255 RefreshTreeIterator(); 250 RefreshTreeIterator();
256 251
257 if (direction_ != FORWARD) { 252 if (direction_ != FORWARD) {
258 // Ensure the non-current iterator is positioned after Key(). 253 // Ensure the non-current iterator is positioned after Key().
259 254
260 LevelDBIterator* non_current = 255 LevelDBIterator* non_current = (current_ == db_iterator_.get())
261 (current_ == db_iterator_.get()) ? tree_iterator_.get() 256 ? tree_iterator_.get()
262 : db_iterator_.get(); 257 : db_iterator_.get();
263 258
264 non_current->Seek(Key()); 259 non_current->Seek(Key());
265 if (non_current->IsValid() && 260 if (non_current->IsValid() &&
266 !comparator_->Compare(non_current->Key(), Key())) 261 !comparator_->Compare(non_current->Key(), Key()))
267 non_current->Next(); // Take an extra step so the non-current key is 262 non_current->Next(); // Take an extra step so the non-current key is
268 // strictly greater than Key(). 263 // strictly greater than Key().
269 264
270 DCHECK(!non_current->IsValid() || 265 DCHECK(!non_current->IsValid() ||
271 comparator_->Compare(non_current->Key(), Key()) > 0); 266 comparator_->Compare(non_current->Key(), Key()) > 0);
272 267
273 direction_ = FORWARD; 268 direction_ = FORWARD;
274 } 269 }
275 270
276 current_->Next(); 271 current_->Next();
277 HandleConflictsAndDeletes(); 272 HandleConflictsAndDeletes();
278 SetCurrentIteratorToSmallestKey(); 273 SetCurrentIteratorToSmallestKey();
279 } 274 }
280 275
281 void LevelDBTransaction::TransactionIterator::Prev() { 276 void LevelDBTransaction::TransactionIterator::Prev() {
282 DCHECK(IsValid()); 277 DCHECK(IsValid());
283 if (tree_changed_) 278 if (tree_changed_)
284 RefreshTreeIterator(); 279 RefreshTreeIterator();
285 280
286 if (direction_ != REVERSE) { 281 if (direction_ != REVERSE) {
287 // Ensure the non-current iterator is positioned before Key(). 282 // Ensure the non-current iterator is positioned before Key().
288 283
289 LevelDBIterator* non_current = 284 LevelDBIterator* non_current = (current_ == db_iterator_.get())
290 (current_ == db_iterator_.get()) ? tree_iterator_.get() 285 ? tree_iterator_.get()
291 : db_iterator_.get(); 286 : db_iterator_.get();
292 287
293 non_current->Seek(Key()); 288 non_current->Seek(Key());
294 if (non_current->IsValid()) { 289 if (non_current->IsValid()) {
295 // Iterator is at first entry >= Key(). 290 // Iterator is at first entry >= Key().
296 // Step back once to entry < key. 291 // Step back once to entry < key.
297 // This is why we don't check for the keys being the same before 292 // This is why we don't check for the keys being the same before
298 // stepping, like we do in Next() above. 293 // stepping, like we do in Next() above.
299 non_current->Prev(); 294 non_current->Prev();
300 } else { 295 } else {
301 non_current->SeekToLast(); // Iterator has no entries >= Key(). Position 296 non_current->SeekToLast(); // Iterator has no entries >= Key(). Position
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 467
473 if (!db_->Write(*write_batch_)) 468 if (!db_->Write(*write_batch_))
474 return false; 469 return false;
475 470
476 finished_ = true; 471 finished_ = true;
477 write_batch_->Clear(); 472 write_batch_->Clear();
478 return true; 473 return true;
479 } 474 }
480 475
481 } // namespace content 476 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698