diff options
author | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-16 13:04:15 +0000 |
---|---|---|
committer | pneubeck@chromium.org <pneubeck@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-16 13:04:15 +0000 |
commit | c976fba1262c41d01654deb2357b8cad9dc589ad (patch) | |
tree | 8f99d131f98193e3e1d22f8aa98c54f3aab25448 /extensions/browser/value_store | |
parent | ea5a778a7d9cf523d920d5f142e26680132688b8 (diff) | |
download | chromium_src-c976fba1262c41d01654deb2357b8cad9dc589ad.zip chromium_src-c976fba1262c41d01654deb2357b8cad9dc589ad.tar.gz chromium_src-c976fba1262c41d01654deb2357b8cad9dc589ad.tar.bz2 |
Log error in ValueStore if JSON serialization during writing fails.
For example, this error occurs if one tries to store a base::BinaryValue.
BUG=NONE
Review URL: https://codereview.chromium.org/326393002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277413 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser/value_store')
-rw-r--r-- | extensions/browser/value_store/leveldb_value_store.cc | 4 | ||||
-rw-r--r-- | extensions/browser/value_store/value_store_frontend.cc | 8 |
2 files changed, 9 insertions, 3 deletions
diff --git a/extensions/browser/value_store/leveldb_value_store.cc b/extensions/browser/value_store/leveldb_value_store.cc index 0f09f5b..6d7fdc9 100644 --- a/extensions/browser/value_store/leveldb_value_store.cc +++ b/extensions/browser/value_store/leveldb_value_store.cc @@ -22,6 +22,7 @@ using content::BrowserThread; namespace { const char kInvalidJson[] = "Invalid JSON"; +const char kCannotSerialize[] = "Cannot serialize value to JSON"; // Scoped leveldb snapshot which releases the snapshot on destruction. class ScopedSnapshot { @@ -390,7 +391,8 @@ scoped_ptr<ValueStore::Error> LeveldbValueStore::AddToBatch( if (write_new_value) { std::string value_as_json; - base::JSONWriter::Write(&value, &value_as_json); + if (!base::JSONWriter::Write(&value, &value_as_json)) + return Error::Create(OTHER_ERROR, kCannotSerialize, util::NewKey(key)); batch->Put(key, value_as_json); } diff --git a/extensions/browser/value_store/value_store_frontend.cc b/extensions/browser/value_store/value_store_frontend.cc index 73b6aff..58318c3 100644 --- a/extensions/browser/value_store/value_store_frontend.cc +++ b/extensions/browser/value_store/value_store_frontend.cc @@ -55,8 +55,12 @@ class ValueStoreFrontend::Backend : public base::RefCountedThreadSafe<Backend> { void Set(const std::string& key, scoped_ptr<base::Value> value) { DCHECK_CURRENTLY_ON(BrowserThread::FILE); // We don't need the old value, so skip generating changes. - storage_->Set(ValueStore::IGNORE_QUOTA | ValueStore::NO_GENERATE_CHANGES, - key, *value.get()); + ValueStore::WriteResult result = storage_->Set( + ValueStore::IGNORE_QUOTA | ValueStore::NO_GENERATE_CHANGES, + key, + *value.get()); + LOG_IF(ERROR, result->HasError()) << "Error while writing " << key << " to " + << db_path_.value(); } void Remove(const std::string& key) { |