Bug 1109954 - Make resolve/reject values optional in callback signatures. r=cpearce

This commit is contained in:
Bobby Holley 2014-12-10 22:38:33 -08:00
parent 2123a80a53
commit df95a4fbf6
7 changed files with 26 additions and 12 deletions

View File

@ -2491,10 +2491,9 @@ MediaDecoderStateMachine::ShutdownReader()
}
void
MediaDecoderStateMachine::FinishShutdown(bool aSuccess)
MediaDecoderStateMachine::FinishShutdown()
{
MOZ_ASSERT(OnStateMachineThread());
MOZ_ASSERT(aSuccess);
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
// The reader's listeners hold references to the state machine,

View File

@ -163,7 +163,7 @@ public:
void SetDormant(bool aDormant);
void Shutdown();
void ShutdownReader();
void FinishShutdown(bool aSuccess);
void FinishShutdown();
// Called from the main thread to get the duration. The decoder monitor
// must be obtained before calling this. It is in units of microseconds.

View File

@ -155,6 +155,23 @@ protected:
const char* mCallSite;
};
/*
* We create two specializations for invoking Resolve/Reject Methods so as to
* make the resolve/reject value argument "optional" via SFINAE.
*/
template<typename ThisType, typename ValueType>
static void InvokeCallbackMethod(ThisType* aThisVal, void(ThisType::*aMethod)(ValueType), ValueType aValue)
{
((*aThisVal).*aMethod)(aValue);
}
template<typename ThisType, typename ValueType>
static void InvokeCallbackMethod(ThisType* aThisVal, void(ThisType::*aMethod)(), ValueType aValue)
{
((*aThisVal).*aMethod)();
}
template<typename TargetType, typename ThisType,
typename ResolveMethodType, typename RejectMethodType>
class ThenValue : public ThenValueBase
@ -187,12 +204,12 @@ protected:
protected:
virtual void DoResolve(ResolveValueType aResolveValue)
{
((*mThisVal).*mResolveMethod)(aResolveValue);
InvokeCallbackMethod(mThisVal.get(), mResolveMethod, aResolveValue);
}
virtual void DoReject(RejectValueType aRejectValue)
{
((*mThisVal).*mRejectMethod)(aRejectValue);
InvokeCallbackMethod(mThisVal.get(), mRejectMethod, aRejectValue);
}
virtual ~ThenValue() {}

View File

@ -299,14 +299,13 @@ MediaSourceReader::Shutdown()
MOZ_ASSERT(mMediaSourceShutdownPromise.IsEmpty());
nsRefPtr<ShutdownPromise> p = mMediaSourceShutdownPromise.Ensure(__func__);
ContinueShutdown(true);
ContinueShutdown();
return p;
}
void
MediaSourceReader::ContinueShutdown(bool aSuccess)
MediaSourceReader::ContinueShutdown()
{
MOZ_ASSERT(aSuccess);
if (mTrackBuffers.Length()) {
mTrackBuffers[0]->Shutdown()->Then(GetTaskQueue(), __func__, this,
&MediaSourceReader::ContinueShutdown,

View File

@ -180,7 +180,7 @@ private:
bool mHasEssentialTrackBuffers;
void ContinueShutdown(bool aSuccess);
void ContinueShutdown();
MediaPromiseHolder<ShutdownPromise> mMediaSourceShutdownPromise;
#ifdef MOZ_FMP4
nsRefPtr<SharedDecoderManager> mSharedDecoderManager;

View File

@ -112,9 +112,8 @@ TrackBuffer::Shutdown()
}
void
TrackBuffer::ContinueShutdown(bool aSuccess)
TrackBuffer::ContinueShutdown()
{
MOZ_ASSERT(aSuccess);
ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());
if (mDecoders.Length()) {
mDecoders[0]->GetReader()->Shutdown()

View File

@ -160,7 +160,7 @@ private:
// Protected by mParentDecoder's monitor.
MediaInfo mInfo;
void ContinueShutdown(bool aSuccess);
void ContinueShutdown();
MediaPromiseHolder<ShutdownPromise> mShutdownPromise;
};