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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
19 #include "mojo/edk/embedder/platform_handle_vector.h" | 19 #include "mojo/edk/embedder/platform_handle_vector.h" |
20 #include "mojo/edk/embedder/platform_shared_buffer.h" | 20 #include "mojo/edk/embedder/platform_shared_buffer.h" |
21 #include "mojo/edk/embedder/scoped_platform_handle.h" | 21 #include "mojo/edk/embedder/scoped_platform_handle.h" |
22 #include "mojo/edk/system/node_channel.h" | 22 #include "mojo/edk/system/node_channel.h" |
23 #include "mojo/edk/system/ports/hash_functions.h" | 23 #include "mojo/edk/system/ports/hash_functions.h" |
24 #include "mojo/edk/system/ports/name.h" | 24 #include "mojo/edk/system/ports/name.h" |
25 #include "mojo/edk/system/ports/node.h" | 25 #include "mojo/edk/system/ports/node.h" |
26 #include "mojo/edk/system/ports/node_delegate.h" | 26 #include "mojo/edk/system/ports/node_delegate.h" |
27 | 27 |
| 28 namespace base { |
| 29 class PortProvider; |
| 30 } |
| 31 |
28 namespace mojo { | 32 namespace mojo { |
29 namespace edk { | 33 namespace edk { |
30 | 34 |
31 class Broker; | 35 class Broker; |
32 class Core; | 36 class Core; |
| 37 class MachPortRelay; |
33 class PortsMessage; | 38 class PortsMessage; |
34 | 39 |
35 // The owner of ports::Node which facilitates core EDK implementation. All | 40 // The owner of ports::Node which facilitates core EDK implementation. All |
36 // public interface methods are safe to call from any thread. | 41 // public interface methods are safe to call from any thread. |
37 class NodeController : public ports::NodeDelegate, | 42 class NodeController : public ports::NodeDelegate, |
38 public NodeChannel::Delegate { | 43 public NodeChannel::Delegate { |
39 public: | 44 public: |
40 class PortObserver : public ports::UserData { | 45 class PortObserver : public ports::UserData { |
41 public: | 46 public: |
42 virtual void OnPortStatusChanged() = 0; | 47 virtual void OnPortStatusChanged() = 0; |
43 | 48 |
44 protected: | 49 protected: |
45 ~PortObserver() override {} | 50 ~PortObserver() override {} |
46 }; | 51 }; |
47 | 52 |
48 // |core| owns and out-lives us. | 53 // |core| owns and out-lives us. |
49 explicit NodeController(Core* core); | 54 explicit NodeController(Core* core); |
50 ~NodeController() override; | 55 ~NodeController() override; |
51 | 56 |
52 const ports::NodeName& name() const { return name_; } | 57 const ports::NodeName& name() const { return name_; } |
53 Core* core() const { return core_; } | 58 Core* core() const { return core_; } |
54 ports::Node* node() const { return node_.get(); } | 59 ports::Node* node() const { return node_.get(); } |
55 scoped_refptr<base::TaskRunner> io_task_runner() const { | 60 scoped_refptr<base::TaskRunner> io_task_runner() const { |
56 return io_task_runner_; | 61 return io_task_runner_; |
57 } | 62 } |
58 | 63 |
| 64 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 65 // Create the relay used to transfer mach ports between processes. |
| 66 void CreateMachPortRelay(base::PortProvider* port_provider); |
| 67 #endif |
| 68 |
59 // Called exactly once, shortly after construction, and before any other | 69 // Called exactly once, shortly after construction, and before any other |
60 // methods are called on this object. | 70 // methods are called on this object. |
61 void SetIOTaskRunner(scoped_refptr<base::TaskRunner> io_task_runner); | 71 void SetIOTaskRunner(scoped_refptr<base::TaskRunner> io_task_runner); |
62 | 72 |
63 // Connects this node to a child node. This node will initiate a handshake. | 73 // Connects this node to a child node. This node will initiate a handshake. |
64 void ConnectToChild(base::ProcessHandle process_handle, | 74 void ConnectToChild(base::ProcessHandle process_handle, |
65 ScopedPlatformHandle platform_handle); | 75 ScopedPlatformHandle platform_handle); |
66 | 76 |
67 // Connects this node to a parent node. The parent node will initiate a | 77 // Connects this node to a parent node. The parent node will initiate a |
68 // handshake. | 78 // handshake. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 ScopedPlatformHandle broker_channel) override; | 165 ScopedPlatformHandle broker_channel) override; |
156 void OnPortsMessage(Channel::MessagePtr message) override; | 166 void OnPortsMessage(Channel::MessagePtr message) override; |
157 void OnRequestPortMerge(const ports::NodeName& from_node, | 167 void OnRequestPortMerge(const ports::NodeName& from_node, |
158 const ports::PortName& connector_port_name, | 168 const ports::PortName& connector_port_name, |
159 const std::string& token) override; | 169 const std::string& token) override; |
160 void OnRequestIntroduction(const ports::NodeName& from_node, | 170 void OnRequestIntroduction(const ports::NodeName& from_node, |
161 const ports::NodeName& name) override; | 171 const ports::NodeName& name) override; |
162 void OnIntroduce(const ports::NodeName& from_node, | 172 void OnIntroduce(const ports::NodeName& from_node, |
163 const ports::NodeName& name, | 173 const ports::NodeName& name, |
164 ScopedPlatformHandle channel_handle) override; | 174 ScopedPlatformHandle channel_handle) override; |
165 #if defined(OS_WIN) | 175 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) |
166 void OnRelayPortsMessage(const ports::NodeName& from_node, | 176 void OnRelayPortsMessage(const ports::NodeName& from_node, |
167 base::ProcessHandle from_process, | 177 base::ProcessHandle from_process, |
168 const ports::NodeName& destination, | 178 const ports::NodeName& destination, |
169 Channel::MessagePtr message) override; | 179 Channel::MessagePtr message) override; |
170 #endif | 180 #endif |
171 void OnChannelError(const ports::NodeName& from_node) override; | 181 void OnChannelError(const ports::NodeName& from_node) override; |
| 182 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 183 MachPortRelay* GetMachPortRelay() override; |
| 184 #endif |
172 | 185 |
173 // Marks this NodeController for destruction when the IO thread shuts down. | 186 // Marks this NodeController for destruction when the IO thread shuts down. |
174 // This is used in case Core is torn down before the IO thread. Must only be | 187 // This is used in case Core is torn down before the IO thread. Must only be |
175 // called on the IO thread. | 188 // called on the IO thread. |
176 void DestroyOnIOThreadShutdown(); | 189 void DestroyOnIOThreadShutdown(); |
177 | 190 |
178 // If there is a registered shutdown callback (meaning shutdown has been | 191 // If there is a registered shutdown callback (meaning shutdown has been |
179 // requested, this checks the Node's status to see if clean shutdown is | 192 // requested, this checks the Node's status to see if clean shutdown is |
180 // possible. If so, shutdown is performed and the shutdown callback is run. | 193 // possible. If so, shutdown is performed and the shutdown callback is run. |
181 void AttemptShutdownIfRequested(); | 194 void AttemptShutdownIfRequested(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 264 |
252 // Indicates whether this object should delete itself on IO thread shutdown. | 265 // Indicates whether this object should delete itself on IO thread shutdown. |
253 // Must only be accessed from the IO thread. | 266 // Must only be accessed from the IO thread. |
254 bool destroy_on_io_thread_shutdown_ = false; | 267 bool destroy_on_io_thread_shutdown_ = false; |
255 | 268 |
256 #if defined(OS_POSIX) | 269 #if defined(OS_POSIX) |
257 // Broker for sync shared buffer creation (posix-only) in children. | 270 // Broker for sync shared buffer creation (posix-only) in children. |
258 scoped_ptr<Broker> broker_; | 271 scoped_ptr<Broker> broker_; |
259 #endif | 272 #endif |
260 | 273 |
| 274 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 275 base::Lock mach_port_relay_lock_; |
| 276 // Relay for transferring mach ports to/from children. |
| 277 scoped_ptr<MachPortRelay> mach_port_relay_; |
| 278 #endif |
| 279 |
261 DISALLOW_COPY_AND_ASSIGN(NodeController); | 280 DISALLOW_COPY_AND_ASSIGN(NodeController); |
262 }; | 281 }; |
263 | 282 |
264 } // namespace edk | 283 } // namespace edk |
265 } // namespace mojo | 284 } // namespace mojo |
266 | 285 |
267 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ | 286 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ |
OLD | NEW |