Enable customing upload parameters for sending crash report.

This commit is contained in:
Cheng Zhao 2013-11-18 18:27:50 +08:00
parent f8f09eb974
commit d181ff4e7f
4 changed files with 22 additions and 16 deletions

View file

@ -17,12 +17,13 @@ namespace api {
v8::Handle<v8::Value> CrashReporter::Start(const v8::Arguments& args) { v8::Handle<v8::Value> CrashReporter::Start(const v8::Arguments& args) {
std::string product_name, company_name, submit_url; std::string product_name, company_name, submit_url;
bool auto_submit, skip_system; bool auto_submit, skip_system;
std::map<std::string, std::string> dict;
if (!FromV8Arguments(args, &product_name, &company_name, &submit_url, if (!FromV8Arguments(args, &product_name, &company_name, &submit_url,
&auto_submit, &skip_system)) &auto_submit, &skip_system, &dict))
return node::ThrowTypeError("Bad argument"); return node::ThrowTypeError("Bad argument");
crash_reporter::CrashReporter::GetInstance()->Start( 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(); return v8::Undefined();
} }

View file

@ -2,14 +2,15 @@ binding = process.atomBinding 'crash_reporter'
class CrashReporter class CrashReporter
start: (options={}) -> start: (options={}) ->
{productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler} = options {productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra} = options
productName ?= 'Atom-Shell' productName ?= 'Atom-Shell'
companyName ?= 'GitHub, Inc' companyName ?= 'GitHub, Inc'
submitUrl ?= 'http://54.249.141.25' submitUrl ?= 'http://54.249.141.25'
autoSubmit ?= true autoSubmit ?= true
ignoreSystemCrashHandler ?= false ignoreSystemCrashHandler ?= false
extra ?= {}
binding.start productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler binding.start productName, companyName, submitUrl, autoSubmit, ignoreSystemCrashHandler, extra
module.exports = new CrashReporter module.exports = new CrashReporter

View file

@ -12,9 +12,8 @@
namespace crash_reporter { namespace crash_reporter {
CrashReporter::CrashReporter() { CrashReporter::CrashReporter() {
SetUploadParameters(); const CommandLine& command = *CommandLine::ForCurrentProcess();
is_browser_ = command.GetSwitchValueASCII(switches::kProcessType).empty();
is_browser_ = upload_parameters_["process_type"].empty();
} }
CrashReporter::~CrashReporter() { CrashReporter::~CrashReporter() {
@ -24,18 +23,19 @@ void CrashReporter::Start(std::string product_name,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
bool auto_submit, 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. // Append "Renderer" for the renderer.
product_name += " Renderer"; product_name += " Renderer";
InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url, InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url,
auto_submit, skip_system_crash_handler); auto_submit, skip_system_crash_handler);
} }
void CrashReporter::SetUploadParameters() { void CrashReporter::SetUploadParameters(const StringMap& parameters) {
const CommandLine& command = *CommandLine::ForCurrentProcess(); upload_parameters_ = parameters;
std::string type = command.GetSwitchValueASCII(switches::kProcessType); upload_parameters_["process_type"] = is_browser_ ? "browser" : "renderer";
upload_parameters_["process_type"] = type;
} }
} // namespace crash_reporter } // namespace crash_reporter

View file

@ -14,13 +14,16 @@ namespace crash_reporter {
class CrashReporter { class CrashReporter {
public: public:
typedef std::map<std::string, std::string> StringMap;
static CrashReporter* GetInstance(); static CrashReporter* GetInstance();
void Start(std::string product_name, void Start(std::string product_name,
const std::string& company_name, const std::string& company_name,
const std::string& submit_url, const std::string& submit_url,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler); bool skip_system_crash_handler,
const StringMap& extra_parameters);
protected: protected:
CrashReporter(); CrashReporter();
@ -32,13 +35,14 @@ class CrashReporter {
const std::string& submit_url, const std::string& submit_url,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler) = 0; bool skip_system_crash_handler) = 0;
virtual void SetUploadParameters(); virtual void SetUploadParameters() = 0;
typedef std::map<std::string, std::string> StringMap;
StringMap upload_parameters_; StringMap upload_parameters_;
bool is_browser_; bool is_browser_;
private: private:
void SetUploadParameters(const StringMap& parameters);
DISALLOW_COPY_AND_ASSIGN(CrashReporter); DISALLOW_COPY_AND_ASSIGN(CrashReporter);
}; };