Commit 0a311ff4 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Move Utility processes off Service Manager

This migrates Utility processes to direct ChildProcess API usage instead
of bootstrapping IPC through the Service Manager.

As this is the last remaining use of Service Manager IPC to bootstrap
Content child processes, this also rips out a bunch of infrastructure
that existed only to support that.

Bug: 977637
Change-Id: I08e542f1d9f294bc1c387ea5845e8ba0d5a7d2b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919719
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718352}
parent cdad5b98
......@@ -31,16 +31,12 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_utility_printing_messages.h"
#include "chrome/services/printing/public/mojom/pdf_to_emf_converter.mojom.h"
#include "content/public/app/content_browser_manifest.h"
#include "content/public/app/content_utility_manifest.h"
#include "content/public/common/child_process_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/font_cache_dispatcher_win.h"
#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_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
......@@ -52,16 +48,8 @@
#include "printing/emf_win.h"
#include "sandbox/win/src/sandbox_policy.h"
#include "sandbox/win/src/sandbox_types.h"
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/constants.h"
#include "services/service_manager/public/mojom/service.mojom.h"
#include "services/service_manager/sandbox/sandbox_type.h"
#include "services/service_manager/sandbox/switches.h"
#include "services/service_manager/service_manager.h"
#include "services/service_manager/service_process_launcher.h"
#include "services/service_manager/service_process_launcher_factory.h"
#include "ui/base/ui_base_switches.h"
namespace {
......@@ -144,9 +132,8 @@ class ServiceUtilityProcessHost::PdfToEmfState {
bool Start(base::ReadOnlySharedMemoryRegion pdf_region,
const printing::PdfRenderSettings& conversion_settings) {
weak_host_->BindInterface(
printing::mojom::PdfToEmfConverterFactory::Name_,
pdf_to_emf_converter_factory_.BindNewPipeAndPassReceiver().PassPipe());
weak_host_->GetHost()->BindReceiver(
pdf_to_emf_converter_factory_.BindNewPipeAndPassReceiver());
pdf_to_emf_converter_factory_.set_disconnect_handler(base::BindOnce(
&PdfToEmfState::OnFailed, weak_host_,
......@@ -239,8 +226,8 @@ ServiceUtilityProcessHost::ServiceUtilityProcessHost(
: client_(client),
client_task_runner_(client_task_runner),
waiting_for_reply_(false) {
child_process_host_ = ChildProcessHost::Create(
this, ChildProcessHost::IpcMode::kServiceManager);
child_process_host_ =
ChildProcessHost::Create(this, ChildProcessHost::IpcMode::kNormal);
}
ServiceUtilityProcessHost::~ServiceUtilityProcessHost() {
......@@ -310,63 +297,12 @@ bool ServiceUtilityProcessHost::StartProcess(bool sandbox) {
return false;
}
// We set up a Service Manager for each utility process hosted here. The
// utility processes launched by the service process only ever need to
// communicate back to the service process itself, so it's safe to host each
// one using its own isolated service manager.
//
// We do this because some common child process code expects to be connected
// to a well-behaved service manager from which it can request common host
// interfaces.
//
// In the isolated service environment there are exactly two service
// instances: this process, which masquerades as "content_browser"; and the
// child process, which exists ostensibly as the only instance of
// "content_utility". This is all set up here.
std::vector<service_manager::Manifest> manifests{
content::GetContentBrowserManifest(),
content::GetContentUtilityManifest()};
service_manager_ = std::make_unique<service_manager::ServiceManager>(
manifests,
service_manager::ServiceManager::ServiceExecutablePolicy::kNotSupported);
service_manager::mojom::ServicePtrInfo browser_proxy;
service_manager_connection_ = content::ServiceManagerConnection::Create(
mojo::MakeRequest(&browser_proxy),
base::SequencedTaskRunnerHandle::Get());
mojo::Remote<service_manager::mojom::ProcessMetadata> metadata;
service_manager_->RegisterService(
service_manager::Identity(content::mojom::kBrowserServiceName,
service_manager::kSystemInstanceGroup,
base::Token{}, base::Token::CreateRandom()),
std::move(browser_proxy), metadata.BindNewPipeAndPassReceiver());
metadata->SetPID(base::GetCurrentProcId());
metadata.reset();
std::string mojo_bootstrap_token = base::NumberToString(base::RandUint64());
service_manager::mojom::ServicePtrInfo utility_service(
mojo_invitation_.AttachMessagePipe(mojo_bootstrap_token), 0u);
utility_service_instance_identity_ =
service_manager::Identity(content::mojom::kUtilityServiceName,
service_manager::kSystemInstanceGroup,
base::Token{}, base::Token::CreateRandom());
service_manager_->RegisterService(utility_service_instance_identity_,
std::move(utility_service),
metadata.BindNewPipeAndPassReceiver());
metadata->SetPID(base::GetCurrentProcId());
service_manager_connection_->Start();
// NOTE: This call to |CreateChannelMojo()| requires a working
// ServiceManagerConnection to have already been established.
child_process_host_->CreateChannelMojo();
base::CommandLine cmd_line(exe_path);
cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess);
cmd_line.AppendSwitchASCII(
service_manager::switches::kServiceRequestChannelToken,
mojo_bootstrap_token);
cmd_line.AppendSwitch(switches::kLang);
cmd_line.AppendArg(switches::kPrefetchArgumentOther);
......@@ -397,6 +333,8 @@ bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line,
cmd_line->CopySwitchesFrom(service_command_line, kForwardSwitches,
base::size(kForwardSwitches));
mojo::OutgoingInvitation mojo_invitation =
std::move(*child_process_host_->GetMojoInvitation());
if (sandbox) {
mojo::PlatformChannel channel;
base::HandlesToInheritVector handles;
......@@ -410,7 +348,7 @@ bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line,
return false;
process_ = std::move(process);
mojo::OutgoingInvitation::Send(std::move(mojo_invitation_),
mojo::OutgoingInvitation::Send(std::move(mojo_invitation),
process_.Handle(),
channel.TakeLocalEndpoint());
} else {
......@@ -420,7 +358,7 @@ bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line,
cmd_line->AppendSwitch(service_manager::switches::kNoSandbox);
process_ = base::LaunchProcess(*cmd_line, base::LaunchOptions());
mojo::OutgoingInvitation::Send(std::move(mojo_invitation_),
mojo::OutgoingInvitation::Send(std::move(mojo_invitation),
process_.Handle(),
channel.TakeServerEndpoint());
}
......@@ -475,13 +413,6 @@ const base::Process& ServiceUtilityProcessHost::GetProcess() {
return process_;
}
void ServiceUtilityProcessHost::BindInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
child_process_host_->BindReceiver(
mojo::GenericPendingReceiver(interface_name, std::move(interface_pipe)));
}
void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) {
if (!success || pdf_to_emf_state_->OnPageProcessed())
OnPDFToEmfFinished(success);
......
......@@ -15,8 +15,6 @@
#include "content/public/common/child_process_host_delegate.h"
#include "ipc/ipc_platform_file.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/public/cpp/identity.h"
namespace base {
class CommandLine;
......@@ -26,7 +24,6 @@ class SingleThreadTaskRunner;
namespace content {
class ChildProcessHost;
class ServiceManagerConnection;
}
namespace printing {
......@@ -36,10 +33,6 @@ struct PrinterCapsAndDefaults;
struct PrinterSemanticCapsAndDefaults;
} // namespace printing
namespace service_manager {
class ServiceManager;
}
// Acts as the service-side host to a utility child process. A
// utility process is a short-lived sandboxed process that is created to run
// a specific task.
......@@ -97,6 +90,8 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
base::SingleThreadTaskRunner* client_task_runner);
~ServiceUtilityProcessHost() override;
content::ChildProcessHost* GetHost() { return child_process_host_.get(); }
// Starts a process to render the specified pages in the given PDF file into
// a metafile. Currently only implemented for Windows. If the PDF has fewer
// pages than the specified page ranges, it will render as many as available.
......@@ -126,8 +121,6 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
void OnChildDisconnected() override;
bool OnMessageReceived(const IPC::Message& message) override;
const base::Process& GetProcess() override;
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
void BindHostReceiver(mojo::GenericPendingReceiver receiver) override;
private:
......@@ -167,16 +160,10 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
scoped_refptr<Client> client_;
scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_;
bool waiting_for_reply_;
mojo::OutgoingInvitation mojo_invitation_;
class PdfToEmfState;
std::unique_ptr<PdfToEmfState> pdf_to_emf_state_;
std::unique_ptr<service_manager::ServiceManager> service_manager_;
std::unique_ptr<content::ServiceManagerConnection>
service_manager_connection_;
service_manager::Identity utility_service_instance_identity_;
base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost);
......
......@@ -302,8 +302,6 @@ jumbo_source_set("browser") {
"$target_gen_dir/devtools/protocol/tracing.h",
"../app_shim_remote_cocoa/web_drag_source_mac.h",
"../app_shim_remote_cocoa/web_drag_source_mac.mm",
"../common/service_manager/child_connection.cc",
"../common/service_manager/child_connection.h",
"about_url_loader_factory.cc",
"about_url_loader_factory.h",
"accessibility/accessibility_event_recorder.cc",
......
......@@ -33,10 +33,8 @@
#include "content/browser/bad_message.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/histogram_controller.h"
#include "content/browser/service_manager/service_manager_context.h"
#include "content/browser/tracing/background_tracing_manager_impl.h"
#include "content/common/child_process_host_impl.h"
#include "content/common/service_manager/child_connection.h"
#include "content/public/browser/browser_child_process_host_delegate.h"
#include "content/public/browser/browser_child_process_observer.h"
#include "content/public/browser/browser_message_filter.h"
......@@ -52,12 +50,10 @@
#include "content/public/common/process_type.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "content/public/common/service_manager_connection.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "net/websockets/websocket_basic_stream.h"
#include "net/websockets/websocket_channel.h"
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/public/cpp/constants.h"
#include "services/tracing/public/cpp/trace_startup.h"
#if defined(OS_MACOSX)
......@@ -217,24 +213,6 @@ BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
CreateMetricsAllocator();
}
BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
content::ProcessType process_type,
BrowserChildProcessHostDelegate* delegate,
const std::string& service_name)
: BrowserChildProcessHostImpl(process_type,
delegate,
ChildProcessHost::IpcMode::kServiceManager) {
DCHECK(!service_name.empty());
child_connection_ = std::make_unique<ChildConnection>(
service_manager::Identity(
service_name, service_manager::kSystemInstanceGroup,
base::Token::CreateRandom(), base::Token::CreateRandom()),
&child_process_host_->GetMojoInvitation().value(),
ServiceManagerContext::GetConnectorForIOThread(),
base::ThreadTaskRunnerHandle::Get());
data_.metrics_name = service_name;
}
BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() {
g_child_process_list.Get().remove(this);
......@@ -332,15 +310,6 @@ void BrowserChildProcessHostImpl::SetProcess(base::Process process) {
data_.SetProcess(std::move(process));
}
service_manager::mojom::ServiceRequest
BrowserChildProcessHostImpl::TakeInProcessServiceRequest() {
base::Optional<mojo::OutgoingInvitation> invitation =
std::move(child_process_host_->GetMojoInvitation());
DCHECK(invitation);
return service_manager::mojom::ServiceRequest(
invitation->ExtractMessagePipe(child_connection_->service_token()));
}
void BrowserChildProcessHostImpl::ForceShutdown() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
g_child_process_list.Get().remove(this);
......@@ -378,21 +347,6 @@ void BrowserChildProcessHostImpl::LaunchWithoutExtraCommandLineSwitches(
cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches,
base::size(kForwardSwitches));
if (child_connection_) {
cmd_line->AppendSwitchASCII(
service_manager::switches::kServiceRequestChannelToken,
child_connection_->service_token());
// Tracing adds too much overhead to the profiling service.
if (service_manager::SandboxTypeFromCommandLine(*cmd_line) !=
service_manager::SANDBOX_TYPE_PROFILING) {
BackgroundTracingManagerImpl::ActivateForProcess(
data_.id,
static_cast<ChildProcessHostImpl*>(child_process_host_.get())
->child_process());
}
}
// All processes should have a non-empty metrics name.
if (data_.metrics_name.empty())
data_.metrics_name = GetProcessTypeNameInEnglish(data_.process_type);
......@@ -408,16 +362,6 @@ void BrowserChildProcessHostImpl::LaunchWithoutExtraCommandLineSwitches(
ShareMetricsAllocatorToProcess();
}
void BrowserChildProcessHostImpl::BindInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!child_connection_)
return;
child_connection_->BindInterface(interface_name, std::move(interface_pipe));
}
void BrowserChildProcessHostImpl::HistogramBadMessageTerminated(
ProcessType process_type) {
UMA_HISTOGRAM_ENUMERATION("ChildProcess.BadMessgeTerminated", process_type,
......@@ -677,9 +621,6 @@ void BrowserChildProcessHostImpl::OnProcessLaunched() {
const base::Process& process = child_process_->GetProcess();
DCHECK(process.IsValid());
if (child_connection_)
child_connection_->SetProcess(process.Duplicate());
#if defined(OS_WIN)
// Start a WaitableEventWatcher that will invoke OnProcessExitedEarly if the
// child process exits. This watcher is stopped once the IPC channel is
......
......@@ -42,7 +42,6 @@ namespace content {
class BrowserChildProcessHostIterator;
class BrowserChildProcessObserver;
class BrowserMessageFilter;
class ChildConnection;
// Plugins/workers and other child processes that live on the IO thread use this
// class. RenderProcessHostImpl is the main exception that doesn't use this
......@@ -56,14 +55,7 @@ class CONTENT_EXPORT BrowserChildProcessHostImpl
public ChildProcessLauncher::Client,
public memory_instrumentation::mojom::CoordinatorConnector {
public:
// Constructs a process host with Service Manager IPC support.
BrowserChildProcessHostImpl(content::ProcessType process_type,
BrowserChildProcessHostDelegate* delegate,
const std::string& service_name);
// Constructs a process host with |ipc_mode| determining how IPC is done.
// To use |IpcMode::kServiceManager|, use the above constructor instead, which
// also provides the child process's service name.
BrowserChildProcessHostImpl(content::ProcessType process_type,
BrowserChildProcessHostDelegate* delegate,
ChildProcessHost::IpcMode ipc_mode);
......@@ -101,14 +93,11 @@ class CONTENT_EXPORT BrowserChildProcessHostImpl
void SetName(const base::string16& name) override;
void SetMetricsName(const std::string& metrics_name) override;
void SetProcess(base::Process process) override;
service_manager::mojom::ServiceRequest TakeInProcessServiceRequest() override;
// ChildProcessHostDelegate implementation:
void OnChannelInitialized(IPC::Channel* channel) override;
void OnChildDisconnected() override;
const base::Process& GetProcess() override;
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
void BindHostReceiver(mojo::GenericPendingReceiver receiver) override;
bool OnMessageReceived(const IPC::Message& message) override;
void OnChannelConnected(int32_t peer_pid) override;
......@@ -143,10 +132,6 @@ class CONTENT_EXPORT BrowserChildProcessHostImpl
BrowserChildProcessHostDelegate* delegate() const { return delegate_; }
ChildConnection* child_connection() const {
return child_connection_.get();
}
mojo::OutgoingInvitation* GetInProcessMojoInvitation() {
return &child_process_host_->GetMojoInvitation().value();
}
......@@ -211,8 +196,6 @@ class CONTENT_EXPORT BrowserChildProcessHostImpl
mojo::Receiver<memory_instrumentation::mojom::CoordinatorConnector>
coordinator_connector_receiver_{this};
std::unique_ptr<ChildConnection> child_connection_;
std::unique_ptr<ChildProcessLauncher> child_process_;
#if defined(OS_WIN)
......
......@@ -8,7 +8,6 @@
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "content/public/app/content_browser_manifest.h"
#include "content/public/app/content_utility_manifest.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
......@@ -38,12 +37,6 @@ const std::vector<service_manager::Manifest>& GetBuiltinServiceManifests() {
std::vector<service_manager::Manifest>{
GetContentBrowserManifest(),
// NOTE: Content child processes are of course not running in the
// browser process, but the distinction between "in-process" and
// "out-of-process" manifests is temporary. For now, this is the right
// place for these manifests.
GetContentUtilityManifest(),
audio::GetManifest(IsAudioServiceOutOfProcess()
? service_manager::Manifest::ExecutionMode::
kOutOfProcessBuiltin
......
......@@ -19,11 +19,9 @@
#include "components/network_session_configurator/common/network_switches.h"
#include "content/browser/browser_child_process_host_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/service_manager/service_manager_context.h"
#include "content/browser/v8_snapshot_files.h"
#include "content/common/child_process_host_impl.h"
#include "content/common/in_process_child_thread_params.h"
#include "content/common/service_manager/child_connection.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
......@@ -32,8 +30,6 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/process_type.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
#include "media/base/media_switches.h"
#include "media/webrtc/webrtc_switches.h"
#include "services/network/public/cpp/network_switches.h"
......@@ -221,8 +217,8 @@ UtilityProcessHost::UtilityProcessHost(std::unique_ptr<Client> client)
started_(false),
name_(base::ASCIIToUTF16("utility process")),
client_(std::move(client)) {
process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this,
mojom::kUtilityServiceName));
process_.reset(new BrowserChildProcessHostImpl(
PROCESS_TYPE_UTILITY, this, ChildProcessHost::IpcMode::kNormal));
}
UtilityProcessHost::~UtilityProcessHost() {
......@@ -319,8 +315,7 @@ bool UtilityProcessHost::StartProcess() {
in_process_thread_.reset(
g_utility_main_thread_factory(InProcessChildThreadParams(
base::CreateSingleThreadTaskRunner({BrowserThread::IO}),
process_->GetInProcessMojoInvitation(),
process_->child_connection()->service_token())));
process_->GetInProcessMojoInvitation())));
in_process_thread_->Start();
} else {
const base::CommandLine& browser_command_line =
......
......@@ -49,13 +49,9 @@
#include "content/common/child_process.mojom.h"
#include "content/common/field_trial_recorder.mojom.h"
#include "content/common/in_process_child_thread_params.h"
#include "content/public/common/connection_filter.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
#include "content/public/common/simple_connection_filter.h"
#include "ipc/ipc_channel_mojo.h"
#include "ipc/ipc_logging.h"
#include "ipc/ipc_platform_file.h"
......@@ -77,7 +73,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/service_manager/embedder/switches.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/sandbox/sandbox_type.h"
#if defined(OS_POSIX)
......@@ -236,36 +231,6 @@ mojo::IncomingInvitation InitializeMojoIPCChannel() {
std::move(endpoint), MOJO_ACCEPT_INVITATION_FLAG_LEAK_TRANSPORT_ENDPOINT);
}
class ChannelBootstrapFilter : public ConnectionFilter {
public:
explicit ChannelBootstrapFilter(
mojo::PendingRemote<IPC::mojom::ChannelBootstrap> bootstrap)
: bootstrap_(std::move(bootstrap)) {}
private:
// ConnectionFilter:
void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe,
service_manager::Connector* connector) override {
if (source_info.identity.name() != mojom::kBrowserServiceName &&
source_info.identity.name() != mojom::kSystemServiceName) {
return;
}
if (interface_name == IPC::mojom::ChannelBootstrap::Name_) {
DCHECK(bootstrap_.is_valid());
mojo::FusePipes(mojo::PendingReceiver<IPC::mojom::ChannelBootstrap>(
std::move(*interface_pipe)),
std::move(bootstrap_));
}
}
mojo::PendingRemote<IPC::mojom::ChannelBootstrap> bootstrap_;
DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter);
};
} // namespace
// Implements the mojom ChildProcess interface and lives on the IO thread.
......@@ -465,7 +430,6 @@ ChildThreadImpl::Options::Builder&
ChildThreadImpl::Options::Builder::InBrowserProcess(
const InProcessChildThreadParams& params) {
options_.browser_process_io_runner = params.io_runner();
options_.in_process_service_request_token = params.service_request_token();
options_.mojo_invitation = params.mojo_invitation();
return *this;
}
......@@ -572,22 +536,6 @@ void ChildThreadImpl::OnFieldTrialGroupFinalized(
field_trial_recorder->FieldTrialActivated(trial_name);
}
void ChildThreadImpl::ConnectLegacyIpcChannelThroughServiceManager() {
DCHECK(service_manager_connection_);
mojo::PendingRemote<IPC::mojom::ChannelBootstrap> bootstrap;
mojo::ScopedMessagePipeHandle handle =
bootstrap.InitWithNewPipeAndPassReceiver().PassPipe();
service_manager_connection_->AddConnectionFilter(
std::make_unique<ChannelBootstrapFilter>(std::move(bootstrap)));
channel_->Init(
IPC::ChannelMojo::CreateClientFactory(
std::move(handle), ChildProcess::current()->io_task_runner(),
ipc_task_runner_ ? ipc_task_runner_
: base::ThreadTaskRunnerHandle::Get()),
true /* create_pipe_now */);
}
void ChildThreadImpl::Init(const Options& options) {
TRACE_EVENT0("startup", "ChildThreadImpl::Init");
g_lazy_child_thread_impl_tls.Pointer()->Set(this);
......@@ -613,59 +561,32 @@ void ChildThreadImpl::Init(const Options& options) {
// whether we were launched in normal IPC mode or deprecated Service Manager
// IPC mode.
mojo::ScopedMessagePipeHandle child_process_pipe;
mojo::ScopedMessagePipeHandle service_request_pipe;
if (!IsInBrowserProcess()) {
mojo_ipc_support_.reset(new mojo::core::ScopedIPCSupport(
GetIOTaskRunner(), mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST));
mojo::IncomingInvitation invitation = InitializeMojoIPCChannel();
std::string service_request_token =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
service_manager::switches::kServiceRequestChannelToken);
if (!service_request_token.empty()) {
service_request_pipe =
invitation.ExtractMessagePipe(service_request_token);
} else {
child_process_pipe = invitation.ExtractMessagePipe(0);
}
child_process_pipe = invitation.ExtractMessagePipe(0);
} else {
if (!options.in_process_service_request_token.empty()) {
service_request_pipe = options.mojo_invitation->ExtractMessagePipe(
options.in_process_service_request_token);
} else {
child_process_pipe = options.mojo_invitation->ExtractMessagePipe(0);
}
child_process_pipe = options.mojo_invitation->ExtractMessagePipe(0);
}
if (service_request_pipe.is_valid()) {
// We're in deprecated legacy IPC mode. Initialize a connection to the
// Service Manager.
service_manager_connection_ = ServiceManagerConnection::Create(
service_manager::mojom::ServiceRequest(std::move(service_request_pipe)),
GetIOTaskRunner());
} else {
// We're in normal IPC mode. Set up the ChildProcess receiver and legacy IPC
// Channel.
DCHECK(child_process_pipe.is_valid());
mojo::PendingRemote<IPC::mojom::ChannelBootstrap> legacy_ipc_bootstrap;
mojo::ScopedMessagePipeHandle legacy_ipc_channel_handle =
legacy_ipc_bootstrap.InitWithNewPipeAndPassReceiver().PassPipe();
channel_->Init(IPC::ChannelMojo::CreateClientFactory(
std::move(legacy_ipc_channel_handle),
ChildProcess::current()->io_task_runner(),
ipc_task_runner_ ? ipc_task_runner_
: base::ThreadTaskRunnerHandle::Get()),
/*create_pipe_now=*/true);
ChildThreadImpl::GetIOTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&IOThreadState::BindChildProcessReceiverAndLegacyIpc,
io_thread_state_,
mojo::PendingReceiver<mojom::ChildProcess>(
std::move(child_process_pipe)),
std::move(legacy_ipc_bootstrap)));
}
mojo::PendingRemote<IPC::mojom::ChannelBootstrap> legacy_ipc_bootstrap;
mojo::ScopedMessagePipeHandle legacy_ipc_channel_handle =
legacy_ipc_bootstrap.InitWithNewPipeAndPassReceiver().PassPipe();
channel_->Init(IPC::ChannelMojo::CreateClientFactory(
std::move(legacy_ipc_channel_handle),
ChildProcess::current()->io_task_runner(),
ipc_task_runner_ ? ipc_task_runner_
: base::ThreadTaskRunnerHandle::Get()),
/*create_pipe_now=*/true);
ChildThreadImpl::GetIOTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&IOThreadState::BindChildProcessReceiverAndLegacyIpc,
io_thread_state_,
mojo::PendingReceiver<mojom::ChildProcess>(
std::move(child_process_pipe)),
std::move(legacy_ipc_bootstrap)));
sync_message_filter_ = channel_->CreateSyncMessageFilter();
thread_safe_sender_ =
......@@ -713,19 +634,6 @@ void ChildThreadImpl::Init(const Options& options) {
channel_->AddFilter(startup_filter);
}
if (service_manager_connection_) {
auto registry = std::make_unique<service_manager::BinderRegistry>();
registry->AddInterface(
base::BindRepeating(&IOThreadState::BindChildProcessReceiver,
io_thread_state_),
ChildThreadImpl::GetIOTaskRunner());
service_manager_connection_->AddConnectionFilter(
std::make_unique<SimpleConnectionFilter>(std::move(registry)));
ConnectLegacyIpcChannelThroughServiceManager();
StartServiceManagerConnection();
}
int connection_timeout = kConnectionTimeoutS;
std::string connection_override =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
......@@ -868,15 +776,6 @@ void ChildThreadImpl::OnAssociatedInterfaceRequest(
}
}
void ChildThreadImpl::StartServiceManagerConnection() {
DCHECK(service_manager_connection_);
// NOTE: You must register any ConnectionFilter instances on
// |service_manager_connection_| *before* this call to |Start()|, otherwise
// incoming interface requests may race with the registration.
service_manager_connection_->Start();
}
void ChildThreadImpl::ExposeInterfacesToBrowser(mojo::BinderMap binders) {
// NOTE: Do not add new binders directly within this method. Instead, modify
// the definition of |ExposeChildInterfacesToBrowser()|, ensuring security
......
......@@ -61,7 +61,6 @@ class BackgroundTracingAgentProviderImpl;
namespace content {
class InProcessChildThreadParams;
class ServiceManagerConnection;
class ThreadSafeSender;
// The main thread of a child process derives from this class.
......@@ -157,12 +156,6 @@ class CONTENT_EXPORT ChildThreadImpl
// Called when the process refcount is 0.
virtual void OnProcessFinalRelease();
// Called by subclasses to manually start the ServiceManagerConnection. Must
// only be called if
// ChildThreadImpl::Options::auto_start_service_manager_connection was set to
// |false| on ChildThreadImpl construction.
void StartServiceManagerConnection();
// Must be called by subclasses during initialization if and only if they set
// |Options::expose_interfaces_to_browser| to |true|. This makes |binders|
// available to handle incoming interface requests from the browser.
......@@ -198,10 +191,6 @@ class CONTENT_EXPORT ChildThreadImpl
void Init(const Options& options);
// We create the channel first without connecting it so we can add filters
// prior to any messages being received, then connect it afterwards.
void ConnectLegacyIpcChannelThroughServiceManager();
// IPC message handlers.
void EnsureConnected();
......@@ -223,7 +212,6 @@ class CONTENT_EXPORT ChildThreadImpl
#endif
std::unique_ptr<mojo::core::ScopedIPCSupport> mojo_ipc_support_;
std::unique_ptr<ServiceManagerConnection> service_manager_connection_;
mojo::AssociatedReceiver<mojom::RouteProvider> route_provider_receiver_{this};
mojo::AssociatedReceiverSet<blink::mojom::AssociatedInterfaceProvider,
......@@ -289,7 +277,6 @@ struct ChildThreadImpl::Options {
scoped_refptr<base::SingleThreadTaskRunner> browser_process_io_runner;
std::vector<IPC::MessageFilter*> startup_filters;
mojo::OutgoingInvitation* mojo_invitation;
std::string in_process_service_request_token;
scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner;
// Indicates that this child process exposes one or more Mojo interfaces to
......
......@@ -150,12 +150,6 @@ void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) {
filter->OnFilterAdded(channel_.get());
}
void ChildProcessHostImpl::BindInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
return delegate_->BindInterface(interface_name, std::move(interface_pipe));
}
void ChildProcessHostImpl::BindReceiver(mojo::GenericPendingReceiver receiver) {
child_process_->BindReceiver(std::move(receiver));
}
......@@ -176,23 +170,16 @@ ChildProcessHostImpl::GetMojoInvitation() {
}
void ChildProcessHostImpl::CreateChannelMojo() {
// If in legacy mode, |channel_| is already initialized by the constructor,
// not bound through the Service Manager.
// If in legacy mode, |channel_| is already initialized by the constructor
// not bound through the ChildProcess API.
if (ipc_mode_ != IpcMode::kLegacy) {
DCHECK(!channel_);
DCHECK_EQ(ipc_mode_, IpcMode::kNormal);
DCHECK(child_process_);
mojo::PendingRemote<IPC::mojom::ChannelBootstrap> bootstrap;
auto bootstrap_receiver = bootstrap.InitWithNewPipeAndPassReceiver();
if (ipc_mode_ == IpcMode::kServiceManager) {
BindInterface(IPC::mojom::ChannelBootstrap::Name_,
bootstrap_receiver.PassPipe());
} else {
DCHECK_EQ(ipc_mode_, IpcMode::kNormal);
DCHECK(child_process_);
child_process_->BootstrapLegacyIpc(std::move(bootstrap_receiver));
}
child_process_->BootstrapLegacyIpc(std::move(bootstrap_receiver));
channel_ = IPC::ChannelMojo::Create(
bootstrap.PassPipe(), IPC::Channel::MODE_SERVER, this,
base::ThreadTaskRunnerHandle::Get(),
......@@ -214,21 +201,6 @@ bool ChildProcessHostImpl::InitChannel() {
delegate_->OnChannelInitialized(channel_.get());
// In legacy mode, |child_process_| endpoint is already bound to a
// disconnected pipe and will remain dysfunctional. In normal mode, it's bound
// in the constructor.
if (!child_process_) {
DCHECK_EQ(ipc_mode_, IpcMode::kServiceManager);
// We want to bind this interface as early as possible, but the constructor
// is too early. |delegate_| may not be fully initialized at that point and
// thus may be unable to properly fulfill the BindInterface() call. Instead
// we bind here since the |delegate_| has already been initialized and this
// is the first potential use of the interface.
mojo::Remote<mojom::ChildProcess> bootstrap;
content::BindInterface(this, child_process_.BindNewPipeAndPassReceiver());
child_process_->Initialize(bootstrap_receiver_.BindNewPipeAndPassRemote());
}
// Make sure these messages get sent first.
#if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED)
bool enabled = IPC::Logging::GetInstance()->Enabled();
......
......@@ -75,8 +75,6 @@ class CONTENT_EXPORT ChildProcessHostImpl
void CreateChannelMojo() override;
bool IsChannelOpening() override;
void AddFilter(IPC::MessageFilter* filter) override;
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
void BindReceiver(mojo::GenericPendingReceiver receiver) override;
void RunService(
const std::string& service_name,
......
......@@ -8,11 +8,8 @@ namespace content {
InProcessChildThreadParams::InProcessChildThreadParams(
scoped_refptr<base::SingleThreadTaskRunner> io_runner,
mojo::OutgoingInvitation* mojo_invitation,
const std::string& service_request_token)
: io_runner_(std::move(io_runner)),
mojo_invitation_(mojo_invitation),
service_request_token_(service_request_token) {}
mojo::OutgoingInvitation* mojo_invitation)
: io_runner_(std::move(io_runner)), mojo_invitation_(mojo_invitation) {}
InProcessChildThreadParams::InProcessChildThreadParams(
const InProcessChildThreadParams& other) = default;
......
......@@ -5,8 +5,6 @@
#ifndef CONTENT_COMMON_IN_PROCESS_CHILD_THREAD_PARAMS_H_
#define CONTENT_COMMON_IN_PROCESS_CHILD_THREAD_PARAMS_H_
#include <string>
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "content/common/content_export.h"
......@@ -21,8 +19,7 @@ class CONTENT_EXPORT InProcessChildThreadParams {
public:
InProcessChildThreadParams(
scoped_refptr<base::SingleThreadTaskRunner> io_runner,
mojo::OutgoingInvitation* mojo_invitation,
const std::string& service_request_token = {});
mojo::OutgoingInvitation* mojo_invitation);
InProcessChildThreadParams(const InProcessChildThreadParams& other);
~InProcessChildThreadParams();
......@@ -32,14 +29,9 @@ class CONTENT_EXPORT InProcessChildThreadParams {
mojo::OutgoingInvitation* mojo_invitation() const { return mojo_invitation_; }
const std::string& service_request_token() const {
return service_request_token_;
}
private:
scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
mojo::OutgoingInvitation* const mojo_invitation_;
std::string service_request_token_;
};
} // namespace content
......
// 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 "content/common/service_manager/child_connection.h"
#include <stdint.h>
#include <utility>
#include "base/bind.h"
#include "base/macros.h"
#include "base/process/process.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "content/public/common/service_manager_connection.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/mojom/service.mojom.h"
namespace content {
class ChildConnection::IOThreadContext
: public base::RefCountedThreadSafe<IOThreadContext> {
public:
IOThreadContext() {}
void Initialize(const service_manager::Identity& child_identity,
service_manager::Connector* connector,
mojo::ScopedMessagePipeHandle service_pipe,
scoped_refptr<base::SequencedTaskRunner> io_task_runner) {
DCHECK(!io_task_runner_);
io_task_runner_ = io_task_runner;
std::unique_ptr<service_manager::Connector> io_thread_connector;
if (connector)
connector_ = connector->Clone();
child_identity_ = child_identity;
io_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&IOThreadContext::InitializeOnIOThread, this,
child_identity, std::move(service_pipe)));
}
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
io_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&IOThreadContext::BindInterfaceOnIOThread, this,
interface_name, std::move(interface_pipe)));
}
void ShutDown() {
if (!io_task_runner_)
return;
bool posted = io_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&IOThreadContext::ShutDownOnIOThread, this));
DCHECK(posted);
}
void BindInterfaceOnIOThread(const std::string& interface_name,
mojo::ScopedMessagePipeHandle request_handle) {
if (connector_) {
connector_->BindInterface(child_identity_, interface_name,
std::move(request_handle));
}
}
void SetProcess(base::Process process) {
DCHECK(io_task_runner_);
io_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&IOThreadContext::SetProcessOnIOThread, this,
std::move(process)));
}
private:
friend class base::RefCountedThreadSafe<IOThreadContext>;
virtual ~IOThreadContext() {}
void InitializeOnIOThread(
const service_manager::Identity& child_identity,
mojo::ScopedMessagePipeHandle service_pipe) {
auto metadata_receiver = remote_metadata_.BindNewPipeAndPassReceiver();
if (connector_) {
connector_->RegisterServiceInstance(
child_identity,
mojo::PendingRemote<service_manager::mojom::Service>(
std::move(service_pipe), 0),
std::move(metadata_receiver));
}
}
void ShutDownOnIOThread() {
connector_.reset();
remote_metadata_.reset();
}
void SetProcessOnIOThread(base::Process process) {
DCHECK(remote_metadata_);
remote_metadata_->SetPID(process.Pid());
remote_metadata_.reset();
process_ = std::move(process);
}
scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
// Usable from the IO thread only.
std::unique_ptr<service_manager::Connector> connector_;
service_manager::Identity child_identity_;
mojo::Remote<service_manager::mojom::ProcessMetadata> remote_metadata_;
// Hold onto the process, and thus its process handle, so that the pid will
// remain valid.
base::Process process_;
DISALLOW_COPY_AND_ASSIGN(IOThreadContext);
};
ChildConnection::ChildConnection(
const service_manager::Identity& child_identity,
mojo::OutgoingInvitation* invitation,
service_manager::Connector* connector,
scoped_refptr<base::SequencedTaskRunner> io_task_runner)
: context_(new IOThreadContext), child_identity_(child_identity) {
service_token_ = base::NumberToString(base::RandUint64());
context_->Initialize(child_identity_, connector,
invitation->AttachMessagePipe(service_token_),
io_task_runner);
}
ChildConnection::~ChildConnection() {
context_->ShutDown();
}
void ChildConnection::BindInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
context_->BindInterface(interface_name, std::move(interface_pipe));
}
void ChildConnection::SetProcess(base::Process process) {
context_->SetProcess(std::move(process));
}
} // namespace content
// 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 CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_
#define CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process.h"
#include "base/sequenced_task_runner.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/mojom/connector.mojom.h"
namespace service_manager {
class Connector;
}
namespace content {
// Helper class to establish a connection between the Service Manager and a
// single child process. Process hosts can use this when launching new processes
// which should be registered with the service manager.
class CONTENT_EXPORT ChildConnection {
public:
// Prepares a new child connection for a child process which will be
// identified to the service manager as |child_identity|. |child_identity|'s
// instance field must be unique among all child connections using the same
// service name. |connector| is the connector to use to establish the
// connection.
ChildConnection(const service_manager::Identity& child_identity,
mojo::OutgoingInvitation* invitation,
service_manager::Connector* connector,
scoped_refptr<base::SequencedTaskRunner> io_task_runner);
~ChildConnection();
// Binds an implementation of |interface_name| to |interface_pipe| in the
// child.
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe);
const service_manager::Identity& child_identity() const {
return child_identity_;
}
// A token which must be passed to the child process via
// |service_manager::switches::kServicePipeToken| in order for the child to
// initialize its end of the Service Manager connection pipe.
std::string service_token() const { return service_token_; }
// Sets the child connection's process. This should be called as soon
// as the process has been launched, and the connection will not be fully
// functional until this is called.
void SetProcess(base::Process process);
private:
class IOThreadContext;
scoped_refptr<IOThreadContext> context_;
service_manager::Identity child_identity_;
std::string service_token_;
base::WeakPtrFactory<ChildConnection> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ChildConnection);
};
} // namespace content
#endif // CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_
......@@ -19,8 +19,6 @@
#include "base/threading/thread_checker.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "content/public/common/connection_filter.h"
#include "content/public/common/service_names.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/system/message_pipe.h"
......@@ -96,27 +94,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
DCHECK(posted);
}
// Safe to call any time before a message is received from a process.
// i.e. can be called when starting the process but not afterwards.
int AddConnectionFilter(std::unique_ptr<ConnectionFilter> filter) {
base::AutoLock lock(lock_);
int id = ++next_filter_id_;
// We should never hit this in practice, but let's crash just in case.
CHECK_NE(id, kInvalidConnectionFilterId);
connection_filters_[id] = std::move(filter);
return id;
}
void RemoveConnectionFilter(int filter_id) {
io_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&IOThreadContext::RemoveConnectionFilterOnIOThread, this,
filter_id));
}
void AddServiceRequestHandler(const std::string& name,
const ServiceRequestHandler& handler) {
AddServiceRequestHandlerWithCallback(
......@@ -198,7 +175,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
}
void StopOnIOThread() {
ClearConnectionFiltersOnIOThread();
request_handlers_.clear();
}
......@@ -225,20 +201,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
StopOnIOThread();
}
void ClearConnectionFiltersOnIOThread() {
base::AutoLock lock(lock_);
connection_filters_.clear();
}
void RemoveConnectionFilterOnIOThread(int filter_id) {
base::AutoLock lock(lock_);
auto it = connection_filters_.find(filter_id);
// During shutdown the connection filters might have been cleared already
// by ClearConnectionFiltersOnIOThread() above, so this id might not exist.
if (it != connection_filters_.end())
connection_filters_.erase(it);
}
void AddServiceRequestHandlerOnIoThread(
const std::string& name,
const ServiceRequestHandlerWithCallback& handler) {
......@@ -253,18 +215,7 @@ class ServiceManagerConnectionImpl::IOThreadContext
void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override {
DCHECK(io_thread_checker_.CalledOnValidThread());
base::AutoLock lock(lock_);
for (auto& entry : connection_filters_) {
entry.second->OnBindInterface(source_info, interface_name,
&interface_pipe,
service_binding_->GetConnector());
// A filter may have bound the interface, claiming the pipe.
if (!interface_pipe.is_valid())
return;
}
}
mojo::ScopedMessagePipeHandle interface_pipe) override {}
void CreatePackagedServiceInstance(
const std::string& service_name,
......@@ -289,7 +240,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
}
void OnDisconnected() override {
ClearConnectionFiltersOnIOThread();
callback_task_runner_->PostTask(FROM_HERE, std::move(stop_callback_));
}
......@@ -318,12 +268,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
// Not owned.
MessageLoopObserver* message_loop_observer_ = nullptr;
// Guards |connection_filters_| and |next_filter_id_|.
base::Lock lock_;
std::map<int, std::unique_ptr<ConnectionFilter>> connection_filters_
GUARDED_BY(lock_);
int next_filter_id_ GUARDED_BY(lock_) = kInvalidConnectionFilterId;
std::map<std::string, ServiceRequestHandlerWithCallback> request_handlers_;
base::WeakPtrFactory<IOThreadContext> weak_factory_{this};
......@@ -425,15 +369,6 @@ void ServiceManagerConnectionImpl::SetConnectionLostClosure(
connection_lost_handler_ = closure;
}
int ServiceManagerConnectionImpl::AddConnectionFilter(
std::unique_ptr<ConnectionFilter> filter) {
return context_->AddConnectionFilter(std::move(filter));
}
void ServiceManagerConnectionImpl::RemoveConnectionFilter(int filter_id) {
context_->RemoveConnectionFilter(filter_id);
}
void ServiceManagerConnectionImpl::AddServiceRequestHandler(
const std::string& name,
const ServiceRequestHandler& handler) {
......
......@@ -39,8 +39,6 @@ class CONTENT_EXPORT ServiceManagerConnectionImpl
void Stop() override;
service_manager::Connector* GetConnector() override;
void SetConnectionLostClosure(const base::Closure& closure) override;
int AddConnectionFilter(std::unique_ptr<ConnectionFilter> filter) override;
void RemoveConnectionFilter(int filter_id) override;
void AddServiceRequestHandler(
const std::string& name,
const ServiceRequestHandler& handler) override;
......
......@@ -192,25 +192,8 @@ source_set("content_browser_manifest") {
]
}
source_set("content_utility_manifest") {
sources = [
"content_utility_manifest.cc",
"content_utility_manifest.h",
]
deps = [
"//base",
"//content/public/common:service_names",
]
public_deps = [
"//services/service_manager/public/cpp",
]
}
group("service_manifests") {
public_deps = [
":content_browser_manifest",
":content_utility_manifest",
]
}
......@@ -6,8 +6,3 @@ per-file content_browser_manifest.cc=file://ipc/SECURITY_OWNERS
per-file content_browser_manifest.h=set noparent
per-file content_browser_manifest.h=file://ipc/SECURITY_OWNERS
per-file content_utility_manifest.cc=set noparent
per-file content_utility_manifest.cc=file://ipc/SECURITY_OWNERS
per-file content_utility_manifest.h=set noparent
per-file content_utility_manifest.h=file://ipc/SECURITY_OWNERS
// 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 "content/public/app/content_utility_manifest.h"
#include "base/no_destructor.h"
#include "content/public/common/service_names.mojom.h"
#include "services/service_manager/public/cpp/manifest_builder.h"
namespace content {
const service_manager::Manifest& GetContentUtilityManifest() {
static base::NoDestructor<service_manager::Manifest> manifest{
service_manager::ManifestBuilder()
.WithServiceName(mojom::kUtilityServiceName)
.WithDisplayName("Content (utility process)")
.ExposeCapability("browser",
std::set<const char*>{
"content.mojom.Child",
"content.mojom.ChildHistogramFetcher",
"content.mojom.ChildHistogramFetcherFactory",
"content.mojom.ChildProcess",
"content.mojom.ResourceUsageReporter",
"IPC.mojom.ChannelBootstrap",
"printing.mojom.PdfToEmfConverterFactory",
"printing.mojom.PdfToPwgRasterConverter",
})
.RequireCapability("device", "device:power_monitor")
.RequireCapability("device", "device:time_zone_monitor")
.RequireCapability(mojom::kSystemServiceName, "dwrite_font_proxy")
.RequireCapability(mojom::kSystemServiceName, "field_trials")
.RequireCapability(mojom::kSystemServiceName, "font_cache")
.RequireCapability(mojom::kSystemServiceName, "sandbox_support")
.RequireCapability("*", "app")
.RequireCapability("font_service", "font_service")
.Build()};
return *manifest;
}
} // namespace content
// 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 CONTENT_PUBLIC_APP_CONTENT_UTILITY_MANIFEST_H_
#define CONTENT_PUBLIC_APP_CONTENT_UTILITY_MANIFEST_H_
#include "services/service_manager/public/cpp/manifest.h"
namespace content {
// Returns the service manifest for the "content_utility" service. Every
// utility (i.e. out-of-process service) process is an instance of this service,
// so this manifest determines what capabilities are directly exposed and
// required by service processes.
const service_manager::Manifest& GetContentUtilityManifest();
} // namespace content
#endif // CONTENT_PUBLIC_APP_CONTENT_UTILITY_MANIFEST_H_
......@@ -21,7 +21,6 @@
#include "content/public/common/process_type.h"
#include "ipc/ipc_sender.h"
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
#include "services/service_manager/public/mojom/service.mojom.h"
#if defined(OS_MACOSX)
#include "base/process/port_provider_mac.h"
......@@ -100,13 +99,6 @@ class CONTENT_EXPORT BrowserChildProcessHost : public IPC::Sender {
// call this method so that the process is associated with this object.
virtual void SetProcess(base::Process process) = 0;
// Takes the ServiceRequest pipe away from this host. Use this only if you
// intend to forego process launch and use the ServiceRequest in-process
// instead. Calling Launch() after this is called will result in the child
// process having no Service Manager connection.
virtual service_manager::mojom::ServiceRequest
TakeInProcessServiceRequest() = 0;
#if defined(OS_MACOSX)
// Returns a PortProvider used to get the task port for child processes.
static base::PortProvider* GetPortProvider();
......
......@@ -124,7 +124,6 @@ jumbo_source_set("common_sources") {
"common_param_traits.h",
"common_param_traits_macros.h",
"common_sandbox_support_linux.h",
"connection_filter.h",
"console_message_level.h",
"content_client.cc",
"content_client.h",
......@@ -200,8 +199,6 @@ jumbo_source_set("common_sources") {
"screen_info.h",
"screen_orientation_values.h",
"service_manager_connection.h",
"simple_connection_filter.cc",
"simple_connection_filter.h",
"socket_permission_request.h",
"stop_find_action.h",
"storage_quota_params.h",
......
......@@ -59,21 +59,12 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Sender {
// process hosts should prefer to use this mode.
kNormal,
// In this mode, the primordial pipe is a service_manager.mojom.Service
// pipe, and the owner of the ChildProcessHost is expected to pass the
// Mojo invitation along to a content::ChildProcessConnection.
//
// In this mode, the ChildProcessHost is fully functional.
//
// DEPRECATED: Do not introduce new uses of this mode.
kServiceManager,
// In this mode, the primordial pipe is a legacy IPC Channel bootstrapping
// pipe (IPC.mojom.ChannelBootstrap). This should be used when the child
// process only uses legacy Chrome IPC (e.g. Chrome's NaCl processes.)
//
// In this mode, ChildProcessHost methods like |BindInterface()| or
// |BindReceiver()| are not functional.
// In this mode, ChildProcessHost methods like |BindReceiver()| are not
// functional.
//
// DEPRECATED: Do not introduce new uses of this mode.
kLegacy,
......@@ -161,14 +152,6 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Sender {
// Adds an IPC message filter. A reference will be kept to the filter.
virtual void AddFilter(IPC::MessageFilter* filter) = 0;
// Bind an interface exposed by the child process. Requests sent to the child
// process via this call are routed through the a ConnectionFilter on the
// corresponding ChildThreadImpl.
//
// DEPRECATED: Use |BindReceiver()| instead.
virtual void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) = 0;
// Bind an interface exposed by the child process. Whether or not the
// interface in |receiver| can be bound depends on the process type and
// potentially on the Content embedder.
......
......@@ -35,10 +35,6 @@ class ChildProcessHostDelegate : public IPC::Listener {
// OnProcessLaunched is called or it will be invalid and may crash.
virtual const base::Process& GetProcess() = 0;
// Binds an interface in the child process.
virtual void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {}
// Binds an interface receiver in the host process, as requested by the child
// process.
virtual void BindHostReceiver(mojo::GenericPendingReceiver receiver) {}
......
// 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 CONTENT_PUBLIC_COMMON_CONNECTION_FILTER_H_
#define CONTENT_PUBLIC_COMMON_CONNECTION_FILTER_H_
#include "content/common/content_export.h"
#include "mojo/public/cpp/system/message_pipe.h"
namespace service_manager {
class Connector;
struct BindSourceInfo;
}
namespace content {
// TODO(beng): Rename to InterfaceBinder?
// See ServiceManagerConnection::AddConnectionFilter().
class CONTENT_EXPORT ConnectionFilter {
public:
virtual ~ConnectionFilter() {}
// Provides the ConnectionFilter with the option of binding an interface
// request from a remote service. The interface request is in
// |interface_pipe|, which is taken by the binding action. If the interface
// request is bound, subsequent ConnectionFilters are not consulted.
virtual void OnBindInterface(
const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe,
service_manager::Connector* connector) = 0;
};
} // namespace content
#endif // CONTENT_PUBLIC_COMMON_CONNECTION_FILTER_H_
......@@ -21,8 +21,6 @@ class Connector;
namespace content {
class ConnectionFilter;
// Encapsulates a connection to a //services/service_manager.
// Access a global instance on the thread the ServiceContext was bound by
// calling Holder::Get().
......@@ -70,9 +68,7 @@ class CONTENT_EXPORT ServiceManagerConnection {
service_manager::mojom::ServiceRequest request,
scoped_refptr<base::SequencedTaskRunner> io_task_runner);
// Begins accepting incoming connections. Connection filters MUST be added
// before calling this in order to avoid races. See AddConnectionFilter()
// below.
// Begins accepting incoming connections.
virtual void Start() = 0;
// Stops accepting incoming connections. This happens asynchronously by
......@@ -89,25 +85,6 @@ class CONTENT_EXPORT ServiceManagerConnection {
// run immediately before returning from this function.
virtual void SetConnectionLostClosure(const base::Closure& closure) = 0;
static const int kInvalidConnectionFilterId = 0;
// Allows the caller to filter inbound connections and/or expose interfaces
// on them. |filter| may be created on any thread, but will be used and
// destroyed exclusively on the IO thread (the thread corresponding to
// |io_task_runner| passed to Create() above.)
//
// Connection filters MUST be added before calling Start() in order to avoid
// races.
//
// Returns a unique identifier that can be passed to RemoveConnectionFilter()
// below.
virtual int AddConnectionFilter(
std::unique_ptr<ConnectionFilter> filter) = 0;
// Removes a filter using the id value returned by AddConnectionFilter().
// Removal (and destruction) happens asynchronously on the IO thread.
virtual void RemoveConnectionFilter(int filter_id) = 0;
// Adds a generic ServiceRequestHandler for a given service name. This
// will be used to satisfy any incoming calls to CreateService() which
// reference the given name.
......
// Copyright 2017 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 "content/public/common/simple_connection_filter.h"
namespace content {
SimpleConnectionFilter::SimpleConnectionFilter(
std::unique_ptr<service_manager::BinderRegistry> registry)
: registry_(std::move(registry)) {}
SimpleConnectionFilter::~SimpleConnectionFilter() {}
void SimpleConnectionFilter::OnBindInterface(
const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe,
service_manager::Connector* connector) {
registry_->TryBindInterface(interface_name, interface_pipe);
}
SimpleConnectionFilterWithSourceInfo::SimpleConnectionFilterWithSourceInfo(
std::unique_ptr<service_manager::BinderRegistryWithArgs<
const service_manager::BindSourceInfo&>> registry)
: registry_(std::move(registry)) {}
SimpleConnectionFilterWithSourceInfo::~SimpleConnectionFilterWithSourceInfo() {}
void SimpleConnectionFilterWithSourceInfo::OnBindInterface(
const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe,
service_manager::Connector* connector) {
registry_->TryBindInterface(interface_name, interface_pipe, source_info);
}
} // namespace content
// Copyright 2017 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 CONTENT_PUBLIC_COMMON_SIMPLE_CONNECTION_FILTER_H_
#define CONTENT_PUBLIC_COMMON_SIMPLE_CONNECTION_FILTER_H_
#include <memory>
#include <string>
#include "content/common/content_export.h"
#include "content/public/common/connection_filter.h"
#include "services/service_manager/public/cpp/binder_registry.h"
namespace service_manager {
struct BindSourceInfo;
}
namespace content {
class CONTENT_EXPORT SimpleConnectionFilter : public ConnectionFilter {
public:
explicit SimpleConnectionFilter(
std::unique_ptr<service_manager::BinderRegistry> registry);
~SimpleConnectionFilter() override;
// ConnectionFilter:
void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe,
service_manager::Connector* connector) override;
private:
std::unique_ptr<service_manager::BinderRegistry> registry_;
DISALLOW_COPY_AND_ASSIGN(SimpleConnectionFilter);
};
class CONTENT_EXPORT SimpleConnectionFilterWithSourceInfo
: public ConnectionFilter {
public:
explicit SimpleConnectionFilterWithSourceInfo(
std::unique_ptr<service_manager::BinderRegistryWithArgs<
const service_manager::BindSourceInfo&>> registry);
~SimpleConnectionFilterWithSourceInfo() override;
// ConnectionFilter:
void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe,
service_manager::Connector* connector) override;
private:
std::unique_ptr<service_manager::BinderRegistryWithArgs<
const service_manager::BindSourceInfo&>>
registry_;
DISALLOW_COPY_AND_ASSIGN(SimpleConnectionFilterWithSourceInfo);
};
} // namespace content
#endif // CONTENT_PUBLIC_COMMON_SIMPLE_CONNECTION_FILTER_H_
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