Commit 1ab1bcf7 authored by Jonathan's avatar Jonathan Committed by Commit Bot

Relnad Update AuraInit to handle failed initialization

This change relands AuraInit changes, with a fix to the shared resources logic
which was causing a crash on chrome --mash

Revert "Revert of Update AuraInit to handle failed initialization (patchset #2 id:40001 of https://codereview.chromium.org/2967943002/ )"

This reverts commit e3f9dbb7.

TBR=sky@chromium.org
TEST=ran chrome --mash

Bug: 678687
Change-Id: I6d64b04c520564a022b65e2e2f6c322803a9db64
Reviewed-on: https://chromium-review.googlesource.com/562497
Commit-Queue: Jonathan Ross <jonross@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485258}
parent 3eb6363c
...@@ -90,9 +90,13 @@ AutoclickApplication::AutoclickApplication() ...@@ -90,9 +90,13 @@ AutoclickApplication::AutoclickApplication()
AutoclickApplication::~AutoclickApplication() {} AutoclickApplication::~AutoclickApplication() {}
void AutoclickApplication::OnStart() { void AutoclickApplication::OnStart() {
aura_init_ = base::MakeUnique<views::AuraInit>( aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak", context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
if (!aura_init_) {
context()->QuitNow();
return;
}
autoclick_controller_common_.reset(new AutoclickControllerCommon( autoclick_controller_common_.reset(new AutoclickControllerCommon(
base::TimeDelta::FromMilliseconds(kDefaultAutoclickDelayMs), this)); base::TimeDelta::FromMilliseconds(kDefaultAutoclickDelayMs), this));
} }
......
...@@ -129,10 +129,14 @@ void WindowManagerApplication::OnStart() { ...@@ -129,10 +129,14 @@ void WindowManagerApplication::OnStart() {
mojo_interface_factory::RegisterInterfaces( mojo_interface_factory::RegisterInterfaces(
&registry_, base::ThreadTaskRunnerHandle::Get()); &registry_, base::ThreadTaskRunnerHandle::Get());
aura_init_ = base::MakeUnique<views::AuraInit>( aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "ash_mus_resources.pak", context()->connector(), context()->identity(), "ash_mus_resources.pak",
"ash_mus_resources_200.pak", nullptr, "ash_mus_resources_200.pak", nullptr,
views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER); views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER);
if (!aura_init_) {
context()->QuitNow();
return;
}
window_manager_ = base::MakeUnique<WindowManager>( window_manager_ = base::MakeUnique<WindowManager>(
context()->connector(), ash_config_, show_primary_host_on_connect_); context()->connector(), ash_config_, show_primary_host_on_connect_);
......
...@@ -69,9 +69,11 @@ TouchHudApplication::TouchHudApplication() : binding_(this) { ...@@ -69,9 +69,11 @@ TouchHudApplication::TouchHudApplication() : binding_(this) {
TouchHudApplication::~TouchHudApplication() {} TouchHudApplication::~TouchHudApplication() {}
void TouchHudApplication::OnStart() { void TouchHudApplication::OnStart() {
aura_init_ = base::MakeUnique<views::AuraInit>( aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak", context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
if (!aura_init_)
context()->QuitNow();
} }
void TouchHudApplication::OnBindInterface( void TouchHudApplication::OnBindInterface(
......
...@@ -222,9 +222,11 @@ void CatalogViewer::RemoveWindow(views::Widget* window) { ...@@ -222,9 +222,11 @@ void CatalogViewer::RemoveWindow(views::Widget* window) {
} }
void CatalogViewer::OnStart() { void CatalogViewer::OnStart() {
aura_init_ = base::MakeUnique<views::AuraInit>( aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak", context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
if (!aura_init_)
context()->QuitNow();
} }
void CatalogViewer::OnBindInterface( void CatalogViewer::OnBindInterface(
......
...@@ -31,10 +31,12 @@ class ViewsExamples : public service_manager::Service, ...@@ -31,10 +31,12 @@ class ViewsExamples : public service_manager::Service,
private: private:
// service_manager::Service: // service_manager::Service:
void OnStart() override { void OnStart() override {
aura_init_ = base::MakeUnique<views::AuraInit>( aura_init_ =
context()->connector(), context()->identity(), views::AuraInit::Create(context()->connector(), context()->identity(),
"views_mus_resources.pak", std::string(), nullptr, "views_mus_resources.pak", std::string(),
views::AuraInit::Mode::AURA_MUS); nullptr, views::AuraInit::Mode::AURA_MUS);
if (!aura_init_)
context()->QuitNow();
} }
void OnBindInterface(const service_manager::BindSourceInfo& source_info, void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name, const std::string& interface_name,
......
...@@ -453,9 +453,11 @@ void WindowTypeLauncher::RemoveWindow(views::Widget* window) { ...@@ -453,9 +453,11 @@ void WindowTypeLauncher::RemoveWindow(views::Widget* window) {
} }
void WindowTypeLauncher::OnStart() { void WindowTypeLauncher::OnStart() {
aura_init_ = base::MakeUnique<views::AuraInit>( aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak", context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
if (!aura_init_)
context()->QuitNow();
} }
void WindowTypeLauncher::OnBindInterface( void WindowTypeLauncher::OnBindInterface(
......
...@@ -171,14 +171,13 @@ void QuickLaunch::RemoveWindow(views::Widget* window) { ...@@ -171,14 +171,13 @@ void QuickLaunch::RemoveWindow(views::Widget* window) {
} }
void QuickLaunch::OnStart() { void QuickLaunch::OnStart() {
aura_init_ = base::MakeUnique<views::AuraInit>(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
// If AuraInit was unable to initialize there is no longer a peer connection. // If AuraInit was unable to initialize there is no longer a peer connection.
// The ServiceManager is in the process of shutting down, however we haven't // The ServiceManager is in the process of shutting down, however we haven't
// been notified yet. Close our ServiceContext and shutdown. // been notified yet. Close our ServiceContext and shutdown.
if (!aura_init_->initialized()) { aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
if (!aura_init_) {
context()->QuitNow(); context()->QuitNow();
return; return;
} }
......
...@@ -364,9 +364,13 @@ void SimpleWM::OnStart() { ...@@ -364,9 +364,13 @@ void SimpleWM::OnStart() {
started_ = true; started_ = true;
screen_ = base::MakeUnique<display::ScreenBase>(); screen_ = base::MakeUnique<display::ScreenBase>();
display::Screen::SetScreenInstance(screen_.get()); display::Screen::SetScreenInstance(screen_.get());
aura_init_ = base::MakeUnique<views::AuraInit>( aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak", context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER); std::string(), nullptr, views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER);
if (!aura_init_) {
context()->QuitNow();
return;
}
window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>( window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>(
context()->connector(), this, this); context()->connector(), this, this);
aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client_.get()); aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client_.get());
......
...@@ -294,9 +294,11 @@ void TaskViewer::RemoveWindow(views::Widget* widget) { ...@@ -294,9 +294,11 @@ void TaskViewer::RemoveWindow(views::Widget* widget) {
} }
void TaskViewer::OnStart() { void TaskViewer::OnStart() {
aura_init_ = base::MakeUnique<views::AuraInit>( aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak", context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
if (!aura_init_)
context()->QuitNow();
} }
void TaskViewer::OnBindInterface( void TaskViewer::OnBindInterface(
......
...@@ -52,27 +52,56 @@ class MusViewsDelegate : public ViewsDelegate { ...@@ -52,27 +52,56 @@ class MusViewsDelegate : public ViewsDelegate {
} // namespace } // namespace
AuraInit::AuraInit(service_manager::Connector* connector, AuraInit::AuraInit() {
const service_manager::Identity& identity,
const std::string& resource_file,
const std::string& resource_file_200,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
Mode mode)
: resource_file_(resource_file),
resource_file_200_(resource_file_200),
env_(aura::Env::CreateInstance(
(mode == Mode::AURA_MUS || mode == Mode::AURA_MUS_WINDOW_MANAGER)
? aura::Env::Mode::MUS
: aura::Env::Mode::LOCAL)) {
if (!ViewsDelegate::GetInstance()) if (!ViewsDelegate::GetInstance())
views_delegate_ = base::MakeUnique<MusViewsDelegate>(); views_delegate_ = base::MakeUnique<MusViewsDelegate>();
}
AuraInit::~AuraInit() {
#if defined(OS_LINUX)
if (font_loader_.get()) {
SkFontConfigInterface::SetGlobal(nullptr);
// FontLoader is ref counted. We need to explicitly shutdown the background
// thread, otherwise the background thread may be shutdown after the app is
// torn down, when we're in a bad state.
font_loader_->Shutdown();
}
#endif
}
std::unique_ptr<AuraInit> AuraInit::Create(
service_manager::Connector* connector,
const service_manager::Identity& identity,
const std::string& resource_file,
const std::string& resource_file_200,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
Mode mode) {
std::unique_ptr<AuraInit> aura_init = base::WrapUnique(new AuraInit());
if (!aura_init->Init(connector, identity, resource_file, resource_file_200,
io_task_runner, mode)) {
aura_init.reset();
}
return aura_init;
}
bool AuraInit::Init(service_manager::Connector* connector,
const service_manager::Identity& identity,
const std::string& resource_file,
const std::string& resource_file_200,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
Mode mode) {
env_ = aura::Env::CreateInstance(
(mode == Mode::AURA_MUS || mode == Mode::AURA_MUS_WINDOW_MANAGER)
? aura::Env::Mode::MUS
: aura::Env::Mode::LOCAL);
if (mode == Mode::AURA_MUS) { if (mode == Mode::AURA_MUS) {
mus_client_ = mus_client_ =
base::WrapUnique(new MusClient(connector, identity, io_task_runner)); base::WrapUnique(new MusClient(connector, identity, io_task_runner));
} }
ui::MaterialDesignController::Initialize(); ui::MaterialDesignController::Initialize();
if (!InitializeResources(connector)) if (!InitializeResources(connector, resource_file, resource_file_200))
return; return false;
// Initialize the skia font code to go ask fontconfig underneath. // Initialize the skia font code to go ask fontconfig underneath.
#if defined(OS_LINUX) #if defined(OS_LINUX)
...@@ -85,30 +114,20 @@ AuraInit::AuraInit(service_manager::Connector* connector, ...@@ -85,30 +114,20 @@ AuraInit::AuraInit(service_manager::Connector* connector,
gfx::Font(); gfx::Font();
ui::InitializeInputMethodForTesting(); ui::InitializeInputMethodForTesting();
initialized_ = true; return true;
}
AuraInit::~AuraInit() {
#if defined(OS_LINUX)
if (font_loader_.get()) {
SkFontConfigInterface::SetGlobal(nullptr);
// FontLoader is ref counted. We need to explicitly shutdown the background
// thread, otherwise the background thread may be shutdown after the app is
// torn down, when we're in a bad state.
font_loader_->Shutdown();
}
#endif
} }
bool AuraInit::InitializeResources(service_manager::Connector* connector) { bool AuraInit::InitializeResources(service_manager::Connector* connector,
const std::string& resource_file,
const std::string& resource_file_200) {
// Resources may have already been initialized (e.g. when 'chrome --mash' is // Resources may have already been initialized (e.g. when 'chrome --mash' is
// used to launch the current app). // used to launch the current app).
if (ui::ResourceBundle::HasSharedInstance()) if (ui::ResourceBundle::HasSharedInstance())
return false; return true;
std::set<std::string> resource_paths({resource_file_}); std::set<std::string> resource_paths({resource_file});
if (!resource_file_200_.empty()) if (!resource_file_200.empty())
resource_paths.insert(resource_file_200_); resource_paths.insert(resource_file_200);
catalog::ResourceLoader loader; catalog::ResourceLoader loader;
filesystem::mojom::DirectoryPtr directory; filesystem::mojom::DirectoryPtr directory;
...@@ -123,15 +142,15 @@ bool AuraInit::InitializeResources(service_manager::Connector* connector) { ...@@ -123,15 +142,15 @@ bool AuraInit::InitializeResources(service_manager::Connector* connector) {
if (!loader.OpenFiles(std::move(directory), resource_paths)) if (!loader.OpenFiles(std::move(directory), resource_paths))
return false; return false;
ui::RegisterPathProvider(); ui::RegisterPathProvider();
base::File pak_file = loader.TakeFile(resource_file_); base::File pak_file = loader.TakeFile(resource_file);
base::File pak_file_2 = pak_file.Duplicate(); base::File pak_file_2 = pak_file.Duplicate();
ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile); std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile);
ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
std::move(pak_file_2), ui::SCALE_FACTOR_100P); std::move(pak_file_2), ui::SCALE_FACTOR_100P);
if (!resource_file_200_.empty()) if (!resource_file_200.empty())
ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
loader.TakeFile(resource_file_200_), ui::SCALE_FACTOR_200P); loader.TakeFile(resource_file_200), ui::SCALE_FACTOR_200P);
return true; return true;
} }
......
...@@ -51,42 +51,51 @@ class VIEWS_MUS_EXPORT AuraInit { ...@@ -51,42 +51,51 @@ class VIEWS_MUS_EXPORT AuraInit {
UI UI
}; };
~AuraInit();
// Returns an AuraInit if initialization can be completed successfully,
// otherwise a nullptr is returned. If initialization fails then Aura is in an
// unusable state, and calling services should shutdown.
// |resource_file| is the file to load strings and 1x icons from. // |resource_file| is the file to load strings and 1x icons from.
// |resource_file_200| can be an empty string, otherwise it is the file to // |resource_file_200| can be an empty string, otherwise it is the file to
// load 2x icons from. // load 2x icons from.
AuraInit(service_manager::Connector* connector, static std::unique_ptr<AuraInit> Create(
const service_manager::Identity& identity, service_manager::Connector* connector,
const std::string& resource_file, const service_manager::Identity& identity,
const std::string& resource_file_200 = std::string(), const std::string& resource_file,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = nullptr, const std::string& resource_file_200 = std::string(),
Mode mode = Mode::UI); scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = nullptr,
~AuraInit(); Mode mode = Mode::UI);
// Only valid if Mode::AURA_MUS was passed to constructor. // Only valid if Mode::AURA_MUS was passed to constructor.
MusClient* mus_client() { return mus_client_.get(); } MusClient* mus_client() { return mus_client_.get(); }
private:
AuraInit();
// Returns true if AuraInit was able to successfully complete initialization. // Returns true if AuraInit was able to successfully complete initialization.
// If this returns false, then Aura is in an unusable state, and calling // If this returns false, then Aura is in an unusable state, and calling
// services should shutdown. // services should shutdown.
bool initialized() { return initialized_; } bool Init(
service_manager::Connector* connector,
private: const service_manager::Identity& identity,
bool InitializeResources(service_manager::Connector* connector); const std::string& resource_file,
const std::string& resource_file_200 = std::string(),
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = nullptr,
Mode mode = Mode::UI);
bool InitializeResources(service_manager::Connector* connector,
const std::string& resource_file,
const std::string& resource_file_200);
#if defined(OS_LINUX) #if defined(OS_LINUX)
sk_sp<font_service::FontLoader> font_loader_; sk_sp<font_service::FontLoader> font_loader_;
#endif #endif
const std::string resource_file_;
const std::string resource_file_200_;
std::unique_ptr<aura::Env> env_; std::unique_ptr<aura::Env> env_;
std::unique_ptr<MusClient> mus_client_; std::unique_ptr<MusClient> mus_client_;
std::unique_ptr<ViewsDelegate> views_delegate_; std::unique_ptr<ViewsDelegate> views_delegate_;
// Whether or not initialization succeeds.
bool initialized_ = false;
DISALLOW_COPY_AND_ASSIGN(AuraInit); DISALLOW_COPY_AND_ASSIGN(AuraInit);
}; };
......
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