Chromium Code Reviews| 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. | 221 // TODO(amistry): Fix sync broker and re-enable on OSX. |
|
Anand Mistry (off Chromium)
2016/03/18 05:40:12
Please delete this comment and add 590979 to the b
| |
| 222 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 222 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 223 // Shared buffer creation failure is fatal, so always use the broker when we | 223 // 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 | 224 // 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 | 225 // the broker for shared buffer creation even though that process is |
| 226 // privileged. | 226 // privileged. |
| 227 if (broker_) { | 227 if (broker_) { |
| 228 return broker_->GetSharedBuffer(num_bytes); | 228 return broker_->GetSharedBuffer(num_bytes); |
| 229 } | 229 } |
| 230 #endif | 230 #endif |
| 231 return PlatformSharedBuffer::Create(num_bytes); | 231 return PlatformSharedBuffer::Create(num_bytes); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void NodeController::RequestShutdown(const base::Closure& callback) { | 234 void NodeController::RequestShutdown(const base::Closure& callback) { |
| 235 { | 235 { |
| 236 base::AutoLock lock(shutdown_lock_); | 236 base::AutoLock lock(shutdown_lock_); |
| 237 shutdown_callback_ = callback; | 237 shutdown_callback_ = callback; |
| 238 } | 238 } |
| 239 | 239 |
| 240 AttemptShutdownIfRequested(); | 240 AttemptShutdownIfRequested(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void NodeController::ConnectToChildOnIOThread( | 243 void NodeController::ConnectToChildOnIOThread( |
| 244 base::ProcessHandle process_handle, | 244 base::ProcessHandle process_handle, |
| 245 ScopedPlatformHandle platform_handle) { | 245 ScopedPlatformHandle platform_handle) { |
| 246 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 246 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 247 | 247 |
| 248 #if defined(OS_POSIX) | 248 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 249 PlatformChannelPair node_channel; | 249 PlatformChannelPair node_channel; |
| 250 // BrokerHost owns itself. | 250 // BrokerHost owns itself. |
| 251 BrokerHost* broker_host = new BrokerHost(std::move(platform_handle)); | 251 BrokerHost* broker_host = new BrokerHost(std::move(platform_handle)); |
| 252 broker_host->SendChannel(node_channel.PassClientHandle()); | 252 broker_host->SendChannel(node_channel.PassClientHandle()); |
| 253 scoped_refptr<NodeChannel> channel = NodeChannel::Create( | 253 scoped_refptr<NodeChannel> channel = NodeChannel::Create( |
| 254 this, node_channel.PassServerHandle(), io_task_runner_); | 254 this, node_channel.PassServerHandle(), io_task_runner_); |
| 255 #else | 255 #else |
| 256 scoped_refptr<NodeChannel> channel = | 256 scoped_refptr<NodeChannel> channel = |
| 257 NodeChannel::Create(this, std::move(platform_handle), io_task_runner_); | 257 NodeChannel::Create(this, std::move(platform_handle), io_task_runner_); |
| 258 #endif | 258 #endif |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 shutdown_callback_.Reset(); | 906 shutdown_callback_.Reset(); |
| 907 } | 907 } |
| 908 | 908 |
| 909 DCHECK(!callback.is_null()); | 909 DCHECK(!callback.is_null()); |
| 910 | 910 |
| 911 callback.Run(); | 911 callback.Run(); |
| 912 } | 912 } |
| 913 | 913 |
| 914 } // namespace edk | 914 } // namespace edk |
| 915 } // namespace mojo | 915 } // namespace mojo |
| OLD | NEW |