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

Side by Side Diff: extensions/browser/value_store/leveldb_value_store.cc

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 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 "extensions/browser/value_store/leveldb_value_store.h" 5 #include "extensions/browser/value_store/leveldb_value_store.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 230
231 for (std::vector<std::string>::const_iterator it = keys.begin(); 231 for (std::vector<std::string>::const_iterator it = keys.begin();
232 it != keys.end(); ++it) { 232 it != keys.end(); ++it) {
233 scoped_ptr<base::Value> old_value; 233 scoped_ptr<base::Value> old_value;
234 scoped_ptr<Error> read_error = 234 scoped_ptr<Error> read_error =
235 ReadFromDb(leveldb::ReadOptions(), *it, &old_value); 235 ReadFromDb(leveldb::ReadOptions(), *it, &old_value);
236 if (read_error) 236 if (read_error)
237 return MakeWriteResult(read_error.Pass()); 237 return MakeWriteResult(read_error.Pass());
238 238
239 if (old_value) { 239 if (old_value) {
240 changes->push_back(ValueStoreChange(*it, old_value.release(), NULL)); 240 changes->push_back(ValueStoreChange(*it, old_value.release(), nullptr));
241 batch.Delete(*it); 241 batch.Delete(*it);
242 } 242 }
243 } 243 }
244 244
245 leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch); 245 leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch);
246 if (!status.ok() && !status.IsNotFound()) 246 if (!status.ok() && !status.IsNotFound())
247 return MakeWriteResult(ToValueStoreError(status, util::NoKey())); 247 return MakeWriteResult(ToValueStoreError(status, util::NoKey()));
248 return MakeWriteResult(changes.Pass()); 248 return MakeWriteResult(changes.Pass());
249 } 249 }
250 250
251 ValueStore::WriteResult LeveldbValueStore::Clear() { 251 ValueStore::WriteResult LeveldbValueStore::Clear() {
252 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 252 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
253 253
254 scoped_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList()); 254 scoped_ptr<ValueStoreChangeList> changes(new ValueStoreChangeList());
255 255
256 ReadResult read_result = Get(); 256 ReadResult read_result = Get();
257 if (read_result->HasError()) 257 if (read_result->HasError())
258 return MakeWriteResult(read_result->PassError()); 258 return MakeWriteResult(read_result->PassError());
259 259
260 base::DictionaryValue& whole_db = read_result->settings(); 260 base::DictionaryValue& whole_db = read_result->settings();
261 while (!whole_db.empty()) { 261 while (!whole_db.empty()) {
262 std::string next_key = base::DictionaryValue::Iterator(whole_db).key(); 262 std::string next_key = base::DictionaryValue::Iterator(whole_db).key();
263 scoped_ptr<base::Value> next_value; 263 scoped_ptr<base::Value> next_value;
264 whole_db.RemoveWithoutPathExpansion(next_key, &next_value); 264 whole_db.RemoveWithoutPathExpansion(next_key, &next_value);
265 changes->push_back( 265 changes->push_back(
266 ValueStoreChange(next_key, next_value.release(), NULL)); 266 ValueStoreChange(next_key, next_value.release(), nullptr));
267 } 267 }
268 268
269 DeleteDbFile(); 269 DeleteDbFile();
270 return MakeWriteResult(changes.Pass()); 270 return MakeWriteResult(changes.Pass());
271 } 271 }
272 272
273 bool LeveldbValueStore::Restore() { 273 bool LeveldbValueStore::Restore() {
274 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 274 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
275 275
276 ReadResult result = Get(); 276 ReadResult result = Get();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 scoped_ptr<ValueStore::Error> LeveldbValueStore::EnsureDbIsOpen() { 322 scoped_ptr<ValueStore::Error> LeveldbValueStore::EnsureDbIsOpen() {
323 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 323 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
324 324
325 if (db_) 325 if (db_)
326 return util::NoError(); 326 return util::NoError();
327 327
328 leveldb::Options options; 328 leveldb::Options options;
329 options.max_open_files = 0; // Use minimum. 329 options.max_open_files = 0; // Use minimum.
330 options.create_if_missing = true; 330 options.create_if_missing = true;
331 331
332 leveldb::DB* db = NULL; 332 leveldb::DB* db = nullptr;
333 leveldb::Status status = 333 leveldb::Status status =
334 leveldb::DB::Open(options, db_path_.AsUTF8Unsafe(), &db); 334 leveldb::DB::Open(options, db_path_.AsUTF8Unsafe(), &db);
335 if (!status.ok()) 335 if (!status.ok())
336 return ToValueStoreError(status, util::NoKey()); 336 return ToValueStoreError(status, util::NoKey());
337 337
338 CHECK(db); 338 CHECK(db);
339 db_.reset(db); 339 db_.reset(db);
340 return util::NoError(); 340 return util::NoError();
341 } 341 }
342 342
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 CHECK(!status.ok()); 433 CHECK(!status.ok());
434 CHECK(!status.IsNotFound()); // not an error 434 CHECK(!status.IsNotFound()); // not an error
435 435
436 std::string message = status.ToString(); 436 std::string message = status.ToString();
437 // The message may contain |db_path_|, which may be considered sensitive 437 // The message may contain |db_path_|, which may be considered sensitive
438 // data, and those strings are passed to the extension, so strip it out. 438 // data, and those strings are passed to the extension, so strip it out.
439 ReplaceSubstringsAfterOffset(&message, 0u, db_path_.AsUTF8Unsafe(), "..."); 439 ReplaceSubstringsAfterOffset(&message, 0u, db_path_.AsUTF8Unsafe(), "...");
440 440
441 return Error::Create(CORRUPTION, message, key.Pass()); 441 return Error::Create(CORRUPTION, message, key.Pass());
442 } 442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698