Bug 1395842 - tighten up assertions in ChannelSuspendAgent which runs on the main thread only.
MozReview-Commit-ID: AK3YHAz750D
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -1000,80 +1000,87 @@ ChannelMediaResource::GetLength()
return mCacheStream.GetLength();
}
// ChannelSuspendAgent
bool
ChannelSuspendAgent::Suspend()
{
+ MOZ_ASSERT(NS_IsMainThread());
SuspendInternal();
return (++mSuspendCount == 1);
}
void
ChannelSuspendAgent::SuspendInternal()
{
+ MOZ_ASSERT(NS_IsMainThread());
if (mChannel) {
bool isPending = false;
nsresult rv = mChannel->IsPending(&isPending);
if (NS_SUCCEEDED(rv) && isPending && !mIsChannelSuspended) {
mChannel->Suspend();
mIsChannelSuspended = true;
}
}
}
bool
ChannelSuspendAgent::Resume()
{
+ MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(IsSuspended(), "Resume without suspend!");
--mSuspendCount;
if (mSuspendCount == 0) {
if (mChannel && mIsChannelSuspended) {
mChannel->Resume();
mIsChannelSuspended = false;
}
return true;
}
return false;
}
void
ChannelSuspendAgent::UpdateSuspendedStatusIfNeeded()
{
+ MOZ_ASSERT(NS_IsMainThread());
if (!mIsChannelSuspended && IsSuspended()) {
SuspendInternal();
}
}
void
ChannelSuspendAgent::NotifyChannelOpened(nsIChannel* aChannel)
{
+ MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aChannel);
mChannel = aChannel;
}
void
ChannelSuspendAgent::NotifyChannelClosing()
{
+ MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mChannel);
// Before close the channel, it need to be resumed to make sure its internal
// state is correct. Besides, We need to suspend the channel after recreating.
if (mIsChannelSuspended) {
mChannel->Resume();
mIsChannelSuspended = false;
}
mChannel = nullptr;
}
bool
ChannelSuspendAgent::IsSuspended()
{
+ MOZ_ASSERT(NS_IsMainThread());
return (mSuspendCount > 0);
}
// FileMediaResource
class FileMediaResource : public BaseMediaResource
{
public:
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -367,17 +367,16 @@ protected:
/**
* This class is responsible for managing the suspend count and report suspend
* status of channel.
**/
class ChannelSuspendAgent {
public:
explicit ChannelSuspendAgent(nsIChannel* aChannel)
: mChannel(aChannel),
- mSuspendCount(0),
mIsChannelSuspended(false)
{}
// True when the channel has been suspended or needs to be suspended.
bool IsSuspended();
// Return true when the channel is logically suspended, i.e. the suspend
// count goes from 0 to 1.
@@ -395,17 +394,17 @@ public:
// Check whether we need to suspend the channel.
void UpdateSuspendedStatusIfNeeded();
private:
// Only suspends channel but not changes the suspend count.
void SuspendInternal();
nsIChannel* mChannel;
- Atomic<uint32_t> mSuspendCount;
+ uint32_t mSuspendCount = 0;
bool mIsChannelSuspended;
};
/**
* This is the MediaResource implementation that wraps Necko channels.
* Much of its functionality is actually delegated to MediaCache via
* an underlying MediaCacheStream.
*