Commit d957b10b authored by sadrul@chromium.org's avatar sadrul@chromium.org

content: Terminate early if the toolkit initialization fails.

On Chrome OS, it is possible for chrome to start without the X11
server (e.g. X server has crashed, and hasn't restarted since). In
such cases, Chrome ends up causing a crash. So instead of the crash,
abort the startup sequence if the toolkit initialization step fails.

BUG=364929
R=jam@chromium.org

Review URL: https://codereview.chromium.org/250723002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266231 0039d316-1c4b-4281-b951-d872f2087c98
parent ffe1703c
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
#if defined(USE_X11) #if defined(USE_X11)
#include "ui/gfx/x/x11_connection.h" #include "ui/gfx/x/x11_connection.h"
#include "ui/gfx/x/x11_types.h"
#endif #endif
#if defined(USE_OZONE) #if defined(USE_OZONE)
...@@ -1028,7 +1029,7 @@ int BrowserMainLoop::BrowserThreadsStarted() { ...@@ -1028,7 +1029,7 @@ int BrowserMainLoop::BrowserThreadsStarted() {
return result_code_; return result_code_;
} }
void BrowserMainLoop::InitializeToolkit() { bool BrowserMainLoop::InitializeToolkit() {
TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit") TRACE_EVENT0("startup", "BrowserMainLoop::InitializeToolkit")
// TODO(evan): this function is rather subtle, due to the variety // TODO(evan): this function is rather subtle, due to the variety
// of intersecting ifdefs we have. To keep it easy to follow, there // of intersecting ifdefs we have. To keep it easy to follow, there
...@@ -1053,13 +1054,21 @@ void BrowserMainLoop::InitializeToolkit() { ...@@ -1053,13 +1054,21 @@ void BrowserMainLoop::InitializeToolkit() {
#endif #endif
#if defined(USE_AURA) #if defined(USE_AURA)
#if defined(USE_X11)
if (!gfx::GetXDisplay())
return false;
#endif
// Env creates the compositor. Aura widgets need the compositor to be created // Env creates the compositor. Aura widgets need the compositor to be created
// before they can be initialized by the browser. // before they can be initialized by the browser.
aura::Env::CreateInstance(); aura::Env::CreateInstance();
#endif #endif // defined(USE_AURA)
if (parts_) if (parts_)
parts_->ToolkitInitialized(); parts_->ToolkitInitialized();
return true;
} }
void BrowserMainLoop::MainMessageLoopRun() { void BrowserMainLoop::MainMessageLoopRun() {
......
...@@ -67,7 +67,9 @@ class CONTENT_EXPORT BrowserMainLoop { ...@@ -67,7 +67,9 @@ class CONTENT_EXPORT BrowserMainLoop {
void Init(); void Init();
void EarlyInitialization(); void EarlyInitialization();
void InitializeToolkit(); // Initializes the toolkit. Returns whether the toolkit initialization was
// successful or not.
bool InitializeToolkit();
void MainMessageLoopStart(); void MainMessageLoopStart();
// Create and start running the tasks we need to complete startup. Note that // Create and start running the tasks we need to complete startup. Note that
......
...@@ -84,7 +84,8 @@ class BrowserMainRunnerImpl : public BrowserMainRunner { ...@@ -84,7 +84,8 @@ class BrowserMainRunnerImpl : public BrowserMainRunner {
main_loop_->EarlyInitialization(); main_loop_->EarlyInitialization();
// Must happen before we try to use a message loop or display any UI. // Must happen before we try to use a message loop or display any UI.
main_loop_->InitializeToolkit(); if (!main_loop_->InitializeToolkit())
return 1;
main_loop_->MainMessageLoopStart(); main_loop_->MainMessageLoopStart();
......
...@@ -21,7 +21,8 @@ class CONTENT_EXPORT BrowserMainRunner { ...@@ -21,7 +21,8 @@ class CONTENT_EXPORT BrowserMainRunner {
static BrowserMainRunner* Create(); static BrowserMainRunner* Create();
// Initialize all necessary browser state. The |parameters| values will be // Initialize all necessary browser state. The |parameters| values will be
// copied. // copied. Returning a non-negative value indicates that initialization
// failed, and the returned value is used as the exit code for the process.
virtual int Initialize(const content::MainFunctionParams& parameters) = 0; virtual int Initialize(const content::MainFunctionParams& parameters) = 0;
// Perform the default run logic. // Perform the default run logic.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment