Support removing extra parameters
authorKevin Sawicki <kevinsawicki@gmail.com>
Thu, 9 Feb 2017 21:05:23 +0000 (13:05 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Tue, 14 Feb 2017 17:37:09 +0000 (09:37 -0800)
atom/common/api/atom_api_crash_reporter.cc
atom/common/crash_reporter/crash_reporter.cc
atom/common/crash_reporter/crash_reporter.h
atom/common/crash_reporter/crash_reporter_mac.h
atom/common/crash_reporter/crash_reporter_mac.mm
docs/api/crash-reporter.md

index 6820e7a7929d65d380c1243ff61d015d0062ce63..0edd787e558cc2c1f5b96a86f2f7578b1758781d 100644 (file)
@@ -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",
index bc3176275fe8536b60280d8b6136f8d00f95a7c3..d901f83fa49fb2306604a70cf9856367e44c3db9 100644 (file)
@@ -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() {
index cd93f171c05b638c1acd1a6d182fcbb0a640dc73..2bdcd9b02d3b8ba6386ef015ed840f39d163dfdd 100644 (file)
@@ -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();
index 8d1b1d0de1c36bdaea81ac6a151d74fe4030c968..583c99a86e9c9cb7a4481802998413f6f7eb83a5 100644 (file)
@@ -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>;
index 0e9b20d6f6636fed4e232164abacab33ab07c31d..4b59be5dfca84c4f79226b99c115f22a876f7317 100644 (file)
@@ -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;
index 096276a3ffa609986ced36d2ecb424fbaa948000..f4ed2d2ce0fa279adef7e5cc4845daf04f77e483 100644 (file)
@@ -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