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 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 case JSON_FILE_LOCKED: | 94 case JSON_FILE_LOCKED: |
95 return kFileLocked; | 95 return kFileLocked; |
96 case JSON_NO_SUCH_FILE: | 96 case JSON_NO_SUCH_FILE: |
97 return kNoSuchFile; | 97 return kNoSuchFile; |
98 default: | 98 default: |
99 NOTREACHED(); | 99 NOTREACHED(); |
100 return ""; | 100 return ""; |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 scoped_ptr<base::Value> JSONFileValueDeserializer::Deserialize( | 104 std::unique_ptr<base::Value> JSONFileValueDeserializer::Deserialize( |
105 int* error_code, | 105 int* error_code, |
106 std::string* error_str) { | 106 std::string* error_str) { |
107 std::string json_string; | 107 std::string json_string; |
108 int error = ReadFileToString(&json_string); | 108 int error = ReadFileToString(&json_string); |
109 if (error != JSON_NO_ERROR) { | 109 if (error != JSON_NO_ERROR) { |
110 if (error_code) | 110 if (error_code) |
111 *error_code = error; | 111 *error_code = error; |
112 if (error_str) | 112 if (error_str) |
113 *error_str = GetErrorMessageForCode(error); | 113 *error_str = GetErrorMessageForCode(error); |
114 return NULL; | 114 return NULL; |
115 } | 115 } |
116 | 116 |
117 JSONStringValueDeserializer deserializer(json_string); | 117 JSONStringValueDeserializer deserializer(json_string); |
118 deserializer.set_allow_trailing_comma(allow_trailing_comma_); | 118 deserializer.set_allow_trailing_comma(allow_trailing_comma_); |
119 return deserializer.Deserialize(error_code, error_str); | 119 return deserializer.Deserialize(error_code, error_str); |
120 } | 120 } |
OLD | NEW |