Backed out changeset 1ff643f2c358 (bug 1251130). r=backout
authorMichal Novotny <michal.novotny@gmail.com>
Fri, 11 Mar 2016 12:55:15 +0100
changeset 288270 3a4549c08a316ccc80258d59f42d7c2cf5da1648
parent 288269 1992eff1a02d5cfc227c2045754a3ba48a13065c
child 288271 f30fc906416f25adf1fff45ff2466ddaaaec23c4
push id30079
push userryanvm@gmail.com
push dateSat, 12 Mar 2016 20:24:19 +0000
treeherdermozilla-central@d1d47ba19ce9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1251130
milestone48.0a1
backs out1ff643f2c358a5c41c47da12e24fbda1c14105f2
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 1ff643f2c358 (bug 1251130). r=backout
netwerk/cache2/CacheFileIOManager.cpp
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -583,16 +583,17 @@ class OpenFileEvent : public nsRunnable 
 public:
   OpenFileEvent(const nsACString &aKey, uint32_t aFlags,
                 CacheFileIOListener *aCallback)
     : mFlags(aFlags)
     , mCallback(aCallback)
     , mKey(aKey)
   {
     MOZ_COUNT_CTOR(OpenFileEvent);
+    mIOMan = CacheFileIOManager::gInstance;
   }
 
 protected:
   ~OpenFileEvent()
   {
     MOZ_COUNT_DTOR(OpenFileEvent);
   }
 
@@ -602,42 +603,43 @@ public:
     nsresult rv = NS_OK;
 
     if (!(mFlags & CacheFileIOManager::SPECIAL_FILE)) {
       SHA1Sum sum;
       sum.update(mKey.BeginReading(), mKey.Length());
       sum.finish(mHash);
     }
 
-    if (!CacheFileIOManager::gInstance) {
+    if (!mIOMan) {
       rv = NS_ERROR_NOT_INITIALIZED;
     } else {
       if (mFlags & CacheFileIOManager::SPECIAL_FILE) {
-        rv = CacheFileIOManager::gInstance->OpenSpecialFileInternal(
-               mKey, mFlags, getter_AddRefs(mHandle));
+        rv = mIOMan->OpenSpecialFileInternal(mKey, mFlags,
+                                             getter_AddRefs(mHandle));
       } else {
-        rv = CacheFileIOManager::gInstance->OpenFileInternal(
-               &mHash, mKey, mFlags, getter_AddRefs(mHandle));
+        rv = mIOMan->OpenFileInternal(&mHash, mKey, mFlags,
+                                      getter_AddRefs(mHandle));
       }
-
+      mIOMan = nullptr;
       if (mHandle) {
         if (mHandle->Key().IsEmpty()) {
           mHandle->Key() = mKey;
         }
       }
     }
 
     mCallback->OnFileOpened(mHandle, rv);
     return NS_OK;
   }
 
 protected:
   SHA1Sum::Hash                 mHash;
   uint32_t                      mFlags;
   nsCOMPtr<CacheFileIOListener> mCallback;
+  RefPtr<CacheFileIOManager>    mIOMan;
   RefPtr<CacheFileHandle>       mHandle;
   nsCString                     mKey;
 };
 
 class ReadEvent : public nsRunnable {
 public:
   ReadEvent(CacheFileHandle *aHandle, int64_t aOffset, char *aBuf,
             int32_t aCount, CacheFileIOListener *aCallback)
@@ -710,19 +712,18 @@ public:
   NS_IMETHOD Run()
   {
     nsresult rv;
 
     if (mHandle->IsClosed() || (mCallback && mCallback->IsKilled())) {
       // We usually get here only after the internal shutdown
       // (i.e. mShuttingDown == true).  Pretend write has succeeded
       // to avoid any past-shutdown file dooming.
-      rv = (CacheFileIOManager::gInstance &&
-            (CacheFileIOManager::gInstance->IsPastShutdownIOLag() ||
-             CacheFileIOManager::gInstance->mShuttingDown))
+      rv = (CacheFileIOManager::gInstance->IsPastShutdownIOLag() ||
+            CacheFileIOManager::gInstance->mShuttingDown)
         ? NS_OK
         : NS_ERROR_NOT_INITIALIZED;
     } else {
       rv = CacheFileIOManager::gInstance->WriteInternal(
           mHandle, mOffset, mBuf, mCount, mValidate, mTruncate);
       if (NS_FAILED(rv) && !mCallback) {
         // No listener is going to handle the error, doom the file
         CacheFileIOManager::gInstance->DoomFileInternal(mHandle);
@@ -794,45 +795,49 @@ public:
                      CacheFileIOListener *aCallback)
     : mCallback(aCallback)
   {
     MOZ_COUNT_CTOR(DoomFileByKeyEvent);
 
     SHA1Sum sum;
     sum.update(aKey.BeginReading(), aKey.Length());
     sum.finish(mHash);
+
+    mIOMan = CacheFileIOManager::gInstance;
   }
 
 protected:
   ~DoomFileByKeyEvent()
   {
     MOZ_COUNT_DTOR(DoomFileByKeyEvent);
   }
 
 public:
   NS_IMETHOD Run()
   {
     nsresult rv;
 
-    if (!CacheFileIOManager::gInstance) {
+    if (!mIOMan) {
       rv = NS_ERROR_NOT_INITIALIZED;
     } else {
-      rv = CacheFileIOManager::gInstance->DoomFileByKeyInternal(&mHash);
+      rv = mIOMan->DoomFileByKeyInternal(&mHash);
+      mIOMan = nullptr;
     }
 
     if (mCallback) {
       mCallback->OnFileDoomed(nullptr, rv);
     }
 
     return NS_OK;
   }
 
 protected:
   SHA1Sum::Hash                 mHash;
   nsCOMPtr<CacheFileIOListener> mCallback;
+  RefPtr<CacheFileIOManager>    mIOMan;
 };
 
 class ReleaseNSPRHandleEvent : public nsRunnable {
 public:
   explicit ReleaseNSPRHandleEvent(CacheFileHandle *aHandle)
     : mHandle(aHandle)
   {
     MOZ_COUNT_CTOR(ReleaseNSPRHandleEvent);
@@ -1042,21 +1047,24 @@ class MetadataWriteScheduleEvent : publi
 public:
   enum EMode {
     SCHEDULE,
     UNSCHEDULE,
     SHUTDOWN
   } mMode;
 
   RefPtr<CacheFile> mFile;
-
-  MetadataWriteScheduleEvent(CacheFile * aFile,
+  RefPtr<CacheFileIOManager> mIOMan;
+
+  MetadataWriteScheduleEvent(CacheFileIOManager * aManager,
+                             CacheFile * aFile,
                              EMode aMode)
     : mMode(aMode)
     , mFile(aFile)
+    , mIOMan(aManager)
   { }
 
   virtual ~MetadataWriteScheduleEvent() { }
 
   NS_IMETHOD Run()
   {
     RefPtr<CacheFileIOManager> ioMan = CacheFileIOManager::gInstance;
     if (!ioMan) {
@@ -1153,46 +1161,46 @@ CacheFileIOManager::Shutdown()
   gInstance->mShutdownDemanded = true;
 
   Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_SHUTDOWN_V2> shutdownTimer;
 
   CacheIndex::PreShutdown();
 
   ShutdownMetadataWriteScheduling();
 
-  RefPtr<CacheFileIOManager> ioMan = gInstance;
-
   {
     mozilla::Mutex lock("CacheFileIOManager::Shutdown() lock");
     mozilla::CondVar condVar(lock, "CacheFileIOManager::Shutdown() condVar");
 
     MutexAutoLock autoLock(lock);
     RefPtr<ShutdownEvent> ev = new ShutdownEvent(&lock, &condVar);
     DebugOnly<nsresult> rv;
     nsCOMPtr<nsIEventTarget> ioTarget = gInstance->mIOThread->Target();
     MOZ_ASSERT(ioTarget);
     rv = ioTarget->Dispatch(ev, nsIEventTarget::DISPATCH_NORMAL);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
     condVar.Wait();
-    MOZ_ASSERT(!gInstance);
-  }
-
-  MOZ_ASSERT(ioMan->mHandles.HandleCount() == 0);
-  MOZ_ASSERT(ioMan->mHandlesByLastUsed.Length() == 0);
-
-  if (ioMan->mIOThread) {
-    ioMan->mIOThread->Shutdown();
+  }
+
+  MOZ_ASSERT(gInstance->mHandles.HandleCount() == 0);
+  MOZ_ASSERT(gInstance->mHandlesByLastUsed.Length() == 0);
+
+  if (gInstance->mIOThread) {
+    gInstance->mIOThread->Shutdown();
   }
 
   CacheIndex::Shutdown();
 
   if (CacheObserver::ClearCacheOnShutdown()) {
     Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE2_SHUTDOWN_CLEAR_PRIVATE> totalTimer;
-    ioMan->SyncRemoveAllCacheFiles();
-  }
+    gInstance->SyncRemoveAllCacheFiles();
+  }
+
+  RefPtr<CacheFileIOManager> ioMan;
+  ioMan.swap(gInstance);
 
   return NS_OK;
 }
 
 nsresult
 CacheFileIOManager::ShutdownInternal()
 {
   LOG(("CacheFileIOManager::ShutdownInternal() [this=%p]", this));
@@ -1251,19 +1259,16 @@ CacheFileIOManager::ShutdownInternal()
   MOZ_ASSERT(mHandles.HandleCount() == 0);
 
   // Release trash directory enumerator
   if (mTrashDirEnumerator) {
     mTrashDirEnumerator->Close();
     mTrashDirEnumerator = nullptr;
   }
 
-  RefPtr<CacheFileIOManager> ioMan;
-  ioMan.swap(gInstance);
-
   return NS_OK;
 }
 
 bool
 CacheFileIOManager::IsPastShutdownIOLag()
 {
 #ifdef DEBUG
   return false;
@@ -1430,17 +1435,17 @@ nsresult
 CacheFileIOManager::ScheduleMetadataWrite(CacheFile * aFile)
 {
   RefPtr<CacheFileIOManager> ioMan = gInstance;
   NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED);
 
   NS_ENSURE_TRUE(!ioMan->mShuttingDown, NS_ERROR_NOT_INITIALIZED);
 
   RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
-    aFile, MetadataWriteScheduleEvent::SCHEDULE);
+    ioMan, aFile, MetadataWriteScheduleEvent::SCHEDULE);
   nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
   NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED);
   return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
 }
 
 nsresult
 CacheFileIOManager::ScheduleMetadataWriteInternal(CacheFile * aFile)
 {
@@ -1472,17 +1477,17 @@ nsresult
 CacheFileIOManager::UnscheduleMetadataWrite(CacheFile * aFile)
 {
   RefPtr<CacheFileIOManager> ioMan = gInstance;
   NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED);
 
   NS_ENSURE_TRUE(!ioMan->mShuttingDown, NS_ERROR_NOT_INITIALIZED);
 
   RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
-    aFile, MetadataWriteScheduleEvent::UNSCHEDULE);
+    ioMan, aFile, MetadataWriteScheduleEvent::UNSCHEDULE);
   nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
   NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED);
   return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
 }
 
 nsresult
 CacheFileIOManager::UnscheduleMetadataWriteInternal(CacheFile * aFile)
 {
@@ -1502,17 +1507,17 @@ CacheFileIOManager::UnscheduleMetadataWr
 // static
 nsresult
 CacheFileIOManager::ShutdownMetadataWriteScheduling()
 {
   RefPtr<CacheFileIOManager> ioMan = gInstance;
   NS_ENSURE_TRUE(ioMan, NS_ERROR_NOT_INITIALIZED);
 
   RefPtr<MetadataWriteScheduleEvent> event = new MetadataWriteScheduleEvent(
-    nullptr, MetadataWriteScheduleEvent::SHUTDOWN);
+    ioMan, nullptr, MetadataWriteScheduleEvent::SHUTDOWN);
   nsCOMPtr<nsIEventTarget> target = ioMan->IOTarget();
   NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED);
   return target->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
 }
 
 nsresult
 CacheFileIOManager::ShutdownMetadataWriteSchedulingInternal()
 {