Add StartInstance helper on CrashReporter
authorKevin Sawicki <kevinsawicki@gmail.com>
Tue, 24 Jan 2017 21:53:05 +0000 (13:53 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Tue, 24 Jan 2017 21:54:46 +0000 (13:54 -0800)
atom/app/node_main.cc
atom/common/api/atom_bindings.cc
atom/common/api/atom_bindings.h
atom/common/crash_reporter/crash_reporter.cc
atom/common/crash_reporter/crash_reporter.h

index 634342aad7e118c2b9ebae34e587063a28dc7e39..af33c05d631eac824d9b19f5b8881421bebf2006 100644 (file)
@@ -8,6 +8,7 @@
 #include "atom/browser/javascript_environment.h"
 #include "atom/browser/node_debugger.h"
 #include "atom/common/api/atom_bindings.h"
+#include "atom/common/crash_reporter/crash_reporter.h"
 #include "atom/common/native_mate_converters/string16_converter.h"
 #include "base/command_line.h"
 #include "base/feature_list.h"
@@ -61,9 +62,9 @@ int NodeMain(int argc, char *argv[]) {
 #endif
     process.SetMethod("crash", &AtomBindings::Crash);
 
-    mate::Dictionary crashReporter =
-        mate::Dictionary::CreateEmpty(gin_env.isolate());
-    crashReporter.SetMethod("start", &AtomBindings::StartCrashReporter);
+    auto crashReporter = mate::Dictionary::CreateEmpty(gin_env.isolate());
+    crashReporter.SetMethod("start",
+                            &crash_reporter::CrashReporter::StartInstance);
     process.Set("crashReporter", crashReporter);
 
     node::LoadEnvironment(env);
index adc8f061aef81720c21f49742cdcf801ddfb9986..2b4bec6328d99c2436597867720b41a70eaf6dd0 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "atom/common/atom_version.h"
 #include "atom/common/chrome_version.h"
-#include "atom/common/crash_reporter/crash_reporter.h"
 #include "atom/common/native_mate_converters/string16_converter.h"
 #include "atom/common/node_includes.h"
 #include "base/logging.h"
@@ -161,9 +160,4 @@ void AtomBindings::Crash() {
   static_cast<DummyClass*>(nullptr)->crash = true;
 }
 
-// static
-void AtomBindings::StartCrashReporter(const mate::Dictionary& options) {
-  crash_reporter::CrashReporter::GetInstance()->StartWithOptions(options);
-}
-
 }  // namespace atom
index be5352ef1bcfb7c87c3659f5ef30d0bbfc6415a7..58c2336c0e8bf9587a45cfdbd554e121e3baf0a8 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "base/macros.h"
 #include "base/strings/string16.h"
-#include "native_mate/dictionary.h"
 #include "v8/include/v8.h"
 #include "vendor/node/deps/uv/include/uv.h"
 
@@ -30,7 +29,6 @@ class AtomBindings {
 
   static void Log(const base::string16& message);
   static void Crash();
-  static void StartCrashReporter(const mate::Dictionary& options);
 
  private:
   void ActivateUVLoop(v8::Isolate* isolate);
index 28184445fd81ed05e237e0319535954ca9e43e09..a36e5525b665fb5ed7c7b0b6b932bd607595f9a3 100644 (file)
@@ -23,25 +23,6 @@ CrashReporter::CrashReporter() {
 CrashReporter::~CrashReporter() {
 }
 
-void CrashReporter::StartWithOptions(const mate::Dictionary& options) {
-  std::string product_name;
-  options.Get("productName", &product_name);
-  std::string company_name;
-  options.Get("companyName", &company_name);
-  std::string submit_url;
-  options.Get("submitURL", &submit_url);
-  base::FilePath crashes_dir;
-  options.Get("crashesDirectory", &crashes_dir);
-  StringMap extra_parameters;
-  options.Get("extra", &extra_parameters);
-
-  extra_parameters["_productName"] = product_name;
-  extra_parameters["_companyName"] = company_name;
-
-  Start(product_name, company_name, submit_url, crashes_dir, true, false,
-        extra_parameters);
-}
-
 void CrashReporter::Start(const std::string& product_name,
                           const std::string& company_name,
                           const std::string& submit_url,
@@ -113,4 +94,27 @@ CrashReporter* CrashReporter::GetInstance() {
 }
 #endif
 
+void CrashReporter::StartInstance(const mate::Dictionary& options) {
+  auto reporter = GetInstance();
+  if (!reporter) return;
+
+  std::string product_name;
+  options.Get("productName", &product_name);
+  std::string company_name;
+  options.Get("companyName", &company_name);
+  std::string submit_url;
+  options.Get("submitURL", &submit_url);
+  base::FilePath crashes_dir;
+  options.Get("crashesDirectory", &crashes_dir);
+  StringMap extra_parameters;
+  options.Get("extra", &extra_parameters);
+
+  extra_parameters["_productName"] = product_name;
+  extra_parameters["_companyName"] = company_name;
+
+  reporter->Start(product_name, company_name, submit_url, crashes_dir, true,
+                  false, extra_parameters);
+}
+
+
 }  // namespace crash_reporter
index c04b5d7ba25d9b456c9dd4ec0d1f331e724569d2..df05574fcb44bb9961edde429f7142b9e71a9bce 100644 (file)
@@ -22,6 +22,7 @@ class CrashReporter {
   typedef std::pair<int, std::string> UploadReportResult;  // upload-date, id
 
   static CrashReporter* GetInstance();
+  static void StartInstance(const mate::Dictionary& options);
 
   void Start(const std::string& product_name,
              const std::string& company_name,
@@ -30,8 +31,6 @@ class CrashReporter {
              bool upload_to_server,
              bool skip_system_crash_handler,
              const StringMap& extra_parameters);
-  void StartWithOptions(const mate::Dictionary& options);
-
   virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports(
       const base::FilePath& crashes_dir);