Commit f0fecc81 authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Set error handler for audio service in MediaDevicesManager in a posted task.

Setting it in the same task appears to cause reentrancy issues that result
in a browser crash.

A test is added in a follow-up CL at https://crrev.com/c/1068683

Bug: 845142
Change-Id: I1dfe690f9fb10743dba6d2165722b9f09142496e
Reviewed-on: https://chromium-review.googlesource.com/1070370
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561476}
parent 95d6100e
...@@ -296,26 +296,30 @@ class MediaDevicesManager::AudioServiceDeviceListener ...@@ -296,26 +296,30 @@ class MediaDevicesManager::AudioServiceDeviceListener
// Check if the service manager is managing the audio service. // Check if the service manager is managing the audio service.
connector->QueryService( connector->QueryService(
service_manager::Identity(audio::mojom::kServiceName), service_manager::Identity(audio::mojom::kServiceName),
base::BindOnce(&AudioServiceDeviceListener::DoConnectToService, base::BindOnce(&AudioServiceDeviceListener::ServiceQueried,
weak_factory_.GetWeakPtr(), connector)); weak_factory_.GetWeakPtr(), connector));
} }
void DoConnectToService(service_manager::Connector* connector, void ServiceQueried(service_manager::Connector* connector,
service_manager::mojom::ConnectResult connect_result, service_manager::mojom::ConnectResult connect_result,
const std::string& ignore) { const std::string& ignore) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!mojo_audio_device_notifier_);
DCHECK(!binding_);
// Do not connect if the service manager is not managing the audio service. // Do not connect if the service manager is not managing the audio service.
if (connect_result != service_manager::mojom::ConnectResult::SUCCEEDED) { if (connect_result != service_manager::mojom::ConnectResult::SUCCEEDED) {
LOG(WARNING) << "Audio service not available: " << connect_result; LOG(WARNING) << "Audio service not available: " << connect_result;
return; return;
} }
DoConnectToService(connector);
}
void DoConnectToService(service_manager::Connector* connector) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!mojo_audio_device_notifier_);
DCHECK(!binding_);
connector->BindInterface(audio::mojom::kServiceName, connector->BindInterface(audio::mojom::kServiceName,
mojo::MakeRequest(&mojo_audio_device_notifier_)); mojo::MakeRequest(&mojo_audio_device_notifier_));
mojo_audio_device_notifier_.set_connection_error_handler(base::BindOnce( mojo_audio_device_notifier_.set_connection_error_handler(base::BindOnce(
&MediaDevicesManager::AudioServiceDeviceListener::TryConnectToService, &MediaDevicesManager::AudioServiceDeviceListener::OnConnectionError,
weak_factory_.GetWeakPtr(), connector)); weak_factory_.GetWeakPtr(), connector));
audio::mojom::DeviceListenerPtr audio_device_listener_ptr; audio::mojom::DeviceListenerPtr audio_device_listener_ptr;
binding_.Bind(mojo::MakeRequest(&audio_device_listener_ptr)); binding_.Bind(mojo::MakeRequest(&audio_device_listener_ptr));
...@@ -323,6 +327,19 @@ class MediaDevicesManager::AudioServiceDeviceListener ...@@ -323,6 +327,19 @@ class MediaDevicesManager::AudioServiceDeviceListener
std::move(audio_device_listener_ptr)); std::move(audio_device_listener_ptr));
} }
void OnConnectionError(service_manager::Connector* connector) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
mojo_audio_device_notifier_.reset();
binding_.Close();
// Resetting the error handler in a posted task since doing it synchronously
// results in a browser crash. See https://crbug.com/845142.
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&AudioServiceDeviceListener::TryConnectToService,
weak_factory_.GetWeakPtr(), connector));
}
mojo::Binding<audio::mojom::DeviceListener> binding_; mojo::Binding<audio::mojom::DeviceListener> binding_;
audio::mojom::DeviceNotifierPtr mojo_audio_device_notifier_; audio::mojom::DeviceNotifierPtr mojo_audio_device_notifier_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment