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

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: dcastagna's review 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 26 matching lines...) Expand all
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 send the task port of the current
42 // process over Mach IPC to the port registered by name (via this class) in 42 // process over Mach IPC to the port registered by name (via this class) in
43 // the parent process. Returns true if the message was sent successfully 43 // the parent process. Returns true if the message was sent successfully
44 // and false if otherwise. 44 // and false if otherwise.
45 static bool ChildSendTaskPortToParent(); 45 static bool ChildSendTaskPortToParent();
46 46
47 // Register an IO surface for use in child process with |client_id|.
48 static bool ChildRegisterIOSurfaceWithParent(int io_surface_id,
49 int client_id,
50 mach_port_t io_surface_port);
51
52 // Unregister an IO surface.
53 static bool ChildUnregisterIOSurfaceWithParent(int io_surface_id,
54 int client_id);
55
56 // Acquire IO surface reference for a registered IO surface. This will only
57 // succeed if the IO surface has been registered for use in the current
58 // process.
59 static mach_port_t ChildAcquireIOSurfaceFromParent(int io_surface_id);
60
Avi (use Gerrit) 2015/05/09 18:00:28 You might as well keep these private and have Mach
47 // Returns the global MachBroker. 61 // Returns the global MachBroker.
48 static MachBroker* GetInstance(); 62 static MachBroker* GetInstance();
49 63
50 // The lock that protects this MachBroker object. Clients MUST acquire and 64 // The lock that protects this MachBroker object. Clients MUST acquire and
51 // release this lock around calls to EnsureRunning(), PlaceholderForPid(), 65 // release this lock around calls to EnsureRunning(), PlaceholderForPid(),
52 // and FinalizePid(). 66 // and FinalizePid().
53 base::Lock& GetLock(); 67 base::Lock& GetLock();
54 68
55 // Performs any necessary setup that cannot happen in the constructor. 69 // Performs any necessary setup that cannot happen in the constructor.
56 // Callers MUST acquire the lock given by GetLock() before calling this 70 // Callers MUST acquire the lock given by GetLock() before calling this
57 // method (and release the lock afterwards). 71 // method (and release the lock afterwards).
58 void EnsureRunning(); 72 void EnsureRunning();
59 73
60 // Adds a placeholder to the map for the given pid with MACH_PORT_NULL. 74 // 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 75 // Callers are expected to later update the port with FinalizePid(). Callers
62 // MUST acquire the lock given by GetLock() before calling this method (and 76 // MUST acquire the lock given by GetLock() before calling this method (and
63 // release the lock afterwards). 77 // release the lock afterwards).
64 void AddPlaceholderForPid(base::ProcessHandle pid, int child_process_id); 78 void AddPlaceholderForPid(base::ProcessHandle pid,
79 int child_process_id,
80 bool is_gpu_process);
65 81
66 // Implement |ProcessMetrics::PortProvider|. 82 // Implement |ProcessMetrics::PortProvider|.
67 mach_port_t TaskForPid(base::ProcessHandle process) const override; 83 mach_port_t TaskForPid(base::ProcessHandle process) const override;
68 84
69 // Implement |BrowserChildProcessObserver|. 85 // Implement |BrowserChildProcessObserver|.
70 void BrowserChildProcessHostDisconnected( 86 void BrowserChildProcessHostDisconnected(
71 const ChildProcessData& data) override; 87 const ChildProcessData& data) override;
72 void BrowserChildProcessCrashed(const ChildProcessData& data, 88 void BrowserChildProcessCrashed(const ChildProcessData& data,
73 int exit_code) override; 89 int exit_code) override;
74 90
(...skipping 12 matching lines...) Expand all
87 103
88 // Updates the mapping for |pid| to include the given |mach_info|. Does 104 // Updates the mapping for |pid| to include the given |mach_info|. Does
89 // nothing if PlaceholderForPid() has not already been called for the given 105 // nothing if PlaceholderForPid() has not already been called for the given
90 // |pid|. Callers MUST acquire the lock given by GetLock() before calling 106 // |pid|. Callers MUST acquire the lock given by GetLock() before calling
91 // this method (and release the lock afterwards). 107 // this method (and release the lock afterwards).
92 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port); 108 void FinalizePid(base::ProcessHandle pid, mach_port_t task_port);
93 109
94 // Removes all mappings belonging to |child_process_id| from the broker. 110 // Removes all mappings belonging to |child_process_id| from the broker.
95 void InvalidateChildProcessId(int child_process_id); 111 void InvalidateChildProcessId(int child_process_id);
96 112
97 // Returns the Mach port name to use when sending or receiving messages. 113 // Register an IO surface for use in child process with |client_id|.
98 // Does the Right Thing in the browser and in child processes. 114 // Callers MUST acquire the lock given by GetLock() before calling this
99 static std::string GetMachPortName(); 115 // method (and release the lock afterwards).
116 bool RegisterIOSurface(base::ProcessHandle pid,
117 int io_surface_id,
118 int client_id,
119 mach_port_t io_surface_port);
120
121 // Unregister an IO surface. Callers MUST acquire the lock given by GetLock()
122 // before calling this method (and release the lock afterwards).
123 void UnregisterIOSurface(base::ProcessHandle pid,
124 int io_surface_id,
125 int client_id);
126
127 // Acquire IO surface reference for a registered IO surface. This will
128 // only succeed if the IO surface is registered for use in |pid|. Callers
129 // MUST acquire the lock given by GetLock() before calling this method
130 // (and release the lock afterwards). Returns MACH_PORT_NULL on failure.
131 mach_port_t AcquireIOSurface(base::ProcessHandle pid, int io_surface_id);
132
100 // Callback used to register notifications on the UI thread. 133 // Callback used to register notifications on the UI thread.
101 void RegisterNotifications(); 134 void RegisterNotifications();
102 135
103 // True if the listener thread has been started. 136 // True if the listener thread has been started.
104 bool listener_thread_started_; 137 bool listener_thread_started_;
105 138
106 // Used to register for notifications received by NotificationObserver. 139 // Used to register for notifications received by NotificationObserver.
107 // Accessed only on the UI thread. 140 // Accessed only on the UI thread.
108 NotificationRegistrar registrar_; 141 NotificationRegistrar registrar_;
109 142
110 // Stores mach info for every process in the broker. 143 // Stores mach info for every process in the broker.
111 typedef std::map<base::ProcessHandle, mach_port_t> MachMap; 144 struct MachPortSet {
145 MachPortSet();
146 explicit MachPortSet(bool is_gpu_process);
147 ~MachPortSet();
148
149 bool is_gpu_process;
150 mach_port_t task_port;
151 std::map<int, mach_port_t> io_surface_ports;
152 };
153 typedef std::map<base::ProcessHandle, MachPortSet> MachMap;
112 MachMap mach_map_; 154 MachMap mach_map_;
113 155
114 // Stores the Child process unique id (RenderProcessHost ID) for every 156 // Stores the Child process unique id (RenderProcessHost ID) for every
115 // process. 157 // process.
116 typedef std::map<int, base::ProcessHandle> ChildProcessIdMap; 158 typedef std::map<int, base::ProcessHandle> ChildProcessIdMap;
117 ChildProcessIdMap child_process_id_map_; 159 ChildProcessIdMap child_process_id_map_;
118 160
119 // Mutex that guards |mach_map_| and |child_process_id_map_|. 161 // Mutex that guards |mach_map_| and |child_process_id_map_|.
120 mutable base::Lock lock_; 162 mutable base::Lock lock_;
121 163
122 DISALLOW_COPY_AND_ASSIGN(MachBroker); 164 DISALLOW_COPY_AND_ASSIGN(MachBroker);
123 }; 165 };
124 166
125 } // namespace content 167 } // namespace content
126 168
127 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_ 169 #endif // CONTENT_BROWSER_MACH_BROKER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698