Chromium Code Reviews| Index: content/renderer/pepper/pepper_platform_audio_input_impl.cc |
| =================================================================== |
| --- content/renderer/pepper/pepper_platform_audio_input_impl.cc (revision 185810) |
| +++ content/renderer/pepper/pepper_platform_audio_input_impl.cc (working copy) |
| @@ -64,17 +64,10 @@ |
| } |
| void PepperPlatformAudioInputImpl::OnStreamCreated( |
| - base::SharedMemoryHandle handle, |
| base::SyncSocket::Handle socket_handle, |
| - int length) { |
| -#if defined(OS_WIN) |
| - DCHECK(handle); |
| - DCHECK(socket_handle); |
| -#else |
| - DCHECK_NE(-1, handle.fd); |
| - DCHECK_NE(-1, socket_handle); |
| -#endif |
| - DCHECK(length); |
| + int total_handles) { |
| + DCHECK_NE(socket_handle, base::SyncSocket::kInvalidHandle); |
| + DCHECK_EQ(total_handles, 1); |
| if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { |
| // No need to check |shutdown_called_| here. If shutdown has occurred, |
| @@ -83,15 +76,42 @@ |
| main_message_loop_proxy_->PostTask( |
| FROM_HERE, |
| base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this, |
| - handle, socket_handle, length)); |
| + socket_handle, total_handles)); |
| } else { |
| // Must dereference the client only on the main thread. Shutdown may have |
| // occurred while the request was in-flight, so we need to NULL check. |
| if (client_) { |
| - client_->StreamCreated(handle, length, socket_handle); |
| + socket_handle_ = socket_handle; |
| } else { |
| // Clean up the handles. |
| base::SyncSocket temp_socket(socket_handle); |
| + } |
| + } |
| +} |
| + |
| +void PepperPlatformAudioInputImpl::OnSharedMemoryCreated( |
| + base::SharedMemoryHandle handle, |
| + int length, |
| + int index) { |
| + DCHECK(base::SharedMemory::IsHandleValid(handle)); |
| + DCHECK(length); |
| + DCHECK_NE(socket_handle_, base::SyncSocket::kInvalidHandle); |
| + |
| + if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { |
|
miu
2013/03/05 04:58:55
Please don't duplicate code. It makes everything
|
| + // No need to check |shutdown_called_| here. If shutdown has occurred, |
| + // |client_| will be NULL and the handles will be cleaned up on the main |
| + // thread. |
| + main_message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&PepperPlatformAudioInputImpl::OnSharedMemoryCreated, this, |
| + handle, length, index)); |
| + } else { |
| + // Must dereference the client only on the main thread. Shutdown may have |
| + // occurred while the request was in-flight, so we need to NULL check. |
| + if (client_) { |
| + client_->StreamCreated(handle, length, socket_handle_); |
| + } else { |
| + // Clean up the handles. |
| base::SharedMemory temp_shared_memory(handle, false); |
| } |
| } |
| @@ -117,7 +137,7 @@ |
| this)); |
| } else { |
| // We will be notified by OnStreamCreated(). |
| - ipc_->CreateStream(stream_id_, params_, device_id, false); |
| + ipc_->CreateStream(stream_id_, params_, device_id, false, 1); |
| } |
| } |
| @@ -139,6 +159,7 @@ |
| PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl() |
| : client_(NULL), |
| + socket_handle_(base::SyncSocket::kInvalidHandle), |
| stream_id_(0), |
| render_view_id_(MSG_ROUTING_NONE), |
| main_message_loop_proxy_(base::MessageLoopProxy::current()), |
| @@ -196,7 +217,7 @@ |
| if (!session_id) { |
| // We will be notified by OnStreamCreated(). |
| ipc_->CreateStream(stream_id_, params_, |
| - media::AudioManagerBase::kDefaultDeviceId, false); |
| + media::AudioManagerBase::kDefaultDeviceId, false, 1); |
| } else { |
| // We will be notified by OnDeviceReady(). |
| ipc_->StartDevice(stream_id_, session_id); |