Commit 342698dc authored by Andreas Butler's avatar Andreas Butler Committed by Commit Bot

[IndexedDB]: Modify RecordCorruptionInfo to use ImportantFileWriter

As per crbug640232, RecordCorruptionInfo's method of writing a
corruption report to a file is modified from making a file and then
writing to it to writing it atomically using ImportantFileWriter's
WriteFileAtomically method to avoid issues involving interruption of
the file write between file creation and actual writing of the record.

Bug: 640232
Change-Id: I69aad54da0c341528dbcf46ebf5a2b08cc3270f6
Reviewed-on: https://chromium-review.googlesource.com/c/1419261Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Commit-Queue: Andreas Butler <andreasbutler@google.com>
Cr-Commit-Position: refs/heads/master@{#625431}
parent 52e5e82f
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/important_file_writer.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
...@@ -55,6 +56,7 @@ ...@@ -55,6 +56,7 @@
#include "third_party/leveldatabase/env_chromium.h" #include "third_party/leveldatabase/env_chromium.h"
using base::FilePath; using base::FilePath;
using base::ImportantFileWriter;
using base::StringPiece; using base::StringPiece;
using blink::IndexedDBDatabaseMetadata; using blink::IndexedDBDatabaseMetadata;
using blink::IndexedDBKey; using blink::IndexedDBKey;
...@@ -852,13 +854,8 @@ bool IndexedDBBackingStore::RecordCorruptionInfo(const FilePath& path_base, ...@@ -852,13 +854,8 @@ bool IndexedDBBackingStore::RecordCorruptionInfo(const FilePath& path_base,
root_dict.SetString("message", message); root_dict.SetString("message", message);
std::string output_js; std::string output_js;
base::JSONWriter::Write(root_dict, &output_js); base::JSONWriter::Write(root_dict, &output_js);
return base::ImportantFileWriter::WriteFileAtomically(info_path,
base::File file(info_path, output_js.c_str());
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
if (!file.IsValid())
return false;
int written = file.Write(0, output_js.c_str(), output_js.length());
return size_t(written) == output_js.length();
} }
void IndexedDBBackingStore::GrantChildProcessPermissions(int child_process_id) { void IndexedDBBackingStore::GrantChildProcessPermissions(int child_process_id) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment