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

Unified Diff: content/browser/renderer_host/media/audio_output_authorization_handler.cc

Issue 2529853002: Fix shutdown crash in AudioOutputAuthorizationHandler. (Closed)
Patch Set: Add mac comment. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/audio_output_authorization_handler.cc
diff --git a/content/browser/renderer_host/media/audio_output_authorization_handler.cc b/content/browser/renderer_host/media/audio_output_authorization_handler.cc
index 3bc765fdc86ec5611fa73f2a2e0c39320abae5fb..bbafb5425b26db5956fc29a4c43a2a57767e20cf 100644
--- a/content/browser/renderer_host/media/audio_output_authorization_handler.cc
+++ b/content/browser/renderer_host/media/audio_output_authorization_handler.cc
@@ -34,8 +34,8 @@ media::AudioParameters TryToFixAudioParameters(
}
media::AudioParameters GetDeviceParametersOnDeviceThread(
+ media::AudioManager* audio_manager,
const std::string& unique_id) {
- media::AudioManager* audio_manager = media::AudioManager::Get();
DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread());
return media::AudioDeviceDescription::IsDefaultDevice(unique_id)
@@ -48,11 +48,13 @@ media::AudioParameters GetDeviceParametersOnDeviceThread(
namespace content {
AudioOutputAuthorizationHandler::AudioOutputAuthorizationHandler(
+ media::AudioManager* audio_manager,
MediaStreamManager* media_stream_manager,
int render_process_id,
const std::string& salt)
- : media_stream_manager_(media_stream_manager),
- permission_checker_(new MediaDevicesPermissionChecker()),
+ : audio_manager_(audio_manager),
+ media_stream_manager_(media_stream_manager),
+ permission_checker_(base::MakeUnique<MediaDevicesPermissionChecker>()),
render_process_id_(render_process_id),
salt_(salt),
weak_factory_(this) {
@@ -189,8 +191,14 @@ void AudioOutputAuthorizationHandler::GetDeviceParameters(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!raw_device_id.empty());
base::PostTaskAndReplyWithResult(
- media::AudioManager::Get()->GetTaskRunner(), FROM_HERE,
- base::Bind(&GetDeviceParametersOnDeviceThread, raw_device_id),
+ // Note: |*audio_manager_| outlives the IO thread, so unretained is safe.
o1ka 2016/11/24 13:17:35 |audio_manager_| is deleted on audio manager threa
Max Morin 2016/11/24 14:12:20 Well, it's a bit more complicated since audio mana
o1ka 2016/11/24 14:34:01 Yes, it's exactly what I'm pointing to. It's not e
Max Morin 2016/11/24 14:49:03 Done in the latest patch set.
o1ka 2016/11/24 15:11:54 Acknowledged.
+ // Mac is a special case. On Mac, this task is posted to the UI thread,
o1ka 2016/11/24 13:17:35 because audio managers tuns on UI thread there.
Max Morin 2016/11/24 14:12:20 Done.
+ // but tasks posted to the UI task runner will be ignored when the
+ // shutdown has progressed to deleting the audio manager, so this is still
+ // safe.
+ audio_manager_->GetTaskRunner(), FROM_HERE,
+ base::Bind(&GetDeviceParametersOnDeviceThread,
+ base::Unretained(audio_manager_), raw_device_id),
base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived,
weak_factory_.GetWeakPtr(), std::move(cb), false,
raw_device_id));

Powered by Google App Engine
This is Rietveld 408576698