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

Side by Side Diff: media/audio/audio_manager_base.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/audio_manager_base.h" 5 #include "media/audio/audio_manager_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 max_num_output_streams_(kDefaultMaxOutputStreams), 91 max_num_output_streams_(kDefaultMaxOutputStreams),
92 max_num_input_streams_(kDefaultMaxInputStreams), 92 max_num_input_streams_(kDefaultMaxInputStreams),
93 num_output_streams_(0), 93 num_output_streams_(0),
94 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we 94 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we
95 // don't block the UI thread when swapping devices. 95 // don't block the UI thread when swapping devices.
96 output_listeners_( 96 output_listeners_(
97 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), 97 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY),
98 audio_log_factory_(audio_log_factory) {} 98 audio_log_factory_(audio_log_factory) {}
99 99
100 AudioManagerBase::~AudioManagerBase() { 100 AudioManagerBase::~AudioManagerBase() {
101 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
102
103 // All the output streams should have been deleted. 101 // All the output streams should have been deleted.
104 CHECK_EQ(0, num_output_streams_); 102 CHECK_EQ(0, num_output_streams_);
105 // All the input streams should have been deleted. 103 // All the input streams should have been deleted.
106 CHECK(input_streams_.empty()); 104 CHECK(input_streams_.empty());
107 } 105 }
108 106
109 base::string16 AudioManagerBase::GetAudioInputDeviceModel() { 107 base::string16 AudioManagerBase::GetAudioInputDeviceModel() {
110 return base::string16(); 108 return base::string16();
111 } 109 }
112 110
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // processing task queue at this point. So even if tasks to close the 351 // processing task queue at this point. So even if tasks to close the
354 // streams are enqueued, they would not run leading to CHECKs getting hit 352 // streams are enqueued, they would not run leading to CHECKs getting hit
355 // in the destructor about open streams. Close them explicitly here. 353 // in the destructor about open streams. Close them explicitly here.
356 // crbug.com/608049. 354 // crbug.com/608049.
357 for (auto iter = input_streams_.begin(); iter != input_streams_.end();) { 355 for (auto iter = input_streams_.begin(); iter != input_streams_.end();) {
358 // Note: Closing the stream will invalidate the iterator. 356 // Note: Closing the stream will invalidate the iterator.
359 // Increment the iterator before closing the stream. 357 // Increment the iterator before closing the stream.
360 AudioInputStream* stream = *iter++; 358 AudioInputStream* stream = *iter++;
361 stream->Close(); 359 stream->Close();
362 } 360 }
363 CHECK(input_streams_.empty());
364 #endif // OS_MACOSX 361 #endif // OS_MACOSX
365 } 362 }
366 363
367 void AudioManagerBase::AddOutputDeviceChangeListener( 364 void AudioManagerBase::AddOutputDeviceChangeListener(
368 AudioDeviceListener* listener) { 365 AudioDeviceListener* listener) {
369 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 366 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
370 output_listeners_.AddObserver(listener); 367 output_listeners_.AddObserver(listener);
371 } 368 }
372 369
373 void AudioManagerBase::RemoveOutputDeviceChangeListener( 370 void AudioManagerBase::RemoveOutputDeviceChangeListener(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 std::move(task_runner), std::move(file_task_runner)); 484 std::move(task_runner), std::move(file_task_runner));
488 } 485 }
489 486
490 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, 487 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input,
491 int max_output) { 488 int max_output) {
492 max_num_output_streams_ = max_output; 489 max_num_output_streams_ = max_output;
493 max_num_input_streams_ = max_input; 490 max_num_input_streams_ = max_input;
494 } 491 }
495 492
496 } // namespace media 493 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698