From a31b0cc12b1550c126af2e58156d86250e14b640 Mon Sep 17 00:00:00 2001 From: "cpu@google.com" Date: Tue, 24 Feb 2009 02:46:38 +0000 Subject: Add destruction to AudioManager singleton for windows -Current unit tests sufice Review URL: http://codereview.chromium.org/28036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10248 0039d316-1c4b-4281-b951-d872f2087c98 --- media/audio/win/audio_manager_win.h | 1 + media/audio/win/audio_output_win.cc | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'media') diff --git a/media/audio/win/audio_manager_win.h b/media/audio/win/audio_manager_win.h index 05040ce..7ade9ec 100644 --- a/media/audio/win/audio_manager_win.h +++ b/media/audio/win/audio_manager_win.h @@ -34,6 +34,7 @@ class AudioManagerWin : public AudioManager { void ReleaseStream(AudioOutputStreamMockWin* stream); private: + friend void DestroyAudioManagerWin(void *); virtual ~AudioManagerWin(); DISALLOW_COPY_AND_ASSIGN(AudioManagerWin); }; diff --git a/media/audio/win/audio_output_win.cc b/media/audio/win/audio_output_win.cc index 6003fcd..ff45ccc 100644 --- a/media/audio/win/audio_output_win.cc +++ b/media/audio/win/audio_output_win.cc @@ -5,6 +5,7 @@ #include #include +#include "base/at_exit.h" #include "base/basictypes.h" #include "media/audio/audio_output.h" #include "media/audio/win/audio_manager_win.h" @@ -80,6 +81,7 @@ class AudioOutputStreamMockWin : public AudioOutputStream { namespace { AudioOutputStreamMockWin* g_last_mock_stream = NULL; +AudioManagerWin* g_audio_manager = NULL; void ReplaceLastMockStream(AudioOutputStreamMockWin* newer) { if (g_last_mock_stream) @@ -135,11 +137,16 @@ AudioManagerWin::~AudioManagerWin() { ReplaceLastMockStream(NULL); } -// TODO(cpu): Decide how to manage the lifetime of the AudioManager singleton. -// Right now we are leaking it. +void DestroyAudioManagerWin(void* param) { + delete g_audio_manager; + g_audio_manager = NULL; +} + AudioManager* AudioManager::GetAudioManager() { - static AudioManagerWin* audio_manager = NULL; - if (!audio_manager) - audio_manager = new AudioManagerWin(); - return audio_manager; + if (!g_audio_manager) { + g_audio_manager = new AudioManagerWin(); + base::AtExitManager::RegisterCallback(&DestroyAudioManagerWin, NULL); + } + return g_audio_manager; } + -- cgit v1.1