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..a496285f81803b182dd50e572a3f8c5fd0362541 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, |
+ Callback<void(bool success)> callback) { |
+ bool result = ImportantFileWriter::WriteFileAtomically(path, *data); |
+ |
+ if (!callback.is_null()) |
+ callback.Run(result); |
+ |
+ 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), |
+ on_next_write_callback_); |
+ on_next_write_callback_.Reset(); |
+ |
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 |
@@ -203,10 +212,16 @@ void ImportantFileWriter::DoScheduledWrite() { |
serializer_ = nullptr; |
} |
-void ImportantFileWriter::RegisterOnNextSuccessfulWriteCallback( |
- const Closure& on_next_successful_write) { |
- DCHECK(on_next_successful_write_.is_null()); |
- on_next_successful_write_ = on_next_successful_write; |
+void ImportantFileWriter::RegisterOnNextSuccessfulWriteReply( |
+ const Closure& on_next_successful_write_reply) { |
+ DCHECK(on_next_successful_write_reply_.is_null()); |
+ on_next_successful_write_reply_ = on_next_successful_write_reply; |
+} |
+ |
+void ImportantFileWriter::RegisterOnNextWriteSynchronousCallback( |
+ const Callback<void(bool success)>& on_next_write_callback) { |
+ DCHECK(on_next_write_callback_.is_null()); |
+ on_next_write_callback_ = on_next_write_callback; |
} |
bool ImportantFileWriter::PostWriteTask(const Callback<bool()>& task) { |
@@ -215,7 +230,7 @@ bool ImportantFileWriter::PostWriteTask(const Callback<bool()>& task) { |
// PostTaskAndReply causes memory leaks in tests (crbug.com/371974) and |
// suppressing all of those is unrealistic hence we avoid most of them by |
// using PostTask() in the typical scenario below. |
- if (!on_next_successful_write_.is_null()) { |
+ if (!on_next_successful_write_reply_.is_null()) { |
return PostTaskAndReplyWithResult( |
task_runner_.get(), |
FROM_HERE, |
@@ -230,9 +245,9 @@ bool ImportantFileWriter::PostWriteTask(const Callback<bool()>& task) { |
void ImportantFileWriter::ForwardSuccessfulWrite(bool result) { |
DCHECK(CalledOnValidThread()); |
- if (result && !on_next_successful_write_.is_null()) { |
- on_next_successful_write_.Run(); |
- on_next_successful_write_.Reset(); |
+ if (result && !on_next_successful_write_reply_.is_null()) { |
+ on_next_successful_write_reply_.Run(); |
+ on_next_successful_write_reply_.Reset(); |
} |
} |