OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_system.h" | 5 #include "media/audio/audio_system.h" |
| 6 #include "base/single_thread_task_runner.h" |
6 | 7 |
7 namespace media { | 8 namespace media { |
8 | 9 |
9 static AudioSystem* g_last_created = nullptr; | 10 static AudioSystem* g_last_created = nullptr; |
10 | 11 |
| 12 void AudioSystem::OnAudioThreadDeleter::operator()( |
| 13 const AudioSystem* instance) const { |
| 14 CHECK(instance); |
| 15 AudioSystem::ClearInstance(instance); |
| 16 |
| 17 if (instance->GetTaskRunner()->BelongsToCurrentThread()) { |
| 18 delete instance; |
| 19 return; |
| 20 } |
| 21 if (!instance->GetTaskRunner()->DeleteSoon(FROM_HERE, instance)) { |
| 22 LOG(WARNING) << "Failed to delete AudioManager instance."; |
| 23 } |
| 24 } |
| 25 |
11 AudioSystem::~AudioSystem() {} | 26 AudioSystem::~AudioSystem() {} |
12 | 27 |
13 AudioSystem* AudioSystem::Get() { | 28 AudioSystem* AudioSystem::Get() { |
14 return g_last_created; | 29 return g_last_created; |
15 } | 30 } |
16 | 31 |
17 void AudioSystem::SetInstance(AudioSystem* audio_system) { | 32 void AudioSystem::SetInstance(AudioSystem* audio_system) { |
18 DCHECK(audio_system); | 33 DCHECK(audio_system); |
19 if (g_last_created && audio_system) { | 34 if (g_last_created && audio_system) { |
20 // We create multiple instances of AudioSystem only when testing. | 35 // We create multiple instances of AudioSystem only when testing. |
21 // We should not encounter this case in production. | 36 // We should not encounter this case in production. |
22 LOG(WARNING) << "Multiple instances of AudioSystem detected"; | 37 LOG(WARNING) << "Multiple instances of AudioSystem detected"; |
23 } | 38 } |
24 g_last_created = audio_system; | 39 g_last_created = audio_system; |
25 } | 40 } |
26 | 41 |
27 void AudioSystem::ClearInstance(const AudioSystem* audio_system) { | 42 void AudioSystem::ClearInstance(const AudioSystem* audio_system) { |
28 DCHECK(audio_system); | 43 DCHECK(audio_system); |
29 if (g_last_created != audio_system) { | 44 if (g_last_created != audio_system) { |
30 // We create multiple instances of AudioSystem only when testing. | 45 // We create multiple instances of AudioSystem only when testing. |
31 // We should not encounter this case in production. | 46 // We should not encounter this case in production. |
32 LOG(WARNING) << "Multiple instances of AudioSystem detected"; | 47 LOG(WARNING) << "Multiple instances of AudioSystem detected"; |
33 } else { | 48 } else { |
34 g_last_created = nullptr; | 49 g_last_created = nullptr; |
35 } | 50 } |
36 } | 51 } |
37 | 52 |
38 } // namespace media | 53 } // namespace media |
OLD | NEW |