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

Unified Diff: media/audio/audio_thread_impl.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/audio_thread_impl.h ('k') | media/audio/cras/audio_manager_cras.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_thread_impl.cc
diff --git a/media/audio/audio_thread_impl.cc b/media/audio/audio_thread_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f7c52863279237966b7998c025939bedd588039b
--- /dev/null
+++ b/media/audio/audio_thread_impl.cc
@@ -0,0 +1,48 @@
+// Copyright 2016 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/audio_thread_impl.h"
+
+#include "base/threading/thread_task_runner_handle.h"
+
+namespace media {
+
+AudioThreadImpl::AudioThreadImpl() : thread_("AudioThread") {
+#if defined(OS_WIN)
+ thread_.init_com_with_mta(true);
+#endif
+ CHECK(thread_.Start());
+
+#if defined(OS_MACOSX)
+ // On Mac, the audio task runner must belong to the main thread.
+ // See http://crbug.com/158170.
+ task_runner_ = base::ThreadTaskRunnerHandle::Get();
+#else
+ task_runner_ = thread_.task_runner();
+#endif
+ worker_task_runner_ = thread_.task_runner();
+}
+
+AudioThreadImpl::~AudioThreadImpl() {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+}
+
+void AudioThreadImpl::Stop() {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+
+ // Note that on MACOSX, we can still have tasks posted on the |task_runner_|,
+ // since it is the main thread task runner and we do not stop the main thread.
+ // But this is fine becuase none of those tasks will actually run.
+ thread_.Stop();
+}
+
+base::SingleThreadTaskRunner* AudioThreadImpl::GetTaskRunner() {
+ return task_runner_.get();
+}
+
+base::SingleThreadTaskRunner* AudioThreadImpl::GetWorkerTaskRunner() {
+ return worker_task_runner_.get();
+}
+
+} // namespace media
« no previous file with comments | « media/audio/audio_thread_impl.h ('k') | media/audio/cras/audio_manager_cras.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698