0

Flatten Service Manager directory structure moar

Wipes out services/service_manager/runner. Most of the references to
this (specifically to runner/common) were already unused remnants of
Mash logic that no longer exists.

Stuff that's still relevant only really matters to Service Manager
internals or the service executable helper library, so it's been moved
accordingly.

Bug: 904240
Change-Id: I4e65e2c58d13b2137d455ac3b306db81b846be1c
Reviewed-on: https://chromium-review.googlesource.com/c/1453545
Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#629737}
This commit is contained in:
Ken Rockot
2019-02-06 21:41:32 +00:00
committed by Commit Bot
parent e09fd2d8b0
commit 1e93aedb2f
44 changed files with 171 additions and 384 deletions

@ -43,7 +43,6 @@
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/ws/public/cpp/input_devices/input_device_controller.h"
#include "services/ws/public/cpp/input_devices/input_device_controller_client.h"
#include "services/ws/public/mojom/constants.mojom.h"

@ -313,7 +313,6 @@
#endif // BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if defined(USE_AURA)
#include "services/service_manager/runner/common/client_util.h"
#include "ui/aura/env.h"
#endif
@ -1172,13 +1171,6 @@ void ChromeBrowserMainParts::ServiceManagerConnectionStarted(
}
void ChromeBrowserMainParts::PreMainMessageLoopRun() {
#if defined(USE_AURA)
if (content::ServiceManagerConnection::GetForProcess() &&
service_manager::ServiceManagerIsRemote()) {
content::ServiceManagerConnection::GetForProcess()->
SetConnectionLostClosure(base::Bind(&chrome::SessionEnding));
}
#endif
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRun");
result_code_ = PreMainMessageLoopRunImpl();

@ -214,7 +214,6 @@ source_set("chromeos") {
"//services/preferences/public/mojom",
"//services/resource_coordinator/public/cpp:resource_coordinator_cpp",
"//services/service_manager/public/cpp",
"//services/service_manager/runner/common",
"//services/ws/public/cpp",
"//services/ws/public/cpp/input_devices",
"//skia",

@ -511,7 +511,6 @@ jumbo_split_static_library("ui") {
"//services/identity/public/cpp",
"//services/metrics/public/cpp:ukm_builders",
"//services/network/public/mojom",
"//services/service_manager/runner/common",
"//skia",
"//storage/browser",
"//storage/common",

@ -26,7 +26,6 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/ws/public/cpp/gpu/gpu.h" // nogncheck
#include "services/ws/public/mojom/constants.mojom.h"
#include "ui/display/screen.h"

@ -33,7 +33,6 @@
#include "content/public/test/network_service_test_helper.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/test_utils.h"
#include "services/service_manager/runner/common/switches.h"
#include "ui/base/test/ui_controls.h"
#if defined(OS_MACOSX)

@ -30,7 +30,6 @@ template("implement_content_app") {
"//crypto",
"//services/service_manager/embedder",
"//services/service_manager/public/mojom",
"//services/service_manager/runner/common",
"//services/tracing/public/cpp",
"//mojo/core/embedder",
"//ppapi/buildflags",

@ -11,6 +11,5 @@ include_rules = [
"+services/network/public/cpp/features.h",
"+services/tracing/public/cpp",
"+services/service_manager/embedder",
"+services/service_manager/runner/common",
"+services/service_manager/sandbox/sandbox_type.h",
]

@ -10,7 +10,6 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/service_names.mojom.h"
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/runner/common/client_util.h"
namespace content {
@ -68,10 +67,10 @@ void ContentServiceManagerMainDelegate::OverrideMojoConfiguration(
mojo::core::Configuration* config) {
// If this is the browser process and there's no remote service manager, we
// will serve as the global Mojo broker.
if (!service_manager::ServiceManagerIsRemote() &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kProcessType))
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kProcessType)) {
config->is_broker_process = true;
}
}
std::vector<service_manager::Manifest>

@ -158,7 +158,6 @@ jumbo_source_set("browser") {
"//services/service_manager/embedder:embedder_result_codes",
"//services/service_manager/public/cpp",
"//services/service_manager/public/mojom",
"//services/service_manager/runner/common",
"//services/service_manager/zygote:zygote_buildflags",
"//services/shape_detection:lib",
"//services/shape_detection/public/mojom",

@ -139,7 +139,6 @@
#include "services/resource_coordinator/public/cpp/memory_instrumentation/client_process_impl.h"
#include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
#include "services/resource_coordinator/public/mojom/service_constants.mojom.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/zygote/common/zygote_buildflags.h"
#include "skia/ext/event_tracer_impl.h"
#include "skia/ext/skia_memory_dump_provider.h"

@ -62,7 +62,6 @@
#include "gpu/ipc/client/gpu_channel_host.h"
#include "gpu/ipc/host/gpu_memory_buffer_support.h"
#include "gpu/vulkan/buildflags.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/ws/public/cpp/gpu/context_provider_command_buffer.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "ui/base/ui_base_features.h"

@ -37,7 +37,6 @@
#include "gpu/ipc/common/gpu_client_ids.h"
#include "gpu/ipc/in_process_command_buffer.h"
#include "services/resource_coordinator/public/mojom/memory_instrumentation/constants.mojom.h"
#include "services/service_manager/runner/common/client_util.h"
#include "ui/base/ui_base_features.h"
#if defined(OS_MACOSX)

@ -73,7 +73,6 @@
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/sandbox/sandbox_type.h"
#include "services/service_manager/sandbox/switches.h"
#include "services/ws/public/mojom/constants.mojom.h"

@ -209,8 +209,6 @@
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/runner/common/switches.h"
#include "services/service_manager/sandbox/switches.h"
#include "services/service_manager/zygote/common/zygote_buildflags.h"
#include "storage/browser/fileapi/sandbox_file_system_backend.h"
@ -3155,10 +3153,6 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
}
}
DCHECK(child_connection_);
renderer_cmd->AppendSwitchASCII(service_manager::switches::kServicePipeToken,
child_connection_->service_token());
#if defined(OS_WIN) && !defined(OFFICIAL_BUILD)
// Needed because we can't show the dialog from the sandbox. Don't pass
// --no-sandbox in official builds because that would bypass the bad_flgs

@ -41,7 +41,6 @@
#include "content/public/browser/guest_mode.h"
#include "content/public/browser/render_process_host.h"
#include "gpu/ipc/common/gpu_messages.h"
#include "services/service_manager/runner/common/client_util.h"
#include "third_party/blink/public/platform/web_touch_event.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/geometry/dip_util.h"

@ -80,7 +80,6 @@
#include "services/service_manager/public/cpp/manifest.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/mojom/service.mojom.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/sandbox/sandbox_type.h"
#include "services/service_manager/service_manager.h"
#include "services/service_manager/service_process_launcher.h"
@ -529,45 +528,37 @@ ServiceManagerContext::ServiceManagerContext(
// The |service_manager_thread_task_runner_| must have been created before
// starting the ServiceManager.
DCHECK(service_manager_thread_task_runner_);
service_manager::mojom::ServiceRequest packaged_services_request;
if (service_manager::ServiceManagerIsRemote()) {
auto endpoint = mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
*base::CommandLine::ForCurrentProcess());
auto invitation = mojo::IncomingInvitation::Accept(std::move(endpoint));
packaged_services_request =
service_manager::GetServiceRequestFromCommandLine(&invitation);
} else {
std::vector<service_manager::Manifest> manifests{
GetContentBrowserManifest(), GetContentGpuManifest(),
GetContentPackagedServicesManifest(), GetContentPluginManifest(),
GetContentRendererManifest(), GetContentUtilityManifest(),
};
for (auto& manifest : manifests) {
base::Optional<service_manager::Manifest> overlay =
GetContentClient()->browser()->GetServiceManifestOverlay(
manifest.service_name);
if (overlay)
manifest.Amend(*overlay);
if (!manifest.preloaded_files.empty()) {
std::map<std::string, base::FilePath> preloaded_files_map;
for (const auto& info : manifest.preloaded_files)
preloaded_files_map.emplace(info.key, info.path);
ChildProcessLauncher::SetRegisteredFilesForService(
manifest.service_name, std::move(preloaded_files_map));
}
std::vector<service_manager::Manifest> manifests{
GetContentBrowserManifest(), GetContentGpuManifest(),
GetContentPackagedServicesManifest(), GetContentPluginManifest(),
GetContentRendererManifest(), GetContentUtilityManifest(),
};
for (auto& manifest : manifests) {
base::Optional<service_manager::Manifest> overlay =
GetContentClient()->browser()->GetServiceManifestOverlay(
manifest.service_name);
if (overlay)
manifest.Amend(*overlay);
if (!manifest.preloaded_files.empty()) {
std::map<std::string, base::FilePath> preloaded_files_map;
for (const auto& info : manifest.preloaded_files)
preloaded_files_map.emplace(info.key, info.path);
ChildProcessLauncher::SetRegisteredFilesForService(
manifest.service_name, std::move(preloaded_files_map));
}
for (auto& extra_manifest :
GetContentClient()->browser()->GetExtraServiceManifests()) {
manifests.emplace_back(std::move(extra_manifest));
}
in_process_context_ =
new InProcessServiceManagerContext(service_manager_thread_task_runner_);
service_manager::mojom::ServicePtr packaged_services_service;
packaged_services_request = mojo::MakeRequest(&packaged_services_service);
in_process_context_->Start(packaged_services_service.PassInterface(),
std::move(manifests));
}
for (auto& extra_manifest :
GetContentClient()->browser()->GetExtraServiceManifests()) {
manifests.emplace_back(std::move(extra_manifest));
}
in_process_context_ =
new InProcessServiceManagerContext(service_manager_thread_task_runner_);
service_manager::mojom::ServicePtr packaged_services_service;
service_manager::mojom::ServiceRequest packaged_services_request =
mojo::MakeRequest(&packaged_services_service);
in_process_context_->Start(packaged_services_service.PassInterface(),
std::move(manifests));
packaged_services_connection_ =
ServiceManagerConnection::Create(std::move(packaged_services_request),

@ -109,7 +109,6 @@ target(link_target_type, "child") {
"//services/resource_coordinator/public/cpp/memory_instrumentation",
"//services/service_manager/public/cpp",
"//services/service_manager/public/mojom",
"//services/service_manager/runner/common",
"//services/tracing/public/cpp",
"//skia",
"//storage/common",

@ -70,7 +70,6 @@
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/sandbox/sandbox_type.h"
#if defined(OS_POSIX)

@ -319,7 +319,6 @@ source_set("common") {
"//services/network/public/mojom",
"//services/resource_coordinator/public/cpp/memory_instrumentation",
"//services/service_manager/public/mojom",
"//services/service_manager/runner/common",
"//services/service_manager/zygote:zygote_buildflags",
"//services/video_capture/public/mojom",
"//services/viz/public/interfaces",

@ -27,7 +27,6 @@
#include "services/service_manager/public/cpp/service_binding.h"
#include "services/service_manager/public/mojom/constants.mojom.h"
#include "services/service_manager/public/mojom/service_factory.mojom.h"
#include "services/service_manager/runner/common/client_util.h"
#if defined(OS_ANDROID)
#include "base/android/jni_android.h"

@ -47,7 +47,6 @@ source_set("service_manager") {
"//services/catalog/public/mojom:constants",
"//services/service_manager/public/cpp",
"//services/service_manager/public/mojom",
"//services/service_manager/runner/common",
"//services/service_manager/sandbox",
]
@ -57,7 +56,10 @@ source_set("service_manager") {
"service_process_launcher.h",
]
deps += [ "//mojo/core/embedder" ]
deps += [
"//mojo/core/embedder",
"//services/service_manager/public/cpp/service_executable:switches",
]
}
if (is_linux) {

@ -48,9 +48,8 @@ if (!is_ios) {
"//services/service_manager",
"//services/service_manager/public/cpp",
"//services/service_manager/public/cpp/service_executable:support",
"//services/service_manager/public/cpp/service_executable:switches",
"//services/service_manager/public/mojom",
"//services/service_manager/runner:init",
"//services/service_manager/runner/common",
]
if (!is_nacl) {

@ -37,9 +37,7 @@
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_executable/service_executable_environment.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/runner/common/switches.h"
#include "services/service_manager/runner/init.h"
#include "services/service_manager/public/cpp/service_executable/switches.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/base/ui_base_switches.h"
@ -157,7 +155,14 @@ void CommonSubprocessInit() {
}
void NonEmbedderProcessInit() {
service_manager::InitializeLogging();
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
logging::InitLogging(settings);
// To view log output with IDs and timestamps use "adb logcat -v threadtime".
logging::SetLogItems(true, // Process ID
true, // Thread ID
true, // Timestamp
true); // Tick count
#if !defined(OFFICIAL_BUILD)
// Initialize stack dumping before initializing sandbox to make sure symbol
@ -173,25 +178,6 @@ void NonEmbedderProcessInit() {
base::TaskScheduler::CreateAndStartWithDefaultParams("ServiceManagerProcess");
}
void WaitForDebuggerIfNecessary() {
if (!ServiceManagerIsRemote())
return;
const auto& command_line = *base::CommandLine::ForCurrentProcess();
const std::string service_name =
command_line.GetSwitchValueASCII(switches::kServiceName);
if (service_name !=
command_line.GetSwitchValueASCII(::switches::kWaitForDebugger)) {
return;
}
// Include the pid as logging may not have been initialized yet (the pid
// printed out by logging is wrong).
LOG(WARNING) << "waiting for debugger to attach for service " << service_name
<< " pid=" << base::Process::Current().Pid();
base::debug::WaitForDebugger(120, true);
}
int RunServiceManager(MainDelegate* delegate) {
NonEmbedderProcessInit();
@ -230,7 +216,6 @@ void InitializeResources() {
int RunService(MainDelegate* delegate) {
NonEmbedderProcessInit();
WaitForDebuggerIfNecessary();
InitializeResources();

@ -9,12 +9,11 @@ source_set("support") {
]
deps = [
":switches",
"//mojo/core/embedder",
"//mojo/public/cpp/platform",
"//mojo/public/cpp/system",
"//services/service_manager/public/cpp",
"//services/service_manager/runner:init",
"//services/service_manager/runner/common",
"//services/service_manager/sandbox",
]
@ -32,6 +31,13 @@ source_set("support") {
}
}
source_set("switches") {
sources = [
"switches.cc",
"switches.h",
]
}
# Service executable targets should link against this to get a boilerplate entry
# point which accepts canonical command-line arguments to establish a connection
# to the Service Manager. In order to link properly, dependents must ensure that
@ -52,7 +58,7 @@ source_set("main") {
deps = [
":support",
"//base",
"//base:base_static",
"//base:i18n",
"//services/service_manager/runner:init",
]
}

@ -5,23 +5,62 @@
#include "base/at_exit.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/debug/debugger.h"
#include "base/debug/stack_trace.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/i18n/icu_util.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/process/launch.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/task_scheduler/task_scheduler.h"
#include "build/build_config.h"
#include "services/service_manager/public/cpp/service_executable/service_executable_environment.h"
#include "services/service_manager/public/cpp/service_executable/service_main.h"
#include "services/service_manager/public/mojom/service.mojom.h"
#include "services/service_manager/runner/init.h"
#if defined(OS_MACOSX)
#include "base/mac/bundle_locations.h"
#endif
namespace {
void WaitForDebuggerIfNecessary() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(::switches::kWaitForDebugger)) {
std::vector<std::string> apps_to_debug = base::SplitString(
command_line->GetSwitchValueASCII(::switches::kWaitForDebugger), ",",
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
std::string app = "launcher";
base::FilePath exe_path =
command_line->GetProgram().BaseName().RemoveExtension();
for (const auto& app_name : apps_to_debug) {
if (base::FilePath().AppendASCII(app_name) == exe_path) {
app = app_name;
break;
}
}
if (apps_to_debug.empty() || base::ContainsValue(apps_to_debug, app)) {
#if defined(OS_WIN)
base::string16 appw = base::UTF8ToUTF16(app);
base::string16 message = base::UTF8ToUTF16(
base::StringPrintf("%s - %ld", app.c_str(), GetCurrentProcessId()));
MessageBox(NULL, message.c_str(), appw.c_str(), MB_OK | MB_SETFOREGROUND);
#else
LOG(ERROR) << app << " waiting for GDB. pid: " << getpid();
base::debug::WaitForDebugger(60, true);
#endif
}
}
}
} // namespace
int main(int argc, char** argv) {
base::AtExitManager at_exit;
base::CommandLine::Init(argc, argv);
@ -30,7 +69,14 @@ int main(int argc, char** argv) {
base::RouteStdioToConsole(false);
#endif
service_manager::InitializeLogging();
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
logging::InitLogging(settings);
// To view log output with IDs and timestamps use "adb logcat -v threadtime".
logging::SetLogItems(true, // Process ID
true, // Thread ID
true, // Timestamp
true); // Tick count
base::i18n::InitializeICU();
@ -45,7 +91,7 @@ int main(int argc, char** argv) {
command_line->GetSwitchValueASCII(switches::kEnableFeatures),
command_line->GetSwitchValueASCII(switches::kDisableFeatures));
service_manager::WaitForDebuggerIfNecessary();
WaitForDebuggerIfNecessary();
service_manager::ServiceExecutableEnvironment environment;
ServiceMain(environment.TakeServiceRequestFromCommandLine());
base::TaskScheduler::GetInstance()->Shutdown();

@ -16,8 +16,7 @@
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/invitation.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/runner/common/switches.h"
#include "services/service_manager/public/cpp/service_executable/switches.h"
#include "services/service_manager/sandbox/sandbox.h"
#include "services/service_manager/sandbox/switches.h"
@ -79,7 +78,9 @@ ServiceExecutableEnvironment::TakeServiceRequestFromCommandLine() {
auto invitation = mojo::IncomingInvitation::Accept(
mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
*base::CommandLine::ForCurrentProcess()));
return GetServiceRequestFromCommandLine(&invitation);
return mojom::ServiceRequest(invitation.ExtractMessagePipe(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kServiceRequestAttachmentName)));
}
} // namespace service_manager

@ -0,0 +1,20 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/service_manager/public/cpp/service_executable/switches.h"
namespace service_manager {
namespace switches {
// Indicates the name of the service to run. Useful for debugging, or if a
// service executable is built to support being run as a number of potential
// different services.
const char kServiceName[] = "service-name";
// The name of the |service_manager::mojom::ServiceRequest| message pipe handle
// that is attached to the incoming Mojo invitation received by the service.
const char kServiceRequestAttachmentName[] = "service-request-attachment-name";
} // namespace switches
} // namespace service_manager

@ -1,9 +1,9 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_SERVICE_MANAGER_RUNNER_COMMON_SWITCHES_H_
#define SERVICES_SERVICE_MANAGER_RUNNER_COMMON_SWITCHES_H_
#ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_EXECUTABLE_SWITCHES_H_
#define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_EXECUTABLE_SWITCHES_H_
namespace service_manager {
namespace switches {
@ -11,9 +11,9 @@ namespace switches {
// All switches in alphabetical order. The switches should be documented
// alongside the definition of their values in the .cc file.
extern const char kServiceName[];
extern const char kServicePipeToken[];
extern const char kServiceRequestAttachmentName[];
} // namespace switches
} // namespace service_manager
#endif // SERVICES_SERVICE_MANAGER_RUNNER_COMMON_SWITCHES_H_
#endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_EXECUTABLE_SWITCHES_H_

@ -1,17 +0,0 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("init") {
sources = [
"init.cc",
"init.h",
]
deps = [
"//base",
"//base:base_static",
"//base:i18n",
"//services/service_manager/runner/common",
]
}

@ -1,22 +0,0 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("common") {
sources = [
"client_util.cc",
"client_util.h",
"switches.cc",
"switches.h",
]
deps = [
"//base",
"//mojo/public/cpp/bindings",
]
public_deps = [
"//mojo/public/cpp/system",
"//services/service_manager/public/mojom",
]
}

@ -1,41 +0,0 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/service_manager/runner/common/client_util.h"
#include <string>
#include "base/command_line.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/runner/common/switches.h"
namespace service_manager {
mojom::ServicePtr PassServiceRequestOnCommandLine(
mojo::OutgoingInvitation* invitation,
base::CommandLine* command_line) {
mojom::ServicePtr client;
auto pipe_name = base::NumberToString(base::RandUint64());
client.Bind(
mojom::ServicePtrInfo(invitation->AttachMessagePipe(pipe_name), 0));
command_line->AppendSwitchASCII(switches::kServicePipeToken, pipe_name);
return client;
}
mojom::ServiceRequest GetServiceRequestFromCommandLine(
mojo::IncomingInvitation* invitation) {
std::string pipe_name =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kServicePipeToken);
return mojom::ServiceRequest(invitation->ExtractMessagePipe(pipe_name));
}
bool ServiceManagerIsRemote() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kServicePipeToken);
}
} // namespace service_manager

@ -1,42 +0,0 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_SERVICE_MANAGER_RUNNER_COMMON_CLIENT_UTIL_H_
#define SERVICES_SERVICE_MANAGER_RUNNER_COMMON_CLIENT_UTIL_H_
#include "services/service_manager/public/mojom/service.mojom.h"
namespace base {
class CommandLine;
}
namespace mojo {
class IncomingInvitation;
class OutgoingInvitation;
}
namespace service_manager {
// Creates a new Service pipe for connection to a not-yet-launched child process
// and returns one end of it. The other end is passed via a token in
// |command_line|. The launched process may extract the corresponding
// ServiceRequest by calling GetServiceRequestFromCommandLine().
mojom::ServicePtr PassServiceRequestOnCommandLine(
mojo::OutgoingInvitation* invitation,
base::CommandLine* command_line);
// Extracts a ServiceRequest from the command line of the current process.
// The parent of this process should have passed a request using
// PassServiceRequestOnCommandLine().
mojom::ServiceRequest GetServiceRequestFromCommandLine(
mojo::IncomingInvitation* invitation);
// Returns true if the ServiceRequest came via the command line from a service
// manager
// instance in another process.
bool ServiceManagerIsRemote();
} // namespace service_manager
#endif // SERVICES_SERVICE_MANAGER_RUNNER_COMMON_CLIENT_UTIL_H_

@ -1,21 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/service_manager/runner/common/switches.h"
namespace service_manager {
namespace switches {
// Specified on the command line of service processes to indicate which service
// should be run. Useful when the service process binary may act as one of many
// different embedded services.
const char kServiceName[] = "service-name";
// Provides a child process with a token string they can exchange for a message
// pipe whose other end is bound to a service_manager::Service binding in the
// Service Manager.
const char kServicePipeToken[] = "service-pipe-token";
} // namespace switches
} // namespace service_manager

@ -1,91 +0,0 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/service_manager/runner/init.h"
#include <stdint.h>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/debug/debugger.h"
#include "base/files/file_path.h"
#include "base/i18n/icu_util.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "services/service_manager/runner/common/switches.h"
#if defined(OS_WIN)
#include <windows.h>
#elif (OS_POSIX)
#include <unistd.h>
#endif
namespace service_manager {
void InitializeLogging() {
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
logging::InitLogging(settings);
// To view log output with IDs and timestamps use "adb logcat -v threadtime".
logging::SetLogItems(true, // Process ID
true, // Thread ID
true, // Timestamp
true); // Tick count
}
void WaitForDebuggerIfNecessary() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(::switches::kWaitForDebugger)) {
std::vector<std::string> apps_to_debug = base::SplitString(
command_line->GetSwitchValueASCII(::switches::kWaitForDebugger), ",",
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
std::string app = "launcher";
base::FilePath exe_path =
command_line->GetProgram().BaseName().RemoveExtension();
for (const auto& app_name : apps_to_debug) {
if (base::FilePath().AppendASCII(app_name) == exe_path) {
app = app_name;
break;
}
}
if (apps_to_debug.empty() || base::ContainsValue(apps_to_debug, app)) {
#if defined(OS_WIN)
base::string16 appw = base::UTF8ToUTF16(app);
base::string16 message = base::UTF8ToUTF16(
base::StringPrintf("%s - %ld", app.c_str(), GetCurrentProcessId()));
MessageBox(NULL, message.c_str(), appw.c_str(), MB_OK | MB_SETFOREGROUND);
#else
LOG(ERROR) << app << " waiting for GDB. pid: " << getpid();
base::debug::WaitForDebugger(60, true);
#endif
}
}
}
NO_SANITIZE("cfi-icall")
void CallLibraryEarlyInitialization(base::NativeLibrary app_library) {
// Do whatever warming that the service wants.
#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
typedef void (*LibraryEarlyInitFunction)(const uint8_t*);
LibraryEarlyInitFunction init_function =
reinterpret_cast<LibraryEarlyInitFunction>(
base::GetFunctionPointerFromNativeLibrary(app_library,
"InitializeBase"));
CHECK(init_function);
// Get the ICU data that we prewarmed in the runner and then pass it to
// the copy of icu in the mojo binary that we're running.
const uint8_t* icu_data = base::i18n::GetRawIcuMemory();
init_function(icu_data);
#endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
// TODO(erg): All chromium binaries load base. We might want to make a
// general system for other people.
}
} // namespace service_manager

@ -1,23 +0,0 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_SERVICE_MANAGER_RUNNER_INIT_H_
#define SERVICES_SERVICE_MANAGER_RUNNER_INIT_H_
#include "base/native_library.h"
namespace service_manager {
// Initialization routines shared by desktop and Android main functions.
void InitializeLogging();
void WaitForDebuggerIfNecessary();
// Calls "LibraryEarlyInitialization" in |app_library| if it exists. We do
// common initialization there now.
void CallLibraryEarlyInitialization(base::NativeLibrary app_library);
} // namespace service_manager
#endif // SERVICES_SERVICE_MANAGER_RUNNER_INIT_H_

@ -15,8 +15,10 @@
#include "base/path_service.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/sequence_checker.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/post_task.h"
#include "base/task_runner_util.h"
@ -26,9 +28,10 @@
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/runner/common/switches.h"
#include "services/service_manager/public/cpp/service_executable/switches.h"
#include "services/service_manager/public/mojom/service.mojom.h"
#include "services/service_manager/sandbox/switches.h"
#include "services/service_manager/switches.h"
#if defined(OS_LINUX)
#include "sandbox/linux/services/namespace_sandbox.h"
@ -140,6 +143,17 @@ mojom::ServicePtr ServiceProcessLauncher::Start(const Identity& target,
return client;
}
// static
mojom::ServicePtr ServiceProcessLauncher::PassServiceRequestOnCommandLine(
mojo::OutgoingInvitation* invitation,
base::CommandLine* command_line) {
const auto attachment_name = base::NumberToString(base::RandUint64());
command_line->AppendSwitchASCII(switches::kServiceRequestAttachmentName,
attachment_name);
return mojom::ServicePtr{
mojom::ServicePtrInfo{invitation->AttachMessagePipe(attachment_name), 0}};
}
base::ProcessId ServiceProcessLauncher::ProcessState::LaunchInBackground(
const Identity& target,
SandboxType sandbox_type,

@ -19,6 +19,10 @@
#include "services/service_manager/sandbox/sandbox_type.h"
#include "services/service_manager/service_process_launcher_delegate.h"
namespace mojo {
class OutgoingInvitation;
}
namespace service_manager {
class Identity;
@ -47,6 +51,16 @@ class ServiceProcessLauncher {
SandboxType sandbox_type,
ProcessReadyCallback callback);
// Exposed publicly for use in tests. Creates a new Service pipe, passing the
// ServiceRequest end through |*invitation| with an identifier stashed in
// |*command_line| that a launched service executable can use to recover it
// from the invitation.
//
// Returns the corresponding ServicePtr endpoint.
static mojom::ServicePtr PassServiceRequestOnCommandLine(
mojo::OutgoingInvitation* invitation,
base::CommandLine* command_line);
private:
class ProcessState;

@ -11,6 +11,7 @@ namespace switches {
// All switches in alphabetical order. The switches should be documented
// alongside the definition of their values in the .cc file.
extern const char kEnableTracing[];
extern const char kServiceRequestAttachmentName[];
} // namespace switches
} // namespace service_manager

@ -70,8 +70,8 @@ source_set("util") {
"//mojo/public/cpp/platform",
"//mojo/public/cpp/system",
"//services/service_manager/public/cpp",
"//services/service_manager/public/cpp/service_executable:switches",
"//services/service_manager/public/mojom",
"//services/service_manager/runner/common",
]
}

@ -18,7 +18,6 @@ source_set("lifecycle") {
"//services/service_manager/public/cpp",
"//services/service_manager/public/cpp/test:test_support",
"//services/service_manager/public/mojom",
"//services/service_manager/runner/common",
"//testing/gtest",
]

@ -25,7 +25,6 @@ source_set("service_manager") {
"//services/service_manager/public/cpp",
"//services/service_manager/public/cpp/test:test_support",
"//services/service_manager/public/mojom",
"//services/service_manager/runner/common",
"//testing/gtest",
]
@ -90,7 +89,5 @@ service_executable("service_manager_unittest_embedder") {
"//build/win:default_exe_manifest",
"//services/service_manager/public/cpp",
"//services/service_manager/public/mojom",
"//services/service_manager/runner:init",
"//services/service_manager/runner/common",
]
}

@ -33,7 +33,7 @@
#include "services/service_manager/public/cpp/service_binding.h"
#include "services/service_manager/public/cpp/test/test_service_manager.h"
#include "services/service_manager/public/mojom/service_manager.mojom.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/service_process_launcher.h"
#include "services/service_manager/tests/service_manager/service_manager.test-mojom.h"
#include "services/service_manager/tests/service_manager/test_manifests.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -265,8 +265,8 @@ class ServiceManagerTest : public testing::Test,
mojo::OutgoingInvitation invitation;
service_manager::mojom::ServicePtr client =
service_manager::PassServiceRequestOnCommandLine(&invitation,
&child_command_line);
ServiceProcessLauncher::PassServiceRequestOnCommandLine(
&invitation, &child_command_line);
service_manager::mojom::PIDReceiverPtr receiver;
connector()->RegisterServiceInstance(
service_manager::Identity(kTestTargetName, kSystemInstanceGroup,

@ -20,10 +20,10 @@
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/service_executable/switches.h"
#include "services/service_manager/public/mojom/connector.mojom.h"
#include "services/service_manager/public/mojom/service.mojom.h"
#include "services/service_manager/public/mojom/service_factory.mojom.h"
#include "services/service_manager/runner/common/switches.h"
namespace service_manager {
namespace test {
@ -66,7 +66,8 @@ mojom::ConnectResult LaunchAndConnectToProcess(
mojo::OutgoingInvitation invitation;
auto pipe_name = base::NumberToString(base::RandUint64());
mojo::ScopedMessagePipeHandle pipe = invitation.AttachMessagePipe(pipe_name);
child_command_line.AppendSwitchASCII(switches::kServicePipeToken, pipe_name);
child_command_line.AppendSwitchASCII(switches::kServiceRequestAttachmentName,
pipe_name);
service_manager::mojom::ServicePtr client;
client.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>(