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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 return make_scoped_ptr(new LevelDBWriteOnlyTransaction(db)); | 428 return make_scoped_ptr(new LevelDBWriteOnlyTransaction(db)); |
429 } | 429 } |
430 | 430 |
431 LevelDBWriteOnlyTransaction::LevelDBWriteOnlyTransaction(LevelDBDatabase* db) | 431 LevelDBWriteOnlyTransaction::LevelDBWriteOnlyTransaction(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 LevelDBWriteOnlyTransaction::~LevelDBWriteOnlyTransaction() { |
435 write_batch_->Clear(); | 435 write_batch_->Clear(); |
436 } | 436 } |
437 | 437 |
| 438 void LevelDBWriteOnlyTransaction::Put(const StringPiece& key, |
| 439 const std::string* value) |
| 440 { |
| 441 DCHECK(!finished_); |
| 442 write_batch_->Put(key, *value); |
| 443 } |
| 444 |
| 445 bool LevelDBWriteOnlyTransaction::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 |
438 void LevelDBWriteOnlyTransaction::Remove(const StringPiece& key) { | 459 void LevelDBWriteOnlyTransaction::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 LevelDBWriteOnlyTransaction::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 |