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

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

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: fixes content_browsertests and content_unittests Created 3 years, 8 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/mock_audio_manager.h" 5 #include "media/audio/mock_audio_manager.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "media/base/audio_parameters.h" 10 #include "media/base/audio_parameters.h"
11 11
12 namespace media { 12 namespace media {
13 13
14 void MockAudioManager::Deleter::operator()(
15 const MockAudioManager* instance) const {
16 CHECK(instance);
17 if (instance->GetTaskRunner()->BelongsToCurrentThread()) {
18 delete instance;
19 return;
20 }
21 // AudioManager must be destroyed on the audio thread.
22 if (!instance->GetTaskRunner()->DeleteSoon(FROM_HERE, instance)) {
23 LOG(WARNING) << "Failed to delete AudioManager instance.";
24 }
25 }
26
27 MockAudioManager::MockAudioManager( 14 MockAudioManager::MockAudioManager(
28 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 15 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
29 : AudioManager(task_runner, task_runner) {} 16 : AudioManager(task_runner, task_runner) {}
30 17
31 MockAudioManager::~MockAudioManager() { 18 MockAudioManager::~MockAudioManager() {
32 } 19 }
33 20
21 void MockAudioManager::Shutdown() {}
22
34 bool MockAudioManager::HasAudioOutputDevices() { 23 bool MockAudioManager::HasAudioOutputDevices() {
35 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 24 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
36 return has_output_devices_; 25 return has_output_devices_;
37 } 26 }
38 27
39 bool MockAudioManager::HasAudioInputDevices() { 28 bool MockAudioManager::HasAudioInputDevices() {
40 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 29 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
41 return has_input_devices_; 30 return has_input_devices_;
42 } 31 }
43 32
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 GetDeviceDescriptionsCallback callback) { 150 GetDeviceDescriptionsCallback callback) {
162 get_input_device_descriptions_cb_ = std::move(callback); 151 get_input_device_descriptions_cb_ = std::move(callback);
163 } 152 }
164 153
165 void MockAudioManager::SetOutputDeviceDescriptionsCallback( 154 void MockAudioManager::SetOutputDeviceDescriptionsCallback(
166 GetDeviceDescriptionsCallback callback) { 155 GetDeviceDescriptionsCallback callback) {
167 get_output_device_descriptions_cb_ = std::move(callback); 156 get_output_device_descriptions_cb_ = std::move(callback);
168 } 157 }
169 158
170 } // namespace media. 159 } // namespace media.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698