Bug 1063364. imgLoader::SetHasProxies/SetHasNoProxies should operate on imgRequests/imgCacheEntrys not URIs. r=seth

There can be more than one imgRequest alive for any given URI, so when we tell the imgLoader that we have/do not have proxies we should be specific which imgRequest/imgCacheEntry this applies to so we don't change the wrong imgRequest/imgCacheEntry.
This commit is contained in:
Timothy Nikkel 2014-09-10 21:47:00 -05:00
parent a23b1f37d8
commit 6e8ee4741e
3 changed files with 33 additions and 22 deletions

View File

@ -1319,58 +1319,69 @@ bool imgLoader::PutIntoCache(nsIURI *key, imgCacheEntry *entry)
return true;
}
bool imgLoader::SetHasNoProxies(ImageURL *key, imgCacheEntry *entry)
bool imgLoader::SetHasNoProxies(imgRequest *aRequest, imgCacheEntry *aEntry)
{
nsRefPtr<ImageURL> uri;
aRequest->GetURI(getter_AddRefs(uri));
#if defined(PR_LOGGING)
nsAutoCString spec;
key->GetSpec(spec);
uri->GetSpec(spec);
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(), "imgLoader::SetHasNoProxies", "uri", spec.get());
#endif
if (entry->Evicted())
aEntry->SetHasNoProxies(true);
if (aEntry->Evicted())
return false;
imgCacheQueue &queue = GetCacheQueue(key);
imgCacheQueue &queue = GetCacheQueue(uri);
nsresult addrv = NS_OK;
if (mCacheTracker)
addrv = mCacheTracker->AddObject(entry);
addrv = mCacheTracker->AddObject(aEntry);
if (NS_SUCCEEDED(addrv)) {
queue.Push(entry);
entry->SetHasNoProxies(true);
queue.Push(aEntry);
}
imgCacheTable &cache = GetCache(key);
imgCacheTable &cache = GetCache(uri);
CheckCacheLimits(cache, queue);
return true;
}
bool imgLoader::SetHasProxies(ImageURL *key)
bool imgLoader::SetHasProxies(imgRequest *aRequest)
{
VerifyCacheSizes();
imgCacheTable &cache = GetCache(key);
nsRefPtr<ImageURL> uri;
aRequest->GetURI(getter_AddRefs(uri));
imgCacheTable &cache = GetCache(uri);
nsAutoCString spec;
key->GetSpec(spec);
uri->GetSpec(spec);
LOG_STATIC_FUNC_WITH_PARAM(GetImgLog(), "imgLoader::SetHasProxies", "uri", spec.get());
nsRefPtr<imgCacheEntry> entry;
if (cache.Get(spec, getter_AddRefs(entry)) && entry && entry->HasNoProxies()) {
imgCacheQueue &queue = GetCacheQueue(key);
queue.Remove(entry);
if (cache.Get(spec, getter_AddRefs(entry)) && entry) {
// Make sure the cache entry is for the right request
nsRefPtr<imgRequest> entryRequest = entry->GetRequest();
if (entryRequest == aRequest && entry->HasNoProxies()) {
imgCacheQueue &queue = GetCacheQueue(uri);
queue.Remove(entry);
if (mCacheTracker)
mCacheTracker->RemoveObject(entry);
if (mCacheTracker)
mCacheTracker->RemoveObject(entry);
entry->SetHasNoProxies(false);
entry->SetHasNoProxies(false);
return true;
return true;
}
}
return false;

View File

@ -329,8 +329,8 @@ public:
// HasObservers(). The request's cache entry will be re-set before this
// happens, by calling imgRequest::SetCacheEntry() when an entry with no
// observers is re-requested.
bool SetHasNoProxies(ImageURL *key, imgCacheEntry *entry);
bool SetHasProxies(ImageURL *key);
bool SetHasNoProxies(imgRequest *aRequest, imgCacheEntry *aEntry);
bool SetHasProxies(imgRequest *aRequest);
private: // methods

View File

@ -177,7 +177,7 @@ void imgRequest::AddProxy(imgRequestProxy *proxy)
if (statusTracker->ConsumerCount() == 0) {
NS_ABORT_IF_FALSE(mURI, "Trying to SetHasProxies without key uri.");
if (mLoader) {
mLoader->SetHasProxies(mURI);
mLoader->SetHasProxies(this);
}
}
@ -209,7 +209,7 @@ nsresult imgRequest::RemoveProxy(imgRequestProxy *proxy, nsresult aStatus)
NS_ABORT_IF_FALSE(mURI, "Removing last observer without key uri.");
if (mLoader) {
mLoader->SetHasNoProxies(mURI, mCacheEntry);
mLoader->SetHasNoProxies(this, mCacheEntry);
}
}
#if defined(PR_LOGGING)