summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-26 15:55:02 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-26 15:55:02 +0000
commitad5f54471a107a27a7d975f38651426b6c042fc3 (patch)
tree53f768a325cbe697577ec4773bf9d0c3d40a6bec
parentb5c5cf54b6e984cbf8061da067398e90f9280d0d (diff)
downloadchromium_src-ad5f54471a107a27a7d975f38651426b6c042fc3.zip
chromium_src-ad5f54471a107a27a7d975f38651426b6c042fc3.tar.gz
chromium_src-ad5f54471a107a27a7d975f38651426b6c042fc3.tar.bz2
First stab at Mac breakpad support.
breakpad_mac.mm still needs some work, there's a bunch of scaffolding in there referring to a custom version of Breakpad I've got going locally. Review URL: http://codereview.chromium.org/53075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12553 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/logging.cc2
-rw-r--r--chrome/app/breakpad_mac.h19
-rw-r--r--chrome/app/breakpad_mac.mm95
-rw-r--r--chrome/app/breakpad_win.cc (renamed from chrome/app/breakpad.cc)4
-rw-r--r--chrome/app/breakpad_win.h (renamed from chrome/app/breakpad.h)2
-rw-r--r--chrome/app/chrome_dll_main.cc9
-rw-r--r--chrome/app/chrome_exe.vcproj4
-rw-r--r--chrome/app/chrome_exe_main.cc6
-rw-r--r--chrome/app/chrome_exe_main.mm11
-rw-r--r--chrome/chrome.gyp7
10 files changed, 143 insertions, 16 deletions
diff --git a/base/logging.cc b/base/logging.cc
index 11dfe5d..41a0933 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -525,8 +525,6 @@ LogMessage::~LogMessage() {
#endif
// Crash the process to generate a dump.
DebugUtil::BreakDebugger();
- // TODO(mmentovai): when we have breakpad support, generate a breakpad
- // dump, but until then, do not invoke the Apple crash reporter.
}
}
} else if (severity_ == LOG_ERROR_REPORT) {
diff --git a/chrome/app/breakpad_mac.h b/chrome/app/breakpad_mac.h
new file mode 100644
index 0000000..0a20e12
--- /dev/null
+++ b/chrome/app/breakpad_mac.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_APP_BREAKPAD_MAC_H_
+#define CHROME_APP_BREAKPAD_MAC_H_
+
+// This header defines the Chrome entry points for Breakpad integration.
+
+// Initializes Breakpad.
+void InitCrashReporter();
+
+// Is Breakpad enabled?
+bool IsCrashReporterEnabled();
+
+// Call on clean process shutdown.
+void DestructCrashReporter();
+
+#endif // CHROME_APP_BREAKPAD_MAC_H_
diff --git a/chrome/app/breakpad_mac.mm b/chrome/app/breakpad_mac.mm
new file mode 100644
index 0000000..5ffc147
--- /dev/null
+++ b/chrome/app/breakpad_mac.mm
@@ -0,0 +1,95 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/app/breakpad_mac.h"
+
+#import <objc/objc-class.h>
+#import <Foundation/Foundation.h>
+
+#import "base/basictypes.h"
+#import "base/logging.h"
+#import "base/scoped_nsautorelease_pool.h"
+
+// TODO(jeremy): Remove this block once we include the breakpad sources
+// in the public tree.
+@interface GoogleBreakpadWrapper : NSObject
+ +(void*)Create:(NSDictionary*) parameters;
+ +(void)Release:(void*) ref;
+@end
+typedef void* GoogleBreakpadRef;
+
+namespace {
+
+// TODO(jeremy): On Windows we store the current URL when a process crashes
+// we probably want to do the same on OS X.
+
+GoogleBreakpadRef gBreakpadRef = NULL;
+
+// Did the user optin for reporting stats.
+bool IsStatsReportingAllowed() {
+ NOTIMPLEMENTED();
+ return true;
+}
+
+} // namespace
+
+bool IsCrashReporterEnabled() {
+ return gBreakpadRef == NULL;
+}
+
+void DestructCrashReporter() {
+ if (gBreakpadRef) {
+ Class breakpad_interface = objc_getClass("GoogleBreakpadWrapper");
+ [breakpad_interface Release:gBreakpadRef];
+ gBreakpadRef = NULL;
+ }
+}
+
+void InitCrashReporter() {
+ DCHECK(gBreakpadRef == NULL);
+ base::ScopedNSAutoreleasePool autorelease_pool;
+
+ // Check for Send stats preference. If preference is not specifically turned
+ // on then disable crash reporting.
+ if (!IsStatsReportingAllowed()) {
+ LOG(WARNING) << "Breakpad disabled";
+ return;
+ }
+
+ NSBundle* main_bundle = [NSBundle mainBundle];
+
+ // Get location of breakpad.
+ NSString* breakpadBundlePath = [[main_bundle privateFrameworksPath]
+ stringByAppendingPathComponent:@"GoogleBreakpad.framework"];
+
+ BOOL is_dir = NO;
+ if (![[NSFileManager defaultManager] fileExistsAtPath:breakpadBundlePath
+ isDirectory:&is_dir] || !is_dir) {
+ return;
+ }
+
+ NSBundle* breakpad_bundle = [NSBundle bundleWithPath:breakpadBundlePath];
+ if (![breakpad_bundle load]) {
+ LOG(ERROR) << "Failed to load Breakpad framework.";
+ return;
+ }
+
+ Class breakpad_interface = [breakpad_bundle
+ classNamed:@"GoogleBreakpadWrapper"];
+
+ if (!breakpad_interface) {
+ LOG(ERROR) << "Failed to find GoogleBreakpadWrapper class.";
+ return;
+ }
+
+ NSDictionary* info_dictionary = [main_bundle infoDictionary];
+ GoogleBreakpadRef breakpad = 0;
+ breakpad = [breakpad_interface Create:info_dictionary];
+ if (!breakpad) {
+ LOG(ERROR) << "Breakpad init failed.";
+ return;
+ }
+
+ gBreakpadRef = breakpad;
+}
diff --git a/chrome/app/breakpad.cc b/chrome/app/breakpad_win.cc
index ae16adc..725b9a7 100644
--- a/chrome/app/breakpad.cc
+++ b/chrome/app/breakpad_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/app/breakpad.h"
+#include "chrome/app/breakpad_win.h"
#include <windows.h>
#include <tchar.h>
@@ -299,7 +299,7 @@ void InitDefaultCrashCallback() {
previous_filter = SetUnhandledExceptionFilter(ChromeExceptionFilter);
}
-void InitCrashReporter(const std::wstring& dll_path) {
+void InitCrashReporterWithDllPath(const std::wstring& dll_path) {
const CommandLine& command = *CommandLine::ForCurrentProcess();
if (!command.HasSwitch(switches::kDisableBreakpad)) {
// Disable the message box for assertions.
diff --git a/chrome/app/breakpad.h b/chrome/app/breakpad_win.h
index 07b261b..3aeb5ea 100644
--- a/chrome/app/breakpad.h
+++ b/chrome/app/breakpad_win.h
@@ -10,7 +10,7 @@
// Calls InitCrashReporterThread in it's own thread for the browser process
// or directly for the plugin and renderer process.
-void InitCrashReporter(const std::wstring& dll_path);
+void InitCrashReporterWithDllPath(const std::wstring& dll_path);
// Intercepts a crash but does not process it, just ask if we want to restart
// the browser or not.
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index 82539ef..1ef0dd0 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -34,6 +34,9 @@
#if defined(OS_WIN)
#include "base/win_util.h"
#endif
+#if defined(OS_MACOSX)
+#include "chrome/app/breakpad_mac.h"
+#endif
#include "chrome/app/scoped_ole_initializer.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/common/chrome_constants.h"
@@ -246,7 +249,11 @@ int ChromeMain(int argc, const char** argv) {
#endif
#if defined(OS_MACOSX)
- DebugUtil::DisableOSCrashDumps();
+ // If Breakpad is not present then turn off os crash dumps so we don't have
+ // to wait eons for Apple's Crash Reporter to generate a dump.
+ if (!IsCrashReporterEnabled()) {
+ DebugUtil::DisableOSCrashDumps();
+ }
#endif
RegisterInvalidParamHandler();
diff --git a/chrome/app/chrome_exe.vcproj b/chrome/app/chrome_exe.vcproj
index 724e365..7ac9ab4 100644
--- a/chrome/app/chrome_exe.vcproj
+++ b/chrome/app/chrome_exe.vcproj
@@ -183,11 +183,11 @@
</File>
</Filter>
<File
- RelativePath=".\breakpad.cc"
+ RelativePath=".\breakpad_win.cc"
>
</File>
<File
- RelativePath=".\breakpad.h"
+ RelativePath=".\breakpad_win.h"
>
</File>
<File
diff --git a/chrome/app/chrome_exe_main.cc b/chrome/app/chrome_exe_main.cc
index 053f149..197a50d 100644
--- a/chrome/app/chrome_exe_main.cc
+++ b/chrome/app/chrome_exe_main.cc
@@ -11,7 +11,7 @@
#include "base/debug_on_start.h"
#include "base/process_util.h"
#include "base/win_util.h"
-#include "chrome/app/breakpad.h"
+#include "chrome/app/breakpad_win.h"
#include "chrome/app/client_util.h"
#include "chrome/app/google_update_client.h"
#include "chrome/common/chrome_switches.h"
@@ -52,7 +52,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
client.Init(L"{8A69D345-D564-463c-AFF1-A69D9E530F96}", dll_name);
// Initialize the crash reporter.
- InitCrashReporter(client.GetDLLPath());
+ InitCrashReporterWithDllPath(client.GetDLLPath());
bool exit_now = true;
if (ShowRestartDialogIfCrashed(&exit_now)) {
@@ -85,7 +85,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
LOAD_WITH_ALTERED_SEARCH_PATH);
// Initialize the crash reporter.
- InitCrashReporter(client_util::GetDLLPath(dll_name, dll_path));
+ InitCrashReporterWithDllPath(client_util::GetDLLPath(dll_name, dll_path));
bool exit_now = true;
if (ShowRestartDialogIfCrashed(&exit_now)) {
diff --git a/chrome/app/chrome_exe_main.mm b/chrome/app/chrome_exe_main.mm
index f6c78e0..e762067 100644
--- a/chrome/app/chrome_exe_main.mm
+++ b/chrome/app/chrome_exe_main.mm
@@ -6,6 +6,7 @@
#include "base/at_exit.h"
#include "base/process_util.h"
+#import "chrome/app/breakpad_mac.h"
// The entry point for all invocations of Chromium, browser and renderer. On
// windows, this does nothing but load chrome.dll and invoke its entry point
@@ -27,8 +28,14 @@ int main(int argc, const char** argv) {
// base::AtExitManager exit_manager;
#if defined(GOOGLE_CHROME_BUILD)
- // TODO(pinkerton): init crash reporter
+ InitCrashReporter();
#endif
- return ChromeMain(argc, argv);
+ int ret = ChromeMain(argc, argv);
+
+#if defined(GOOGLE_CHROME_BUILD)
+ DestructCrashReporter();
+#endif
+
+ return ret;
}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index fcc83c6..0921376 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1468,8 +1468,10 @@
],
'sources': [
# All .cc, .h, .m, and .mm files under app except for tests.
- 'app/breakpad.cc',
- 'app/breakpad.h',
+ 'app/breakpad_win.cc',
+ 'app/breakpad_win.h',
+ 'app/breakpad_mac.mm',
+ 'app/breakpad_mac.h',
'app/chrome_dll_main.cc',
'app/chrome_dll_resource.h',
'app/chrome_exe_main.cc',
@@ -1666,7 +1668,6 @@
},
],
'sources!': [
- 'app/breakpad.cc',
'app/chrome_exe_main.cc',
'app/client_util.cc',
'app/google_update_client.cc',