OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/files/important_file_writer.h" | 5 #include "base/files/important_file_writer.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 // If this happens in the wild something really bad is going on. | 68 // If this happens in the wild something really bad is going on. |
69 CHECK_LE(data.length(), static_cast<size_t>(kint32max)); | 69 CHECK_LE(data.length(), static_cast<size_t>(kint32max)); |
70 int bytes_written = WritePlatformFile( | 70 int bytes_written = WritePlatformFile( |
71 tmp_file, 0, data.data(), static_cast<int>(data.length())); | 71 tmp_file, 0, data.data(), static_cast<int>(data.length())); |
72 FlushPlatformFile(tmp_file); // Ignore return value. | 72 FlushPlatformFile(tmp_file); // Ignore return value. |
73 | 73 |
74 if (!ClosePlatformFile(tmp_file)) { | 74 if (!ClosePlatformFile(tmp_file)) { |
75 LogFailure(path, FAILED_CLOSING, "failed to close temporary file"); | 75 LogFailure(path, FAILED_CLOSING, "failed to close temporary file"); |
76 base::Delete(tmp_file_path, false); | 76 base::DeleteFile(tmp_file_path, false); |
77 return false; | 77 return false; |
78 } | 78 } |
79 | 79 |
80 if (bytes_written < static_cast<int>(data.length())) { | 80 if (bytes_written < static_cast<int>(data.length())) { |
81 LogFailure(path, FAILED_WRITING, "error writing, bytes_written=" + | 81 LogFailure(path, FAILED_WRITING, "error writing, bytes_written=" + |
82 IntToString(bytes_written)); | 82 IntToString(bytes_written)); |
83 base::Delete(tmp_file_path, false); | 83 base::DeleteFile(tmp_file_path, false); |
84 return false; | 84 return false; |
85 } | 85 } |
86 | 86 |
87 if (!base::ReplaceFile(tmp_file_path, path, NULL)) { | 87 if (!base::ReplaceFile(tmp_file_path, path, NULL)) { |
88 LogFailure(path, FAILED_RENAMING, "could not rename temporary file"); | 88 LogFailure(path, FAILED_RENAMING, "could not rename temporary file"); |
89 base::Delete(tmp_file_path, false); | 89 base::DeleteFile(tmp_file_path, false); |
90 return false; | 90 return false; |
91 } | 91 } |
92 | 92 |
93 return true; | 93 return true; |
94 } | 94 } |
95 | 95 |
96 ImportantFileWriter::ImportantFileWriter( | 96 ImportantFileWriter::ImportantFileWriter( |
97 const FilePath& path, base::SequencedTaskRunner* task_runner) | 97 const FilePath& path, base::SequencedTaskRunner* task_runner) |
98 : path_(path), | 98 : path_(path), |
99 task_runner_(task_runner), | 99 task_runner_(task_runner), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (serializer_->SerializeData(&data)) { | 158 if (serializer_->SerializeData(&data)) { |
159 WriteNow(data); | 159 WriteNow(data); |
160 } else { | 160 } else { |
161 DLOG(WARNING) << "failed to serialize data to be saved in " | 161 DLOG(WARNING) << "failed to serialize data to be saved in " |
162 << path_.value().c_str(); | 162 << path_.value().c_str(); |
163 } | 163 } |
164 serializer_ = NULL; | 164 serializer_ = NULL; |
165 } | 165 } |
166 | 166 |
167 } // namespace base | 167 } // namespace base |
OLD | NEW |