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

Side by Side 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 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/renderer_host/media/audio_output_authorization_handler .h" 5 #include "content/browser/renderer_host/media/audio_output_authorization_handler .h"
6 6
7 #include "base/task_runner_util.h" 7 #include "base/task_runner_util.h"
8 #include "content/browser/bad_message.h" 8 #include "content/browser/bad_message.h"
9 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 9 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 28
29 // If hardware parameters are still invalid, use dummy parameters with 29 // If hardware parameters are still invalid, use dummy parameters with
30 // fake audio path and let the client handle the error. 30 // fake audio path and let the client handle the error.
31 return params_copy.IsValid() 31 return params_copy.IsValid()
32 ? params_copy 32 ? params_copy
33 : media::AudioParameters::UnavailableDeviceParams(); 33 : media::AudioParameters::UnavailableDeviceParams();
34 } 34 }
35 35
36 media::AudioParameters GetDeviceParametersOnDeviceThread( 36 media::AudioParameters GetDeviceParametersOnDeviceThread(
37 media::AudioManager* audio_manager,
37 const std::string& unique_id) { 38 const std::string& unique_id) {
38 media::AudioManager* audio_manager = media::AudioManager::Get();
39 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); 39 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread());
40 40
41 return media::AudioDeviceDescription::IsDefaultDevice(unique_id) 41 return media::AudioDeviceDescription::IsDefaultDevice(unique_id)
42 ? audio_manager->GetDefaultOutputStreamParameters() 42 ? audio_manager->GetDefaultOutputStreamParameters()
43 : audio_manager->GetOutputStreamParameters(unique_id); 43 : audio_manager->GetOutputStreamParameters(unique_id);
44 } 44 }
45 45
46 } // namespace 46 } // namespace
47 47
48 namespace content { 48 namespace content {
49 49
50 AudioOutputAuthorizationHandler::AudioOutputAuthorizationHandler( 50 AudioOutputAuthorizationHandler::AudioOutputAuthorizationHandler(
51 media::AudioManager* audio_manager,
51 MediaStreamManager* media_stream_manager, 52 MediaStreamManager* media_stream_manager,
52 int render_process_id, 53 int render_process_id,
53 const std::string& salt) 54 const std::string& salt)
54 : media_stream_manager_(media_stream_manager), 55 : audio_manager_(audio_manager),
55 permission_checker_(new MediaDevicesPermissionChecker()), 56 media_stream_manager_(media_stream_manager),
57 permission_checker_(base::MakeUnique<MediaDevicesPermissionChecker>()),
56 render_process_id_(render_process_id), 58 render_process_id_(render_process_id),
57 salt_(salt), 59 salt_(salt),
58 weak_factory_(this) { 60 weak_factory_(this) {
59 DCHECK(media_stream_manager_); 61 DCHECK(media_stream_manager_);
60 } 62 }
61 63
62 void AudioOutputAuthorizationHandler::OverridePermissionsForTesting( 64 void AudioOutputAuthorizationHandler::OverridePermissionsForTesting(
63 bool override_value) { 65 bool override_value) {
64 DCHECK_CURRENTLY_ON(BrowserThread::IO); 66 DCHECK_CURRENTLY_ON(BrowserThread::IO);
65 permission_checker_.reset(new MediaDevicesPermissionChecker(override_value)); 67 permission_checker_.reset(new MediaDevicesPermissionChecker(override_value));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false, 184 cb.Run(media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, false,
183 media::AudioParameters::UnavailableDeviceParams(), std::string()); 185 media::AudioParameters::UnavailableDeviceParams(), std::string());
184 } 186 }
185 187
186 void AudioOutputAuthorizationHandler::GetDeviceParameters( 188 void AudioOutputAuthorizationHandler::GetDeviceParameters(
187 AuthorizationCompletedCallback cb, 189 AuthorizationCompletedCallback cb,
188 const std::string& raw_device_id) const { 190 const std::string& raw_device_id) const {
189 DCHECK_CURRENTLY_ON(BrowserThread::IO); 191 DCHECK_CURRENTLY_ON(BrowserThread::IO);
190 DCHECK(!raw_device_id.empty()); 192 DCHECK(!raw_device_id.empty());
191 base::PostTaskAndReplyWithResult( 193 base::PostTaskAndReplyWithResult(
192 media::AudioManager::Get()->GetTaskRunner(), FROM_HERE, 194 // 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.
193 base::Bind(&GetDeviceParametersOnDeviceThread, raw_device_id), 195 // 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.
196 // but tasks posted to the UI task runner will be ignored when the
197 // shutdown has progressed to deleting the audio manager, so this is still
198 // safe.
199 audio_manager_->GetTaskRunner(), FROM_HERE,
200 base::Bind(&GetDeviceParametersOnDeviceThread,
201 base::Unretained(audio_manager_), raw_device_id),
194 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived, 202 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived,
195 weak_factory_.GetWeakPtr(), std::move(cb), false, 203 weak_factory_.GetWeakPtr(), std::move(cb), false,
196 raw_device_id)); 204 raw_device_id));
197 } 205 }
198 206
199 void AudioOutputAuthorizationHandler::DeviceParametersReceived( 207 void AudioOutputAuthorizationHandler::DeviceParametersReceived(
200 AuthorizationCompletedCallback cb, 208 AuthorizationCompletedCallback cb,
201 bool should_send_id, 209 bool should_send_id,
202 const std::string& raw_device_id, 210 const std::string& raw_device_id,
203 const media::AudioParameters& output_params) const { 211 const media::AudioParameters& output_params) const {
204 DCHECK_CURRENTLY_ON(BrowserThread::IO); 212 DCHECK_CURRENTLY_ON(BrowserThread::IO);
205 DCHECK(!raw_device_id.empty()); 213 DCHECK(!raw_device_id.empty());
206 214
207 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, 215 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id,
208 output_params.IsValid() ? output_params 216 output_params.IsValid() ? output_params
209 : TryToFixAudioParameters(output_params), 217 : TryToFixAudioParameters(output_params),
210 raw_device_id); 218 raw_device_id);
211 } 219 }
212 220
213 } // namespace content 221 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698