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

Side by Side Diff: ppapi/proxy/ppb_audio_proxy.cc

Issue 6580050: Factor fd sharing code in proxy and fix fd issues once and for all. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/proxy/ppb_audio_proxy.h" 5 #include "ppapi/proxy/ppb_audio_proxy.h"
6 6
7 #include "base/threading/simple_thread.h" 7 #include "base/threading/simple_thread.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_audio.h" 9 #include "ppapi/c/ppb_audio.h"
10 #include "ppapi/c/trusted/ppb_audio_trusted.h" 10 #include "ppapi/c/trusted/ppb_audio_trusted.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 &GetCurrentConfiguration, 122 &GetCurrentConfiguration,
123 &StartPlayback, 123 &StartPlayback,
124 &StopPlayback 124 &StopPlayback
125 }; 125 };
126 126
127 InterfaceProxy* CreateAudioProxy(Dispatcher* dispatcher, 127 InterfaceProxy* CreateAudioProxy(Dispatcher* dispatcher,
128 const void* target_interface) { 128 const void* target_interface) {
129 return new PPB_Audio_Proxy(dispatcher, target_interface); 129 return new PPB_Audio_Proxy(dispatcher, target_interface);
130 } 130 }
131 131
132 base::PlatformFile IntToPlatformFile(int32_t handle) {
133 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle,
134 // those casts are ugly.
135 #if defined(OS_WIN)
136 return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle));
137 #elif defined(OS_POSIX)
138 return handle;
139 #else
140 #error Not implemented.
141 #endif
142 }
143
132 } // namespace 144 } // namespace
133 145
134 PPB_Audio_Proxy::PPB_Audio_Proxy(Dispatcher* dispatcher, 146 PPB_Audio_Proxy::PPB_Audio_Proxy(Dispatcher* dispatcher,
135 const void* target_interface) 147 const void* target_interface)
136 : InterfaceProxy(dispatcher, target_interface), 148 : InterfaceProxy(dispatcher, target_interface),
137 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 149 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
138 } 150 }
139 151
140 PPB_Audio_Proxy::~PPB_Audio_Proxy() { 152 PPB_Audio_Proxy::~PPB_Audio_Proxy() {
141 } 153 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 231 }
220 object->SetStreamInfo( 232 object->SetStreamInfo(
221 handle, length, IPC::PlatformFileForTransitToPlatformFile(socket_handle)); 233 handle, length, IPC::PlatformFileForTransitToPlatformFile(socket_handle));
222 } 234 }
223 235
224 void PPB_Audio_Proxy::AudioChannelConnected( 236 void PPB_Audio_Proxy::AudioChannelConnected(
225 int32_t result, 237 int32_t result,
226 const HostResource& resource) { 238 const HostResource& resource) {
227 IPC::PlatformFileForTransit socket_handle = 239 IPC::PlatformFileForTransit socket_handle =
228 IPC::InvalidPlatformFileForTransit(); 240 IPC::InvalidPlatformFileForTransit();
229 #if defined(OS_WIN) 241 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit();
230 base::SharedMemoryHandle shared_memory = NULL;
231 #elif defined(OS_POSIX)
232 base::SharedMemoryHandle shared_memory(-1, false);
233 #else
234 #error Not implemented.
235 #endif
236 uint32_t shared_memory_length = 0; 242 uint32_t shared_memory_length = 0;
237 243
238 int32_t result_code = result; 244 int32_t result_code = result;
239 if (result_code == PP_OK) { 245 if (result_code == PP_OK) {
240 result_code = GetAudioConnectedHandles(resource, &socket_handle, 246 result_code = GetAudioConnectedHandles(resource, &socket_handle,
241 &shared_memory, 247 &shared_memory,
242 &shared_memory_length); 248 &shared_memory_length);
243 } 249 }
244 250
245 // Send all the values, even on error. This simplifies some of our cleanup 251 // Send all the values, even on error. This simplifies some of our cleanup
(...skipping 18 matching lines...) Expand all
264 if (!audio_trusted) 270 if (!audio_trusted)
265 return PP_ERROR_NOINTERFACE; 271 return PP_ERROR_NOINTERFACE;
266 272
267 // Get the socket handle for signaling. 273 // Get the socket handle for signaling.
268 int32_t socket_handle; 274 int32_t socket_handle;
269 int32_t result = audio_trusted->GetSyncSocket(resource.host_resource(), 275 int32_t result = audio_trusted->GetSyncSocket(resource.host_resource(),
270 &socket_handle); 276 &socket_handle);
271 if (result != PP_OK) 277 if (result != PP_OK)
272 return result; 278 return result;
273 279
274 #if defined(OS_WIN) 280 *foreign_socket_handle = dispatcher()->ShareHandleWithRemote(
viettrungluu 2011/02/25 01:25:03 Could you add a comment that the handle doesn't be
275 // On Windows, duplicate the socket into the plugin process, this will 281 IntToPlatformFile(socket_handle), false);
276 // automatically close the source handle. 282 if (*foreign_socket_handle == IPC::InvalidPlatformFileForTransit())
277 ::DuplicateHandle( 283 return PP_ERROR_FAILED;
278 GetCurrentProcess(),
279 reinterpret_cast<HANDLE>(static_cast<intptr_t>(socket_handle)),
280 dispatcher()->remote_process_handle(), foreign_socket_handle,
281 STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE,
282 FALSE, DUPLICATE_CLOSE_SOURCE);
283 #else
284 // On Posix, the socket handle will be auto-duplicated when we send the
285 // FileDescriptor. Don't set AutoClose since this is not our handle.
286 *foreign_socket_handle = base::FileDescriptor(socket_handle, false);
287 #endif
288 284
289 // Get the shared memory for the buffer. 285 // Get the shared memory for the buffer.
290 // TODO(brettw) remove the reinterpret cast when the interface is updated.
291 int shared_memory_handle; 286 int shared_memory_handle;
292 result = audio_trusted->GetSharedMemory(resource.host_resource(), 287 result = audio_trusted->GetSharedMemory(resource.host_resource(),
293 &shared_memory_handle, 288 &shared_memory_handle,
294 shared_memory_length); 289 shared_memory_length);
295 if (result != PP_OK) 290 if (result != PP_OK)
296 return result; 291 return result;
297 292
298 base::SharedMemory shared_memory( 293 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote(
299 #if defined(OS_WIN) 294 IntToPlatformFile(shared_memory_handle), false);
300 reinterpret_cast<HANDLE>(static_cast<intptr_t>(shared_memory_handle)), 295 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit())
301 #else
302 base::FileDescriptor(shared_memory_handle, false),
303 #endif
304 false);
305
306 // Duplicate the shared memory to the plugin process. This will automatically
307 // close the source handle.
308 if (!shared_memory.GiveToProcess(dispatcher()->remote_process_handle(),
309 foreign_shared_memory_handle))
310 return PP_ERROR_FAILED; 296 return PP_ERROR_FAILED;
311 297
312 return PP_OK; 298 return PP_OK;
313 } 299 }
314 300
315 } // namespace proxy 301 } // namespace proxy
316 } // namespace pp 302 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698