]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Initialize exception handler.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 19 Nov 2013 13:37:02 +0000 (21:37 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 19 Nov 2013 13:37:02 +0000 (21:37 +0800)
common/crash_reporter/crash_reporter_win.cc
common/crash_reporter/crash_reporter_win.h

index 60da71eca484404b454b1f3c149cf873f86e9748..65d5b8d743e5e6dd1216216dc702b2959679d736 100644 (file)
@@ -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<CrashReporterWin*>(context);
+  if (succeeded && !self->skip_system_crash_handler_)
+    return true;
+  else
+    return false;
+}
+
 // static
 CrashReporterWin* CrashReporterWin::GetInstance() {
   return Singleton<CrashReporterWin>::get();
index af7b06346c0ce1e6527df55a9e09af4f0b12d38e..ebd85624d6990a7dcd7324878a15cb6ccf53bfb6 100644 (file)
@@ -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 <typename T> 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<google_breakpad::ExceptionHandler> breakpad_;
+
   DISALLOW_COPY_AND_ASSIGN(CrashReporterWin);
 };