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 = [
"+components/version_info",
"+mojo/edk/embedder",
"+sandbox/win/src",
"+services/service_manager/public",
]
......@@ -33,6 +33,7 @@
#include "content/public/common/result_codes.h"
#include "content/public/common/sandbox_init.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/named_platform_channel_pair.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
......@@ -216,20 +217,21 @@ bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults(
}
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();
if (exe_path.empty()) {
NOTREACHED() << "Unable to get utility process binary name.";
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);
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.AppendArg(switches::kPrefetchArgumentOther);
......@@ -337,7 +339,14 @@ const base::Process& ServiceUtilityProcessHost::GetProcess() const {
void ServiceUtilityProcessHost::BindInterface(
const std::string& interface_name,
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) {
......
......@@ -14,6 +14,7 @@
#include "content/public/common/child_process_host_delegate.h"
#include "ipc/ipc_platform_file.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
#include "services/service_manager/public/interfaces/service.mojom.h"
namespace base {
class CommandLine;
......@@ -155,6 +156,8 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
class PdfToEmfState;
std::unique_ptr<PdfToEmfState> pdf_to_emf_state_;
service_manager::mojom::ServicePtr utility_process_connection_;
base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost);
......
......@@ -38,6 +38,8 @@
namespace {
const char kMojoChannelToken[] = "mojo-channel-token";
// Launch the child process:
// |nss_path| - path to the NSS directory holding the decryption libraries.
// |mojo_handle| - platform handle for Mojo transport.
......@@ -48,7 +50,7 @@ base::Process LaunchNSSDecrypterChildProcess(
const std::string& mojo_channel_token) {
base::CommandLine cl(*base::CommandLine::ForCurrentProcess());
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.
// See "chrome/utility/importer/nss_decryptor_mac.mm" for an explanation of
......@@ -289,7 +291,7 @@ MULTIPROCESS_TEST_MAIN(NSSDecrypterChildProcess) {
kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor))));
mojo::ScopedMessagePipeHandle mojo_handle = invitation->ExtractMessagePipe(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kMojoChannelToken));
kMojoChannelToken));
std::unique_ptr<IPC::Channel> channel =
IPC::Channel::CreateClient(mojo_handle.release(), &listener);
......
......@@ -408,27 +408,13 @@ void ChildThreadImpl::OnFieldTrialGroupFinalized(
void ChildThreadImpl::ConnectChannel(
mojo::edk::IncomingBrokerClientInvitation* invitation) {
std::string channel_token;
mojo::ScopedMessagePipeHandle handle;
if (!IsInBrowserProcess()) {
channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kMojoChannelToken);
}
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(service_manager_connection_);
IPC::mojom::ChannelBootstrapPtr bootstrap;
mojo::ScopedMessagePipeHandle handle =
mojo::MakeRequest(&bootstrap).PassMessagePipe();
service_manager_connection_->AddConnectionFilter(
base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface()));
DCHECK(handle.is_valid());
channel_->Init(
IPC::ChannelMojo::CreateClientFactory(
std::move(handle), ChildProcess::current()->io_task_runner()),
......
......@@ -31,7 +31,6 @@
#include "ipc/ipc_channel_mojo.h"
#include "ipc/ipc_logging.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/service_manager/public/cpp/interface_provider.h"
......@@ -119,24 +118,7 @@ void ChildProcessHostImpl::ForceShutdown() {
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() {
// 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;
BindInterface(IPC::mojom::ChannelBootstrap::Name_, std::move(pipe.handle1));
......
......@@ -64,8 +64,6 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
// ChildProcessHost implementation
bool Send(IPC::Message* message) override;
void ForceShutdown() override;
std::string CreateChannelMojo(
mojo::edk::OutgoingBrokerClientInvitation* invitation) override;
void CreateChannelMojo() override;
bool IsChannelOpening() override;
void AddFilter(IPC::MessageFilter* filter) override;
......@@ -94,7 +92,6 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
base::Process peer_process_;
bool opening_channel_; // True while we're waiting the channel to be opened.
std::unique_ptr<IPC::Channel> channel_;
std::string channel_id_;
// 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
......
......@@ -12,7 +12,6 @@
#include "content/common/content_export.h"
#include "content/public/common/bind_interface_helpers.h"
#include "ipc/ipc_channel_proxy.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
namespace base {
class FilePath;
......@@ -73,14 +72,6 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Sender {
// Does not check with the delegate's CanShutdown.
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
// brokered through the Service Manager like any other service connection.
virtual void CreateChannelMojo() = 0;
......
......@@ -6,9 +6,6 @@
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
// process.
const char kServiceRequestChannelToken[] = "service-request-channel-token";
......
......@@ -9,7 +9,6 @@
namespace switches {
CONTENT_EXPORT extern const char kMojoChannelToken[];
CONTENT_EXPORT extern const char kServiceRequestChannelToken[];
} // namespace switches
......
......@@ -16,8 +16,11 @@
#include "base/run_loop.h"
#include "build/build_config.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/mojo_channel_switches.h"
#include "content/public/common/service_manager_connection.h"
#include "ipc/ipc.mojom.h"
#include "ipc/ipc_channel_mojo.h"
#include "mojo/edk/embedder/configuration.h"
#include "mojo/edk/embedder/embedder.h"
......@@ -31,6 +34,33 @@
#endif
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() {
mojo::edk::Configuration config;
......@@ -109,12 +139,19 @@ bool ReplayProcess::Initialize(int argc, const char** argv) {
void ReplayProcess::OpenChannel() {
DCHECK(broker_client_invitation_);
channel_ = IPC::ChannelProxy::Create(
IPC::ChannelMojo::CreateClientFactory(
service_manager_connection_ = content::ServiceManagerConnection::Create(
service_manager::mojom::ServiceRequest(
broker_client_invitation_->ExtractMessagePipe(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kMojoChannelToken)),
io_thread_.task_runner()),
switches::kServiceRequestChannelToken))),
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());
}
......
......@@ -19,6 +19,10 @@
#include "ipc/ipc_message.h"
#include "tools/ipc_fuzzer/message_lib/message_file.h"
namespace content {
class ServiceManagerConnection;
}
namespace mojo {
namespace edk {
class IncomingBrokerClientInvitation;
......@@ -57,6 +61,8 @@ class ReplayProcess : public IPC::Listener {
std::unique_ptr<mojo::edk::ScopedIPCSupport> mojo_ipc_support_;
std::unique_ptr<mojo::edk::IncomingBrokerClientInvitation>
broker_client_invitation_;
std::unique_ptr<content::ServiceManagerConnection>
service_manager_connection_;
std::unique_ptr<IPC::ChannelProxy> channel_;
base::MessageLoop main_loop_;
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