OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/audio/audio_manager.h" | 5 #include "media/audio/audio_manager.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | |
9 | 10 |
10 static bool g_destroy_called = false; | 11 // Used only to make sure we never create more than one instance. |
henrika (OOO until Aug 14)
2011/12/06 16:53:28
I have read the comment but still don't understand
tommi (sloooow) - chröme
2011/12/06 20:28:48
This is a safeguard to make sure that there exists
| |
11 static AudioManager* g_audio_manager = NULL; | 12 static AudioManager* g_audio_manager = NULL; |
12 | 13 |
13 // static | 14 AudioManager::AudioManager() { |
14 void AudioManager::Destroy(void* not_used) { | 15 CHECK(g_audio_manager == NULL); |
15 g_destroy_called = true; | 16 g_audio_manager = this; |
16 | |
17 if (g_audio_manager) { | |
18 g_audio_manager->Cleanup(); | |
19 | |
20 AudioManager* audio_manager = g_audio_manager; | |
21 g_audio_manager = NULL; | |
22 delete audio_manager; | |
23 } | |
24 } | 17 } |
25 | 18 |
26 // static | 19 AudioManager::~AudioManager() { |
27 AudioManager* AudioManager::GetAudioManager() { | 20 CHECK(g_audio_manager == this); |
28 if (!g_audio_manager && !g_destroy_called) { | 21 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 } | 22 } |
35 | 23 |
36 // static | 24 #ifndef NDEBUG |
37 bool AudioManager::SingletonExists() { | 25 void AudioManager::AddRef() const { |
38 return g_audio_manager != NULL; | 26 base::RefCountedThreadSafe<AudioManager>::AddRef(); |
39 } | 27 } |
40 | 28 |
29 void AudioManager::Release() const { | |
30 base::RefCountedThreadSafe<AudioManager>::Release(); | |
31 } | |
32 #endif | |
33 | |
41 // static | 34 // static |
42 void AudioManager::Resurrect() { | 35 scoped_refptr<AudioManager> AudioManager::Create() { |
43 g_destroy_called = false; | 36 AudioManager* ret = CreateAudioManager(); |
37 DCHECK(ret == g_audio_manager); | |
38 ret->Init(); | |
39 return ret; | |
44 } | 40 } |
OLD | NEW |