OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/edk/system/node_controller.h" | 5 #include "mojo/edk/system/node_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 io_task_runner_->PostTask( | 120 io_task_runner_->PostTask( |
121 FROM_HERE, | 121 FROM_HERE, |
122 base::Bind(&NodeController::ConnectToChildOnIOThread, | 122 base::Bind(&NodeController::ConnectToChildOnIOThread, |
123 base::Unretained(this), | 123 base::Unretained(this), |
124 process_handle, | 124 process_handle, |
125 base::Passed(&platform_handle))); | 125 base::Passed(&platform_handle))); |
126 } | 126 } |
127 | 127 |
128 void NodeController::ConnectToParent(ScopedPlatformHandle platform_handle) { | 128 void NodeController::ConnectToParent(ScopedPlatformHandle platform_handle) { |
129 // TODO(amistry): Consider the need for a broker on Windows. | 129 // TODO(amistry): Consider the need for a broker on Windows. |
130 #if defined(OS_POSIX) | 130 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
131 // On posix, use the bootstrap channel for the broker and receive the node's | 131 // On posix, use the bootstrap channel for the broker and receive the node's |
132 // channel synchronously as the first message from the broker. | 132 // channel synchronously as the first message from the broker. |
133 broker_.reset(new Broker(std::move(platform_handle))); | 133 broker_.reset(new Broker(std::move(platform_handle))); |
134 platform_handle = broker_->GetParentPlatformHandle(); | 134 platform_handle = broker_->GetParentPlatformHandle(); |
135 #endif | 135 #endif |
136 | 136 |
137 io_task_runner_->PostTask( | 137 io_task_runner_->PostTask( |
138 FROM_HERE, | 138 FROM_HERE, |
139 base::Bind(&NodeController::ConnectToParentOnIOThread, | 139 base::Bind(&NodeController::ConnectToParentOnIOThread, |
140 base::Unretained(this), | 140 base::Unretained(this), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 int NodeController::MergeLocalPorts(const ports::PortRef& port0, | 212 int NodeController::MergeLocalPorts(const ports::PortRef& port0, |
213 const ports::PortRef& port1) { | 213 const ports::PortRef& port1) { |
214 int rv = node_->MergeLocalPorts(port0, port1); | 214 int rv = node_->MergeLocalPorts(port0, port1); |
215 AcceptIncomingMessages(); | 215 AcceptIncomingMessages(); |
216 return rv; | 216 return rv; |
217 } | 217 } |
218 | 218 |
219 scoped_refptr<PlatformSharedBuffer> NodeController::CreateSharedBuffer( | 219 scoped_refptr<PlatformSharedBuffer> NodeController::CreateSharedBuffer( |
220 size_t num_bytes) { | 220 size_t num_bytes) { |
221 // TODO(amistry): Fix sync broker and re-enable on OSX. | |
222 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 221 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
223 // Shared buffer creation failure is fatal, so always use the broker when we | 222 // Shared buffer creation failure is fatal, so always use the broker when we |
224 // have one. This does mean that a non-root process that has children will use | 223 // have one. This does mean that a non-root process that has children will use |
225 // the broker for shared buffer creation even though that process is | 224 // the broker for shared buffer creation even though that process is |
226 // privileged. | 225 // privileged. |
227 if (broker_) { | 226 if (broker_) { |
228 return broker_->GetSharedBuffer(num_bytes); | 227 return broker_->GetSharedBuffer(num_bytes); |
229 } | 228 } |
230 #endif | 229 #endif |
231 return PlatformSharedBuffer::Create(num_bytes); | 230 return PlatformSharedBuffer::Create(num_bytes); |
232 } | 231 } |
233 | 232 |
234 void NodeController::RequestShutdown(const base::Closure& callback) { | 233 void NodeController::RequestShutdown(const base::Closure& callback) { |
235 { | 234 { |
236 base::AutoLock lock(shutdown_lock_); | 235 base::AutoLock lock(shutdown_lock_); |
237 shutdown_callback_ = callback; | 236 shutdown_callback_ = callback; |
238 } | 237 } |
239 | 238 |
240 AttemptShutdownIfRequested(); | 239 AttemptShutdownIfRequested(); |
241 } | 240 } |
242 | 241 |
243 void NodeController::ConnectToChildOnIOThread( | 242 void NodeController::ConnectToChildOnIOThread( |
244 base::ProcessHandle process_handle, | 243 base::ProcessHandle process_handle, |
245 ScopedPlatformHandle platform_handle) { | 244 ScopedPlatformHandle platform_handle) { |
246 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 245 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
247 | 246 |
248 #if defined(OS_POSIX) | 247 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
249 PlatformChannelPair node_channel; | 248 PlatformChannelPair node_channel; |
250 // BrokerHost owns itself. | 249 // BrokerHost owns itself. |
251 BrokerHost* broker_host = new BrokerHost(std::move(platform_handle)); | 250 BrokerHost* broker_host = new BrokerHost(std::move(platform_handle)); |
252 broker_host->SendChannel(node_channel.PassClientHandle()); | 251 broker_host->SendChannel(node_channel.PassClientHandle()); |
253 scoped_refptr<NodeChannel> channel = NodeChannel::Create( | 252 scoped_refptr<NodeChannel> channel = NodeChannel::Create( |
254 this, node_channel.PassServerHandle(), io_task_runner_); | 253 this, node_channel.PassServerHandle(), io_task_runner_); |
255 #else | 254 #else |
256 scoped_refptr<NodeChannel> channel = | 255 scoped_refptr<NodeChannel> channel = |
257 NodeChannel::Create(this, std::move(platform_handle), io_task_runner_); | 256 NodeChannel::Create(this, std::move(platform_handle), io_task_runner_); |
258 #endif | 257 #endif |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 shutdown_callback_.Reset(); | 905 shutdown_callback_.Reset(); |
907 } | 906 } |
908 | 907 |
909 DCHECK(!callback.is_null()); | 908 DCHECK(!callback.is_null()); |
910 | 909 |
911 callback.Run(); | 910 callback.Run(); |
912 } | 911 } |
913 | 912 |
914 } // namespace edk | 913 } // namespace edk |
915 } // namespace mojo | 914 } // namespace mojo |
OLD | NEW |