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

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: Set svn eol properties for a couple of files 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
« no previous file with comments | « media/audio/audio_input_unittest.cc ('k') | media/audio/audio_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_manager.h
===================================================================
--- media/audio/audio_manager.h (revision 114012)
+++ media/audio/audio_manager.h (working copy)
@@ -5,7 +5,10 @@
#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 +18,29 @@
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 {
+// TODO(tommi): Make the manager non-refcounted when it's safe to do so.
+// -> Bug 107087.
+class MEDIA_EXPORT AudioManager
+ : public base::RefCountedThreadSafe<AudioManager> {
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().
+ 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,28 +124,12 @@
// 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;
-
- 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.
- static AudioManager* CreateAudioManager();
+ friend class base::RefCountedThreadSafe<AudioManager>;
+ virtual ~AudioManager();
};
DISABLE_RUNNABLE_METHOD_REFCOUNT(AudioManager);
« no previous file with comments | « media/audio/audio_input_unittest.cc ('k') | media/audio/audio_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698