Bug 1196476 - Replace ProgressTracker::FirstObserverIs() with a simpler mechanism on imgRequest. r=tn

This commit is contained in:
Seth Fowler 2015-08-24 19:49:33 -07:00
parent eda90e10c3
commit e0b216d11c
4 changed files with 12 additions and 21 deletions

View File

@ -425,20 +425,6 @@ ProgressTracker::RemoveObserver(IProgressObserver* aObserver)
return removed; return removed;
} }
bool
ProgressTracker::FirstObserverIs(IProgressObserver* aObserver)
{
MOZ_ASSERT(NS_IsMainThread(), "Use mObservers on main thread only");
ObserverArray::ForwardIterator iter(mObservers);
while (iter.HasMore()) {
nsRefPtr<IProgressObserver> observer = iter.GetNext().get();
if (observer) {
return observer.get() == aObserver;
}
}
return false;
}
void void
ProgressTracker::OnUnlockedDraw() ProgressTracker::OnUnlockedDraw()
{ {

View File

@ -155,11 +155,6 @@ public:
return mObservers.Length(); return mObservers.Length();
} }
// This is intentionally non-general because its sole purpose is to support
// some obscure network priority logic in imgRequest. That stuff could
// probably be improved, but it's too scary to mess with at the moment.
bool FirstObserverIs(IProgressObserver* aObserver);
// Resets our weak reference to our image. Image subclasses should call this // Resets our weak reference to our image. Image subclasses should call this
// in their destructor. // in their destructor.
void ResetImage(); void ResetImage();

View File

@ -64,6 +64,7 @@ imgRequest::imgRequest(imgLoader* aLoader, const ImageCacheKey& aCacheKey)
: mLoader(aLoader) : mLoader(aLoader)
, mCacheKey(aCacheKey) , mCacheKey(aCacheKey)
, mLoadId(nullptr) , mLoadId(nullptr)
, mFirstProxy(nullptr)
, mValidator(nullptr) , mValidator(nullptr)
, mInnerWindowId(0) , mInnerWindowId(0)
, mCORSMode(imgIRequest::CORS_NONE) , mCORSMode(imgIRequest::CORS_NONE)
@ -218,6 +219,12 @@ imgRequest::AddProxy(imgRequestProxy* proxy)
NS_PRECONDITION(proxy, "null imgRequestProxy passed in"); NS_PRECONDITION(proxy, "null imgRequestProxy passed in");
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgRequest::AddProxy", "proxy", proxy); LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgRequest::AddProxy", "proxy", proxy);
if (!mFirstProxy) {
// Save a raw pointer to the first proxy we see, for use in the network
// priority logic.
mFirstProxy = proxy;
}
// If we're empty before adding, we have to tell the loader we now have // If we're empty before adding, we have to tell the loader we now have
// proxies. // proxies.
nsRefPtr<ProgressTracker> progressTracker = GetProgressTracker(); nsRefPtr<ProgressTracker> progressTracker = GetProgressTracker();
@ -535,8 +542,7 @@ imgRequest::AdjustPriority(imgRequestProxy* proxy, int32_t delta)
// concern though is that image loads remain lower priority than other pieces // concern though is that image loads remain lower priority than other pieces
// of content such as link clicks, CSS, and JS. // of content such as link clicks, CSS, and JS.
// //
nsRefPtr<ProgressTracker> progressTracker = GetProgressTracker(); if (!mFirstProxy || proxy != mFirstProxy) {
if (!progressTracker->FirstObserverIs(proxy)) {
return; return;
} }

View File

@ -256,6 +256,10 @@ private:
void* mLoadId; void* mLoadId;
/// Raw pointer to the first proxy that was added to this imgRequest. Use only
/// pointer comparisons; there's no guarantee this will remain valid.
void* mFirstProxy;
imgCacheValidator* mValidator; imgCacheValidator* mValidator;
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback; nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
nsCOMPtr<nsIChannel> mNewRedirectChannel; nsCOMPtr<nsIChannel> mNewRedirectChannel;