Index: media/audio/audio_manager.cc |
=================================================================== |
--- media/audio/audio_manager.cc (revision 113173) |
+++ media/audio/audio_manager.cc (working copy) |
@@ -1,3 +1,4 @@ |
+ |
scherkus (not reviewing)
2011/12/10 00:16:52
!!!
tommi (sloooow) - chröme
2011/12/10 09:59:57
Done. thanks!!!
|
// Copyright (c) 2011 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. |
@@ -6,39 +7,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; |
} |