From d181ff4e7f51f6783ac12e7e27b79529b88a7dce Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 18 Nov 2013 18:27:50 +0800 Subject: [PATCH] Enable customing upload parameters for sending crash report. --- common/api/atom_api_crash_reporter.cc | 5 +++-- common/api/lib/crash-reporter.coffee | 5 +++-- common/crash_reporter/crash_reporter.cc | 18 +++++++++--------- common/crash_reporter/crash_reporter.h | 10 +++++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/common/api/atom_api_crash_reporter.cc b/common/api/atom_api_crash_reporter.cc index 529ef6c..26b1c29 100644 --- a/common/api/atom_api_crash_reporter.cc +++ b/common/api/atom_api_crash_reporter.cc @@ -17,12 +17,13 @@ namespace api { v8::Handle CrashReporter::Start(const v8::Arguments& args) { std::string product_name, company_name, submit_url; bool auto_submit, skip_system; + std::map dict; if (!FromV8Arguments(args, &product_name, &company_name, &submit_url, - &auto_submit, &skip_system)) + &auto_submit, &skip_system, &dict)) return node::ThrowTypeError("Bad argument"); crash_reporter::CrashReporter::GetInstance()->Start( - product_name, company_name, submit_url, auto_submit, skip_system); + product_name, company_name, submit_url, auto_submit, skip_system, dict); return v8::Undefined(); } diff --git a/common/api/lib/crash-reporter.coffee b/common/api/lib/crash-reporter.coffee index cf19871..9a54510 100644 --- a/common/api/lib/crash-reporter.coffee +++ b/common/api/lib/crash-reporter.coffee @@ -2,14 +2,15 @@ binding = process.atomBinding 'crash_reporter' class CrashReporter start: (options={}) -> - {productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler} = options + {productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra} = options productName ?= 'Atom-Shell' companyName ?= 'GitHub, Inc' submitUrl ?= 'http://54.249.141.25' autoSubmit ?= true ignoreSystemCrashHandler ?= false + extra ?= {} - binding.start productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler + binding.start productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra module.exports = new CrashReporter diff --git a/common/crash_reporter/crash_reporter.cc b/common/crash_reporter/crash_reporter.cc index 66b3cc8..f52f335 100644 --- a/common/crash_reporter/crash_reporter.cc +++ b/common/crash_reporter/crash_reporter.cc @@ -12,9 +12,8 @@ namespace crash_reporter { CrashReporter::CrashReporter() { - SetUploadParameters(); - - is_browser_ = upload_parameters_["process_type"].empty(); + const CommandLine& command = *CommandLine::ForCurrentProcess(); + is_browser_ = command.GetSwitchValueASCII(switches::kProcessType).empty(); } CrashReporter::~CrashReporter() { @@ -24,18 +23,19 @@ void CrashReporter::Start(std::string product_name, const std::string& company_name, const std::string& submit_url, bool auto_submit, - bool skip_system_crash_handler) { + bool skip_system_crash_handler, + const StringMap& extra_parameters) { + SetUploadParameters(extra_parameters); + // Append "Renderer" for the renderer. product_name += " Renderer"; InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url, auto_submit, skip_system_crash_handler); } -void CrashReporter::SetUploadParameters() { - const CommandLine& command = *CommandLine::ForCurrentProcess(); - std::string type = command.GetSwitchValueASCII(switches::kProcessType); - - upload_parameters_["process_type"] = type; +void CrashReporter::SetUploadParameters(const StringMap& parameters) { + upload_parameters_ = parameters; + upload_parameters_["process_type"] = is_browser_ ? "browser" : "renderer"; } } // namespace crash_reporter diff --git a/common/crash_reporter/crash_reporter.h b/common/crash_reporter/crash_reporter.h index d9a57e7..3e61bcc 100644 --- a/common/crash_reporter/crash_reporter.h +++ b/common/crash_reporter/crash_reporter.h @@ -14,13 +14,16 @@ namespace crash_reporter { class CrashReporter { public: + typedef std::map StringMap; + static CrashReporter* GetInstance(); void Start(std::string product_name, const std::string& company_name, const std::string& submit_url, bool auto_submit, - bool skip_system_crash_handler); + bool skip_system_crash_handler, + const StringMap& extra_parameters); protected: CrashReporter(); @@ -32,13 +35,14 @@ class CrashReporter { const std::string& submit_url, bool auto_submit, bool skip_system_crash_handler) = 0; - virtual void SetUploadParameters(); + virtual void SetUploadParameters() = 0; - typedef std::map StringMap; StringMap upload_parameters_; bool is_browser_; private: + void SetUploadParameters(const StringMap& parameters); + DISALLOW_COPY_AND_ASSIGN(CrashReporter); }; -- 2.7.4