OLD | NEW |
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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 if (!old_value || !old_value->Equals(&value)) { | 382 if (!old_value || !old_value->Equals(&value)) { |
383 changes->push_back( | 383 changes->push_back( |
384 ValueStoreChange(key, old_value.release(), value.DeepCopy())); | 384 ValueStoreChange(key, old_value.release(), value.DeepCopy())); |
385 } else { | 385 } else { |
386 write_new_value = false; | 386 write_new_value = false; |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 if (write_new_value) { | 390 if (write_new_value) { |
391 std::string value_as_json; | 391 std::string value_as_json; |
392 if (!base::JSONWriter::Write(&value, &value_as_json)) | 392 if (!base::JSONWriter::Write(value, &value_as_json)) |
393 return Error::Create(OTHER_ERROR, kCannotSerialize, util::NewKey(key)); | 393 return Error::Create(OTHER_ERROR, kCannotSerialize, util::NewKey(key)); |
394 batch->Put(key, value_as_json); | 394 batch->Put(key, value_as_json); |
395 } | 395 } |
396 | 396 |
397 return util::NoError(); | 397 return util::NoError(); |
398 } | 398 } |
399 | 399 |
400 scoped_ptr<ValueStore::Error> LeveldbValueStore::WriteToDb( | 400 scoped_ptr<ValueStore::Error> LeveldbValueStore::WriteToDb( |
401 leveldb::WriteBatch* batch) { | 401 leveldb::WriteBatch* batch) { |
402 leveldb::Status status = db_->Write(leveldb::WriteOptions(), batch); | 402 leveldb::Status status = db_->Write(leveldb::WriteOptions(), batch); |
(...skipping 28 matching lines...) Expand all Loading... |
431 CHECK(!status.ok()); | 431 CHECK(!status.ok()); |
432 CHECK(!status.IsNotFound()); // not an error | 432 CHECK(!status.IsNotFound()); // not an error |
433 | 433 |
434 std::string message = status.ToString(); | 434 std::string message = status.ToString(); |
435 // The message may contain |db_path_|, which may be considered sensitive | 435 // 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. | 436 // data, and those strings are passed to the extension, so strip it out. |
437 ReplaceSubstringsAfterOffset(&message, 0u, db_path_.AsUTF8Unsafe(), "..."); | 437 ReplaceSubstringsAfterOffset(&message, 0u, db_path_.AsUTF8Unsafe(), "..."); |
438 | 438 |
439 return Error::Create(CORRUPTION, message, key.Pass()); | 439 return Error::Create(CORRUPTION, message, key.Pass()); |
440 } | 440 } |
OLD | NEW |