Skip to content

Commit

Permalink
Allow delegate to handle ContentMainRunner fatal initialization error.
Browse files Browse the repository at this point in the history
Report ContentMainRunner fatal error during initialization to the delegate,
which may gracefuly exit with some message instead crashing.
Default behavior is CHECK(false).

Bug: 792839
Change-Id: I1e7c85c58f1a008e8818e2efb00dbba7f4774826
Reviewed-on: https://chromium-review.googlesource.com/815054
Reviewed-by: Ken Rockot <rockot@chromium.org>
Commit-Queue: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#527056}
  • Loading branch information
mpichlin authored and Commit Bot committed Jan 4, 2018
1 parent a264968 commit 8237d65
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
29 changes: 21 additions & 8 deletions content/app/content_main_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ class ContentMainRunnerImpl : public ContentMainRunner {
Shutdown();
}

int TerminateForFatalInitializationError() {
if (delegate_)
return delegate_->TerminateForFatalInitializationError();

CHECK(false);
return 0;
}

int Initialize(const ContentMainParams& params) override {
ui_task_ = params.ui_task;

Expand Down Expand Up @@ -620,13 +628,16 @@ class ContentMainRunnerImpl : public ContentMainRunner {
int icudata_fd = g_fds->MaybeGet(kAndroidICUDataDescriptor);
if (icudata_fd != -1) {
auto icudata_region = g_fds->GetRegion(kAndroidICUDataDescriptor);
CHECK(base::i18n::InitializeICUWithFileDescriptor(icudata_fd,
icudata_region));
if (!base::i18n::InitializeICUWithFileDescriptor(icudata_fd,
icudata_region))
return TerminateForFatalInitializationError();
} else {
CHECK(base::i18n::InitializeICU());
if (!base::i18n::InitializeICU())
return TerminateForFatalInitializationError();
}
#else
CHECK(base::i18n::InitializeICU());
if (!base::i18n::InitializeICU())
return TerminateForFatalInitializationError();
#endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)

base::StatisticsRecorder::Initialize();
Expand Down Expand Up @@ -655,9 +666,10 @@ class ContentMainRunnerImpl : public ContentMainRunner {
delegate_->PreSandboxStartup();

#if defined(OS_WIN)
CHECK(InitializeSandbox(
service_manager::SandboxTypeFromCommandLine(command_line),
params.sandbox_info));
if (!InitializeSandbox(
service_manager::SandboxTypeFromCommandLine(command_line),
params.sandbox_info))
return TerminateForFatalInitializationError();
#elif defined(OS_MACOSX)
// Do not initialize the sandbox at this point if the V2
// sandbox is enabled for the process type.
Expand All @@ -670,7 +682,8 @@ class ContentMainRunnerImpl : public ContentMainRunner {
// On OS X the renderer sandbox needs to be initialized later in the
// startup sequence in RendererMainPlatformDelegate::EnableSandbox().
} else {
CHECK(InitializeSandbox());
if (!InitializeSandbox())
return TerminateForFatalInitializationError();
}
#endif

Expand Down
6 changes: 6 additions & 0 deletions content/public/app/content_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "content/public/app/content_main_delegate.h"

#include "base/logging.h"
#include "build/build_config.h"
#include "content/public/gpu/content_gpu_client.h"
#include "content/public/renderer/content_renderer_client.h"
Expand Down Expand Up @@ -48,6 +49,11 @@ void ContentMainDelegate::ZygoteStarting(

#endif // defined(OS_LINUX)

int ContentMainDelegate::TerminateForFatalInitializationError() {
CHECK(false);
return 0;
}

bool ContentMainDelegate::ShouldEnableProfilerRecording() {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions content/public/app/content_main_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class CONTENT_EXPORT ContentMainDelegate {
// Returns whether or not profiler recording should be enabled.
virtual bool ShouldEnableProfilerRecording();

// Fatal errors during initialization are reported by this function, so that
// the embedder can implement graceful exit by displaying some message and
// returning initialization error code. Default behavior is CHECK(false).
virtual int TerminateForFatalInitializationError();

// Overrides the Service Manager process type to use for the currently running
// process.
virtual service_manager::ProcessType OverrideProcessType();
Expand Down

0 comments on commit 8237d65

Please sign in to comment.