OLD | NEW |
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 #include "ppapi/proxy/ppb_audio_input_proxy.h" | 5 #include "ppapi/proxy/ppb_audio_input_proxy.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "ppapi/c/dev/ppb_audio_input_dev.h" | 8 #include "ppapi/c/dev/ppb_audio_input_dev.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/ppb_audio_config.h" | 10 #include "ppapi/c/ppb_audio_config.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); | 279 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); |
280 if (enter.succeeded()) { | 280 if (enter.succeeded()) { |
281 static_cast<AudioInput*>(enter.object())->OnEnumerateDevicesComplete( | 281 static_cast<AudioInput*>(enter.object())->OnEnumerateDevicesComplete( |
282 result, devices); | 282 result, devices); |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 void PPB_AudioInput_Proxy::OnMsgOpenACK( | 286 void PPB_AudioInput_Proxy::OnMsgOpenACK( |
287 const HostResource& audio_input, | 287 const HostResource& audio_input, |
288 int32_t result, | 288 int32_t result, |
289 IPC::PlatformFileForTransit socket_handle, | 289 const ppapi::proxy::SerializedHandle& socket_handle, |
290 base::SharedMemoryHandle handle, | 290 const ppapi::proxy::SerializedHandle& handle) { |
291 uint32_t length) { | 291 CHECK(socket_handle.is_socket()); |
| 292 CHECK(handle.is_shmem()); |
292 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); | 293 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); |
293 if (enter.failed()) { | 294 if (enter.failed()) { |
294 // The caller may still have given us these handles in the failure case. | 295 // The caller may still have given us these handles in the failure case. |
295 // The easiest way to clean these up is to just put them in the objects | 296 // The easiest way to clean these up is to just put them in the objects |
296 // and then close them. This failure case is not performance critical. | 297 // and then close them. This failure case is not performance critical. |
297 base::SyncSocket temp_socket( | 298 base::SyncSocket temp_socket( |
298 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | 299 IPC::PlatformFileForTransitToPlatformFile( |
299 base::SharedMemory temp_mem(handle, false); | 300 socket_handle.descriptor())); |
| 301 base::SharedMemory temp_mem(handle.shmem(), false); |
300 } else { | 302 } else { |
301 static_cast<AudioInput*>(enter.object())->OnOpenComplete( | 303 static_cast<AudioInput*>(enter.object())->OnOpenComplete( |
302 result, handle, length, | 304 result, handle.shmem(), handle.size(), |
303 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | 305 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor())); |
304 } | 306 } |
305 } | 307 } |
306 | 308 |
307 void PPB_AudioInput_Proxy::EnumerateDevicesACKInHost( | 309 void PPB_AudioInput_Proxy::EnumerateDevicesACKInHost( |
308 int32_t result, | 310 int32_t result, |
309 const HostResource& audio_input) { | 311 const HostResource& audio_input) { |
310 EnterHostFromHostResource<PPB_AudioInput_API> enter(audio_input); | 312 EnterHostFromHostResource<PPB_AudioInput_API> enter(audio_input); |
311 dispatcher()->Send(new PpapiMsg_PPBAudioInput_EnumerateDevicesACK( | 313 dispatcher()->Send(new PpapiMsg_PPBAudioInput_EnumerateDevicesACK( |
312 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, | 314 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, |
313 enter.succeeded() && result == PP_OK ? | 315 enter.succeeded() && result == PP_OK ? |
314 enter.object()->GetDeviceRefData() : std::vector<DeviceRefData>())); | 316 enter.object()->GetDeviceRefData() : std::vector<DeviceRefData>())); |
315 } | 317 } |
316 | 318 |
317 void PPB_AudioInput_Proxy::OpenACKInHost(int32_t result, | 319 void PPB_AudioInput_Proxy::OpenACKInHost(int32_t result, |
318 const HostResource& audio_input) { | 320 const HostResource& audio_input) { |
319 IPC::PlatformFileForTransit socket_handle = | 321 ppapi::proxy::SerializedHandle socket_handle( |
320 IPC::InvalidPlatformFileForTransit(); | 322 ppapi::proxy::SerializedHandle::SOCKET); |
321 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); | 323 ppapi::proxy::SerializedHandle shared_memory( |
322 uint32_t shared_memory_length = 0; | 324 ppapi::proxy::SerializedHandle::SHARED_MEMORY); |
323 | 325 |
324 if (result == PP_OK) { | 326 if (result == PP_OK) { |
325 result = GetAudioInputConnectedHandles(audio_input, &socket_handle, | 327 IPC::PlatformFileForTransit temp_socket; |
326 &shared_memory, | 328 base::SharedMemoryHandle temp_shmem; |
327 &shared_memory_length); | 329 uint32_t temp_size; |
| 330 result = GetAudioInputConnectedHandles(audio_input, &temp_socket, |
| 331 &temp_shmem, &temp_size); |
| 332 if (result == PP_OK) { |
| 333 socket_handle.set_socket(temp_socket); |
| 334 shared_memory.set_shmem(temp_shmem, temp_size); |
| 335 } |
328 } | 336 } |
329 | 337 |
330 // Send all the values, even on error. This simplifies some of our cleanup | 338 // Send all the values, even on error. This simplifies some of our cleanup |
331 // code since the handles will be in the other process and could be | 339 // code since the handles will be in the other process and could be |
332 // inconvenient to clean up. Our IPC code will automatically handle this for | 340 // inconvenient to clean up. Our IPC code will automatically handle this for |
333 // us, as long as the remote side always closes the handles it receives | 341 // us, as long as the remote side always closes the handles it receives |
334 // (in OnMsgOpenACK), even in the failure case. | 342 // (in OnMsgOpenACK), even in the failure case. |
335 dispatcher()->Send(new PpapiMsg_PPBAudioInput_OpenACK( | 343 dispatcher()->Send(new PpapiMsg_PPBAudioInput_OpenACK( |
336 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, socket_handle, | 344 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, socket_handle, |
337 shared_memory, shared_memory_length)); | 345 shared_memory)); |
338 } | 346 } |
339 | 347 |
340 int32_t PPB_AudioInput_Proxy::GetAudioInputConnectedHandles( | 348 int32_t PPB_AudioInput_Proxy::GetAudioInputConnectedHandles( |
341 const HostResource& resource, | 349 const HostResource& resource, |
342 IPC::PlatformFileForTransit* foreign_socket_handle, | 350 IPC::PlatformFileForTransit* foreign_socket_handle, |
343 base::SharedMemoryHandle* foreign_shared_memory_handle, | 351 base::SharedMemoryHandle* foreign_shared_memory_handle, |
344 uint32_t* shared_memory_length) { | 352 uint32_t* shared_memory_length) { |
345 // Get the audio interface which will give us the handles. | 353 // Get the audio interface which will give us the handles. |
346 EnterHostFromHostResource<PPB_AudioInput_API> enter(resource); | 354 EnterHostFromHostResource<PPB_AudioInput_API> enter(resource); |
347 if (enter.failed()) | 355 if (enter.failed()) |
(...skipping 22 matching lines...) Expand all Loading... |
370 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( | 378 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
371 IntToPlatformFile(shared_memory_handle), false); | 379 IntToPlatformFile(shared_memory_handle), false); |
372 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 380 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
373 return PP_ERROR_FAILED; | 381 return PP_ERROR_FAILED; |
374 | 382 |
375 return PP_OK; | 383 return PP_OK; |
376 } | 384 } |
377 | 385 |
378 } // namespace proxy | 386 } // namespace proxy |
379 } // namespace ppapi | 387 } // namespace ppapi |
OLD | NEW |