Back out 8d1b087b9713 (bug 707436) for mochitest-ipcplugins leaks
authorPhil Ringnalda <philringnalda@gmail.com>
Fri, 23 Dec 2011 19:21:17 -0800
changeset 84528 eb614b45e4788f24219d2f3b118ad177783d95ee
parent 84527 cf4feabb94cca2945a167c11d8bb4bc160c3a38f
child 84529 c631f9c3e9a94dc2783e036811b423a7826226f1
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs707436
milestone12.0a1
backs out8d1b087b9713400ef46de7e42725b0fb4603cc84
Back out 8d1b087b9713 (bug 707436) for mochitest-ipcplugins leaks
netwerk/cache/nsCacheService.cpp
netwerk/cache/nsCacheService.h
netwerk/cache/nsDiskCacheDevice.cpp
netwerk/cache/nsDiskCacheDevice.h
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -70,17 +70,16 @@
 #include "nsVoidArray.h"
 #include "nsDeleteDir.h"
 #include "nsIPrivateBrowsingService.h"
 #include "nsNetCID.h"
 #include <math.h>  // for log()
 #include "mozilla/Util.h" // for DebugOnly
 #include "mozilla/Services.h"
 #include "mozilla/Telemetry.h"
-#include "nsITimer.h"
 
 #include "mozilla/FunctionTimer.h"
 
 #include "mozilla/net/NeckoCommon.h"
 
 using namespace mozilla;
 
 /******************************************************************************
@@ -214,30 +213,16 @@ private:
     PRInt32                 mCacheCompressionLevel;
 
     bool                    mSanitizeOnShutdown;
     bool                    mClearCacheOnShutdown;
 };
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheProfilePrefObserver, nsIObserver)
 
-class nsSetDiskSmartSizeCallback : public nsITimerCallback
-{
-public:
-    NS_DECL_ISUPPORTS
-
-    NS_IMETHOD Notify(nsITimer* aTimer) {
-        nsCacheService::gService->SetDiskSmartSize(true);
-        NS_RELEASE(aTimer);
-        return NS_OK;
-    }
-};
-
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsSetDiskSmartSizeCallback, nsITimerCallback)
-
 // Runnable sent to main thread after the cache IO thread calculates available
 // disk space, so that there is no race in setting mDiskCacheCapacity.
 class nsSetSmartSizeEvent: public nsRunnable 
 {
 public:
     nsSetSmartSizeEvent(PRInt32 smartSize)
         : mSmartSize(smartSize) {}
 
@@ -462,17 +447,17 @@ nsCacheProfilePrefObserver::Observe(nsIS
             // Is the update because smartsizing was turned on, or off?
             bool smartSizeEnabled;
             rv = branch->GetBoolPref(DISK_CACHE_SMART_SIZE_ENABLED_PREF,
                                      &smartSizeEnabled);
             if (NS_FAILED(rv)) 
                 return rv;
             PRInt32 newCapacity = 0;
             if (smartSizeEnabled) {
-                nsCacheService::SetDiskSmartSize(false);
+                nsCacheService::SetDiskSmartSize();
             } else {
                 // Smart sizing switched off: use user specified size
                 rv = branch->GetIntPref(DISK_CACHE_CAPACITY_PREF, &newCapacity);
                 if (NS_FAILED(rv)) 
                     return rv;
                 mDiskCacheCapacity = NS_MAX(0, newCapacity);
                 nsCacheService::SetDiskCacheCapacity(mDiskCacheCapacity);
             }
@@ -1457,29 +1442,18 @@ nsCacheService::CreateDiskDevice()
         printf("###    - disabling disk cache for this session.\n");
         printf("###\n");
 #endif        
         mEnableDiskDevice = false;
         delete mDiskDevice;
         mDiskDevice = nsnull;
     }
 
-    // Disk device is usually created during the startup. Delay smart size
-    // calculation to avoid possible massive IO caused by eviction of entries
-    // in case the new smart size is smaller than current cache usage.
-    nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1", &rv);
-    if (NS_FAILED(rv))
-        return rv;
-
-    rv = timer->InitWithCallback(new nsSetDiskSmartSizeCallback(), 1000*60*3,
-                                 nsITimer::TYPE_ONE_SHOT);
-    if (NS_FAILED(rv))
-        return rv;
-
-    timer.forget();
+    SetDiskSmartSize_Locked(true);
+
     return rv;
 }
 
 nsresult
 nsCacheService::CreateOfflineDevice()
 {
     CACHE_LOG_ALWAYS(("Creating offline device"));
 
@@ -2667,23 +2641,23 @@ nsCacheService::OnEnterExitPrivateBrowsi
 
     if (gService->mMemoryDevice) {
         // clear memory cache
         gService->mMemoryDevice->EvictEntries(nsnull);
     }
 }
 
 nsresult
-nsCacheService::SetDiskSmartSize(bool checkPref)
+nsCacheService::SetDiskSmartSize()
 {
     nsCacheServiceAutoLock lock;
 
     if (!gService) return NS_ERROR_NOT_AVAILABLE;
 
-    return gService->SetDiskSmartSize_Locked(checkPref);
+    return gService->SetDiskSmartSize_Locked(false);
 }
 
 nsresult
 nsCacheService::SetDiskSmartSize_Locked(bool checkPref)
 {
     nsresult rv;
 
     if (!mObserver->DiskCacheParentDirectory())
--- a/netwerk/cache/nsCacheService.h
+++ b/netwerk/cache/nsCacheService.h
@@ -177,31 +177,30 @@ public:
 
     static void      SetMemoryCache();
 
     static void      SetCacheCompressionLevel(PRInt32 level);
 
     static void      OnEnterExitPrivateBrowsing();
 
     // Starts smart cache size computation if disk device is available
-    static nsresult  SetDiskSmartSize(bool checkPref);
+    static nsresult  SetDiskSmartSize();
 
     nsresult         Init();
     void             Shutdown();
 
     static void      AssertOwnsLock()
     { gService->mLock.AssertCurrentThreadOwns(); }
 
 private:
     friend class nsCacheServiceAutoLock;
     friend class nsOfflineCacheDevice;
     friend class nsProcessRequestEvent;
     friend class nsSetSmartSizeEvent;
     friend class nsBlockOnCacheThreadEvent;
-    friend class nsSetDiskSmartSizeCallback;
 
     /**
      * Internal Methods
      */
 
     static void      Lock();
     static void      Unlock();
 
--- a/netwerk/cache/nsDiskCacheDevice.cpp
+++ b/netwerk/cache/nsDiskCacheDevice.cpp
@@ -113,32 +113,16 @@ public:
     void CancelEvent() { mCanceled = true; }
 private:
     bool mCanceled;
     nsCacheEntry *mEntry;
     nsDiskCacheDevice *mDevice;
     nsDiskCacheBinding *mBinding;
 };
 
-class nsEvictDiskCacheEntriesEvent : public nsRunnable {
-public:
-    nsEvictDiskCacheEntriesEvent(nsDiskCacheDevice *device)
-        : mDevice(device) {}
-
-    NS_IMETHOD Run()
-    {
-        nsCacheServiceAutoLock lock;
-        mDevice->EvictDiskCacheEntries(mDevice->mCacheCapacity);
-        return NS_OK;
-    }
-
-private:
-    nsDiskCacheDevice *mDevice;
-};
-
 /******************************************************************************
  *  nsDiskCacheEvictor
  *
  *  Helper class for nsDiskCacheDevice.
  *
  *****************************************************************************/
 
 class nsDiskCacheEvictor : public nsDiskCacheRecordVisitor
@@ -1131,24 +1115,18 @@ nsDiskCacheDevice::getCacheDirectory(nsI
  *  NOTE: called while holding the cache service lock
  */
 void
 nsDiskCacheDevice::SetCapacity(PRUint32  capacity)
 {
     // Units are KiB's
     mCacheCapacity = capacity;
     if (Initialized()) {
-        if (NS_IsMainThread()) {
-            // Do not evict entries on the main thread
-            nsCacheService::DispatchToCacheIOThread(
-                new nsEvictDiskCacheEntriesEvent(this));
-        } else {
-            // start evicting entries if the new size is smaller!
-            EvictDiskCacheEntries(mCacheCapacity);
-        }
+        // start evicting entries if the new size is smaller!
+        EvictDiskCacheEntries(mCacheCapacity);
     }
     // Let cache map know of the new capacity
     mCacheMap.NotifyCapacityChange(capacity);
 }
 
 
 PRUint32 nsDiskCacheDevice::getCacheCapacity()
 {
--- a/netwerk/cache/nsDiskCacheDevice.h
+++ b/netwerk/cache/nsDiskCacheDevice.h
@@ -102,17 +102,16 @@ public:
     PRUint32                getCacheCapacity();
     PRUint32                getCacheSize();
     PRUint32                getEntryCount();
     
     nsDiskCacheMap *        CacheMap()    { return &mCacheMap; }
     
 private:    
     friend class nsDiskCacheDeviceDeactivateEntryEvent;
-    friend class nsEvictDiskCacheEntriesEvent;
     /**
      *  Private methods
      */
 
     inline bool IsValidBinding(nsDiskCacheBinding *binding)
     {
         NS_ASSERTION(binding, "  binding == nsnull");
         NS_ASSERTION(binding->mDeactivateEvent == nsnull,