app_list: Fix unnecessary image zoomy on click.
[chromium-blink-merge.git] / base / json / json_string_value_serializer.cc
blob7611fbeed654229cc45bdd0776fe4cb17c180831
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/json/json_string_value_serializer.h"
7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h"
9 #include "base/logging.h"
11 using base::Value;
13 JSONStringValueSerializer::~JSONStringValueSerializer() {}
15 bool JSONStringValueSerializer::Serialize(const Value& root) {
16 return SerializeInternal(root, false);
19 bool JSONStringValueSerializer::SerializeAndOmitBinaryValues(
20 const Value& root) {
21 return SerializeInternal(root, true);
24 bool JSONStringValueSerializer::SerializeInternal(const Value& root,
25 bool omit_binary_values) {
26 if (!json_string_ || initialized_with_const_string_)
27 return false;
29 int options = 0;
30 if (omit_binary_values)
31 options |= base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES;
32 if (pretty_print_)
33 options |= base::JSONWriter::OPTIONS_PRETTY_PRINT;
35 base::JSONWriter::WriteWithOptions(&root, options, json_string_);
36 return true;
39 Value* JSONStringValueSerializer::Deserialize(int* error_code,
40 std::string* error_str) {
41 if (!json_string_)
42 return NULL;
44 return base::JSONReader::ReadAndReturnError(*json_string_,
45 allow_trailing_comma_ ? base::JSON_ALLOW_TRAILING_COMMAS :
46 base::JSON_PARSE_RFC,
47 error_code, error_str);