OLD | NEW |
---|---|
1 | |
scherkus (not reviewing)
2011/12/10 00:16:52
!!!
tommi (sloooow) - chröme
2011/12/10 09:59:57
Done. thanks!!!
| |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
4 | 5 |
5 #include "media/audio/audio_manager.h" | 6 #include "media/audio/audio_manager.h" |
6 | 7 |
7 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | |
9 | 11 |
10 static bool g_destroy_called = false; | 12 // Used only to make sure we never create more than one instance. |
11 static AudioManager* g_audio_manager = NULL; | 13 static AudioManager* g_audio_manager = NULL; |
12 | 14 |
13 // static | 15 // Forward declaration of the platform specific AudioManager factory function. |
14 void AudioManager::Destroy(void* not_used) { | 16 AudioManager* CreateAudioManager(); |
15 g_destroy_called = true; | |
16 | 17 |
17 if (g_audio_manager) { | 18 AudioManager::AudioManager() { |
18 g_audio_manager->Cleanup(); | 19 CHECK(g_audio_manager == NULL); |
19 | 20 g_audio_manager = this; |
20 AudioManager* audio_manager = g_audio_manager; | |
21 g_audio_manager = NULL; | |
22 delete audio_manager; | |
23 } | |
24 } | 21 } |
25 | 22 |
26 // static | 23 AudioManager::~AudioManager() { |
27 AudioManager* AudioManager::GetAudioManager() { | 24 CHECK(g_audio_manager == this); |
28 if (!g_audio_manager && !g_destroy_called) { | 25 g_audio_manager = NULL; |
29 g_audio_manager = CreateAudioManager(); | |
30 g_audio_manager->Init(); | |
31 base::AtExitManager::RegisterCallback(&AudioManager::Destroy, NULL); | |
32 } | |
33 return g_audio_manager; | |
34 } | 26 } |
35 | 27 |
36 // static | 28 #ifndef NDEBUG |
37 bool AudioManager::SingletonExists() { | 29 void AudioManager::AddRef() const { |
38 return g_audio_manager != NULL; | 30 base::RefCountedThreadSafe<AudioManager>::AddRef(); |
39 } | 31 } |
40 | 32 |
33 void AudioManager::Release() const { | |
34 base::RefCountedThreadSafe<AudioManager>::Release(); | |
35 } | |
36 #endif | |
37 | |
41 // static | 38 // static |
42 void AudioManager::Resurrect() { | 39 scoped_refptr<AudioManager> AudioManager::Create() { |
43 g_destroy_called = false; | 40 AudioManager* ret = CreateAudioManager(); |
41 DCHECK(ret == g_audio_manager); | |
42 ret->Init(); | |
43 return ret; | |
44 } | 44 } |
OLD | NEW |