From a0db48451041d771b54f7e9513c80ebfa85c0607 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 5 Oct 2016 15:23:51 -0700 Subject: [PATCH] Use app.getPath directly for temp path --- atom/common/crash_reporter/crash_reporter.cc | 34 +++++++--------------- atom/common/crash_reporter/crash_reporter.h | 10 ++++--- atom/common/crash_reporter/crash_reporter_linux.cc | 11 ++++--- atom/common/crash_reporter/crash_reporter_linux.h | 3 +- atom/common/crash_reporter/crash_reporter_mac.h | 3 +- atom/common/crash_reporter/crash_reporter_mac.mm | 15 ++++------ atom/common/crash_reporter/crash_reporter_win.cc | 7 ++--- lib/common/api/crash-reporter.js | 6 ++-- 8 files changed, 37 insertions(+), 52 deletions(-) diff --git a/atom/common/crash_reporter/crash_reporter.cc b/atom/common/crash_reporter/crash_reporter.cc index 7a962da..f7ddd76 100644 --- a/atom/common/crash_reporter/crash_reporter.cc +++ b/atom/common/crash_reporter/crash_reporter.cc @@ -8,7 +8,6 @@ #include "atom/common/atom_version.h" #include "base/command_line.h" #include "base/files/file_util.h" -#include "base/path_service.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "content/public/common/content_switches.h" @@ -26,29 +25,19 @@ CrashReporter::~CrashReporter() { void CrashReporter::Start(const std::string& product_name, const std::string& company_name, const std::string& submit_url, + const std::string& temp_path, bool auto_submit, bool skip_system_crash_handler, const StringMap& extra_parameters) { SetUploadParameters(extra_parameters); InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url, - auto_submit, skip_system_crash_handler); + temp_path, auto_submit, skip_system_crash_handler); } -bool CrashReporter::GetTempDirectory(base::FilePath* path) { - bool success = PathService::Get(base::DIR_TEMP, path); - if (!success) - LOG(ERROR) << "Cannot get temp directory"; - return success; -} - -bool CrashReporter::GetCrashesDirectory( - const std::string& product_name, base::FilePath* path) { - if (GetTempDirectory(path)) { - *path = path->Append(product_name + " Crashes"); - return true; - } - return false; +base::FilePath CrashReporter::GetCrashesDirectory( + const std::string& product_name, const std::string& temp_dir) { + return base::FilePath(temp_dir).Append(product_name + " Crashes"); } void CrashReporter::SetUploadParameters(const StringMap& parameters) { @@ -60,16 +49,14 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) { } std::vector -CrashReporter::GetUploadedReports(const std::string& product_name) { +CrashReporter::GetUploadedReports(const std::string& product_name, + const std::string& temp_path) { std::vector result; - base::FilePath crashes_dir; - if (!GetCrashesDirectory(product_name, &crashes_dir)) - return result; - + base::FilePath uploads_path = + GetCrashesDirectory(product_name, temp_path).Append("uploads.log"); std::string file_content; - if (base::ReadFileToString(crashes_dir.Append("uploads.log"), - &file_content)) { + if (base::ReadFileToString(uploads_path, &file_content)) { std::vector reports = base::SplitString( file_content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); for (const std::string& report : reports) { @@ -90,6 +77,7 @@ void CrashReporter::InitBreakpad(const std::string& product_name, const std::string& version, const std::string& company_name, const std::string& submit_url, + const std::string& temp_path, bool auto_submit, bool skip_system_crash_handler) { } diff --git a/atom/common/crash_reporter/crash_reporter.h b/atom/common/crash_reporter/crash_reporter.h index 5f59468..84208df 100644 --- a/atom/common/crash_reporter/crash_reporter.h +++ b/atom/common/crash_reporter/crash_reporter.h @@ -25,12 +25,14 @@ class CrashReporter { void Start(const std::string& product_name, const std::string& company_name, const std::string& submit_url, + const std::string& temp_path, bool auto_submit, bool skip_system_crash_handler, const StringMap& extra_parameters); virtual std::vector GetUploadedReports( - const std::string& product_name); + const std::string& product_name, + const std::string& temp_path); protected: CrashReporter(); @@ -40,13 +42,13 @@ class CrashReporter { const std::string& version, const std::string& company_name, const std::string& submit_url, + const std::string& temp_path, bool auto_submit, bool skip_system_crash_handler); virtual void SetUploadParameters(); - bool GetTempDirectory(base::FilePath* path); - bool GetCrashesDirectory(const std::string& product_name, - base::FilePath* path); + base::FilePath GetCrashesDirectory(const std::string& product_name, + const std::string& temp_dir); StringMap upload_parameters_; bool is_browser_; diff --git a/atom/common/crash_reporter/crash_reporter_linux.cc b/atom/common/crash_reporter/crash_reporter_linux.cc index e1d2389..e2f4c80 100644 --- a/atom/common/crash_reporter/crash_reporter_linux.cc +++ b/atom/common/crash_reporter/crash_reporter_linux.cc @@ -60,9 +60,10 @@ void CrashReporterLinux::InitBreakpad(const std::string& product_name, const std::string& version, const std::string& company_name, const std::string& submit_url, + const std::string& temp_dir, bool auto_submit, bool skip_system_crash_handler) { - EnableCrashDumping(product_name); + EnableCrashDumping(product_name, temp_dir); crash_keys_.SetKeyValue("prod", ATOM_PRODUCT_NAME); crash_keys_.SetKeyValue("ver", version.c_str()); @@ -77,11 +78,9 @@ void CrashReporterLinux::SetUploadParameters() { upload_parameters_["platform"] = "linux"; } -void CrashReporterLinux::EnableCrashDumping(const std::string& product_name) { - base::FilePath dumps_path; - if (!GetCrashesDirectory(product_name, &dumps_path)) - return; - +void CrashReporterLinux::EnableCrashDumping(const std::string& product_name, + const std::string& temp_dir) { + base::FilePath dumps_path = GetCrashesDirectory(product_name, temp_dir); base::CreateDirectory(dumps_path); std::string log_file = base::StringPrintf( diff --git a/atom/common/crash_reporter/crash_reporter_linux.h b/atom/common/crash_reporter/crash_reporter_linux.h index de5a50e..a8f1a68 100644 --- a/atom/common/crash_reporter/crash_reporter_linux.h +++ b/atom/common/crash_reporter/crash_reporter_linux.h @@ -41,7 +41,8 @@ class CrashReporterLinux : public CrashReporter { CrashReporterLinux(); virtual ~CrashReporterLinux(); - void EnableCrashDumping(const std::string& product_name); + void EnableCrashDumping(const std::string& product_name, + const std::string& temp_dir); static bool CrashDone(const google_breakpad::MinidumpDescriptor& minidump, void* context, diff --git a/atom/common/crash_reporter/crash_reporter_mac.h b/atom/common/crash_reporter/crash_reporter_mac.h index 8acf502..89fb235 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.h +++ b/atom/common/crash_reporter/crash_reporter_mac.h @@ -27,6 +27,7 @@ class CrashReporterMac : public CrashReporter { const std::string& version, const std::string& company_name, const std::string& submit_url, + const std::string& temp_path, bool auto_submit, bool skip_system_crash_handler) override; void SetUploadParameters() override; @@ -42,7 +43,7 @@ class CrashReporterMac : public CrashReporter { const base::StringPiece& value); std::vector GetUploadedReports( - const std::string& path) override; + const std::string& path, const std::string& temp_path) override; std::unique_ptr simple_string_dictionary_; diff --git a/atom/common/crash_reporter/crash_reporter_mac.mm b/atom/common/crash_reporter/crash_reporter_mac.mm index 99e8846..8c09e831 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.mm +++ b/atom/common/crash_reporter/crash_reporter_mac.mm @@ -31,6 +31,7 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name, const std::string& version, const std::string& company_name, const std::string& submit_url, + const std::string& temp_dir, bool auto_submit, bool skip_system_crash_handler) { // check whether crashpad has been initialized. @@ -38,10 +39,7 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name, if (simple_string_dictionary_) return; - base::FilePath database_path; - if (!GetCrashesDirectory(product_name, &database_path)) - return; - + base::FilePath database_path = GetCrashesDirectory(product_name, temp_dir); if (is_browser_) { @autoreleasepool { base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath(); @@ -95,15 +93,14 @@ void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key, } std::vector -CrashReporterMac::GetUploadedReports(const std::string& product_name) { +CrashReporterMac::GetUploadedReports(const std::string& product_name, + const std::string& temp_path) { std::vector uploaded_reports; - base::FilePath file_path; - if (!GetCrashesDirectory(product_name, &file_path) || - !base::PathExists(file_path)) { + base::FilePath file_path = GetCrashesDirectory(product_name, temp_path); + if (!base::PathExists(file_path)) { return uploaded_reports; } - // Load crashpad database. std::unique_ptr database = crashpad::CrashReportDatabase::Initialize(file_path); diff --git a/atom/common/crash_reporter/crash_reporter_win.cc b/atom/common/crash_reporter/crash_reporter_win.cc index 27af3e1..e2fe672 100644 --- a/atom/common/crash_reporter/crash_reporter_win.cc +++ b/atom/common/crash_reporter/crash_reporter_win.cc @@ -149,14 +149,11 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name, const std::string& version, const std::string& company_name, const std::string& submit_url, + const std::string& temp_path, bool auto_submit, bool skip_system_crash_handler) { skip_system_crash_handler_ = skip_system_crash_handler; - base::FilePath temp_dir; - if (!GetTempDirectory(&temp_dir)) - return; - base::string16 pipe_name = base::ReplaceStringPlaceholders( kPipeNameFormat, base::UTF8ToUTF16(product_name), NULL); base::string16 wait_name = base::ReplaceStringPlaceholders( @@ -175,7 +172,7 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name, breakpad_.reset(); breakpad_.reset(new google_breakpad::ExceptionHandler( - temp_dir.value(), + temp_path, FilterCallback, MinidumpCallback, this, diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index fd7e30b..ca3d33a 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -13,6 +13,7 @@ class CrashReporter { let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options const app = (process.type === 'browser' ? electron : electron.remote).app + this.tempDirectory = app.getPath('temp') if (this.productName == null) { this.productName = app.getName() } @@ -34,7 +35,6 @@ class CrashReporter { if (extra._version == null) { extra._version = app.getVersion() } - if (companyName == null) { throw new Error('companyName is a required option to crashReporter.start') } @@ -53,7 +53,7 @@ class CrashReporter { }) } - binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra) + binding.start(this.productName, companyName, submitURL, this.tempDirectory, autoSubmit, ignoreSystemCrashHandler, extra) } getLastCrashReport () { @@ -66,7 +66,7 @@ class CrashReporter { } getUploadedReports () { - return binding._getUploadedReports(this.productName) + return binding._getUploadedReports(this.productName, this.tempDirectory) } } -- 2.7.4