Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: media/audio/audio_manager.cc

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_manager.h ('k') | media/audio/audio_manager_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
11 static AudioManager* g_audio_manager = NULL; 12 static AudioManager* g_audio_manager = NULL;
12 13
13 // static 14 // Forward declaration of the platform specific AudioManager factory function.
14 void AudioManager::Destroy(void* not_used) { 15 AudioManager* CreateAudioManager();
15 g_destroy_called = true;
16 16
17 if (g_audio_manager) { 17 AudioManager::AudioManager() {
18 g_audio_manager->Cleanup(); 18 CHECK(g_audio_manager == NULL);
19 19 g_audio_manager = this;
20 AudioManager* audio_manager = g_audio_manager;
21 g_audio_manager = NULL;
22 delete audio_manager;
23 }
24 } 20 }
25 21
26 // static 22 AudioManager::~AudioManager() {
27 AudioManager* AudioManager::GetAudioManager() { 23 CHECK(g_audio_manager == this);
28 if (!g_audio_manager && !g_destroy_called) { 24 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 } 25 }
35 26
36 // static 27 #ifndef NDEBUG
37 bool AudioManager::SingletonExists() { 28 void AudioManager::AddRef() const {
38 return g_audio_manager != NULL; 29 base::RefCountedThreadSafe<AudioManager>::AddRef();
39 } 30 }
40 31
32 void AudioManager::Release() const {
33 base::RefCountedThreadSafe<AudioManager>::Release();
34 }
35 #endif
36
41 // static 37 // static
42 void AudioManager::Resurrect() { 38 scoped_refptr<AudioManager> AudioManager::Create() {
43 g_destroy_called = false; 39 AudioManager* ret = CreateAudioManager();
40 DCHECK(ret == g_audio_manager);
41 ret->Init();
42 return ret;
44 } 43 }
OLDNEW
« no previous file with comments | « media/audio/audio_manager.h ('k') | media/audio/audio_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698