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

Unified Diff: media/audio/audio_manager.cc

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_manager.h ('k') | media/audio/audio_manager_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_manager.cc
===================================================================
--- media/audio/audio_manager.cc (revision 114012)
+++ media/audio/audio_manager.cc (working copy)
@@ -6,39 +6,38 @@
#include "base/at_exit.h"
#include "base/logging.h"
+#include "base/message_loop.h"
-static bool g_destroy_called = false;
+// Used only to make sure we never create more than one instance.
static AudioManager* g_audio_manager = NULL;
-// static
-void AudioManager::Destroy(void* not_used) {
- g_destroy_called = true;
+// Forward declaration of the platform specific AudioManager factory function.
+AudioManager* CreateAudioManager();
- if (g_audio_manager) {
- g_audio_manager->Cleanup();
+AudioManager::AudioManager() {
+ CHECK(g_audio_manager == NULL);
+ g_audio_manager = this;
+}
- AudioManager* audio_manager = g_audio_manager;
- g_audio_manager = NULL;
- delete audio_manager;
- }
+AudioManager::~AudioManager() {
+ CHECK(g_audio_manager == this);
+ g_audio_manager = NULL;
}
-// static
-AudioManager* AudioManager::GetAudioManager() {
- if (!g_audio_manager && !g_destroy_called) {
- g_audio_manager = CreateAudioManager();
- g_audio_manager->Init();
- base::AtExitManager::RegisterCallback(&AudioManager::Destroy, NULL);
- }
- return g_audio_manager;
+#ifndef NDEBUG
+void AudioManager::AddRef() const {
+ base::RefCountedThreadSafe<AudioManager>::AddRef();
}
-// static
-bool AudioManager::SingletonExists() {
- return g_audio_manager != NULL;
+void AudioManager::Release() const {
+ base::RefCountedThreadSafe<AudioManager>::Release();
}
+#endif
// static
-void AudioManager::Resurrect() {
- g_destroy_called = false;
+scoped_refptr<AudioManager> AudioManager::Create() {
+ AudioManager* ret = CreateAudioManager();
+ DCHECK(ret == g_audio_manager);
+ ret->Init();
+ return ret;
}
« no previous file with comments | « media/audio/audio_manager.h ('k') | media/audio/audio_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698