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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/leveldb_wrapper.cc

Issue 461823002: [SyncFS] Support Delete operation on LevelDBWrapper::Iterator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nitpick Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/sync_file_system/drive_backend/leveldb_wrapper.h" 5 #include "chrome/browser/sync_file_system/drive_backend/leveldb_wrapper.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 db_iterator_->Next(); 60 db_iterator_->Next();
61 if (comp >= 0) 61 if (comp >= 0)
62 ++map_iterator_; 62 ++map_iterator_;
63 } else { 63 } else {
64 ++map_iterator_; 64 ++map_iterator_;
65 } 65 }
66 66
67 AdvanceIterators(); 67 AdvanceIterators();
68 } 68 }
69 69
70 void LevelDBWrapper::Iterator::Delete() {
71 DCHECK(Valid());
72
73 const std::string key_str = key().ToString();
74 Transaction deletion(DELETE_OPERATION, std::string());
75 std::pair<PendingOperationMap::iterator, bool> inserted =
76 db_->pending_.insert(std::make_pair(key_str, deletion));
tzik 2014/08/12 06:28:33 Can we put previous iterator as a hint like this?
peria 2014/08/12 06:41:48 We can, but if we can add a hint, insert() returns
tzik 2014/08/12 07:32:36 Ah, I wasn't aware that. How about doing like belo
peria 2014/08/12 07:44:35 Done.
77 map_iterator_ = inserted.first;
78 if (!inserted.second)
79 map_iterator_->second = deletion;
80
81 AdvanceIterators();
82 }
83
70 leveldb::Slice LevelDBWrapper::Iterator::key() { 84 leveldb::Slice LevelDBWrapper::Iterator::key() {
71 DCHECK(Valid()); 85 DCHECK(Valid());
72 86
73 if (!db_iterator_->Valid()) 87 if (!db_iterator_->Valid())
74 return map_iterator_->first; 88 return map_iterator_->first;
75 if (map_iterator_ == db_->pending_.end()) 89 if (map_iterator_ == db_->pending_.end())
76 return db_iterator_->key(); 90 return db_iterator_->key();
77 91
78 const leveldb::Slice db_key = db_iterator_->key(); 92 const leveldb::Slice db_key = db_iterator_->key();
79 const leveldb::Slice map_key = map_iterator_->first; 93 const leveldb::Slice map_key = map_iterator_->first;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 void LevelDBWrapper::Clear() { 206 void LevelDBWrapper::Clear() {
193 pending_.clear(); 207 pending_.clear();
194 } 208 }
195 209
196 leveldb::DB* LevelDBWrapper::GetLevelDB() { 210 leveldb::DB* LevelDBWrapper::GetLevelDB() {
197 return db_.get(); 211 return db_.get();
198 } 212 }
199 213
200 } // namespace drive_backend 214 } // namespace drive_backend
201 } // namespace sync_file_system 215 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698