summaryrefslogtreecommitdiffstats
path: root/mojo/edk/system/remote_message_pipe_bootstrap.cc
diff options
context:
space:
mode:
authorrockot <rockot@chromium.org>2016-02-09 12:16:47 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-09 20:18:35 +0000
commit7f38d5b807c65ea0ca2a743c6defaaa9f747a30c (patch)
treede7fc21ed1c6f3df2347a3b5693868018df2a781 /mojo/edk/system/remote_message_pipe_bootstrap.cc
parent08c9d1ef6670f512e6b81a2316973ba7be9a3860 (diff)
downloadchromium_src-7f38d5b807c65ea0ca2a743c6defaaa9f747a30c.zip
chromium_src-7f38d5b807c65ea0ca2a743c6defaaa9f747a30c.tar.gz
chromium_src-7f38d5b807c65ea0ca2a743c6defaaa9f747a30c.tar.bz2
[mojo-edk] Reland: Simplify multiprocess pipe bootstrap
This is a reland of https://crrev.com/b3ea203171e07f5c7e476e94d210ec4ad53ce5b0 which was reverted for breaking browser tests in debug builds. The problem was essentially that faster init -> faster shutdown -> exposed bad racy behavior in ChannelInit. This reland rmeoves the bad racy behavior from ChannelInit. This introduces a new MergePort message at the Ports layer for joining two independent port cycles which each have an unused (i.e. unwritten, unread, unsent) receiving port. MergePort allows us to create a MessagePipeDispatcher which is immediately usable but which will eventually be linked to a MessagePipeDispatcher on another port cycle, potentially in another process. The basic idea is to create a fully functional port pair but only bind one port to an MPD. Do this on each end and merge the dangling ports asynchronously. The simplification here allows a lot of code to be deleted from NodeController, some of which is deleted in this CL. Future work will convert existing bootstrap sites back to using synchronous bootstrap, including the token-based APIs. BUG=584764 TBR=amistry@chromium.org TBR=ben@chromium.org Review URL: https://codereview.chromium.org/1682043002 Cr-Commit-Position: refs/heads/master@{#374441}
Diffstat (limited to 'mojo/edk/system/remote_message_pipe_bootstrap.cc')
-rw-r--r--mojo/edk/system/remote_message_pipe_bootstrap.cc23
1 files changed, 13 insertions, 10 deletions
diff --git a/mojo/edk/system/remote_message_pipe_bootstrap.cc b/mojo/edk/system/remote_message_pipe_bootstrap.cc
index 671542f3..2342166 100644
--- a/mojo/edk/system/remote_message_pipe_bootstrap.cc
+++ b/mojo/edk/system/remote_message_pipe_bootstrap.cc
@@ -31,18 +31,17 @@ struct BootstrapData {
void RemoteMessagePipeBootstrap::Create(
NodeController* node_controller,
ScopedPlatformHandle platform_handle,
- const ports::PortRef& port,
- const base::Closure& callback) {
+ const ports::PortRef& port) {
if (node_controller->io_task_runner()->RunsTasksOnCurrentThread()) {
// Owns itself.
- new RemoteMessagePipeBootstrap(node_controller, std::move(platform_handle),
- port, callback);
+ new RemoteMessagePipeBootstrap(
+ node_controller, std::move(platform_handle), port);
} else {
node_controller->io_task_runner()->PostTask(
FROM_HERE,
base::Bind(&RemoteMessagePipeBootstrap::Create,
base::Unretained(node_controller),
- base::Passed(&platform_handle), port, callback));
+ base::Passed(&platform_handle), port));
}
}
@@ -56,11 +55,9 @@ RemoteMessagePipeBootstrap::~RemoteMessagePipeBootstrap() {
RemoteMessagePipeBootstrap::RemoteMessagePipeBootstrap(
NodeController* node_controller,
ScopedPlatformHandle platform_handle,
- const ports::PortRef& port,
- const base::Closure& callback)
+ const ports::PortRef& port)
: node_controller_(node_controller),
local_port_(port),
- callback_(callback),
io_task_runner_(base::ThreadTaskRunnerHandle::Get()),
channel_(Channel::Create(this, std::move(platform_handle),
io_task_runner_)) {
@@ -119,8 +116,14 @@ void RemoteMessagePipeBootstrap::OnChannelMessage(
}
peer_info_received_ = true;
- node_controller_->ConnectToRemotePort(
- local_port_, data->node_name, data->port_name, callback_);
+
+ // We need to choose one side to initiate the port merge. It doesn't matter
+ // who does it as long as they don't both try. Simple solution: pick the one
+ // with the "smaller" port name.
+ if (local_port_.name() < data->port_name) {
+ node_controller_->node()->MergePorts(local_port_, data->node_name,
+ data->port_name);
+ }
// Send another ping to the other end to trigger shutdown. This may race with
// the other end sending its own ping, but it doesn't matter. Whoever wins