| 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 { |
| 441 DCHECK(!finished_); |
| 442 write_batch_->Put(key, *value); |
| 443 } |
| 444 |
| 445 bool LevelDBUncachedTransaction::Get(const StringPiece& key, |
| 446 std::string* value, bool* found) |
| 447 { |
| 448 *found = false; |
| 449 DCHECK(!finished_); |
| 450 |
| 451 bool ok = db_->Get(key, value, found); |
| 452 if (!ok) { |
| 453 DCHECK(!found); |
| 454 return false; |
| 455 } |
| 456 return true; |
| 457 } |
| 458 |
| 459 void LevelDBUncachedTransaction::Remove(const StringPiece& key) { |
| 439 DCHECK(!finished_); | 460 DCHECK(!finished_); |
| 440 write_batch_->Remove(key); | 461 write_batch_->Remove(key); |
| 441 } | 462 } |
| 442 | 463 |
| 443 bool LevelDBWriteOnlyTransaction::Commit() { | 464 bool LevelDBUncachedTransaction::Commit() { |
| 444 DCHECK(!finished_); | 465 DCHECK(!finished_); |
| 445 | 466 |
| 446 if (!db_->Write(*write_batch_)) | 467 if (!db_->Write(*write_batch_)) |
| 447 return false; | 468 return false; |
| 448 | 469 |
| 449 finished_ = true; | 470 finished_ = true; |
| 450 write_batch_->Clear(); | 471 write_batch_->Clear(); |
| 451 return true; | 472 return true; |
| 452 } | 473 } |
| 453 | 474 |
| 454 } // namespace content | 475 } // namespace content |
| OLD | NEW |