OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_ | |
6 #define MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_ | |
7 | |
8 #include "base/mac/mach_port_broker.h" | |
9 | |
10 namespace base { | |
11 template <typename T> struct DefaultSingletonTraits; | |
12 } | |
13 | |
14 namespace mojo { | |
15 namespace shell { | |
16 | |
17 // A global singleton |MachBroker| is used by the shell to provide access to | |
18 // Mach task ports for shell out-of-process applications. | |
19 class MachBroker { | |
20 public: | |
21 // Sends the task port of the current process to the parent over Mach IPC. | |
22 // For use in child processes. | |
23 static void SendTaskPortToParent(); | |
24 | |
25 // Returns the global |MachBroker|. For use in the shell. | |
26 static MachBroker* GetInstance(); | |
27 | |
28 // Registers |pid| with a MACH_PORT_NULL task port in the port provider. A | |
29 // child's pid must be registered before the broker will accept a task port | |
30 // from that child. | |
31 // Callers MUST acquire the lock given by GetLock() before calling this method | |
32 // (and release the lock afterwards). | |
33 void ExpectPid(base::ProcessHandle pid); | |
34 | |
35 // Removes |pid| from the port provider. | |
36 // Callers MUST acquire the lock given by GetLock() before calling this method | |
37 // (and release the lock afterwards). | |
38 void RemovePid(base::ProcessHandle pid); | |
39 | |
40 base::Lock& GetLock() { return broker_.GetLock(); } | |
41 base::PortProvider* port_provider() { return &broker_; } | |
42 | |
43 private: | |
44 MachBroker(); | |
45 ~MachBroker(); | |
46 friend struct base::DefaultSingletonTraits<MachBroker>; | |
47 | |
48 base::MachPortBroker broker_; | |
49 }; | |
50 | |
51 } // namespace shell | |
52 } // namespace mojo | |
53 | |
54 #endif // MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_ | |
OLD | NEW |