Commit 75609819 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Migrate Service Manager to public invitation API

Migrates Service Manager away from the EDK invitation API and over to
the new public API.

Mostly a PoC CL for porting the old stuff to the new stuff, but this
also means that Service Manager now only depends on EDK for
initialization.

Bug: 844763,844764
Change-Id: I10e40a95fdd4760cabd537b2a4ac4c56fb4e33e1
Reviewed-on: https://chromium-review.googlesource.com/1070533
Commit-Queue: Ken Rockot <rockot@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561898}
parent eca8c747
...@@ -109,6 +109,8 @@ jumbo_source_set("browser") { ...@@ -109,6 +109,8 @@ jumbo_source_set("browser") {
"//media/mojo/services", "//media/mojo/services",
"//mojo/edk", "//mojo/edk",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//mojo/public/cpp/platform",
"//mojo/public/cpp/system",
"//mojo/public/js:resources", "//mojo/public/js:resources",
"//net", "//net",
"//net:extras", "//net:extras",
......
...@@ -45,8 +45,8 @@ ...@@ -45,8 +45,8 @@
#include "media/media_buildflags.h" #include "media/media_buildflags.h"
#include "media/mojo/buildflags.h" #include "media/mojo/buildflags.h"
#include "media/mojo/interfaces/constants.mojom.h" #include "media/mojo/interfaces/constants.mojom.h"
#include "mojo/edk/embedder/embedder.h" #include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/edk/embedder/incoming_broker_client_invitation.h" #include "mojo/public/cpp/system/invitation.h"
#include "services/audio/public/mojom/constants.mojom.h" #include "services/audio/public/mojom/constants.mojom.h"
#include "services/audio/service_factory.h" #include "services/audio/service_factory.h"
#include "services/catalog/manifest_provider.h" #include "services/catalog/manifest_provider.h"
...@@ -405,11 +405,11 @@ ServiceManagerContext::ServiceManagerContext( ...@@ -405,11 +405,11 @@ ServiceManagerContext::ServiceManagerContext(
DCHECK(service_manager_thread_task_runner_); DCHECK(service_manager_thread_task_runner_);
service_manager::mojom::ServiceRequest packaged_services_request; service_manager::mojom::ServiceRequest packaged_services_request;
if (service_manager::ServiceManagerIsRemote()) { if (service_manager::ServiceManagerIsRemote()) {
auto invitation = auto endpoint = mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
mojo::edk::IncomingBrokerClientInvitation::AcceptFromCommandLine( *base::CommandLine::ForCurrentProcess());
mojo::edk::TransportProtocol::kLegacy); auto invitation = mojo::IncomingInvitation::Accept(std::move(endpoint));
packaged_services_request = packaged_services_request =
service_manager::GetServiceRequestFromCommandLine(invitation.get()); service_manager::GetServiceRequestFromCommandLine(&invitation);
} else { } else {
std::unique_ptr<BuiltinManifestProvider> manifest_provider = std::unique_ptr<BuiltinManifestProvider> manifest_provider =
std::make_unique<BuiltinManifestProvider>(); std::make_unique<BuiltinManifestProvider>();
......
...@@ -12,6 +12,7 @@ source_set("standalone_service") { ...@@ -12,6 +12,7 @@ source_set("standalone_service") {
deps = [ deps = [
"//mojo/edk", "//mojo/edk",
"//mojo/public/cpp/platform",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//services/service_manager/runner:init", "//services/service_manager/runner:init",
......
...@@ -12,9 +12,11 @@ ...@@ -12,9 +12,11 @@
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/task_scheduler/task_scheduler.h" #include "base/task_scheduler/task_scheduler.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "build/build_config.h"
#include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/incoming_broker_client_invitation.h"
#include "mojo/edk/embedder/scoped_ipc_support.h" #include "mojo/edk/embedder/scoped_ipc_support.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/invitation.h"
#include "mojo/public/cpp/system/message_pipe.h" #include "mojo/public/cpp/system/message_pipe.h"
#include "services/service_manager/public/cpp/service_context.h" #include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/runner/common/client_util.h" #include "services/service_manager/runner/common/client_util.h"
...@@ -42,9 +44,9 @@ void RunStandaloneService(const StandaloneServiceCallback& callback) { ...@@ -42,9 +44,9 @@ void RunStandaloneService(const StandaloneServiceCallback& callback) {
MachBroker::SendTaskPortToParent(); MachBroker::SendTaskPortToParent();
#endif #endif
#if defined(OS_LINUX)
const base::CommandLine& command_line = const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess(); *base::CommandLine::ForCurrentProcess();
#if defined(OS_LINUX)
if (command_line.HasSwitch(switches::kServiceSandboxType)) { if (command_line.HasSwitch(switches::kServiceSandboxType)) {
// Warm parts of base in the copy of base in the mojo runner. // Warm parts of base in the copy of base in the mojo runner.
base::RandUint64(); base::RandUint64();
...@@ -73,10 +75,10 @@ void RunStandaloneService(const StandaloneServiceCallback& callback) { ...@@ -73,10 +75,10 @@ void RunStandaloneService(const StandaloneServiceCallback& callback) {
io_thread.task_runner(), io_thread.task_runner(),
mojo::edk::ScopedIPCSupport::ShutdownPolicy::CLEAN); mojo::edk::ScopedIPCSupport::ShutdownPolicy::CLEAN);
auto invitation = auto invitation = mojo::IncomingInvitation::Accept(
mojo::edk::IncomingBrokerClientInvitation::AcceptFromCommandLine( mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
mojo::edk::TransportProtocol::kLegacy); command_line));
callback.Run(GetServiceRequestFromCommandLine(invitation.get())); callback.Run(GetServiceRequestFromCommandLine(&invitation));
} }
} // namespace service_manager } // namespace service_manager
...@@ -13,11 +13,10 @@ source_set("common") { ...@@ -13,11 +13,10 @@ source_set("common") {
deps = [ deps = [
"//base", "//base",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//mojo/public/cpp/system",
] ]
public_deps = [ public_deps = [
"//mojo/edk", "//mojo/public/cpp/system",
"//services/service_manager/public/mojom", "//services/service_manager/public/mojom",
] ]
} }
...@@ -7,32 +7,30 @@ ...@@ -7,32 +7,30 @@
#include <string> #include <string>
#include "base/command_line.h" #include "base/command_line.h"
#include "mojo/edk/embedder/embedder.h" #include "base/rand_util.h"
#include "mojo/edk/embedder/incoming_broker_client_invitation.h" #include "base/strings/string_number_conversions.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h" #include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/runner/common/switches.h" #include "services/service_manager/runner/common/switches.h"
namespace service_manager { namespace service_manager {
mojom::ServicePtr PassServiceRequestOnCommandLine( mojom::ServicePtr PassServiceRequestOnCommandLine(
mojo::edk::OutgoingBrokerClientInvitation* invitation, mojo::OutgoingInvitation* invitation,
base::CommandLine* command_line) { base::CommandLine* command_line) {
mojom::ServicePtr client; mojom::ServicePtr client;
std::string token = mojo::edk::GenerateRandomToken(); auto pipe_name = base::NumberToString(base::RandUint64());
client.Bind(mojom::ServicePtrInfo(invitation->AttachMessagePipe(token), 0)); client.Bind(
command_line->AppendSwitchASCII(switches::kServicePipeToken, token); mojom::ServicePtrInfo(invitation->AttachMessagePipe(pipe_name), 0));
command_line->AppendSwitchASCII(switches::kServicePipeToken, pipe_name);
return client; return client;
} }
mojom::ServiceRequest GetServiceRequestFromCommandLine( mojom::ServiceRequest GetServiceRequestFromCommandLine(
mojo::edk::IncomingBrokerClientInvitation* invitation) { mojo::IncomingInvitation* invitation) {
std::string token = std::string pipe_name =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kServicePipeToken); switches::kServicePipeToken);
mojom::ServiceRequest request; return mojom::ServiceRequest(invitation->ExtractMessagePipe(pipe_name));
if (!token.empty())
request = mojom::ServiceRequest(invitation->ExtractMessagePipe(token));
return request;
} }
bool ServiceManagerIsRemote() { bool ServiceManagerIsRemote() {
......
...@@ -12,10 +12,8 @@ class CommandLine; ...@@ -12,10 +12,8 @@ class CommandLine;
} }
namespace mojo { namespace mojo {
namespace edk { class IncomingInvitation;
class IncomingBrokerClientInvitation; class OutgoingInvitation;
class OutgoingBrokerClientInvitation;
}
} }
namespace service_manager { namespace service_manager {
...@@ -25,14 +23,14 @@ namespace service_manager { ...@@ -25,14 +23,14 @@ namespace service_manager {
// |command_line|. The launched process may extract the corresponding // |command_line|. The launched process may extract the corresponding
// ServiceRequest by calling GetServiceRequestFromCommandLine(). // ServiceRequest by calling GetServiceRequestFromCommandLine().
mojom::ServicePtr PassServiceRequestOnCommandLine( mojom::ServicePtr PassServiceRequestOnCommandLine(
mojo::edk::OutgoingBrokerClientInvitation* invitation, mojo::OutgoingInvitation* invitation,
base::CommandLine* command_line); base::CommandLine* command_line);
// Extracts a ServiceRequest from the command line of the current process. // Extracts a ServiceRequest from the command line of the current process.
// The parent of this process should have passed a request using // The parent of this process should have passed a request using
// PassServiceRequestOnCommandLine(). // PassServiceRequestOnCommandLine().
mojom::ServiceRequest GetServiceRequestFromCommandLine( mojom::ServiceRequest GetServiceRequestFromCommandLine(
mojo::edk::IncomingBrokerClientInvitation* invitation); mojo::IncomingInvitation* invitation);
// Returns true if the ServiceRequest came via the command line from a service // Returns true if the ServiceRequest came via the command line from a service
// manager // manager
......
...@@ -35,7 +35,7 @@ source_set("lib") { ...@@ -35,7 +35,7 @@ source_set("lib") {
public_deps = [ public_deps = [
"//base", "//base",
"//mojo/edk", "//mojo/public/cpp/platform",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
] ]
...@@ -61,7 +61,6 @@ if (!is_ios) { ...@@ -61,7 +61,6 @@ if (!is_ios) {
":lib", ":lib",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//mojo/edk",
"//services/service_manager", "//services/service_manager",
"//services/service_manager/runner:init", "//services/service_manager/runner:init",
"//services/service_manager/runner/common", "//services/service_manager/runner/common",
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/public/cpp/bindings/interface_ptr_info.h" #include "mojo/public/cpp/bindings/interface_ptr_info.h"
#include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/core.h"
#include "services/service_manager/public/cpp/standalone_service/switches.h" #include "services/service_manager/public/cpp/standalone_service/switches.h"
...@@ -82,12 +81,12 @@ mojom::ServicePtr ServiceProcessLauncher::Start(const Identity& target, ...@@ -82,12 +81,12 @@ mojom::ServicePtr ServiceProcessLauncher::Start(const Identity& target,
switches::kServiceSandboxType, switches::kServiceSandboxType,
StringFromUtilitySandboxType(sandbox_type_)); StringFromUtilitySandboxType(sandbox_type_));
} }
mojo_ipc_channel_.reset(new mojo::edk::PlatformChannelPair); channel_.emplace();
mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess( channel_->PrepareToPassRemoteEndpoint(&handle_passing_info_,
child_command_line.get(), &handle_passing_info_); child_command_line.get());
mojom::ServicePtr client = PassServiceRequestOnCommandLine( mojom::ServicePtr client =
&broker_client_invitation_, child_command_line.get()); PassServiceRequestOnCommandLine(&invitation_, child_command_line.get());
base::PostTaskWithTraitsAndReply( base::PostTaskWithTraitsAndReply(
FROM_HERE, {base::TaskPriority::USER_BLOCKING, base::MayBlock()}, FROM_HERE, {base::TaskPriority::USER_BLOCKING, base::MayBlock()},
...@@ -103,9 +102,9 @@ void ServiceProcessLauncher::Join() { ...@@ -103,9 +102,9 @@ void ServiceProcessLauncher::Join() {
// TODO: This code runs on the IO thread where Wait() is not allowed. This // TODO: This code runs on the IO thread where Wait() is not allowed. This
// needs to be fixed: https://crbug.com/844078. // needs to be fixed: https://crbug.com/844078.
base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_sync; base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_sync;
if (mojo_ipc_channel_) if (channel_)
start_child_process_event_.Wait(); start_child_process_event_.Wait();
mojo_ipc_channel_.reset(); channel_.reset();
if (child_process_.IsValid()) { if (child_process_.IsValid()) {
int rv = -1; int rv = -1;
LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) LOG_IF(ERROR, !child_process_.WaitForExit(&rv))
...@@ -119,7 +118,7 @@ void ServiceProcessLauncher::DidStart(ProcessReadyCallback callback) { ...@@ -119,7 +118,7 @@ void ServiceProcessLauncher::DidStart(ProcessReadyCallback callback) {
std::move(callback).Run(child_process_.Pid()); std::move(callback).Run(child_process_.Pid());
} else { } else {
LOG(ERROR) << "Failed to start child process"; LOG(ERROR) << "Failed to start child process";
mojo_ipc_channel_.reset(); channel_.reset();
std::move(callback).Run(base::kNullProcessId); std::move(callback).Run(base::kNullProcessId);
} }
} }
...@@ -202,12 +201,11 @@ void ServiceProcessLauncher::DoLaunch( ...@@ -202,12 +201,11 @@ void ServiceProcessLauncher::DoLaunch(
<< ", instance=" << target_.instance() << ", name=" << target_.name() << ", instance=" << target_.instance() << ", name=" << target_.name()
<< ", user_id=" << target_.user_id(); << ", user_id=" << target_.user_id();
if (mojo_ipc_channel_.get()) { if (channel_) {
mojo_ipc_channel_->ChildProcessLaunched(); channel_->RemoteProcessLaunched();
broker_client_invitation_.Send( mojo::OutgoingInvitation::Send(std::move(invitation_),
child_process_.Handle(), child_process_.Handle(),
mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy, channel_->TakeLocalEndpoint());
mojo_ipc_channel_->PassServerHandle()));
} }
} }
start_child_process_event_.Signal(); start_child_process_event_.Signal();
......
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/process/process.h" #include "base/process/process.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h" #include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/edk/embedder/platform_channel_pair.h" #include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/public/mojom/service_factory.mojom.h" #include "services/service_manager/public/mojom/service_factory.mojom.h"
#include "services/service_manager/runner/host/service_process_launcher_delegate.h" #include "services/service_manager/runner/host/service_process_launcher_delegate.h"
#include "services/service_manager/sandbox/sandbox_type.h" #include "services/service_manager/sandbox/sandbox_type.h"
...@@ -68,9 +69,9 @@ class ServiceProcessLauncher { ...@@ -68,9 +69,9 @@ class ServiceProcessLauncher {
base::Process child_process_; base::Process child_process_;
// Used to initialize the Mojo IPC channel between parent and child. // Used to initialize the Mojo IPC channel between parent and child.
std::unique_ptr<mojo::edk::PlatformChannelPair> mojo_ipc_channel_; base::Optional<mojo::PlatformChannel> channel_;
mojo::edk::HandlePassingInformation handle_passing_info_; mojo::PlatformChannel::HandlePassingInfo handle_passing_info_;
mojo::edk::OutgoingBrokerClientInvitation broker_client_invitation_; mojo::OutgoingInvitation invitation_;
// Since Start() calls a method on another thread, we use an event to block // Since Start() calls a method on another thread, we use an event to block
// the main thread if it tries to destruct |this| while launching the process. // the main thread if it tries to destruct |this| while launching the process.
......
...@@ -15,7 +15,6 @@ source_set("standalone") { ...@@ -15,7 +15,6 @@ source_set("standalone") {
deps = [ deps = [
"//base", "//base",
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
"//mojo/edk",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//services/catalog:lib", "//services/catalog:lib",
"//services/service_manager", "//services/service_manager",
......
...@@ -26,7 +26,6 @@ service_test("service_manager_unittests") { ...@@ -26,7 +26,6 @@ service_test("service_manager_unittests") {
":interfaces", ":interfaces",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//mojo/edk",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//services/catalog:lib", "//services/catalog:lib",
...@@ -62,7 +61,8 @@ source_set("util") { ...@@ -62,7 +61,8 @@ source_set("util") {
deps = [ deps = [
"//base", "//base",
"//base:base_static", "//base:base_static",
"//mojo/edk", "//mojo/public/cpp/platform",
"//mojo/public/cpp/system",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//services/service_manager/public/mojom", "//services/service_manager/public/mojom",
"//services/service_manager/runner/common", "//services/service_manager/runner/common",
......
...@@ -18,7 +18,7 @@ source_set("service_manager") { ...@@ -18,7 +18,7 @@ source_set("service_manager") {
":interfaces", ":interfaces",
"//base", "//base",
"//base/test:test_config", "//base/test:test_config",
"//mojo/edk", "//mojo/public/cpp/platform",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//services/service_manager/public/cpp:service_test_support", "//services/service_manager/public/cpp:service_test_support",
...@@ -105,7 +105,6 @@ service("service_manager_unittest_embedder") { ...@@ -105,7 +105,6 @@ service("service_manager_unittest_embedder") {
":interfaces", ":interfaces",
"//base", "//base",
"//build/win:default_exe_manifest", "//build/win:default_exe_manifest",
"//mojo/edk",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//services/service_manager/public/cpp/standalone_service:main", "//services/service_manager/public/cpp/standalone_service:main",
"//services/service_manager/public/mojom", "//services/service_manager/public/mojom",
......
...@@ -22,11 +22,10 @@ ...@@ -22,11 +22,10 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h" #include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h" #include "services/service_manager/public/cpp/service_context.h"
...@@ -264,20 +263,20 @@ class ServiceManagerTest : public test::ServiceTest, ...@@ -264,20 +263,20 @@ class ServiceManagerTest : public test::ServiceTest,
// Create the channel to be shared with the target process. Pass one end // Create the channel to be shared with the target process. Pass one end
// on the command line. // on the command line.
mojo::edk::PlatformChannelPair platform_channel_pair; mojo::PlatformChannel channel;
base::LaunchOptions options; base::LaunchOptions options;
#if defined(OS_WIN) #if defined(OS_WIN)
platform_channel_pair.PrepareToPassClientHandleToChildProcess( channel.PrepareToPassRemoteEndpoint(&options.handles_to_inherit,
&child_command_line, &options.handles_to_inherit); &child_command_line);
#elif defined(OS_FUCHSIA) #elif defined(OS_FUCHSIA)
platform_channel_pair.PrepareToPassClientHandleToChildProcess( channel.PrepareToPassRemoteEndpoint(&options.handles_to_transfer,
&child_command_line, &options.handles_to_transfer); &child_command_line);
#else #else
platform_channel_pair.PrepareToPassClientHandleToChildProcess( channel.PrepareToPassRemoteEndpoint(&options.fds_to_remap,
&child_command_line, &options.fds_to_remap); &child_command_line);
#endif #endif
mojo::edk::OutgoingBrokerClientInvitation invitation; mojo::OutgoingInvitation invitation;
service_manager::mojom::ServicePtr client = service_manager::mojom::ServicePtr client =
service_manager::PassServiceRequestOnCommandLine(&invitation, service_manager::PassServiceRequestOnCommandLine(&invitation,
&child_command_line); &child_command_line);
...@@ -293,12 +292,10 @@ class ServiceManagerTest : public test::ServiceTest, ...@@ -293,12 +292,10 @@ class ServiceManagerTest : public test::ServiceTest,
target_ = base::LaunchProcess(child_command_line, options); target_ = base::LaunchProcess(child_command_line, options);
DCHECK(target_.IsValid()); DCHECK(target_.IsValid());
platform_channel_pair.ChildProcessLaunched(); channel.RemoteProcessLaunched();
receiver->SetPID(target_.Pid()); receiver->SetPID(target_.Pid());
invitation.Send( mojo::OutgoingInvitation::Send(std::move(invitation), target_.Handle(),
target_.Handle(), channel.TakeLocalEndpoint());
mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy,
platform_channel_pair.PassServerHandle()));
} }
void StartEmbedderService() { void StartEmbedderService() {
......
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process/process.h" #include "base/process/process.h"
#include "base/rand_util.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/edk/embedder/embedder.h" #include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h" #include "mojo/public/cpp/system/invitation.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/mojom/connector.mojom.h" #include "services/service_manager/public/mojom/connector.mojom.h"
#include "services/service_manager/public/mojom/service_factory.mojom.h" #include "services/service_manager/public/mojom/service_factory.mojom.h"
...@@ -57,15 +57,15 @@ mojom::ConnectResult LaunchAndConnectToProcess( ...@@ -57,15 +57,15 @@ mojom::ConnectResult LaunchAndConnectToProcess(
// Create the channel to be shared with the target process. Pass one end // Create the channel to be shared with the target process. Pass one end
// on the command line. // on the command line.
mojo::edk::PlatformChannelPair platform_channel_pair; mojo::PlatformChannel channel;
mojo::edk::HandlePassingInformation handle_passing_info; mojo::PlatformChannel::HandlePassingInfo handle_passing_info;
platform_channel_pair.PrepareToPassClientHandleToChildProcess( channel.PrepareToPassRemoteEndpoint(&handle_passing_info,
&child_command_line, &handle_passing_info); &child_command_line);
mojo::edk::OutgoingBrokerClientInvitation invitation; mojo::OutgoingInvitation invitation;
std::string token = mojo::edk::GenerateRandomToken(); auto pipe_name = base::NumberToString(base::RandUint64());
mojo::ScopedMessagePipeHandle pipe = invitation.AttachMessagePipe(token); mojo::ScopedMessagePipeHandle pipe = invitation.AttachMessagePipe(pipe_name);
child_command_line.AppendSwitchASCII(switches::kServicePipeToken, token); child_command_line.AppendSwitchASCII(switches::kServicePipeToken, pipe_name);
service_manager::mojom::ServicePtr client; service_manager::mojom::ServicePtr client;
client.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>( client.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>(
...@@ -86,18 +86,17 @@ mojom::ConnectResult LaunchAndConnectToProcess( ...@@ -86,18 +86,17 @@ mojom::ConnectResult LaunchAndConnectToProcess(
#if defined(OS_WIN) #if defined(OS_WIN)
options.handles_to_inherit = handle_passing_info; options.handles_to_inherit = handle_passing_info;
#elif defined(OS_FUCHSIA) #elif defined(OS_FUCHSIA)
options.handles_to_transfer = handle_passing_info; options.handles_to_transfer = handle_passing_info;
#elif defined(OS_POSIX) #elif defined(OS_POSIX)
options.fds_to_remap = handle_passing_info; options.fds_to_remap = handle_passing_info;
#endif #endif
*process = base::LaunchProcess(child_command_line, options); *process = base::LaunchProcess(child_command_line, options);
DCHECK(process->IsValid()); DCHECK(process->IsValid());
platform_channel_pair.ChildProcessLaunched(); channel.RemoteProcessLaunched();
receiver->SetPID(process->Pid()); receiver->SetPID(process->Pid());
invitation.Send( mojo::OutgoingInvitation::Send(std::move(invitation), process->Handle(),
process->Handle(), channel.TakeLocalEndpoint());
mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy,
platform_channel_pair.PassServerHandle()));
return result; return result;
} }
......
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