Commit 14665867 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Remove the deprecated Channel creation API for content child processes.

Remove the deprecated ChildProcessHost::CreateChannelMojo overload
and migrate its final user (service utility process) to the other
overload. This requires the service process to directly connect to the
service_manager.mojom.Service interface to bind interfaces and claim to
be the browser service when binding interfaces so ChildThreadImpl allows
the IPC bootstrap request.

Change replay process to support the non-deprecated approach of using
the initial mojo handle as a service_manager::mojom::ServiceRequest.

Change chrome/utility/importer/firefox_importer_unittest_utils_mac.cc
to define its own constant for the channel token and remove the shared
content::switches::kMojoChannelToken.

Bug: 666605
Change-Id: Ib0721eecae5f53373262d320ebeb23745b62c7c1
Reviewed-on: https://chromium-review.googlesource.com/564914Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488159}
parent 7add13b6
...@@ -6,4 +6,5 @@ include_rules = [ ...@@ -6,4 +6,5 @@ include_rules = [
"+components/version_info", "+components/version_info",
"+mojo/edk/embedder", "+mojo/edk/embedder",
"+sandbox/win/src", "+sandbox/win/src",
"+services/service_manager/public",
] ]
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "content/public/common/result_codes.h" #include "content/public/common/result_codes.h"
#include "content/public/common/sandbox_init.h" #include "content/public/common/sandbox_init.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h" #include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "content/public/common/service_names.mojom.h"
#include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/named_platform_channel_pair.h" #include "mojo/edk/embedder/named_platform_channel_pair.h"
#include "mojo/edk/embedder/platform_channel_pair.h" #include "mojo/edk/embedder/platform_channel_pair.h"
...@@ -216,20 +217,21 @@ bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( ...@@ -216,20 +217,21 @@ bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults(
} }
bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) {
std::string mojo_channel_token =
child_process_host_->CreateChannelMojo(&broker_client_invitation_);
if (mojo_channel_token.empty())
return false;
base::FilePath exe_path = GetUtilityProcessCmd(); base::FilePath exe_path = GetUtilityProcessCmd();
if (exe_path.empty()) { if (exe_path.empty()) {
NOTREACHED() << "Unable to get utility process binary name."; NOTREACHED() << "Unable to get utility process binary name.";
return false; return false;
} }
std::string mojo_bootstrap_token = mojo::edk::GenerateRandomToken();
utility_process_connection_.Bind(service_manager::mojom::ServicePtrInfo(
broker_client_invitation_.AttachMessagePipe(mojo_bootstrap_token), 0u));
child_process_host_->CreateChannelMojo();
base::CommandLine cmd_line(exe_path); base::CommandLine cmd_line(exe_path);
cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess); cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess);
cmd_line.AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); cmd_line.AppendSwitchASCII(switches::kServiceRequestChannelToken,
mojo_bootstrap_token);
cmd_line.AppendSwitch(switches::kLang); cmd_line.AppendSwitch(switches::kLang);
cmd_line.AppendArg(switches::kPrefetchArgumentOther); cmd_line.AppendArg(switches::kPrefetchArgumentOther);
...@@ -337,7 +339,14 @@ const base::Process& ServiceUtilityProcessHost::GetProcess() const { ...@@ -337,7 +339,14 @@ const base::Process& ServiceUtilityProcessHost::GetProcess() const {
void ServiceUtilityProcessHost::BindInterface( void ServiceUtilityProcessHost::BindInterface(
const std::string& interface_name, const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) { mojo::ScopedMessagePipeHandle interface_pipe) {
child_process_host_->BindInterface(interface_name, std::move(interface_pipe)); service_manager::BindSourceInfo source_info;
// ChildThreadImpl expects a connection from the browser process for
// establishing its legacy IPC channel.
source_info.identity =
service_manager::Identity{content::mojom::kBrowserServiceName};
utility_process_connection_->OnBindInterface(source_info, interface_name,
std::move(interface_pipe),
base::Bind(&base::DoNothing));
} }
void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) { void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "content/public/common/child_process_host_delegate.h" #include "content/public/common/child_process_host_delegate.h"
#include "ipc/ipc_platform_file.h" #include "ipc/ipc_platform_file.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h" #include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
#include "services/service_manager/public/interfaces/service.mojom.h"
namespace base { namespace base {
class CommandLine; class CommandLine;
...@@ -155,6 +156,8 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate { ...@@ -155,6 +156,8 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
class PdfToEmfState; class PdfToEmfState;
std::unique_ptr<PdfToEmfState> pdf_to_emf_state_; std::unique_ptr<PdfToEmfState> pdf_to_emf_state_;
service_manager::mojom::ServicePtr utility_process_connection_;
base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_; base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost); DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost);
......
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
namespace { namespace {
const char kMojoChannelToken[] = "mojo-channel-token";
// Launch the child process: // Launch the child process:
// |nss_path| - path to the NSS directory holding the decryption libraries. // |nss_path| - path to the NSS directory holding the decryption libraries.
// |mojo_handle| - platform handle for Mojo transport. // |mojo_handle| - platform handle for Mojo transport.
...@@ -48,7 +50,7 @@ base::Process LaunchNSSDecrypterChildProcess( ...@@ -48,7 +50,7 @@ base::Process LaunchNSSDecrypterChildProcess(
const std::string& mojo_channel_token) { const std::string& mojo_channel_token) {
base::CommandLine cl(*base::CommandLine::ForCurrentProcess()); base::CommandLine cl(*base::CommandLine::ForCurrentProcess());
cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess");
cl.AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); cl.AppendSwitchASCII(kMojoChannelToken, mojo_channel_token);
// Set env variable needed for FF encryption libs to load. // Set env variable needed for FF encryption libs to load.
// See "chrome/utility/importer/nss_decryptor_mac.mm" for an explanation of // See "chrome/utility/importer/nss_decryptor_mac.mm" for an explanation of
...@@ -289,7 +291,7 @@ MULTIPROCESS_TEST_MAIN(NSSDecrypterChildProcess) { ...@@ -289,7 +291,7 @@ MULTIPROCESS_TEST_MAIN(NSSDecrypterChildProcess) {
kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor)))); kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor))));
mojo::ScopedMessagePipeHandle mojo_handle = invitation->ExtractMessagePipe( mojo::ScopedMessagePipeHandle mojo_handle = invitation->ExtractMessagePipe(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kMojoChannelToken)); kMojoChannelToken));
std::unique_ptr<IPC::Channel> channel = std::unique_ptr<IPC::Channel> channel =
IPC::Channel::CreateClient(mojo_handle.release(), &listener); IPC::Channel::CreateClient(mojo_handle.release(), &listener);
......
...@@ -408,27 +408,13 @@ void ChildThreadImpl::OnFieldTrialGroupFinalized( ...@@ -408,27 +408,13 @@ void ChildThreadImpl::OnFieldTrialGroupFinalized(
void ChildThreadImpl::ConnectChannel( void ChildThreadImpl::ConnectChannel(
mojo::edk::IncomingBrokerClientInvitation* invitation) { mojo::edk::IncomingBrokerClientInvitation* invitation) {
std::string channel_token; DCHECK(service_manager_connection_);
mojo::ScopedMessagePipeHandle handle; IPC::mojom::ChannelBootstrapPtr bootstrap;
if (!IsInBrowserProcess()) { mojo::ScopedMessagePipeHandle handle =
channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( mojo::MakeRequest(&bootstrap).PassMessagePipe();
switches::kMojoChannelToken); service_manager_connection_->AddConnectionFilter(
} base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface()));
if (!channel_token.empty()) {
// TODO(rockot): Remove all paths which lead to this branch. The Channel
// connection should always be established by a service manager connection
// from the browser. http://crbug.com/623396.
handle = invitation->ExtractMessagePipe(channel_token);
} else {
DCHECK(service_manager_connection_);
IPC::mojom::ChannelBootstrapPtr bootstrap;
handle = mojo::MakeRequest(&bootstrap).PassMessagePipe();
service_manager_connection_->AddConnectionFilter(
base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface()));
}
DCHECK(handle.is_valid());
channel_->Init( channel_->Init(
IPC::ChannelMojo::CreateClientFactory( IPC::ChannelMojo::CreateClientFactory(
std::move(handle), ChildProcess::current()->io_task_runner()), std::move(handle), ChildProcess::current()->io_task_runner()),
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "ipc/ipc_channel_mojo.h" #include "ipc/ipc_channel_mojo.h"
#include "ipc/ipc_logging.h" #include "ipc/ipc_logging.h"
#include "ipc/message_filter.h" #include "ipc/message_filter.h"
#include "mojo/edk/embedder/embedder.h"
#include "services/resource_coordinator/public/interfaces/memory_instrumentation/constants.mojom.h" #include "services/resource_coordinator/public/interfaces/memory_instrumentation/constants.mojom.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
...@@ -119,24 +118,7 @@ void ChildProcessHostImpl::ForceShutdown() { ...@@ -119,24 +118,7 @@ void ChildProcessHostImpl::ForceShutdown() {
Send(new ChildProcessMsg_Shutdown()); Send(new ChildProcessMsg_Shutdown());
} }
std::string ChildProcessHostImpl::CreateChannelMojo(
mojo::edk::OutgoingBrokerClientInvitation* invitation) {
DCHECK(channel_id_.empty());
channel_id_ = mojo::edk::GenerateRandomToken();
channel_ =
IPC::ChannelMojo::Create(invitation->AttachMessagePipe(channel_id_),
IPC::Channel::MODE_SERVER, this);
if (!channel_ || !InitChannel())
return std::string();
return channel_id_;
}
void ChildProcessHostImpl::CreateChannelMojo() { void ChildProcessHostImpl::CreateChannelMojo() {
// TODO(rockot): Remove |channel_id_| once this is the only code path by which
// the Channel is created. For now it serves to at least mutually exclude
// different CreateChannel* calls.
DCHECK(channel_id_.empty());
channel_id_ = "ChannelMojo";
mojo::MessagePipe pipe; mojo::MessagePipe pipe;
BindInterface(IPC::mojom::ChannelBootstrap::Name_, std::move(pipe.handle1)); BindInterface(IPC::mojom::ChannelBootstrap::Name_, std::move(pipe.handle1));
......
...@@ -64,8 +64,6 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost, ...@@ -64,8 +64,6 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
// ChildProcessHost implementation // ChildProcessHost implementation
bool Send(IPC::Message* message) override; bool Send(IPC::Message* message) override;
void ForceShutdown() override; void ForceShutdown() override;
std::string CreateChannelMojo(
mojo::edk::OutgoingBrokerClientInvitation* invitation) override;
void CreateChannelMojo() override; void CreateChannelMojo() override;
bool IsChannelOpening() override; bool IsChannelOpening() override;
void AddFilter(IPC::MessageFilter* filter) override; void AddFilter(IPC::MessageFilter* filter) override;
...@@ -94,7 +92,6 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost, ...@@ -94,7 +92,6 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
base::Process peer_process_; base::Process peer_process_;
bool opening_channel_; // True while we're waiting the channel to be opened. bool opening_channel_; // True while we're waiting the channel to be opened.
std::unique_ptr<IPC::Channel> channel_; std::unique_ptr<IPC::Channel> channel_;
std::string channel_id_;
// Holds all the IPC message filters. Since this object lives on the IO // Holds all the IPC message filters. Since this object lives on the IO
// thread, we don't have a IPC::ChannelProxy and so we manage filters // thread, we don't have a IPC::ChannelProxy and so we manage filters
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/common/bind_interface_helpers.h" #include "content/public/common/bind_interface_helpers.h"
#include "ipc/ipc_channel_proxy.h" #include "ipc/ipc_channel_proxy.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
namespace base { namespace base {
class FilePath; class FilePath;
...@@ -73,14 +72,6 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Sender { ...@@ -73,14 +72,6 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Sender {
// Does not check with the delegate's CanShutdown. // Does not check with the delegate's CanShutdown.
virtual void ForceShutdown() = 0; virtual void ForceShutdown() = 0;
// Creates the IPC channel on top of Mojo. Returns the Mojo channel token if
// succeeded, or an empty string on failure.
//
// DEPRECATED: Don't use this. Instead implement GetRemoteInterfaces() in the
// delegate and use the CreateChannelMojo() version below.
virtual std::string CreateChannelMojo(
mojo::edk::OutgoingBrokerClientInvitation* invitation) = 0;
// Creates the IPC channel over a Mojo message pipe. The pipe connection is // Creates the IPC channel over a Mojo message pipe. The pipe connection is
// brokered through the Service Manager like any other service connection. // brokered through the Service Manager like any other service connection.
virtual void CreateChannelMojo() = 0; virtual void CreateChannelMojo() = 0;
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
namespace switches { namespace switches {
// The token to use to construct the message pipe on which to layer ChannelMojo.
const char kMojoChannelToken[] = "mojo-channel-token";
// The token to use to construct the message pipe for a service in a child // The token to use to construct the message pipe for a service in a child
// process. // process.
const char kServiceRequestChannelToken[] = "service-request-channel-token"; const char kServiceRequestChannelToken[] = "service-request-channel-token";
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
namespace switches { namespace switches {
CONTENT_EXPORT extern const char kMojoChannelToken[];
CONTENT_EXPORT extern const char kServiceRequestChannelToken[]; CONTENT_EXPORT extern const char kServiceRequestChannelToken[];
} // namespace switches } // namespace switches
......
...@@ -16,8 +16,11 @@ ...@@ -16,8 +16,11 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "content/public/common/connection_filter.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/mojo_channel_switches.h" #include "content/public/common/mojo_channel_switches.h"
#include "content/public/common/service_manager_connection.h"
#include "ipc/ipc.mojom.h"
#include "ipc/ipc_channel_mojo.h" #include "ipc/ipc_channel_mojo.h"
#include "mojo/edk/embedder/configuration.h" #include "mojo/edk/embedder/configuration.h"
#include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/embedder.h"
...@@ -31,6 +34,33 @@ ...@@ -31,6 +34,33 @@
#endif #endif
namespace ipc_fuzzer { namespace ipc_fuzzer {
namespace {
class IPCChannelBootstrapper : public content::ConnectionFilter {
public:
explicit IPCChannelBootstrapper(
mojo::ScopedMessagePipeHandle bootstrap_handle)
: bootstrap_handle_(std::move(bootstrap_handle)) {}
private:
void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe,
service_manager::Connector* connector) override {
if (interface_name != IPC::mojom::ChannelBootstrap::Name_)
return;
DCHECK(bootstrap_handle_.is_valid());
mojo::FuseMessagePipes(std::move(*interface_pipe),
std::move(bootstrap_handle_));
}
mojo::ScopedMessagePipeHandle bootstrap_handle_;
DISALLOW_COPY_AND_ASSIGN(IPCChannelBootstrapper);
};
} // namespace
void InitializeMojo() { void InitializeMojo() {
mojo::edk::Configuration config; mojo::edk::Configuration config;
...@@ -109,12 +139,19 @@ bool ReplayProcess::Initialize(int argc, const char** argv) { ...@@ -109,12 +139,19 @@ bool ReplayProcess::Initialize(int argc, const char** argv) {
void ReplayProcess::OpenChannel() { void ReplayProcess::OpenChannel() {
DCHECK(broker_client_invitation_); DCHECK(broker_client_invitation_);
channel_ = IPC::ChannelProxy::Create( service_manager_connection_ = content::ServiceManagerConnection::Create(
IPC::ChannelMojo::CreateClientFactory( service_manager::mojom::ServiceRequest(
broker_client_invitation_->ExtractMessagePipe( broker_client_invitation_->ExtractMessagePipe(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kMojoChannelToken)), switches::kServiceRequestChannelToken))),
io_thread_.task_runner()), io_thread_.task_runner());
mojo::MessagePipe ipc_pipe;
service_manager_connection_->AddConnectionFilter(
base::MakeUnique<IPCChannelBootstrapper>(std::move(ipc_pipe.handle0)));
service_manager_connection_->Start();
channel_ = IPC::ChannelProxy::Create(
IPC::ChannelMojo::CreateClientFactory(std::move(ipc_pipe.handle1),
io_thread_.task_runner()),
this, io_thread_.task_runner()); this, io_thread_.task_runner());
} }
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include "ipc/ipc_message.h" #include "ipc/ipc_message.h"
#include "tools/ipc_fuzzer/message_lib/message_file.h" #include "tools/ipc_fuzzer/message_lib/message_file.h"
namespace content {
class ServiceManagerConnection;
}
namespace mojo { namespace mojo {
namespace edk { namespace edk {
class IncomingBrokerClientInvitation; class IncomingBrokerClientInvitation;
...@@ -57,6 +61,8 @@ class ReplayProcess : public IPC::Listener { ...@@ -57,6 +61,8 @@ class ReplayProcess : public IPC::Listener {
std::unique_ptr<mojo::edk::ScopedIPCSupport> mojo_ipc_support_; std::unique_ptr<mojo::edk::ScopedIPCSupport> mojo_ipc_support_;
std::unique_ptr<mojo::edk::IncomingBrokerClientInvitation> std::unique_ptr<mojo::edk::IncomingBrokerClientInvitation>
broker_client_invitation_; broker_client_invitation_;
std::unique_ptr<content::ServiceManagerConnection>
service_manager_connection_;
std::unique_ptr<IPC::ChannelProxy> channel_; std::unique_ptr<IPC::ChannelProxy> channel_;
base::MessageLoop main_loop_; base::MessageLoop main_loop_;
base::Thread io_thread_; base::Thread io_thread_;
......
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