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

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

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: Address Joi's comments. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/json/json_value_serializer.cc » ('j') | base/json/json_value_serializer.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef BASE_JSON_JSON_VALUE_SERIALIZER_H_ 5 #ifndef BASE_JSON_JSON_VALUE_SERIALIZER_H_
6 #define BASE_JSON_JSON_VALUE_SERIALIZER_H_ 6 #define BASE_JSON_JSON_VALUE_SERIALIZER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 18 matching lines...) Expand all
29 // deserialization only. 29 // deserialization only.
30 explicit JSONStringValueSerializer(const std::string& json_string) 30 explicit JSONStringValueSerializer(const std::string& json_string)
31 : json_string_(&const_cast<std::string&>(json_string)), 31 : json_string_(&const_cast<std::string&>(json_string)),
32 initialized_with_const_string_(true), 32 initialized_with_const_string_(true),
33 pretty_print_(false), 33 pretty_print_(false),
34 allow_trailing_comma_(false) { 34 allow_trailing_comma_(false) {
35 } 35 }
36 36
37 virtual ~JSONStringValueSerializer(); 37 virtual ~JSONStringValueSerializer();
38 38
39 // Equivalent to calling Serialize(root, false).
40 virtual bool Serialize(const Value& root);
41
39 // Attempt to serialize the data structure represented by Value into 42 // Attempt to serialize the data structure represented by Value into
40 // JSON. If the return value is true, the result will have been written 43 // JSON. If the return value is true, the result will have been written
41 // into the string passed into the constructor. 44 // into the string passed into the constructor. |ignore_binary_values| is
42 virtual bool Serialize(const Value& root); 45 // used to indicate how the serializer should behave when encountering a
46 // binary value.
47 virtual bool Serialize(const Value& root, bool ignore_binary_values);
willchan no longer on Chromium 2011/11/10 18:33:07 No overloading, and why is this virtual, it's not
Eric Dingle 2011/11/10 23:19:57 Done.
43 48
44 // Attempt to deserialize the data structure encoded in the string passed 49 // Attempt to deserialize the data structure encoded in the string passed
45 // in to the constructor into a structure of Value objects. If the return 50 // in to the constructor into a structure of Value objects. If the return
46 // value is NULL, and if |error_code| is non-null, |error_code| will 51 // value is NULL, and if |error_code| is non-null, |error_code| will
47 // contain an integer error code (either JsonFileError or JsonParseError). 52 // contain an integer error code (either JsonFileError or JsonParseError).
48 // If |error_message| is non-null, it will be filled in with a formatted 53 // If |error_message| is non-null, it will be filled in with a formatted
49 // error message including the location of the error if appropriate. 54 // error message including the location of the error if appropriate.
50 // The caller takes ownership of the returned value. 55 // The caller takes ownership of the returned value.
51 virtual Value* Deserialize(int* error_code, std::string* error_message); 56 virtual Value* Deserialize(int* error_code, std::string* error_message);
52 57
(...skipping 18 matching lines...) Expand all
71 public: 76 public:
72 // json_file_patch is the path of a file that will be source of the 77 // json_file_patch is the path of a file that will be source of the
73 // deserialization or the destination of the serialization. 78 // deserialization or the destination of the serialization.
74 // When deserializing, the file should exist, but when serializing, the 79 // When deserializing, the file should exist, but when serializing, the
75 // serializer will attempt to create the file at the specified location. 80 // serializer will attempt to create the file at the specified location.
76 explicit JSONFileValueSerializer(const FilePath& json_file_path) 81 explicit JSONFileValueSerializer(const FilePath& json_file_path)
77 : json_file_path_(json_file_path) {} 82 : json_file_path_(json_file_path) {}
78 83
79 virtual ~JSONFileValueSerializer() {} 84 virtual ~JSONFileValueSerializer() {}
80 85
86 // Equivalent to calling Serialize(root, false).
87 virtual bool Serialize(const Value& root);
88
81 // DO NOT USE except in unit tests to verify the file was written properly. 89 // DO NOT USE except in unit tests to verify the file was written properly.
82 // We should never serialize directly to a file since this will block the 90 // We should never serialize directly to a file since this will block the
83 // thread. Instead, serialize to a string and write to the file you want on 91 // thread. Instead, serialize to a string and write to the file you want on
84 // the file thread. 92 // the file thread.
85 // 93 //
86 // Attempt to serialize the data structure represented by Value into 94 // Attempt to serialize the data structure represented by Value into
87 // JSON. If the return value is true, the result will have been written 95 // JSON. If the return value is true, the result will have been written
88 // into the file whose name was passed into the constructor. 96 // into the file whose name was passed into the constructor.
89 virtual bool Serialize(const Value& root); 97 virtual bool Serialize(const Value& root, bool ignore_binary_values);
90 98
91 // Attempt to deserialize the data structure encoded in the file passed 99 // Attempt to deserialize the data structure encoded in the file passed
92 // in to the constructor into a structure of Value objects. If the return 100 // in to the constructor into a structure of Value objects. If the return
93 // value is NULL, and if |error_code| is non-null, |error_code| will 101 // value is NULL, and if |error_code| is non-null, |error_code| will
94 // contain an integer error code (either JsonFileError or JsonParseError). 102 // contain an integer error code (either JsonFileError or JsonParseError).
95 // If |error_message| is non-null, it will be filled in with a formatted 103 // If |error_message| is non-null, it will be filled in with a formatted
96 // error message including the location of the error if appropriate. 104 // error message including the location of the error if appropriate.
97 // The caller takes ownership of the returned value. 105 // The caller takes ownership of the returned value.
98 virtual Value* Deserialize(int* error_code, std::string* error_message); 106 virtual Value* Deserialize(int* error_code, std::string* error_message);
99 107
(...skipping 20 matching lines...) Expand all
120 FilePath json_file_path_; 128 FilePath json_file_path_;
121 129
122 // A wrapper for file_util::ReadFileToString which returns a non-zero 130 // A wrapper for file_util::ReadFileToString which returns a non-zero
123 // JsonFileError if there were file errors. 131 // JsonFileError if there were file errors.
124 int ReadFileToString(std::string* json_string); 132 int ReadFileToString(std::string* json_string);
125 133
126 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); 134 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer);
127 }; 135 };
128 136
129 #endif // BASE_JSON_JSON_VALUE_SERIALIZER_H_ 137 #endif // BASE_JSON_JSON_VALUE_SERIALIZER_H_
OLDNEW
« no previous file with comments | « no previous file | base/json/json_value_serializer.cc » ('j') | base/json/json_value_serializer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698