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

Unified Diff: mojo/shell/runner/host/mach_broker.h

Issue 1812523003: Add mach ports support to the Mojo shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-mach-ports
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/shell/runner/host/child_process_host.cc ('k') | mojo/shell/runner/host/mach_broker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/runner/host/mach_broker.h
diff --git a/mojo/shell/runner/host/mach_broker.h b/mojo/shell/runner/host/mach_broker.h
new file mode 100644
index 0000000000000000000000000000000000000000..19b4b8bb98e092450651c24d6a4eaa6075a8bb97
--- /dev/null
+++ b/mojo/shell/runner/host/mach_broker.h
@@ -0,0 +1,54 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_
+#define MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_
+
+#include "base/mac/mach_port_broker.h"
+
+namespace base {
+template <typename T> struct DefaultSingletonTraits;
+}
+
+namespace mojo {
+namespace shell {
+
+// A global singleton |MachBroker| is used by the shell to provide access to
+// Mach task ports for shell out-of-process applications.
+class MachBroker {
+ public:
+ // Sends the task port of the current process to the parent over Mach IPC.
+ // For use in child processes.
+ static void SendTaskPortToParent();
+
+ // Returns the global |MachBroker|. For use in the shell.
+ static MachBroker* GetInstance();
+
+ // Registers |pid| with a MACH_PORT_NULL task port in the port provider. A
+ // child's pid must be registered before the broker will accept a task port
+ // from that child.
+ // Callers MUST acquire the lock given by GetLock() before calling this method
+ // (and release the lock afterwards).
+ void ExpectPid(base::ProcessHandle pid);
+
+ // Removes |pid| from the port provider.
+ // Callers MUST acquire the lock given by GetLock() before calling this method
+ // (and release the lock afterwards).
+ void RemovePid(base::ProcessHandle pid);
+
+ base::Lock& GetLock() { return broker_.GetLock(); }
+ base::PortProvider* port_provider() { return &broker_; }
+
+ private:
+ MachBroker();
+ ~MachBroker();
+ friend struct base::DefaultSingletonTraits<MachBroker>;
+
+ base::MachPortBroker broker_;
+};
+
+} // namespace shell
+} // namespace mojo
+
+#endif // MOJO_SHELL_RUNNER_HOST_MACH_BROKER_H_
« no previous file with comments | « mojo/shell/runner/host/child_process_host.cc ('k') | mojo/shell/runner/host/mach_broker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698