Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: content/browser/indexed_db/leveldb/leveldb_transaction.cc

Issue 1996443003: Return number of values deleted by IDBObjectStore.delete(range) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) {
40 std::string* value,
41 bool deleted) {
42 DCHECK(!finished_); 40 DCHECK(!finished_);
43 DataType::iterator it = data_.find(key); 41 DataType::iterator it = data_.find(key);
44
45 if (it == data_.end()) { 42 if (it == data_.end()) {
46 Record* record = new Record(); 43 Record* record = new Record();
47 record->key.assign(key.begin(), key.end() - key.begin()); 44 record->key.assign(key.begin(), key.end() - key.begin());
48 record->value.swap(*value); 45 record->value.swap(*value);
49 record->deleted = deleted; 46 record->deleted = false;
cmumford 2016/05/19 17:07:16 Redundant: the constructor initializes deleted to
palakj1 2016/05/19 23:47:52 code segment removed
50 data_[record->key] = record; 47 data_[record->key] = record;
51 NotifyIterators(); 48 NotifyIterators();
52 return; 49 return;
53 } 50 }
54 51 it->second->deleted = false;
55 it->second->value.swap(*value); 52 it->second->value.swap(*value);
56 it->second->deleted = deleted;
57 } 53 }
58 54
59 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) { 55 // if key non existent or already recorded as deleted : false
cmumford 2016/05/19 17:07:16 API comment is better in the header only.
palakj1 2016/05/19 23:47:52 Done
60 Set(key, value, false); 56 bool LevelDBTransaction::Remove(const StringPiece& key) {
61 }
62
63 void LevelDBTransaction::Remove(const StringPiece& key) {
64 std::string empty; 57 std::string empty;
65 Set(key, &empty, true); 58 DCHECK(!finished_);
cmumford 2016/05/19 17:07:16 This seems to be an overall more complicated appro
palakj1 2016/05/19 23:47:52 changes made as suggested by cmumford: call to Se
59 DataType::iterator it = data_.find(key);
60 if (it == data_.end())
61 return false;
dmurph 2016/05/19 01:01:39 We still want to create our deleted record here. C
palakj1 2016/05/19 23:47:52 done.
62 if (it->second->deleted)
63 return false;
64 it->second->deleted = true;
65 it->second->value.swap(empty);
66 return 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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698