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

Side by Side Diff: content/browser/mach_broker_mac.h

Issue 1137453002: content: Pass IOSurface references using Mach IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove parameter from MachBroker::InitChildProcess Created 5 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_BROWSER_MACH_BROKER_MAC_H_ 5 #ifndef CONTENT_BROWSER_MACH_BROKER_MAC_H_
6 #define CONTENT_BROWSER_MACH_BROKER_MAC_H_ 6 #define CONTENT_BROWSER_MACH_BROKER_MAC_H_
7 7
8 #include <mach/mach.h> 8 #include <mach/mach.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 20 matching lines...) Expand all
31 // the regular IPC system uses. Hence, the child processes open a Mach 31 // the regular IPC system uses. Hence, the child processes open a Mach
32 // connection shortly after launching and ipc their mach data to the browser 32 // connection shortly after launching and ipc their mach data to the browser
33 // process. This data is kept in a global |MachBroker| object. 33 // process. This data is kept in a global |MachBroker| object.
34 // 34 //
35 // Since this data arrives over a separate channel, it is not available 35 // Since this data arrives over a separate channel, it is not available
36 // immediately after a child process has been started. 36 // immediately after a child process has been started.
37 class CONTENT_EXPORT MachBroker : public base::ProcessMetrics::PortProvider, 37 class CONTENT_EXPORT MachBroker : public base::ProcessMetrics::PortProvider,
38 public BrowserChildProcessObserver, 38 public BrowserChildProcessObserver,
39 public NotificationObserver { 39 public NotificationObserver {
40 public: 40 public:
41 // For use in child processes. This will send the task port of the current 41 // For use in child processes. This will allocate Mach ports and send the
42 // process over Mach IPC to the port registered by name (via this class) in 42 // task port of the current process over Mach IPC to the port registered by
43 // the parent process. Returns true if the message was sent successfully 43 // name (via this class) in the parent process. Returns true if Mach ports
44 // and false if otherwise. 44 // were successfully allocated and the task port successfully sent to the
45 static bool ChildSendTaskPortToParent(); 45 // parent process.
46 static bool InitChildProcess();
46 47
47 // Returns the global MachBroker. 48 // Returns the global MachBroker.
48 static MachBroker* GetInstance(); 49 static MachBroker* GetInstance();
49 50
50 // The lock that protects this MachBroker object. Clients MUST acquire and 51 // The lock that protects this MachBroker object. Clients MUST acquire and
51 // release this lock around calls to EnsureRunning(), PlaceholderForPid(), 52 // release this lock around calls to EnsureRunning(), PlaceholderForPid(),
52 // and FinalizePid(). 53 // and FinalizePid().
53 base::Lock& GetLock(); 54 base::Lock& GetLock();
54 55
55 // Performs any necessary setup that cannot happen in the constructor. 56 // Performs any necessary setup that cannot happen in the constructor.
56 // Callers MUST acquire the lock given by GetLock() before calling this 57 // Callers MUST acquire the lock given by GetLock() before calling this
57 // method (and release the lock afterwards). 58 // method (and release the lock afterwards).
58 void EnsureRunning(); 59 void EnsureRunning();
59 60
60 // Adds a placeholder to the map for the given pid with MACH_PORT_NULL. 61 // Adds a placeholder to the map for the given pid with MACH_PORT_NULL.
61 // Callers are expected to later update the port with FinalizePid(). Callers 62 // Callers are expected to later update the port with FinalizePid(). Callers
62 // MUST acquire the lock given by GetLock() before calling this method (and 63 // MUST acquire the lock given by GetLock() before calling this method (and
63 // release the lock afterwards). 64 // release the lock afterwards).
64 void AddPlaceholderForPid(base::ProcessHandle pid, int child_process_id); 65 void AddPlaceholderForPid(base::ProcessHandle pid,
66 int child_process_id,
67 bool is_gpu_process);
65 68
66 // Implement |ProcessMetrics::PortProvider|. 69 // Implement |ProcessMetrics::PortProvider|.
67 mach_port_t TaskForPid(base::ProcessHandle process) const override; 70 mach_port_t TaskForPid(base::ProcessHandle process) const override;
68 71
69 // Implement |BrowserChildProcessObserver|. 72 // Implement |BrowserChildProcessObserver|.
70 void BrowserChildProcessHostDisconnected( 73 void BrowserChildProcessHostDisconnected(
71 const ChildProcessData& data) override; 74 const ChildProcessData& data) override;
72 void BrowserChildProcessCrashed(const ChildProcessData& data, 75 void BrowserChildProcessCrashed(const ChildProcessData& data,
73 int exit_code) override; 76 int exit_code) override;
74 77
(...skipping 12 matching lines...) Expand all
87 90
88 // Updates the mapping for |pid| to include the given |mach_info|. Does 91 // Updates the mapping for |pid| to include the given |mach_info|. Does
89 // nothing if PlaceholderForPid() has not already been called for the given 92 // nothing if PlaceholderForPid() has not already been called for the given
90 // |pid|. Callers MUST acquire the lock given by GetLock() before calling 93 // |pid|. Callers MUST acquire the lock given by GetLock() before calling
91 // this method (and release the lock afterwards). 94 // this method (and release the lock afterwards).
92 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); 95 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port);
93 96
94 // Removes all mappings belonging to |child_process_id| from the broker. 97 // Removes all mappings belonging to |child_process_id| from the broker.
95 void InvalidateChildProcessId(int child_process_id); 98 void InvalidateChildProcessId(int child_process_id);
96 99
100 // Register an IO surface for use in child process with |client_id|.
101 // Callers MUST acquire the lock given by GetLock() before calling this
102 // method (and release the lock afterwards).
103 bool RegisterIOSurface(base::ProcessHandle pid,
104 int io_surface_id,
105 int client_id,
106 mach_port_t io_surface_port);
107
108 // Unregister an IO surface. Callers MUST acquire the lock given by GetLock()
109 // before calling this method (and release the lock afterwards).
110 void UnregisterIOSurface(base::ProcessHandle pid,
111 int io_surface_id,
112 int client_id);
113
114 // Acquire IO surface reference for a registered IO surface. This will
115 // only succeed if the IO surface is registered for use in |pid|. Callers
116 // MUST acquire the lock given by GetLock() before calling this method
117 // (and release the lock afterwards). Returns MACH_PORT_NULL on failure.
118 mach_port_t AcquireIOSurface(base::ProcessHandle pid, int io_surface_id);
119
97 // Returns the Mach port name to use when sending or receiving messages. 120 // Returns the Mach port name to use when sending or receiving messages.
98 // Does the Right Thing in the browser and in child processes. 121 // Does the Right Thing in the browser and in child processes.
99 static std::string GetMachPortName(); 122 static std::string GetMachPortName();
100 // Callback used to register notifications on the UI thread. 123 // Callback used to register notifications on the UI thread.
101 void RegisterNotifications(); 124 void RegisterNotifications();
102 125
103 // True if the listener thread has been started. 126 // True if the listener thread has been started.
104 bool listener_thread_started_; 127 bool listener_thread_started_;
105 128
106 // Used to register for notifications received by NotificationObserver. 129 // Used to register for notifications received by NotificationObserver.
107 // Accessed only on the UI thread. 130 // Accessed only on the UI thread.
108 NotificationRegistrar registrar_; 131 NotificationRegistrar registrar_;
109 132
110 // Stores mach info for every process in the broker. 133 // Stores mach info for every process in the broker.
111 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; 134 struct MachPortSet {
135 MachPortSet();
136 explicit MachPortSet(bool is_gpu_process);
137 ~MachPortSet();
138
139 bool is_gpu_process;
140 mach_port_t task_port;
141 std::map<int, mach_port_t> io_surface_ports;
142 };
143 typedef std::map<base::ProcessHandle, MachPortSet> MachMap;
112 MachMap mach_map_; 144 MachMap mach_map_;
113 145
114 // Stores the Child process unique id (RenderProcessHost ID) for every 146 // Stores the Child process unique id (RenderProcessHost ID) for every
115 // process. 147 // process.
116 typedef std::map<int, base::ProcessHandle> ChildProcessIdMap; 148 typedef std::map<int, base::ProcessHandle> ChildProcessIdMap;
117 ChildProcessIdMap child_process_id_map_; 149 ChildProcessIdMap child_process_id_map_;
118 150
119 // Mutex that guards |mach_map_| and |child_process_id_map_|. 151 // Mutex that guards |mach_map_| and |child_process_id_map_|.
120 mutable base::Lock lock_; 152 mutable base::Lock lock_;
121 153
122 DISALLOW_COPY_AND_ASSIGN(MachBroker); 154 DISALLOW_COPY_AND_ASSIGN(MachBroker);
123 }; 155 };
124 156
125 } // namespace content 157 } // namespace content
126 158
127 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_ 159 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698