OLD | NEW |
1 // Copyright (c) 2009 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 CONTENT_COMMON_JSON_VALUE_SERIALIZER_H_ | 5 #ifndef CONTENT_COMMON_JSON_VALUE_SERIALIZER_H_ |
6 #define CONTENT_COMMON_JSON_VALUE_SERIALIZER_H_ | 6 #define CONTENT_COMMON_JSON_VALUE_SERIALIZER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 | 14 |
15 class JSONStringValueSerializer : public ValueSerializer { | 15 class JSONStringValueSerializer : public base::ValueSerializer { |
16 public: | 16 public: |
17 // json_string is the string that will be source of the deserialization | 17 // json_string is the string that will be source of the deserialization |
18 // or the destination of the serialization. The caller of the constructor | 18 // or the destination of the serialization. The caller of the constructor |
19 // retains ownership of the string. | 19 // retains ownership of the string. |
20 explicit JSONStringValueSerializer(std::string* json_string) | 20 explicit JSONStringValueSerializer(std::string* json_string) |
21 : json_string_(json_string), | 21 : json_string_(json_string), |
22 initialized_with_const_string_(false), | 22 initialized_with_const_string_(false), |
23 pretty_print_(false), | 23 pretty_print_(false), |
24 allow_trailing_comma_(false) { | 24 allow_trailing_comma_(false) { |
25 } | 25 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 private: | 59 private: |
60 std::string* json_string_; | 60 std::string* json_string_; |
61 bool initialized_with_const_string_; | 61 bool initialized_with_const_string_; |
62 bool pretty_print_; // If true, serialization will span multiple lines. | 62 bool pretty_print_; // If true, serialization will span multiple lines. |
63 // If true, deserialization will allow trailing commas. | 63 // If true, deserialization will allow trailing commas. |
64 bool allow_trailing_comma_; | 64 bool allow_trailing_comma_; |
65 | 65 |
66 DISALLOW_COPY_AND_ASSIGN(JSONStringValueSerializer); | 66 DISALLOW_COPY_AND_ASSIGN(JSONStringValueSerializer); |
67 }; | 67 }; |
68 | 68 |
69 class JSONFileValueSerializer : public ValueSerializer { | 69 class JSONFileValueSerializer : public base::ValueSerializer { |
70 public: | 70 public: |
71 // json_file_patch is the path of a file that will be source of the | 71 // json_file_patch is the path of a file that will be source of the |
72 // deserialization or the destination of the serialization. | 72 // deserialization or the destination of the serialization. |
73 // When deserializing, the file should exist, but when serializing, the | 73 // When deserializing, the file should exist, but when serializing, the |
74 // serializer will attempt to create the file at the specified location. | 74 // serializer will attempt to create the file at the specified location. |
75 explicit JSONFileValueSerializer(const FilePath& json_file_path) | 75 explicit JSONFileValueSerializer(const FilePath& json_file_path) |
76 : json_file_path_(json_file_path) {} | 76 : json_file_path_(json_file_path) {} |
77 | 77 |
78 virtual ~JSONFileValueSerializer() {} | 78 virtual ~JSONFileValueSerializer() {} |
79 | 79 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 FilePath json_file_path_; | 119 FilePath json_file_path_; |
120 | 120 |
121 // A wrapper for file_util::ReadFileToString which returns a non-zero | 121 // A wrapper for file_util::ReadFileToString which returns a non-zero |
122 // JsonFileError if there were file errors. | 122 // JsonFileError if there were file errors. |
123 int ReadFileToString(std::string* json_string); | 123 int ReadFileToString(std::string* json_string); |
124 | 124 |
125 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); | 125 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); |
126 }; | 126 }; |
127 | 127 |
128 #endif // CONTENT_COMMON_JSON_VALUE_SERIALIZER_H_ | 128 #endif // CONTENT_COMMON_JSON_VALUE_SERIALIZER_H_ |
OLD | NEW |