Chromium Code Reviews| Index: base/files/important_file_writer.cc |
| diff --git a/base/files/important_file_writer.cc b/base/files/important_file_writer.cc |
| index 28550ad52fc9addfe6c2fdb8f908c069b2647eab..2e9b7d08f2ee72bddb8b2e79bb466ac7f2e1e462 100644 |
| --- a/base/files/important_file_writer.cc |
| +++ b/base/files/important_file_writer.cc |
| @@ -58,8 +58,14 @@ void LogFailure(const FilePath& path, TempFileFailure failure_code, |
| // Helper function to call WriteFileAtomically() with a |
| // std::unique_ptr<std::string>. |
| bool WriteScopedStringToFileAtomically(const FilePath& path, |
| - std::unique_ptr<std::string> data) { |
| - return ImportantFileWriter::WriteFileAtomically(path, *data); |
| + std::unique_ptr<std::string> data, |
| + base::Closure callback) { |
| + bool result = ImportantFileWriter::WriteFileAtomically(path, *data); |
| + |
| + if (result && !callback.is_null()) |
| + callback.Run(); |
| + |
| + return result; |
| } |
| } // namespace |
| @@ -168,7 +174,10 @@ void ImportantFileWriter::WriteNow(std::unique_ptr<std::string> data) { |
| if (HasPendingWrite()) |
| timer_.Stop(); |
| - auto task = Bind(&WriteScopedStringToFileAtomically, path_, Passed(&data)); |
| + auto task = Bind(&WriteScopedStringToFileAtomically, path_, Passed(&data), |
| + blocking_on_next_successful_write_); |
| + blocking_on_next_successful_write_.Reset(); |
|
gab
2016/08/03 18:19:34
This won't respect the contract (it won't stay aro
proberge
2016/08/04 00:13:45
Right, unlike the migration case we care about a s
|
| + |
| if (!PostWriteTask(task)) { |
| // Posting the task to background message loop is not expected |
| // to fail, but if it does, avoid losing data and just hit the disk |
| @@ -209,6 +218,12 @@ void ImportantFileWriter::RegisterOnNextSuccessfulWriteCallback( |
| on_next_successful_write_ = on_next_successful_write; |
| } |
| +void ImportantFileWriter::RegisterOnNextSuccessfulWriteBlockingCallback( |
| + const Closure& on_next_successful_write) { |
| + DCHECK(blocking_on_next_successful_write_.is_null()); |
| + blocking_on_next_successful_write_ = on_next_successful_write; |
| +} |
| + |
| bool ImportantFileWriter::PostWriteTask(const Callback<bool()>& task) { |
| // TODO(gab): This code could always use PostTaskAndReplyWithResult and let |
| // ForwardSuccessfulWrite() no-op if |on_next_successful_write_| is null, but |