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

Unified Diff: base/json/json_value_serializer.cc

Issue 8505033: Allow JSONWriter and JSONValueSerializer to omit binary values when instructed to do so. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove extra virtual. Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: base/json/json_value_serializer.cc
diff --git a/base/json/json_value_serializer.cc b/base/json/json_value_serializer.cc
index d667bc198e76fe7c19cdc0a3af0667982fbfade0..e83787a39feebf5a9a778d3e0c510e7c2cfc5c05 100644
--- a/base/json/json_value_serializer.cc
+++ b/base/json/json_value_serializer.cc
@@ -17,10 +17,19 @@ const char* JSONFileValueSerializer::kNoSuchFile = "File doesn't exist.";
JSONStringValueSerializer::~JSONStringValueSerializer() {}
bool JSONStringValueSerializer::Serialize(const Value& root) {
+ return SerializeWithOptionalBinaryValues(root, false);
+}
+
+bool JSONStringValueSerializer::SerializeWithOptionalBinaryValues(
+ const Value& root, bool omit_binary_values) {
if (!json_string_ || initialized_with_const_string_)
return false;
- base::JSONWriter::Write(&root, pretty_print_, json_string_);
+ base::JSONWriter::WriteWithOptions(
+ &root,
+ pretty_print_,
+ omit_binary_values ? base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES : 0,
+ json_string_);
return true;
}
@@ -38,10 +47,16 @@ Value* JSONStringValueSerializer::Deserialize(int* error_code,
/******* File Serializer *******/
bool JSONFileValueSerializer::Serialize(const Value& root) {
+ return SerializeWithOptionalBinaryValues(root, false);
+}
+
+bool JSONFileValueSerializer::SerializeWithOptionalBinaryValues(
+ const Value& root, bool omit_binary_values) {
std::string json_string;
JSONStringValueSerializer serializer(&json_string);
serializer.set_pretty_print(true);
- bool result = serializer.Serialize(root);
+ bool result = serializer.SerializeWithOptionalBinaryValues(
+ root, omit_binary_values);
if (!result)
return false;

Powered by Google App Engine
This is Rietveld 408576698