From e3a56240c956023ea0ee709146901e279c2a586b Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 18 Dec 2017 16:18:49 +0530 Subject: [PATCH] REVIEW: fix base::File helper usage on incorrect task sequence --- atom/common/crash_reporter/crash_reporter.cc | 2 ++ .../crash_reporter/crash_reporter_linux.cc | 26 ++++++++++++++++++- .../crash_reporter/crash_reporter_linux.h | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/atom/common/crash_reporter/crash_reporter.cc b/atom/common/crash_reporter/crash_reporter.cc index 88930f0d3ce5..97476623e88f 100644 --- a/atom/common/crash_reporter/crash_reporter.cc +++ b/atom/common/crash_reporter/crash_reporter.cc @@ -11,6 +11,7 @@ #include "base/files/file_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" +#include "base/threading/thread_restrictions.h" #include "content/public/common/content_switches.h" namespace crash_reporter { @@ -53,6 +54,7 @@ bool CrashReporter::GetUploadToServer() { std::vector CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) { + base::ThreadRestrictions::ScopedAllowIO allow_io; std::string file_content; std::vector result; base::FilePath uploads_path = diff --git a/atom/common/crash_reporter/crash_reporter_linux.cc b/atom/common/crash_reporter/crash_reporter_linux.cc index d14c15de195f..db6dd663b09e 100644 --- a/atom/common/crash_reporter/crash_reporter_linux.cc +++ b/atom/common/crash_reporter/crash_reporter_linux.cc @@ -17,6 +17,7 @@ #include "base/logging.h" #include "base/memory/singleton.h" #include "base/process/memory.h" +#include "base/task_scheduler/post_task.h" #include "vendor/breakpad/src/client/linux/handler/exception_handler.h" #include "vendor/breakpad/src/common/linux/linux_libc_support.h" @@ -34,6 +35,18 @@ static const size_t kDistroSize = 128; // no limit. static const off_t kMaxMinidumpFileSize = 1258291; +bool CreateCrashDataDirectory(const base::FilePath& crashes_dir) { + // Make sure the crash log directory is created. + bool success = base::CreateDirectoryAndGetError(crashes_dir, nullptr); + + if (!success) { + NOTREACHED() << "Failed to create directory '" << crashes_dir.value() + << "'"; + } + + return success; +} + } // namespace CrashReporterLinux::CrashReporterLinux() @@ -90,7 +103,18 @@ bool CrashReporterLinux::GetUploadToServer() { } void CrashReporterLinux::EnableCrashDumping(const base::FilePath& crashes_dir) { - base::CreateDirectory(crashes_dir); + base::PostTaskWithTraitsAndReplyWithResult( + FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, + base::Bind(&CreateCrashDataDirectory, crashes_dir), + base::Bind(&CrashReporterLinux::OnCrashDataDirectoryCreated, + base::Unretained(this), crashes_dir)); +} + +void CrashReporterLinux::OnCrashDataDirectoryCreated( + const base::FilePath& crashes_dir, + bool success) { + if (!success) + return; std::string log_file = crashes_dir.Append("uploads.log").value(); strncpy(g_crash_log_path, log_file.c_str(), sizeof(g_crash_log_path)); diff --git a/atom/common/crash_reporter/crash_reporter_linux.h b/atom/common/crash_reporter/crash_reporter_linux.h index 75a57ec1c172..880e3203baad 100644 --- a/atom/common/crash_reporter/crash_reporter_linux.h +++ b/atom/common/crash_reporter/crash_reporter_linux.h @@ -45,6 +45,8 @@ class CrashReporterLinux : public CrashReporter { virtual ~CrashReporterLinux(); void EnableCrashDumping(const base::FilePath& crashes_dir); + void OnCrashDataDirectoryCreated(const base::FilePath& crashes_dir, + bool success); static bool CrashDone(const google_breakpad::MinidumpDescriptor& minidump, void* context,