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

Unified Diff: media/audio/audio_manager.h

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: fixes content_browsertests and content_unittests Created 3 years, 9 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
Index: media/audio/audio_manager.h
diff --git a/media/audio/audio_manager.h b/media/audio/audio_manager.h
index cd91b399d6d4595ce60faf0131baa65f9cfd8bca..3f7f36200baf530c056a96f478a304c5ebee77f1 100644
--- a/media/audio/audio_manager.h
+++ b/media/audio/audio_manager.h
@@ -14,6 +14,7 @@
#include "base/memory/ref_counted.h"
#include "base/sequenced_task_runner_helpers.h"
#include "base/strings/string16.h"
+#include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "media/audio/audio_device_description.h"
#include "media/audio/audio_logging.h"
@@ -30,13 +31,6 @@ class AudioInputStream;
class AudioManager;
class AudioOutputStream;
-class MEDIA_EXPORT AudioManagerDeleter {
- public:
- void operator()(const AudioManager* instance) const;
-};
-using ScopedAudioManagerPtr =
- std::unique_ptr<AudioManager, AudioManagerDeleter>;
-
// Manages all audio resources. Provides some convenience functions that avoid
// the need to provide iterators over the existing streams.
//
@@ -44,6 +38,8 @@ using ScopedAudioManagerPtr =
// thread hang is detected, it is reported to UMA.
class MEDIA_EXPORT AudioManager {
public:
+ virtual ~AudioManager();
+
// Construct the audio manager; only one instance is allowed.
// The returned instance must be deleted on AudioManager::GetTaskRunnner().
//
@@ -63,7 +59,7 @@ class MEDIA_EXPORT AudioManager {
//
// |file_task_runner| is used for audio debug recordings and is the task
// runner to do file output operations on.
- static ScopedAudioManagerPtr Create(
+ static std::unique_ptr<AudioManager> Create(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
@@ -71,7 +67,7 @@ class MEDIA_EXPORT AudioManager {
// A convenience wrapper of AudioManager::Create for testing.
// The given |task_runner| is shared for both audio io and heavyweight tasks.
- static ScopedAudioManagerPtr CreateForTesting(
+ static std::unique_ptr<AudioManager> CreateForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
// Starts monitoring AudioManager task runner for hangs.
@@ -95,6 +91,10 @@ class MEDIA_EXPORT AudioManager {
// like src/chrome.
static AudioManager* Get();
+ // Releases all audio resources.
+ // Must be called on the audio thread.
+ virtual void Shutdown() = 0;
+
// Returns true if the OS reports existence of audio devices. This does not
// guarantee that the existing devices support all formats and sample rates.
virtual bool HasAudioOutputDevices() = 0;
@@ -265,7 +265,6 @@ class MEDIA_EXPORT AudioManager {
AudioManager(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner);
- virtual ~AudioManager();
// Initializes output debug recording. Can be called on any thread; will post
// to the audio thread if not called on it.
@@ -273,11 +272,9 @@ class MEDIA_EXPORT AudioManager {
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) = 0;
private:
- friend class base::DeleteHelper<AudioManager>;
- friend class AudioManagerDeleter;
-
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
+ base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(AudioManager);
};

Powered by Google App Engine
This is Rietveld 408576698