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 #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" |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 | 416 |
417 void LevelDBTransaction::NotifyIterators() { | 417 void LevelDBTransaction::NotifyIterators() { |
418 for (std::set<TransactionIterator*>::iterator i = iterators_.begin(); | 418 for (std::set<TransactionIterator*>::iterator i = iterators_.begin(); |
419 i != iterators_.end(); | 419 i != iterators_.end(); |
420 ++i) { | 420 ++i) { |
421 TransactionIterator* transaction_iterator = *i; | 421 TransactionIterator* transaction_iterator = *i; |
422 transaction_iterator->DataChanged(); | 422 transaction_iterator->DataChanged(); |
423 } | 423 } |
424 } | 424 } |
425 | 425 |
426 scoped_ptr<LevelDBWriteOnlyTransaction> LevelDBWriteOnlyTransaction::Create( | 426 scoped_ptr<LevelDBUncachedTransaction> LevelDBUncachedTransaction::Create( |
427 LevelDBDatabase* db) { | 427 LevelDBDatabase* db) { |
428 return make_scoped_ptr(new LevelDBWriteOnlyTransaction(db)); | 428 return make_scoped_ptr(new LevelDBUncachedTransaction(db)); |
429 } | 429 } |
430 | 430 |
431 LevelDBWriteOnlyTransaction::LevelDBWriteOnlyTransaction(LevelDBDatabase* db) | 431 LevelDBUncachedTransaction::LevelDBUncachedTransaction(LevelDBDatabase* db) |
432 : db_(db), write_batch_(LevelDBWriteBatch::Create()), finished_(false) {} | 432 : db_(db), write_batch_(LevelDBWriteBatch::Create()), finished_(false) {} |
433 | 433 |
434 LevelDBWriteOnlyTransaction::~LevelDBWriteOnlyTransaction() { | 434 LevelDBUncachedTransaction::~LevelDBUncachedTransaction() { |
435 write_batch_->Clear(); | 435 write_batch_->Clear(); |
436 } | 436 } |
437 | 437 |
438 void LevelDBWriteOnlyTransaction::Remove(const StringPiece& key) { | 438 void LevelDBUncachedTransaction::Put(const StringPiece& key, |
439 const std::string* value) { | |
440 DCHECK(!finished_); | |
441 write_batch_->Put(key, *value); | |
442 } | |
443 | |
444 bool LevelDBUncachedTransaction::Get(const StringPiece& key, | |
445 std::string* value, | |
446 bool* found) { | |
447 *found = false; | |
448 DCHECK(!finished_); | |
449 | |
450 bool ok = db_->Get(key, value, found); | |
451 if (!ok) { | |
452 DCHECK(!found); | |
jsbell
2013/12/20 00:44:20
How about:
DCHECK(ok || !found);
return ok;
ericu
2014/02/20 00:50:29
That's nicer, thanks.
| |
453 return false; | |
454 } | |
455 return true; | |
456 } | |
457 | |
458 void LevelDBUncachedTransaction::Remove(const StringPiece& key) { | |
439 DCHECK(!finished_); | 459 DCHECK(!finished_); |
440 write_batch_->Remove(key); | 460 write_batch_->Remove(key); |
441 } | 461 } |
442 | 462 |
443 bool LevelDBWriteOnlyTransaction::Commit() { | 463 bool LevelDBUncachedTransaction::Commit() { |
444 DCHECK(!finished_); | 464 DCHECK(!finished_); |
445 | 465 |
446 if (!db_->Write(*write_batch_)) | 466 if (!db_->Write(*write_batch_)) |
447 return false; | 467 return false; |
448 | 468 |
449 finished_ = true; | 469 finished_ = true; |
450 write_batch_->Clear(); | 470 write_batch_->Clear(); |
451 return true; | 471 return true; |
452 } | 472 } |
453 | 473 |
454 } // namespace content | 474 } // namespace content |
OLD | NEW |