Commit 0919113a authored by Tommy Steimel's avatar Tommy Steimel Committed by Commit Bot

MPRIS: Prevent race condition with emitting signals before MPRIS starts

This CL adds a check to delay emitting signals until the service has
started. This prevents a race condition where an MprisService user
(e.g. MediaKeysListenerManager) would cause signals to be emitted
before the service was ready.

Bug: 952113
Change-Id: I2fecfbb5507e9ab25700263e1972bc80a606a3a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1566625Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650549}
parent 5e106696
...@@ -227,8 +227,12 @@ void MprisServiceImpl::InitializeDbusInterface() { ...@@ -227,8 +227,12 @@ void MprisServiceImpl::InitializeDbusInterface() {
void MprisServiceImpl::OnExported(const std::string& interface_name, void MprisServiceImpl::OnExported(const std::string& interface_name,
const std::string& method_name, const std::string& method_name,
bool success) { bool success) {
if (success) if (!success) {
num_methods_exported_++; service_failed_to_start_ = true;
return;
}
num_methods_exported_++;
// Still waiting for more methods to finish exporting. // Still waiting for more methods to finish exporting.
if (num_methods_exported_ < kNumMethodsToExport) if (num_methods_exported_ < kNumMethodsToExport)
...@@ -242,8 +246,10 @@ void MprisServiceImpl::OnExported(const std::string& interface_name, ...@@ -242,8 +246,10 @@ void MprisServiceImpl::OnExported(const std::string& interface_name,
void MprisServiceImpl::OnOwnership(const std::string& service_name, void MprisServiceImpl::OnOwnership(const std::string& service_name,
bool success) { bool success) {
if (!success) if (!success) {
service_failed_to_start_ = true;
return; return;
}
service_ready_ = true; service_ready_ = true;
...@@ -441,6 +447,12 @@ void MprisServiceImpl::EmitPropertiesChangedSignalDebounced() { ...@@ -441,6 +447,12 @@ void MprisServiceImpl::EmitPropertiesChangedSignalDebounced() {
} }
void MprisServiceImpl::EmitPropertiesChangedSignal() { void MprisServiceImpl::EmitPropertiesChangedSignal() {
// If we're still trying to start the service, delay emitting.
if (!service_ready_ && !service_failed_to_start_) {
EmitPropertiesChangedSignalDebounced();
return;
}
if (!bus_ || !exported_object_ || !service_ready_) if (!bus_ || !exported_object_ || !service_ready_)
return; return;
......
...@@ -132,6 +132,9 @@ class COMPONENT_EXPORT(MPRIS) MprisServiceImpl : public MprisService { ...@@ -132,6 +132,9 @@ class COMPONENT_EXPORT(MPRIS) MprisServiceImpl : public MprisService {
// True if we have finished creating the DBus service and received ownership. // True if we have finished creating the DBus service and received ownership.
bool service_ready_ = false; bool service_ready_ = false;
// True if we failed to start the MPRIS DBus service.
bool service_failed_to_start_ = false;
// Used to only send 1 PropertiesChanged signal when many properties are // Used to only send 1 PropertiesChanged signal when many properties are
// changed at once. // changed at once.
base::OneShotTimer properties_changed_debounce_timer_; base::OneShotTimer properties_changed_debounce_timer_;
......
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