Commit 6ab73b02 authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

Define base::SyncSocket::Handle in terms of PlatformFile.

This CL also does some general cleanup:
- Adds a ScopedHandle type to simplify resource management.
- Removes vestigial TransitDescriptor passing, which had test-only
  users.
- Fixes a double-close in AudioInputDeviceTest.CreateStream.

Change-Id: I9f7a31baee32336583736c1fbcaa89508a90c127
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050889Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarTommi <tommi@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741085}
parent c0591393
......@@ -552,6 +552,7 @@ jumbo_component("base") {
"strings/utf_string_conversions.h",
"supports_user_data.cc",
"supports_user_data.h",
"sync_socket.cc",
"sync_socket.h",
"synchronization/atomic_flag.cc",
"synchronization/atomic_flag.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/sync_socket.h"
namespace base {
const SyncSocket::Handle SyncSocket::kInvalidHandle = kInvalidPlatformFile;
SyncSocket::SyncSocket() = default;
SyncSocket::SyncSocket(Handle handle) : handle_(handle) {}
SyncSocket::SyncSocket(ScopedHandle handle) : handle_(std::move(handle)) {}
SyncSocket::~SyncSocket() = default;
SyncSocket::ScopedHandle SyncSocket::Take() {
return std::move(handle_);
}
CancelableSyncSocket::CancelableSyncSocket() = default;
CancelableSyncSocket::CancelableSyncSocket(Handle handle)
: SyncSocket(handle) {}
CancelableSyncSocket::CancelableSyncSocket(ScopedHandle handle)
: SyncSocket(std::move(handle)) {}
} // namespace base
......@@ -13,8 +13,8 @@
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/files/platform_file.h"
#include "base/macros.h"
#include "base/process/process_handle.h"
#include "base/synchronization/waitable_event.h"
#include "base/time/time.h"
#include "build/build_config.h"
......@@ -32,19 +32,15 @@ namespace base {
class BASE_EXPORT SyncSocket {
public:
#if defined(OS_WIN)
typedef HANDLE Handle;
typedef Handle TransitDescriptor;
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
typedef int Handle;
typedef FileDescriptor TransitDescriptor;
#endif
using Handle = PlatformFile;
using ScopedHandle = ScopedPlatformFile;
static const Handle kInvalidHandle;
SyncSocket();
// Creates a SyncSocket from a Handle. Used in transport.
explicit SyncSocket(Handle handle) : handle_(handle) {}
// Creates a SyncSocket from a Handle.
explicit SyncSocket(Handle handle);
explicit SyncSocket(ScopedHandle handle);
virtual ~SyncSocket();
// Initializes and connects a pair of sockets.
......@@ -52,17 +48,8 @@ class BASE_EXPORT SyncSocket {
// return, the sockets will both be valid and connected.
static bool CreatePair(SyncSocket* socket_a, SyncSocket* socket_b);
// Returns |Handle| wrapped in a |TransitDescriptor|.
static Handle UnwrapHandle(const TransitDescriptor& descriptor);
// Prepares a |TransitDescriptor| which wraps |Handle| used for transit.
// This is used to prepare the underlying shared resource before passing back
// the handle to be used by the peer process.
bool PrepareTransitDescriptor(ProcessHandle peer_process_handle,
TransitDescriptor* descriptor);
// Closes the SyncSocket. Returns true on success, false on failure.
virtual bool Close();
// Closes the SyncSocket.
virtual void Close();
// Sends the message to the remote peer of the SyncSocket.
// Note it is not safe to send messages from the same socket handle by
......@@ -89,15 +76,19 @@ class BASE_EXPORT SyncSocket {
// not block when called.
virtual size_t Peek();
// Returns true if the Handle is valid, and false if it is not.
bool IsValid() const;
// Extracts the contained handle. Used for transferring between
// processes.
Handle handle() const { return handle_; }
Handle handle() const;
// Extracts and takes ownership of the contained handle.
Handle Release();
ScopedHandle Take();
protected:
Handle handle_;
ScopedHandle handle_;
private:
DISALLOW_COPY_AND_ASSIGN(SyncSocket);
......@@ -110,6 +101,7 @@ class BASE_EXPORT CancelableSyncSocket : public SyncSocket {
public:
CancelableSyncSocket();
explicit CancelableSyncSocket(Handle handle);
explicit CancelableSyncSocket(ScopedHandle handle);
~CancelableSyncSocket() override = default;
// Initializes a pair of cancelable sockets. See documentation for
......@@ -128,7 +120,7 @@ class BASE_EXPORT CancelableSyncSocket : public SyncSocket {
// and there isn't a way to cancel a blocking synchronous Read that is
// supported on <Vista. So, for Windows only, we override these
// SyncSocket methods in order to support shutting down the 'socket'.
bool Close() override;
void Close() override;
size_t Receive(void* buffer, size_t length) override;
size_t ReceiveWithTimeout(void* buffer,
size_t length,
......@@ -150,12 +142,6 @@ class BASE_EXPORT CancelableSyncSocket : public SyncSocket {
DISALLOW_COPY_AND_ASSIGN(CancelableSyncSocket);
};
#if defined(OS_WIN) && !defined(COMPONENT_BUILD)
// TODO(cpu): remove this once chrome is split in two dlls.
__declspec(selectany)
const SyncSocket::Handle SyncSocket::kInvalidHandle = INVALID_HANDLE_VALUE;
#endif
} // namespace base
#endif // BASE_SYNC_SOCKET_H_
......@@ -14,54 +14,22 @@
namespace base {
const SyncSocket::Handle SyncSocket::kInvalidHandle = -1;
SyncSocket::SyncSocket() : handle_(kInvalidHandle) {
}
SyncSocket::~SyncSocket() {
Close();
}
// static
bool SyncSocket::CreatePair(SyncSocket* socket_a, SyncSocket* socket_b) {
return false;
}
// static
SyncSocket::Handle SyncSocket::UnwrapHandle(
const SyncSocket::TransitDescriptor& descriptor) {
// TODO(xians): Still unclear how NaCl uses SyncSocket.
// See http://crbug.com/409656
NOTIMPLEMENTED();
return SyncSocket::kInvalidHandle;
}
bool SyncSocket::PrepareTransitDescriptor(
ProcessHandle peer_process_handle,
SyncSocket::TransitDescriptor* descriptor) {
// TODO(xians): Still unclear how NaCl uses SyncSocket.
// See http://crbug.com/409656
NOTIMPLEMENTED();
return false;
}
bool SyncSocket::Close() {
if (handle_ != kInvalidHandle) {
if (close(handle_) < 0)
DPLOG(ERROR) << "close";
handle_ = kInvalidHandle;
}
return true;
void SyncSocket::Close() {
handle_.reset();
}
size_t SyncSocket::Send(const void* buffer, size_t length) {
const ssize_t bytes_written = write(handle_, buffer, length);
const ssize_t bytes_written = write(handle(), buffer, length);
return bytes_written > 0 ? bytes_written : 0;
}
size_t SyncSocket::Receive(void* buffer, size_t length) {
const ssize_t bytes_read = read(handle_, buffer, length);
const ssize_t bytes_read = read(handle(), buffer, length);
return bytes_read > 0 ? bytes_read : 0;
}
......@@ -75,17 +43,16 @@ size_t SyncSocket::Peek() {
return 0;
}
SyncSocket::Handle SyncSocket::Release() {
Handle r = handle_;
handle_ = kInvalidHandle;
return r;
bool SyncSocket::IsValid() const {
return handle_.is_valid();
}
CancelableSyncSocket::CancelableSyncSocket() {
SyncSocket::Handle SyncSocket::handle() const {
return handle_.get();
}
CancelableSyncSocket::CancelableSyncSocket(Handle handle)
: SyncSocket(handle) {
SyncSocket::Handle SyncSocket::Release() {
return handle_.release();
}
size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
......@@ -93,7 +60,8 @@ size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
}
bool CancelableSyncSocket::Shutdown() {
return SyncSocket::Close();
Close();
return true;
}
// static
......
......@@ -44,93 +44,63 @@ size_t SendHelper(SyncSocket::Handle handle,
: 0;
}
bool CloseHandle(SyncSocket::Handle handle) {
if (handle != SyncSocket::kInvalidHandle && close(handle) < 0) {
DPLOG(ERROR) << "close";
return false;
}
return true;
}
} // namespace
const SyncSocket::Handle SyncSocket::kInvalidHandle = -1;
SyncSocket::SyncSocket() : handle_(kInvalidHandle) {}
SyncSocket::~SyncSocket() {
Close();
}
// static
bool SyncSocket::CreatePair(SyncSocket* socket_a, SyncSocket* socket_b) {
DCHECK_NE(socket_a, socket_b);
DCHECK_EQ(socket_a->handle_, kInvalidHandle);
DCHECK_EQ(socket_b->handle_, kInvalidHandle);
DCHECK(!socket_a->IsValid());
DCHECK(!socket_b->IsValid());
#if defined(OS_MACOSX)
int nosigpipe = 1;
#endif // defined(OS_MACOSX)
Handle handles[2] = { kInvalidHandle, kInvalidHandle };
if (socketpair(AF_UNIX, SOCK_STREAM, 0, handles) != 0) {
CloseHandle(handles[0]);
CloseHandle(handles[1]);
return false;
ScopedHandle handles[2];
{
Handle raw_handles[2] = {kInvalidHandle, kInvalidHandle};
if (socketpair(AF_UNIX, SOCK_STREAM, 0, raw_handles) != 0) {
return false;
}
handles[0].reset(raw_handles[0]);
handles[1].reset(raw_handles[1]);
}
#if defined(OS_MACOSX)
// On OSX an attempt to read or write to a closed socket may generate a
// SIGPIPE rather than returning -1. setsockopt will shut this off.
if (0 != setsockopt(handles[0], SOL_SOCKET, SO_NOSIGPIPE,
&nosigpipe, sizeof nosigpipe) ||
0 != setsockopt(handles[1], SOL_SOCKET, SO_NOSIGPIPE,
&nosigpipe, sizeof nosigpipe)) {
CloseHandle(handles[0]);
CloseHandle(handles[1]);
if (0 != setsockopt(handles[0].get(), SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe)) ||
0 != setsockopt(handles[1].get(), SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe,
sizeof(nosigpipe))) {
return false;
}
#endif
// Copy the handles out for successful return.
socket_a->handle_ = handles[0];
socket_b->handle_ = handles[1];
socket_a->handle_ = std::move(handles[0]);
socket_b->handle_ = std::move(handles[1]);
return true;
}
// static
SyncSocket::Handle SyncSocket::UnwrapHandle(
const TransitDescriptor& descriptor) {
return descriptor.fd;
}
bool SyncSocket::PrepareTransitDescriptor(ProcessHandle peer_process_handle,
TransitDescriptor* descriptor) {
descriptor->fd = handle();
descriptor->auto_close = false;
return descriptor->fd != kInvalidHandle;
}
bool SyncSocket::Close() {
const bool retval = CloseHandle(handle_);
handle_ = kInvalidHandle;
return retval;
void SyncSocket::Close() {
handle_.reset();
}
size_t SyncSocket::Send(const void* buffer, size_t length) {
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
return SendHelper(handle_, buffer, length);
return SendHelper(handle(), buffer, length);
}
size_t SyncSocket::Receive(void* buffer, size_t length) {
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
DCHECK_GT(length, 0u);
DCHECK_LE(length, kMaxMessageLength);
DCHECK_NE(handle_, kInvalidHandle);
DCHECK(IsValid());
char* charbuffer = static_cast<char*>(buffer);
if (ReadFromFD(handle_, charbuffer, length))
if (ReadFromFD(handle(), charbuffer, length))
return length;
return 0;
}
......@@ -141,7 +111,7 @@ size_t SyncSocket::ReceiveWithTimeout(void* buffer,
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
DCHECK_GT(length, 0u);
DCHECK_LE(length, kMaxMessageLength);
DCHECK_NE(handle_, kInvalidHandle);
DCHECK(IsValid());
// Only timeouts greater than zero and less than one second are allowed.
DCHECK_GT(timeout.InMicroseconds(), 0);
......@@ -153,7 +123,7 @@ size_t SyncSocket::ReceiveWithTimeout(void* buffer,
const TimeTicks finish_time = start_time + timeout;
struct pollfd pollfd;
pollfd.fd = handle_;
pollfd.fd = handle();
pollfd.events = POLLIN;
pollfd.revents = 0;
......@@ -196,9 +166,9 @@ size_t SyncSocket::ReceiveWithTimeout(void* buffer,
}
size_t SyncSocket::Peek() {
DCHECK_NE(handle_, kInvalidHandle);
DCHECK(IsValid());
int number_chars = 0;
if (ioctl(handle_, FIONREAD, &number_chars) == -1) {
if (ioctl(handle_.get(), FIONREAD, &number_chars) == -1) {
// If there is an error in ioctl, signal that the channel would block.
return 0;
}
......@@ -206,39 +176,40 @@ size_t SyncSocket::Peek() {
return number_chars;
}
SyncSocket::Handle SyncSocket::Release() {
Handle r = handle_;
handle_ = kInvalidHandle;
return r;
bool SyncSocket::IsValid() const {
return handle_.is_valid();
}
CancelableSyncSocket::CancelableSyncSocket() = default;
CancelableSyncSocket::CancelableSyncSocket(Handle handle)
: SyncSocket(handle) {
SyncSocket::Handle SyncSocket::handle() const {
return handle_.get();
}
SyncSocket::Handle SyncSocket::Release() {
return handle_.release();
}
bool CancelableSyncSocket::Shutdown() {
DCHECK_NE(handle_, kInvalidHandle);
return HANDLE_EINTR(shutdown(handle_, SHUT_RDWR)) >= 0;
DCHECK(IsValid());
return HANDLE_EINTR(shutdown(handle(), SHUT_RDWR)) >= 0;
}
size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
DCHECK_GT(length, 0u);
DCHECK_LE(length, kMaxMessageLength);
DCHECK_NE(handle_, kInvalidHandle);
DCHECK(IsValid());
const int flags = fcntl(handle_, F_GETFL);
const int flags = fcntl(handle(), F_GETFL);
if (flags != -1 && (flags & O_NONBLOCK) == 0) {
// Set the socket to non-blocking mode for sending if its original mode
// is blocking.
fcntl(handle_, F_SETFL, flags | O_NONBLOCK);
fcntl(handle(), F_SETFL, flags | O_NONBLOCK);
}
const size_t len = SendHelper(handle_, buffer, length);
const size_t len = SendHelper(handle(), buffer, length);
if (flags != -1 && (flags & O_NONBLOCK) == 0) {
// Restore the original flags.
fcntl(handle_, F_SETFL, flags);
fcntl(handle(), F_SETFL, flags);
}
return len;
......
......@@ -96,8 +96,8 @@ void SendReceivePeek(SyncSocket* socket_a, SyncSocket* socket_b) {
ASSERT_EQ(0u, socket_a->Peek());
ASSERT_EQ(0u, socket_b->Peek());
ASSERT_TRUE(socket_a->Close());
ASSERT_TRUE(socket_b->Close());
socket_a->Close();
socket_b->Close();
}
} // namespace
......
......@@ -32,10 +32,12 @@ const int kOutBufferSize = 4096;
const int kInBufferSize = 4096;
const int kDefaultTimeoutMilliSeconds = 1000;
bool CreatePairImpl(HANDLE* socket_a, HANDLE* socket_b, bool overlapped) {
bool CreatePairImpl(ScopedHandle* socket_a,
ScopedHandle* socket_b,
bool overlapped) {
DCHECK_NE(socket_a, socket_b);
DCHECK_EQ(*socket_a, SyncSocket::kInvalidHandle);
DCHECK_EQ(*socket_b, SyncSocket::kInvalidHandle);
DCHECK(!socket_a->IsValid());
DCHECK(!socket_b->IsValid());
wchar_t name[kPipePathMax];
ScopedHandle handle_a;
......@@ -97,8 +99,8 @@ bool CreatePairImpl(HANDLE* socket_a, HANDLE* socket_b, bool overlapped) {
}
}
*socket_a = handle_a.Take();
*socket_b = handle_b.Take();
*socket_a = std::move(handle_a);
*socket_b = std::move(handle_b);
return true;
}
......@@ -203,57 +205,25 @@ size_t CancelableFileOperation(Function operation,
} // namespace
#if defined(COMPONENT_BUILD)
const SyncSocket::Handle SyncSocket::kInvalidHandle = INVALID_HANDLE_VALUE;
#endif
SyncSocket::SyncSocket() : handle_(kInvalidHandle) {}
SyncSocket::~SyncSocket() {
Close();
}
// static
bool SyncSocket::CreatePair(SyncSocket* socket_a, SyncSocket* socket_b) {
return CreatePairImpl(&socket_a->handle_, &socket_b->handle_, false);
}
// static
SyncSocket::Handle SyncSocket::UnwrapHandle(
const TransitDescriptor& descriptor) {
return descriptor;
}
bool SyncSocket::PrepareTransitDescriptor(ProcessHandle peer_process_handle,
TransitDescriptor* descriptor) {
DCHECK(descriptor);
if (!::DuplicateHandle(GetCurrentProcess(), handle(), peer_process_handle,
descriptor, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
DPLOG(ERROR) << "Cannot duplicate socket handle for peer process.";
return false;
}
return true;
}
bool SyncSocket::Close() {
if (handle_ == kInvalidHandle)
return true;
const BOOL result = CloseHandle(handle_);
handle_ = kInvalidHandle;
return result == TRUE;
void SyncSocket::Close() {
handle_.Close();
}
size_t SyncSocket::Send(const void* buffer, size_t length) {
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
DCHECK_GT(length, 0u);
DCHECK_LE(length, kMaxMessageLength);
DCHECK_NE(handle_, kInvalidHandle);
DCHECK(IsValid());
size_t count = 0;
while (count < length) {
DWORD len;
DWORD chunk = GetNextChunkSize(count, length);
if (::WriteFile(handle_, static_cast<const char*>(buffer) + count, chunk,
if (::WriteFile(handle(), static_cast<const char*>(buffer) + count, chunk,
&len, NULL) == FALSE) {
return count;
}
......@@ -273,12 +243,12 @@ size_t SyncSocket::Receive(void* buffer, size_t length) {
ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
DCHECK_GT(length, 0u);
DCHECK_LE(length, kMaxMessageLength);
DCHECK_NE(handle_, kInvalidHandle);
DCHECK(IsValid());
size_t count = 0;
while (count < length) {
DWORD len;
DWORD chunk = GetNextChunkSize(count, length);
if (::ReadFile(handle_, static_cast<char*>(buffer) + count, chunk, &len,
if (::ReadFile(handle(), static_cast<char*>(buffer) + count, chunk, &len,
NULL) == FALSE) {
return count;
}
......@@ -289,28 +259,21 @@ size_t SyncSocket::Receive(void* buffer, size_t length) {
size_t SyncSocket::Peek() {
DWORD available = 0;
PeekNamedPipe(handle_, NULL, 0, NULL, &available, NULL);
PeekNamedPipe(handle(), NULL, 0, NULL, &available, NULL);
return available;
}
SyncSocket::Handle SyncSocket::Release() {
Handle r = handle_;
handle_ = kInvalidHandle;
return r;
bool SyncSocket::IsValid() const {
return handle_.IsValid();
}
CancelableSyncSocket::CancelableSyncSocket()
: shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED),
file_operation_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED) {}
SyncSocket::Handle SyncSocket::handle() const {
return handle_.Get();
}
CancelableSyncSocket::CancelableSyncSocket(Handle handle)
: SyncSocket(handle),
shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED),
file_operation_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED) {}
SyncSocket::Handle SyncSocket::Release() {
return handle_.Take();
}
bool CancelableSyncSocket::Shutdown() {
// This doesn't shut down the pipe immediately, but subsequent Receive or Send
......@@ -319,29 +282,28 @@ bool CancelableSyncSocket::Shutdown() {
return true;
}
bool CancelableSyncSocket::Close() {
const bool result = SyncSocket::Close();
void CancelableSyncSocket::Close() {
SyncSocket::Close();
shutdown_event_.Reset();
return result;
}
size_t CancelableSyncSocket::Send(const void* buffer, size_t length) {
static const DWORD kWaitTimeOutInMs = 500;
return CancelableFileOperation(
&::WriteFile, handle_, reinterpret_cast<const char*>(buffer), length,
&::WriteFile, handle(), reinterpret_cast<const char*>(buffer), length,
&file_operation_, &shutdown_event_, this, kWaitTimeOutInMs);
}
size_t CancelableSyncSocket::Receive(void* buffer, size_t length) {
return CancelableFileOperation(
&::ReadFile, handle_, reinterpret_cast<char*>(buffer), length,
&::ReadFile, handle(), reinterpret_cast<char*>(buffer), length,
&file_operation_, &shutdown_event_, this, INFINITE);
}
size_t CancelableSyncSocket::ReceiveWithTimeout(void* buffer,
size_t length,
TimeDelta timeout) {
return CancelableFileOperation(&::ReadFile, handle_,
return CancelableFileOperation(&::ReadFile, handle(),
reinterpret_cast<char*>(buffer), length,
&file_operation_, &shutdown_event_, this,
static_cast<DWORD>(timeout.InMilliseconds()));
......
......@@ -60,7 +60,7 @@ class CapturedAudioInputTest : public ::testing::Test {
mojo::PendingRemote<mojom::AudioStreamCreatorClient> client,
const media::AudioParameters& params,
uint32_t total_segments) {
EXPECT_EQ(base::SyncSocket::kInvalidHandle, socket_.handle());
EXPECT_FALSE(socket_.IsValid());
EXPECT_FALSE(stream_);
mojo::PendingRemote<media::mojom::AudioInputStream> pending_stream;
auto input_stream = std::make_unique<MockStream>();
......
......@@ -109,9 +109,6 @@ TEST(AudioInputDeviceTest, CreateStream) {
ASSERT_TRUE(
CancelableSyncSocket::CreatePair(&browser_socket, &renderer_socket));
SyncSocket::TransitDescriptor audio_device_socket_descriptor;
ASSERT_TRUE(renderer_socket.PrepareTransitDescriptor(
base::GetCurrentProcessHandle(), &audio_device_socket_descriptor));
base::ReadOnlySharedMemoryRegion duplicated_shared_memory_region =
shared_memory.region.Duplicate();
ASSERT_TRUE(duplicated_shared_memory_region.IsValid());
......@@ -126,10 +123,8 @@ TEST(AudioInputDeviceTest, CreateStream) {
EXPECT_CALL(*input_ipc, CreateStream(_, _, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
static_cast<AudioInputIPCDelegate*>(device.get())
->OnStreamCreated(
std::move(duplicated_shared_memory_region),
SyncSocket::UnwrapHandle(audio_device_socket_descriptor),
false);
->OnStreamCreated(std::move(duplicated_shared_memory_region),
renderer_socket.Release(), false);
}));
EXPECT_CALL(*input_ipc, RecordStream());
......
......@@ -199,17 +199,13 @@ void AudioOutputDeviceTest::CallOnStreamCreated() {
// Create duplicates of the handles we pass to AudioOutputDevice since
// ownership will be transferred and AudioOutputDevice is responsible for
// freeing.
SyncSocket::TransitDescriptor audio_device_socket_descriptor;
ASSERT_TRUE(renderer_socket_.PrepareTransitDescriptor(
base::GetCurrentProcessHandle(), &audio_device_socket_descriptor));
base::UnsafeSharedMemoryRegion duplicated_memory_region =
shared_memory_region_.Duplicate();
ASSERT_TRUE(duplicated_memory_region.IsValid());
audio_device_->OnStreamCreated(
std::move(duplicated_memory_region),
SyncSocket::UnwrapHandle(audio_device_socket_descriptor),
/*playing_automatically*/ false);
audio_device_->OnStreamCreated(std::move(duplicated_memory_region),
renderer_socket_.Release(),
/*playing_automatically*/ false);
task_env_.FastForwardBy(base::TimeDelta());
}
......
......@@ -48,7 +48,7 @@ class TestCancelableSyncSocket : public base::CancelableSyncSocket {
// closes it. We have to make sure we do not also retain the handle in the
// sync socket, as the sync socket closes the handle on destruction.
if (expect_ownership_transfer_)
EXPECT_EQ(handle(), kInvalidHandle);
EXPECT_FALSE(IsValid());
}
private:
......
......@@ -48,7 +48,7 @@ class TestCancelableSyncSocket : public base::CancelableSyncSocket {
// closes it. We have to make sure we do not also retain the handle in the
// sync socket, as the sync socket closes the handle on destruction.
if (expect_ownership_transfer_)
EXPECT_EQ(handle(), kInvalidHandle);
EXPECT_FALSE(IsValid());
}
private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment