Commit 2a0ba12b authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Fix cursor for chrome --mash

Grouping the ash service and ui service into the same process broke
image cursors. Fix it by providing the necessary task runner for cursor
resource loading. Make MashServiceRegistry into a class so it can hold
the cursor set.

Also refactor ui::Service InitParams to make it more clear when it is
running in-process vs. out-of-process.

Bug: 722527
Test: Run chrome --mash, hovering NTP tiles has hand cursor
Change-Id: Ie2b3fc9d523af9f06e16a1b6137f8481182169de
Reviewed-on: https://chromium-review.googlesource.com/832996Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526998}
parent 614a67e2
...@@ -50,6 +50,7 @@ specific_include_rules = { ...@@ -50,6 +50,7 @@ specific_include_rules = {
"+components/font_service/public/interfaces", "+components/font_service/public/interfaces",
"+mash/quick_launch/public", "+mash/quick_launch/public",
"+mash/quick_launch/quick_launch.h", "+mash/quick_launch/quick_launch.h",
"+services/ui/common/image_cursors_set.h",
"+services/ui/public", "+services/ui/public",
"+services/ui/service.h", "+services/ui/service.h",
], ],
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
#endif #endif
#endif #endif
#if BUILDFLAG(ENABLE_MUS) #if defined(OS_CHROMEOS)
#include "chrome/utility/mash_service_factory.h" #include "chrome/utility/mash_service_factory.h"
#endif #endif
...@@ -144,6 +144,10 @@ ChromeContentUtilityClient::ChromeContentUtilityClient() ...@@ -144,6 +144,10 @@ ChromeContentUtilityClient::ChromeContentUtilityClient()
(BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN))
handlers_.push_back(base::MakeUnique<printing::PrintingHandler>()); handlers_.push_back(base::MakeUnique<printing::PrintingHandler>());
#endif #endif
#if defined(OS_CHROMEOS)
mash_service_factory_ = std::make_unique<MashServiceFactory>();
#endif
} }
ChromeContentUtilityClient::~ChromeContentUtilityClient() = default; ChromeContentUtilityClient::~ChromeContentUtilityClient() = default;
...@@ -293,7 +297,8 @@ void ChromeContentUtilityClient::RegisterServices( ...@@ -293,7 +297,8 @@ void ChromeContentUtilityClient::RegisterServices(
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_EXTENSIONS)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
RegisterOutOfProcessMashServices(services); // TODO(jamescook): Figure out why we have to do this when not using --mash.
mash_service_factory_->RegisterOutOfProcessServices(services);
#endif #endif
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "content/public/utility/content_utility_client.h" #include "content/public/utility/content_utility_client.h"
class MashServiceFactory;
class UtilityMessageHandler; class UtilityMessageHandler;
class ChromeContentUtilityClient : public content::ContentUtilityClient { class ChromeContentUtilityClient : public content::ContentUtilityClient {
...@@ -42,6 +43,11 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient { ...@@ -42,6 +43,11 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient {
// True if the utility process runs with elevated privileges. // True if the utility process runs with elevated privileges.
bool utility_process_running_elevated_; bool utility_process_running_elevated_;
#if defined(OS_CHROMEOS)
// Must be owned by utility main thread.
std::unique_ptr<MashServiceFactory> mash_service_factory_;
#endif
DISALLOW_COPY_AND_ASSIGN(ChromeContentUtilityClient); DISALLOW_COPY_AND_ASSIGN(ChromeContentUtilityClient);
}; };
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/font_service/public/interfaces/constants.mojom.h" #include "components/font_service/public/interfaces/constants.mojom.h"
#include "mash/quick_launch/public/interfaces/constants.mojom.h" #include "mash/quick_launch/public/interfaces/constants.mojom.h"
#include "mash/quick_launch/quick_launch.h" #include "mash/quick_launch/quick_launch.h"
#include "services/ui/common/image_cursors_set.h"
#include "services/ui/public/interfaces/constants.mojom.h" #include "services/ui/public/interfaces/constants.mojom.h"
#include "services/ui/service.h" #include "services/ui/service.h"
...@@ -32,25 +33,31 @@ void RegisterMashService( ...@@ -32,25 +33,31 @@ void RegisterMashService(
services->emplace(name, service_info); services->emplace(name, service_info);
} }
// Runs on the UI service main thread.
// NOTE: For --mus the UI service is created at the //chrome/browser layer, // NOTE: For --mus the UI service is created at the //chrome/browser layer,
// not in //content. See ServiceManagerContext. // not in //content. See ServiceManagerContext.
std::unique_ptr<service_manager::Service> CreateUiService( std::unique_ptr<service_manager::Service> CreateUiService(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { const scoped_refptr<base::SingleThreadTaskRunner>& resource_runner,
ui::Service::InProcessConfig config; base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr) {
config.resource_runner = task_runner; ui::Service::InitParams params;
// TODO(jamescook): Fix cursor loading. params.running_standalone = false;
config.should_host_viz = true; params.resource_runner = resource_runner;
return std::make_unique<ui::Service>(&config); params.image_cursors_set_weak_ptr = image_cursors_set_weak_ptr;
params.should_host_viz = true;
return std::make_unique<ui::Service>(params);
} }
// Runs on the utility process main thread.
void RegisterUiService( void RegisterUiService(
content::ContentUtilityClient::StaticServiceMap* services) { content::ContentUtilityClient::StaticServiceMap* services,
ui::ImageCursorsSet* cursors) {
service_manager::EmbeddedServiceInfo service_info; service_manager::EmbeddedServiceInfo service_info;
service_info.use_own_thread = true; service_info.use_own_thread = true;
service_info.message_loop_type = base::MessageLoop::TYPE_UI; service_info.message_loop_type = base::MessageLoop::TYPE_UI;
service_info.thread_priority = base::ThreadPriority::DISPLAY; service_info.thread_priority = base::ThreadPriority::DISPLAY;
service_info.factory = base::BindRepeating( service_info.factory =
&CreateUiService, base::ThreadTaskRunnerHandle::Get()); base::BindRepeating(&CreateUiService, base::ThreadTaskRunnerHandle::Get(),
cursors->GetWeakPtr());
services->emplace(ui::mojom::kServiceName, service_info); services->emplace(ui::mojom::kServiceName, service_info);
} }
...@@ -78,9 +85,14 @@ std::unique_ptr<service_manager::Service> CreateFontService() { ...@@ -78,9 +85,14 @@ std::unique_ptr<service_manager::Service> CreateFontService() {
} // namespace } // namespace
void RegisterOutOfProcessMashServices( MashServiceFactory::MashServiceFactory()
: cursors_(std::make_unique<ui::ImageCursorsSet>()) {}
MashServiceFactory::~MashServiceFactory() = default;
void MashServiceFactory::RegisterOutOfProcessServices(
content::ContentUtilityClient::StaticServiceMap* services) { content::ContentUtilityClient::StaticServiceMap* services) {
RegisterUiService(services); RegisterUiService(services, cursors_.get());
RegisterMashService(services, mash::quick_launch::mojom::kServiceName, RegisterMashService(services, mash::quick_launch::mojom::kServiceName,
&CreateQuickLaunch); &CreateQuickLaunch);
RegisterMashService(services, ash::mojom::kServiceName, &CreateAshService); RegisterMashService(services, ash::mojom::kServiceName, &CreateAshService);
......
...@@ -5,10 +5,29 @@ ...@@ -5,10 +5,29 @@
#ifndef CHROME_UTILITY_MASH_SERVICE_FACTORY_H_ #ifndef CHROME_UTILITY_MASH_SERVICE_FACTORY_H_
#define CHROME_UTILITY_MASH_SERVICE_FACTORY_H_ #define CHROME_UTILITY_MASH_SERVICE_FACTORY_H_
#include <memory>
#include "content/public/utility/content_utility_client.h" #include "content/public/utility/content_utility_client.h"
// Registers the out-of-process services for --mash. namespace ui {
void RegisterOutOfProcessMashServices( class ImageCursorsSet;
content::ContentUtilityClient::StaticServiceMap* services); }
// Lives on the utility process main thread.
class MashServiceFactory {
public:
MashServiceFactory();
~MashServiceFactory();
// Registers out-of-process services for --mash.
void RegisterOutOfProcessServices(
content::ContentUtilityClient::StaticServiceMap* services);
private:
// Must live on the utility main thread.
std::unique_ptr<ui::ImageCursorsSet> cursors_;
DISALLOW_COPY_AND_ASSIGN(MashServiceFactory);
};
#endif // CHROME_UTILITY_MASH_SERVICE_FACTORY_H_ #endif // CHROME_UTILITY_MASH_SERVICE_FACTORY_H_
...@@ -272,12 +272,13 @@ std::unique_ptr<service_manager::Service> CreateEmbeddedUIService( ...@@ -272,12 +272,13 @@ std::unique_ptr<service_manager::Service> CreateEmbeddedUIService(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr, base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr,
discardable_memory::DiscardableSharedMemoryManager* memory_manager) { discardable_memory::DiscardableSharedMemoryManager* memory_manager) {
ui::Service::InProcessConfig config; ui::Service::InitParams params;
config.resource_runner = task_runner; params.running_standalone = false;
config.image_cursors_set_weak_ptr = image_cursors_set_weak_ptr; params.resource_runner = task_runner;
config.memory_manager = memory_manager; params.image_cursors_set_weak_ptr = image_cursors_set_weak_ptr;
config.should_host_viz = switches::IsMusHostingViz(); params.memory_manager = memory_manager;
return std::make_unique<ui::Service>(&config); params.should_host_viz = switches::IsMusHostingViz();
return std::make_unique<ui::Service>(params);
} }
void RegisterUIServiceInProcessIfNecessary( void RegisterUIServiceInProcessIfNecessary(
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#include "services/ui/service.h" #include "services/ui/service.h"
MojoResult ServiceMain(MojoHandle service_request_handle) { MojoResult ServiceMain(MojoHandle service_request_handle) {
ui::Service* ui_service = new ui::Service; ui::Service::InitParams params;
ui_service->set_running_standalone(true); params.running_standalone = true;
ui::Service* ui_service = new ui::Service(params);
service_manager::ServiceRunner runner(ui_service); service_manager::ServiceRunner runner(ui_service);
runner.set_message_loop_type(base::MessageLoop::TYPE_UI); runner.set_message_loop_type(base::MessageLoop::TYPE_UI);
return runner.Run(service_request_handle); return runner.Run(service_request_handle);
......
...@@ -80,27 +80,22 @@ const char kResourceFile200[] = "mus_app_resources_200.pak"; ...@@ -80,27 +80,22 @@ const char kResourceFile200[] = "mus_app_resources_200.pak";
class ThreadedImageCursorsFactoryImpl : public ws::ThreadedImageCursorsFactory { class ThreadedImageCursorsFactoryImpl : public ws::ThreadedImageCursorsFactory {
public: public:
// Uses the same InProcessConfig as the UI Service. |config| will be null when explicit ThreadedImageCursorsFactoryImpl(const Service::InitParams& params) {
// the UI Service runs in it's own separate process as opposed to the WM's // When running in-process use |resource_runner_| to load cursors.
// process. if (params.resource_runner) {
explicit ThreadedImageCursorsFactoryImpl( resource_runner_ = params.resource_runner;
const Service::InProcessConfig* config) { // |params.image_cursors_set_weak_ptr| must be set, but don't DCHECK
if (config) { // because it can only be dereferenced on |resource_runner_|.
resource_runner_ = config->resource_runner; image_cursors_set_weak_ptr_ = params.image_cursors_set_weak_ptr;
image_cursors_set_weak_ptr_ = config->image_cursors_set_weak_ptr;
DCHECK(resource_runner_);
} }
} }
~ThreadedImageCursorsFactoryImpl() override {} ~ThreadedImageCursorsFactoryImpl() override = default;
// ws::ThreadedImageCursorsFactory: // ws::ThreadedImageCursorsFactory:
std::unique_ptr<ws::ThreadedImageCursors> CreateCursors() override { std::unique_ptr<ws::ThreadedImageCursors> CreateCursors() override {
// |resource_runner_| will not be initialized if and only if UI Service runs // When running out-of-process lazily initialize the resource runner to the
// in it's own separate process. In this case we can (lazily) initialize it // UI service's thread.
// to the current thread (i.e. the UI Services's thread). We also initialize
// the local |image_cursors_set_| and make |image_cursors_set_weak_ptr_|
// point to it.
if (!resource_runner_) { if (!resource_runner_) {
resource_runner_ = base::ThreadTaskRunnerHandle::Get(); resource_runner_ = base::ThreadTaskRunnerHandle::Get();
image_cursors_set_ = std::make_unique<ui::ImageCursorsSet>(); image_cursors_set_ = std::make_unique<ui::ImageCursorsSet>();
...@@ -135,19 +130,21 @@ struct Service::UserState { ...@@ -135,19 +130,21 @@ struct Service::UserState {
std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory;
}; };
Service::InProcessConfig::InProcessConfig() = default; Service::InitParams::InitParams() = default;
Service::InProcessConfig::~InProcessConfig() = default; Service::InitParams::~InitParams() = default;
Service::Service(const InProcessConfig* config) Service::Service(const InitParams& params)
: is_in_process_(config != nullptr), : running_standalone_(params.running_standalone),
threaded_image_cursors_factory_( threaded_image_cursors_factory_(
std::make_unique<ThreadedImageCursorsFactoryImpl>(config)), std::make_unique<ThreadedImageCursorsFactoryImpl>(params)),
test_config_(false), test_config_(false),
ime_registrar_(&ime_driver_), ime_registrar_(&ime_driver_),
discardable_shared_memory_manager_(config ? config->memory_manager discardable_shared_memory_manager_(params.memory_manager),
: nullptr), should_host_viz_(params.should_host_viz) {
should_host_viz_(!config || config->should_host_viz) {} // UI service must host viz when running in its own process.
DCHECK(!running_standalone_ || should_host_viz_);
}
Service::~Service() { Service::~Service() {
in_destructor_ = true; in_destructor_ = true;
...@@ -171,7 +168,7 @@ Service::~Service() { ...@@ -171,7 +168,7 @@ Service::~Service() {
} }
bool Service::InitializeResources(service_manager::Connector* connector) { bool Service::InitializeResources(service_manager::Connector* connector) {
if (is_in_process() || ui::ResourceBundle::HasSharedInstance()) if (!running_standalone_ || ui::ResourceBundle::HasSharedInstance())
return true; return true;
std::set<std::string> resource_paths; std::set<std::string> resource_paths;
...@@ -187,8 +184,7 @@ bool Service::InitializeResources(service_manager::Connector* connector) { ...@@ -187,8 +184,7 @@ bool Service::InitializeResources(service_manager::Connector* connector) {
return false; return false;
} }
if (running_standalone_) ui::RegisterPathProvider();
ui::RegisterPathProvider();
// Initialize resource bundle with 1x and 2x cursor bitmaps. // Initialize resource bundle with 1x and 2x cursor bitmaps.
ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
...@@ -256,7 +252,7 @@ void Service::OnStart() { ...@@ -256,7 +252,7 @@ void Service::OnStart() {
ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()
->SetCurrentLayoutByName("us"); ->SetCurrentLayoutByName("us");
if (!is_in_process()) { if (running_standalone_) {
client_native_pixmap_factory_ = ui::CreateClientNativePixmapFactoryOzone(); client_native_pixmap_factory_ = ui::CreateClientNativePixmapFactoryOzone();
gfx::ClientNativePixmapFactory::SetInstance( gfx::ClientNativePixmapFactory::SetInstance(
client_native_pixmap_factory_.get()); client_native_pixmap_factory_.get());
...@@ -411,8 +407,9 @@ void Service::OnWillCreateTreeForWindowManager( ...@@ -411,8 +407,9 @@ void Service::OnWillCreateTreeForWindowManager(
ws::DisplayCreationConfig::MANUAL) { ws::DisplayCreationConfig::MANUAL) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
display::ScreenManagerForwarding::Mode mode = display::ScreenManagerForwarding::Mode mode =
is_in_process() ? display::ScreenManagerForwarding::Mode::IN_WM_PROCESS running_standalone_
: display::ScreenManagerForwarding::Mode::OWN_PROCESS; ? display::ScreenManagerForwarding::Mode::OWN_PROCESS
: display::ScreenManagerForwarding::Mode::IN_WM_PROCESS;
screen_manager_ = std::make_unique<display::ScreenManagerForwarding>(mode); screen_manager_ = std::make_unique<display::ScreenManagerForwarding>(mode);
#else #else
CHECK(false); CHECK(false);
......
...@@ -74,11 +74,12 @@ class WindowServer; ...@@ -74,11 +74,12 @@ class WindowServer;
class Service : public service_manager::Service, class Service : public service_manager::Service,
public ws::WindowServerDelegate { public ws::WindowServerDelegate {
public: public:
// Contains the configuration necessary to run the UI Service inside the struct InitParams {
// Window Manager's process. InitParams();
struct InProcessConfig { ~InitParams();
InProcessConfig();
~InProcessConfig(); // UI service runs in its own process (i.e. not embedded in browser or ash).
bool running_standalone = false;
// Can be used to load resources. // Can be used to load resources.
scoped_refptr<base::SingleThreadTaskRunner> resource_runner = nullptr; scoped_refptr<base::SingleThreadTaskRunner> resource_runner = nullptr;
...@@ -95,17 +96,12 @@ class Service : public service_manager::Service, ...@@ -95,17 +96,12 @@ class Service : public service_manager::Service,
bool should_host_viz = true; bool should_host_viz = true;
private: private:
DISALLOW_COPY_AND_ASSIGN(InProcessConfig); DISALLOW_COPY_AND_ASSIGN(InitParams);
}; };
// |config| should be null when UI Service runs in it's own separate process, explicit Service(const InitParams& params);
// as opposed to inside the Window Manager's process.
explicit Service(const InProcessConfig* config = nullptr);
~Service() override; ~Service() override;
// Call if the ui::Service is being run as a standalone process.
void set_running_standalone(bool value) { running_standalone_ = value; }
private: private:
// Holds InterfaceRequests received before the first WindowTreeHost Display // Holds InterfaceRequests received before the first WindowTreeHost Display
// has been established. // has been established.
...@@ -114,8 +110,6 @@ class Service : public service_manager::Service, ...@@ -114,8 +110,6 @@ class Service : public service_manager::Service,
using UserIdToUserState = std::map<ws::UserId, std::unique_ptr<UserState>>; using UserIdToUserState = std::map<ws::UserId, std::unique_ptr<UserState>>;
bool is_in_process() const { return is_in_process_; }
// Attempts to initialize the resource bundle. Returns true if successful, // Attempts to initialize the resource bundle. Returns true if successful,
// otherwise false if resources cannot be loaded. // otherwise false if resources cannot be loaded.
bool InitializeResources(service_manager::Connector* connector); bool InitializeResources(service_manager::Connector* connector);
...@@ -204,9 +198,9 @@ class Service : public service_manager::Service, ...@@ -204,9 +198,9 @@ class Service : public service_manager::Service,
// and must outlive |registry_|. // and must outlive |registry_|.
InputDeviceServer input_device_server_; InputDeviceServer input_device_server_;
// True if the UI Service runs inside WM's process, false if it runs inside // True if the UI Service runs runs inside its own process, false if it is
// its own process. // embedded in another process.
const bool is_in_process_; const bool running_standalone_;
std::unique_ptr<ws::ThreadedImageCursorsFactory> std::unique_ptr<ws::ThreadedImageCursorsFactory>
threaded_image_cursors_factory_; threaded_image_cursors_factory_;
...@@ -248,8 +242,6 @@ class Service : public service_manager::Service, ...@@ -248,8 +242,6 @@ class Service : public service_manager::Service,
bool in_destructor_ = false; bool in_destructor_ = false;
bool running_standalone_ = false;
DISALLOW_COPY_AND_ASSIGN(Service); DISALLOW_COPY_AND_ASSIGN(Service);
}; };
......
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