| 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/file_util.h" | 7 #include "base/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 18 matching lines...) Expand all Loading... |
| 29 std::string json_string; | 29 std::string json_string; |
| 30 JSONStringValueSerializer serializer(&json_string); | 30 JSONStringValueSerializer serializer(&json_string); |
| 31 serializer.set_pretty_print(true); | 31 serializer.set_pretty_print(true); |
| 32 bool result = omit_binary_values ? | 32 bool result = omit_binary_values ? |
| 33 serializer.SerializeAndOmitBinaryValues(root) : | 33 serializer.SerializeAndOmitBinaryValues(root) : |
| 34 serializer.Serialize(root); | 34 serializer.Serialize(root); |
| 35 if (!result) | 35 if (!result) |
| 36 return false; | 36 return false; |
| 37 | 37 |
| 38 int data_size = static_cast<int>(json_string.size()); | 38 int data_size = static_cast<int>(json_string.size()); |
| 39 if (file_util::WriteFile(json_file_path_, | 39 if (base::WriteFile(json_file_path_, json_string.data(), data_size) != |
| 40 json_string.data(), | 40 data_size) |
| 41 data_size) != data_size) | |
| 42 return false; | 41 return false; |
| 43 | 42 |
| 44 return true; | 43 return true; |
| 45 } | 44 } |
| 46 | 45 |
| 47 int JSONFileValueSerializer::ReadFileToString(std::string* json_string) { | 46 int JSONFileValueSerializer::ReadFileToString(std::string* json_string) { |
| 48 DCHECK(json_string); | 47 DCHECK(json_string); |
| 49 if (!base::ReadFileToString(json_file_path_, json_string)) { | 48 if (!base::ReadFileToString(json_file_path_, json_string)) { |
| 50 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
| 51 int error = ::GetLastError(); | 50 int error = ::GetLastError(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 *error_code = error; | 89 *error_code = error; |
| 91 if (error_str) | 90 if (error_str) |
| 92 *error_str = GetErrorMessageForCode(error); | 91 *error_str = GetErrorMessageForCode(error); |
| 93 return NULL; | 92 return NULL; |
| 94 } | 93 } |
| 95 | 94 |
| 96 JSONStringValueSerializer serializer(json_string); | 95 JSONStringValueSerializer serializer(json_string); |
| 97 serializer.set_allow_trailing_comma(allow_trailing_comma_); | 96 serializer.set_allow_trailing_comma(allow_trailing_comma_); |
| 98 return serializer.Deserialize(error_code, error_str); | 97 return serializer.Deserialize(error_code, error_str); |
| 99 } | 98 } |
| OLD | NEW |