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

Side by Side Diff: base/json/json_string_value_serializer.h

Issue 9465030: Break two classes defined in json_value_serializer.cc, .h into separate files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « base/json/json_file_value_serializer.cc ('k') | base/json/json_string_value_serializer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_
6 #define BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/base_export.h"
12 #include "base/basictypes.h"
13 #include "base/file_path.h"
14 #include "base/values.h"
15
16 class BASE_EXPORT JSONStringValueSerializer : public base::ValueSerializer {
17 public:
18 // json_string is the string that will be source of the deserialization
19 // or the destination of the serialization. The caller of the constructor
20 // retains ownership of the string.
21 explicit JSONStringValueSerializer(std::string* json_string)
22 : json_string_(json_string),
23 initialized_with_const_string_(false),
24 pretty_print_(false),
25 allow_trailing_comma_(false) {
26 }
27
28 // This version allows initialization with a const string reference for
29 // deserialization only.
30 explicit JSONStringValueSerializer(const std::string& json_string)
31 : json_string_(&const_cast<std::string&>(json_string)),
32 initialized_with_const_string_(true),
33 pretty_print_(false),
34 allow_trailing_comma_(false) {
35 }
36
37 virtual ~JSONStringValueSerializer();
38
39 // Attempt to serialize the data structure represented by Value into
40 // JSON. If the return value is true, the result will have been written
41 // into the string passed into the constructor.
42 virtual bool Serialize(const Value& root) OVERRIDE;
43
44 // Equivalent to Serialize(root) except binary values are omitted from the
45 // output.
46 bool SerializeAndOmitBinaryValues(const Value& root);
47
48 // Attempt to deserialize the data structure encoded in the string passed
49 // in to the constructor into a structure of Value objects. If the return
50 // value is NULL, and if |error_code| is non-null, |error_code| will
51 // contain an integer error code (either JsonFileError or JsonParseError).
52 // If |error_message| is non-null, it will be filled in with a formatted
53 // error message including the location of the error if appropriate.
54 // The caller takes ownership of the returned value.
55 virtual Value* Deserialize(int* error_code,
56 std::string* error_message) OVERRIDE;
57
58 void set_pretty_print(bool new_value) { pretty_print_ = new_value; }
59 bool pretty_print() { return pretty_print_; }
60
61 void set_allow_trailing_comma(bool new_value) {
62 allow_trailing_comma_ = new_value;
63 }
64
65 private:
66 bool SerializeInternal(const Value& root, bool omit_binary_values);
67
68 std::string* json_string_;
69 bool initialized_with_const_string_;
70 bool pretty_print_; // If true, serialization will span multiple lines.
71 // If true, deserialization will allow trailing commas.
72 bool allow_trailing_comma_;
73
74 DISALLOW_COPY_AND_ASSIGN(JSONStringValueSerializer);
75 };
76
77 #endif // BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_
78
OLDNEW
« no previous file with comments | « base/json/json_file_value_serializer.cc ('k') | base/json/json_string_value_serializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698