Index: base/files/important_file_writer.cc |
diff --git a/base/files/important_file_writer.cc b/base/files/important_file_writer.cc |
index edd400ce183f13fada7f89ad861c95e5510f7d55..ede6c7693c2e69d283cd9d89fbaedd8db9e8630a 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), |
+ Passed(&on_next_write_callback_)); |
+ on_next_write_callback_.Reset(); |
dcheng
2016/09/14 06:54:49
No need to call Reset() here, Passed() will transf
proberge
2016/09/14 14:33:33
Done.
|
+ |
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(); |
dcheng
2016/09/14 06:54:49
This can use RunAndReset() in callback_helpers.h
proberge
2016/09/14 14:33:33
RunAndReset is available to ScopedClosureRunner, n
|
} |
} |