From 4105527d07dc7a6ea1a67b2dcf8a14c63b65eca2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 19 Nov 2013 21:37:02 +0800 Subject: [PATCH] win: Initialize exception handler. --- common/crash_reporter/crash_reporter_win.cc | 37 ++++++++++++++++++--- common/crash_reporter/crash_reporter_win.h | 16 +++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/common/crash_reporter/crash_reporter_win.cc b/common/crash_reporter/crash_reporter_win.cc index 60da71eca484..65d5b8d743e5 100644 --- a/common/crash_reporter/crash_reporter_win.cc +++ b/common/crash_reporter/crash_reporter_win.cc @@ -4,17 +4,15 @@ #include "common/crash_reporter/crash_reporter_win.h" +#include "base/logging.h" #include "base/memory/singleton.h" namespace crash_reporter { -CrashReporterWin::CrashReporterWin() - : breakpad_(NULL) { +CrashReporterWin::CrashReporterWin() { } CrashReporterWin::~CrashReporterWin() { - if (breakpad_ != NULL) - BreakpadRelease(breakpad_); } void CrashReporterWin::InitBreakpad(const std::string& product_name, @@ -23,12 +21,43 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name, const std::string& submit_url, bool auto_submit, bool skip_system_crash_handler) { + skip_system_crash_handler_ = skip_system_crash_handler; + + wchar_t temp_dir[MAX_PATH] = { 0 }; + ::GetTempPathW(MAX_PATH, temp_dir); + + breakpad_.reset(new google_breakpad::ExceptionHandler(temp_dir, + FilterCallback, + MinidumpCallback, + this, + google_breakpad::ExceptionHandler::HANDLER_ALL)); } void CrashReporterWin::SetUploadParameters() { upload_parameters_["platform"] = "win32"; } +// static +bool CrashReporterWin::FilterCallback(void* context, + EXCEPTION_POINTERS* exinfo, + MDRawAssertionInfo* assertion) { + return true; +} + +// static +bool CrashReporterWin::MinidumpCallback(const wchar_t* dump_path, + const wchar_t* minidump_id, + void* context, + EXCEPTION_POINTERS* exinfo, + MDRawAssertionInfo* assertion, + bool succeeded) { + CrashReporterWin* self = static_cast(context); + if (succeeded && !self->skip_system_crash_handler_) + return true; + else + return false; +} + // static CrashReporterWin* CrashReporterWin::GetInstance() { return Singleton::get(); diff --git a/common/crash_reporter/crash_reporter_win.h b/common/crash_reporter/crash_reporter_win.h index af7b06346c0c..ebd85624d699 100644 --- a/common/crash_reporter/crash_reporter_win.h +++ b/common/crash_reporter/crash_reporter_win.h @@ -6,7 +6,9 @@ #define ATOM_COMMON_CRASH_REPORTER_CRASH_REPORTER_WIN_H_ #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "common/crash_reporter/crash_reporter.h" +#include "vendor/breakpad/src/client/windows/handler/exception_handler.h" template struct DefaultSingletonTraits; @@ -30,6 +32,20 @@ class CrashReporterWin : public CrashReporter { CrashReporterWin(); virtual ~CrashReporterWin(); + static bool FilterCallback(void* context, + EXCEPTION_POINTERS* exinfo, + MDRawAssertionInfo* assertion); + + static bool MinidumpCallback(const wchar_t* dump_path, + const wchar_t* minidump_id, + void* context, + EXCEPTION_POINTERS* exinfo, + MDRawAssertionInfo* assertion, + bool succeeded); + + bool skip_system_crash_handler_; + scoped_ptr breakpad_; + DISALLOW_COPY_AND_ASSIGN(CrashReporterWin); };