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

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

Issue 1124223012: Change JSONReader::ReadToValue to return a scoped_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chromedriver Created 5 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
« no previous file with comments | « content/public/test/browser_test_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 leveldb::ReadOptions options = leveldb::ReadOptions(); 139 leveldb::ReadOptions options = leveldb::ReadOptions();
140 // All interaction with the db is done on the same thread, so snapshotting 140 // All interaction with the db is done on the same thread, so snapshotting
141 // isn't strictly necessary. This is just defensive. 141 // isn't strictly necessary. This is just defensive.
142 scoped_ptr<base::DictionaryValue> settings(new base::DictionaryValue()); 142 scoped_ptr<base::DictionaryValue> settings(new base::DictionaryValue());
143 143
144 ScopedSnapshot snapshot(db_.get()); 144 ScopedSnapshot snapshot(db_.get());
145 options.snapshot = snapshot.get(); 145 options.snapshot = snapshot.get();
146 scoped_ptr<leveldb::Iterator> it(db_->NewIterator(options)); 146 scoped_ptr<leveldb::Iterator> it(db_->NewIterator(options));
147 for (it->SeekToFirst(); it->Valid(); it->Next()) { 147 for (it->SeekToFirst(); it->Valid(); it->Next()) {
148 std::string key = it->key().ToString(); 148 std::string key = it->key().ToString();
149 base::Value* value = json_reader.ReadToValue(it->value().ToString()); 149 scoped_ptr<base::Value> value =
150 json_reader.ReadToValue(it->value().ToString());
150 if (!value) { 151 if (!value) {
151 return MakeReadResult( 152 return MakeReadResult(
152 Error::Create(CORRUPTION, kInvalidJson, util::NewKey(key))); 153 Error::Create(CORRUPTION, kInvalidJson, util::NewKey(key)));
153 } 154 }
154 settings->SetWithoutPathExpansion(key, value); 155 settings->SetWithoutPathExpansion(key, value.Pass());
155 } 156 }
156 157
157 if (it->status().IsNotFound()) { 158 if (it->status().IsNotFound()) {
158 NOTREACHED() << "IsNotFound() but iterating over all keys?!"; 159 NOTREACHED() << "IsNotFound() but iterating over all keys?!";
159 return MakeReadResult(settings.Pass()); 160 return MakeReadResult(settings.Pass());
160 } 161 }
161 162
162 if (!it->status().ok()) 163 if (!it->status().ok())
163 return MakeReadResult(ToValueStoreError(it->status(), util::NoKey())); 164 return MakeReadResult(ToValueStoreError(it->status(), util::NoKey()));
164 165
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 351
351 if (s.IsNotFound()) { 352 if (s.IsNotFound()) {
352 // Despite there being no value, it was still a success. Check this first 353 // Despite there being no value, it was still a success. Check this first
353 // because ok() is false on IsNotFound. 354 // because ok() is false on IsNotFound.
354 return util::NoError(); 355 return util::NoError();
355 } 356 }
356 357
357 if (!s.ok()) 358 if (!s.ok())
358 return ToValueStoreError(s, util::NewKey(key)); 359 return ToValueStoreError(s, util::NewKey(key));
359 360
360 base::Value* value = base::JSONReader().ReadToValue(value_as_json); 361 scoped_ptr<base::Value> value = base::JSONReader().ReadToValue(value_as_json);
361 if (!value) 362 if (!value)
362 return Error::Create(CORRUPTION, kInvalidJson, util::NewKey(key)); 363 return Error::Create(CORRUPTION, kInvalidJson, util::NewKey(key));
363 364
364 setting->reset(value); 365 *setting = value.Pass();
365 return util::NoError(); 366 return util::NoError();
366 } 367 }
367 368
368 scoped_ptr<ValueStore::Error> LeveldbValueStore::AddToBatch( 369 scoped_ptr<ValueStore::Error> LeveldbValueStore::AddToBatch(
369 ValueStore::WriteOptions options, 370 ValueStore::WriteOptions options,
370 const std::string& key, 371 const std::string& key,
371 const base::Value& value, 372 const base::Value& value,
372 leveldb::WriteBatch* batch, 373 leveldb::WriteBatch* batch,
373 ValueStoreChangeList* changes) { 374 ValueStoreChangeList* changes) {
374 bool write_new_value = true; 375 bool write_new_value = true;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 CHECK(!status.ok()); 432 CHECK(!status.ok());
432 CHECK(!status.IsNotFound()); // not an error 433 CHECK(!status.IsNotFound()); // not an error
433 434
434 std::string message = status.ToString(); 435 std::string message = status.ToString();
435 // The message may contain |db_path_|, which may be considered sensitive 436 // The message may contain |db_path_|, which may be considered sensitive
436 // data, and those strings are passed to the extension, so strip it out. 437 // data, and those strings are passed to the extension, so strip it out.
437 ReplaceSubstringsAfterOffset(&message, 0u, db_path_.AsUTF8Unsafe(), "..."); 438 ReplaceSubstringsAfterOffset(&message, 0u, db_path_.AsUTF8Unsafe(), "...");
438 439
439 return Error::Create(CORRUPTION, message, key.Pass()); 440 return Error::Create(CORRUPTION, message, key.Pass());
440 } 441 }
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698