diff options
Diffstat (limited to 'chrome/app')
-rw-r--r-- | chrome/app/breakpad_linux.cc | 4 | ||||
-rw-r--r-- | chrome/app/breakpad_mac.h | 6 | ||||
-rw-r--r-- | chrome/app/breakpad_mac.mm | 98 | ||||
-rw-r--r-- | chrome/app/chrome_dll_main.cc | 44 |
4 files changed, 69 insertions, 83 deletions
diff --git a/chrome/app/breakpad_linux.cc b/chrome/app/breakpad_linux.cc index b23a5d7..19c82ba 100644 --- a/chrome/app/breakpad_linux.cc +++ b/chrome/app/breakpad_linux.cc @@ -611,11 +611,11 @@ void InitCrashReporter() { // We might be chrooted in a zygote or renderer process so we cannot call // GetCollectStatsConsent because that needs access the the user's home // dir. Instead, we set a command line flag for these processes. - if (!parsed_command_line.HasSwitch(switches::kRendererCrashDump)) + if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter)) return; // Get the guid and linux distro from the command line switch. std::string switch_value = WideToASCII( - parsed_command_line.GetSwitchValue(switches::kRendererCrashDump)); + parsed_command_line.GetSwitchValue(switches::kEnableCrashReporter)); size_t separator = switch_value.find(","); if (separator != std::string::npos) { google_update::linux_guid = switch_value.substr(0, separator); diff --git a/chrome/app/breakpad_mac.h b/chrome/app/breakpad_mac.h index 8872191..ce6f25f 100644 --- a/chrome/app/breakpad_mac.h +++ b/chrome/app/breakpad_mac.h @@ -5,8 +5,6 @@ #ifndef CHROME_APP_BREAKPAD_MAC_H_ #define CHROME_APP_BREAKPAD_MAC_H_ -extern "C" { - // This header defines the Chrome entry points for Breakpad integration. // Initializes Breakpad. @@ -23,7 +21,7 @@ bool IsCrashReporterDisabled(); // Call on clean process shutdown. void DestructCrashReporter(); -#if __OBJC__ +#ifdef __OBJC__ @class NSString; @@ -36,6 +34,4 @@ void ClearCrashKeyValue(NSString* key); #endif // __OBJC__ -} - #endif // CHROME_APP_BREAKPAD_MAC_H_ diff --git a/chrome/app/breakpad_mac.mm b/chrome/app/breakpad_mac.mm index 3bad98d..8a36f16 100644 --- a/chrome/app/breakpad_mac.mm +++ b/chrome/app/breakpad_mac.mm @@ -14,15 +14,14 @@ #include "base/sys_string_conversions.h" #import "breakpad/src/client/mac/Framework/Breakpad.h" #include "chrome/common/child_process_logging.h" +#include "chrome/common/chrome_switches.h" #include "chrome/installer/util/google_update_settings.h" -extern "C" { - namespace { BreakpadRef gBreakpadRef = NULL; -} // namespace +} // namespace bool IsCrashReporterDisabled() { return gBreakpadRef == NULL; @@ -40,66 +39,65 @@ 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. - bool user_consented = GoogleUpdateSettings::GetCollectStatsConsent(); - if (!user_consented) { + // Check whether the user has consented to stats and crash reporting. The + // browser process can make this determination directly. Helper processes + // may not have access to the disk or to the same data as the browser + // process, so the browser passes the consent preference to them on the + // command line. + NSBundle* main_bundle = [NSBundle mainBundle]; + NSDictionary* info_dictionary = [main_bundle infoDictionary]; + bool is_browser = [[info_dictionary objectForKey:@"LSUIElement"] + isEqualToString:@"1"] ? true : false; + bool enable_breakpad = + is_browser ? GoogleUpdateSettings::GetCollectStatsConsent() : + CommandLine::ForCurrentProcess()-> + HasSwitch(switches::kEnableCrashReporter); + + if (!enable_breakpad) { LOG(WARNING) << "Breakpad disabled"; return; } - NSBundle* main_bundle = [NSBundle mainBundle]; + // Tell Breakpad where crash_inspector and crash_report_sender are. NSString* resource_path = [main_bundle resourcePath]; - - NSDictionary* info_dictionary = [main_bundle infoDictionary]; - 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]; - + 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]; + + NSMutableDictionary *breakpad_config = + [[info_dictionary mutableCopy] autorelease]; [breakpad_config setObject:inspector_location forKey:@BREAKPAD_INSPECTOR_LOCATION]; [breakpad_config setObject:reporter_location forKey:@BREAKPAD_REPORTER_EXE_LOCATION]; - // Pass crash to Crash Reporter if we're a foreground application [the - // browser process]. This is so the user gets notification when Chrome - // crashes and also since we get "restart ui" for free. - BOOL is_background_app = [[info_dictionary objectForKey:@"LSUIElement"] - isEqualToString:@"1"]; - if (!is_background_app) { + // In the main application (the browser process), crashes can be passed to + // the system's Crash Reporter. This allows the system to notify the user + // when the application crashes, and provide the user with the option to + // restart it. + if (is_browser) [breakpad_config setObject:@"NO" forKey:@BREAKPAD_SEND_AND_EXIT]; - } - // Init breakpad - BreakpadRef breakpad = NULL; - breakpad = BreakpadCreate(breakpad_config); - if (!breakpad) { - LOG(ERROR) << "Breakpad init failed."; + // Initialize Breakpad. + gBreakpadRef = BreakpadCreate(breakpad_config); + if (!gBreakpadRef) { + LOG(ERROR) << "Breakpad initializaiton failed"; return; } - // This needs to be set before calling SetCrashKeyValue(). - gBreakpadRef = breakpad; - - // Set breakpad MetaData values. - // These values are added to the plist when building a branded Chrome.app. - NSString* version_str = [info_dictionary objectForKey:@BREAKPAD_VERSION]; - SetCrashKeyValue(@"ver", version_str); - NSString* prod_name_str = [info_dictionary objectForKey:@BREAKPAD_PRODUCT]; - SetCrashKeyValue(@"prod", prod_name_str); + // Set Breakpad metadata values. These values are added to Info.plist during + // the branded Google Chrome.app build. + SetCrashKeyValue(@"ver", [info_dictionary objectForKey:@BREAKPAD_VERSION]); + SetCrashKeyValue(@"prod", [info_dictionary objectForKey:@BREAKPAD_PRODUCT]); SetCrashKeyValue(@"plat", @"OS X"); - // Enable child process crashes to include the page url. - child_process_logging::SetCrashKeyFunctions( - SetCrashKeyValue, ClearCrashKeyValue); + // Enable child process crashes to include the page URL. + // TODO: Should this only be done for certain process types? + child_process_logging::SetCrashKeyFunctions(SetCrashKeyValue, + ClearCrashKeyValue); } void InitCrashProcessInfo() { @@ -108,10 +106,9 @@ void InitCrashProcessInfo() { } // Determine the process type. - NSString *process_type = @"browser"; - const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); + NSString* process_type = @"browser"; std::wstring process_type_switch = - parsed_command_line.GetSwitchValue(switches::kProcessType); + CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kProcessType); if (!process_type_switch.empty()) { process_type = base::SysWideToNSString(process_type_switch); } @@ -139,6 +136,3 @@ void ClearCrashKeyValue(NSString* key) { BreakpadRemoveUploadParameter(gBreakpadRef, key); } - -} - diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc index c17dcfe..4b23cc1 100644 --- a/chrome/app/chrome_dll_main.cc +++ b/chrome/app/chrome_dll_main.cc @@ -298,29 +298,14 @@ int ChromeMain(int argc, const char** argv) { #endif #if defined(OS_MACOSX) - // TODO(mark): Some of these things ought to be handled in chrome_exe_main.mm, - // such as Breakpad initialization. Under the current architecture, nothing - // in chrome_exe_main can rely directly on chrome_dll code on the Mac, - // though, so until some of this code is refactored to avoid such a - // dependency, it lives here. See also the TODO(mark) below at - // DestructCrashReporter(). + // TODO(mark): Some of these things ought to be handled in chrome_exe_main.mm. + // Under the current architecture, nothing in chrome_exe_main can rely + // directly on chrome_dll code on the Mac, though, so until some of this code + // is refactored to avoid such a dependency, it lives here. See also the + // TODO(mark) below at InitCrashReporter() and DestructCrashReporter(). base::EnableTerminationOnHeapCorruption(); - - // The exit manager is in charge of calling the dtors of singletons. - // Win has one here, but we assert with multiples from BrowserMain() if we - // keep it. - // base::AtExitManager exit_manager; - -#if defined(GOOGLE_CHROME_BUILD) - InitCrashReporter(); -#endif - - // 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 (IsCrashReporterDisabled()) { - DebugUtil::DisableOSCrashDumps(); - } #endif // OS_MACOSX + RegisterInvalidParamHandler(); // The exit manager is in charge of calling the dtors of singleton objects. @@ -350,9 +335,20 @@ int ChromeMain(int argc, const char** argv) { #endif #if defined(OS_MACOSX) - // Needs to be called after CommandLine::Init(). - InitCrashProcessInfo(); -#endif + // TODO(mark): Right now, InitCrashReporter() needs to be called after + // CommandLine::Init(). Ideally, Breakpad initialization could occur + // sooner, preferably even before the framework dylib is even loaded, to + // catch potential early early crashes. + InitCrashReporter(); + + // If Breakpad is not present, turn off OS crash dumps to avoid having + // to wait eons for Apple's Crash Reporter to generate dumps for builds + // where debugging symbols are present. + if (IsCrashReporterDisabled()) + DebugUtil::DisableOSCrashDumps(); + else + InitCrashProcessInfo(); +#endif // OS_MACOSX const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |