Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: mojo/edk/system/node_controller.h

Issue 2227553002: Support mojo connections between unrelated peer processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/node_channel.cc ('k') | mojo/edk/system/node_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 base::Closure shutdown_callback_; 310 base::Closure shutdown_callback_;
299 // Flag to fast-path checking |shutdown_callback_|. 311 // Flag to fast-path checking |shutdown_callback_|.
300 AtomicFlag shutdown_callback_flag_; 312 AtomicFlag shutdown_callback_flag_;
301 313
302 // All other fields below must only be accessed on the I/O thread, i.e., the 314 // All other fields below must only be accessed on the I/O thread, i.e., the
303 // thread on which core_->io_task_runner() runs tasks. 315 // thread on which core_->io_task_runner() runs tasks.
304 316
305 // Channels to children during handshake. 317 // Channels to children during handshake.
306 NodeMap pending_children_; 318 NodeMap pending_children_;
307 319
320 using PeerNodeMap =
321 std::unordered_map<ports::NodeName,
322 std::pair<scoped_refptr<NodeChannel>, ports::PortRef>>;
323 PeerNodeMap pending_peers_;
324
308 // Indicates whether this object should delete itself on IO thread shutdown. 325 // Indicates whether this object should delete itself on IO thread shutdown.
309 // Must only be accessed from the IO thread. 326 // Must only be accessed from the IO thread.
310 bool destroy_on_io_thread_shutdown_ = false; 327 bool destroy_on_io_thread_shutdown_ = false;
311 328
312 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL_SFI) 329 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL_SFI)
313 // Broker for sync shared buffer creation (non-Mac posix-only) in children. 330 // Broker for sync shared buffer creation (non-Mac posix-only) in children.
314 std::unique_ptr<Broker> broker_; 331 std::unique_ptr<Broker> broker_;
315 #endif 332 #endif
316 333
317 #if defined(OS_MACOSX) && !defined(OS_IOS) 334 #if defined(OS_MACOSX) && !defined(OS_IOS)
318 base::Lock mach_port_relay_lock_; 335 base::Lock mach_port_relay_lock_;
319 // Relay for transferring mach ports to/from children. 336 // Relay for transferring mach ports to/from children.
320 std::unique_ptr<MachPortRelay> mach_port_relay_; 337 std::unique_ptr<MachPortRelay> mach_port_relay_;
321 #endif 338 #endif
322 339
323 DISALLOW_COPY_AND_ASSIGN(NodeController); 340 DISALLOW_COPY_AND_ASSIGN(NodeController);
324 }; 341 };
325 342
326 } // namespace edk 343 } // namespace edk
327 } // namespace mojo 344 } // namespace mojo
328 345
329 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ 346 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/node_channel.cc ('k') | mojo/edk/system/node_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698