diff --git a/atom/common/api/atom_api_crash_reporter.cc b/atom/common/api/atom_api_crash_reporter.cc index 24eb6920016f..fb9ad3bb54c5 100644 --- a/atom/common/api/atom_api_crash_reporter.cc +++ b/atom/common/api/atom_api_crash_reporter.cc @@ -42,6 +42,8 @@ void Initialize(v8::Local exports, v8::Local unused, base::Bind(&CrashReporter::GetUploadedReports, report)); dict.SetMethod("_setShouldUpload", base::Bind(&CrashReporter::SetShouldUpload, report)); + dict.SetMethod("_getShouldUpload", + base::Bind(&CrashReporter::GetShouldUpload, report)); } } // namespace diff --git a/atom/common/crash_reporter/crash_reporter.cc b/atom/common/crash_reporter/crash_reporter.cc index a672df65ac21..dc76adf6b72d 100644 --- a/atom/common/crash_reporter/crash_reporter.cc +++ b/atom/common/crash_reporter/crash_reporter.cc @@ -47,6 +47,10 @@ void CrashReporter::SetShouldUpload(const bool should_upload) { } +bool CrashReporter::GetShouldUpload() { + return true; +} + std::vector CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) { std::string file_content; diff --git a/atom/common/crash_reporter/crash_reporter.h b/atom/common/crash_reporter/crash_reporter.h index caf445562822..fe7d109460b1 100644 --- a/atom/common/crash_reporter/crash_reporter.h +++ b/atom/common/crash_reporter/crash_reporter.h @@ -34,6 +34,7 @@ class CrashReporter { const base::FilePath& crashes_dir); virtual void SetShouldUpload(bool should_upload); + virtual bool GetShouldUpload(); protected: CrashReporter(); diff --git a/atom/common/crash_reporter/crash_reporter_mac.h b/atom/common/crash_reporter/crash_reporter_mac.h index 2e3c43639f75..d9b0ca734473 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.h +++ b/atom/common/crash_reporter/crash_reporter_mac.h @@ -33,6 +33,7 @@ class CrashReporterMac : public CrashReporter { bool skip_system_crash_handler) override; void SetUploadParameters() override; void SetShouldUpload(bool should_upload) override; + bool GetShouldUpload() override; private: friend struct base::DefaultSingletonTraits; diff --git a/atom/common/crash_reporter/crash_reporter_mac.mm b/atom/common/crash_reporter/crash_reporter_mac.mm index fa01c8d0dcb6..9c649a21a14c 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.mm +++ b/atom/common/crash_reporter/crash_reporter_mac.mm @@ -75,12 +75,18 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name, if (is_browser_) { database_ = crashpad::CrashReportDatabase::Initialize(crashes_dir); - if (database_) { - database_->GetSettings()->SetUploadsEnabled(should_upload); - } + SetShouldUpload(should_upload); } } +bool CrashReporterMac::GetShouldUpload() { + bool enabled = true; + if (database_) { + database_->GetSettings()->GetUploadsEnabled(&enabled); + } + return enabled; +} + void CrashReporterMac::SetShouldUpload(const bool should_upload) { if (database_) { database_->GetSettings()->SetUploadsEnabled(should_upload); diff --git a/docs/api/crash-reporter.md b/docs/api/crash-reporter.md index 89f7e138e269..216a36a53b16 100644 --- a/docs/api/crash-reporter.md +++ b/docs/api/crash-reporter.md @@ -75,12 +75,16 @@ ID. Returns `Boolean` - Whether reports should be submitted to the server. Set through the `start` method or `setShouldUpload`. +**NOTE:** This API can only be used from the main process + ### `crashReporter.setShouldUpload(shouldUpload)` _macOS_ * `shouldUpload` Boolean _macOS_ - Whether reports should be submitted to the server This would normally be controlled by user preferences. +**NOTE:** This API can only be used from the main process + ## Crash Report Payload The crash reporter will send the following data to the `submitURL` as diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index e17670321b71..7a8648aa4417 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -62,7 +62,6 @@ class CrashReporter { }) } - this._shouldUpload = shouldUpload binding.start(this.getProductName(), companyName, submitURL, this.getCrashesDirectory(), shouldUpload, ignoreSystemCrashHandler, extra) } @@ -104,12 +103,19 @@ class CrashReporter { } getShouldUpload() { - return this._shouldUpload + if (process.type === 'browser') { + return binding._getShouldUpload() + } else { + throw new Error('getShouldUpload can only be called from the main process') + } } setShouldUpload(shouldUpload) { - this._shouldUpload = shouldUpload - return binding._setShouldUpload(shouldUpload) + if (process.type === 'browser') { + return binding._setShouldUpload(shouldUpload) + } else { + throw new Error('setShouldUpload can only be called from the main process') + } } }