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 18 matching lines...) Expand all Loading... |
29 LevelDBTransaction::Record::~Record() {} | 29 LevelDBTransaction::Record::~Record() {} |
30 | 30 |
31 void LevelDBTransaction::Clear() { | 31 void LevelDBTransaction::Clear() { |
32 for (const auto& it : data_) | 32 for (const auto& it : data_) |
33 delete it.second; | 33 delete it.second; |
34 data_.clear(); | 34 data_.clear(); |
35 } | 35 } |
36 | 36 |
37 LevelDBTransaction::~LevelDBTransaction() { Clear(); } | 37 LevelDBTransaction::~LevelDBTransaction() { Clear(); } |
38 | 38 |
39 void LevelDBTransaction::Set(const StringPiece& key, | 39 bool LevelDBTransaction::Set(const StringPiece& key, |
40 std::string* value, | 40 std::string* value, |
41 bool deleted) { | 41 bool deleted) { |
42 DCHECK(!finished_); | 42 DCHECK(!finished_); |
43 DataType::iterator it = data_.find(key); | 43 DataType::iterator it = data_.find(key); |
44 | 44 |
45 if (it == data_.end()) { | 45 if (it == data_.end()) { |
46 Record* record = new Record(); | 46 Record* record = new Record(); |
47 record->key.assign(key.begin(), key.end() - key.begin()); | 47 record->key.assign(key.begin(), key.end() - key.begin()); |
48 record->value.swap(*value); | 48 record->value.swap(*value); |
49 record->deleted = deleted; | 49 record->deleted = deleted; |
50 data_[record->key] = record; | 50 data_[record->key] = record; |
51 NotifyIterators(); | 51 NotifyIterators(); |
52 return; | 52 return false; |
53 } | 53 } |
54 | 54 bool replaced_deleted_value = it->second->deleted; |
55 it->second->value.swap(*value); | 55 it->second->value.swap(*value); |
56 it->second->deleted = deleted; | 56 it->second->deleted = deleted; |
| 57 return replaced_deleted_value; |
57 } | 58 } |
58 | 59 |
59 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) { | 60 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) { |
60 Set(key, value, false); | 61 Set(key, value, false); |
61 } | 62 } |
62 | 63 |
63 void LevelDBTransaction::Remove(const StringPiece& key) { | 64 bool LevelDBTransaction::Remove(const StringPiece& key) { |
64 std::string empty; | 65 std::string empty; |
65 Set(key, &empty, true); | 66 return !Set(key, &empty, true); |
66 } | 67 } |
67 | 68 |
68 leveldb::Status LevelDBTransaction::Get(const StringPiece& key, | 69 leveldb::Status LevelDBTransaction::Get(const StringPiece& key, |
69 std::string* value, | 70 std::string* value, |
70 bool* found) { | 71 bool* found) { |
71 *found = false; | 72 *found = false; |
72 DCHECK(!finished_); | 73 DCHECK(!finished_); |
73 std::string string_key(key.begin(), key.end() - key.begin()); | 74 std::string string_key(key.begin(), key.end() - key.begin()); |
74 DataType::const_iterator it = data_.find(string_key); | 75 DataType::const_iterator it = data_.find(string_key); |
75 | 76 |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 495 |
495 leveldb::Status s = db_->Write(*write_batch_); | 496 leveldb::Status s = db_->Write(*write_batch_); |
496 if (s.ok()) { | 497 if (s.ok()) { |
497 finished_ = true; | 498 finished_ = true; |
498 write_batch_->Clear(); | 499 write_batch_->Clear(); |
499 } | 500 } |
500 return s; | 501 return s; |
501 } | 502 } |
502 | 503 |
503 } // namespace content | 504 } // namespace content |
OLD | NEW |