| 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 | 9 |
| 10 static bool g_destroy_called = false; | 10 static bool g_destroy_called = false; |
| 11 static AudioManager* g_audio_manager = NULL; | 11 static AudioManager* g_audio_manager = NULL; |
| 12 | 12 |
| 13 // static | 13 // static |
| 14 void AudioManager::Destroy(void* not_used) { | 14 void AudioManager::Destroy(void* not_used) { |
| 15 g_destroy_called = true; | 15 g_destroy_called = true; |
| 16 | 16 |
| 17 g_audio_manager->Cleanup(); | 17 if (g_audio_manager) { |
| 18 g_audio_manager->Cleanup(); |
| 18 | 19 |
| 19 AudioManager* audio_manager = g_audio_manager; | 20 AudioManager* audio_manager = g_audio_manager; |
| 20 g_audio_manager = NULL; | 21 g_audio_manager = NULL; |
| 21 delete audio_manager; | 22 delete audio_manager; |
| 23 } |
| 22 } | 24 } |
| 23 | 25 |
| 24 // static | 26 // static |
| 25 AudioManager* AudioManager::GetAudioManager() { | 27 AudioManager* AudioManager::GetAudioManager() { |
| 26 if (!g_audio_manager && !g_destroy_called) { | 28 if (!g_audio_manager && !g_destroy_called) { |
| 27 g_audio_manager = CreateAudioManager(); | 29 g_audio_manager = CreateAudioManager(); |
| 28 g_audio_manager->Init(); | 30 g_audio_manager->Init(); |
| 29 base::AtExitManager::RegisterCallback(&AudioManager::Destroy, NULL); | 31 base::AtExitManager::RegisterCallback(&AudioManager::Destroy, NULL); |
| 30 } | 32 } |
| 31 return g_audio_manager; | 33 return g_audio_manager; |
| 32 } | 34 } |
| OLD | NEW |