add new method and mark setExtraParameter for deprecation

This commit is contained in:
Shelley Vohr 2017-11-01 21:57:43 -04:00
parent 33092e6324
commit 3af83f1c97
No known key found for this signature in database
GPG key ID: F13993A75599653C
8 changed files with 72 additions and 25 deletions

View file

@ -31,8 +31,17 @@ struct Converter<CrashReporter::UploadReportResult> {
namespace {
void SetExtraParameter(const std::string& key, const std::string& value) {
CrashReporter::GetInstance()->SetExtraParameter(key, value);
// TODO(2.0) Deprecate
void SetExtraParameter(const std::string& key, mate::Arguments* args) {
std::string value;
if (args->GetNext(&value))
CrashReporter::GetInstance()->AddExtraParameter(key, value);
else
CrashReporter::GetInstance()->RemoveExtraParameter(key);
}
void AddExtraParameter(const std::string& key, const std::string& value) {
CrashReporter::GetInstance()->AddExtraParameter(key, value);
}
void RemoveExtraParameter(const std::string& key) {
@ -49,6 +58,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
auto reporter = base::Unretained(CrashReporter::GetInstance());
dict.SetMethod("start", base::Bind(&CrashReporter::Start, reporter));
dict.SetMethod("setExtraParameter", &SetExtraParameter);
dict.SetMethod("addExtraParameter", &AddExtraParameter);
dict.SetMethod("removeExtraParameter", &RemoveExtraParameter);
dict.SetMethod("getParameters", &GetParameters);
dict.SetMethod("getUploadedReports",

View file

@ -86,7 +86,7 @@ void CrashReporter::InitBreakpad(const std::string& product_name,
void CrashReporter::SetUploadParameters() {
}
void CrashReporter::SetExtraParameter(const std::string& key,
void CrashReporter::AddExtraParameter(const std::string& key,
const std::string& value) {
}

View file

@ -37,7 +37,7 @@ class CrashReporter {
virtual void SetUploadToServer(bool upload_to_server);
virtual bool GetUploadToServer();
virtual void SetExtraParameter(const std::string& key,
virtual void AddExtraParameter(const std::string& key,
const std::string& value);
virtual void RemoveExtraParameter(const std::string& key);
virtual std::map<std::string, std::string> GetParameters() const;

View file

@ -35,7 +35,7 @@ class CrashReporterMac : public CrashReporter {
void SetUploadParameters() override;
void SetUploadToServer(bool upload_to_server) override;
bool GetUploadToServer() override;
void SetExtraParameter(const std::string& key,
void AddExtraParameter(const std::string& key,
const std::string& value) override;
void RemoveExtraParameter(const std::string& key) override;
std::map<std::string, std::string> GetParameters() const override;

View file

@ -105,7 +105,7 @@ void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key,
simple_string_dictionary_->SetKeyValue(key.data(), value.data());
}
void CrashReporterMac::SetExtraParameter(const std::string& key,
void CrashReporterMac::AddExtraParameter(const std::string& key,
const std::string& value) {
if (simple_string_dictionary_) {
SetCrashKeyValue(key, value);

View file

@ -116,16 +116,23 @@ called before `start` is called.
**Note:** This API can only be called from the main process.
### `crashReporter.setExtraParameter(key, value)` _macOS_
### `crashReporter.addExtraParameter(key, value)` _macOS_
* `key` String - Parameter key, must be less than 64 characters long.
* `value` String - Parameter value, must be less than 64 characters long.
Set an extra parameter to be sent with the crash report. The values
specified here will be sent in addition to any values set via the `extra` option
when `start` was called. This API is only available on macOS, if you need to
add/update extra parameters on Linux and Windows after your first call to
`start` you can call `start` again with the updated `extra` options.
specified here will be sent in addition to any values set via the `extra` option when `start` was called. This API is only available on macOS, if you need to add/update extra parameters on Linux and Windows after your first call to `start` you can call `start` again with the updated `extra` options.
**Note:** This API will be deprecated in `2.0`
### `crashReporter.addExtraParameter(key, value)` _macOS_
* `key` String - Parameter key, must be less than 64 characters long.
* `value` String - Parameter value, must be less than 64 characters long.
Set an extra parameter to be sent with the crash report. The values
specified here will be sent in addition to any values set via the `extra` option when `start` was called. This API is only available on macOS, if you need to add/update extra parameters on Linux and Windows after your first call to `start` you can call `start` again with the updated `extra` options.
### `crashReporter.removeExtraParameter(key)` _macOS_

View file

@ -104,14 +104,19 @@ class CrashReporter {
}
}
removeExtraParameter (key) {
binding.removeExtraParameter(key)
}
// TODO(2.0) Deprecate
setExtraParameter (key, value) {
binding.setExtraParameter(key, value)
}
addExtraParameter (key, value) {
binding.addExtraParameter(key, value)
}
removeExtraParameter (key) {
binding.removeExtraParameter(key)
}
getParameters (key, value) {
return binding.getParameters()
}

View file

@ -11,7 +11,7 @@ const {closeWindow} = require('./window-helpers')
const {remote} = require('electron')
const {app, BrowserWindow, crashReporter} = remote.require('electron')
describe('crashReporter module', () => {
describe.only('crashReporter module', () => {
if (process.mas || process.env.DISABLE_CRASH_REPORTER_TESTS) return
let originalTempDirectory = null
@ -328,7 +328,8 @@ describe('crashReporter module', () => {
const parameters = crashReporter.getParameters()
assert(typeof parameters === 'object')
})
it('adds a parameter', () => {
// TODO(2.0) deprecate
it('adds a parameter with setExtraParameter', () => {
// only run on MacOS
if (process.platform !== 'darwin') return
@ -338,11 +339,22 @@ describe('crashReporter module', () => {
})
crashReporter.setExtraParameter('hello', 'world')
const updatedParams = crashReporter.getParameters()
assert('hello' in updatedParams)
assert('hello' in crashReporter.getParameters())
})
it('removes a parameter', () => {
it('adds a parameter with addExtraParameter', () => {
// only run on MacOS
if (process.platform !== 'darwin') return
crashReporter.start({
companyName: 'Umbrella Corporation',
submitURL: 'http://127.0.0.1/crashes'
})
crashReporter.addExtraParameter('hello', 'world')
assert('hello' in crashReporter.getParameters())
})
// TODO(2.0) deprecate
it('removes a parameter with setExtraParameter', () => {
// only run on MacOS
if (process.platform !== 'darwin') return
@ -352,12 +364,25 @@ describe('crashReporter module', () => {
})
crashReporter.setExtraParameter('hello', 'world')
const originalParams = crashReporter.getParameters()
assert('hello' in originalParams)
assert('hello' in crashReporter.getParameters())
crashReporter.setExtraParameter('hello')
assert(!('hello' in crashReporter.getParameters()))
})
it('removes a parameter with removeExtraParameter', () => {
// only run on MacOS
if (process.platform !== 'darwin') return
crashReporter.start({
companyName: 'Umbrella Corporation',
submitURL: 'http://127.0.0.1/crashes'
})
crashReporter.setExtraParameter('hello', 'world')
assert('hello' in crashReporter.getParameters())
crashReporter.removeExtraParameter('hello')
const updatedParams = crashReporter.getParameters()
assert(!('hello' in updatedParams))
assert(!('hello' in crashReporter.getParameters()))
})
})
})