Browse Source

Add StartInstance helper on CrashReporter

Kevin Sawicki 8 years ago
parent
commit
795b674996

+ 4 - 3
atom/app/node_main.cc

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

+ 0 - 6
atom/common/api/atom_bindings.cc

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

+ 0 - 2
atom/common/api/atom_bindings.h

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

+ 23 - 19
atom/common/crash_reporter/crash_reporter.cc

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

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

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