Bug 1436341 - Fix assertion for when a device operation fails. r?jib
The previous assertion was from an earlier developer stage which changed
during development of
bug 1299515. It assumed that mDeviceEnabled was
updated only after passing the assert.
In the final version of
bug 1299515 that is no longer true, and
both the failed and the successful device operation asserts
can now be unified to one.
MozReview-Commit-ID: KMdnIs0UgPr
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -4096,16 +4096,18 @@ SourceListener::SetEnabledFor(TrackID aT
(MozPromiseHolder<DeviceOperationPromise>& h) {
h.Resolve(aEnable ? device->Start() : device->Stop(), __func__);
});
}, []() {
// Timer was canceled by us. We signal this with NS_ERROR_ABORT.
return DeviceOperationPromise::CreateAndResolve(NS_ERROR_ABORT, __func__);
})->Then(GetMainThreadSerialEventTarget(), __func__,
[self, this, &state, aTrackID, aEnable](nsresult aResult) mutable {
+ MOZ_ASSERT_IF(aResult != NS_ERROR_ABORT,
+ state.mDeviceEnabled == aEnable);
MOZ_ASSERT(state.mOperationInProgress);
state.mOperationInProgress = false;
if (state.mStopped) {
// Device was stopped on main thread during the operation. Nothing to do.
return;
}
@@ -4115,19 +4117,16 @@ SourceListener::SetEnabledFor(TrackID aT
aTrackID == kAudioTrack ? "audio" : "video",
aTrackID,
NS_SUCCEEDED(aResult) ? "succeeded" : "failed"));
if (NS_FAILED(aResult) && aResult != NS_ERROR_ABORT) {
// This path handles errors from starting or stopping the device.
// NS_ERROR_ABORT are for cases where *we* aborted. They need graceful
// handling.
- MOZ_ASSERT(state.mDeviceEnabled != aEnable,
- "If operating the device failed, the device's `enabled` "
- "state must remain at its old value");
if (aEnable) {
// Starting the device failed. Stopping the track here will make the
// MediaStreamTrack end after a pass through the MediaStreamGraph.
StopTrack(aTrackID);
} else {
// Stopping the device failed. This is odd, but not fatal.
MOZ_ASSERT_UNREACHABLE("The device should be stoppable");
@@ -4137,17 +4136,16 @@ SourceListener::SetEnabledFor(TrackID aT
}
return;
}
// This path is for a device operation aResult that was success or
// NS_ERROR_ABORT (*we* canceled the operation).
// At this point we have to follow up on the intended state, i.e., update
// the device state if the track state changed in the meantime.
- MOZ_ASSERT_IF(NS_SUCCEEDED(aResult), state.mDeviceEnabled == aEnable);
if (state.mTrackEnabled == state.mDeviceEnabled) {
// Intended state is same as device's current state.
// Nothing more to do.
return;
}
// Track state changed during this operation. We'll start over.