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 #ifndef MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ |
6 #define MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ | 6 #define MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <unordered_map> | 10 #include <unordered_map> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 const ProcessErrorCallback& process_error_callback); | 78 const ProcessErrorCallback& process_error_callback); |
79 | 79 |
80 // Closes all reserved ports which associated with the child process | 80 // Closes all reserved ports which associated with the child process |
81 // |child_token|. | 81 // |child_token|. |
82 void CloseChildPorts(const std::string& child_token); | 82 void CloseChildPorts(const std::string& child_token); |
83 | 83 |
84 // Connects this node to a parent node. The parent node will initiate a | 84 // Connects this node to a parent node. The parent node will initiate a |
85 // handshake. | 85 // handshake. |
86 void ConnectToParent(ScopedPlatformHandle platform_handle); | 86 void ConnectToParent(ScopedPlatformHandle platform_handle); |
87 | 87 |
| 88 // Connects this node to a peer node. On success, |port| will be merged with |
| 89 // the corresponding port in the peer node. |
| 90 void ConnectToPeer(ScopedPlatformHandle handle, const ports::PortRef& port); |
| 91 |
88 // Sets a port's observer. If |observer| is null the port's current observer | 92 // Sets a port's observer. If |observer| is null the port's current observer |
89 // is removed. | 93 // is removed. |
90 void SetPortObserver(const ports::PortRef& port, | 94 void SetPortObserver(const ports::PortRef& port, |
91 const scoped_refptr<PortObserver>& observer); | 95 const scoped_refptr<PortObserver>& observer); |
92 | 96 |
93 // Closes a port. Use this in lieu of calling Node::ClosePort() directly, as | 97 // Closes a port. Use this in lieu of calling Node::ClosePort() directly, as |
94 // it ensures the port's observer has also been removed. | 98 // it ensures the port's observer has also been removed. |
95 void ClosePort(const ports::PortRef& port); | 99 void ClosePort(const ports::PortRef& port); |
96 | 100 |
97 // Sends a message on a port to its peer. | 101 // Sends a message on a port to its peer. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 const std::string child_token; | 143 const std::string child_token; |
140 }; | 144 }; |
141 | 145 |
142 void ConnectToChildOnIOThread( | 146 void ConnectToChildOnIOThread( |
143 base::ProcessHandle process_handle, | 147 base::ProcessHandle process_handle, |
144 ScopedPlatformHandle platform_handle, | 148 ScopedPlatformHandle platform_handle, |
145 ports::NodeName token, | 149 ports::NodeName token, |
146 const ProcessErrorCallback& process_error_callback); | 150 const ProcessErrorCallback& process_error_callback); |
147 void ConnectToParentOnIOThread(ScopedPlatformHandle platform_handle); | 151 void ConnectToParentOnIOThread(ScopedPlatformHandle platform_handle); |
148 | 152 |
| 153 void ConnectToPeerOnIOThread(ScopedPlatformHandle handle, |
| 154 ports::NodeName token, |
| 155 ports::PortRef port); |
| 156 |
149 scoped_refptr<NodeChannel> GetPeerChannel(const ports::NodeName& name); | 157 scoped_refptr<NodeChannel> GetPeerChannel(const ports::NodeName& name); |
150 scoped_refptr<NodeChannel> GetParentChannel(); | 158 scoped_refptr<NodeChannel> GetParentChannel(); |
151 scoped_refptr<NodeChannel> GetBrokerChannel(); | 159 scoped_refptr<NodeChannel> GetBrokerChannel(); |
152 | 160 |
153 void AddPeer(const ports::NodeName& name, | 161 void AddPeer(const ports::NodeName& name, |
154 scoped_refptr<NodeChannel> channel, | 162 scoped_refptr<NodeChannel> channel, |
155 bool start_channel); | 163 bool start_channel); |
156 void DropPeer(const ports::NodeName& name, NodeChannel* channel); | 164 void DropPeer(const ports::NodeName& name, NodeChannel* channel); |
157 void SendPeerMessage(const ports::NodeName& name, | 165 void SendPeerMessage(const ports::NodeName& name, |
158 ports::ScopedMessage message); | 166 ports::ScopedMessage message); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 Channel::MessagePtr message) override; | 207 Channel::MessagePtr message) override; |
200 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) | 208 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) |
201 void OnRelayPortsMessage(const ports::NodeName& from_node, | 209 void OnRelayPortsMessage(const ports::NodeName& from_node, |
202 base::ProcessHandle from_process, | 210 base::ProcessHandle from_process, |
203 const ports::NodeName& destination, | 211 const ports::NodeName& destination, |
204 Channel::MessagePtr message) override; | 212 Channel::MessagePtr message) override; |
205 void OnPortsMessageFromRelay(const ports::NodeName& from_node, | 213 void OnPortsMessageFromRelay(const ports::NodeName& from_node, |
206 const ports::NodeName& source_node, | 214 const ports::NodeName& source_node, |
207 Channel::MessagePtr message) override; | 215 Channel::MessagePtr message) override; |
208 #endif | 216 #endif |
| 217 void OnAcceptPeer(const ports::NodeName& from_node, |
| 218 const ports::NodeName& token, |
| 219 const ports::NodeName& peer_name, |
| 220 const ports::PortName& port_name) override; |
209 void OnChannelError(const ports::NodeName& from_node, | 221 void OnChannelError(const ports::NodeName& from_node, |
210 NodeChannel* channel) override; | 222 NodeChannel* channel) override; |
211 #if defined(OS_MACOSX) && !defined(OS_IOS) | 223 #if defined(OS_MACOSX) && !defined(OS_IOS) |
212 MachPortRelay* GetMachPortRelay() override; | 224 MachPortRelay* GetMachPortRelay() override; |
213 #endif | 225 #endif |
214 | 226 |
215 // Marks this NodeController for destruction when the IO thread shuts down. | 227 // Marks this NodeController for destruction when the IO thread shuts down. |
216 // This is used in case Core is torn down before the IO thread. Must only be | 228 // This is used in case Core is torn down before the IO thread. Must only be |
217 // called on the IO thread. | 229 // called on the IO thread. |
218 void DestroyOnIOThreadShutdown(); | 230 void DestroyOnIOThreadShutdown(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 base::Closure shutdown_callback_; | 308 base::Closure shutdown_callback_; |
297 // Flag to fast-path checking |shutdown_callback_|. | 309 // Flag to fast-path checking |shutdown_callback_|. |
298 AtomicFlag shutdown_callback_flag_; | 310 AtomicFlag shutdown_callback_flag_; |
299 | 311 |
300 // All other fields below must only be accessed on the I/O thread, i.e., the | 312 // All other fields below must only be accessed on the I/O thread, i.e., the |
301 // thread on which core_->io_task_runner() runs tasks. | 313 // thread on which core_->io_task_runner() runs tasks. |
302 | 314 |
303 // Channels to children during handshake. | 315 // Channels to children during handshake. |
304 NodeMap pending_children_; | 316 NodeMap pending_children_; |
305 | 317 |
| 318 using PeerNodeMap = |
| 319 std::unordered_map<ports::NodeName, |
| 320 std::pair<scoped_refptr<NodeChannel>, ports::PortRef>>; |
| 321 PeerNodeMap pending_peers_; |
| 322 |
306 // Indicates whether this object should delete itself on IO thread shutdown. | 323 // Indicates whether this object should delete itself on IO thread shutdown. |
307 // Must only be accessed from the IO thread. | 324 // Must only be accessed from the IO thread. |
308 bool destroy_on_io_thread_shutdown_ = false; | 325 bool destroy_on_io_thread_shutdown_ = false; |
309 | 326 |
310 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL_SFI) | 327 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL_SFI) |
311 // Broker for sync shared buffer creation (non-Mac posix-only) in children. | 328 // Broker for sync shared buffer creation (non-Mac posix-only) in children. |
312 std::unique_ptr<Broker> broker_; | 329 std::unique_ptr<Broker> broker_; |
313 #endif | 330 #endif |
314 | 331 |
315 #if defined(OS_MACOSX) && !defined(OS_IOS) | 332 #if defined(OS_MACOSX) && !defined(OS_IOS) |
316 base::Lock mach_port_relay_lock_; | 333 base::Lock mach_port_relay_lock_; |
317 // Relay for transferring mach ports to/from children. | 334 // Relay for transferring mach ports to/from children. |
318 std::unique_ptr<MachPortRelay> mach_port_relay_; | 335 std::unique_ptr<MachPortRelay> mach_port_relay_; |
319 #endif | 336 #endif |
320 | 337 |
321 DISALLOW_COPY_AND_ASSIGN(NodeController); | 338 DISALLOW_COPY_AND_ASSIGN(NodeController); |
322 }; | 339 }; |
323 | 340 |
324 } // namespace edk | 341 } // namespace edk |
325 } // namespace mojo | 342 } // namespace mojo |
326 | 343 |
327 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ | 344 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ |
OLD | NEW |