Skip to content

Commit

Permalink
Replace MessageLoopProxy with SingleThreadTaskRunner for the rest of …
Browse files Browse the repository at this point in the history
…media/.

BUG=315922
R=dalecurtis@chromium.org
TBR=jam

Review URL: https://codereview.chromium.org/66183002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243390 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
scherkus@chromium.org committed Jan 7, 2014
1 parent b2a34d5 commit a0e7e86
Show file tree
Hide file tree
Showing 62 changed files with 418 additions and 417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h"

#include "base/lazy_instance.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/strings/string_number_conversions.h"
#include "base/task_runner_util.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
Expand Down Expand Up @@ -99,15 +98,15 @@ void WebrtcAudioPrivateEventService::SignalEvent() {
bool WebrtcAudioPrivateGetSinksFunction::RunImpl() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

AudioManager::Get()->GetMessageLoop()->PostTaskAndReply(
AudioManager::Get()->GetTaskRunner()->PostTaskAndReply(
FROM_HERE,
base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoQuery, this),
base::Bind(&WebrtcAudioPrivateGetSinksFunction::DoneOnUIThread, this));
return true;
}

void WebrtcAudioPrivateGetSinksFunction::DoQuery() {
DCHECK(AudioManager::Get()->GetMessageLoop()->BelongsToCurrentThread());
DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread());

AudioDeviceNames device_names;
AudioManager::Get()->GetAudioOutputDeviceNames(&device_names);
Expand Down Expand Up @@ -198,7 +197,7 @@ void WebrtcAudioPrivateGetActiveSinkFunction::OnSinkId(const std::string& id) {

WebrtcAudioPrivateSetActiveSinkFunction::
WebrtcAudioPrivateSetActiveSinkFunction()
: message_loop_(base::MessageLoopProxy::current()),
: task_runner_(base::MessageLoopProxy::current()),
tab_id_(0),
num_remaining_sink_ids_(0) {
}
Expand Down Expand Up @@ -244,7 +243,7 @@ void WebrtcAudioPrivateSetActiveSinkFunction::OnControllerList(

void WebrtcAudioPrivateSetActiveSinkFunction::SwitchDone() {
if (--num_remaining_sink_ids_ == 0) {
message_loop_->PostTask(
task_runner_->PostTask(
FROM_HERE,
base::Bind(&WebrtcAudioPrivateSetActiveSinkFunction::DoneOnUIThread,
this));
Expand All @@ -268,7 +267,7 @@ bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunImpl() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
EXTENSION_FUNCTION_VALIDATE(params_.get());

AudioManager::Get()->GetMessageLoop()->PostTaskAndReply(
AudioManager::Get()->GetTaskRunner()->PostTaskAndReply(
FROM_HERE,
base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction::
GetDevicesOnDeviceThread, this),
Expand All @@ -280,7 +279,7 @@ bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunImpl() {
}

void WebrtcAudioPrivateGetAssociatedSinkFunction::GetDevicesOnDeviceThread() {
DCHECK(AudioManager::Get()->GetMessageLoop()->BelongsToCurrentThread());
DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread());
AudioManager::Get()->GetAudioInputDeviceNames(&source_devices_);
}

Expand Down Expand Up @@ -332,7 +331,7 @@ void WebrtcAudioPrivateGetAssociatedSinkFunction::OnGetRawSourceIDDone(
const std::string& raw_source_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::PostTaskAndReplyWithResult(
AudioManager::Get()->GetMessageLoop(),
AudioManager::Get()->GetTaskRunner(),
FROM_HERE,
base::Bind(&WebrtcAudioPrivateGetAssociatedSinkFunction::
GetAssociatedSinkOnDeviceThread,
Expand All @@ -346,7 +345,7 @@ void WebrtcAudioPrivateGetAssociatedSinkFunction::OnGetRawSourceIDDone(
std::string
WebrtcAudioPrivateGetAssociatedSinkFunction::GetAssociatedSinkOnDeviceThread(
const std::string& raw_source_id) {
DCHECK(AudioManager::Get()->GetMessageLoop()->BelongsToCurrentThread());
DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread());

// We return an empty string if there is no associated output device.
std::string result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "url/gurl.h"

namespace base {
class MessageLoopProxy;
class SingleThreadTaskRunner;
}

namespace extensions {
Expand Down Expand Up @@ -107,8 +107,8 @@ class WebrtcAudioPrivateSetActiveSinkFunction
void SwitchDone();
void DoneOnUIThread();

// Message loop of the thread this class is constructed on.
const scoped_refptr<base::MessageLoopProxy> message_loop_;
// Task runner of the thread this class is constructed on.
const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;

int tab_id_;
std::string sink_id_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

#include "base/json/json_writer.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -103,8 +102,8 @@ class WebrtcAudioPrivateTest : public AudioWaitingExtensionTest {
AudioDeviceNames* device_names) {
AudioManager* audio_manager = AudioManager::Get();

if (!audio_manager->GetMessageLoop()->BelongsToCurrentThread()) {
audio_manager->GetMessageLoop()->PostTask(
if (!audio_manager->GetTaskRunner()->BelongsToCurrentThread()) {
audio_manager->GetTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&WebrtcAudioPrivateTest::GetAudioDeviceNames, this,
EnumerationFunc, device_names));
Expand Down
11 changes: 6 additions & 5 deletions content/browser/renderer_host/media/audio_input_renderer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,13 @@ void AudioInputRendererHost::OnCreateStream(
entry->writer.reset(writer.release());
if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) {
entry->controller = media::AudioInputController::CreateForStream(
audio_manager_->GetMessageLoop(),
audio_manager_->GetTaskRunner(),
this,
WebContentsAudioInputStream::Create(device_id,
audio_params,
audio_manager_->GetWorkerLoop(),
audio_mirroring_manager_),
WebContentsAudioInputStream::Create(
device_id,
audio_params,
audio_manager_->GetWorkerTaskRunner(),
audio_mirroring_manager_),
entry->writer.get(),
user_input_monitor_);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class AudioRendererHostTest : public testing::Test {
base::RunLoop().RunUntilIdle();

base::RunLoop run_loop;
audio_manager_->GetMessageLoop()->PostTask(
audio_manager_->GetTaskRunner()->PostTask(
FROM_HERE, media::BindToCurrentLoop(run_loop.QuitClosure()));
run_loop.Run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void WebContentsAudioInputStream::Impl::OnTargetChanged(int render_process_id,
WebContentsAudioInputStream* WebContentsAudioInputStream::Create(
const std::string& device_id,
const media::AudioParameters& params,
const scoped_refptr<base::MessageLoopProxy>& worker_loop,
const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
AudioMirroringManager* audio_mirroring_manager) {
int render_process_id;
int render_view_id;
Expand All @@ -295,7 +295,7 @@ WebContentsAudioInputStream* WebContentsAudioInputStream::Create(
audio_mirroring_manager,
new WebContentsTracker(),
new media::VirtualAudioInputStream(
params, worker_loop,
params, worker_task_runner,
media::VirtualAudioInputStream::AfterCloseCallback()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "media/audio/audio_io.h"

namespace base {
class MessageLoopProxy;
class SingleThreadTaskRunner;
}

namespace media {
Expand Down Expand Up @@ -55,13 +55,13 @@ class CONTENT_EXPORT WebContentsAudioInputStream
// WebContentsCaptureUtil::ExtractTabCaptureTarget(). The caller must
// guarantee Close() is called on the returned object so that it may
// self-destruct.
// |worker_loop| is the loop on which AudioInputCallback methods are called
// and may or may not be the single thread that invokes the AudioInputStream
// methods.
// |worker_task_runner| is the task runner on which AudioInputCallback methods
// are called and may or may not be the single thread that invokes the
// AudioInputStream methods.
static WebContentsAudioInputStream* Create(
const std::string& device_id,
const media::AudioParameters& params,
const scoped_refptr<base::MessageLoopProxy>& worker_loop,
const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
AudioMirroringManager* audio_mirroring_manager);

private:
Expand Down
2 changes: 1 addition & 1 deletion content/browser/renderer_host/render_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ base::TaskRunner* RenderMessageFilter::OverrideTaskRunnerForMessage(
#if defined(OS_MACOSX)
// OSX CoreAudio calls must all happen on the main thread.
if (message.type() == ViewHostMsg_GetAudioHardwareConfig::ID)
return audio_manager_->GetMessageLoop().get();
return audio_manager_->GetTaskRunner().get();
#endif
return NULL;
}
Expand Down
16 changes: 8 additions & 8 deletions content/test/webrtc_audio_device_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/test_timeouts.h"
Expand Down Expand Up @@ -399,20 +398,21 @@ bool MAYBE_WebRTCAudioDeviceTest::OnMessageReceived(

// Posts a final task to the IO message loop and waits for completion.
void MAYBE_WebRTCAudioDeviceTest::WaitForIOThreadCompletion() {
WaitForMessageLoopCompletion(
ChildProcess::current()->io_message_loop()->message_loop_proxy().get());
WaitForTaskRunnerCompletion(
ChildProcess::current()->io_message_loop()->message_loop_proxy());
}

void MAYBE_WebRTCAudioDeviceTest::WaitForAudioManagerCompletion() {
if (audio_manager_)
WaitForMessageLoopCompletion(audio_manager_->GetMessageLoop().get());
WaitForTaskRunnerCompletion(audio_manager_->GetTaskRunner());
}

void MAYBE_WebRTCAudioDeviceTest::WaitForMessageLoopCompletion(
base::MessageLoopProxy* loop) {
void MAYBE_WebRTCAudioDeviceTest::WaitForTaskRunnerCompletion(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
base::WaitableEvent* event = new base::WaitableEvent(false, false);
loop->PostTask(FROM_HERE, base::Bind(&base::WaitableEvent::Signal,
base::Unretained(event)));
task_runner->PostTask(
FROM_HERE,
base::Bind(&base::WaitableEvent::Signal, base::Unretained(event)));
if (event->TimedWait(TestTimeouts::action_max_timeout())) {
delete event;
} else {
Expand Down
4 changes: 2 additions & 2 deletions content/test/webrtc_audio_device_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "content/browser/renderer_host/media/mock_media_observer.h"
#include "content/public/renderer/content_renderer_client.h"
#include "ipc/ipc_listener.h"
Expand Down Expand Up @@ -151,7 +150,8 @@ class MAYBE_WebRTCAudioDeviceTest : public ::testing::Test,
// Posts a final task to the IO message loop and waits for completion.
void WaitForIOThreadCompletion();
void WaitForAudioManagerCompletion();
void WaitForMessageLoopCompletion(base::MessageLoopProxy* loop);
void WaitForTaskRunnerCompletion(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);

std::string GetTestDataPath(const base::FilePath::StringType& file_name);

Expand Down
3 changes: 1 addition & 2 deletions media/audio/alsa/alsa_output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "base/bind.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
#include "base/time/time.h"
#include "media/audio/alsa/alsa_util.h"
Expand Down Expand Up @@ -159,7 +158,7 @@ AlsaPcmOutputStream::AlsaPcmOutputStream(const std::string& device_name,
volume_(1.0f),
source_callback_(NULL),
audio_bus_(AudioBus::Create(params)) {
DCHECK(manager_->GetMessageLoop()->BelongsToCurrentThread());
DCHECK(manager_->GetTaskRunner()->BelongsToCurrentThread());
DCHECK_EQ(audio_bus_->frames() * bytes_per_frame_, packet_size_);

// Sanity check input values.
Expand Down
5 changes: 2 additions & 3 deletions media/audio/alsa/alsa_output_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/message_loop/message_loop.h"
#include "base/strings/stringprintf.h"
#include "media/audio/alsa/alsa_output.h"
#include "media/audio/alsa/alsa_wrapper.h"
Expand Down Expand Up @@ -102,8 +101,8 @@ class MockAudioManagerAlsa : public AudioManagerAlsa {
}

// We don't mock this method since all tests will do the same thing
// and use the current message loop.
virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoop() OVERRIDE {
// and use the current task runner.
virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() OVERRIDE {
return base::MessageLoop::current()->message_loop_proxy();
}

Expand Down
2 changes: 1 addition & 1 deletion media/audio/android/audio_manager_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void AudioManagerAndroid::Close() {
}

void AudioManagerAndroid::SetMute(JNIEnv* env, jobject obj, jboolean muted) {
GetMessageLoop()->PostTask(
GetTaskRunner()->PostTask(
FROM_HERE,
base::Bind(
&AudioManagerAndroid::DoSetMuteOnAudioThread,
Expand Down
Loading

0 comments on commit a0e7e86

Please sign in to comment.