Chromium Code Reviews| 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 "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 std::string* value, | 47 std::string* value, |
| 48 bool deleted) { | 48 bool deleted) { |
| 49 DCHECK(!finished_); | 49 DCHECK(!finished_); |
| 50 DataType::iterator it = data_.find(key); | 50 DataType::iterator it = data_.find(key); |
| 51 | 51 |
| 52 if (it == data_.end()) { | 52 if (it == data_.end()) { |
| 53 std::unique_ptr<Record> record = base::MakeUnique<Record>(); | 53 std::unique_ptr<Record> record = base::MakeUnique<Record>(); |
| 54 record->key.assign(key.begin(), key.end() - key.begin()); | 54 record->key.assign(key.begin(), key.end() - key.begin()); |
| 55 record->value.swap(*value); | 55 record->value.swap(*value); |
| 56 record->deleted = deleted; | 56 record->deleted = deleted; |
| 57 size_ += sizeof(Record) + key.size() * 2 + value->size(); | |
|
pwnall
2017/05/23 23:01:09
This book-keeping looks subtle enough to require t
dmurph
2017/05/24 02:01:58
BAsed on our convo, recording right before the jou
| |
| 57 data_[record->key] = std::move(record); | 58 data_[record->key] = std::move(record); |
| 58 NotifyIterators(); | 59 NotifyIterators(); |
| 59 return; | 60 return; |
| 60 } | 61 } |
| 62 size_ += value->size(); | |
| 61 it->second->value.swap(*value); | 63 it->second->value.swap(*value); |
| 64 size_ -= value->size(); | |
| 62 it->second->deleted = deleted; | 65 it->second->deleted = deleted; |
| 63 } | 66 } |
| 64 | 67 |
| 65 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) { | 68 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) { |
| 66 Set(key, value, false); | 69 Set(key, value, false); |
| 67 } | 70 } |
| 68 | 71 |
| 69 void LevelDBTransaction::Remove(const StringPiece& key) { | 72 void LevelDBTransaction::Remove(const StringPiece& key) { |
| 70 std::string empty; | 73 std::string empty; |
| 71 Set(key, &empty, true); | 74 Set(key, &empty, true); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 } | 371 } |
| 369 | 372 |
| 370 void LevelDBTransaction::TransactionIterator::DataChanged() { | 373 void LevelDBTransaction::TransactionIterator::DataChanged() { |
| 371 data_changed_ = true; | 374 data_changed_ = true; |
| 372 } | 375 } |
| 373 | 376 |
| 374 void LevelDBTransaction::TransactionIterator::Delete() { | 377 void LevelDBTransaction::TransactionIterator::Delete() { |
| 375 DCHECK(IsValid()); | 378 DCHECK(IsValid()); |
| 376 if (current_ == data_iterator_.get()) { | 379 if (current_ == data_iterator_.get()) { |
| 377 data_iterator_->Delete(); | 380 data_iterator_->Delete(); |
| 381 transaction_->size_ -= data_iterator_->Value().size(); | |
|
pwnall
2017/05/23 23:01:10
IIUC, this removes the record from the map, so I t
dmurph
2017/05/24 02:01:58
Added tests. Offline convo - record isn't removed
| |
| 378 } else { | 382 } else { |
| 379 std::unique_ptr<Record> record = base::MakeUnique<Record>(); | 383 std::unique_ptr<Record> record = base::MakeUnique<Record>(); |
| 380 record->key = Key().as_string(); | 384 record->key = Key().as_string(); |
| 381 record->deleted = true; | 385 record->deleted = true; |
| 386 transaction_->size_ += sizeof(Record) + record->key.size() * 2; | |
| 382 transaction_->data_[record->key] = std::move(record); | 387 transaction_->data_[record->key] = std::move(record); |
| 383 } | 388 } |
| 384 } | 389 } |
| 385 | 390 |
| 386 void LevelDBTransaction::TransactionIterator::RefreshDataIterator() const { | 391 void LevelDBTransaction::TransactionIterator::RefreshDataIterator() const { |
| 387 DCHECK(data_changed_); | 392 DCHECK(data_changed_); |
| 388 | 393 |
| 389 data_changed_ = false; | 394 data_changed_ = false; |
| 390 | 395 |
| 391 if (data_iterator_->IsValid() && data_iterator_.get() == current_) { | 396 if (data_iterator_->IsValid() && data_iterator_.get() == current_) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 | 544 |
| 540 leveldb::Status s = db_->Write(*write_batch_); | 545 leveldb::Status s = db_->Write(*write_batch_); |
| 541 if (s.ok()) { | 546 if (s.ok()) { |
| 542 finished_ = true; | 547 finished_ = true; |
| 543 write_batch_->Clear(); | 548 write_batch_->Clear(); |
| 544 } | 549 } |
| 545 return s; | 550 return s; |
| 546 } | 551 } |
| 547 | 552 |
| 548 } // namespace content | 553 } // namespace content |
| OLD | NEW |