0

Reland "Add InitParams for views::AuraInit"

This reverts commit e959c2d741.

Fixed by adding EXPORT macro on the new struct.

Original change's description:
> Revert "Add InitParams for views::AuraInit"
>
> This reverts commit dfd53f1153.
>
> Reason for revert: GPU FYI Windows bots compile failure
> crbug.com/854442
>
> Compile error:
> [40824/45748] LINK task_viewer.service.exe task_viewer.service.exe.pdb
> FAILED: task_viewer.service.exe task_viewer.service.exe.pdb
> C:/b/swarming/w/ir/cache/vpython/80ee9f/Scripts/python.exe ../../build/toolchain/win/tool_wrapper.py link-wrapper environment.x64 False ../../third_party/llvm-build/Release+Asserts/bin/lld-link.exe /nologo /OUT:./task_viewer.service.exe /PDB:./task_viewer.service.exe.pdb @./task_viewer.service.exe.rsp
> C:\b\swarming\w\ir\cache\builder\src\third_party\llvm-build\Release+Asserts\bin\lld-link.exe: error: undefined symbol: ??0InitParams@AuraInit@views@@QEAA@XZ
> >>> referenced by obj/mash/task_viewer/lib/task_viewer.obj:(?OnStart@TaskViewer@task_viewer@mash@@EEAAXXZ)
> C:\b\swarming\w\ir\cache\builder\src\third_party\llvm-build\Release+Asserts\bin\lld-link.exe: error: undefined symbol: ??1InitParams@AuraInit@views@@QEAA@XZ
> >>> referenced by obj/mash/task_viewer/lib/task_viewer.obj:(?OnStart@TaskViewer@task_viewer@mash@@EEAAXXZ)
>
> Original change's description:
> > Add InitParams for views::AuraInit
> >
> > It's up to 7 parameters and I'm about to add an 8th.
> >
> > Bug: 851578
> > Test: existing tests
> > Change-Id: I5dbfb98c90861a334ef9046cec4d69fb756879a1
> > Reviewed-on: https://chromium-review.googlesource.com/1106431
> > Reviewed-by: Scott Violet <sky@chromium.org>
> > Commit-Queue: James Cook <jamescook@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#568594}
>
> TBR=jamescook@chromium.org,sky@chromium.org
>
> Change-Id: Iea7d59178394a95cbc6f419cd7079d00d66a8ac6
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 851578, 854442
> Reviewed-on: https://chromium-review.googlesource.com/1107139
> Reviewed-by: weiliangc <weiliangc@chromium.org>
> Commit-Queue: weiliangc <weiliangc@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#568678}

TBR=jamescook@chromium.org,sky@chromium.org,weiliangc@chromium.org

Change-Id: Id0a3e75d0e02c87165375ecc345553041ecc4252
Bug: 851578, 854442
Reviewed-on: https://chromium-review.googlesource.com/1107997
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568862}
This commit is contained in:
James Cook
2018-06-20 16:18:27 +00:00
committed by Commit Bot
parent 52b9372f38
commit fc1b03375d
12 changed files with 105 additions and 106 deletions

@ -93,11 +93,12 @@ AutoclickApplication::AutoclickApplication()
AutoclickApplication::~AutoclickApplication() = default;
void AutoclickApplication::OnStart() {
const bool register_path_provider = running_standalone_;
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS,
register_path_provider);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS;
params.register_path_provider = running_standalone_;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_) {
context()->QuitNow();
return;

@ -174,11 +174,12 @@ void QuickLaunchApplication::OnStart() {
// 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
// been notified yet. Close our ServiceContext and shutdown.
const bool register_path_provider = running_standalone_;
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS2,
register_path_provider);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS2;
params.register_path_provider = running_standalone_;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_) {
context()->QuitNow();
return;

@ -33,10 +33,12 @@ void ShortcutViewerApplication::RegisterForTraceEvents() {
}
void ShortcutViewerApplication::OnStart() {
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS2,
false /*register_path_provider*/);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS2;
params.register_path_provider = false;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_) {
context()->QuitNow();
return;

@ -45,11 +45,12 @@ void TapVisualizerApp::Start() {
}
void TapVisualizerApp::OnStart() {
const bool register_path_provider = false;
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS2,
register_path_provider);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS2;
params.register_path_provider = false;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_) {
context()->QuitNow();
return;

@ -179,11 +179,14 @@ void WindowManagerService::OnStart() {
registry_.AddInterface(base::BindRepeating(
&WindowManagerService::BindServiceFactory, base::Unretained(this)));
const bool register_path_provider = running_standalone_;
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(),
"ash_service_resources.pak", "ash_service_resources_200.pak", nullptr,
views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER, register_path_provider);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.resource_file = "ash_service_resources.pak";
params.resource_file_200 = "ash_service_resources_200.pak";
params.mode = views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER;
params.register_path_provider = running_standalone_;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_) {
context()->QuitNow();
return;

@ -222,9 +222,11 @@ void CatalogViewer::RemoveWindow(views::Widget* window) {
}
void CatalogViewer::OnStart() {
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_)
context()->QuitNow();
}

@ -31,10 +31,11 @@ class ViewsExamples : public service_manager::Service,
private:
// service_manager::Service:
void OnStart() override {
aura_init_ =
views::AuraInit::Create(context()->connector(), context()->identity(),
"views_mus_resources.pak", std::string(),
nullptr, views::AuraInit::Mode::AURA_MUS);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_)
context()->QuitNow();
}

@ -453,9 +453,11 @@ void WindowTypeLauncher::RemoveWindow(views::Widget* window) {
}
void WindowTypeLauncher::OnStart() {
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_)
context()->QuitNow();
}

@ -366,9 +366,11 @@ void SimpleWM::OnStart() {
started_ = true;
screen_ = std::make_unique<display::ScreenBase>();
display::Screen::SetScreenInstance(screen_.get());
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_) {
context()->QuitNow();
return;

@ -297,9 +297,11 @@ void TaskViewer::RemoveWindow(views::Widget* widget) {
}
void TaskViewer::OnStart() {
aura_init_ = views::AuraInit::Create(
context()->connector(), context()->identity(), "views_mus_resources.pak",
std::string(), nullptr, views::AuraInit::Mode::AURA_MUS);
views::AuraInit::InitParams params;
params.connector = context()->connector();
params.identity = context()->identity();
params.mode = views::AuraInit::Mode::AURA_MUS;
aura_init_ = views::AuraInit::Create(params);
if (!aura_init_)
context()->QuitNow();
}

@ -46,6 +46,10 @@ class MusViewsDelegate : public ViewsDelegate {
} // namespace
AuraInit::InitParams::InitParams() : resource_file("views_mus_resources.pak") {}
AuraInit::InitParams::~InitParams() = default;
AuraInit::AuraInit() {
if (!ViewsDelegate::GetInstance())
views_delegate_ = std::make_unique<MusViewsDelegate>();
@ -53,71 +57,53 @@ AuraInit::AuraInit() {
AuraInit::~AuraInit() = default;
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,
bool register_path_provider) {
// static
std::unique_ptr<AuraInit> AuraInit::Create(const InitParams& params) {
// Using 'new' to access a non-public constructor. go/totw/134
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, register_path_provider)) {
if (!aura_init->Init(params))
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,
bool register_path_provider) {
bool AuraInit::Init(const InitParams& params) {
env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS);
if (mode == Mode::AURA_MUS || mode == Mode::AURA_MUS2) {
MusClient::InitParams params;
params.connector = connector;
params.identity = identity;
params.io_task_runner = io_task_runner;
params.wtc_config = mode == Mode::AURA_MUS2
? aura::WindowTreeClient::Config::kMus2
: aura::WindowTreeClient::Config::kMash;
params.create_wm_state = true;
mus_client_ = std::make_unique<MusClient>(params);
if (params.mode == Mode::AURA_MUS || params.mode == Mode::AURA_MUS2) {
MusClient::InitParams mus_params;
mus_params.connector = params.connector;
mus_params.identity = params.identity;
mus_params.io_task_runner = params.io_task_runner;
mus_params.wtc_config = params.mode == Mode::AURA_MUS2
? aura::WindowTreeClient::Config::kMus2
: aura::WindowTreeClient::Config::kMash;
mus_params.create_wm_state = true;
mus_client_ = std::make_unique<MusClient>(mus_params);
}
// MaterialDesignController may have initialized already (such as happens
// in the utility process).
if (!ui::MaterialDesignController::is_mode_initialized())
ui::MaterialDesignController::Initialize();
if (!InitializeResources(connector, resource_file, resource_file_200,
register_path_provider)) {
if (!InitializeResources(params))
return false;
}
ui::InitializeInputMethodForTesting();
return true;
}
bool AuraInit::InitializeResources(service_manager::Connector* connector,
const std::string& resource_file,
const std::string& resource_file_200,
bool register_path_provider) {
bool AuraInit::InitializeResources(const InitParams& params) {
// Resources may have already been initialized (e.g. when chrome with mash is
// used to launch the current app).
if (ui::ResourceBundle::HasSharedInstance())
return true;
std::set<std::string> resource_paths({resource_file});
if (!resource_file_200.empty())
resource_paths.insert(resource_file_200);
std::set<std::string> resource_paths({params.resource_file});
if (!params.resource_file_200.empty())
resource_paths.insert(params.resource_file_200);
catalog::ResourceLoader loader;
filesystem::mojom::DirectoryPtr directory;
connector->BindInterface(catalog::mojom::kServiceName, &directory);
params.connector->BindInterface(catalog::mojom::kServiceName, &directory);
// TODO(jonross): if this proves useful in resolving the crash of
// mash_unittests then switch AuraInit to have an Init method, returning a
// bool for success. Then update all callsites to use this to determine the
@ -127,17 +113,17 @@ bool AuraInit::InitializeResources(service_manager::Connector* connector,
// Calling services will shutdown ServiceContext as appropriate.
if (!loader.OpenFiles(std::move(directory), resource_paths))
return false;
if (register_path_provider)
if (params.register_path_provider)
ui::RegisterPathProvider();
base::File pak_file = loader.TakeFile(resource_file);
base::File pak_file = loader.TakeFile(params.resource_file);
base::File pak_file_2 = pak_file.Duplicate();
ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
std::move(pak_file), base::MemoryMappedFile::Region::kWholeFile);
ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
std::move(pak_file_2), ui::SCALE_FACTOR_100P);
if (!resource_file_200.empty())
if (!params.resource_file_200.empty())
ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
loader.TakeFile(resource_file_200), ui::SCALE_FACTOR_200P);
loader.TakeFile(params.resource_file_200), ui::SCALE_FACTOR_200P);
return true;
}

@ -9,6 +9,7 @@
#include <string>
#include "base/macros.h"
#include "services/service_manager/public/cpp/identity.h"
#include "ui/aura/env.h"
#include "ui/views/mus/mus_export.h"
@ -22,7 +23,6 @@ class SingleThreadTaskRunner;
namespace service_manager {
class Connector;
class Identity;
}
namespace views {
@ -49,20 +49,24 @@ class VIEWS_MUS_EXPORT AuraInit {
~AuraInit();
struct VIEWS_MUS_EXPORT InitParams {
InitParams();
~InitParams();
service_manager::Connector* connector = nullptr;
service_manager::Identity identity;
// File for strings and 1x icons. Defaults to views_mus_resources.pak.
std::string resource_file;
// File for 2x icons. Can be empty.
std::string resource_file_200;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = nullptr;
Mode mode = Mode::AURA_MUS;
bool register_path_provider = true;
};
// 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_200| can be an empty string, otherwise it is the file to
// load 2x icons from.
static std::unique_ptr<AuraInit> Create(
service_manager::Connector* connector,
const service_manager::Identity& identity,
const std::string& resource_file,
const std::string& resource_file_200 = std::string(),
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = nullptr,
Mode mode = Mode::AURA_MUS,
bool register_path_provider = true);
static std::unique_ptr<AuraInit> Create(const InitParams& params);
// Only valid if Mode::AURA_MUS was passed to constructor.
MusClient* mus_client() { return mus_client_.get(); }
@ -73,18 +77,10 @@ class VIEWS_MUS_EXPORT AuraInit {
// Returns true if AuraInit was able to successfully complete initialization.
// If this returns false, then Aura is in an unusable state, and calling
// services should shutdown.
bool 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,
bool register_path_provider);
bool Init(const InitParams& params);
bool InitializeResources(service_manager::Connector* connector,
const std::string& resource_file,
const std::string& resource_file_200,
bool register_path_provider);
// Returns true on success.
bool InitializeResources(const InitParams& params);
std::unique_ptr<aura::Env> env_;
std::unique_ptr<MusClient> mus_client_;