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

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

Issue 1712143002: [mojo-edk] Add support for transferring mach ports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More stuff. Created 4 years, 9 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
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 <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 CreateMachPortRelayIfNeeded(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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 ScopedPlatformHandle broker_channel) override; 162 ScopedPlatformHandle broker_channel) override;
153 void OnPortsMessage(Channel::MessagePtr message) override; 163 void OnPortsMessage(Channel::MessagePtr message) override;
154 void OnRequestPortMerge(const ports::NodeName& from_node, 164 void OnRequestPortMerge(const ports::NodeName& from_node,
155 const ports::PortName& connector_port_name, 165 const ports::PortName& connector_port_name,
156 const std::string& token) override; 166 const std::string& token) override;
157 void OnRequestIntroduction(const ports::NodeName& from_node, 167 void OnRequestIntroduction(const ports::NodeName& from_node,
158 const ports::NodeName& name) override; 168 const ports::NodeName& name) override;
159 void OnIntroduce(const ports::NodeName& from_node, 169 void OnIntroduce(const ports::NodeName& from_node,
160 const ports::NodeName& name, 170 const ports::NodeName& name,
161 ScopedPlatformHandle channel_handle) override; 171 ScopedPlatformHandle channel_handle) override;
162 #if defined(OS_WIN) 172 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
163 void OnRelayPortsMessage(const ports::NodeName& from_node, 173 void OnRelayPortsMessage(const ports::NodeName& from_node,
164 base::ProcessHandle from_process, 174 base::ProcessHandle from_process,
165 const ports::NodeName& destination, 175 const ports::NodeName& destination,
166 Channel::MessagePtr message) override; 176 Channel::MessagePtr message) override;
167 #endif 177 #endif
168 void OnChannelError(const ports::NodeName& from_node) override; 178 void OnChannelError(const ports::NodeName& from_node) override;
179 #if defined(OS_MACOSX) && !defined(OS_IOS)
180 MachPortRelay* GetMachPortRelay() override;
181 #endif
169 182
170 // Marks this NodeController for destruction when the IO thread shuts down. 183 // Marks this NodeController for destruction when the IO thread shuts down.
171 // This is used in case Core is torn down before the IO thread. Must only be 184 // This is used in case Core is torn down before the IO thread. Must only be
172 // called on the IO thread. 185 // called on the IO thread.
173 void DestroyOnIOThreadShutdown(); 186 void DestroyOnIOThreadShutdown();
174 187
175 // If there is a registered shutdown callback (meaning shutdown has been 188 // If there is a registered shutdown callback (meaning shutdown has been
176 // requested, this checks the Node's status to see if clean shutdown is 189 // requested, this checks the Node's status to see if clean shutdown is
177 // possible. If so, shutdown is performed and the shutdown callback is run. 190 // possible. If so, shutdown is performed and the shutdown callback is run.
178 void AttemptShutdownIfRequested(); 191 void AttemptShutdownIfRequested();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 261
249 // Indicates whether this object should delete itself on IO thread shutdown. 262 // Indicates whether this object should delete itself on IO thread shutdown.
250 // Must only be accessed from the IO thread. 263 // Must only be accessed from the IO thread.
251 bool destroy_on_io_thread_shutdown_ = false; 264 bool destroy_on_io_thread_shutdown_ = false;
252 265
253 #if defined(OS_POSIX) 266 #if defined(OS_POSIX)
254 // Broker for sync shared buffer creation (posix-only) in children. 267 // Broker for sync shared buffer creation (posix-only) in children.
255 scoped_ptr<Broker> broker_; 268 scoped_ptr<Broker> broker_;
256 #endif 269 #endif
257 270
271 #if defined(OS_MACOSX) && !defined(OS_IOS)
272 base::Lock mach_port_relay_lock_;
273 // Relay for transferring mach ports to/from children.
274 scoped_ptr<MachPortRelay> mach_port_relay_;
275 #endif
276
258 DISALLOW_COPY_AND_ASSIGN(NodeController); 277 DISALLOW_COPY_AND_ASSIGN(NodeController);
259 }; 278 };
260 279
261 } // namespace edk 280 } // namespace edk
262 } // namespace mojo 281 } // namespace mojo
263 282
264 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_ 283 #endif // MOJO_EDK_SYSTEM_NODE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698