Browse Source

add new method and mark setExtraParameter for deprecation

Shelley Vohr 7 years ago
parent
commit
3af83f1c97

+ 12 - 2
atom/common/api/atom_api_crash_reporter.cc

@@ -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",

+ 1 - 1
atom/common/crash_reporter/crash_reporter.cc

@@ -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) {
 }
 

+ 1 - 1
atom/common/crash_reporter/crash_reporter.h

@@ -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;

+ 1 - 1
atom/common/crash_reporter/crash_reporter_mac.h

@@ -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;

+ 1 - 1
atom/common/crash_reporter/crash_reporter_mac.mm

@@ -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);

+ 12 - 5
docs/api/crash-reporter.md

@@ -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_
 

+ 9 - 4
lib/common/api/crash-reporter.js

@@ -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()
   }

+ 34 - 9
spec/api-crash-reporter-spec.js

@@ -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,37 @@ describe('crashReporter module', () => {
       })
 
       crashReporter.setExtraParameter('hello', 'world')
-      const updatedParams = crashReporter.getParameters()
+      assert('hello' in crashReporter.getParameters())
+    })
+    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
+
+      crashReporter.start({
+        companyName: 'Umbrella Corporation',
+        submitURL: 'http://127.0.0.1/crashes'
+      })
+
+      crashReporter.setExtraParameter('hello', 'world')
+      assert('hello' in crashReporter.getParameters())
 
-      assert('hello' in updatedParams)
+      crashReporter.setExtraParameter('hello')
+      assert(!('hello' in crashReporter.getParameters()))
     })
-    it('removes a parameter', () => {
+    it('removes a parameter with removeExtraParameter', () => {
       // only run on MacOS
       if (process.platform !== 'darwin') return
 
@@ -352,12 +379,10 @@ describe('crashReporter module', () => {
       })
 
       crashReporter.setExtraParameter('hello', 'world')
-      const originalParams = crashReporter.getParameters()
-      assert('hello' in originalParams)
+      assert('hello' in crashReporter.getParameters())
 
       crashReporter.removeExtraParameter('hello')
-      const updatedParams = crashReporter.getParameters()
-      assert(!('hello' in updatedParams))
+      assert(!('hello' in crashReporter.getParameters()))
     })
   })
 })