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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 return make_scoped_ptr(new LevelDBWriteOnlyTransaction(db)); | 450 return make_scoped_ptr(new LevelDBWriteOnlyTransaction(db)); |
451 } | 451 } |
452 | 452 |
453 LevelDBWriteOnlyTransaction::LevelDBWriteOnlyTransaction(LevelDBDatabase* db) | 453 LevelDBWriteOnlyTransaction::LevelDBWriteOnlyTransaction(LevelDBDatabase* db) |
454 : db_(db), write_batch_(LevelDBWriteBatch::Create()), finished_(false) {} | 454 : db_(db), write_batch_(LevelDBWriteBatch::Create()), finished_(false) {} |
455 | 455 |
456 LevelDBWriteOnlyTransaction::~LevelDBWriteOnlyTransaction() { | 456 LevelDBWriteOnlyTransaction::~LevelDBWriteOnlyTransaction() { |
457 write_batch_->Clear(); | 457 write_batch_->Clear(); |
458 } | 458 } |
459 | 459 |
| 460 void LevelDBWriteOnlyTransaction::Put(const StringPiece& key, |
| 461 const std::string* value) |
| 462 { |
| 463 DCHECK(!finished_); |
| 464 write_batch_->Put(key, *value); |
| 465 } |
| 466 |
| 467 bool LevelDBWriteOnlyTransaction::Get(const StringPiece& key, |
| 468 std::string* value, bool* found) |
| 469 { |
| 470 *found = false; |
| 471 DCHECK(!finished_); |
| 472 |
| 473 bool ok = db_->Get(key, value, found); |
| 474 if (!ok) { |
| 475 DCHECK(!found); |
| 476 return false; |
| 477 } |
| 478 return true; |
| 479 } |
| 480 |
460 void LevelDBWriteOnlyTransaction::Remove(const StringPiece& key) { | 481 void LevelDBWriteOnlyTransaction::Remove(const StringPiece& key) { |
461 DCHECK(!finished_); | 482 DCHECK(!finished_); |
462 write_batch_->Remove(key); | 483 write_batch_->Remove(key); |
463 } | 484 } |
464 | 485 |
465 bool LevelDBWriteOnlyTransaction::Commit() { | 486 bool LevelDBWriteOnlyTransaction::Commit() { |
466 DCHECK(!finished_); | 487 DCHECK(!finished_); |
467 | 488 |
468 if (!db_->Write(*write_batch_)) | 489 if (!db_->Write(*write_batch_)) |
469 return false; | 490 return false; |
470 | 491 |
471 finished_ = true; | 492 finished_ = true; |
472 write_batch_->Clear(); | 493 write_batch_->Clear(); |
473 return true; | 494 return true; |
474 } | 495 } |
475 | 496 |
476 } // namespace content | 497 } // namespace content |
OLD | NEW |