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

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: merge 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
« no previous file with comments | « base/files/important_file_writer.h ('k') | chrome/browser/rlz/rlz.h » ('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 536b0fb161b93cadd3a38a355bf2e071b9c1f59d..351adc242098637514328ee7e6897a4db321fcba 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::WriteFileAtomically(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,17 @@ 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::WriteFileAtomically),
+ 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);
+ WriteFileAtomically(path_, data);
}
}
« no previous file with comments | « base/files/important_file_writer.h ('k') | chrome/browser/rlz/rlz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698