Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 File tmp_file(tmp_file_path, File::FLAG_OPEN | File::FLAG_WRITE); | 83 File tmp_file(tmp_file_path, File::FLAG_OPEN | File::FLAG_WRITE); |
| 84 if (!tmp_file.IsValid()) { | 84 if (!tmp_file.IsValid()) { |
| 85 LogFailure(path, FAILED_OPENING, "could not open temporary file"); | 85 LogFailure(path, FAILED_OPENING, "could not open temporary file"); |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // If this happens in the wild something really bad is going on. | 89 // If this happens in the wild something really bad is going on. |
| 90 CHECK_LE(data.length(), static_cast<size_t>(kint32max)); | 90 CHECK_LE(data.length(), static_cast<size_t>(kint32max)); |
| 91 int bytes_written = tmp_file.Write(0, data.data(), | 91 int bytes_written = tmp_file.Write(0, data.data(), |
| 92 static_cast<int>(data.length())); | 92 static_cast<int>(data.length())); |
| 93 bool flush_success = tmp_file.Flush(); | 93 bool flush_success = tmp_file.FlushData(); |
|
rvargas (doing something else)
2015/03/20 18:56:05
Incidentally, crbug.com/468046 is about doing _mor
hashimoto
2015/03/20 19:38:57
Hmm, ImportantFileWriter's slowness is already a p
hashimoto
2015/03/20 19:40:30
Oops, wrong bug number.
crbug.com/418627 is the co
rvargas (doing something else)
2015/03/20 21:43:00
Shouldn't we profile it from the field? The fact t
| |
| 94 tmp_file.Close(); | 94 tmp_file.Close(); |
| 95 | 95 |
| 96 if (bytes_written < static_cast<int>(data.length())) { | 96 if (bytes_written < static_cast<int>(data.length())) { |
| 97 LogFailure(path, FAILED_WRITING, "error writing, bytes_written=" + | 97 LogFailure(path, FAILED_WRITING, "error writing, bytes_written=" + |
| 98 IntToString(bytes_written)); | 98 IntToString(bytes_written)); |
| 99 base::DeleteFile(tmp_file_path, false); | 99 base::DeleteFile(tmp_file_path, false); |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 | 102 |
| 103 if (!flush_success) { | 103 if (!flush_success) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 | 213 |
| 214 void ImportantFileWriter::ForwardSuccessfulWrite(bool result) { | 214 void ImportantFileWriter::ForwardSuccessfulWrite(bool result) { |
| 215 DCHECK(CalledOnValidThread()); | 215 DCHECK(CalledOnValidThread()); |
| 216 if (result && !on_next_successful_write_.is_null()) { | 216 if (result && !on_next_successful_write_.is_null()) { |
| 217 on_next_successful_write_.Run(); | 217 on_next_successful_write_.Run(); |
| 218 on_next_successful_write_.Reset(); | 218 on_next_successful_write_.Reset(); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace base | 222 } // namespace base |
| OLD | NEW |