OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/json/json_file_value_serializer.h" | 5 #include "base/json/json_file_value_serializer.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 case JSON_FILE_LOCKED: | 93 case JSON_FILE_LOCKED: |
94 return kFileLocked; | 94 return kFileLocked; |
95 case JSON_NO_SUCH_FILE: | 95 case JSON_NO_SUCH_FILE: |
96 return kNoSuchFile; | 96 return kNoSuchFile; |
97 default: | 97 default: |
98 NOTREACHED(); | 98 NOTREACHED(); |
99 return ""; | 99 return ""; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 base::Value* JSONFileValueDeserializer::Deserialize(int* error_code, | 103 scoped_ptr<base::Value> JSONFileValueDeserializer::Deserialize( |
104 std::string* error_str) { | 104 int* error_code, |
| 105 std::string* error_str) { |
105 std::string json_string; | 106 std::string json_string; |
106 int error = ReadFileToString(&json_string); | 107 int error = ReadFileToString(&json_string); |
107 if (error != JSON_NO_ERROR) { | 108 if (error != JSON_NO_ERROR) { |
108 if (error_code) | 109 if (error_code) |
109 *error_code = error; | 110 *error_code = error; |
110 if (error_str) | 111 if (error_str) |
111 *error_str = GetErrorMessageForCode(error); | 112 *error_str = GetErrorMessageForCode(error); |
112 return NULL; | 113 return NULL; |
113 } | 114 } |
114 | 115 |
115 JSONStringValueDeserializer deserializer(json_string); | 116 JSONStringValueDeserializer deserializer(json_string); |
116 deserializer.set_allow_trailing_comma(allow_trailing_comma_); | 117 deserializer.set_allow_trailing_comma(allow_trailing_comma_); |
117 return deserializer.Deserialize(error_code, error_str); | 118 return deserializer.Deserialize(error_code, error_str); |
118 } | 119 } |
OLD | NEW |