| 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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 } else { | 570 } else { |
| 571 // We aren't the broker, so wait for a broker connection. | 571 // We aren't the broker, so wait for a broker connection. |
| 572 base::AutoLock lock(broker_lock_); | 572 base::AutoLock lock(broker_lock_); |
| 573 pending_broker_clients_.push(child_name); | 573 pending_broker_clients_.push(child_name); |
| 574 } | 574 } |
| 575 } | 575 } |
| 576 } | 576 } |
| 577 | 577 |
| 578 void NodeController::OnAddBrokerClient(const ports::NodeName& from_node, | 578 void NodeController::OnAddBrokerClient(const ports::NodeName& from_node, |
| 579 const ports::NodeName& client_name, | 579 const ports::NodeName& client_name, |
| 580 ScopedPlatformHandle process_handle) { | 580 base::ProcessHandle process_handle) { |
| 581 #if defined(OS_WIN) |
| 582 // Scoped handle to avoid leaks on error. |
| 583 ScopedPlatformHandle scoped_process_handle = |
| 584 ScopedPlatformHandle(PlatformHandle(process_handle)); |
| 585 #endif |
| 581 scoped_refptr<NodeChannel> sender = GetPeerChannel(from_node); | 586 scoped_refptr<NodeChannel> sender = GetPeerChannel(from_node); |
| 582 if (!sender) { | 587 if (!sender) { |
| 583 DLOG(ERROR) << "Ignoring AddBrokerClient from unknown sender."; | 588 DLOG(ERROR) << "Ignoring AddBrokerClient from unknown sender."; |
| 584 return; | 589 return; |
| 585 } | 590 } |
| 586 | 591 |
| 587 if (GetPeerChannel(client_name)) { | 592 if (GetPeerChannel(client_name)) { |
| 588 DLOG(ERROR) << "Ignoring AddBrokerClient for known client."; | 593 DLOG(ERROR) << "Ignoring AddBrokerClient for known client."; |
| 589 DropPeer(from_node); | 594 DropPeer(from_node); |
| 590 return; | 595 return; |
| 591 } | 596 } |
| 592 | 597 |
| 593 PlatformChannelPair broker_channel; | 598 PlatformChannelPair broker_channel; |
| 594 scoped_refptr<NodeChannel> client = NodeChannel::Create( | 599 scoped_refptr<NodeChannel> client = NodeChannel::Create( |
| 595 this, broker_channel.PassServerHandle(), io_task_runner_); | 600 this, broker_channel.PassServerHandle(), io_task_runner_); |
| 596 | 601 |
| 597 #if defined(OS_WIN) | 602 #if defined(OS_WIN) |
| 598 // The broker must have a working handle to the client process in order to | 603 // The broker must have a working handle to the client process in order to |
| 599 // properly copy other handles to and from the client. | 604 // properly copy other handles to and from the client. |
| 600 if(!process_handle.is_valid()) { | 605 if (!scoped_process_handle.is_valid()) { |
| 601 DLOG(ERROR) << "Broker rejecting client with invalid process handle."; | 606 DLOG(ERROR) << "Broker rejecting client with invalid process handle."; |
| 602 return; | 607 return; |
| 603 } | 608 } |
| 604 client->SetRemoteProcessHandle(process_handle.release().handle); | 609 client->SetRemoteProcessHandle(scoped_process_handle.release().handle); |
| 610 #else |
| 611 client->SetRemoteProcessHandle(process_handle); |
| 605 #endif | 612 #endif |
| 606 | 613 |
| 607 AddPeer(client_name, client, true /* start_channel */); | 614 AddPeer(client_name, client, true /* start_channel */); |
| 608 | 615 |
| 609 DVLOG(1) << "Broker " << name_ << " accepting client " << client_name | 616 DVLOG(1) << "Broker " << name_ << " accepting client " << client_name |
| 610 << " from peer " << from_node; | 617 << " from peer " << from_node; |
| 611 | 618 |
| 612 sender->BrokerClientAdded(client_name, broker_channel.PassClientHandle()); | 619 sender->BrokerClientAdded(client_name, broker_channel.PassClientHandle()); |
| 613 } | 620 } |
| 614 | 621 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 shutdown_callback_.Reset(); | 877 shutdown_callback_.Reset(); |
| 871 } | 878 } |
| 872 | 879 |
| 873 DCHECK(!callback.is_null()); | 880 DCHECK(!callback.is_null()); |
| 874 | 881 |
| 875 callback.Run(); | 882 callback.Run(); |
| 876 } | 883 } |
| 877 | 884 |
| 878 } // namespace edk | 885 } // namespace edk |
| 879 } // namespace mojo | 886 } // namespace mojo |
| OLD | NEW |