Bug 490384 - mochitest-plain: random test_bug466586.html | undefined. r=vlad
authorJoe Drew <joe@drew.ca>
Thu, 07 May 2009 12:19:12 -0700
changeset 28098 70292deb49e0a6228983346440cb04391a8b5ce0
parent 28096 0fb93c90d996243e12c09758278ec539af0bf66b
child 28099 e40b313aca1ffc333f168d74b5112e79033695ea
push id6892
push userrsayre@mozilla.com
push dateFri, 08 May 2009 00:23:45 +0000
treeherdermozilla-central@bed245918256 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad
bugs490384, 466586
milestone1.9.2a1pre
Bug 490384 - mochitest-plain: random test_bug466586.html | undefined. r=vlad
modules/libpr0n/src/imgLoader.cpp
modules/libpr0n/src/imgLoader.h
--- a/modules/libpr0n/src/imgLoader.cpp
+++ b/modules/libpr0n/src/imgLoader.cpp
@@ -446,21 +446,20 @@ private:
 };
 
 NS_IMPL_ISUPPORTS1(imgCacheObserver, nsIObserver)
 
 NS_IMETHODIMP
 imgCacheObserver::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData)
 {
   if (strcmp(aTopic, "memory-pressure") == 0) {
-    mLoader.ClearCache(PR_FALSE);
-    mLoader.ClearCache(PR_TRUE);
+    mLoader.MinimizeCaches();
   } else if (strcmp(aTopic, "chrome-flush-skin-caches") == 0 ||
              strcmp(aTopic, "chrome-flush-caches") == 0) {
-    mLoader.ClearCache(PR_TRUE);
+    mLoader.ClearChromeImageCache();
   }
   return NS_OK;
 }
 
 class imgCacheExpirationTracker : public nsExpirationTracker<imgCacheEntry, 3>
 {
   enum { TIMEOUT_SECONDS = 10 };
 public:
@@ -651,22 +650,28 @@ void imgLoader::Shutdown()
   ClearImageCache();
   NS_IF_RELEASE(gCacheObserver);
   delete gCacheTracker;
   gCacheTracker = nsnull;
 }
 
 nsresult imgLoader::ClearChromeImageCache()
 {
-  return EvictEntries(sChromeCache, sChromeCacheQueue);
+  return EvictEntries(sChromeCache);
 }
 
 nsresult imgLoader::ClearImageCache()
 {
-  return EvictEntries(sCache, sCacheQueue);
+  return EvictEntries(sCache);
+}
+
+void imgLoader::MinimizeCaches()
+{
+  EvictEntries(sCacheQueue);
+  EvictEntries(sChromeCacheQueue);
 }
 
 PRBool imgLoader::PutIntoCache(nsIURI *key, imgCacheEntry *entry)
 {
   imgCacheTable &cache = GetCache(key);
 
   nsCAutoString spec;
   key->GetSpec(spec);
@@ -1101,32 +1106,49 @@ static PLDHashOperator EnumEvictEntries(
   nsTArray<nsRefPtr<imgCacheEntry> > *entries = 
     reinterpret_cast<nsTArray<nsRefPtr<imgCacheEntry> > *>(data);
 
   entries->AppendElement(aData);
 
   return PL_DHASH_NEXT;
 }
 
-nsresult imgLoader::EvictEntries(imgCacheTable &aCacheToClear, imgCacheQueue &aQueueToClear)
+nsresult imgLoader::EvictEntries(imgCacheTable &aCacheToClear)
 {
-  LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries");
+  LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries table");
 
   // We have to make a temporary, since RemoveFromCache removes the element
   // from the queue, invalidating iterators.
   nsTArray<nsRefPtr<imgCacheEntry> > entries;
   aCacheToClear.Enumerate(EnumEvictEntries, &entries);
 
   for (PRUint32 i = 0; i < entries.Length(); ++i)
     if (!RemoveFromCache(entries[i]))
       return NS_ERROR_FAILURE;
 
   return NS_OK;
 }
 
+nsresult imgLoader::EvictEntries(imgCacheQueue &aQueueToClear)
+{
+  LOG_STATIC_FUNC(gImgLog, "imgLoader::EvictEntries queue");
+
+  // We have to make a temporary, since RemoveFromCache removes the element
+  // from the queue, invalidating iterators.
+  nsTArray<nsRefPtr<imgCacheEntry> > entries(aQueueToClear.GetNumElements());
+  for (imgCacheQueue::const_iterator i = aQueueToClear.begin(); i != aQueueToClear.end(); ++i)
+    entries.AppendElement(*i);
+
+  for (PRUint32 i = 0; i < entries.Length(); ++i)
+    if (!RemoveFromCache(entries[i]))
+      return NS_ERROR_FAILURE;
+
+  return NS_OK;
+}
+
 #define LOAD_FLAGS_CACHE_MASK    (nsIRequest::LOAD_BYPASS_CACHE | \
                                   nsIRequest::LOAD_FROM_CACHE)
 
 #define LOAD_FLAGS_VALIDATE_MASK (nsIRequest::VALIDATE_ALWAYS |   \
                                   nsIRequest::VALIDATE_NEVER |    \
                                   nsIRequest::VALIDATE_ONCE_PER_SESSION)
 
 
--- a/modules/libpr0n/src/imgLoader.h
+++ b/modules/libpr0n/src/imgLoader.h
@@ -230,16 +230,17 @@ public:
   virtual ~imgLoader();
 
   static nsresult GetMimeTypeFromContent(const char* aContents, PRUint32 aLength, nsACString& aContentType);
 
   static void Shutdown(); // for use by the factory
 
   static nsresult ClearChromeImageCache();
   static nsresult ClearImageCache();
+  static void MinimizeCaches();
 
   static nsresult InitCache();
 
   static PRBool RemoveFromCache(nsIURI *aKey);
   static PRBool RemoveFromCache(imgCacheEntry *entry);
 
   static PRBool PutIntoCache(nsIURI *key, imgCacheEntry *entry);
 
@@ -297,17 +298,18 @@ private: // methods
   nsresult CreateNewProxyForRequest(imgRequest *aRequest, nsILoadGroup *aLoadGroup,
                                     imgIDecoderObserver *aObserver,
                                     nsLoadFlags aLoadFlags, imgIRequest *aRequestProxy,
                                     imgIRequest **_retval);
 
 
   typedef nsRefPtrHashtable<nsCStringHashKey, imgCacheEntry> imgCacheTable;
 
-  static nsresult EvictEntries(imgCacheTable &aCacheToClear, imgCacheQueue &aQueueToClear);
+  static nsresult EvictEntries(imgCacheTable &aCacheToClear);
+  static nsresult EvictEntries(imgCacheQueue &aQueueToClear);
 
   static imgCacheTable &GetCache(nsIURI *aURI);
   static imgCacheQueue &GetCacheQueue(nsIURI *aURI);
   static void CacheEntriesChanged(nsIURI *aURI, PRInt32 sizediff = 0);
   static void CheckCacheLimits(imgCacheTable &cache, imgCacheQueue &queue);
 
 private: // data
   friend class imgCacheEntry;