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

Side by Side Diff: base/json/json_file_value_serializer.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/files/file_util_proxy_unittest.cc ('k') | base/json/json_value_serializer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « base/files/file_util_proxy_unittest.cc ('k') | base/json/json_value_serializer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698