Commit 0eea3b2f authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: makes WindowService available in classic builds

This makes it so that if an app requests the WindowService it's
launched in Ash. This is only enabled if --mash and --mus is not
specified.

BUG=837686
TEST=none

Change-Id: Ic01879e0aff8828b17c0652bd74078daba628d40
Reviewed-on: https://chromium-review.googlesource.com/1045248
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556338}
parent ab0defd8
......@@ -2887,6 +2887,7 @@ jumbo_split_static_library("browser") {
"//services/ui/public/cpp/input_devices",
"//services/ui/public/cpp/input_devices:input_device_controller",
"//services/ui/public/interfaces",
"//services/ui/ws2:lib",
"//ui/ozone",
]
allow_circular_includes_from += [ "//chrome/browser/chromeos" ]
......
......@@ -209,8 +209,15 @@ include_rules = [
]
specific_include_rules = {
"browser_process_platform_part_chromeos\.cc": [
# AshService is necessary while Ash runs in process.
"ash_service_registry\.cc": [
# The following are needed for classic mode to create the WindowService.
# Once Ash runs out of process no longer needed.
"+ash/content/content_gpu_support.h",
"+ash/shell.h",
"+ash/ws/window_service_delegate_impl.h",
"+services/ui/ws2/window_service.h",
# Needed for classic mode.
"+ash/ash_service.h",
],
# TODO(mash): see bugs 768439 and 768395.
......
......@@ -4,13 +4,21 @@
#include "chrome/browser/ash_service_registry.h"
#include "ash/ash_service.h"
#include "ash/components/quick_launch/public/mojom/constants.mojom.h"
#include "ash/content/content_gpu_support.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "ash/shell.h"
#include "ash/ws/window_service_delegate_impl.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "chrome/browser/chromeos/prefs/pref_connector_service.h"
#include "components/services/font/public/interfaces/constants.mojom.h"
#include "services/ui/public/interfaces/constants.mojom.h"
#include "services/ui/ws2/window_service.h"
#include "ui/base/ui_base_features.h"
using content::ContentBrowserClient;
......@@ -23,42 +31,106 @@ struct Service {
const char* process_group; // If null, uses a separate process.
};
constexpr Service kServices[] = {
// Services shared between mash and non-mash configs.
constexpr Service kCommonServices[] = {
{quick_launch::mojom::kServiceName, "Quick Launch", nullptr},
{ui::mojom::kServiceName, "UI Service", kAshAndUiProcessGroup},
{ash::mojom::kServiceName, "Ash Window Manager and Shell",
kAshAndUiProcessGroup},
{"autoclick_app", "Accessibility Autoclick", nullptr},
{"touch_hud_app", "Touch HUD", nullptr},
{font_service::mojom::kServiceName, "Font Service", nullptr},
};
} // namespace
// Services unique to mash. Note that the non-mash case also has an Ash service,
// it's just registered differently (see RegisterInProcessServices()).
constexpr Service kMashServices[] = {
{ui::mojom::kServiceName, "UI Service", kAshAndUiProcessGroup},
{ash::mojom::kServiceName, "Ash Window Manager and Shell",
kAshAndUiProcessGroup},
};
void RegisterOutOfProcessServices(
ContentBrowserClient::OutOfProcessServiceMap* services) {
for (const auto& service : kServices) {
void RegisterOutOfProcessServicesImpl(
const Service* services,
size_t num_services,
ContentBrowserClient::OutOfProcessServiceMap* services_map) {
for (size_t i = 0; i < num_services; ++i) {
const Service& service = services[i];
base::string16 display_name = base::ASCIIToUTF16(service.display_name);
if (service.process_group) {
(*services)[service.name] = ContentBrowserClient::OutOfProcessServiceInfo(
display_name, service.process_group);
(*services_map)[service.name] =
ContentBrowserClient::OutOfProcessServiceInfo(display_name,
service.process_group);
} else {
(*services)[service.name] =
(*services_map)[service.name] =
ContentBrowserClient::OutOfProcessServiceInfo(display_name);
}
}
}
std::unique_ptr<service_manager::Service> CreateEmbeddedWindowService() {
return std::make_unique<ui::ws2::WindowService>(
ash::Shell::Get()->window_service_delegate(),
std::make_unique<ash::ContentGpuSupport>());
}
} // namespace
void RegisterOutOfProcessServices(
ContentBrowserClient::OutOfProcessServiceMap* services) {
if (base::FeatureList::IsEnabled(features::kMash)) {
RegisterOutOfProcessServicesImpl(kCommonServices,
base::size(kCommonServices), services);
RegisterOutOfProcessServicesImpl(kMashServices, base::size(kMashServices),
services);
} else {
RegisterOutOfProcessServicesImpl(kCommonServices,
base::size(kCommonServices), services);
}
}
void RegisterInProcessServices(
content::ContentBrowserClient::StaticServiceMap* services) {
{
service_manager::EmbeddedServiceInfo info;
info.factory =
base::BindRepeating([]() -> std::unique_ptr<service_manager::Service> {
return std::make_unique<AshPrefConnector>();
});
info.task_runner = base::ThreadTaskRunnerHandle::Get();
(*services)[ash::mojom::kPrefConnectorServiceName] = info;
}
if (base::FeatureList::IsEnabled(features::kMash))
return;
(*services)[ash::mojom::kServiceName] =
ash::AshService::CreateEmbeddedServiceInfo();
service_manager::EmbeddedServiceInfo ui_service_info;
ui_service_info.factory = base::BindRepeating(&CreateEmbeddedWindowService);
ui_service_info.task_runner = base::ThreadTaskRunnerHandle::Get();
(*services)[ui::mojom::kServiceName] = ui_service_info;
}
bool IsAshRelatedServiceName(const std::string& name) {
for (size_t i = 0; i < base::size(kServices); ++i) {
if (name == kServices[i].name)
for (const Service& service : kMashServices) {
if (name == service.name)
return true;
}
for (const Service& service : kCommonServices) {
if (name == service.name)
return true;
}
return false;
}
std::string GetAshRelatedServiceLabel(const std::string& service_name) {
for (const Service& service : kServices) {
for (const Service& service : kMashServices) {
if (service_name == service.name) {
// Use the process group name when available because that makes it more
// obvious that multiple services are running in the same process.
return service.process_group ? service.process_group : service.name;
}
}
for (const Service& service : kCommonServices) {
if (service_name == service.name) {
// Use the process group name when available because that makes it more
// obvious that multiple services are running in the same process.
......
......@@ -14,10 +14,14 @@ namespace ash_service_registry {
// Process group used for the ash service and the ui service. Visible for test.
constexpr char kAshAndUiProcessGroup[] = "ash_and_ui";
// Starts one of Mash's embedded services.
// Registers the set of Ash related services that run out of process.
void RegisterOutOfProcessServices(
content::ContentBrowserClient::OutOfProcessServiceMap* services);
// Registers the set of Ash related services that run in process.
void RegisterInProcessServices(
content::ContentBrowserClient::StaticServiceMap* services);
// Returns true if |name| identifies an Ash related service.
bool IsAshRelatedServiceName(const std::string& name);
......
......@@ -6,11 +6,15 @@
#include "ash/public/interfaces/constants.mojom.h"
#include "base/stl_util.h"
#include "base/test/scoped_feature_list.h"
#include "content/public/browser/content_browser_client.h"
#include "services/ui/public/interfaces/constants.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ui_base_features.h"
TEST(AshServiceRegistryTest, AshAndUiInSameProcess) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kMash);
content::ContentBrowserClient::OutOfProcessServiceMap services;
ash_service_registry::RegisterOutOfProcessServices(&services);
......
......@@ -6,11 +6,11 @@
#include <utility>
#include "ash/ash_service.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "base/logging.h"
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
#include "chrome/browser/ash_service_registry.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/ash_config.h"
#include "chrome/browser/chromeos/chrome_service_name.h"
......@@ -18,7 +18,6 @@
#include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
#include "chrome/browser/chromeos/net/delay_network_call.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/prefs/pref_connector_service.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
......@@ -28,7 +27,6 @@
#include "chrome/browser/chromeos/system/timezone_resolver_manager.h"
#include "chrome/browser/chromeos/system/timezone_util.h"
#include "chrome/browser/component_updater/cros_component_installer.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/account_manager/account_manager_factory.h"
......@@ -182,22 +180,7 @@ BrowserProcessPlatformPart::CreateBrowserPolicyConnector() {
void BrowserProcessPlatformPart::RegisterInProcessServices(
content::ContentBrowserClient::StaticServiceMap* services) {
{
service_manager::EmbeddedServiceInfo info;
info.factory = base::Bind([] {
return std::unique_ptr<service_manager::Service>(
std::make_unique<AshPrefConnector>());
});
info.task_runner = base::ThreadTaskRunnerHandle::Get();
services->insert(
std::make_pair(ash::mojom::kPrefConnectorServiceName, info));
}
if (!ash_util::IsRunningInMash()) {
services->insert(
std::make_pair(ash::mojom::kServiceName,
ash::AshService::CreateEmbeddedServiceInfo()));
}
ash_service_registry::RegisterInProcessServices(services);
}
chromeos::system::SystemClock* BrowserProcessPlatformPart::GetSystemClock() {
......
......@@ -2079,6 +2079,12 @@ void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine(
command_line->AppendSwitchASCII(
switches::kMashServiceName,
ash_service_registry::GetAshRelatedServiceLabel(identity.name()));
if (!base::FeatureList::IsEnabled(features::kMash)) {
// TODO(sky): this is necessary because WindowTreeClient only connects to
// the gpu related interfaces if Mash is set.
command_line->AppendSwitchASCII(switches::kEnableFeatures,
features::kMash.name);
}
}
#endif
// TODO(sky): move to a whitelist, but currently the set of flags is rather
......@@ -3426,8 +3432,7 @@ void ChromeContentBrowserClient::RegisterOutOfProcessServices(
l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_UNZIP_NAME);
#if defined(OS_CHROMEOS)
if (base::FeatureList::IsEnabled(features::kMash))
ash_service_registry::RegisterOutOfProcessServices(services);
ash_service_registry::RegisterOutOfProcessServices(services);
#endif
}
......
......@@ -411,8 +411,6 @@ TEST(ChromeContentBrowserClientTest, GetMetricSuffixForURL) {
#if defined(OS_CHROMEOS)
// This behavior only matters on Chrome OS, which is why this isn't wrapped in
// ENABLE_MASH_PACKAGED_SERVICES (which is used for Linux Ozone).
TEST(ChromeContentBrowserClientTest, ShouldTerminateOnServiceQuit) {
const struct {
std::string service_name;
......
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