| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_COMMON_JSON_VALUE_SERIALIZER_H__ | 5 #ifndef CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ |
| 6 #define CHROME_COMMON_JSON_VALUE_SERIALIZER_H__ | 6 #define CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 | 13 |
| 14 class JSONStringValueSerializer : public ValueSerializer { | 14 class JSONStringValueSerializer : public ValueSerializer { |
| 15 public: | 15 public: |
| 16 // json_string is the string that will be source of the deserialization | 16 // json_string is the string that will be source of the deserialization |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 DISALLOW_EVIL_CONSTRUCTORS(JSONStringValueSerializer); | 61 DISALLOW_EVIL_CONSTRUCTORS(JSONStringValueSerializer); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class JSONFileValueSerializer : public ValueSerializer { | 64 class JSONFileValueSerializer : public ValueSerializer { |
| 65 public: | 65 public: |
| 66 // json_file_patch is the path of a file that will be source of the | 66 // json_file_patch is the path of a file that will be source of the |
| 67 // deserialization or the destination of the serialization. | 67 // deserialization or the destination of the serialization. |
| 68 // When deserializing, the file should exist, but when serializing, the | 68 // When deserializing, the file should exist, but when serializing, the |
| 69 // serializer will attempt to create the file at the specified location. | 69 // serializer will attempt to create the file at the specified location. |
| 70 JSONFileValueSerializer(const FilePath& json_file_path) | 70 explicit JSONFileValueSerializer(const FilePath& json_file_path) |
| 71 : json_file_path_(json_file_path) {} | 71 : json_file_path_(json_file_path) {} |
| 72 | 72 |
| 73 ~JSONFileValueSerializer() {} | 73 ~JSONFileValueSerializer() {} |
| 74 | 74 |
| 75 // DO NOT USE except in unit tests to verify the file was written properly. | 75 // DO NOT USE except in unit tests to verify the file was written properly. |
| 76 // We should never serialize directly to a file since this will block the | 76 // We should never serialize directly to a file since this will block the |
| 77 // thread. Instead, serialize to a string and write to the file you want on | 77 // thread. Instead, serialize to a string and write to the file you want on |
| 78 // the file thread. | 78 // the file thread. |
| 79 // | 79 // |
| 80 // Attempt to serialize the data structure represented by Value into | 80 // Attempt to serialize the data structure represented by Value into |
| 81 // JSON. If the return value is true, the result will have been written | 81 // JSON. If the return value is true, the result will have been written |
| 82 // into the file whose name was passed into the constructor. | 82 // into the file whose name was passed into the constructor. |
| 83 bool Serialize(const Value& root); | 83 bool Serialize(const Value& root); |
| 84 | 84 |
| 85 // Attempt to deserialize the data structure encoded in the file passed | 85 // Attempt to deserialize the data structure encoded in the file passed |
| 86 // in to the constructor into a structure of Value objects. If the return | 86 // in to the constructor into a structure of Value objects. If the return |
| 87 // value is NULL, and if |error_message| is non-null, |error_message| will | 87 // value is NULL, and if |error_message| is non-null, |error_message| will |
| 88 // contain a string describing the error. The caller takes ownership of the | 88 // contain a string describing the error. The caller takes ownership of the |
| 89 // returned value. | 89 // returned value. |
| 90 Value* Deserialize(std::string* error_message); | 90 Value* Deserialize(std::string* error_message); |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 FilePath json_file_path_; | 93 FilePath json_file_path_; |
| 94 | 94 |
| 95 DISALLOW_EVIL_CONSTRUCTORS(JSONFileValueSerializer); | 95 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 #endif // CHROME_COMMON_JSON_VALUE_SERIALIZER_H__ | 98 #endif // CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ |
| OLD | NEW |