From 795b674996297c0f6c8a7daaf45cc783483efca7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 Jan 2017 13:53:05 -0800 Subject: [PATCH] Add StartInstance helper on CrashReporter --- atom/app/node_main.cc | 7 ++-- atom/common/api/atom_bindings.cc | 6 --- atom/common/api/atom_bindings.h | 2 - atom/common/crash_reporter/crash_reporter.cc | 42 +++++++++++--------- atom/common/crash_reporter/crash_reporter.h | 3 +- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index 634342aad7e1..af33c05d631e 100644 --- a/atom/app/node_main.cc +++ b/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); diff --git a/atom/common/api/atom_bindings.cc b/atom/common/api/atom_bindings.cc index adc8f061aef8..2b4bec6328d9 100644 --- a/atom/common/api/atom_bindings.cc +++ b/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(nullptr)->crash = true; } -// static -void AtomBindings::StartCrashReporter(const mate::Dictionary& options) { - crash_reporter::CrashReporter::GetInstance()->StartWithOptions(options); -} - } // namespace atom diff --git a/atom/common/api/atom_bindings.h b/atom/common/api/atom_bindings.h index be5352ef1bcf..58c2336c0e8b 100644 --- a/atom/common/api/atom_bindings.h +++ b/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); diff --git a/atom/common/crash_reporter/crash_reporter.cc b/atom/common/crash_reporter/crash_reporter.cc index 28184445fd81..a36e5525b665 100644 --- a/atom/common/crash_reporter/crash_reporter.cc +++ b/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 diff --git a/atom/common/crash_reporter/crash_reporter.h b/atom/common/crash_reporter/crash_reporter.h index c04b5d7ba25d..df05574fcb44 100644 --- a/atom/common/crash_reporter/crash_reporter.h +++ b/atom/common/crash_reporter/crash_reporter.h @@ -22,6 +22,7 @@ class CrashReporter { typedef std::pair 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 GetUploadedReports( const base::FilePath& crashes_dir);