Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3377)

Unified Diff: base/files/important_file_writer.cc

Issue 2372663003: Allow ImportantFileWriter to take in a pre-write callback. (Closed)
Patch Set: Add a WaitableEvent to fix a race condition in CallbackRunsOnWriterThread Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/important_file_writer.h ('k') | base/files/important_file_writer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/important_file_writer.cc
diff --git a/base/files/important_file_writer.cc b/base/files/important_file_writer.cc
index 0099cda0b55a8b6f54275126a617af0fe08ff068..cc0a616c5be7e5e09e5235a9f658de6c3e70d740 100644
--- a/base/files/important_file_writer.cc
+++ b/base/files/important_file_writer.cc
@@ -57,13 +57,18 @@ void LogFailure(const FilePath& path, TempFileFailure failure_code,
// Helper function to call WriteFileAtomically() with a
// std::unique_ptr<std::string>.
-void WriteScopedStringToFileAtomically(const FilePath& path,
- std::unique_ptr<std::string> data,
- Callback<void(bool success)> callback) {
+void WriteScopedStringToFileAtomically(
+ const FilePath& path,
+ std::unique_ptr<std::string> data,
+ Closure before_write_callback,
+ Callback<void(bool success)> after_write_callback) {
+ if (!before_write_callback.is_null())
+ before_write_callback.Run();
+
bool result = ImportantFileWriter::WriteFileAtomically(path, *data);
- if (!callback.is_null())
- callback.Run(result);
+ if (!after_write_callback.is_null())
+ after_write_callback.Run(result);
}
} // namespace
@@ -173,7 +178,8 @@ void ImportantFileWriter::WriteNow(std::unique_ptr<std::string> data) {
timer_.Stop();
Closure task = Bind(&WriteScopedStringToFileAtomically, path_, Passed(&data),
- Passed(&on_next_write_callback_));
+ Passed(&before_next_write_callback_),
+ Passed(&after_next_write_callback_));
if (!task_runner_->PostTask(FROM_HERE, MakeCriticalClosure(task))) {
// Posting the task to background message loop is not expected
@@ -209,9 +215,11 @@ void ImportantFileWriter::DoScheduledWrite() {
serializer_ = nullptr;
}
-void ImportantFileWriter::RegisterOnNextWriteCallback(
- const Callback<void(bool success)>& on_next_write_callback) {
- on_next_write_callback_ = on_next_write_callback;
+void ImportantFileWriter::RegisterOnNextWriteCallbacks(
+ const Closure& before_next_write_callback,
+ const Callback<void(bool success)>& after_next_write_callback) {
+ before_next_write_callback_ = before_next_write_callback;
+ after_next_write_callback_ = after_next_write_callback;
}
} // namespace base
« no previous file with comments | « base/files/important_file_writer.h ('k') | base/files/important_file_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698