macOS: Support crash reporting from unbundled apps (issue #1532)

This commit is contained in:
Marshall Greenblatt 2017-01-27 14:16:04 -05:00
parent dda50912ed
commit a56ac9782e
3 changed files with 30 additions and 25 deletions

View File

@ -96,6 +96,9 @@ int RunAsCrashpadHandler(const base::CommandLine& command_line) {
}),
argv.end());
// HandlerMain expects the first argument to be the program name.
argv.insert(argv.begin(), command_line.GetProgram().value());
std::unique_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]);
std::vector<std::string> storage;
storage.reserve(argv.size());

View File

@ -59,24 +59,26 @@ void InitCrashReporter(const base::CommandLine& command_line,
// framework dylib is even loaded, to catch potential early crashes.
crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
// Mac Chrome is packaged with a main app bundle and a helper app bundle.
// The main app bundle should only be used for the browser process, so it
// should never see a --type switch (switches::kProcessType). Likewise,
// the helper should always have a --type switch.
//
// This check is done this late so there is already a call to
// base::mac::IsBackgroundOnlyProcess(), so there is no change in
// startup/initialization order.
if (base::mac::AmIBundled()) {
// Mac Chrome is packaged with a main app bundle and a helper app bundle.
// The main app bundle should only be used for the browser process, so it
// should never see a --type switch (switches::kProcessType). Likewise,
// the helper should always have a --type switch.
//
// This check is done this late so there is already a call to
// base::mac::IsBackgroundOnlyProcess(), so there is no change in
// startup/initialization order.
// The helper's Info.plist marks it as a background only app.
if (base::mac::IsBackgroundOnlyProcess()) {
CHECK(command_line.HasSwitch(switches::kProcessType) &&
!process_type.empty())
<< "Helper application requires --type.";
} else {
CHECK(!command_line.HasSwitch(switches::kProcessType) &&
process_type.empty())
<< "Main application forbids --type, saw " << process_type;
// The helper's Info.plist marks it as a background only app.
if (base::mac::IsBackgroundOnlyProcess()) {
CHECK(command_line.HasSwitch(switches::kProcessType) &&
!process_type.empty())
<< "Helper application requires --type.";
} else {
CHECK(!command_line.HasSwitch(switches::kProcessType) &&
process_type.empty())
<< "Main application forbids --type, saw " << process_type;
}
}
g_crash_reporting_enabled = true;

View File

@ -91,16 +91,16 @@ void OverrideFrameworkBundlePath() {
}
void OverrideChildProcessPath() {
// ChildProcessHost::GetChildPath() requires either kBrowserSubprocessPath or
// CHILD_PROCESS_EXE but not both.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kBrowserSubprocessPath)) {
return;
base::FilePath child_process_path =
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kBrowserSubprocessPath);
if (child_process_path.empty()) {
child_process_path = util_mac::GetChildProcessPath();
DCHECK(!child_process_path.empty());
}
base::FilePath child_process_path = util_mac::GetChildProcessPath();
DCHECK(!child_process_path.empty());
// Used by ChildProcessHost::GetChildPath and PlatformCrashpadInitialization.
PathService::Override(content::CHILD_PROCESS_EXE, child_process_path);
}