Use app.getPath directly for temp path

This commit is contained in:
Kevin Sawicki 2016-10-05 15:23:51 -07:00
parent b3b856f476
commit a0db484510
8 changed files with 37 additions and 52 deletions

View file

@ -8,7 +8,6 @@
#include "atom/common/atom_version.h" #include "atom/common/atom_version.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
@ -26,29 +25,19 @@ CrashReporter::~CrashReporter() {
void CrashReporter::Start(const std::string& product_name, void CrashReporter::Start(const std::string& product_name,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const std::string& temp_path,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler, bool skip_system_crash_handler,
const StringMap& extra_parameters) { const StringMap& extra_parameters) {
SetUploadParameters(extra_parameters); SetUploadParameters(extra_parameters);
InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url, 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) { base::FilePath CrashReporter::GetCrashesDirectory(
bool success = PathService::Get(base::DIR_TEMP, path); const std::string& product_name, const std::string& temp_dir) {
if (!success) return base::FilePath(temp_dir).Append(product_name + " Crashes");
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;
} }
void CrashReporter::SetUploadParameters(const StringMap& parameters) { void CrashReporter::SetUploadParameters(const StringMap& parameters) {
@ -60,16 +49,14 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) {
} }
std::vector<CrashReporter::UploadReportResult> std::vector<CrashReporter::UploadReportResult>
CrashReporter::GetUploadedReports(const std::string& product_name) { CrashReporter::GetUploadedReports(const std::string& product_name,
const std::string& temp_path) {
std::vector<CrashReporter::UploadReportResult> result; std::vector<CrashReporter::UploadReportResult> result;
base::FilePath crashes_dir; base::FilePath uploads_path =
if (!GetCrashesDirectory(product_name, &crashes_dir)) GetCrashesDirectory(product_name, temp_path).Append("uploads.log");
return result;
std::string file_content; std::string file_content;
if (base::ReadFileToString(crashes_dir.Append("uploads.log"), if (base::ReadFileToString(uploads_path, &file_content)) {
&file_content)) {
std::vector<std::string> reports = base::SplitString( std::vector<std::string> reports = base::SplitString(
file_content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); file_content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
for (const std::string& report : reports) { 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& version,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const std::string& temp_path,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler) { bool skip_system_crash_handler) {
} }

View file

@ -25,12 +25,14 @@ class CrashReporter {
void Start(const std::string& product_name, void Start(const std::string& product_name,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const std::string& temp_path,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler, bool skip_system_crash_handler,
const StringMap& extra_parameters); const StringMap& extra_parameters);
virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports( virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports(
const std::string& product_name); const std::string& product_name,
const std::string& temp_path);
protected: protected:
CrashReporter(); CrashReporter();
@ -40,13 +42,13 @@ class CrashReporter {
const std::string& version, const std::string& version,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const std::string& temp_path,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler); bool skip_system_crash_handler);
virtual void SetUploadParameters(); virtual void SetUploadParameters();
bool GetTempDirectory(base::FilePath* path); base::FilePath GetCrashesDirectory(const std::string& product_name,
bool GetCrashesDirectory(const std::string& product_name, const std::string& temp_dir);
base::FilePath* path);
StringMap upload_parameters_; StringMap upload_parameters_;
bool is_browser_; bool is_browser_;

View file

@ -60,9 +60,10 @@ void CrashReporterLinux::InitBreakpad(const std::string& product_name,
const std::string& version, const std::string& version,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const std::string& temp_dir,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler) { bool skip_system_crash_handler) {
EnableCrashDumping(product_name); EnableCrashDumping(product_name, temp_dir);
crash_keys_.SetKeyValue("prod", ATOM_PRODUCT_NAME); crash_keys_.SetKeyValue("prod", ATOM_PRODUCT_NAME);
crash_keys_.SetKeyValue("ver", version.c_str()); crash_keys_.SetKeyValue("ver", version.c_str());
@ -77,11 +78,9 @@ void CrashReporterLinux::SetUploadParameters() {
upload_parameters_["platform"] = "linux"; upload_parameters_["platform"] = "linux";
} }
void CrashReporterLinux::EnableCrashDumping(const std::string& product_name) { void CrashReporterLinux::EnableCrashDumping(const std::string& product_name,
base::FilePath dumps_path; const std::string& temp_dir) {
if (!GetCrashesDirectory(product_name, &dumps_path)) base::FilePath dumps_path = GetCrashesDirectory(product_name, temp_dir);
return;
base::CreateDirectory(dumps_path); base::CreateDirectory(dumps_path);
std::string log_file = base::StringPrintf( std::string log_file = base::StringPrintf(

View file

@ -41,7 +41,8 @@ class CrashReporterLinux : public CrashReporter {
CrashReporterLinux(); CrashReporterLinux();
virtual ~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, static bool CrashDone(const google_breakpad::MinidumpDescriptor& minidump,
void* context, void* context,

View file

@ -27,6 +27,7 @@ class CrashReporterMac : public CrashReporter {
const std::string& version, const std::string& version,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const std::string& temp_path,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler) override; bool skip_system_crash_handler) override;
void SetUploadParameters() override; void SetUploadParameters() override;
@ -42,7 +43,7 @@ class CrashReporterMac : public CrashReporter {
const base::StringPiece& value); const base::StringPiece& value);
std::vector<UploadReportResult> GetUploadedReports( std::vector<UploadReportResult> GetUploadedReports(
const std::string& path) override; const std::string& path, const std::string& temp_path) override;
std::unique_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_; std::unique_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_;

View file

@ -31,6 +31,7 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
const std::string& version, const std::string& version,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const std::string& temp_dir,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler) { bool skip_system_crash_handler) {
// check whether crashpad has been initialized. // check whether crashpad has been initialized.
@ -38,10 +39,7 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
if (simple_string_dictionary_) if (simple_string_dictionary_)
return; return;
base::FilePath database_path; base::FilePath database_path = GetCrashesDirectory(product_name, temp_dir);
if (!GetCrashesDirectory(product_name, &database_path))
return;
if (is_browser_) { if (is_browser_) {
@autoreleasepool { @autoreleasepool {
base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath(); base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath();
@ -95,15 +93,14 @@ void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key,
} }
std::vector<CrashReporter::UploadReportResult> std::vector<CrashReporter::UploadReportResult>
CrashReporterMac::GetUploadedReports(const std::string& product_name) { CrashReporterMac::GetUploadedReports(const std::string& product_name,
const std::string& temp_path) {
std::vector<CrashReporter::UploadReportResult> uploaded_reports; std::vector<CrashReporter::UploadReportResult> uploaded_reports;
base::FilePath file_path; base::FilePath file_path = GetCrashesDirectory(product_name, temp_path);
if (!GetCrashesDirectory(product_name, &file_path) || if (!base::PathExists(file_path)) {
!base::PathExists(file_path)) {
return uploaded_reports; return uploaded_reports;
} }
// Load crashpad database. // Load crashpad database.
std::unique_ptr<crashpad::CrashReportDatabase> database = std::unique_ptr<crashpad::CrashReportDatabase> database =
crashpad::CrashReportDatabase::Initialize(file_path); crashpad::CrashReportDatabase::Initialize(file_path);

View file

@ -149,14 +149,11 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
const std::string& version, const std::string& version,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const std::string& temp_path,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler) { bool skip_system_crash_handler) {
skip_system_crash_handler_ = 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( base::string16 pipe_name = base::ReplaceStringPlaceholders(
kPipeNameFormat, base::UTF8ToUTF16(product_name), NULL); kPipeNameFormat, base::UTF8ToUTF16(product_name), NULL);
base::string16 wait_name = base::ReplaceStringPlaceholders( base::string16 wait_name = base::ReplaceStringPlaceholders(
@ -175,7 +172,7 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
breakpad_.reset(); breakpad_.reset();
breakpad_.reset(new google_breakpad::ExceptionHandler( breakpad_.reset(new google_breakpad::ExceptionHandler(
temp_dir.value(), temp_path,
FilterCallback, FilterCallback,
MinidumpCallback, MinidumpCallback,
this, this,

View file

@ -13,6 +13,7 @@ class CrashReporter {
let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options
const app = (process.type === 'browser' ? electron : electron.remote).app const app = (process.type === 'browser' ? electron : electron.remote).app
this.tempDirectory = app.getPath('temp')
if (this.productName == null) { if (this.productName == null) {
this.productName = app.getName() this.productName = app.getName()
} }
@ -34,7 +35,6 @@ class CrashReporter {
if (extra._version == null) { if (extra._version == null) {
extra._version = app.getVersion() extra._version = app.getVersion()
} }
if (companyName == null) { if (companyName == null) {
throw new Error('companyName is a required option to crashReporter.start') 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 () { getLastCrashReport () {
@ -66,7 +66,7 @@ class CrashReporter {
} }
getUploadedReports () { getUploadedReports () {
return binding._getUploadedReports(this.productName) return binding._getUploadedReports(this.productName, this.tempDirectory)
} }
} }