| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 } | 427 } |
| 428 | 428 |
| 429 LevelDBDirectTransaction::LevelDBDirectTransaction(LevelDBDatabase* db) | 429 LevelDBDirectTransaction::LevelDBDirectTransaction(LevelDBDatabase* db) |
| 430 : db_(db), write_batch_(LevelDBWriteBatch::Create()), finished_(false) {} | 430 : db_(db), write_batch_(LevelDBWriteBatch::Create()), finished_(false) {} |
| 431 | 431 |
| 432 LevelDBDirectTransaction::~LevelDBDirectTransaction() { | 432 LevelDBDirectTransaction::~LevelDBDirectTransaction() { |
| 433 write_batch_->Clear(); | 433 write_batch_->Clear(); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void LevelDBDirectTransaction::Put(const StringPiece& key, | 436 void LevelDBDirectTransaction::Put(const StringPiece& key, |
| 437 const std::string* value) { | 437 const std::string* value) { |
| 438 DCHECK(!finished_); | 438 DCHECK(!finished_); |
| 439 write_batch_->Put(key, *value); | 439 write_batch_->Put(key, *value); |
| 440 } | 440 } |
| 441 | 441 |
| 442 leveldb::Status LevelDBDirectTransaction::Get(const StringPiece& key, | 442 leveldb::Status LevelDBDirectTransaction::Get(const StringPiece& key, |
| 443 std::string* value, | 443 std::string* value, |
| 444 bool* found) { | 444 bool* found) { |
| 445 *found = false; | 445 *found = false; |
| 446 DCHECK(!finished_); | 446 DCHECK(!finished_); |
| 447 | 447 |
| 448 leveldb::Status s = db_->Get(key, value, found); | 448 leveldb::Status s = db_->Get(key, value, found); |
| 449 DCHECK(s.ok() || !*found); | 449 DCHECK(s.ok() || !*found); |
| 450 return s; | 450 return s; |
| 451 } | 451 } |
| 452 | 452 |
| 453 void LevelDBDirectTransaction::Remove(const StringPiece& key) { | 453 void LevelDBDirectTransaction::Remove(const StringPiece& key) { |
| 454 DCHECK(!finished_); | 454 DCHECK(!finished_); |
| 455 write_batch_->Remove(key); | 455 write_batch_->Remove(key); |
| 456 } | 456 } |
| 457 | 457 |
| 458 leveldb::Status LevelDBDirectTransaction::Commit() { | 458 leveldb::Status LevelDBDirectTransaction::Commit() { |
| 459 DCHECK(!finished_); | 459 DCHECK(!finished_); |
| 460 | 460 |
| 461 leveldb::Status s = db_->Write(*write_batch_); | 461 leveldb::Status s = db_->Write(*write_batch_); |
| 462 if (s.ok()) { | 462 if (s.ok()) { |
| 463 finished_ = true; | 463 finished_ = true; |
| 464 write_batch_->Clear(); | 464 write_batch_->Clear(); |
| 465 } | 465 } |
| 466 return s; | 466 return s; |
| 467 } | 467 } |
| 468 | 468 |
| 469 } // namespace content | 469 } // namespace content |
| OLD | NEW |