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.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 : db_(db), | 21 : db_(db), |
| 22 snapshot_(db), | 22 snapshot_(db), |
| 23 comparator_(db->Comparator()), | 23 comparator_(db->Comparator()), |
| 24 data_comparator_(comparator_), | 24 data_comparator_(comparator_), |
| 25 data_(data_comparator_), | 25 data_(data_comparator_), |
| 26 finished_(false) {} | 26 finished_(false) {} |
| 27 | 27 |
| 28 LevelDBTransaction::Record::Record() : deleted(false) {} | 28 LevelDBTransaction::Record::Record() : deleted(false) {} |
| 29 LevelDBTransaction::Record::~Record() {} | 29 LevelDBTransaction::Record::~Record() {} |
| 30 | 30 |
| 31 void LevelDBTransaction::Clear() { | 31 void LevelDBTransaction::Clear() { |
|
cmumford
2016/08/13 00:08:38
Now only used in LevelDBTransaction::Rollback(). C
jsbell
2016/08/16 03:05:28
Done.
| |
| 32 for (const auto& it : data_) | |
| 33 delete it.second; | |
| 34 data_.clear(); | 32 data_.clear(); |
| 35 } | 33 } |
| 36 | 34 |
| 37 LevelDBTransaction::~LevelDBTransaction() { Clear(); } | 35 LevelDBTransaction::~LevelDBTransaction() {} |
| 38 | 36 |
| 39 bool LevelDBTransaction::Set(const StringPiece& key, | 37 bool LevelDBTransaction::Set(const StringPiece& key, |
| 40 std::string* value, | 38 std::string* value, |
| 41 bool deleted) { | 39 bool deleted) { |
| 42 DCHECK(!finished_); | 40 DCHECK(!finished_); |
| 43 DataType::iterator it = data_.find(key); | 41 DataType::iterator it = data_.find(key); |
| 44 | 42 |
| 45 if (it == data_.end()) { | 43 if (it == data_.end()) { |
| 46 Record* record = new Record(); | 44 std::unique_ptr<Record> record = base::MakeUnique<Record>(); |
| 47 record->key.assign(key.begin(), key.end() - key.begin()); | 45 record->key.assign(key.begin(), key.end() - key.begin()); |
| 48 record->value.swap(*value); | 46 record->value.swap(*value); |
| 49 record->deleted = deleted; | 47 record->deleted = deleted; |
| 50 data_[record->key] = record; | 48 data_[record->key] = std::move(record); |
| 51 NotifyIterators(); | 49 NotifyIterators(); |
| 52 return false; | 50 return false; |
| 53 } | 51 } |
| 54 bool replaced_deleted_value = it->second->deleted; | 52 bool replaced_deleted_value = it->second->deleted; |
| 55 it->second->value.swap(*value); | 53 it->second->value.swap(*value); |
| 56 it->second->deleted = deleted; | 54 it->second->deleted = deleted; |
| 57 return replaced_deleted_value; | 55 return replaced_deleted_value; |
| 58 } | 56 } |
| 59 | 57 |
| 60 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) { | 58 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 98 |
| 101 base::TimeTicks begin_time = base::TimeTicks::Now(); | 99 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 102 std::unique_ptr<LevelDBWriteBatch> write_batch = LevelDBWriteBatch::Create(); | 100 std::unique_ptr<LevelDBWriteBatch> write_batch = LevelDBWriteBatch::Create(); |
| 103 | 101 |
| 104 auto it = data_.begin(); | 102 auto it = data_.begin(); |
| 105 while (it != data_.end()) { | 103 while (it != data_.end()) { |
| 106 if (!it->second->deleted) | 104 if (!it->second->deleted) |
| 107 write_batch->Put(it->first, it->second->value); | 105 write_batch->Put(it->first, it->second->value); |
| 108 else | 106 else |
| 109 write_batch->Remove(it->first); | 107 write_batch->Remove(it->first); |
| 110 | |
| 111 delete it->second; | |
| 112 data_.erase(it++); | 108 data_.erase(it++); |
| 113 } | 109 } |
| 114 | 110 |
| 115 DCHECK(data_.empty()); | 111 DCHECK(data_.empty()); |
| 116 | 112 |
| 117 leveldb::Status s = db_->Write(*write_batch); | 113 leveldb::Status s = db_->Write(*write_batch); |
| 118 if (s.ok()) { | 114 if (s.ok()) { |
| 119 finished_ = true; | 115 finished_ = true; |
| 120 UMA_HISTOGRAM_TIMES("WebCore.IndexedDB.LevelDB.Transaction.CommitTime", | 116 UMA_HISTOGRAM_TIMES("WebCore.IndexedDB.LevelDB.Transaction.CommitTime", |
| 121 base::TimeTicks::Now() - begin_time); | 117 base::TimeTicks::Now() - begin_time); |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 | 491 |
| 496 leveldb::Status s = db_->Write(*write_batch_); | 492 leveldb::Status s = db_->Write(*write_batch_); |
| 497 if (s.ok()) { | 493 if (s.ok()) { |
| 498 finished_ = true; | 494 finished_ = true; |
| 499 write_batch_->Clear(); | 495 write_batch_->Clear(); |
| 500 } | 496 } |
| 501 return s; | 497 return s; |
| 502 } | 498 } |
| 503 | 499 |
| 504 } // namespace content | 500 } // namespace content |
| OLD | NEW |