Merge pull request #7901 from electron/rename-auto-upload

Rename autoUpload to uploadToServer
This commit is contained in:
Kevin Sawicki 2016-11-28 15:34:07 -08:00 committed by GitHub
commit 594aaec7bb
13 changed files with 125 additions and 20 deletions

View file

@ -40,6 +40,10 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
base::Bind(&CrashReporter::Start, report)); base::Bind(&CrashReporter::Start, report));
dict.SetMethod("_getUploadedReports", dict.SetMethod("_getUploadedReports",
base::Bind(&CrashReporter::GetUploadedReports, report)); base::Bind(&CrashReporter::GetUploadedReports, report));
dict.SetMethod("_setUploadToServer",
base::Bind(&CrashReporter::SetUploadToServer, report));
dict.SetMethod("_getUploadToServer",
base::Bind(&CrashReporter::GetUploadToServer, report));
} }
} // namespace } // namespace

View file

@ -26,13 +26,13 @@ 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 base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
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,
crashes_dir, auto_submit, skip_system_crash_handler); crashes_dir, upload_to_server, skip_system_crash_handler);
} }
void CrashReporter::SetUploadParameters(const StringMap& parameters) { void CrashReporter::SetUploadParameters(const StringMap& parameters) {
@ -43,6 +43,13 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) {
SetUploadParameters(); SetUploadParameters();
} }
void CrashReporter::SetUploadToServer(const bool upload_to_server) {
}
bool CrashReporter::GetUploadToServer() {
return true;
}
std::vector<CrashReporter::UploadReportResult> std::vector<CrashReporter::UploadReportResult>
CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) { CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) {
std::string file_content; std::string file_content;

View file

@ -26,13 +26,16 @@ class CrashReporter {
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
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 base::FilePath& crashes_dir); const base::FilePath& crashes_dir);
virtual void SetUploadToServer(bool upload_to_server);
virtual bool GetUploadToServer();
protected: protected:
CrashReporter(); CrashReporter();
virtual ~CrashReporter(); virtual ~CrashReporter();
@ -42,7 +45,7 @@ class CrashReporter {
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
bool skip_system_crash_handler); bool skip_system_crash_handler);
virtual void SetUploadParameters(); virtual void SetUploadParameters();

View file

@ -60,7 +60,7 @@ void CrashReporterLinux::InitBreakpad(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 base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
bool skip_system_crash_handler) { bool skip_system_crash_handler) {
EnableCrashDumping(crashes_dir); EnableCrashDumping(crashes_dir);

View file

@ -32,7 +32,7 @@ class CrashReporterLinux : public CrashReporter {
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
bool skip_system_crash_handler) override; bool skip_system_crash_handler) override;
void SetUploadParameters() override; void SetUploadParameters() override;

View file

@ -11,6 +11,7 @@
#include "atom/common/crash_reporter/crash_reporter.h" #include "atom/common/crash_reporter/crash_reporter.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "vendor/crashpad/client/crash_report_database.h"
#include "vendor/crashpad/client/simple_string_dictionary.h" #include "vendor/crashpad/client/simple_string_dictionary.h"
namespace base { namespace base {
@ -28,9 +29,11 @@ class CrashReporterMac : public CrashReporter {
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
bool skip_system_crash_handler) override; bool skip_system_crash_handler) override;
void SetUploadParameters() override; void SetUploadParameters() override;
void SetUploadToServer(bool upload_to_server) override;
bool GetUploadToServer() override;
private: private:
friend struct base::DefaultSingletonTraits<CrashReporterMac>; friend struct base::DefaultSingletonTraits<CrashReporterMac>;
@ -46,6 +49,7 @@ class CrashReporterMac : public CrashReporter {
const base::FilePath& crashes_dir) override; const base::FilePath& crashes_dir) override;
std::unique_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_; std::unique_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_;
std::unique_ptr<crashpad::CrashReportDatabase> database_;
DISALLOW_COPY_AND_ASSIGN(CrashReporterMac); DISALLOW_COPY_AND_ASSIGN(CrashReporterMac);
}; };

View file

@ -13,7 +13,6 @@
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "vendor/crashpad/client/crash_report_database.h"
#include "vendor/crashpad/client/crashpad_client.h" #include "vendor/crashpad/client/crashpad_client.h"
#include "vendor/crashpad/client/crashpad_info.h" #include "vendor/crashpad/client/crashpad_info.h"
#include "vendor/crashpad/client/settings.h" #include "vendor/crashpad/client/settings.h"
@ -31,7 +30,7 @@ void CrashReporterMac::InitBreakpad(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 base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
bool skip_system_crash_handler) { bool skip_system_crash_handler) {
// check whether crashpad has been initialized. // check whether crashpad has been initialized.
// Only need to initialize once. // Only need to initialize once.
@ -73,11 +72,23 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
SetCrashKeyValue(upload_parameter.first, upload_parameter.second); SetCrashKeyValue(upload_parameter.first, upload_parameter.second);
} }
if (is_browser_) { if (is_browser_) {
std::unique_ptr<crashpad::CrashReportDatabase> database = database_ =
crashpad::CrashReportDatabase::Initialize(crashes_dir); crashpad::CrashReportDatabase::Initialize(crashes_dir);
if (database) { SetUploadToServer(upload_to_server);
database->GetSettings()->SetUploadsEnabled(auto_submit); }
} }
bool CrashReporterMac::GetUploadToServer() {
bool enabled = true;
if (database_) {
database_->GetSettings()->GetUploadsEnabled(&enabled);
}
return enabled;
}
void CrashReporterMac::SetUploadToServer(const bool upload_to_server) {
if (database_) {
database_->GetSettings()->SetUploadsEnabled(upload_to_server);
} }
} }

View file

@ -150,7 +150,7 @@ void CrashReporterWin::InitBreakpad(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 base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
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;

View file

@ -28,7 +28,7 @@ class CrashReporterWin : public CrashReporter {
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool upload_to_server,
bool skip_system_crash_handler) override; bool skip_system_crash_handler) override;
void SetUploadParameters() override; void SetUploadParameters() override;

View file

@ -40,7 +40,7 @@ The `crashReporter` module has the following methods:
* `companyName` String (optional) * `companyName` String (optional)
* `submitURL` String - URL that crash reports will be sent to as POST. * `submitURL` String - URL that crash reports will be sent to as POST.
* `productName` String (optional) - Defaults to `app.getName()`. * `productName` String (optional) - Defaults to `app.getName()`.
* `autoSubmit` Boolean (optional) - Send the crash report without user interaction. * `uploadToServer` Boolean (optional) _macOS_ - Whether crash reports should be sent to the server
Default is `true`. Default is `true`.
* `ignoreSystemCrashHandler` Boolean (optional) - Default is `false`. * `ignoreSystemCrashHandler` Boolean (optional) - Default is `false`.
* `extra` Object (optional) - An object you can define that will be sent along with the * `extra` Object (optional) - An object you can define that will be sent along with the
@ -70,6 +70,22 @@ Returns [`CrashReport[]`](structures/crash-report.md):
Returns all uploaded crash reports. Each report contains the date and uploaded Returns all uploaded crash reports. Each report contains the date and uploaded
ID. ID.
### `crashReporter.getUploadToServer()` _macOS_
Returns `Boolean` - Whether reports should be submitted to the server. Set through
the `start` method or `setUploadToServer`.
**Note:** This API can only be called from the main process.
### `crashReporter.setUploadToServer(uploadToServer)` _macOS_
* `uploadToServer` Boolean _macOS_ - Whether reports should be submitted to the server
This would normally be controlled by user preferences. This has no effect if
called before `start` is called.
**Note:** This API can only be called from the main process.
## Crash Report Payload ## Crash Report Payload
The crash reporter will send the following data to the `submitURL` as The crash reporter will send the following data to the `submitURL` as

View file

@ -40,6 +40,23 @@ clipboard.writeHtml()
clipboard.writeHTML() clipboard.writeHTML()
``` ```
## `crashReporter`
```js
// Deprecated
crashReporter.start({
companyName: 'Crashly',
submitURL: 'https://crash.server.com',
autoSubmit: true
})
// Replace with
crashReporter.start({
companyName: 'Crashly',
submitURL: 'https://crash.server.com',
uploadToServer: true
})
```
## `nativeImage` ## `nativeImage`
```js ```js

View file

@ -13,11 +13,17 @@ class CrashReporter {
options = {} options = {}
} }
this.productName = options.productName != null ? options.productName : app.getName() this.productName = options.productName != null ? options.productName : app.getName()
let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options let {companyName, extra, ignoreSystemCrashHandler, submitURL, uploadToServer} = options
if (autoSubmit == null) { if (uploadToServer == null) {
autoSubmit = true // TODO: Remove deprecated autoSubmit property in 2.0
uploadToServer = options.autoSubmit
} }
if (uploadToServer == null) {
uploadToServer = true
}
if (ignoreSystemCrashHandler == null) { if (ignoreSystemCrashHandler == null) {
ignoreSystemCrashHandler = false ignoreSystemCrashHandler = false
} }
@ -56,7 +62,7 @@ class CrashReporter {
}) })
} }
binding.start(this.getProductName(), companyName, submitURL, this.getCrashesDirectory(), autoSubmit, ignoreSystemCrashHandler, extra) binding.start(this.getProductName(), companyName, submitURL, this.getCrashesDirectory(), uploadToServer, ignoreSystemCrashHandler, extra)
} }
getLastCrashReport () { getLastCrashReport () {
@ -95,6 +101,22 @@ class CrashReporter {
} }
return this.tempDirectory return this.tempDirectory
} }
getUploadToServer () {
if (process.type === 'browser') {
return binding._getUploadToServer()
} else {
throw new Error('getUploadToServer can only be called from the main process')
}
}
setUploadToServer (uploadToServer) {
if (process.type === 'browser') {
return binding._setUploadToServer(uploadToServer)
} else {
throw new Error('setUploadToServer can only be called from the main process')
}
}
} }
module.exports = new CrashReporter() module.exports = new CrashReporter()

View file

@ -117,6 +117,27 @@ describe('crashReporter module', function () {
}) })
}) })
}) })
describe('.get/setUploadToServer', function () {
it('throws an error when called from the renderer process', function () {
assert.throws(() => require('electron').crashReporter.getUploadToServer())
})
it('can be read/set from the main process', function () {
if (process.platform === 'darwin') {
crashReporter.start({
companyName: 'Umbrella Corporation',
submitURL: 'http://127.0.0.1/crashes',
autoSubmit: true
})
assert.equal(crashReporter.getUploadToServer(), true)
crashReporter.setUploadToServer(false)
assert.equal(crashReporter.getUploadToServer(), false)
} else {
assert.equal(crashReporter.getUploadToServer(), true)
}
})
})
}) })
const waitForCrashReport = () => { const waitForCrashReport = () => {