OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/audio/test_audio_thread.h" |
| 6 |
| 7 #include "base/run_loop.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 |
| 10 namespace media { |
| 11 |
| 12 TestAudioThread::TestAudioThread() : TestAudioThread(false) {} |
| 13 |
| 14 TestAudioThread::TestAudioThread(bool use_real_thread) { |
| 15 if (use_real_thread) { |
| 16 thread_ = base::MakeUnique<base::Thread>("AudioThread"); |
| 17 #if defined(OS_WIN) |
| 18 thread_->init_com_with_mta(true); |
| 19 #endif |
| 20 CHECK(thread_->Start()); |
| 21 task_runner_ = thread_->task_runner(); |
| 22 } else { |
| 23 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 24 } |
| 25 } |
| 26 |
| 27 TestAudioThread::~TestAudioThread() { |
| 28 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 29 } |
| 30 |
| 31 void TestAudioThread::Stop() { |
| 32 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 33 if (thread_) |
| 34 thread_->Stop(); |
| 35 else |
| 36 base::RunLoop().RunUntilIdle(); |
| 37 } |
| 38 |
| 39 base::SingleThreadTaskRunner* TestAudioThread::GetTaskRunner() { |
| 40 return task_runner_.get(); |
| 41 } |
| 42 |
| 43 base::SingleThreadTaskRunner* TestAudioThread::GetWorkerTaskRunner() { |
| 44 return task_runner_.get(); |
| 45 } |
| 46 |
| 47 } // namespace media |
OLD | NEW |