Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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>()), | |
|
o1ka
2016/11/24 14:34:01
Why?
Max Morin
2016/11/24 14:49:03
This was also a drive-by fix :). Reading on chromi
o1ka
2016/11/24 15:11:54
Ok. Though I have not really seen a problem with t
| |
| 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 Loading... | |
| 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: In the case of a shutdown, the task to delete |audio_manager_| is |
| 193 base::Bind(&GetDeviceParametersOnDeviceThread, raw_device_id), | 195 // posted to the audio thread after the IO thread is stopped, so the task |
| 196 // to delete the audio manager hasn't been posted yet. This means that | |
|
o1ka
2016/11/24 14:34:01
task to delete -> destructor?
Max Morin
2016/11/24 14:49:03
Not really? The task will delete the pointer (if y
o1ka
2016/11/24 15:11:54
:) Acknowledged.
| |
| 197 // unretained is safe here. | |
| 198 // Mac is a special case. Since the audio manager lives on the UI thread | |
| 199 // on Mac, this task is posted to the UI thread, but tasks posted to the | |
| 200 // UI task runner will be ignored when the shutdown has progressed to | |
| 201 // deleting the audio manager, so this is still safe. | |
| 202 audio_manager_->GetTaskRunner(), FROM_HERE, | |
| 203 base::Bind(&GetDeviceParametersOnDeviceThread, | |
| 204 base::Unretained(audio_manager_), raw_device_id), | |
| 194 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived, | 205 base::Bind(&AudioOutputAuthorizationHandler::DeviceParametersReceived, |
| 195 weak_factory_.GetWeakPtr(), std::move(cb), false, | 206 weak_factory_.GetWeakPtr(), std::move(cb), false, |
| 196 raw_device_id)); | 207 raw_device_id)); |
| 197 } | 208 } |
| 198 | 209 |
| 199 void AudioOutputAuthorizationHandler::DeviceParametersReceived( | 210 void AudioOutputAuthorizationHandler::DeviceParametersReceived( |
| 200 AuthorizationCompletedCallback cb, | 211 AuthorizationCompletedCallback cb, |
| 201 bool should_send_id, | 212 bool should_send_id, |
| 202 const std::string& raw_device_id, | 213 const std::string& raw_device_id, |
| 203 const media::AudioParameters& output_params) const { | 214 const media::AudioParameters& output_params) const { |
| 204 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 205 DCHECK(!raw_device_id.empty()); | 216 DCHECK(!raw_device_id.empty()); |
| 206 | 217 |
| 207 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, | 218 cb.Run(media::OUTPUT_DEVICE_STATUS_OK, should_send_id, |
| 208 output_params.IsValid() ? output_params | 219 output_params.IsValid() ? output_params |
| 209 : TryToFixAudioParameters(output_params), | 220 : TryToFixAudioParameters(output_params), |
| 210 raw_device_id); | 221 raw_device_id); |
| 211 } | 222 } |
| 212 | 223 |
| 213 } // namespace content | 224 } // namespace content |
| OLD | NEW |