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