Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: media/audio/test_audio_thread.cc

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/test_audio_thread.h ('k') | media/audio/win/audio_low_latency_input_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/test_audio_thread.cc
diff --git a/media/audio/test_audio_thread.cc b/media/audio/test_audio_thread.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8b4cebcd94dc4c48ed832555983f9564a229f1cb
--- /dev/null
+++ b/media/audio/test_audio_thread.cc
@@ -0,0 +1,47 @@
+// Copyright 2017 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 "media/audio/test_audio_thread.h"
+
+#include "base/run_loop.h"
+#include "base/threading/thread_task_runner_handle.h"
+
+namespace media {
+
+TestAudioThread::TestAudioThread() : TestAudioThread(false) {}
+
+TestAudioThread::TestAudioThread(bool use_real_thread) {
+ if (use_real_thread) {
+ thread_ = base::MakeUnique<base::Thread>("AudioThread");
+#if defined(OS_WIN)
+ thread_->init_com_with_mta(true);
+#endif
+ CHECK(thread_->Start());
+ task_runner_ = thread_->task_runner();
+ } else {
+ task_runner_ = base::ThreadTaskRunnerHandle::Get();
+ }
+}
+
+TestAudioThread::~TestAudioThread() {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+}
+
+void TestAudioThread::Stop() {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ if (thread_)
+ thread_->Stop();
+ else
+ base::RunLoop().RunUntilIdle();
+}
+
+base::SingleThreadTaskRunner* TestAudioThread::GetTaskRunner() {
+ return task_runner_.get();
+}
+
+base::SingleThreadTaskRunner* TestAudioThread::GetWorkerTaskRunner() {
+ return task_runner_.get();
+}
+
+} // namespace media
« no previous file with comments | « media/audio/test_audio_thread.h ('k') | media/audio/win/audio_low_latency_input_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698