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

Unified Diff: base/files/important_file_writer.cc

Issue 2204943002: Integrate registry_hash_store_contents with the rest of tracked prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Experiment with giving two transactions to EnforceAndReport Created 4 years, 4 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
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

Powered by Google App Engine
This is Rietveld 408576698