OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "content/browser/browser_io_surface_manager_mac.h" | 5 #include "content/browser/browser_io_surface_manager_mac.h" |
6 | 6 |
7 #include <servers/bootstrap.h> | 7 #include <servers/bootstrap.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 } | 192 } |
193 | 193 |
194 union { | 194 union { |
195 mach_msg_header_t header; | 195 mach_msg_header_t header; |
196 IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface; | 196 IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface; |
197 IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface; | 197 IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface; |
198 } reply = {{0}}; | 198 } reply = {{0}}; |
199 | 199 |
200 switch (request.msg.header.msgh_id) { | 200 switch (request.msg.header.msgh_id) { |
201 case IOSurfaceManagerHostMsg_RegisterIOSurface::ID: | 201 case IOSurfaceManagerHostMsg_RegisterIOSurface::ID: |
202 if (!HandleRegisterIOSurfaceRequest(request.msg.register_io_surface, | 202 HandleRegisterIOSurfaceRequest(request.msg.register_io_surface, |
203 &reply.register_io_surface)) { | 203 &reply.register_io_surface); |
204 return; | |
205 } | |
206 break; | 204 break; |
207 case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID: | 205 case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID: |
208 HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface); | 206 HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface, |
207 NULL); | |
Avi (use Gerrit)
2015/09/17 15:12:30
nullptr
ccameron
2015/09/17 18:35:05
Done.
| |
209 // Unregister requests are asynchronous and do not require a reply as | 208 // Unregister requests are asynchronous and do not require a reply as |
210 // there is no guarantee for how quickly an IO surface is removed from | 209 // there is no guarantee for how quickly an IO surface is removed from |
211 // the IOSurfaceManager instance after it has been deleted by a child | 210 // the IOSurfaceManager instance after it has been deleted by a child |
212 // process. | 211 // process. |
213 return; | 212 return; |
214 case IOSurfaceManagerHostMsg_AcquireIOSurface::ID: | 213 case IOSurfaceManagerHostMsg_AcquireIOSurface::ID: |
215 if (!HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface, | 214 HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface, |
216 &reply.acquire_io_surface)) { | 215 &reply.acquire_io_surface); |
217 return; | |
218 } | |
219 break; | 216 break; |
220 default: | 217 default: |
221 LOG(ERROR) << "Unknown message received!"; | 218 LOG(ERROR) << "Unknown message received!"; |
222 return; | 219 return; |
223 } | 220 } |
224 | 221 |
225 kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, | 222 kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, |
226 reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs, | 223 reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs, |
227 MACH_PORT_NULL); | 224 MACH_PORT_NULL); |
228 if (kr != KERN_SUCCESS) { | 225 if (kr != KERN_SUCCESS) { |
229 MACH_LOG(ERROR, kr) << "mach_msg"; | 226 MACH_LOG(ERROR, kr) << "mach_msg"; |
230 } | 227 } |
231 } | 228 } |
232 | 229 |
233 bool BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest( | 230 void BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest( |
234 const IOSurfaceManagerHostMsg_RegisterIOSurface& request, | 231 const IOSurfaceManagerHostMsg_RegisterIOSurface& request, |
235 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { | 232 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { |
236 base::AutoLock lock(lock_); | 233 base::AutoLock lock(lock_); |
237 | 234 |
238 IOSurfaceManagerToken token; | 235 IOSurfaceManagerToken token; |
239 static_assert(sizeof(request.token_name) == sizeof(token.name), | 236 static_assert(sizeof(request.token_name) == sizeof(token.name), |
240 "Mach message token size doesn't match expectation."); | 237 "Mach message token size doesn't match expectation."); |
241 token.SetName(request.token_name); | 238 token.SetName(request.token_name); |
242 if (token.IsZero() || token != gpu_process_token_) { | 239 if (token.IsZero() || token != gpu_process_token_) { |
243 LOG(ERROR) << "Illegal message from non-GPU process!"; | 240 LOG(ERROR) << "Illegal message from non-GPU process!"; |
244 return false; | 241 return; |
reveman
2015/09/17 03:58:22
don't we have to set some of the reply fields in t
ccameron
2015/09/17 18:35:05
This gets called from HandleRequest, which sets th
| |
245 } | 242 } |
246 | 243 |
247 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); | 244 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); |
248 io_surfaces_.add(key, make_scoped_ptr(new base::mac::ScopedMachSendRight( | 245 io_surfaces_.add(key, make_scoped_ptr(new base::mac::ScopedMachSendRight( |
249 request.io_surface_port.name))); | 246 request.io_surface_port.name))); |
250 | 247 |
251 reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits); | 248 reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits); |
252 reply->header.msgh_remote_port = request.header.msgh_remote_port; | 249 reply->header.msgh_remote_port = request.header.msgh_remote_port; |
253 reply->header.msgh_size = sizeof(*reply); | 250 reply->header.msgh_size = sizeof(*reply); |
254 reply->result = true; | 251 reply->result = true; |
255 return true; | |
256 } | 252 } |
257 | 253 |
258 bool BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest( | 254 void BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest( |
259 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) { | 255 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request, |
256 bool* result) { | |
260 base::AutoLock lock(lock_); | 257 base::AutoLock lock(lock_); |
261 | 258 |
262 IOSurfaceManagerToken token; | 259 IOSurfaceManagerToken token; |
263 static_assert(sizeof(request.token_name) == sizeof(token.name), | 260 static_assert(sizeof(request.token_name) == sizeof(token.name), |
264 "Mach message token size doesn't match expectation."); | 261 "Mach message token size doesn't match expectation."); |
265 token.SetName(request.token_name); | 262 token.SetName(request.token_name); |
266 if (token.IsZero() || token != gpu_process_token_) { | 263 if (token.IsZero() || token != gpu_process_token_) { |
267 LOG(ERROR) << "Illegal message from non-GPU process!"; | 264 LOG(ERROR) << "Illegal message from non-GPU process!"; |
268 return false; | 265 if (result) |
266 *result = false; | |
267 return; | |
269 } | 268 } |
270 | 269 |
271 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); | 270 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); |
272 io_surfaces_.erase(key); | 271 io_surfaces_.erase(key); |
273 return true; | 272 if (result) |
273 *result = true; | |
274 } | 274 } |
275 | 275 |
276 bool BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest( | 276 void BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest( |
277 const IOSurfaceManagerHostMsg_AcquireIOSurface& request, | 277 const IOSurfaceManagerHostMsg_AcquireIOSurface& request, |
278 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { | 278 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { |
279 base::AutoLock lock(lock_); | 279 base::AutoLock lock(lock_); |
280 | 280 |
281 IOSurfaceManagerToken token; | 281 IOSurfaceManagerToken token; |
282 static_assert(sizeof(request.token_name) == sizeof(token.name), | 282 static_assert(sizeof(request.token_name) == sizeof(token.name), |
283 "Mach message token size doesn't match expectation."); | 283 "Mach message token size doesn't match expectation."); |
284 token.SetName(request.token_name); | 284 token.SetName(request.token_name); |
285 auto child_process_id_it = child_process_ids_.find(token); | 285 auto child_process_id_it = child_process_ids_.find(token); |
286 if (child_process_id_it == child_process_ids_.end()) { | 286 if (child_process_id_it == child_process_ids_.end()) { |
287 LOG(ERROR) << "Illegal message from non-child process!"; | 287 LOG(ERROR) << "Illegal message from non-child process!"; |
288 return false; | 288 return; |
reveman
2015/09/17 03:58:22
Same here. Don't we have some set some reply field
ccameron
2015/09/17 18:35:05
Done.
| |
289 } | 289 } |
290 | 290 |
291 reply->header.msgh_bits = | 291 reply->header.msgh_bits = |
292 MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX; | 292 MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX; |
293 reply->header.msgh_remote_port = request.header.msgh_remote_port; | 293 reply->header.msgh_remote_port = request.header.msgh_remote_port; |
294 reply->header.msgh_size = sizeof(*reply); | 294 reply->header.msgh_size = sizeof(*reply); |
295 reply->result = true; | |
295 | 296 |
296 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), | 297 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), |
297 child_process_id_it->second); | 298 child_process_id_it->second); |
298 auto it = io_surfaces_.find(key); | 299 auto it = io_surfaces_.find(key); |
299 if (it == io_surfaces_.end()) { | 300 if (it == io_surfaces_.end()) { |
300 LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id; | 301 LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id; |
301 return true; | 302 return; |
302 } | 303 } |
303 | 304 |
304 reply->body.msgh_descriptor_count = 1; | 305 reply->body.msgh_descriptor_count = 1; |
305 reply->io_surface_port.name = it->second->get(); | 306 reply->io_surface_port.name = it->second->get(); |
306 reply->io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; | 307 reply->io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; |
307 reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; | 308 reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; |
308 return true; | |
309 } | 309 } |
310 | 310 |
311 } // namespace content | 311 } // namespace content |
OLD | NEW |