Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1372)

Unified Diff: mojo/edk/system/node_controller.cc

Issue 2735113003: Changing SpawnChild to return a struct.
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/node_controller.h ('k') | mojo/edk/test/multiprocess_test_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/node_controller.cc
diff --git a/mojo/edk/system/node_controller.cc b/mojo/edk/system/node_controller.cc
index cafd604d1cb36d78a017eee4edb3af5d3d4a33c6..c55e489876984e63bcf023f88f5c22a7903124f9 100644
--- a/mojo/edk/system/node_controller.cc
+++ b/mojo/edk/system/node_controller.cc
@@ -165,7 +165,7 @@ void NodeController::SetIOTaskRunner(
void NodeController::ConnectToChild(
base::ProcessHandle process_handle,
- ScopedPlatformHandle platform_handle,
+ ConnectionParam connection_param,
const std::string& child_token,
const ProcessErrorCallback& process_error_callback) {
// Generate the temporary remote node name here so that it can be associated
@@ -196,13 +196,10 @@ void NodeController::ConnectToChild(
#endif
io_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&NodeController::ConnectToChildOnIOThread,
- base::Unretained(this),
- process_handle,
- base::Passed(&platform_handle),
- node_name,
- process_error_callback));
+ FROM_HERE, base::Bind(&NodeController::ConnectToChildOnIOThread,
+ base::Unretained(this), process_handle,
+ base::Passed(&connection_param), node_name,
+ process_error_callback));
}
void NodeController::CloseChildPorts(const std::string& child_token) {
@@ -235,13 +232,13 @@ void NodeController::ClosePeerConnection(const std::string& peer_token) {
base::Unretained(this), peer_token));
}
-void NodeController::ConnectToParent(ScopedPlatformHandle platform_handle) {
+void NodeController::ConnectToParent(ConnectionParam connection_param) {
#if !defined(OS_MACOSX) && !defined(OS_NACL_SFI)
// Use the bootstrap channel for the broker and receive the node's channel
// synchronously as the first message from the broker.
base::ElapsedTimer timer;
- broker_.reset(new Broker(std::move(platform_handle)));
- platform_handle = broker_->GetParentPlatformHandle();
+ broker_.reset(new Broker(connection_param.TakeChannelHandle()));
+ ScopedPlatformHandle platform_handle = broker_->GetParentPlatformHandle();
UMA_HISTOGRAM_TIMES("Mojo.System.GetParentPlatformHandleSyncTime",
timer.Elapsed());
@@ -253,24 +250,32 @@ void NodeController::ConnectToParent(ScopedPlatformHandle platform_handle) {
CancelPendingPortMerges();
return;
}
+ connection_param =
+ ConnectionParam(std::move(platform_handle)
+#if defined(OS_ANDROID)
+ ,
+ std::move(connection_param.TakeParcelableChannelClient()),
+ std::move(connection_param.TakeParcelableChannelServer())
+#endif
+ );
#endif
io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NodeController::ConnectToParentOnIOThread,
- base::Unretained(this),
- base::Passed(&platform_handle)));
+ base::Unretained(this), base::Passed(&connection_param)));
}
-void NodeController::ConnectToPeer(ScopedPlatformHandle handle,
+void NodeController::ConnectToPeer(ConnectionParam connection_param,
const ports::PortRef& port,
const std::string& peer_token) {
ports::NodeName node_name;
GenerateRandomName(&node_name);
io_task_runner_->PostTask(
- FROM_HERE, base::Bind(&NodeController::ConnectToPeerOnIOThread,
- base::Unretained(this), base::Passed(&handle),
- node_name, port, peer_token));
+ FROM_HERE,
+ base::Bind(&NodeController::ConnectToPeerOnIOThread,
+ base::Unretained(this), base::Passed(&connection_param),
+ node_name, port, peer_token));
}
void NodeController::SetPortObserver(
@@ -395,7 +400,7 @@ void NodeController::NotifyBadMessageFrom(const ports::NodeName& source_node,
void NodeController::ConnectToChildOnIOThread(
base::ProcessHandle process_handle,
- ScopedPlatformHandle platform_handle,
+ ConnectionParam connection_param,
ports::NodeName token,
const ProcessErrorCallback& process_error_callback) {
DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
@@ -405,7 +410,7 @@ void NodeController::ConnectToChildOnIOThread(
ScopedPlatformHandle server_handle = node_channel.PassServerHandle();
// BrokerHost owns itself.
BrokerHost* broker_host =
- new BrokerHost(process_handle, std::move(platform_handle));
+ new BrokerHost(process_handle, connection_param.TakeChannelHandle());
bool channel_ok = broker_host->SendChannel(node_channel.PassClientHandle());
#if defined(OS_WIN)
@@ -420,12 +425,24 @@ void NodeController::ConnectToChildOnIOThread(
CHECK(channel_ok);
#endif // defined(OS_WIN)
- scoped_refptr<NodeChannel> channel = NodeChannel::Create(
- this, std::move(server_handle), io_task_runner_, process_error_callback);
+#if defined(OS_ANDROID)
+ DCHECK(connection_param.is_valid_parcelable_channel_client());
+ DCHECK(connection_param.is_valid_parcelable_channel_server());
+
+ ConnectionParam new_connection_param(
+ std::move(server_handle), connection_param.TakeParcelableChannelClient(),
+ connection_param.TakeParcelableChannelServer());
+#else
+ ConnectionParam new_connection_param(std::move(server_handle));
+#endif
+
+ scoped_refptr<NodeChannel> channel =
+ NodeChannel::Create(this, std::move(new_connection_param),
+ io_task_runner_, process_error_callback);
#else // !defined(OS_MACOSX) && !defined(OS_NACL)
scoped_refptr<NodeChannel> channel =
- NodeChannel::Create(this, std::move(platform_handle), io_task_runner_,
+ NodeChannel::Create(this, std::move(connection_param), io_task_runner_,
process_error_callback);
#endif // !defined(OS_MACOSX) && !defined(OS_NACL)
@@ -445,7 +462,7 @@ void NodeController::ConnectToChildOnIOThread(
}
void NodeController::ConnectToParentOnIOThread(
- ScopedPlatformHandle platform_handle) {
+ ConnectionParam connection_param) {
DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
{
@@ -456,7 +473,7 @@ void NodeController::ConnectToParentOnIOThread(
// into our |peers_| map. That will happen as soon as we receive an
// AcceptChild message from them.
bootstrap_parent_channel_ =
- NodeChannel::Create(this, std::move(platform_handle), io_task_runner_,
+ NodeChannel::Create(this, std::move(connection_param), io_task_runner_,
ProcessErrorCallback());
// Prevent the parent pipe handle from being closed on shutdown. Pipe
// closure is used by the parent to detect the child process has exited.
@@ -468,14 +485,14 @@ void NodeController::ConnectToParentOnIOThread(
bootstrap_parent_channel_->Start();
}
-void NodeController::ConnectToPeerOnIOThread(ScopedPlatformHandle handle,
+void NodeController::ConnectToPeerOnIOThread(ConnectionParam connection_param,
ports::NodeName token,
ports::PortRef port,
const std::string& peer_token) {
DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
- scoped_refptr<NodeChannel> channel =
- NodeChannel::Create(this, std::move(handle), io_task_runner_, {});
+ scoped_refptr<NodeChannel> channel = NodeChannel::Create(
+ this, std::move(connection_param), io_task_runner_, {});
peer_connections_.insert(
{token, PeerConnection{channel, port, peer_token}});
peers_by_token_.insert({peer_token, token});
@@ -995,9 +1012,10 @@ void NodeController::OnAddBrokerClient(const ports::NodeName& from_node,
}
PlatformChannelPair broker_channel;
- scoped_refptr<NodeChannel> client = NodeChannel::Create(
- this, broker_channel.PassServerHandle(), io_task_runner_,
- ProcessErrorCallback());
+ ConnectionParam connection_param(broker_channel.PassServerHandle());
+ scoped_refptr<NodeChannel> client =
+ NodeChannel::Create(this, std::move(connection_param), io_task_runner_,
+ ProcessErrorCallback());
#if defined(OS_WIN)
// The broker must have a working handle to the client process in order to
@@ -1073,7 +1091,8 @@ void NodeController::OnAcceptBrokerClient(const ports::NodeName& from_node,
broker = parent;
} else {
DCHECK(broker_channel.is_valid());
- broker = NodeChannel::Create(this, std::move(broker_channel),
+ ConnectionParam connection_param(std::move(broker_channel));
+ broker = NodeChannel::Create(this, std::move(connection_param),
io_task_runner_, ProcessErrorCallback());
AddPeer(broker_name, broker, true /* start_channel */);
}
@@ -1201,8 +1220,9 @@ void NodeController::OnIntroduce(const ports::NodeName& from_node,
return;
}
+ ConnectionParam connection_param(std::move(channel_handle));
scoped_refptr<NodeChannel> channel =
- NodeChannel::Create(this, std::move(channel_handle), io_task_runner_,
+ NodeChannel::Create(this, std::move(connection_param), io_task_runner_,
ProcessErrorCallback());
DVLOG(1) << "Adding new peer " << name << " via parent introduction.";
« no previous file with comments | « mojo/edk/system/node_controller.h ('k') | mojo/edk/test/multiprocess_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698