Skip to content

Commit

Permalink
Mojo: Delete IncomingBrokerClientConnection
Browse files Browse the repository at this point in the history
This is fully replaced by the public IncomingInvitation type.

Bug: 844763
Change-Id: I7eb07f0c3ca04f5670d30ef0ce3631d0cc2a06c5
Reviewed-on: https://chromium-review.googlesource.com/1071228
Commit-Queue: Ken Rockot <rockot@chromium.org>
Reviewed-by: Joe Downing <joedow@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562862}
  • Loading branch information
krockot authored and Commit Bot committed May 30, 2018
1 parent 081207b commit fe962ba
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 217 deletions.
36 changes: 16 additions & 20 deletions components/nacl/common/nacl_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,41 @@
#include "base/command_line.h"
#include "content/public/common/service_names.mojom.h"
#include "ipc/ipc.mojom.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/incoming_broker_client_invitation.h"
#include "mojo/edk/embedder/scoped_ipc_support.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel_endpoint.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/invitation.h"
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"

#if defined(OS_POSIX)
#include "base/files/scoped_file.h"
#include "base/posix/global_descriptors.h"
#include "services/service_manager/embedder/descriptors.h"
#elif defined(OS_WIN)
#include "mojo/edk/embedder/platform_channel_pair.h"
#endif

namespace {

std::unique_ptr<mojo::edk::IncomingBrokerClientInvitation>
EstablishMojoConnection() {
mojo::IncomingInvitation EstablishMojoConnection() {
mojo::PlatformChannelEndpoint endpoint;
#if defined(OS_WIN)
mojo::edk::ScopedInternalPlatformHandle platform_channel(
mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess(
*base::CommandLine::ForCurrentProcess()));
endpoint = mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
*base::CommandLine::ForCurrentProcess());
#else
mojo::edk::ScopedInternalPlatformHandle platform_channel(
mojo::edk::InternalPlatformHandle(
base::GlobalDescriptors::GetInstance()->Get(
service_manager::kMojoIPCChannel)));
endpoint = mojo::PlatformChannelEndpoint(mojo::PlatformHandle(
base::ScopedFD(base::GlobalDescriptors::GetInstance()->Get(
service_manager::kMojoIPCChannel))));
#endif
DCHECK(platform_channel.is_valid());
return mojo::edk::IncomingBrokerClientInvitation::Accept(
mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy,
std::move(platform_channel)));
DCHECK(endpoint.is_valid());
return mojo::IncomingInvitation::Accept(std::move(endpoint));
}

service_manager::mojom::ServiceRequest ConnectToServiceManager(
mojo::edk::IncomingBrokerClientInvitation* invitation) {
mojo::IncomingInvitation* invitation) {
const std::string service_request_channel_token =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
service_manager::switches::kServiceRequestChannelToken);
Expand Down Expand Up @@ -113,6 +109,6 @@ std::unique_ptr<service_manager::ServiceContext> CreateNaClServiceContext(
auto context = std::make_unique<service_manager::ServiceContext>(
std::make_unique<NaClService>(bootstrap.PassInterface(),
std::move(ipc_support)),
ConnectToServiceManager(invitation.get()));
ConnectToServiceManager(&invitation));
return context;
}
54 changes: 25 additions & 29 deletions content/child/child_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/message_loop/timer_slack.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h"
#include "base/optional.h"
#include "base/process/process.h"
#include "base/process/process_handle.h"
#include "base/run_loop.h"
Expand Down Expand Up @@ -52,11 +53,13 @@
#include "ipc/ipc_sync_channel.h"
#include "ipc/ipc_sync_message_filter.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/incoming_broker_client_invitation.h"
#include "mojo/edk/embedder/named_platform_channel_pair.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/scoped_ipc_support.h"
#include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel_endpoint.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/buffer.h"
#include "mojo/public/cpp/system/invitation.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/device/public/cpp/power_monitor/power_monitor_broadcast_source.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/client_process_impl.h"
Expand Down Expand Up @@ -236,40 +239,34 @@ base::LazyInstance<QuitClosure>::DestructorAtExit g_quit_closure =
LAZY_INSTANCE_INITIALIZER;
#endif

std::unique_ptr<mojo::edk::IncomingBrokerClientInvitation>
InitializeMojoIPCChannel() {
base::Optional<mojo::IncomingInvitation> InitializeMojoIPCChannel() {
TRACE_EVENT0("startup", "InitializeMojoIPCChannel");
mojo::edk::ScopedInternalPlatformHandle platform_channel;
mojo::PlatformChannelEndpoint endpoint;
#if defined(OS_WIN)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch)) {
platform_channel =
mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess(
*base::CommandLine::ForCurrentProcess());
mojo::PlatformChannel::kHandleSwitch)) {
endpoint = mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
*base::CommandLine::ForCurrentProcess());
} else {
// If this process is elevated, it will have a pipe path passed on the
// command line.
platform_channel =
mojo::edk::NamedPlatformChannelPair::PassClientHandleFromParentProcess(
*base::CommandLine::ForCurrentProcess());
endpoint = mojo::NamedPlatformChannel::ConnectToServer(
*base::CommandLine::ForCurrentProcess());
}
#elif defined(OS_FUCHSIA)
platform_channel =
mojo::edk::PlatformChannelPair::PassClientHandleFromParentProcess(
*base::CommandLine::ForCurrentProcess());
endpoint = mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
*base::CommandLine::ForCurrentProcess());
#elif defined(OS_POSIX)
platform_channel.reset(mojo::edk::InternalPlatformHandle(
base::GlobalDescriptors::GetInstance()->Get(
service_manager::kMojoIPCChannel)));
endpoint = mojo::PlatformChannelEndpoint(mojo::PlatformHandle(
base::ScopedFD(base::GlobalDescriptors::GetInstance()->Get(
service_manager::kMojoIPCChannel))));
#endif
// Mojo isn't supported on all child process types.
// TODO(crbug.com/604282): Support Mojo in the remaining processes.
if (!platform_channel.is_valid())
return nullptr;
if (!endpoint.is_valid())
return base::nullopt;

return mojo::edk::IncomingBrokerClientInvitation::Accept(
mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy,
std::move(platform_channel)));
return mojo::IncomingInvitation::Accept(std::move(endpoint));
}

class ChannelBootstrapFilter : public ConnectionFilter {
Expand Down Expand Up @@ -419,8 +416,7 @@ void ChildThreadImpl::OnFieldTrialGroupFinalized(
field_trial_recorder->FieldTrialActivated(trial_name);
}

void ChildThreadImpl::ConnectChannel(
mojo::edk::IncomingBrokerClientInvitation* invitation) {
void ChildThreadImpl::ConnectChannel() {
DCHECK(service_manager_connection_);
IPC::mojom::ChannelBootstrapPtr bootstrap;
mojo::ScopedMessagePipeHandle handle =
Expand Down Expand Up @@ -457,12 +453,12 @@ void ChildThreadImpl::Init(const Options& options) {
IPC::Logging::GetInstance()->SetIPCSender(this);
#endif

std::unique_ptr<mojo::edk::IncomingBrokerClientInvitation> invitation;
mojo::ScopedMessagePipeHandle service_request_pipe;
if (!IsInBrowserProcess()) {
mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport(
GetIOTaskRunner(), mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST));
invitation = InitializeMojoIPCChannel();
base::Optional<mojo::IncomingInvitation> invitation =
InitializeMojoIPCChannel();

std::string service_request_token =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
Expand Down Expand Up @@ -551,7 +547,7 @@ void ChildThreadImpl::Init(const Options& options) {
channel_->AddFilter(startup_filter);
}

ConnectChannel(invitation.get());
ConnectChannel();

// This must always be done after ConnectChannel, because ConnectChannel() may
// add a ConnectionFilter to the connection.
Expand Down
3 changes: 1 addition & 2 deletions content/child/child_thread_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class SyncMessageFilter;

namespace mojo {
namespace edk {
class IncomingBrokerClientInvitation;
class OutgoingBrokerClientInvitation;
class ScopedIPCSupport;
} // namespace edk
Expand Down Expand Up @@ -198,7 +197,7 @@ class CONTENT_EXPORT ChildThreadImpl

// We create the channel first without connecting it so we can add filters
// prior to any messages being received, then connect it afterwards.
void ConnectChannel(mojo::edk::IncomingBrokerClientInvitation* invitation);
void ConnectChannel();

// IPC message handlers.

Expand Down
2 changes: 0 additions & 2 deletions mojo/edk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ component("edk") {

public = [
"embedder/embedder.h",
"embedder/incoming_broker_client_invitation.h",
"embedder/outgoing_broker_client_invitation.h",
"embedder/peer_connection.h",
]

sources = [
"embedder/embedder.cc",
"embedder/incoming_broker_client_invitation.cc",
"embedder/outgoing_broker_client_invitation.cc",
"embedder/peer_connection.cc",
]
Expand Down
50 changes: 0 additions & 50 deletions mojo/edk/embedder/incoming_broker_client_invitation.cc

This file was deleted.

58 changes: 0 additions & 58 deletions mojo/edk/embedder/incoming_broker_client_invitation.h

This file was deleted.

27 changes: 16 additions & 11 deletions mojo/edk/test/multiprocess_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/incoming_broker_client_invitation.h"
#include "mojo/edk/embedder/named_platform_handle.h"
#include "mojo/edk/embedder/named_platform_handle_utils.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
#include "mojo/edk/embedder/peer_connection.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/invitation.h"
#include "testing/gtest/include/gtest/gtest.h"

#if defined(OS_MACOSX) && !defined(OS_IOS)
Expand Down Expand Up @@ -216,25 +218,28 @@ void MultiprocessTestHelper::ChildSetup() {
CHECK(base::CommandLine::InitializedForCurrentProcess());

auto& command_line = *base::CommandLine::ForCurrentProcess();
NamedPlatformHandle named_pipe(
NamedPlatformChannel::ServerName named_pipe(
command_line.GetSwitchValueNative(kNamedPipeName));
if (command_line.HasSwitch(kRunAsBrokerClient)) {
std::unique_ptr<IncomingBrokerClientInvitation> invitation;
mojo::IncomingInvitation invitation;
#if defined(OS_MACOSX) && !defined(OS_IOS)
CHECK(base::MachPortBroker::ChildSendTaskPortToParent("mojo_test"));
#endif
if (named_pipe.is_valid()) {
invitation = IncomingBrokerClientInvitation::Accept(ConnectionParams(
TransportProtocol::kLegacy, CreateClientHandle(named_pipe)));
if (!named_pipe.empty()) {
invitation = mojo::IncomingInvitation::Accept(
mojo::NamedPlatformChannel::ConnectToServer(named_pipe));
} else {
invitation = IncomingBrokerClientInvitation::AcceptFromCommandLine(
TransportProtocol::kLegacy);
auto endpoint =
mojo::PlatformChannel::RecoverPassedEndpointFromCommandLine(
command_line);
invitation = IncomingInvitation::Accept(std::move(endpoint));
}
primordial_pipe = invitation->ExtractMessagePipe(kTestChildMessagePipeName);
primordial_pipe = invitation.ExtractMessagePipe(kTestChildMessagePipeName);
} else {
if (named_pipe.is_valid()) {
if (!named_pipe.empty()) {
NamedPlatformHandle pipe_name(named_pipe);
primordial_pipe = g_child_peer_connection.Get().Connect(ConnectionParams(
TransportProtocol::kLegacy, CreateClientHandle(named_pipe)));
TransportProtocol::kLegacy, CreateClientHandle(pipe_name)));
} else {
primordial_pipe = g_child_peer_connection.Get().Connect(ConnectionParams(
TransportProtocol::kLegacy,
Expand Down
Loading

0 comments on commit fe962ba

Please sign in to comment.