diff options
author | burnik <burnik@chromium.org> | 2014-09-07 23:58:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-08 07:10:25 +0000 |
commit | 3d67005036e98d91a329e5f70dbc4f1ddb27a1ab (patch) | |
tree | 6da0575c5699e1b8f8f3451c3acfa08b26f3291a /media/audio | |
parent | 4189453237c2ef570d07e132c72b171664a19e51 (diff) | |
download | chromium_src-3d67005036e98d91a329e5f70dbc4f1ddb27a1ab.zip chromium_src-3d67005036e98d91a329e5f70dbc4f1ddb27a1ab.tar.gz chromium_src-3d67005036e98d91a329e5f70dbc4f1ddb27a1ab.tar.bz2 |
Preparing |SyncSocket|'s handle for the peer process is different for POSIX and Windows
which leads to code duplication, platform #ifdef checks on multiple levels and
general confusion on how to work with the SyncSocket.
Typical use case for |SyncSocket|:
1. Browser creates and connects the socket pair - one for browser and one for renderer.
2. Browser prepares the foreign socket (Windows duplicates, POSIX creates file descriptor).
3. Browser relays the foreign socket handle to the renderer via IPC.
4. Renderer receives the IPC and creates the socket using the handle provided.
5. Sockets are ready for send/receive on both ends.
Steps 1-4 get simplified since there is no need to check the platform in order to prepare the socket for transit.
What this CL brings:
1. Adds |SyncSocket::TransitDescriptor| type which wraps the socket handle and is cross-platform.
2. Adds |SyncSocket::PrepareTransitDescriptor| method which is implemented depending on the platform.
3. Adds |SyncSocket::UnwrapHandle| method which unwraps |SyncSocket::Handle| from |SyncSocket::TransitDescriptor|.
4. Removes #ifdefs for platform-checks in code using |SyncSocket| and simplifies preparing the SyncSocket.
Note:
- There is still some less evident duplication in the ppapi and pepper-broker code which should be addressed.
- SyncSocket unit test should also be reviewed.
- There is a similar pattern when using SharedMemory.
BUG=409656
Review URL: https://codereview.chromium.org/525313002
Cr-Commit-Position: refs/heads/master@{#293680}
Diffstat (limited to 'media/audio')
-rw-r--r-- | media/audio/audio_output_device_unittest.cc | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/media/audio/audio_output_device_unittest.cc b/media/audio/audio_output_device_unittest.cc index 0e1fd1e5..363ee38 100644 --- a/media/audio/audio_output_device_unittest.cc +++ b/media/audio/audio_output_device_unittest.cc @@ -54,25 +54,6 @@ class MockAudioOutputIPC : public AudioOutputIPC { MOCK_METHOD1(SetVolume, void(double volume)); }; -// Creates a copy of a SyncSocket handle that we can give to AudioOutputDevice. -// On Windows this means duplicating the pipe handle so that AudioOutputDevice -// can call CloseHandle() (since ownership has been transferred), but on other -// platforms, we just copy the same socket handle since AudioOutputDevice on -// those platforms won't actually own the socket (FileDescriptor.auto_close is -// false). -bool DuplicateSocketHandle(SyncSocket::Handle socket_handle, - SyncSocket::Handle* copy) { -#if defined(OS_WIN) - HANDLE process = GetCurrentProcess(); - ::DuplicateHandle(process, socket_handle, process, copy, - 0, FALSE, DUPLICATE_SAME_ACCESS); - return *copy != NULL; -#else - *copy = socket_handle; - return *copy != -1; -#endif -} - ACTION_P2(SendPendingBytes, socket, pending_bytes) { socket->Send(&pending_bytes, sizeof(pending_bytes)); } @@ -120,7 +101,7 @@ class AudioOutputDeviceTest int AudioOutputDeviceTest::CalculateMemorySize() { // Calculate output memory size. - return AudioBus::CalculateMemorySize(default_audio_parameters_); + return AudioBus::CalculateMemorySize(default_audio_parameters_); } AudioOutputDeviceTest::AudioOutputDeviceTest() { @@ -163,15 +144,16 @@ void AudioOutputDeviceTest::CreateStream() { // Create duplicates of the handles we pass to AudioOutputDevice since // ownership will be transferred and AudioOutputDevice is responsible for // freeing. - SyncSocket::Handle audio_device_socket = SyncSocket::kInvalidHandle; - ASSERT_TRUE(DuplicateSocketHandle(renderer_socket_.handle(), - &audio_device_socket)); + SyncSocket::TransitDescriptor audio_device_socket_descriptor; + ASSERT_TRUE(renderer_socket_.PrepareTransitDescriptor( + base::GetCurrentProcessHandle(), &audio_device_socket_descriptor)); base::SharedMemoryHandle duplicated_memory_handle; ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(), &duplicated_memory_handle)); - audio_device_->OnStreamCreated(duplicated_memory_handle, audio_device_socket, - kMemorySize); + audio_device_->OnStreamCreated( + duplicated_memory_handle, + SyncSocket::UnwrapHandle(audio_device_socket_descriptor), kMemorySize); io_loop_.RunUntilIdle(); } |