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

Unified Diff: base/files/important_file_writer.cc

Issue 11308196: [cros] RlzValueStore made protected by a cross-process lock and not persisted over browser lifetime… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment Created 8 years, 1 month 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 536b0fb161b93cadd3a38a355bf2e071b9c1f59d..a2a14cdd5aaa52908da6a83714e1a2f55b2627eb 100644
--- a/base/files/important_file_writer.cc
+++ b/base/files/important_file_writer.cc
@@ -42,7 +42,11 @@ void LogFailure(const FilePath& path, TempFileFailure failure_code,
<< " : " << message;
}
-void WriteToDiskTask(const FilePath& path, const std::string& data) {
+} // namespace
+
+// static
+bool ImportantFileWriter::WriteToDisk(const FilePath& path,
+ const std::string& data) {
// Write the data to a temp file then rename to avoid data loss if we crash
// while writing the file. Ensure that the temp file is on the same volume
// as target file, so it can be moved in one step, and that the temp file
@@ -50,7 +54,7 @@ void WriteToDiskTask(const FilePath& path, const std::string& data) {
FilePath tmp_file_path;
if (!file_util::CreateTemporaryFileInDir(path.DirName(), &tmp_file_path)) {
LogFailure(path, FAILED_CREATING, "could not create temporary file");
- return;
+ return false;
}
int flags = PLATFORM_FILE_OPEN | PLATFORM_FILE_WRITE;
@@ -58,7 +62,7 @@ void WriteToDiskTask(const FilePath& path, const std::string& data) {
CreatePlatformFile(tmp_file_path, flags, NULL, NULL);
if (tmp_file == kInvalidPlatformFileValue) {
LogFailure(path, FAILED_OPENING, "could not open temporary file");
- return;
+ return false;
}
// If this happens in the wild something really bad is going on.
@@ -70,24 +74,24 @@ void WriteToDiskTask(const FilePath& path, const std::string& data) {
if (!ClosePlatformFile(tmp_file)) {
LogFailure(path, FAILED_CLOSING, "failed to close temporary file");
file_util::Delete(tmp_file_path, false);
- return;
+ return false;
}
if (bytes_written < static_cast<int>(data.length())) {
LogFailure(path, FAILED_WRITING, "error writing, bytes_written=" +
IntToString(bytes_written));
file_util::Delete(tmp_file_path, false);
- return;
+ return false;
}
if (!file_util::ReplaceFile(tmp_file_path, path)) {
LogFailure(path, FAILED_RENAMING, "could not rename temporary file");
file_util::Delete(tmp_file_path, false);
- return;
+ return false;
}
-}
-} // namespace
+ return true;
+}
ImportantFileWriter::ImportantFileWriter(
const FilePath& path, base::SequencedTaskRunner* task_runner)
@@ -122,14 +126,16 @@ void ImportantFileWriter::WriteNow(const std::string& data) {
if (HasPendingWrite())
timer_.Stop();
- if (!task_runner_->PostTask(FROM_HERE,
- MakeCriticalClosure(Bind(&WriteToDiskTask, path_, data)))) {
+ if (!task_runner_->PostTask(
+ FROM_HERE,
+ MakeCriticalClosure(Bind(
+ IgnoreResult(&ImportantFileWriter::WriteToDisk), path_, data)))) {
// Posting the task to background message loop is not expected
// to fail, but if it does, avoid losing data and just hit the disk
// on the current thread.
NOTREACHED();
- WriteToDiskTask(path_, data);
+ WriteToDisk(path_, data);
}
}

Powered by Google App Engine
This is Rietveld 408576698