Commit 440f5bdf authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

Remove SequencedTaskRunnerHandle::Get() usages in MojoAudioOutputIPC

This is part of efforts to replace base::ThreadTaskRunnerHandle::Get()
and SequencedTaskRunnerHandle::Get() with other appropriate task runners
in the renderer.

Bug: 827065
Change-Id: I6b4d582ba9e1d53dfddebacc8baec199eb311271
Reviewed-on: https://chromium-review.googlesource.com/985995
Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: default avatarMax Morin <maxmorin@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Reviewed-by: default avatarBill Budge <bbudge@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548683}
parent 91808c04
......@@ -39,7 +39,8 @@ AudioOutputIPCFactory::CreateAudioOutputIPC(int frame_id) const {
// Unretained is safe due to the contract at the top of the header file.
return std::make_unique<MojoAudioOutputIPC>(
base::BindRepeating(&AudioOutputIPCFactory::GetRemoteFactory,
base::Unretained(this), frame_id));
base::Unretained(this), frame_id),
io_task_runner_);
}
return audio_message_filter_->CreateAudioOutputIPC(frame_id);
}
......
......@@ -6,7 +6,6 @@
#include <utility>
#include "base/threading/sequenced_task_runner_handle.h"
#include "media/audio/audio_device_description.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "mojo/public/cpp/system/platform_handle.h"
......@@ -21,12 +20,13 @@ void TrivialAuthorizedCallback(media::OutputDeviceStatus,
} // namespace
MojoAudioOutputIPC::MojoAudioOutputIPC(FactoryAccessorCB factory_accessor)
MojoAudioOutputIPC::MojoAudioOutputIPC(
FactoryAccessorCB factory_accessor,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
: factory_accessor_(std::move(factory_accessor)),
binding_(this),
weak_factory_(this) {
DETACH_FROM_THREAD(thread_checker_);
}
io_task_runner_(std::move(io_task_runner)),
weak_factory_(this) {}
MojoAudioOutputIPC::~MojoAudioOutputIPC() {
DCHECK(!AuthorizationRequested() && !StreamCreationRequested())
......@@ -41,7 +41,7 @@ void MojoAudioOutputIPC::RequestDeviceAuthorization(
int session_id,
const std::string& device_id,
const url::Origin& security_origin) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(delegate);
DCHECK(!delegate_);
DCHECK(!AuthorizationRequested());
......@@ -63,7 +63,7 @@ void MojoAudioOutputIPC::RequestDeviceAuthorization(
void MojoAudioOutputIPC::CreateStream(media::AudioOutputIPCDelegate* delegate,
const media::AudioParameters& params) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(delegate);
DCHECK(!StreamCreationRequested());
if (!AuthorizationRequested()) {
......@@ -94,19 +94,19 @@ void MojoAudioOutputIPC::CreateStream(media::AudioOutputIPCDelegate* delegate,
}
void MojoAudioOutputIPC::PlayStream() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(stream_.is_bound());
stream_->Play();
}
void MojoAudioOutputIPC::PauseStream() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(stream_.is_bound());
stream_->Pause();
}
void MojoAudioOutputIPC::CloseStream() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
stream_provider_.reset();
stream_.reset();
binding_.Close();
......@@ -117,13 +117,13 @@ void MojoAudioOutputIPC::CloseStream() {
}
void MojoAudioOutputIPC::SetVolume(double volume) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(stream_.is_bound());
stream_->SetVolume(volume);
}
void MojoAudioOutputIPC::OnError() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(delegate_);
delegate_->OnError();
}
......@@ -138,7 +138,7 @@ bool MojoAudioOutputIPC::StreamCreationRequested() {
media::mojom::AudioOutputStreamProviderRequest
MojoAudioOutputIPC::MakeProviderRequest() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(!AuthorizationRequested());
media::mojom::AudioOutputStreamProviderRequest request =
mojo::MakeRequest(&stream_provider_);
......@@ -161,7 +161,7 @@ void MojoAudioOutputIPC::DoRequestDeviceAuthorization(
int session_id,
const std::string& device_id,
AuthorizationCB callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
auto* factory = factory_accessor_.Run();
if (!factory) {
LOG(ERROR) << "MojoAudioOutputIPC failed to acquire factory";
......@@ -172,7 +172,7 @@ void MojoAudioOutputIPC::DoRequestDeviceAuthorization(
// when the factory is destroyed before reply, i.e. calling
// OnDeviceAuthorized with ERROR_INTERNAL in the normal case.
// The AudioOutputIPCDelegate will call CloseStream as necessary.
base::SequencedTaskRunnerHandle::Get()->PostTask(
io_task_runner_->PostTask(
FROM_HERE,
base::BindOnce([](AuthorizationCB cb) {}, std::move(callback)));
return;
......@@ -188,14 +188,14 @@ void MojoAudioOutputIPC::ReceivedDeviceAuthorization(
media::OutputDeviceStatus status,
const media::AudioParameters& params,
const std::string& device_id) const {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(delegate_);
delegate_->OnDeviceAuthorized(status, params, device_id);
}
void MojoAudioOutputIPC::StreamCreated(
media::mojom::AudioDataPipePtr data_pipe) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
DCHECK(delegate_);
base::PlatformFile socket_handle;
......
......@@ -10,7 +10,6 @@
#include "base/callback_helpers.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "content/common/media/renderer_audio_output_stream_factory.mojom.h"
#include "media/audio/audio_output_ipc.h"
......@@ -31,7 +30,9 @@ class CONTENT_EXPORT MojoAudioOutputIPC
// |factory_accessor| is required to provide a
// RendererAudioOutputStreamFactory* if IPC is possible.
explicit MojoAudioOutputIPC(FactoryAccessorCB factory_accessor);
MojoAudioOutputIPC(
FactoryAccessorCB factory_accessor,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
~MojoAudioOutputIPC() override;
......@@ -73,12 +74,11 @@ class CONTENT_EXPORT MojoAudioOutputIPC
const FactoryAccessorCB factory_accessor_;
THREAD_CHECKER(thread_checker_);
mojo::Binding<media::mojom::AudioOutputStreamClient> binding_;
media::mojom::AudioOutputStreamProviderPtr stream_provider_;
media::mojom::AudioOutputStreamPtr stream_;
media::AudioOutputIPCDelegate* delegate_ = nullptr;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
// To make sure we don't send an "authorization completed" callback for a
// stream after it's closed, we use this weak factory.
......
......@@ -19,6 +19,7 @@
#include "mojo/public/cpp/system/platform_handle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "url/origin.h"
using testing::_;
......@@ -205,7 +206,9 @@ TEST(MojoAudioOutputIPC, AuthorizeWithoutFactory_CallsAuthorizedWithError) {
StrictMock<MockDelegate> delegate;
std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(NullAccessor());
std::make_unique<MojoAudioOutputIPC>(
NullAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin());
......@@ -224,7 +227,9 @@ TEST(MojoAudioOutputIPC,
StrictMock<MockDelegate> delegate;
std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(NullAccessor());
std::make_unique<MojoAudioOutputIPC>(
NullAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
ipc->CreateStream(&delegate, Params());
......@@ -240,7 +245,9 @@ TEST(MojoAudioOutputIPC, DeviceAuthorized_Propagates) {
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
stream_factory.PrepareProviderForAuthorization(
kSessionId, kDeviceId, std::make_unique<TestStreamProvider>(nullptr));
......@@ -262,7 +269,9 @@ TEST(MojoAudioOutputIPC, OnDeviceCreated_Propagates) {
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
stream_factory.PrepareProviderForAuthorization(
kSessionId, kDeviceId, std::make_unique<TestStreamProvider>(&stream));
......@@ -286,7 +295,9 @@ TEST(MojoAudioOutputIPC,
StrictMock<MockStream> stream;
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
// Note: This call implicitly EXPECTs that authorization is requested,
// and constructing the TestStreamProvider with a |&stream| EXPECTs that the
......@@ -312,7 +323,9 @@ TEST(MojoAudioOutputIPC, IsReusable) {
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
for (int i = 0; i < 5; ++i) {
stream_factory.PrepareProviderForAuthorization(
......@@ -341,7 +354,9 @@ TEST(MojoAudioOutputIPC, IsReusableAfterError) {
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
stream_factory.PrepareProviderForAuthorization(
kSessionId, kDeviceId, std::make_unique<TestStreamProvider>(nullptr));
......@@ -391,7 +406,9 @@ TEST(MojoAudioOutputIPC, DeviceNotAuthorized_Propagates) {
StrictMock<MockDelegate> delegate;
std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
stream_factory.RefuseNextRequest(kSessionId, kDeviceId);
ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin());
......@@ -420,7 +437,9 @@ TEST(MojoAudioOutputIPC,
StrictMock<MockDelegate> delegate;
std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin());
......@@ -450,7 +469,9 @@ TEST(MojoAudioOutputIPC,
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin());
......@@ -475,7 +496,9 @@ TEST(MojoAudioOutputIPC, AuthorizeNoClose_DCHECKs) {
kSessionId, kDeviceId, std::make_unique<TestStreamProvider>(nullptr));
std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin());
EXPECT_DCHECK_DEATH(ipc.reset());
......@@ -495,7 +518,9 @@ TEST(MojoAudioOutputIPC, CreateNoClose_DCHECKs) {
std::make_unique<TestStreamProvider>(&stream));
std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
ipc->CreateStream(&delegate, Params());
EXPECT_DCHECK_DEATH(ipc.reset());
......@@ -511,7 +536,9 @@ TEST(MojoAudioOutputIPC, Play_Plays) {
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
stream_factory.PrepareProviderForAuthorization(
kSessionId, kDeviceId, std::make_unique<TestStreamProvider>(&stream));
......@@ -537,7 +564,9 @@ TEST(MojoAudioOutputIPC, Pause_Pauses) {
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
stream_factory.PrepareProviderForAuthorization(
kSessionId, kDeviceId, std::make_unique<TestStreamProvider>(&stream));
......@@ -563,7 +592,9 @@ TEST(MojoAudioOutputIPC, SetVolume_SetsVolume) {
StrictMock<MockDelegate> delegate;
const std::unique_ptr<media::AudioOutputIPC> ipc =
std::make_unique<MojoAudioOutputIPC>(stream_factory.GetAccessor());
std::make_unique<MojoAudioOutputIPC>(
stream_factory.GetAccessor(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting());
stream_factory.PrepareProviderForAuthorization(
kSessionId, kDeviceId, std::make_unique<TestStreamProvider>(&stream));
......
......@@ -252,12 +252,13 @@ TEST_F(RendererAudioOutputStreamFactoryIntegrationTest, StreamIntegrationTest) {
// Wait for factory_ptr to be set.
SyncWith(renderer_ipc_task_runner);
auto renderer_side_ipc =
std::make_unique<MojoAudioOutputIPC>(base::BindRepeating(
auto renderer_side_ipc = std::make_unique<MojoAudioOutputIPC>(
base::BindRepeating(
[](mojom::RendererAudioOutputStreamFactory* factory_ptr) {
return factory_ptr;
},
factory_ptr));
factory_ptr),
renderer_ipc_task_runner);
auto device = base::MakeRefCounted<media::AudioOutputDevice>(
std::move(renderer_side_ipc), renderer_ipc_task_runner, kNoSessionId, "",
......
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