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

Unified Diff: media/audio/audio_manager.h

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Address comments from Avi Created 9 years 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
===================================================================
--- media/audio/audio_manager.h (revision 113173)
+++ media/audio/audio_manager.h (working copy)
@@ -5,7 +5,9 @@
#ifndef MEDIA_AUDIO_AUDIO_MANAGER_H_
#define MEDIA_AUDIO_AUDIO_MANAGER_H_
+#include <string>
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "base/task.h"
#include "media/audio/audio_device_name.h"
@@ -15,14 +17,28 @@
class AudioOutputStream;
class MessageLoop;
-// TODO(sergeyu): In this interface and some other places AudioParameters struct
-// is passed by value. It is better to change it to const reference.
-
// Manages all audio resources. In particular it owns the AudioOutputStream
// objects. Provides some convenience functions that avoid the need to provide
// iterators over the existing streams.
-class MEDIA_EXPORT AudioManager {
+class MEDIA_EXPORT AudioManager
+ : public base::RefCountedThreadSafe<AudioManager> {
henrika (OOO until Aug 14) 2011/12/07 10:08:34 nit, indent two more?
tommi (sloooow) - chröme 2011/12/07 12:26:44 Done.
public:
+ AudioManager();
+
+#ifndef NDEBUG
+ // Allow base classes in debug builds to override the reference counting
+ // functions. This allows us to protect against regressions and enforce
+ // correct usage. The default implementation just calls the base class.
+ virtual void AddRef() const;
+ virtual void Release() const;
+#endif
+
+ // Use to construct the audio manager.
+ // NOTE: There should only be one instance. If you try to create more than
+ // one instance, it will hit a CHECK().
+ // TODO(cpu): Define threading requirements for interacting with AudioManager.
henrika (OOO until Aug 14) 2011/12/07 10:08:34 Still a valid comment?
tommi (sloooow) - chröme 2011/12/07 12:26:44 Nope. Removed.
+ static scoped_refptr<AudioManager> Create();
+
// 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;
@@ -106,27 +122,15 @@
// Returns message loop used for audio IO.
virtual MessageLoop* GetMessageLoop() = 0;
- // Get AudioManager singleton.
- // TODO(cpu): Define threading requirements for interacting with AudioManager.
- static AudioManager* GetAudioManager();
-
protected:
- virtual ~AudioManager() {}
-
- // Called from GetAudioManager() to initialiaze the instance.
+ // Called from Create() to initialize the instance.
virtual void Init() = 0;
- // Called by Destroy() to cleanup the instance before destruction.
- virtual void Cleanup() = 0;
+ friend class base::RefCountedThreadSafe<AudioManager>;
+ virtual ~AudioManager();
private:
- // Allow unit tests to delete and recreate the singleton.
- friend class AutoAudioManagerCleanup;
- static void Destroy(void*);
- static bool SingletonExists();
- static void Resurrect();
-
- // Called by GetAudioManager() to create platform-specific audio manager.
+ // Called by Create() to create platform-specific audio manager.
static AudioManager* CreateAudioManager();
};

Powered by Google App Engine
This is Rietveld 408576698