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

Side by Side Diff: content/child/child_io_surface_manager_mac.cc

Issue 1411523006: mac: Make Mach port scopers better ScopedGenerics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update 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
« no previous file with comments | « content/browser/mach_broker_mac.mm ('k') | ipc/attachment_broker_mac_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/child/child_io_surface_manager_mac.h" 5 #include "content/child/child_io_surface_manager_mac.h"
6 6
7 #include "base/mac/mach_logging.h" 7 #include "base/mac/mach_logging.h"
8 #include "content/common/mac/io_surface_manager_messages.h" 8 #include "content/common/mac/io_surface_manager_messages.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 27 matching lines...) Expand all
38 union { 38 union {
39 IOSurfaceManagerHostMsg_RegisterIOSurface request; 39 IOSurfaceManagerHostMsg_RegisterIOSurface request;
40 struct { 40 struct {
41 IOSurfaceManagerMsg_RegisterIOSurfaceReply msg; 41 IOSurfaceManagerMsg_RegisterIOSurfaceReply msg;
42 mach_msg_trailer_t trailer; 42 mach_msg_trailer_t trailer;
43 } reply; 43 } reply;
44 } data = {{{0}}}; 44 } data = {{{0}}};
45 data.request.header.msgh_bits = 45 data.request.header.msgh_bits =
46 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE) | 46 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE) |
47 MACH_MSGH_BITS_COMPLEX; 47 MACH_MSGH_BITS_COMPLEX;
48 data.request.header.msgh_remote_port = service_port_; 48 data.request.header.msgh_remote_port = service_port_.get();
49 data.request.header.msgh_local_port = reply_port; 49 data.request.header.msgh_local_port = reply_port;
50 data.request.header.msgh_size = sizeof(data.request); 50 data.request.header.msgh_size = sizeof(data.request);
51 data.request.header.msgh_id = IOSurfaceManagerHostMsg_RegisterIOSurface::ID; 51 data.request.header.msgh_id = IOSurfaceManagerHostMsg_RegisterIOSurface::ID;
52 data.request.body.msgh_descriptor_count = 1; 52 data.request.body.msgh_descriptor_count = 1;
53 data.request.io_surface_port.name = scoped_io_surface_right; 53 data.request.io_surface_port.name = scoped_io_surface_right.get();
54 data.request.io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; 54 data.request.io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND;
55 data.request.io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; 55 data.request.io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR;
56 data.request.io_surface_id = io_surface_id.id; 56 data.request.io_surface_id = io_surface_id.id;
57 data.request.client_id = client_id; 57 data.request.client_id = client_id;
58 memcpy(data.request.token_name, token_.name, sizeof(token_.name)); 58 memcpy(data.request.token_name, token_.name, sizeof(token_.name));
59 59
60 kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG, 60 kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG,
61 sizeof(data.request), sizeof(data.reply), reply_port, 61 sizeof(data.request), sizeof(data.reply), reply_port,
62 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); 62 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
63 if (kr != KERN_SUCCESS) { 63 if (kr != KERN_SUCCESS) {
64 MACH_LOG(ERROR, kr) << "mach_msg"; 64 MACH_LOG(ERROR, kr) << "mach_msg";
65 return false; 65 return false;
66 } 66 }
67 67
68 return data.reply.msg.result; 68 return data.reply.msg.result;
69 } 69 }
70 70
71 void ChildIOSurfaceManager::UnregisterIOSurface(IOSurfaceId io_surface_id, 71 void ChildIOSurfaceManager::UnregisterIOSurface(IOSurfaceId io_surface_id,
72 int client_id) { 72 int client_id) {
73 DCHECK(service_port_.is_valid()); 73 DCHECK(service_port_.is_valid());
74 DCHECK(!token_.IsZero()); 74 DCHECK(!token_.IsZero());
75 75
76 IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}}; 76 IOSurfaceManagerHostMsg_UnregisterIOSurface request = {{0}};
77 request.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0); 77 request.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
78 request.header.msgh_remote_port = service_port_; 78 request.header.msgh_remote_port = service_port_.get();
79 request.header.msgh_local_port = MACH_PORT_NULL; 79 request.header.msgh_local_port = MACH_PORT_NULL;
80 request.header.msgh_size = sizeof(request); 80 request.header.msgh_size = sizeof(request);
81 request.header.msgh_id = IOSurfaceManagerHostMsg_UnregisterIOSurface::ID; 81 request.header.msgh_id = IOSurfaceManagerHostMsg_UnregisterIOSurface::ID;
82 request.io_surface_id = io_surface_id.id; 82 request.io_surface_id = io_surface_id.id;
83 request.client_id = client_id; 83 request.client_id = client_id;
84 memcpy(request.token_name, token_.name, sizeof(token_.name)); 84 memcpy(request.token_name, token_.name, sizeof(token_.name));
85 85
86 kern_return_t kr = 86 kern_return_t kr =
87 mach_msg(&request.header, MACH_SEND_MSG, sizeof(request), 0, 87 mach_msg(&request.header, MACH_SEND_MSG, sizeof(request), 0,
88 MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); 88 MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
(...skipping 18 matching lines...) Expand all
107 107
108 union { 108 union {
109 IOSurfaceManagerHostMsg_AcquireIOSurface request; 109 IOSurfaceManagerHostMsg_AcquireIOSurface request;
110 struct { 110 struct {
111 IOSurfaceManagerMsg_AcquireIOSurfaceReply msg; 111 IOSurfaceManagerMsg_AcquireIOSurfaceReply msg;
112 mach_msg_trailer_t trailer; 112 mach_msg_trailer_t trailer;
113 } reply; 113 } reply;
114 } data = {{{0}}}; 114 } data = {{{0}}};
115 data.request.header.msgh_bits = 115 data.request.header.msgh_bits =
116 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE); 116 MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE);
117 data.request.header.msgh_remote_port = service_port_; 117 data.request.header.msgh_remote_port = service_port_.get();
118 data.request.header.msgh_local_port = reply_port; 118 data.request.header.msgh_local_port = reply_port;
119 data.request.header.msgh_size = sizeof(data.request); 119 data.request.header.msgh_size = sizeof(data.request);
120 data.request.header.msgh_id = IOSurfaceManagerHostMsg_AcquireIOSurface::ID; 120 data.request.header.msgh_id = IOSurfaceManagerHostMsg_AcquireIOSurface::ID;
121 data.request.io_surface_id = io_surface_id.id; 121 data.request.io_surface_id = io_surface_id.id;
122 memcpy(data.request.token_name, token_.name, sizeof(token_.name)); 122 memcpy(data.request.token_name, token_.name, sizeof(token_.name));
123 123
124 kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG, 124 kr = mach_msg(&data.request.header, MACH_SEND_MSG | MACH_RCV_MSG,
125 sizeof(data.request), sizeof(data.reply), reply_port, 125 sizeof(data.request), sizeof(data.reply), reply_port,
126 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); 126 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
127 if (kr != KERN_SUCCESS) { 127 if (kr != KERN_SUCCESS) {
128 MACH_LOG(ERROR, kr) << "mach_msg"; 128 MACH_LOG(ERROR, kr) << "mach_msg";
129 return nullptr; 129 return nullptr;
130 } 130 }
131 if (!data.reply.msg.result) { 131 if (!data.reply.msg.result) {
132 DLOG(ERROR) << "Browser refused AcquireIOSurface request"; 132 DLOG(ERROR) << "Browser refused AcquireIOSurface request";
133 return nullptr; 133 return nullptr;
134 } 134 }
135 135
136 // Deallocate the right after creating an IOSurface reference. 136 // Deallocate the right after creating an IOSurface reference.
137 base::mac::ScopedMachSendRight scoped_io_surface_right( 137 base::mac::ScopedMachSendRight scoped_io_surface_right(
138 data.reply.msg.io_surface_port.name); 138 data.reply.msg.io_surface_port.name);
139 139
140 return IOSurfaceLookupFromMachPort(scoped_io_surface_right); 140 return IOSurfaceLookupFromMachPort(scoped_io_surface_right.get());
141 } 141 }
142 142
143 ChildIOSurfaceManager::ChildIOSurfaceManager() {} 143 ChildIOSurfaceManager::ChildIOSurfaceManager() {}
144 144
145 ChildIOSurfaceManager::~ChildIOSurfaceManager() {} 145 ChildIOSurfaceManager::~ChildIOSurfaceManager() {}
146 146
147 } // namespace content 147 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mach_broker_mac.mm ('k') | ipc/attachment_broker_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698