Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1497)

Unified Diff: chrome/common/json_value_serializer.cc

Issue 2929: Some initial work on compiling chrome/common/ on Linux.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/jpeg_codec.cc ('k') | chrome/common/libxml_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/json_value_serializer.cc
===================================================================
--- chrome/common/json_value_serializer.cc (revision 2299)
+++ chrome/common/json_value_serializer.cc (working copy)
@@ -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,16 @@
if (!result)
return false;
- FILE* file = NULL;
- _wfopen_s(&file, json_file_path_.c_str(), L"wb");
- if (!file)
- return false;
-
- size_t amount_written =
- fwrite(json_string.data(), 1, json_string.size(), file);
- fclose(file);
-
- return amount_written == json_string.size();
+ return file_util::WriteFile(json_file_path_, json_string.data(),
+ json_string.size());
}
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);
}
« no previous file with comments | « chrome/common/jpeg_codec.cc ('k') | chrome/common/libxml_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698