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

Side by Side Diff: content/browser/browser_io_surface_manager_mac.cc

Issue 1370963002: Mac: Don't CHECK that AcquireIOSurface succeeds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2490
Patch Set: Created 5 years, 2 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 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 192
193 union { 193 union {
194 mach_msg_header_t header; 194 mach_msg_header_t header;
195 IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface; 195 IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface;
196 IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface; 196 IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface;
197 } reply = {{0}}; 197 } reply = {{0}};
198 198
199 switch (request.msg.header.msgh_id) { 199 switch (request.msg.header.msgh_id) {
200 case IOSurfaceManagerHostMsg_RegisterIOSurface::ID: 200 case IOSurfaceManagerHostMsg_RegisterIOSurface::ID:
201 if (!HandleRegisterIOSurfaceRequest(request.msg.register_io_surface, 201 HandleRegisterIOSurfaceRequest(request.msg.register_io_surface,
202 &reply.register_io_surface)) { 202 &reply.register_io_surface);
203 return;
204 }
205 break; 203 break;
206 case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID: 204 case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID:
207 HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface); 205 HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface);
208 // Unregister requests are asynchronous and do not require a reply as 206 // Unregister requests are asynchronous and do not require a reply as
209 // there is no guarantee for how quickly an IO surface is removed from 207 // there is no guarantee for how quickly an IO surface is removed from
210 // the IOSurfaceManager instance after it has been deleted by a child 208 // the IOSurfaceManager instance after it has been deleted by a child
211 // process. 209 // process.
212 return; 210 return;
213 case IOSurfaceManagerHostMsg_AcquireIOSurface::ID: 211 case IOSurfaceManagerHostMsg_AcquireIOSurface::ID:
214 if (!HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface, 212 HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface,
215 &reply.acquire_io_surface)) { 213 &reply.acquire_io_surface);
216 return;
217 }
218 break; 214 break;
219 default: 215 default:
220 LOG(ERROR) << "Unknown message received!"; 216 LOG(ERROR) << "Unknown message received!";
221 return; 217 return;
222 } 218 }
223 219
224 kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, 220 kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT,
225 reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs, 221 reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs,
226 MACH_PORT_NULL); 222 MACH_PORT_NULL);
227 if (kr != KERN_SUCCESS) { 223 if (kr != KERN_SUCCESS) {
228 MACH_LOG(ERROR, kr) << "mach_msg"; 224 MACH_LOG(ERROR, kr) << "mach_msg";
229 } 225 }
230 } 226 }
231 227
232 bool BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest( 228 void BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest(
233 const IOSurfaceManagerHostMsg_RegisterIOSurface& request, 229 const IOSurfaceManagerHostMsg_RegisterIOSurface& request,
234 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { 230 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) {
235 base::AutoLock lock(lock_); 231 base::AutoLock lock(lock_);
236 232
233 reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits);
234 reply->header.msgh_remote_port = request.header.msgh_remote_port;
235 reply->header.msgh_size = sizeof(*reply);
236 reply->body.msgh_descriptor_count = 0;
237 reply->result = false;
238
237 IOSurfaceManagerToken token; 239 IOSurfaceManagerToken token;
238 static_assert(sizeof(request.token_name) == sizeof(token.name), 240 static_assert(sizeof(request.token_name) == sizeof(token.name),
239 "Mach message token size doesn't match expectation."); 241 "Mach message token size doesn't match expectation.");
240 token.SetName(request.token_name); 242 token.SetName(request.token_name);
241 if (token.IsZero() || token != gpu_process_token_) { 243 if (token.IsZero() || token != gpu_process_token_) {
242 LOG(ERROR) << "Illegal message from non-GPU process!"; 244 LOG(ERROR) << "Illegal message from non-GPU process!";
243 return false; 245 return;
244 } 246 }
245 247
246 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); 248 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id);
247 io_surfaces_.add(key, make_scoped_ptr(new base::mac::ScopedMachSendRight( 249 io_surfaces_.add(key, make_scoped_ptr(new base::mac::ScopedMachSendRight(
248 request.io_surface_port.name))); 250 request.io_surface_port.name)));
249
250 reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits);
251 reply->header.msgh_remote_port = request.header.msgh_remote_port;
252 reply->header.msgh_size = sizeof(*reply);
253 reply->result = true; 251 reply->result = true;
254 return true;
255 } 252 }
256 253
257 bool BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest( 254 bool BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest(
258 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) { 255 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) {
259 base::AutoLock lock(lock_); 256 base::AutoLock lock(lock_);
260 257
261 IOSurfaceManagerToken token; 258 IOSurfaceManagerToken token;
262 static_assert(sizeof(request.token_name) == sizeof(token.name), 259 static_assert(sizeof(request.token_name) == sizeof(token.name),
263 "Mach message token size doesn't match expectation."); 260 "Mach message token size doesn't match expectation.");
264 token.SetName(request.token_name); 261 token.SetName(request.token_name);
265 if (token.IsZero() || token != gpu_process_token_) { 262 if (token.IsZero() || token != gpu_process_token_) {
266 LOG(ERROR) << "Illegal message from non-GPU process!"; 263 LOG(ERROR) << "Illegal message from non-GPU process!";
267 return false; 264 return false;
268 } 265 }
269 266
270 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); 267 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id);
271 io_surfaces_.erase(key); 268 io_surfaces_.erase(key);
272 return true; 269 return true;
273 } 270 }
274 271
275 bool BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest( 272 void BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest(
276 const IOSurfaceManagerHostMsg_AcquireIOSurface& request, 273 const IOSurfaceManagerHostMsg_AcquireIOSurface& request,
277 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { 274 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) {
278 base::AutoLock lock(lock_); 275 base::AutoLock lock(lock_);
279 276
277 reply->header.msgh_bits =
278 MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX;
279 reply->header.msgh_remote_port = request.header.msgh_remote_port;
280 reply->header.msgh_size = sizeof(*reply);
281 reply->body.msgh_descriptor_count = 0;
282 reply->result = false;
283 reply->io_surface_port.name = MACH_PORT_NULL;
284 reply->io_surface_port.disposition = 0;
285 reply->io_surface_port.type = 0;
286
280 IOSurfaceManagerToken token; 287 IOSurfaceManagerToken token;
281 static_assert(sizeof(request.token_name) == sizeof(token.name), 288 static_assert(sizeof(request.token_name) == sizeof(token.name),
282 "Mach message token size doesn't match expectation."); 289 "Mach message token size doesn't match expectation.");
283 token.SetName(request.token_name); 290 token.SetName(request.token_name);
284 auto child_process_id_it = child_process_ids_.find(token); 291 auto child_process_id_it = child_process_ids_.find(token);
285 if (child_process_id_it == child_process_ids_.end()) { 292 if (child_process_id_it == child_process_ids_.end()) {
286 LOG(ERROR) << "Illegal message from non-child process!"; 293 LOG(ERROR) << "Illegal message from non-child process!";
287 return false; 294 return;
288 } 295 }
289 296
290 reply->header.msgh_bits = 297 reply->result = true;
291 MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX;
292 reply->header.msgh_remote_port = request.header.msgh_remote_port;
293 reply->header.msgh_size = sizeof(*reply);
294
295 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), 298 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id),
296 child_process_id_it->second); 299 child_process_id_it->second);
297 auto it = io_surfaces_.find(key); 300 auto it = io_surfaces_.find(key);
298 if (it == io_surfaces_.end()) { 301 if (it == io_surfaces_.end()) {
299 LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id; 302 LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id;
300 return true; 303 return;
301 } 304 }
302 305
303 reply->body.msgh_descriptor_count = 1; 306 reply->body.msgh_descriptor_count = 1;
304 reply->io_surface_port.name = it->second->get(); 307 reply->io_surface_port.name = it->second->get();
305 reply->io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; 308 reply->io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND;
306 reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; 309 reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR;
307 return true;
308 } 310 }
309 311
310 } // namespace content 312 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_io_surface_manager_mac.h ('k') | content/browser/browser_io_surface_manager_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698