Browse Source

Support removing extra parameters

Kevin Sawicki 8 years ago
parent
commit
3b7207da9f

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

@@ -31,14 +31,21 @@ struct Converter<CrashReporter::UploadReportResult> {
 
 namespace {
 
+void SetExtraParameter(const std::string& key, mate::Arguments* args) {
+  std::string value;
+  if (args->GetNext(&value))
+    CrashReporter::GetInstance()->SetExtraParameter(key, value);
+  else
+    CrashReporter::GetInstance()->RemoveExtraParameter(key);
+}
+
 
 void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
                 v8::Local<v8::Context> context, void* priv) {
   mate::Dictionary dict(context->GetIsolate(), exports);
   auto reporter = base::Unretained(CrashReporter::GetInstance());
   dict.SetMethod("start", base::Bind(&CrashReporter::Start, reporter));
-  dict.SetMethod("setExtraParameter",
-                 base::Bind(&CrashReporter::SetExtraParameter, reporter));
+  dict.SetMethod("setExtraParameter", &SetExtraParameter);
   dict.SetMethod("getUploadedReports",
                  base::Bind(&CrashReporter::GetUploadedReports, reporter));
   dict.SetMethod("setUploadToServer",

+ 3 - 0
atom/common/crash_reporter/crash_reporter.cc

@@ -90,6 +90,9 @@ void CrashReporter::SetExtraParameter(const std::string& key,
                                       const std::string& value) {
 }
 
+void CrashReporter::RemoveExtraParameter(const std::string& key) {
+}
+
 #if defined(OS_MACOSX) && defined(MAS_BUILD)
 // static
 CrashReporter* CrashReporter::GetInstance() {

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

@@ -39,6 +39,7 @@ class CrashReporter {
   virtual bool GetUploadToServer();
   virtual void SetExtraParameter(const std::string& key,
                                  const std::string& value);
+  virtual void RemoveExtraParameter(const std::string& key);
 
  protected:
   CrashReporter();

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

@@ -36,6 +36,7 @@ class CrashReporterMac : public CrashReporter {
   bool GetUploadToServer() override;
   void SetExtraParameter(const std::string& key,
                          const std::string& value) override;
+  void RemoveExtraParameter(const std::string& key) override;
 
  private:
   friend struct base::DefaultSingletonTraits<CrashReporterMac>;

+ 7 - 0
atom/common/crash_reporter/crash_reporter_mac.mm

@@ -108,6 +108,13 @@ void CrashReporterMac::SetExtraParameter(const std::string& key,
     upload_parameters_[key] = value;
 }
 
+void CrashReporterMac::RemoveExtraParameter(const std::string& key) {
+  if (simple_string_dictionary_)
+    simple_string_dictionary_->RemoveKey(key.data());
+  else
+    upload_parameters_.erase(key);
+}
+
 std::vector<CrashReporter::UploadReportResult>
 CrashReporterMac::GetUploadedReports(const base::FilePath& crashes_dir) {
   std::vector<CrashReporter::UploadReportResult> uploaded_reports;

+ 2 - 1
docs/api/crash-reporter.md

@@ -118,7 +118,8 @@ called before `start` is called.
 ### `crashReporter.setExtraParameter(key, value)` _macOS_
 
 * `key` String - Parameter key.
-* `value` String - Parameter value.
+* `value` String - Parameter value. Specifying `null` or `undefined` will
+  remove the key from the extra parameters.
 
 Set an extra data to set be sent with the crash report. The values specified
 here will be sent in addition to any values set via the `extra` option to