Chromium Code Reviews| Index: chrome/app/breakpad_mac.mm |
| diff --git a/chrome/app/breakpad_mac.mm b/chrome/app/breakpad_mac.mm |
| index a301e86f6bb982103467c40f17fe5a4da46a41eb..f4825e03b5295a811f5e876ff80ad57c23b2128f 100644 |
| --- a/chrome/app/breakpad_mac.mm |
| +++ b/chrome/app/breakpad_mac.mm |
| @@ -4,38 +4,42 @@ |
| #import "chrome/app/breakpad_mac.h" |
| -#import <dlfcn.h> |
| #import <Foundation/Foundation.h> |
| +#include "base/base_switches.h" |
| #import "base/basictypes.h" |
| +#include "base/command_line.h" |
| #import "base/logging.h" |
| #import "base/scoped_nsautorelease_pool.h" |
| +#include "base/sys_string_conversions.h" |
| +#import "breakpad/src/client/mac/Framework/Breakpad.h" |
| -// For definition of SetActiveRendererURL(). |
| -#import "chrome/renderer/renderer_logging.h" |
| -#import "googleurl/src/gurl.h" |
| +#if !defined(GOOGLE_CHROME_BUILD) |
| +// If we aren't compiling as a branded build, then add dummy versions of the |
| +// Breakpad functions so we don't have to link against Breakpad. |
| -// TODO(jeremy): On Windows we store the current URL when a process crashes |
| -// we probably want to do the same on OS X. |
| +BreakpadRef BreakpadCreate(NSDictionary *parameters) { |
| + NOTREACHED(); |
| + return NULL; |
| +} |
| -namespace { |
| +void BreakpadRelease(BreakpadRef ref) { |
| + NOTREACHED(); |
| +} |
| -// TODO(jeremy): Remove this block once we include the breakpad sources |
| -// in the public tree. |
| -typedef void* GoogleBreakpadRef; |
| +void BreakpadSetKeyValue(BreakpadRef ref, NSString *key, NSString *value) { |
| + NOTREACHED(); |
| +} |
| -typedef void (*GoogleBreakpadSetKeyValuePtr) (GoogleBreakpadRef, NSString*, |
| - NSString*); |
| -typedef void (*GoogleBreakpadRemoveKeyValuePtr) (GoogleBreakpadRef, NSString*); |
| -typedef GoogleBreakpadRef (*GoogleBreakPadCreatePtr) (NSDictionary*); |
| -typedef void (*GoogleBreakPadReleasePtr) (GoogleBreakpadRef); |
| +void BreakpadRemoveKeyValue(BreakpadRef ref, NSString *key) { |
| + NOTREACHED(); |
| +} |
| + |
| +#endif // !defined(GOOGLE_CHROME_BUILD) |
| +namespace { |
| -GoogleBreakpadRef gBreakpadRef = NULL; |
| -GoogleBreakPadCreatePtr gBreakPadCreateFunc = NULL; |
| -GoogleBreakPadReleasePtr gBreakPadReleaseFunc = NULL; |
| -GoogleBreakpadSetKeyValuePtr gBreakpadSetKeyValueFunc = NULL; |
| -GoogleBreakpadRemoveKeyValuePtr gBreakpadRemoveKeyValueFunc = NULL; |
| +BreakpadRef gBreakpadRef = NULL; |
| // Did the user optin for reporting stats. |
| bool IsStatsReportingAllowed() { |
| @@ -51,8 +55,7 @@ bool IsCrashReporterEnabled() { |
| void DestructCrashReporter() { |
| if (gBreakpadRef) { |
| - DCHECK(gBreakPadReleaseFunc != NULL); |
| - gBreakPadReleaseFunc(gBreakpadRef); |
| + BreakpadRelease(gBreakpadRef); |
| gBreakpadRef = NULL; |
| } |
| } |
| @@ -69,63 +72,61 @@ void InitCrashReporter() { |
| } |
| 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; |
| - } |
| - |
| - // Retrieve Breakpad interface functions. |
| - gBreakPadCreateFunc = reinterpret_cast<GoogleBreakPadCreatePtr>( |
| - dlsym(RTLD_DEFAULT, "GoogleBreakpadCreate")); |
| - gBreakPadReleaseFunc = reinterpret_cast<GoogleBreakPadReleasePtr>( |
| - dlsym(RTLD_DEFAULT, "GoogleBreakpadRelease")); |
| - gBreakpadSetKeyValueFunc = reinterpret_cast<GoogleBreakpadSetKeyValuePtr>( |
| - dlsym(RTLD_DEFAULT, "GoogleBreakpadSetKeyValue")); |
| - gBreakpadRemoveKeyValueFunc = |
| - reinterpret_cast<GoogleBreakpadRemoveKeyValuePtr>( |
| - dlsym(RTLD_DEFAULT, "GoogleBreakpadRemoveKeyValue")); |
| - |
| - if (!gBreakPadCreateFunc || !gBreakPadReleaseFunc |
| - || !gBreakpadSetKeyValueFunc || !gBreakpadRemoveKeyValueFunc) { |
| - LOG(ERROR) << "Failed to find Breakpad wrapper classes."; |
| - return; |
| - } |
| + NSString* resource_path = [main_bundle resourcePath]; |
| NSDictionary* info_dictionary = [main_bundle infoDictionary]; |
| - GoogleBreakpadRef breakpad = NULL; |
| - breakpad = gBreakPadCreateFunc(info_dictionary); |
| + NSMutableDictionary *breakpad_config = [info_dictionary |
| + mutableCopy]; |
| + |
| + // Tell Breakpad where inspector & crash_reporter are. |
| + NSString *inspector_location = [resource_path |
| + stringByAppendingPathComponent:@"crash_inspector"]; |
| + NSString *reporter_bundle_location = [resource_path |
| + stringByAppendingPathComponent:@"crash_report_sender.app"]; |
| + NSString *reporter_location = [[NSBundle |
| + bundleWithPath:reporter_bundle_location] |
| + executablePath]; |
| + |
| + [breakpad_config setObject:inspector_location |
| + forKey:@BREAKPAD_INSPECTOR_LOCATION]; |
| + [breakpad_config setObject:reporter_location |
| + forKey:@BREAKPAD_REPORTER_EXE_LOCATION]; |
| + |
| + // Init breakpad |
| + BreakpadRef breakpad = NULL; |
| + breakpad = BreakpadCreate(breakpad_config); |
| if (!breakpad) { |
| LOG(ERROR) << "Breakpad init failed."; |
| return; |
| } |
| - // TODO(jeremy): determine whether we're running in the browser or |
| - // renderer processes. |
| - bool is_renderer = false; |
| - |
| // This needs to be set before calling SetCrashKeyValue(). |
| gBreakpadRef = breakpad; |
| // Set breakpad MetaData values. |
| - NSString* version_str = [info_dictionary objectForKey:@"CFBundleVersion"]; |
| + NSString* version_str = [info_dictionary objectForKey:@BREAKPAD_VERSION]; |
|
John Grabowski
2009/04/22 00:01:58
Feedback not applied or responded on this line
|
| SetCrashKeyValue(@"ver", version_str); |
| - NSString* prod_name_str = [info_dictionary objectForKey:@"CFBundleExecutable"]; |
| + NSString* prod_name_str = [info_dictionary objectForKey:@BREAKPAD_PRODUCT]; |
| SetCrashKeyValue(@"prod", prod_name_str); |
| SetCrashKeyValue(@"plat", @"OS X"); |
| - NSString *product_type = is_renderer ? @"renderer" : @"browser"; |
| - SetCrashKeyValue(@"ptype", product_type); |
| +} |
| + |
| +void InitCrashProcessInfo() { |
| + if (gBreakpadRef == NULL) { |
| + return; |
| + } |
| + |
| + // Determine the process type. |
| + NSString *process_type = @"browser"; |
| + const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| + std::wstring process_type_switch = |
| + parsed_command_line.GetSwitchValue(switches::kProcessType); |
| + if (!process_type_switch.empty()) { |
| + process_type = base::SysWideToNSString(process_type_switch); |
| + } |
| + |
| + // Store process type in crash dump. |
| + SetCrashKeyValue(@"ptype", process_type); |
| } |
| void SetCrashKeyValue(NSString* key, NSString* value) { |
| @@ -137,8 +138,7 @@ void SetCrashKeyValue(NSString* key, NSString* value) { |
| return; |
| } |
| - DCHECK(gBreakpadSetKeyValueFunc != NULL); |
| - gBreakpadSetKeyValueFunc(gBreakpadRef, key, value); |
| + BreakpadSetKeyValue(gBreakpadRef, key, value); |
| } |
| void ClearCrashKeyValue(NSString* key) { |
| @@ -146,6 +146,5 @@ void ClearCrashKeyValue(NSString* key) { |
| return; |
| } |
| - DCHECK(gBreakpadRemoveKeyValueFunc != NULL); |
| - gBreakpadRemoveKeyValueFunc(gBreakpadRef, key); |
| + BreakpadRemoveKeyValue(gBreakpadRef, key); |
| } |