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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 221 } |
222 | 222 |
223 for (const auto& port : ports_to_close) | 223 for (const auto& port : ports_to_close) |
224 node_->ClosePort(port); | 224 node_->ClosePort(port); |
225 | 225 |
226 // Ensure local port closure messages are processed. | 226 // Ensure local port closure messages are processed. |
227 AcceptIncomingMessages(); | 227 AcceptIncomingMessages(); |
228 } | 228 } |
229 | 229 |
230 void NodeController::ConnectToParent(ScopedPlatformHandle platform_handle) { | 230 void NodeController::ConnectToParent(ScopedPlatformHandle platform_handle) { |
231 // TODO(amistry): Consider the need for a broker on Windows. | 231 #if !defined(OS_MACOSX) && !defined(OS_NACL_SFI) |
232 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL_SFI) | 232 // Use the bootstrap channel for the broker and receive the node's channel |
233 // On posix, use the bootstrap channel for the broker and receive the node's | 233 // synchronously as the first message from the broker. |
234 // channel synchronously as the first message from the broker. | |
235 base::ElapsedTimer timer; | 234 base::ElapsedTimer timer; |
236 broker_.reset(new Broker(std::move(platform_handle))); | 235 broker_.reset(new Broker(std::move(platform_handle))); |
237 platform_handle = broker_->GetParentPlatformHandle(); | 236 platform_handle = broker_->GetParentPlatformHandle(); |
238 UMA_HISTOGRAM_TIMES("Mojo.System.GetParentPlatformHandleSyncTime", | 237 UMA_HISTOGRAM_TIMES("Mojo.System.GetParentPlatformHandleSyncTime", |
239 timer.Elapsed()); | 238 timer.Elapsed()); |
240 | 239 |
241 if (!platform_handle.is_valid()) { | 240 if (!platform_handle.is_valid()) { |
242 // Most likely the browser side of the channel has already been closed and | 241 // Most likely the browser side of the channel has already been closed and |
243 // the broker was unable to negotiate a NodeChannel pipe. In this case we | 242 // the broker was unable to negotiate a NodeChannel pipe. In this case we |
244 // can cancel parent connection. | 243 // can cancel parent connection. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 348 |
350 int NodeController::MergeLocalPorts(const ports::PortRef& port0, | 349 int NodeController::MergeLocalPorts(const ports::PortRef& port0, |
351 const ports::PortRef& port1) { | 350 const ports::PortRef& port1) { |
352 int rv = node_->MergeLocalPorts(port0, port1); | 351 int rv = node_->MergeLocalPorts(port0, port1); |
353 AcceptIncomingMessages(); | 352 AcceptIncomingMessages(); |
354 return rv; | 353 return rv; |
355 } | 354 } |
356 | 355 |
357 scoped_refptr<PlatformSharedBuffer> NodeController::CreateSharedBuffer( | 356 scoped_refptr<PlatformSharedBuffer> NodeController::CreateSharedBuffer( |
358 size_t num_bytes) { | 357 size_t num_bytes) { |
359 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL_SFI) | 358 #if !defined(OS_MACOSX) && !defined(OS_NACL_SFI) |
360 // Shared buffer creation failure is fatal, so always use the broker when we | 359 // Shared buffer creation failure is fatal, so always use the broker when we |
361 // have one. This does mean that a non-root process that has children will use | 360 // have one. This does mean that a non-root process that has children will use |
362 // the broker for shared buffer creation even though that process is | 361 // the broker for shared buffer creation even though that process is |
363 // privileged. | 362 // privileged. |
364 if (broker_) { | 363 if (broker_) { |
365 return broker_->GetSharedBuffer(num_bytes); | 364 return broker_->GetSharedBuffer(num_bytes); |
366 } | 365 } |
367 #endif | 366 #endif |
368 return PlatformSharedBuffer::Create(num_bytes); | 367 return PlatformSharedBuffer::Create(num_bytes); |
369 } | 368 } |
(...skipping 15 matching lines...) Expand all Loading... |
385 peer->NotifyBadMessage(error); | 384 peer->NotifyBadMessage(error); |
386 } | 385 } |
387 | 386 |
388 void NodeController::ConnectToChildOnIOThread( | 387 void NodeController::ConnectToChildOnIOThread( |
389 base::ProcessHandle process_handle, | 388 base::ProcessHandle process_handle, |
390 ScopedPlatformHandle platform_handle, | 389 ScopedPlatformHandle platform_handle, |
391 ports::NodeName token, | 390 ports::NodeName token, |
392 const ProcessErrorCallback& process_error_callback) { | 391 const ProcessErrorCallback& process_error_callback) { |
393 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 392 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
394 | 393 |
395 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL) | 394 #if !defined(OS_MACOSX) && !defined(OS_NACL) |
396 PlatformChannelPair node_channel; | 395 PlatformChannelPair node_channel; |
397 // BrokerHost owns itself. | 396 // BrokerHost owns itself. |
398 BrokerHost* broker_host = new BrokerHost(std::move(platform_handle)); | 397 BrokerHost* broker_host = |
| 398 new BrokerHost(process_handle, std::move(platform_handle)); |
399 broker_host->SendChannel(node_channel.PassClientHandle()); | 399 broker_host->SendChannel(node_channel.PassClientHandle()); |
400 scoped_refptr<NodeChannel> channel = NodeChannel::Create( | 400 scoped_refptr<NodeChannel> channel = NodeChannel::Create( |
401 this, node_channel.PassServerHandle(), io_task_runner_, | 401 this, node_channel.PassServerHandle(), io_task_runner_, |
402 process_error_callback); | 402 process_error_callback); |
403 #else | 403 #else |
404 scoped_refptr<NodeChannel> channel = | 404 scoped_refptr<NodeChannel> channel = |
405 NodeChannel::Create(this, std::move(platform_handle), io_task_runner_, | 405 NodeChannel::Create(this, std::move(platform_handle), io_task_runner_, |
406 process_error_callback); | 406 process_error_callback); |
407 #endif | 407 #endif |
408 | 408 |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 shutdown_callback_flag_.Set(false); | 1353 shutdown_callback_flag_.Set(false); |
1354 } | 1354 } |
1355 | 1355 |
1356 DCHECK(!callback.is_null()); | 1356 DCHECK(!callback.is_null()); |
1357 | 1357 |
1358 callback.Run(); | 1358 callback.Run(); |
1359 } | 1359 } |
1360 | 1360 |
1361 } // namespace edk | 1361 } // namespace edk |
1362 } // namespace mojo | 1362 } // namespace mojo |
OLD | NEW |