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 <queue> | 8 #include <queue> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <unordered_set> | 10 #include <unordered_set> |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 void ConnectToParentPort(const ports::PortRef& local_port, | 103 void ConnectToParentPort(const ports::PortRef& local_port, |
104 const std::string& token, | 104 const std::string& token, |
105 const base::Closure& callback); | 105 const base::Closure& callback); |
106 | 106 |
107 // Connects two reserved ports to each other. Useful when two independent | 107 // Connects two reserved ports to each other. Useful when two independent |
108 // systems in the same (parent) process need to establish a port pair without | 108 // systems in the same (parent) process need to establish a port pair without |
109 // any direct knowledge of each other. | 109 // any direct knowledge of each other. |
110 void ConnectReservedPorts(const std::string& token1, | 110 void ConnectReservedPorts(const std::string& token1, |
111 const std::string& token2); | 111 const std::string& token2); |
112 | 112 |
113 // Connects a local port to a port on a remote node. Note that a connection to | |
114 // the remote node need not be established yet. The port will be connected | |
115 // ASAP, at which point |callback| will be run. | |
116 void ConnectToRemotePort(const ports::PortRef& local_port, | |
117 const ports::NodeName& remote_node_name, | |
118 const ports::PortName& remote_port_name, | |
119 const base::Closure& callback); | |
120 | |
121 // Creates a new shared buffer for use in the current process. | 113 // Creates a new shared buffer for use in the current process. |
122 scoped_refptr<PlatformSharedBuffer> CreateSharedBuffer(size_t num_bytes); | 114 scoped_refptr<PlatformSharedBuffer> CreateSharedBuffer(size_t num_bytes); |
123 | 115 |
124 // Request that the Node be shut down cleanly. This may take an arbitrarily | 116 // Request that the Node be shut down cleanly. This may take an arbitrarily |
125 // long time to complete, at which point |callback| will be called. | 117 // long time to complete, at which point |callback| will be called. |
126 // | 118 // |
127 // Note that while it is safe to continue using the NodeController's public | 119 // Note that while it is safe to continue using the NodeController's public |
128 // interface after requesting shutdown, you do so at your own risk and there | 120 // interface after requesting shutdown, you do so at your own risk and there |
129 // is NO guarantee that new messages will be sent or ports will complete | 121 // is NO guarantee that new messages will be sent or ports will complete |
130 // transfer. | 122 // transfer. |
(...skipping 18 matching lines...) Expand all Loading... |
149 | 141 |
150 // Tracks a reserved port. | 142 // Tracks a reserved port. |
151 struct ReservedPort { | 143 struct ReservedPort { |
152 ReservedPort(); | 144 ReservedPort(); |
153 ~ReservedPort(); | 145 ~ReservedPort(); |
154 | 146 |
155 ports::PortRef local_port; | 147 ports::PortRef local_port; |
156 ReservePortCallback callback; | 148 ReservePortCallback callback; |
157 }; | 149 }; |
158 | 150 |
159 // Tracks a pending connection to a remote port on any peer. | |
160 struct PendingRemotePortConnection { | |
161 PendingRemotePortConnection(); | |
162 ~PendingRemotePortConnection(); | |
163 | |
164 ports::PortRef local_port; | |
165 ports::NodeName remote_node_name; | |
166 ports::PortName remote_port_name; | |
167 base::Closure callback; | |
168 }; | |
169 | |
170 void ConnectToChildOnIOThread(base::ProcessHandle process_handle, | 151 void ConnectToChildOnIOThread(base::ProcessHandle process_handle, |
171 ScopedPlatformHandle platform_handle); | 152 ScopedPlatformHandle platform_handle); |
172 void ConnectToParentOnIOThread(ScopedPlatformHandle platform_handle); | 153 void ConnectToParentOnIOThread(ScopedPlatformHandle platform_handle); |
173 void RequestParentPortConnectionOnIOThread(const ports::PortRef& local_port, | 154 void RequestParentPortConnectionOnIOThread(const ports::PortRef& local_port, |
174 const std::string& token, | 155 const std::string& token, |
175 const base::Closure& callback); | 156 const base::Closure& callback); |
176 void ConnectToRemotePortOnIOThread( | |
177 const PendingRemotePortConnection& connection); | |
178 | 157 |
179 scoped_refptr<NodeChannel> GetPeerChannel(const ports::NodeName& name); | 158 scoped_refptr<NodeChannel> GetPeerChannel(const ports::NodeName& name); |
180 scoped_refptr<NodeChannel> GetParentChannel(); | 159 scoped_refptr<NodeChannel> GetParentChannel(); |
181 | 160 |
182 void AddPeer(const ports::NodeName& name, | 161 void AddPeer(const ports::NodeName& name, |
183 scoped_refptr<NodeChannel> channel, | 162 scoped_refptr<NodeChannel> channel, |
184 bool start_channel); | 163 bool start_channel); |
185 void DropPeer(const ports::NodeName& name); | 164 void DropPeer(const ports::NodeName& name); |
186 void SendPeerMessage(const ports::NodeName& name, | 165 void SendPeerMessage(const ports::NodeName& name, |
187 ports::ScopedMessage message); | 166 ports::ScopedMessage message); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // Channels to children during handshake. | 261 // Channels to children during handshake. |
283 NodeMap pending_children_; | 262 NodeMap pending_children_; |
284 | 263 |
285 // Port connection requests which have been deferred until we have a parent. | 264 // Port connection requests which have been deferred until we have a parent. |
286 std::vector<PendingPortRequest> pending_port_requests_; | 265 std::vector<PendingPortRequest> pending_port_requests_; |
287 | 266 |
288 // Port connection requests awaiting a response from the parent. | 267 // Port connection requests awaiting a response from the parent. |
289 std::unordered_map<ports::PortName, base::Closure> | 268 std::unordered_map<ports::PortName, base::Closure> |
290 pending_parent_port_connections_; | 269 pending_parent_port_connections_; |
291 | 270 |
292 // Port connections pending the availability of a remote peer node. | |
293 std::unordered_map<ports::NodeName, std::vector<PendingRemotePortConnection>> | |
294 pending_remote_port_connections_; | |
295 | |
296 // Indicates whether this object should delete itself on IO thread shutdown. | 271 // Indicates whether this object should delete itself on IO thread shutdown. |
297 // Must only be accessed from the IO thread. | 272 // Must only be accessed from the IO thread. |
298 bool destroy_on_io_thread_shutdown_ = false; | 273 bool destroy_on_io_thread_shutdown_ = false; |
299 | 274 |
300 DISALLOW_COPY_AND_ASSIGN(NodeController); | 275 DISALLOW_COPY_AND_ASSIGN(NodeController); |
301 }; | 276 }; |
302 | 277 |
303 } // namespace edk | 278 } // namespace edk |
304 } // namespace mojo | 279 } // namespace mojo |
305 | 280 |
306 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ | 281 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ |
OLD | NEW |