summaryrefslogtreecommitdiffstats
path: root/chrome/common/json_value_serializer.cc
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 16:45:34 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 16:45:34 +0000
commitbc9147a10c7287f285ddc1c246cc9d38cd5987c4 (patch)
tree0e8516815d0fd31b439a4cebe4baf8e9e94c98d6 /chrome/common/json_value_serializer.cc
parentc12bf1a1aa1a24d7f516b7e76428518c594d7da5 (diff)
downloadchromium_src-bc9147a10c7287f285ddc1c246cc9d38cd5987c4.zip
chromium_src-bc9147a10c7287f285ddc1c246cc9d38cd5987c4.tar.gz
chromium_src-bc9147a10c7287f285ddc1c246cc9d38cd5987c4.tar.bz2
Some initial work on compiling chrome/common/ on Linux.
Patch from Pawel Hajdan Jr. BUG=2410 Review URL: http://codereview.chromium.org/2929 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2311 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/json_value_serializer.cc')
-rw-r--r--chrome/common/json_value_serializer.cc39
1 files changed, 10 insertions, 29 deletions
diff --git a/chrome/common/json_value_serializer.cc b/chrome/common/json_value_serializer.cc
index a50ed11..b07fb29 100644
--- a/chrome/common/json_value_serializer.cc
+++ b/chrome/common/json_value_serializer.cc
@@ -4,6 +4,7 @@
#include "chrome/common/json_value_serializer.h"
+#include "base/file_util.h"
#include "base/json_reader.h"
#include "base/json_writer.h"
#include "base/string_util.h"
@@ -37,41 +38,21 @@ bool JSONFileValueSerializer::Serialize(const Value& root) {
if (!result)
return false;
- FILE* file = NULL;
- _wfopen_s(&file, json_file_path_.c_str(), L"wb");
- if (!file)
+ int data_size = static_cast<int>(json_string.size());
+ if (file_util::WriteFile(json_file_path_,
+ json_string.data(),
+ data_size) != data_size)
return false;
- size_t amount_written =
- fwrite(json_string.data(), 1, json_string.size(), file);
- fclose(file);
-
- return amount_written == json_string.size();
+ return true;
}
bool JSONFileValueSerializer::Deserialize(Value** root) {
- FILE* file = NULL;
- _wfopen_s(&file, json_file_path_.c_str(), L"rb");
- if (!file)
- return false;
-
- fseek(file, 0, SEEK_END);
- size_t file_size = ftell(file);
- rewind(file);
-
- bool result = false;
std::string json_string;
- size_t chars_read = fread(
- // WriteInto assumes the last character is a null, and it's not in this
- // case, so we need to add 1 to our size to ensure the last character
- // doesn't get cut off.
- WriteInto(&json_string, file_size + 1), 1, file_size, file);
- if (chars_read == file_size) {
- JSONStringValueSerializer serializer(json_string);
- result = serializer.Deserialize(root);
+ if (!file_util::ReadFileToString(json_file_path_, &json_string)) {
+ return false;
}
-
- fclose(file);
- return result;
+ JSONStringValueSerializer serializer(json_string);
+ return serializer.Deserialize(root);
}