Chromium Code Reviews| 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/values.h" | 12 #include "base/values.h" |
| 12 | 13 |
| 13 class JSONStringValueSerializer : public ValueSerializer { | 14 class JSONStringValueSerializer : public ValueSerializer { |
| 14 public: | 15 public: |
| 15 // 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 |
| 16 // or the destination of the serialization. The caller of the constructor | 17 // or the destination of the serialization. The caller of the constructor |
| 17 // retains ownership of the string. | 18 // retains ownership of the string. |
| 18 JSONStringValueSerializer(std::string* json_string) | 19 JSONStringValueSerializer(std::string* json_string) |
| 19 : json_string_(json_string), | 20 : json_string_(json_string), |
| 20 initialized_with_const_string_(false), | 21 initialized_with_const_string_(false), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 60 |
| 60 DISALLOW_EVIL_CONSTRUCTORS(JSONStringValueSerializer); | 61 DISALLOW_EVIL_CONSTRUCTORS(JSONStringValueSerializer); |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 class JSONFileValueSerializer : public ValueSerializer { | 64 class JSONFileValueSerializer : public ValueSerializer { |
| 64 public: | 65 public: |
| 65 // 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 |
| 66 // deserialization or the destination of the serialization. | 67 // deserialization or the destination of the serialization. |
| 67 // When deserializing, the file should exist, but when serializing, the | 68 // When deserializing, the file should exist, but when serializing, the |
| 68 // 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) | |
| 71 : json_file_path_(json_file_path) {} | |
| 72 // DEPRECATED - DO NOT USE | |
| 73 // TODO(port): remove references to this | |
| 69 JSONFileValueSerializer(const std::wstring& json_file_path) | 74 JSONFileValueSerializer(const std::wstring& json_file_path) |
| 70 : json_file_path_(json_file_path) {} | 75 : json_file_path_(FilePath::FromWStringHack(json_file_path)) {} |
| 71 | 76 |
| 72 ~JSONFileValueSerializer() {} | 77 ~JSONFileValueSerializer() {} |
| 73 | 78 |
| 74 // DO NOT USE except in unit tests to verify the file was written properly. | 79 // DO NOT USE except in unit tests to verify the file was written properly. |
| 75 // We should never serialize directly to a file since this will block the | 80 // We should never serialize directly to a file since this will block the |
| 76 // thread. Instead, serialize to a string and write to the file you want on | 81 // thread. Instead, serialize to a string and write to the file you want on |
| 77 // the file thread. | 82 // the file thread. |
| 78 // | 83 // |
| 79 // Attempt to serialize the data structure represented by Value into | 84 // Attempt to serialize the data structure represented by Value into |
| 80 // JSON. If the return value is true, the result will have been written | 85 // JSON. If the return value is true, the result will have been written |
| 81 // into the file whose name was passed into the constructor. | 86 // into the file whose name was passed into the constructor. |
| 82 bool Serialize(const Value& root); | 87 bool Serialize(const Value& root); |
| 83 | 88 |
| 84 // Attempt to deserialize the data structure encoded in the file passed | 89 // Attempt to deserialize the data structure encoded in the file passed |
| 85 // in to the constructor into a structure of Value objects. If the return | 90 // in to the constructor into a structure of Value objects. If the return |
| 86 // value is NULL, and if |error_message| is non-null, |error_message| will | 91 // value is NULL, and if |error_message| is non-null, |error_message| will |
| 87 // contain a string describing the error. The caller takes ownership of the | 92 // contain a string describing the error. The caller takes ownership of the |
| 88 // returned value. | 93 // returned value. |
| 89 Value* Deserialize(std::string* error_message); | 94 Value* Deserialize(std::string* error_message); |
| 90 | 95 |
| 91 private: | 96 private: |
| 92 std::wstring json_file_path_; | 97 FilePath json_file_path_; |
|
Matt Perry
2009/03/06 19:40:10
there doesn't need to be a corresponding .cc chang
Erik does not do reviews
2009/03/06 19:42:14
believe it or not, no. The reason is that all of
| |
| 93 | 98 |
| 94 DISALLOW_EVIL_CONSTRUCTORS(JSONFileValueSerializer); | 99 DISALLOW_EVIL_CONSTRUCTORS(JSONFileValueSerializer); |
| 95 }; | 100 }; |
| 96 | 101 |
| 97 #endif // CHROME_COMMON_JSON_VALUE_SERIALIZER_H__ | 102 #endif // CHROME_COMMON_JSON_VALUE_SERIALIZER_H__ |
| 98 | 103 |
| OLD | NEW |