Bug 1525900 - Remove unused code from old cache. r=mayhemer
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 07 Feb 2019 05:49:00 +0200
changeset 459036 890618032e65075128c90fba0562f829190112e6
parent 458990 f300070152e95b11e8d54b7ff18889ce32c79240
child 459037 8f7958c7d3e5423765018623ada76d08fe0c6d53
push id35555
push userrgurzau@mozilla.com
push dateThu, 14 Feb 2019 17:02:25 +0000
treeherdermozilla-central@dbbadd12f849 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1525900
milestone67.0a1
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
Bug 1525900 - Remove unused code from old cache. r=mayhemer
netwerk/cache/moz.build
netwerk/cache/nsCacheService.cpp
netwerk/cache/nsCacheService.h
netwerk/cache/nsDiskCacheBinding.cpp
netwerk/cache/nsDiskCacheBinding.h
netwerk/cache/nsDiskCacheBlockFile.cpp
netwerk/cache/nsDiskCacheBlockFile.h
netwerk/cache/nsDiskCacheDevice.cpp
netwerk/cache/nsDiskCacheDevice.h
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/cache/nsDiskCacheEntry.cpp
netwerk/cache/nsDiskCacheEntry.h
netwerk/cache/nsDiskCacheMap.cpp
netwerk/cache/nsDiskCacheMap.h
netwerk/cache/nsDiskCacheStreams.cpp
netwerk/cache/nsDiskCacheStreams.h
netwerk/cache/nsMemoryCacheDevice.cpp
netwerk/cache/nsMemoryCacheDevice.h
toolkit/components/telemetry/Histograms.json
toolkit/components/telemetry/histogram-whitelists.json
--- a/netwerk/cache/moz.build
+++ b/netwerk/cache/moz.build
@@ -32,24 +32,17 @@ UNIFIED_SOURCES += [
     'nsCache.cpp',
     'nsCacheEntry.cpp',
     'nsCacheEntryDescriptor.cpp',
     'nsCacheMetaData.cpp',
     'nsCacheService.cpp',
     'nsCacheSession.cpp',
     'nsCacheUtils.cpp',
     'nsDeleteDir.cpp',
-    'nsDiskCacheBinding.cpp',
-    'nsDiskCacheBlockFile.cpp',
-    'nsDiskCacheDevice.cpp',
     'nsDiskCacheDeviceSQL.cpp',
-    'nsDiskCacheEntry.cpp',
-    'nsDiskCacheMap.cpp',
-    'nsDiskCacheStreams.cpp',
-    'nsMemoryCacheDevice.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '/netwerk/base',
 ]
 
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -14,19 +14,17 @@
 
 #include "necko-config.h"
 
 #include "nsCache.h"
 #include "nsCacheRequest.h"
 #include "nsCacheEntry.h"
 #include "nsCacheEntryDescriptor.h"
 #include "nsCacheDevice.h"
-#include "nsMemoryCacheDevice.h"
 #include "nsICacheVisitor.h"
-#include "nsDiskCacheDevice.h"
 #include "nsDiskCacheDeviceSQL.h"
 #include "nsCacheUtils.h"
 #include "../cache2/CacheObserver.h"
 #include "nsINamed.h"
 #include "nsIObserverService.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIFile.h"
@@ -74,74 +72,51 @@ class nsCacheProfilePrefObserver : publi
   virtual ~nsCacheProfilePrefObserver() = default;
 
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   nsCacheProfilePrefObserver()
       : mHaveProfile(false),
-        mDiskCacheEnabled(false),
-        mDiskCacheCapacity(0),
-        mDiskCacheMaxEntrySize(-1)  // -1 means "no limit"
-        ,
         mOfflineCacheEnabled(false),
         mOfflineCacheCapacity(0),
-        mMemoryCacheEnabled(false),
-        mMemoryCacheCapacity(-1),
-        mMemoryCacheMaxEntrySize(-1)  // -1 means "no limit"
-        ,
         mCacheCompressionLevel(CACHE_COMPRESSION_LEVEL),
         mSanitizeOnShutdown(false),
         mClearCacheOnShutdown(false) {}
 
   nsresult Install();
   void Remove();
   nsresult ReadPrefs(nsIPrefBranch *branch);
 
-  bool DiskCacheEnabled();
-  int32_t DiskCacheCapacity() { return mDiskCacheCapacity; }
-  void SetDiskCacheCapacity(int32_t);
-  int32_t DiskCacheMaxEntrySize() { return mDiskCacheMaxEntrySize; }
   nsIFile *DiskCacheParentDirectory() { return mDiskCacheParentDirectory; }
 
   bool OfflineCacheEnabled();
   int32_t OfflineCacheCapacity() { return mOfflineCacheCapacity; }
   nsIFile *OfflineCacheParentDirectory() {
     return mOfflineCacheParentDirectory;
   }
 
-  bool MemoryCacheEnabled();
-  int32_t MemoryCacheCapacity();
-  int32_t MemoryCacheMaxEntrySize() { return mMemoryCacheMaxEntrySize; }
-
   int32_t CacheCompressionLevel();
 
   bool SanitizeAtShutdown() {
     return mSanitizeOnShutdown && mClearCacheOnShutdown;
   }
 
   void PrefChanged(const char *aPref);
 
  private:
   bool mHaveProfile;
 
-  bool mDiskCacheEnabled;
-  int32_t mDiskCacheCapacity;      // in kilobytes
-  int32_t mDiskCacheMaxEntrySize;  // in kilobytes
   nsCOMPtr<nsIFile> mDiskCacheParentDirectory;
 
   bool mOfflineCacheEnabled;
   int32_t mOfflineCacheCapacity;  // in kilobytes
   nsCOMPtr<nsIFile> mOfflineCacheParentDirectory;
 
-  bool mMemoryCacheEnabled;
-  int32_t mMemoryCacheCapacity;      // in kilobytes
-  int32_t mMemoryCacheMaxEntrySize;  // in kilobytes
-
   int32_t mCacheCompressionLevel;
 
   bool mSanitizeOnShutdown;
   bool mClearCacheOnShutdown;
 };
 
 NS_IMPL_ISUPPORTS(nsCacheProfilePrefObserver, nsIObserver)
 
@@ -208,20 +183,16 @@ void nsCacheProfilePrefObserver::Remove(
   // remove Pref Service observers
   nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
   if (!prefs) return;
   Preferences::UnregisterCallbacks(
       PREF_CHANGE_METHOD(nsCacheProfilePrefObserver::PrefChanged), prefList,
       this);
 }
 
-void nsCacheProfilePrefObserver::SetDiskCacheCapacity(int32_t capacity) {
-  mDiskCacheCapacity = std::max(0, capacity);
-}
-
 NS_IMETHODIMP
 nsCacheProfilePrefObserver::Observe(nsISupports *subject, const char *topic,
                                     const char16_t *data_unicode) {
   NS_ConvertUTF16toUTF8 data(data_unicode);
   CACHE_LOG_INFO(("Observe [topic=%s data=%s]\n", topic, data.get()));
 
   if (!nsCacheService::IsInitialized()) {
     if (!strcmp("resume_process_notification", topic)) {
@@ -388,100 +359,23 @@ nsresult nsCacheService::SyncWithCacheIO
   gService->mNotified = false;
   while (!gService->mNotified) {
     gService->mCondVar.Wait();
   }
 
   return NS_OK;
 }
 
-bool nsCacheProfilePrefObserver::DiskCacheEnabled() {
-  if ((mDiskCacheCapacity == 0) || (!mDiskCacheParentDirectory)) return false;
-  return mDiskCacheEnabled && (!mSanitizeOnShutdown || !mClearCacheOnShutdown);
-}
-
 bool nsCacheProfilePrefObserver::OfflineCacheEnabled() {
   if ((mOfflineCacheCapacity == 0) || (!mOfflineCacheParentDirectory))
     return false;
 
   return mOfflineCacheEnabled;
 }
 
-bool nsCacheProfilePrefObserver::MemoryCacheEnabled() {
-  if (mMemoryCacheCapacity == 0) return false;
-  return mMemoryCacheEnabled;
-}
-
-/**
- * MemoryCacheCapacity
- *
- * If the browser.cache.memory.capacity preference is positive, we use that
- * value for the amount of memory available for the cache.
- *
- * If browser.cache.memory.capacity is zero, the memory cache is disabled.
- *
- * If browser.cache.memory.capacity is negative or not present, we use a
- * formula that grows less than linearly with the amount of system memory,
- * with an upper limit on the cache size. No matter how much physical RAM is
- * present, the default cache size would not exceed 32 MB. This maximum would
- * apply only to systems with more than 4 GB of RAM (e.g. terminal servers)
- *
- *   RAM   Cache
- *   ---   -----
- *   32 Mb   2 Mb
- *   64 Mb   4 Mb
- *  128 Mb   6 Mb
- *  256 Mb  10 Mb
- *  512 Mb  14 Mb
- * 1024 Mb  18 Mb
- * 2048 Mb  24 Mb
- * 4096 Mb  30 Mb
- *
- * The equation for this is (for cache size C and memory size K (kbytes)):
- *  x = log2(K) - 14
- *  C = x^2/3 + x + 2/3 + 0.1 (0.1 for rounding)
- *  if (C > 32) C = 32
- */
-
-int32_t nsCacheProfilePrefObserver::MemoryCacheCapacity() {
-  int32_t capacity = mMemoryCacheCapacity;
-  if (capacity >= 0) {
-    CACHE_LOG_DEBUG(("Memory cache capacity forced to %d\n", capacity));
-    return capacity;
-  }
-
-  static uint64_t bytes = PR_GetPhysicalMemorySize();
-  CACHE_LOG_DEBUG(("Physical Memory size is %" PRIu64 "\n", bytes));
-
-  // If getting the physical memory failed, arbitrarily assume
-  // 32 MB of RAM. We use a low default to have a reasonable
-  // size on all the devices we support.
-  if (bytes == 0) bytes = 32 * 1024 * 1024;
-
-  // Conversion from unsigned int64_t to double doesn't work on all platforms.
-  // We need to truncate the value at INT64_MAX to make sure we don't
-  // overflow.
-  if (bytes > INT64_MAX) bytes = INT64_MAX;
-
-  uint64_t kbytes = bytes >> 10;
-
-  double kBytesD = double(kbytes);
-
-  double x = log(kBytesD) / log(2.0) - 14;
-  if (x > 0) {
-    capacity = (int32_t)(x * x / 3.0 + x + 2.0 / 3 + 0.1);  // 0.1 for rounding
-    if (capacity > 32) capacity = 32;
-    capacity *= 1024;
-  } else {
-    capacity = 0;
-  }
-
-  return capacity;
-}
-
 int32_t nsCacheProfilePrefObserver::CacheCompressionLevel() {
   return mCacheCompressionLevel;
 }
 
 /******************************************************************************
  * nsProcessRequestEvent
  *****************************************************************************/
 
@@ -573,32 +467,27 @@ class nsDoomEvent : public Runnable {
   nsCOMPtr<nsIEventTarget> mEventTarget;
 };
 
 /******************************************************************************
  * nsCacheService
  *****************************************************************************/
 nsCacheService *nsCacheService::gService = nullptr;
 
-NS_IMPL_ISUPPORTS(nsCacheService, nsICacheService, nsICacheServiceInternal,
-                  nsIMemoryReporter)
+NS_IMPL_ISUPPORTS(nsCacheService, nsICacheService, nsICacheServiceInternal)
 
 nsCacheService::nsCacheService()
     : mObserver(nullptr),
       mLock("nsCacheService.mLock"),
       mCondVar(mLock, "nsCacheService.mCondVar"),
       mNotified(false),
       mTimeStampLock("nsCacheService.mTimeStampLock"),
       mInitialized(false),
       mClearingEntries(false),
-      mEnableMemoryDevice(true),
-      mEnableDiskDevice(true),
       mEnableOfflineDevice(false),
-      mMemoryDevice(nullptr),
-      mDiskDevice(nullptr),
       mOfflineDevice(nullptr),
       mDoomedEntries{},
       mTotalEntries(0),
       mCacheHits(0),
       mCacheMisses(0),
       mMaxKeyLength(0),
       mMaxDataSize(0),
       mMaxMetaSize(0),
@@ -658,21 +547,17 @@ nsresult nsCacheService::Init() {
 
   // create profile/preference observer
   if (!mObserver) {
     mObserver = new nsCacheProfilePrefObserver();
     NS_ADDREF(mObserver);
     mObserver->Install();
   }
 
-  mEnableDiskDevice = mObserver->DiskCacheEnabled();
   mEnableOfflineDevice = mObserver->OfflineCacheEnabled();
-  mEnableMemoryDevice = mObserver->MemoryCacheEnabled();
-
-  RegisterWeakMemoryReporter(this);
 
   mInitialized = true;
   return NS_OK;
 }
 
 void nsCacheService::Shutdown() {
   // This method must be called on the main thread because mCacheIOThread must
   // only be modified on the main thread.
@@ -694,18 +579,16 @@ void nsCacheService::Shutdown() {
     if (!mInitialized) return;
 
     mClearingEntries = true;
     DoomActiveEntries(nullptr);
   }
 
   CloseAllStreams();
 
-  UnregisterWeakMemoryReporter(this);
-
   {
     nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SHUTDOWN));
     NS_ASSERTION(mInitialized, "Bad state");
 
     mInitialized = false;
 
     // Clear entries
     ClearDoomList();
@@ -714,23 +597,16 @@ void nsCacheService::Shutdown() {
     // proceeding with destructive actions (bug #620660)
     (void)SyncWithCacheIOThread();
     mActiveEntries.Shutdown();
 
     // obtain the disk cache directory in case we need to sanitize it
     parentDir = mObserver->DiskCacheParentDirectory();
     shouldSanitize = mObserver->SanitizeAtShutdown();
 
-    // deallocate memory and disk caches
-    delete mMemoryDevice;
-    mMemoryDevice = nullptr;
-
-    delete mDiskDevice;
-    mDiskDevice = nullptr;
-
     if (mOfflineDevice) mOfflineDevice->Shutdown();
 
     NS_IF_RELEASE(mOfflineDevice);
 
     for (auto iter = mCustomOfflineDevices.Iter(); !iter.Done(); iter.Next()) {
       iter.Data()->Shutdown();
       iter.Remove();
     }
@@ -832,45 +708,26 @@ nsresult nsCacheService::EvictEntriesFor
     const char *clientID, nsCacheStoragePolicy storagePolicy) {
   RefPtr<EvictionNotifierRunnable> r =
       new EvictionNotifierRunnable(NS_ISUPPORTS_CAST(nsICacheService *, this));
   NS_DispatchToMainThread(r);
 
   nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_EVICTENTRIESFORCLIENT));
   nsresult res = NS_OK;
 
-  if (storagePolicy == nsICache::STORE_ANYWHERE ||
-      storagePolicy == nsICache::STORE_ON_DISK) {
-    if (mEnableDiskDevice) {
-      nsresult rv = NS_OK;
-      if (!mDiskDevice) rv = CreateDiskDevice();
-      if (mDiskDevice) rv = mDiskDevice->EvictEntries(clientID);
-      if (NS_FAILED(rv)) res = rv;
-    }
-  }
-
   // Only clear the offline cache if it has been specifically asked for.
   if (storagePolicy == nsICache::STORE_OFFLINE) {
     if (mEnableOfflineDevice) {
       nsresult rv = NS_OK;
       if (!mOfflineDevice) rv = CreateOfflineDevice();
       if (mOfflineDevice) rv = mOfflineDevice->EvictEntries(clientID);
       if (NS_FAILED(rv)) res = rv;
     }
   }
 
-  if (storagePolicy == nsICache::STORE_ANYWHERE ||
-      storagePolicy == nsICache::STORE_IN_MEMORY) {
-    // If there is no memory device, there is no need to evict it...
-    if (mMemoryDevice) {
-      nsresult rv = mMemoryDevice->EvictEntries(clientID);
-      if (NS_FAILED(rv)) res = rv;
-    }
-  }
-
   return res;
 }
 
 nsresult nsCacheService::IsStorageEnabledForPolicy(
     nsCacheStoragePolicy storagePolicy, bool *result) {
   if (gService == nullptr) return NS_ERROR_NOT_AVAILABLE;
   nsCacheServiceAutoLock lock(
       LOCK_TELEM(NSCACHESERVICE_ISSTORAGEENABLEDFORPOLICY));
@@ -886,26 +743,16 @@ nsresult nsCacheService::DoomEntry(nsCac
                    PromiseFlatCString(key).get()));
   if (!gService || !gService->mInitialized) return NS_ERROR_NOT_INITIALIZED;
 
   return DispatchToCacheIOThread(new nsDoomEvent(session, key, listener));
 }
 
 bool nsCacheService::IsStorageEnabledForPolicy_Locked(
     nsCacheStoragePolicy storagePolicy) {
-  if (gService->mEnableMemoryDevice &&
-      (storagePolicy == nsICache::STORE_ANYWHERE ||
-       storagePolicy == nsICache::STORE_IN_MEMORY)) {
-    return true;
-  }
-  if (gService->mEnableDiskDevice &&
-      (storagePolicy == nsICache::STORE_ANYWHERE ||
-       storagePolicy == nsICache::STORE_ON_DISK)) {
-    return true;
-  }
   if (gService->mEnableOfflineDevice &&
       storagePolicy == nsICache::STORE_OFFLINE) {
     return true;
   }
 
   return false;
 }
 
@@ -913,37 +760,22 @@ NS_IMETHODIMP nsCacheService::VisitEntri
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult nsCacheService::VisitEntriesInternal(nsICacheVisitor *visitor) {
   NS_ENSURE_ARG_POINTER(visitor);
 
   nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_VISITENTRIES));
 
-  if (!(mEnableDiskDevice || mEnableMemoryDevice || mEnableOfflineDevice))
-    return NS_ERROR_NOT_AVAILABLE;
+  if (!mEnableOfflineDevice) return NS_ERROR_NOT_AVAILABLE;
 
   // XXX record the fact that a visitation is in progress,
   // XXX i.e. keep list of visitors in progress.
 
   nsresult rv = NS_OK;
-  // If there is no memory device, there are then also no entries to visit...
-  if (mMemoryDevice) {
-    rv = mMemoryDevice->Visit(visitor);
-    if (NS_FAILED(rv)) return rv;
-  }
-
-  if (mEnableDiskDevice) {
-    if (!mDiskDevice) {
-      rv = CreateDiskDevice();
-      if (NS_FAILED(rv)) return rv;
-    }
-    rv = mDiskDevice->Visit(visitor);
-    if (NS_FAILED(rv)) return rv;
-  }
 
   if (mEnableOfflineDevice) {
     if (!mOfflineDevice) {
       rv = CreateOfflineDevice();
       if (NS_FAILED(rv)) return rv;
     }
     rv = mOfflineDevice->Visit(visitor);
     if (NS_FAILED(rv)) return rv;
@@ -1026,47 +858,16 @@ NS_IMETHODIMP nsCacheService::GetLockHel
   }
 
   return NS_OK;
 }
 
 /**
  * Internal Methods
  */
-nsresult nsCacheService::CreateDiskDevice() {
-  if (!mInitialized) return NS_ERROR_NOT_AVAILABLE;
-  if (!mEnableDiskDevice) return NS_ERROR_NOT_AVAILABLE;
-  if (mDiskDevice) return NS_OK;
-
-  mDiskDevice = new nsDiskCacheDevice;
-  if (!mDiskDevice) return NS_ERROR_OUT_OF_MEMORY;
-
-  // set the preferences
-  mDiskDevice->SetCacheParentDirectory(mObserver->DiskCacheParentDirectory());
-  mDiskDevice->SetCapacity(mObserver->DiskCacheCapacity());
-  mDiskDevice->SetMaxEntrySize(mObserver->DiskCacheMaxEntrySize());
-
-  nsresult rv = mDiskDevice->Init();
-  if (NS_FAILED(rv)) {
-#if DEBUG
-    printf("###\n");
-    printf("### mDiskDevice->Init() failed (0x%.8x)\n",
-           static_cast<uint32_t>(rv));
-    printf("###    - disabling disk cache for this session.\n");
-    printf("###\n");
-#endif
-    mEnableDiskDevice = false;
-    delete mDiskDevice;
-    mDiskDevice = nullptr;
-    return rv;
-  }
-
-  return NS_OK;
-}
-
 nsresult nsCacheService::GetOfflineDevice(nsOfflineCacheDevice **aDevice) {
   if (!mOfflineDevice) {
     nsresult rv = CreateOfflineDevice();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   NS_ADDREF(*aDevice = mOfflineDevice);
   return NS_OK;
@@ -1134,40 +935,16 @@ nsresult nsCacheService::CreateCustomOff
                      static_cast<uint32_t>(rv)));
     CACHE_LOG_DEBUG(("    - disabling offline cache for this session.\n"));
 
     NS_RELEASE(*aDevice);
   }
   return rv;
 }
 
-nsresult nsCacheService::CreateMemoryDevice() {
-  if (!mInitialized) return NS_ERROR_NOT_AVAILABLE;
-  if (!mEnableMemoryDevice) return NS_ERROR_NOT_AVAILABLE;
-  if (mMemoryDevice) return NS_OK;
-
-  mMemoryDevice = new nsMemoryCacheDevice;
-  if (!mMemoryDevice) return NS_ERROR_OUT_OF_MEMORY;
-
-  // set preference
-  int32_t capacity = mObserver->MemoryCacheCapacity();
-  CACHE_LOG_DEBUG(("Creating memory device with capacity %d\n", capacity));
-  mMemoryDevice->SetCapacity(capacity);
-  mMemoryDevice->SetMaxEntrySize(mObserver->MemoryCacheMaxEntrySize());
-
-  nsresult rv = mMemoryDevice->Init();
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Initialization of Memory Cache failed.");
-    delete mMemoryDevice;
-    mMemoryDevice = nullptr;
-  }
-
-  return rv;
-}
-
 nsresult nsCacheService::RemoveCustomOfflineDevice(
     nsOfflineCacheDevice *aDevice) {
   nsCOMPtr<nsIFile> profileDir = aDevice->BaseDirectory();
   if (!profileDir) return NS_ERROR_UNEXPECTED;
 
   nsAutoString profilePath;
   nsresult rv = profileDir->GetPath(profilePath);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1405,18 +1182,17 @@ nsresult nsCacheService::ActivateEntry(n
   nsresult rv = NS_OK;
 
   NS_ASSERTION(request != nullptr, "ActivateEntry called with no request");
   if (result) *result = nullptr;
   if (doomedEntry) *doomedEntry = nullptr;
   if ((!request) || (!result) || (!doomedEntry)) return NS_ERROR_NULL_POINTER;
 
   // check if the request can be satisfied
-  if (!mEnableMemoryDevice && !request->IsStreamBased())
-    return NS_ERROR_FAILURE;
+  if (!request->IsStreamBased()) return NS_ERROR_FAILURE;
   if (!IsStorageEnabledForPolicy_Locked(request->StoragePolicy()))
     return NS_ERROR_FAILURE;
 
   // search active entries (including those not bound to device)
   nsCacheEntry *entry = mActiveEntries.GetEntry(&(request->mKey));
   CACHE_LOG_DEBUG(("Active entry for request %p is %p\n", request, entry));
 
   if (!entry) {
@@ -1494,46 +1270,19 @@ error:
 }
 
 nsCacheEntry *nsCacheService::SearchCacheDevices(nsCString *key,
                                                  nsCacheStoragePolicy policy,
                                                  bool *collision) {
   Telemetry::AutoTimer<Telemetry::CACHE_DEVICE_SEARCH_2> timer;
   nsCacheEntry *entry = nullptr;
 
-  CACHE_LOG_DEBUG(("mMemoryDevice: 0x%p\n", mMemoryDevice));
-
   *collision = false;
-  if ((policy == nsICache::STORE_ANYWHERE) ||
-      (policy == nsICache::STORE_IN_MEMORY)) {
-    // If there is no memory device, then there is nothing to search...
-    if (mMemoryDevice) {
-      entry = mMemoryDevice->FindEntry(key, collision);
-      CACHE_LOG_DEBUG(
-          ("Searching mMemoryDevice for key %s found: 0x%p, "
-           "collision: %d\n",
-           key->get(), entry, *collision));
-    }
-  }
-
-  if (!entry && ((policy == nsICache::STORE_ANYWHERE) ||
-                 (policy == nsICache::STORE_ON_DISK))) {
-    if (mEnableDiskDevice) {
-      if (!mDiskDevice) {
-        nsresult rv = CreateDiskDevice();
-        if (NS_FAILED(rv)) return nullptr;
-      }
-
-      entry = mDiskDevice->FindEntry(key, collision);
-    }
-  }
-
-  if (!entry &&
-      (policy == nsICache::STORE_OFFLINE ||
-       (policy == nsICache::STORE_ANYWHERE && gIOService->IsOffline()))) {
+  if (policy == nsICache::STORE_OFFLINE ||
+      (policy == nsICache::STORE_ANYWHERE && gIOService->IsOffline())) {
     if (mEnableOfflineDevice) {
       if (!mOfflineDevice) {
         nsresult rv = CreateOfflineDevice();
         if (NS_FAILED(rv)) return nullptr;
       }
 
       entry = mOfflineDevice->FindEntry(key, collision);
     }
@@ -1543,62 +1292,16 @@ nsCacheEntry *nsCacheService::SearchCach
 }
 
 nsCacheDevice *nsCacheService::EnsureEntryHasDevice(nsCacheEntry *entry) {
   nsCacheDevice *device = entry->CacheDevice();
   // return device if found, possibly null if the entry is doomed i.e prevent
   // doomed entries to bind to a device (see e.g. bugs #548406 and #596443)
   if (device || entry->IsDoomed()) return device;
 
-  int64_t predictedDataSize = entry->PredictedDataSize();
-  if (entry->IsStreamData() && entry->IsAllowedOnDisk() && mEnableDiskDevice) {
-    // this is the default
-    if (!mDiskDevice) {
-      (void)CreateDiskDevice();  // ignore the error (check for mDiskDevice
-                                 // instead)
-    }
-
-    if (mDiskDevice) {
-      // Bypass the cache if Content-Length says the entry will be too big
-      if (predictedDataSize != -1 &&
-          mDiskDevice->EntryIsTooBig(predictedDataSize)) {
-        DebugOnly<nsresult> rv = nsCacheService::DoomEntry(entry);
-        NS_ASSERTION(NS_SUCCEEDED(rv), "DoomEntry() failed.");
-        return nullptr;
-      }
-
-      entry->MarkBinding();  // enter state of binding
-      nsresult rv = mDiskDevice->BindEntry(entry);
-      entry->ClearBinding();  // exit state of binding
-      if (NS_SUCCEEDED(rv)) device = mDiskDevice;
-    }
-  }
-
-  // if we can't use mDiskDevice, try mMemoryDevice
-  if (!device && mEnableMemoryDevice && entry->IsAllowedInMemory()) {
-    if (!mMemoryDevice) {
-      (void)CreateMemoryDevice();  // ignore the error (check for mMemoryDevice
-                                   // instead)
-    }
-    if (mMemoryDevice) {
-      // Bypass the cache if Content-Length says entry will be too big
-      if (predictedDataSize != -1 &&
-          mMemoryDevice->EntryIsTooBig(predictedDataSize)) {
-        DebugOnly<nsresult> rv = nsCacheService::DoomEntry(entry);
-        NS_ASSERTION(NS_SUCCEEDED(rv), "DoomEntry() failed.");
-        return nullptr;
-      }
-
-      entry->MarkBinding();  // enter state of binding
-      nsresult rv = mMemoryDevice->BindEntry(entry);
-      entry->ClearBinding();  // exit state of binding
-      if (NS_SUCCEEDED(rv)) device = mMemoryDevice;
-    }
-  }
-
   if (!device && entry->IsStreamData() && entry->IsAllowedOffline() &&
       mEnableOfflineDevice) {
     if (!mOfflineDevice) {
       (void)CreateOfflineDevice();  // ignore the error (check for
                                     // mOfflineDevice instead)
     }
 
     device = entry->CustomCacheDevice() ? entry->CustomCacheDevice()
@@ -1673,68 +1376,38 @@ void nsCacheService::OnProfileShutdown()
 
   nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILESHUTDOWN));
   gService->ClearDoomList();
 
   // Make sure to wait for any pending cache-operations before
   // proceeding with destructive actions (bug #620660)
   (void)SyncWithCacheIOThread();
 
-  if (gService->mDiskDevice && gService->mEnableDiskDevice) {
-    gService->mDiskDevice->Shutdown();
-  }
-  gService->mEnableDiskDevice = false;
-
   if (gService->mOfflineDevice && gService->mEnableOfflineDevice) {
     gService->mOfflineDevice->Shutdown();
   }
   for (auto iter = gService->mCustomOfflineDevices.Iter(); !iter.Done();
        iter.Next()) {
     iter.Data()->Shutdown();
     iter.Remove();
   }
 
   gService->mEnableOfflineDevice = false;
 
-  if (gService->mMemoryDevice) {
-    // clear memory cache
-    gService->mMemoryDevice->EvictEntries(nullptr);
-  }
-
   gService->mClearingEntries = false;
 }
 
 void nsCacheService::OnProfileChanged() {
   if (!gService) return;
 
   CACHE_LOG_DEBUG(("nsCacheService::OnProfileChanged"));
 
   nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_ONPROFILECHANGED));
 
-  gService->mEnableDiskDevice = gService->mObserver->DiskCacheEnabled();
   gService->mEnableOfflineDevice = gService->mObserver->OfflineCacheEnabled();
-  gService->mEnableMemoryDevice = gService->mObserver->MemoryCacheEnabled();
-
-  if (gService->mDiskDevice) {
-    gService->mDiskDevice->SetCacheParentDirectory(
-        gService->mObserver->DiskCacheParentDirectory());
-    gService->mDiskDevice->SetCapacity(
-        gService->mObserver->DiskCacheCapacity());
-
-    // XXX initialization of mDiskDevice could be made lazily, if
-    // mEnableDiskDevice is false
-    nsresult rv = gService->mDiskDevice->Init();
-    if (NS_FAILED(rv)) {
-      NS_ERROR(
-          "nsCacheService::OnProfileChanged: Re-initializing disk device "
-          "failed");
-      gService->mEnableDiskDevice = false;
-      // XXX delete mDiskDevice?
-    }
-  }
 
   if (gService->mOfflineDevice) {
     gService->mOfflineDevice->SetCacheParentDirectory(
         gService->mObserver->OfflineCacheParentDirectory());
     gService->mOfflineDevice->SetCapacity(
         gService->mObserver->OfflineCacheCapacity());
 
     // XXX initialization of mOfflineDevice could be made lazily, if
@@ -1744,68 +1417,16 @@ void nsCacheService::OnProfileChanged() 
     if (NS_FAILED(rv)) {
       NS_ERROR(
           "nsCacheService::OnProfileChanged: Re-initializing offline device "
           "failed");
       gService->mEnableOfflineDevice = false;
       // XXX delete mOfflineDevice?
     }
   }
-
-  // If memoryDevice exists, reset its size to the new profile
-  if (gService->mMemoryDevice) {
-    if (gService->mEnableMemoryDevice) {
-      // make sure that capacity is reset to the right value
-      int32_t capacity = gService->mObserver->MemoryCacheCapacity();
-      CACHE_LOG_DEBUG(("Resetting memory device capacity to %d\n", capacity));
-      gService->mMemoryDevice->SetCapacity(capacity);
-    } else {
-      // tell memory device to evict everything
-      CACHE_LOG_DEBUG(("memory device disabled\n"));
-      gService->mMemoryDevice->SetCapacity(0);
-      // Don't delete memory device, because some entries may be active still...
-    }
-  }
-}
-
-void nsCacheService::SetDiskCacheEnabled(bool enabled) {
-  if (!gService) return;
-  nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHEENABLED));
-  gService->mEnableDiskDevice = enabled;
-}
-
-void nsCacheService::SetDiskCacheCapacity(int32_t capacity) {
-  if (!gService) return;
-  nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETDISKCACHECAPACITY));
-
-  if (gService->mDiskDevice) {
-    gService->mDiskDevice->SetCapacity(capacity);
-  }
-
-  gService->mEnableDiskDevice = gService->mObserver->DiskCacheEnabled();
-}
-
-void nsCacheService::SetDiskCacheMaxEntrySize(int32_t maxSize) {
-  if (!gService) return;
-  nsCacheServiceAutoLock lock(
-      LOCK_TELEM(NSCACHESERVICE_SETDISKCACHEMAXENTRYSIZE));
-
-  if (gService->mDiskDevice) {
-    gService->mDiskDevice->SetMaxEntrySize(maxSize);
-  }
-}
-
-void nsCacheService::SetMemoryCacheMaxEntrySize(int32_t maxSize) {
-  if (!gService) return;
-  nsCacheServiceAutoLock lock(
-      LOCK_TELEM(NSCACHESERVICE_SETMEMORYCACHEMAXENTRYSIZE));
-
-  if (gService->mMemoryDevice) {
-    gService->mMemoryDevice->SetMaxEntrySize(maxSize);
-  }
 }
 
 void nsCacheService::SetOfflineCacheEnabled(bool enabled) {
   if (!gService) return;
   nsCacheServiceAutoLock lock(
       LOCK_TELEM(NSCACHESERVICE_SETOFFLINECACHEENABLED));
   gService->mEnableOfflineDevice = enabled;
 }
@@ -1817,42 +1438,16 @@ void nsCacheService::SetOfflineCacheCapa
 
   if (gService->mOfflineDevice) {
     gService->mOfflineDevice->SetCapacity(capacity);
   }
 
   gService->mEnableOfflineDevice = gService->mObserver->OfflineCacheEnabled();
 }
 
-void nsCacheService::SetMemoryCache() {
-  if (!gService) return;
-
-  CACHE_LOG_DEBUG(("nsCacheService::SetMemoryCache"));
-
-  nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_SETMEMORYCACHE));
-
-  gService->mEnableMemoryDevice = gService->mObserver->MemoryCacheEnabled();
-
-  if (gService->mEnableMemoryDevice) {
-    if (gService->mMemoryDevice) {
-      int32_t capacity = gService->mObserver->MemoryCacheCapacity();
-      // make sure that capacity is reset to the right value
-      CACHE_LOG_DEBUG(("Resetting memory device capacity to %d\n", capacity));
-      gService->mMemoryDevice->SetCapacity(capacity);
-    }
-  } else {
-    if (gService->mMemoryDevice) {
-      // tell memory device to evict everything
-      CACHE_LOG_DEBUG(("memory device disabled\n"));
-      gService->mMemoryDevice->SetCapacity(0);
-      // Don't delete memory device, because some entries may be active still...
-    }
-  }
-}
-
 /******************************************************************************
  * static methods for nsCacheEntryDescriptor
  *****************************************************************************/
 void nsCacheService::CloseDescriptor(nsCacheEntryDescriptor *descriptor) {
   // ask entry to remove descriptor
   nsCacheEntry *entry = descriptor->CacheEntry();
   bool doomEntry;
   bool stillActive = entry->RemoveDescriptor(descriptor, &doomEntry);
@@ -2357,36 +1952,9 @@ void nsCacheService::MoveOrRemoveDiskCac
 }
 
 static bool IsEntryPrivate(nsCacheEntry *entry) { return entry->IsPrivate(); }
 
 void nsCacheService::LeavePrivateBrowsing() {
   nsCacheServiceAutoLock lock;
 
   gService->DoomActiveEntries(IsEntryPrivate);
-
-  if (gService->mMemoryDevice) {
-    // clear memory cache
-    gService->mMemoryDevice->EvictPrivateEntries();
-  }
 }
-
-MOZ_DEFINE_MALLOC_SIZE_OF(DiskCacheDeviceMallocSizeOf)
-
-NS_IMETHODIMP
-nsCacheService::CollectReports(nsIHandleReportCallback *aHandleReport,
-                               nsISupports *aData, bool aAnonymize) {
-  size_t disk = 0;
-  if (mDiskDevice) {
-    nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHESERVICE_DISKDEVICEHEAPSIZE));
-    disk = mDiskDevice->SizeOfIncludingThis(DiskCacheDeviceMallocSizeOf);
-  }
-
-  size_t memory = mMemoryDevice ? mMemoryDevice->TotalSize() : 0;
-
-  MOZ_COLLECT_REPORT("explicit/network/disk-cache", KIND_HEAP, UNITS_BYTES,
-                     disk, "Memory used by the network disk cache.");
-
-  MOZ_COLLECT_REPORT("explicit/network/memory-cache", KIND_HEAP, UNITS_BYTES,
-                     memory, "Memory used by the network memory cache.");
-
-  return NS_OK;
-}
--- a/netwerk/cache/nsCacheService.h
+++ b/netwerk/cache/nsCacheService.h
@@ -8,31 +8,28 @@
 #define _nsCacheService_h_
 
 #include "nsICacheService.h"
 #include "nsCacheSession.h"
 #include "nsCacheDevice.h"
 #include "nsCacheEntry.h"
 #include "nsThreadUtils.h"
 #include "nsICacheListener.h"
-#include "nsIMemoryReporter.h"
 
 #include "prthread.h"
 #include "nsIObserver.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsRefPtrHashtable.h"
 #include "mozilla/CondVar.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Telemetry.h"
 
 class nsCacheRequest;
 class nsCacheProfilePrefObserver;
-class nsDiskCacheDevice;
-class nsMemoryCacheDevice;
 class nsOfflineCacheDevice;
 class nsCacheServiceAutoLock;
 class nsITimer;
 class mozIStorageService;
 
 /******************************************************************************
  * nsNotifyDoomListener
  *****************************************************************************/
@@ -55,25 +52,23 @@ class nsNotifyDoomListener : public mozi
   nsICacheListener *mListener;
   nsresult mStatus;
 };
 
 /******************************************************************************
  *  nsCacheService
  ******************************************************************************/
 
-class nsCacheService final : public nsICacheServiceInternal,
-                             public nsIMemoryReporter {
+class nsCacheService final : public nsICacheServiceInternal {
   virtual ~nsCacheService();
 
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSICACHESERVICE
   NS_DECL_NSICACHESERVICEINTERNAL
-  NS_DECL_NSIMEMORYREPORTER
 
   nsCacheService();
 
   // Define a Create method to be used with a factory:
   static nsresult Create(nsISupports *outer, const nsIID &iid, void **result);
 
   /**
    * Methods called by nsCacheSession
@@ -163,34 +158,20 @@ class nsCacheService final : public nsIC
   static nsresult SyncWithCacheIOThread();
 
   /**
    * Methods called by nsCacheProfilePrefObserver
    */
   static void OnProfileShutdown();
   static void OnProfileChanged();
 
-  static void SetDiskCacheEnabled(bool enabled);
-  // Sets the disk cache capacity (in kilobytes)
-  static void SetDiskCacheCapacity(int32_t capacity);
-  // Set max size for a disk-cache entry (in KB). -1 disables limit up to
-  // 1/8th of disk cache size
-  static void SetDiskCacheMaxEntrySize(int32_t maxSize);
-  // Set max size for a memory-cache entry (in kilobytes). -1 disables
-  // limit up to 90% of memory cache size
-  static void SetMemoryCacheMaxEntrySize(int32_t maxSize);
-
   static void SetOfflineCacheEnabled(bool enabled);
   // Sets the offline cache capacity (in kilobytes)
   static void SetOfflineCacheCapacity(int32_t capacity);
 
-  static void SetMemoryCache();
-
-  static void SetCacheCompressionLevel(int32_t level);
-
   static void MoveOrRemoveDiskCache(nsIFile *aOldCacheDir,
                                     nsIFile *aNewCacheDir,
                                     const char *aCacheSubdir);
 
   nsresult Init();
   void Shutdown();
 
   static bool IsInitialized() {
@@ -215,17 +196,16 @@ class nsCacheService final : public nsIC
   nsresult EvictEntriesInternal(nsCacheStoragePolicy storagePolicy);
 
  private:
   friend class nsCacheServiceAutoLock;
   friend class nsOfflineCacheDevice;
   friend class nsProcessRequestEvent;
   friend class nsBlockOnCacheThreadEvent;
   friend class nsDoomEvent;
-  friend class nsDiskCacheMap;
   friend class nsAsyncDoomEvent;
   friend class nsCacheEntryDescriptor;
 
   /**
    * Internal Methods
    */
 
   static void Lock();
@@ -301,22 +281,18 @@ class nsCacheService final : public nsIC
 
   nsCOMPtr<nsIThread> mCacheIOThread;
 
   nsTArray<nsISupports *> mDoomedObjects;
 
   bool mInitialized;
   bool mClearingEntries;
 
-  bool mEnableMemoryDevice;
-  bool mEnableDiskDevice;
   bool mEnableOfflineDevice;
 
-  nsMemoryCacheDevice *mMemoryDevice;
-  nsDiskCacheDevice *mDiskDevice;
   nsOfflineCacheDevice *mOfflineDevice;
 
   nsRefPtrHashtable<nsStringHashKey, nsOfflineCacheDevice>
       mCustomOfflineDevices;
 
   nsCacheEntryHashTable mActiveEntries;
   PRCList mDoomedEntries;
 
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheBinding.cpp
+++ /dev/null
@@ -1,317 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "mozilla/MemoryReporting.h"
-#include "nsCache.h"
-#include <limits.h>
-
-#include "nscore.h"
-#include "nsDiskCacheBinding.h"
-#include "nsCacheService.h"
-
-using namespace mozilla;
-
-/******************************************************************************
- *  static hash table callback functions
- *
- *****************************************************************************/
-struct HashTableEntry : PLDHashEntryHdr {
-  nsDiskCacheBinding *mBinding;
-};
-
-static PLDHashNumber HashKey(const void *key) {
-  return (PLDHashNumber)NS_PTR_TO_INT32(key);
-}
-
-static bool MatchEntry(const PLDHashEntryHdr *header, const void *key) {
-  HashTableEntry *hashEntry = (HashTableEntry *)header;
-  return (hashEntry->mBinding->mRecord.HashNumber() ==
-          (PLDHashNumber)NS_PTR_TO_INT32(key));
-}
-
-static void MoveEntry(PLDHashTable * /* table */, const PLDHashEntryHdr *src,
-                      PLDHashEntryHdr *dst) {
-  new (KnownNotNull, dst) HashTableEntry(std::move(*(HashTableEntry *)src));
-  // No need to delete `src`.
-}
-
-static void ClearEntry(PLDHashTable * /* table */, PLDHashEntryHdr *header) {
-  ((HashTableEntry *)header)->mBinding = nullptr;
-}
-
-/******************************************************************************
- *  Utility Functions
- *****************************************************************************/
-nsDiskCacheBinding *GetCacheEntryBinding(nsCacheEntry *entry) {
-  return (nsDiskCacheBinding *)entry->Data();
-}
-
-/******************************************************************************
- *  nsDiskCacheBinding
- *****************************************************************************/
-
-NS_IMPL_ISUPPORTS0(nsDiskCacheBinding)
-
-nsDiskCacheBinding::nsDiskCacheBinding(nsCacheEntry *entry,
-                                       nsDiskCacheRecord *record)
-    : mCacheEntry(entry), mStreamIO(nullptr), mDeactivateEvent(nullptr) {
-  NS_ASSERTION(record->ValidRecord(), "bad record");
-  PR_INIT_CLIST(this);
-  mRecord = *record;
-  mDoomed = entry->IsDoomed();
-  mGeneration = record->Generation();  // 0 == uninitialized, or data & meta
-                                       // using block files
-}
-
-nsDiskCacheBinding::~nsDiskCacheBinding() {
-  // Grab the cache lock since the binding is stored in nsCacheEntry::mData
-  // and it is released using nsCacheService::ReleaseObject_Locked() which
-  // releases the object outside the cache lock.
-  nsCacheServiceAutoLock lock;
-
-  NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "binding deleted while still on list");
-  if (!PR_CLIST_IS_EMPTY(this))
-    PR_REMOVE_LINK(this);  // XXX why are we still on a list?
-
-  // sever streamIO/binding link
-  if (mStreamIO) {
-    if (NS_FAILED(mStreamIO->ClearBinding()))
-      nsCacheService::DoomEntry(mCacheEntry);
-    NS_RELEASE(mStreamIO);
-  }
-}
-
-nsresult nsDiskCacheBinding::EnsureStreamIO() {
-  if (!mStreamIO) {
-    mStreamIO = new nsDiskCacheStreamIO(this);
-    if (!mStreamIO) return NS_ERROR_OUT_OF_MEMORY;
-    NS_ADDREF(mStreamIO);
-  }
-  return NS_OK;
-}
-
-/******************************************************************************
- *  nsDiskCacheBindery
- *
- *  Keeps track of bound disk cache entries to detect for collisions.
- *
- *****************************************************************************/
-
-const PLDHashTableOps nsDiskCacheBindery::ops = {HashKey, MatchEntry, MoveEntry,
-                                                 ClearEntry};
-
-nsDiskCacheBindery::nsDiskCacheBindery()
-    : table(&ops, sizeof(HashTableEntry), kInitialTableLength),
-      initialized(false) {}
-
-nsDiskCacheBindery::~nsDiskCacheBindery() { Reset(); }
-
-void nsDiskCacheBindery::Init() {
-  table.ClearAndPrepareForLength(kInitialTableLength);
-  initialized = true;
-}
-
-void nsDiskCacheBindery::Reset() {
-  if (initialized) {
-    table.ClearAndPrepareForLength(kInitialTableLength);
-    initialized = false;
-  }
-}
-
-nsDiskCacheBinding *nsDiskCacheBindery::CreateBinding(
-    nsCacheEntry *entry, nsDiskCacheRecord *record) {
-  NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
-  nsCOMPtr<nsISupports> data = entry->Data();
-  if (data) {
-    NS_ERROR("cache entry already has bind data");
-    return nullptr;
-  }
-
-  nsDiskCacheBinding *binding = new nsDiskCacheBinding(entry, record);
-  if (!binding) return nullptr;
-
-  // give ownership of the binding to the entry
-  entry->SetData(binding);
-
-  // add binding to collision detection system
-  nsresult rv = AddBinding(binding);
-  if (NS_FAILED(rv)) {
-    entry->SetData(nullptr);
-    return nullptr;
-  }
-
-  return binding;
-}
-
-/**
- *  FindActiveEntry :  to find active colliding entry so we can doom it
- */
-nsDiskCacheBinding *nsDiskCacheBindery::FindActiveBinding(
-    uint32_t hashNumber) const {
-  NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
-  // find hash entry for key
-  auto hashEntry = static_cast<HashTableEntry *>(
-      table.Search((void *)(uintptr_t)hashNumber));
-  if (!hashEntry) return nullptr;
-
-  // walk list looking for active entry
-  NS_ASSERTION(hashEntry->mBinding, "hash entry left with no binding");
-  nsDiskCacheBinding *binding = hashEntry->mBinding;
-  while (binding->mCacheEntry->IsDoomed()) {
-    binding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
-    if (binding == hashEntry->mBinding) return nullptr;
-  }
-  return binding;
-}
-
-/**
- *  AddBinding
- *
- *  Called from FindEntry() if we read an entry off of disk
- *      - it may already have a generation number
- *      - a generation number conflict is an error
- *
- *  Called from BindEntry()
- *      - a generation number needs to be assigned
- */
-nsresult nsDiskCacheBindery::AddBinding(nsDiskCacheBinding *binding) {
-  NS_ENSURE_ARG_POINTER(binding);
-  NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
-
-  // find hash entry for key
-  auto hashEntry = static_cast<HashTableEntry *>(
-      table.Add((void *)(uintptr_t)binding->mRecord.HashNumber(), fallible));
-  if (!hashEntry) return NS_ERROR_OUT_OF_MEMORY;
-
-  if (hashEntry->mBinding == nullptr) {
-    hashEntry->mBinding = binding;
-    if (binding->mGeneration == 0)
-      binding->mGeneration = 1;  // if generation uninitialized, set it to 1
-
-    return NS_OK;
-  }
-
-  // insert binding in generation order
-  nsDiskCacheBinding *p = hashEntry->mBinding;
-  bool calcGeneration =
-      (binding->mGeneration == 0);  // do we need to calculate generation?
-  if (calcGeneration)
-    binding->mGeneration = 1;  // initialize to 1 if uninitialized
-  while (true) {
-    if (binding->mGeneration < p->mGeneration) {
-      // here we are
-      PR_INSERT_BEFORE(binding, p);
-      if (hashEntry->mBinding == p) hashEntry->mBinding = binding;
-      break;
-    }
-
-    if (binding->mGeneration == p->mGeneration) {
-      if (calcGeneration)
-        ++binding->mGeneration;  // try the next generation
-      else {
-        NS_ERROR("### disk cache: generations collide!");
-        return NS_ERROR_UNEXPECTED;
-      }
-    }
-
-    p = (nsDiskCacheBinding *)PR_NEXT_LINK(p);
-    if (p == hashEntry->mBinding) {
-      // end of line: insert here or die
-      p = (nsDiskCacheBinding *)PR_PREV_LINK(
-          p);  // back up and check generation
-      if (p->mGeneration == 255) {
-        NS_WARNING("### disk cache: generation capacity at full");
-        return NS_ERROR_UNEXPECTED;
-      }
-      PR_INSERT_BEFORE(binding, hashEntry->mBinding);
-      break;
-    }
-  }
-  return NS_OK;
-}
-
-/**
- *  RemoveBinding :  remove binding from collision detection on deactivation
- */
-void nsDiskCacheBindery::RemoveBinding(nsDiskCacheBinding *binding) {
-  NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
-  if (!initialized) return;
-
-  void *key = (void *)(uintptr_t)binding->mRecord.HashNumber();
-  auto hashEntry =
-      static_cast<HashTableEntry *>(table.Search((void *)(uintptr_t)key));
-  if (!hashEntry) {
-    NS_WARNING("### disk cache: binding not in hashtable!");
-    return;
-  }
-
-  if (binding == hashEntry->mBinding) {
-    if (PR_CLIST_IS_EMPTY(binding)) {
-      // remove this hash entry
-      table.Remove((void *)(uintptr_t)binding->mRecord.HashNumber());
-      return;
-    }
-    // promote next binding to head, and unlink this binding
-    hashEntry->mBinding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
-  }
-  PR_REMOVE_AND_INIT_LINK(binding);
-}
-
-/**
- * ActiveBindings: return true if any bindings have open descriptors.
- */
-bool nsDiskCacheBindery::ActiveBindings() {
-  NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
-  if (!initialized) return false;
-
-  for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {
-    auto entry = static_cast<HashTableEntry *>(iter.Get());
-    nsDiskCacheBinding *binding = entry->mBinding;
-    nsDiskCacheBinding *head = binding;
-    do {
-      if (binding->IsActive()) {
-        return true;
-      }
-      binding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
-    } while (binding != head);
-  }
-
-  return false;
-}
-
-/**
- * SizeOfExcludingThis: return the amount of heap memory (bytes) being used by
- * the bindery.
- */
-size_t nsDiskCacheBindery::SizeOfExcludingThis(
-    mozilla::MallocSizeOf aMallocSizeOf) {
-  NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
-  if (!initialized) return 0;
-
-  size_t size = 0;
-
-  for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {
-    auto entry = static_cast<HashTableEntry *>(iter.Get());
-    nsDiskCacheBinding *binding = entry->mBinding;
-
-    nsDiskCacheBinding *head = binding;
-    do {
-      size += aMallocSizeOf(binding);
-      if (binding->mStreamIO) {
-        size += binding->mStreamIO->SizeOfIncludingThis(aMallocSizeOf);
-      }
-
-      // No good way to get at mDeactivateEvent internals for proper
-      // size, so we use this as an estimate.
-      if (binding->mDeactivateEvent) {
-        size += aMallocSizeOf(binding->mDeactivateEvent);
-      }
-      binding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
-    } while (binding != head);
-  }
-
-  return size;
-}
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheBinding.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _nsDiskCacheBinding_h_
-#define _nsDiskCacheBinding_h_
-
-#include "mozilla/MemoryReporting.h"
-#include "nspr.h"
-#include "PLDHashTable.h"
-
-#include "nsISupports.h"
-#include "nsCacheEntry.h"
-
-#include "nsDiskCacheMap.h"
-#include "nsDiskCacheStreams.h"
-
-/******************************************************************************
- *  nsDiskCacheBinding
- *
- *  Created for disk cache specific data and stored in nsCacheEntry.mData as
- *  an nsISupports.  Also stored in nsDiskCacheHashTable, with collisions
- *  linked by the PRCList.
- *
- *****************************************************************************/
-
-class nsDiskCacheDeviceDeactivateEntryEvent;
-
-class nsDiskCacheBinding : public nsISupports, public PRCList {
-  virtual ~nsDiskCacheBinding();
-
- public:
-  NS_DECL_THREADSAFE_ISUPPORTS
-
-  nsDiskCacheBinding(nsCacheEntry* entry, nsDiskCacheRecord* record);
-
-  nsresult EnsureStreamIO();
-  bool IsActive() { return mCacheEntry != nullptr; }
-
-  // XXX make friends
- public:
-  nsCacheEntry* mCacheEntry;  // back pointer to parent nsCacheEntry
-  nsDiskCacheRecord mRecord;
-  nsDiskCacheStreamIO* mStreamIO;  // strong reference
-  bool mDoomed;                    // record is not stored in cache map
-  uint8_t mGeneration;             // possibly just reservation
-
-  // If set, points to a pending event which will deactivate |mCacheEntry|.
-  // If not set then either |mCacheEntry| is not deactivated, or it has been
-  // deactivated but the device returned it from FindEntry() before the event
-  // fired. In both two latter cases this binding is to be considered valid.
-  nsDiskCacheDeviceDeactivateEntryEvent* mDeactivateEvent;
-};
-
-/******************************************************************************
- *  Utility Functions
- *****************************************************************************/
-
-nsDiskCacheBinding* GetCacheEntryBinding(nsCacheEntry* entry);
-
-/******************************************************************************
- *  nsDiskCacheBindery
- *
- *  Used to keep track of nsDiskCacheBinding associated with active/bound (and
- *  possibly doomed) entries.  Lookups on 4 byte disk hash to find collisions
- *  (which need to be doomed, instead of just evicted.  Collisions are linked
- *  using a PRCList to keep track of current generation number.
- *
- *  Used to detect hash number collisions, and find available generation
- *  numbers.
- *
- *  Not all nsDiskCacheBinding have a generation number.
- *
- *  Generation numbers may be aquired late, or lost (when data fits in block
- *  file)
- *
- *  Collisions can occur:
- *      BindEntry()       - hashnumbers collide (possibly different keys)
- *
- *  Generation number required:
- *      DeactivateEntry() - metadata written to disk, may require file
- *      GetFileForEntry() - force data to require file
- *      writing to stream - data size may require file
- *
- *  Binding can be kept in PRCList in order of generation numbers.
- *  Binding with no generation number can be Appended to PRCList (last).
- *
- *****************************************************************************/
-
-class nsDiskCacheBindery {
- public:
-  nsDiskCacheBindery();
-  ~nsDiskCacheBindery();
-
-  void Init();
-  void Reset();
-
-  nsDiskCacheBinding* CreateBinding(nsCacheEntry* entry,
-                                    nsDiskCacheRecord* record);
-
-  nsDiskCacheBinding* FindActiveBinding(uint32_t hashNumber) const;
-  void RemoveBinding(nsDiskCacheBinding* binding);
-  bool ActiveBindings();
-
-  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
-
- private:
-  nsresult AddBinding(nsDiskCacheBinding* binding);
-
-  // member variables
-  static const PLDHashTableOps ops;
-  PLDHashTable table;
-  bool initialized;
-
-  static const uint32_t kInitialTableLength = 0;
-};
-
-#endif /* _nsDiskCacheBinding_h_ */
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheBlockFile.cpp
+++ /dev/null
@@ -1,407 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsCache.h"
-#include "nsDiskCache.h"
-#include "nsDiskCacheBlockFile.h"
-#include "mozilla/FileUtils.h"
-#include "mozilla/IntegerPrintfMacros.h"
-#include "mozilla/MemoryReporting.h"
-#include <algorithm>
-
-using namespace mozilla;
-
-/******************************************************************************
- * nsDiskCacheBlockFile -
- *****************************************************************************/
-
-/******************************************************************************
- *  Open
- *****************************************************************************/
-nsresult nsDiskCacheBlockFile::Open(
-    nsIFile *blockFile, uint32_t blockSize, uint32_t bitMapSize,
-    nsDiskCache::CorruptCacheInfo *corruptInfo) {
-  NS_ENSURE_ARG_POINTER(corruptInfo);
-  *corruptInfo = nsDiskCache::kUnexpectedError;
-
-  if (bitMapSize % 32) {
-    *corruptInfo = nsDiskCache::kInvalidArgPointer;
-    return NS_ERROR_INVALID_ARG;
-  }
-
-  mBlockSize = blockSize;
-  mBitMapWords = bitMapSize / 32;
-  uint32_t bitMapBytes = mBitMapWords * 4;
-
-  // open the file - restricted to user, the data could be confidential
-  nsresult rv =
-      blockFile->OpenNSPRFileDesc(PR_RDWR | PR_CREATE_FILE, 00600, &mFD);
-  if (NS_FAILED(rv)) {
-    *corruptInfo = nsDiskCache::kCouldNotCreateBlockFile;
-    CACHE_LOG_DEBUG(
-        ("CACHE: nsDiskCacheBlockFile::Open "
-         "[this=%p] unable to open or create file: %" PRId32,
-         this, static_cast<uint32_t>(rv)));
-    return rv;  // unable to open or create file
-  }
-
-  // allocate bit map buffer
-  mBitMap = new uint32_t[mBitMapWords];
-
-  // check if we just creating the file
-  mFileSize = PR_Available(mFD);
-  if (mFileSize < 0) {
-    // XXX an error occurred. We could call PR_GetError(), but how would that
-    // help?
-    *corruptInfo = nsDiskCache::kBlockFileSizeError;
-    rv = NS_ERROR_UNEXPECTED;
-    goto error_exit;
-  }
-  if (mFileSize == 0) {
-    // initialize bit map and write it
-    memset(mBitMap, 0, bitMapBytes);
-    if (!Write(0, mBitMap, bitMapBytes)) {
-      *corruptInfo = nsDiskCache::kBlockFileBitMapWriteError;
-      goto error_exit;
-    }
-
-  } else if ((uint32_t)mFileSize < bitMapBytes) {
-    *corruptInfo = nsDiskCache::kBlockFileSizeLessThanBitMap;
-    rv = NS_ERROR_UNEXPECTED;  // XXX NS_ERROR_CACHE_INVALID;
-    goto error_exit;
-
-  } else {
-    // read the bit map
-    const int32_t bytesRead = PR_Read(mFD, mBitMap, bitMapBytes);
-    if ((bytesRead < 0) || ((uint32_t)bytesRead < bitMapBytes)) {
-      *corruptInfo = nsDiskCache::kBlockFileBitMapReadError;
-      rv = NS_ERROR_UNEXPECTED;
-      goto error_exit;
-    }
-#if defined(IS_LITTLE_ENDIAN)
-    // Swap from network format
-    for (unsigned int i = 0; i < mBitMapWords; ++i)
-      mBitMap[i] = ntohl(mBitMap[i]);
-#endif
-    // validate block file size
-    // Because not whole blocks are written, the size may be a
-    // little bit smaller than used blocks times blocksize,
-    // because the last block will generally not be 'whole'.
-    const uint32_t estimatedSize = CalcBlockFileSize();
-    if ((uint32_t)mFileSize + blockSize < estimatedSize) {
-      *corruptInfo = nsDiskCache::kBlockFileEstimatedSizeError;
-      rv = NS_ERROR_UNEXPECTED;
-      goto error_exit;
-    }
-  }
-  CACHE_LOG_DEBUG(
-      ("CACHE: nsDiskCacheBlockFile::Open [this=%p] succeeded", this));
-  return NS_OK;
-
-error_exit:
-  CACHE_LOG_DEBUG(
-      ("CACHE: nsDiskCacheBlockFile::Open [this=%p] failed with "
-       "error %" PRId32,
-       this, static_cast<uint32_t>(rv)));
-  Close(false);
-  return rv;
-}
-
-/******************************************************************************
- *  Close
- *****************************************************************************/
-nsresult nsDiskCacheBlockFile::Close(bool flush) {
-  nsresult rv = NS_OK;
-
-  if (mFD) {
-    if (flush) rv = FlushBitMap();
-    PRStatus err = PR_Close(mFD);
-    if (NS_SUCCEEDED(rv) && (err != PR_SUCCESS)) rv = NS_ERROR_UNEXPECTED;
-    mFD = nullptr;
-  }
-
-  if (mBitMap) {
-    delete[] mBitMap;
-    mBitMap = nullptr;
-  }
-
-  return rv;
-}
-
-/******************************************************************************
- *  AllocateBlocks
- *
- *  Allocates 1-4 blocks, using a first fit strategy,
- *  so that no group of blocks spans a quad block boundary.
- *
- *  Returns block number of first block allocated or -1 on failure.
- *
- *****************************************************************************/
-int32_t nsDiskCacheBlockFile::AllocateBlocks(int32_t numBlocks) {
-  const int maxPos = 32 - numBlocks;
-  const uint32_t mask = (0x01 << numBlocks) - 1;
-  for (unsigned int i = 0; i < mBitMapWords; ++i) {
-    uint32_t mapWord = ~mBitMap[i];  // flip bits so free bits are 1
-    if (mapWord) {                   // At least one free bit
-      // Binary search for first free bit in word
-      int bit = 0;
-      if ((mapWord & 0x0FFFF) == 0) {
-        bit |= 16;
-        mapWord >>= 16;
-      }
-      if ((mapWord & 0x000FF) == 0) {
-        bit |= 8;
-        mapWord >>= 8;
-      }
-      if ((mapWord & 0x0000F) == 0) {
-        bit |= 4;
-        mapWord >>= 4;
-      }
-      if ((mapWord & 0x00003) == 0) {
-        bit |= 2;
-        mapWord >>= 2;
-      }
-      if ((mapWord & 0x00001) == 0) {
-        bit |= 1;
-        mapWord >>= 1;
-      }
-      // Find first fit for mask
-      for (; bit <= maxPos; ++bit) {
-        // all bits selected by mask are 1, so free
-        if ((mask & mapWord) == mask) {
-          mBitMap[i] |= mask << bit;
-          mBitMapDirty = true;
-          return (int32_t)i * 32 + bit;
-        }
-      }
-    }
-  }
-
-  return -1;
-}
-
-/******************************************************************************
- *  DeallocateBlocks
- *****************************************************************************/
-nsresult nsDiskCacheBlockFile::DeallocateBlocks(int32_t startBlock,
-                                                int32_t numBlocks) {
-  if (!mFD) return NS_ERROR_NOT_AVAILABLE;
-
-  if ((startBlock < 0) || ((uint32_t)startBlock > mBitMapWords * 32 - 1) ||
-      (numBlocks < 1) || (numBlocks > 4))
-    return NS_ERROR_ILLEGAL_VALUE;
-
-  const int32_t startWord = startBlock >> 5;  // Divide by 32
-  const uint32_t startBit = startBlock & 31;  // Modulo by 32
-
-  // make sure requested deallocation doesn't span a word boundary
-  if (startBit + numBlocks > 32) return NS_ERROR_UNEXPECTED;
-  uint32_t mask = ((0x01 << numBlocks) - 1) << startBit;
-
-  // make sure requested deallocation is currently allocated
-  if ((mBitMap[startWord] & mask) != mask) return NS_ERROR_ABORT;
-
-  mBitMap[startWord] ^= mask;  // flips the bits off;
-  mBitMapDirty = true;
-  // XXX rv = FlushBitMap();  // coherency vs. performance
-  return NS_OK;
-}
-
-/******************************************************************************
- *  WriteBlocks
- *****************************************************************************/
-nsresult nsDiskCacheBlockFile::WriteBlocks(void *buffer, uint32_t size,
-                                           int32_t numBlocks,
-                                           int32_t *startBlock) {
-  // presume buffer != nullptr and startBlock != nullptr
-  NS_ENSURE_TRUE(mFD, NS_ERROR_NOT_AVAILABLE);
-
-  // allocate some blocks in the cache block file
-  *startBlock = AllocateBlocks(numBlocks);
-  if (*startBlock < 0) return NS_ERROR_NOT_AVAILABLE;
-
-  // seek to block position
-  int32_t blockPos = mBitMapWords * 4 + *startBlock * mBlockSize;
-
-  // write the blocks
-  return Write(blockPos, buffer, size) ? NS_OK : NS_ERROR_FAILURE;
-}
-
-/******************************************************************************
- *  ReadBlocks
- *****************************************************************************/
-nsresult nsDiskCacheBlockFile::ReadBlocks(void *buffer, int32_t startBlock,
-                                          int32_t numBlocks,
-                                          int32_t *bytesRead) {
-  // presume buffer != nullptr and bytesRead != bytesRead
-
-  if (!mFD) return NS_ERROR_NOT_AVAILABLE;
-  nsresult rv = VerifyAllocation(startBlock, numBlocks);
-  if (NS_FAILED(rv)) return rv;
-
-  // seek to block position
-  int32_t blockPos = mBitMapWords * 4 + startBlock * mBlockSize;
-  int32_t filePos = PR_Seek(mFD, blockPos, PR_SEEK_SET);
-  if (filePos != blockPos) return NS_ERROR_UNEXPECTED;
-
-  // read the blocks
-  int32_t bytesToRead = *bytesRead;
-  if ((bytesToRead <= 0) || ((uint32_t)bytesToRead > mBlockSize * numBlocks)) {
-    bytesToRead = mBlockSize * numBlocks;
-  }
-  *bytesRead = PR_Read(mFD, buffer, bytesToRead);
-
-  CACHE_LOG_DEBUG(
-      ("CACHE: nsDiskCacheBlockFile::Read [this=%p] "
-       "returned %d / %d bytes",
-       this, *bytesRead, bytesToRead));
-
-  return NS_OK;
-}
-
-/******************************************************************************
- *  FlushBitMap
- *****************************************************************************/
-nsresult nsDiskCacheBlockFile::FlushBitMap() {
-  if (!mBitMapDirty) return NS_OK;
-
-#if defined(IS_LITTLE_ENDIAN)
-  uint32_t *bitmap = new uint32_t[mBitMapWords];
-  // Copy and swap to network format
-  uint32_t *p = bitmap;
-  for (unsigned int i = 0; i < mBitMapWords; ++i, ++p) *p = htonl(mBitMap[i]);
-#else
-  uint32_t *bitmap = mBitMap;
-#endif
-
-  // write bitmap
-  bool written = Write(0, bitmap, mBitMapWords * 4);
-#if defined(IS_LITTLE_ENDIAN)
-  delete[] bitmap;
-#endif
-  if (!written) return NS_ERROR_UNEXPECTED;
-
-  PRStatus err = PR_Sync(mFD);
-  if (err != PR_SUCCESS) return NS_ERROR_UNEXPECTED;
-
-  mBitMapDirty = false;
-  return NS_OK;
-}
-
-/******************************************************************************
- *  VerifyAllocation
- *
- *  Return values:
- *      NS_OK if all bits are marked allocated
- *      NS_ERROR_ILLEGAL_VALUE if parameters don't obey constraints
- *      NS_ERROR_FAILURE if some or all the bits are marked unallocated
- *
- *****************************************************************************/
-nsresult nsDiskCacheBlockFile::VerifyAllocation(int32_t startBlock,
-                                                int32_t numBlocks) {
-  if ((startBlock < 0) || ((uint32_t)startBlock > mBitMapWords * 32 - 1) ||
-      (numBlocks < 1) || (numBlocks > 4))
-    return NS_ERROR_ILLEGAL_VALUE;
-
-  const int32_t startWord = startBlock >> 5;  // Divide by 32
-  const uint32_t startBit = startBlock & 31;  // Modulo by 32
-
-  // make sure requested deallocation doesn't span a word boundary
-  if (startBit + numBlocks > 32) return NS_ERROR_ILLEGAL_VALUE;
-  uint32_t mask = ((0x01 << numBlocks) - 1) << startBit;
-
-  // check if all specified blocks are currently allocated
-  if ((mBitMap[startWord] & mask) != mask) return NS_ERROR_FAILURE;
-
-  return NS_OK;
-}
-
-/******************************************************************************
- *  CalcBlockFileSize
- *
- *  Return size of the block file according to the bits set in mBitmap
- *
- *****************************************************************************/
-uint32_t nsDiskCacheBlockFile::CalcBlockFileSize() {
-  // search for last byte in mBitMap with allocated bits
-  uint32_t estimatedSize = mBitMapWords * 4;
-  int32_t i = mBitMapWords;
-  while (--i >= 0) {
-    if (mBitMap[i]) break;
-  }
-
-  if (i >= 0) {
-    // binary search to find last allocated bit in byte
-    uint32_t mapWord = mBitMap[i];
-    uint32_t lastBit = 31;
-    if ((mapWord & 0xFFFF0000) == 0) {
-      lastBit ^= 16;
-      mapWord <<= 16;
-    }
-    if ((mapWord & 0xFF000000) == 0) {
-      lastBit ^= 8;
-      mapWord <<= 8;
-    }
-    if ((mapWord & 0xF0000000) == 0) {
-      lastBit ^= 4;
-      mapWord <<= 4;
-    }
-    if ((mapWord & 0xC0000000) == 0) {
-      lastBit ^= 2;
-      mapWord <<= 2;
-    }
-    if ((mapWord & 0x80000000) == 0) {
-      lastBit ^= 1;
-      mapWord <<= 1;
-    }
-    estimatedSize += (i * 32 + lastBit + 1) * mBlockSize;
-  }
-
-  return estimatedSize;
-}
-
-/******************************************************************************
- *  Write
- *
- *  Wrapper around PR_Write that grows file in larger chunks to combat
- *  fragmentation
- *
- *****************************************************************************/
-bool nsDiskCacheBlockFile::Write(int32_t offset, const void *buf,
-                                 int32_t amount) {
-  /* Grow the file to 4mb right away, then double it until the file grows to
-     20mb. 20mb is a magic threshold because OSX stops autodefragging files
-     bigger than that. Beyond 20mb grow in 4mb chunks.
-   */
-  const int32_t upTo = offset + amount;
-  // Use a conservative definition of 20MB
-  const int32_t minPreallocate = 4 * 1024 * 1024;
-  const int32_t maxPreallocate = 20 * 1000 * 1000;
-  if (mFileSize < upTo) {
-    // maximal file size
-    const int32_t maxFileSize = mBitMapWords * 4 * (mBlockSize * 8 + 1);
-    if (upTo > maxPreallocate) {
-      // grow the file as a multiple of minPreallocate
-      mFileSize =
-          ((upTo + minPreallocate - 1) / minPreallocate) * minPreallocate;
-    } else {
-      // Grow quickly between 1MB to 20MB
-      if (mFileSize)
-        while (mFileSize < upTo) mFileSize *= 2;
-      mFileSize = clamped(mFileSize, minPreallocate, maxPreallocate);
-    }
-    mFileSize = std::min(mFileSize, maxFileSize);
-#if !defined(XP_MACOSX)
-    mozilla::fallocate(mFD, mFileSize);
-#endif
-  }
-  if (PR_Seek(mFD, offset, PR_SEEK_SET) != offset) return false;
-  return PR_Write(mFD, buf, amount) == amount;
-}
-
-size_t nsDiskCacheBlockFile::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) {
-  return aMallocSizeOf(mBitMap) + aMallocSizeOf(mFD);
-}
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheBlockFile.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et tw=80 : */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _nsDiskCacheBlockFile_h_
-#define _nsDiskCacheBlockFile_h_
-
-#include "mozilla/MemoryReporting.h"
-#include "nsIFile.h"
-#include "nsDiskCache.h"
-
-/******************************************************************************
- *  nsDiskCacheBlockFile
- *
- *  The structure of a cache block file is a 4096 bytes bit map, followed by
- *  some number of blocks of mBlockSize.  The creator of a
- *  nsDiskCacheBlockFile object must provide the block size for a given file.
- *
- *****************************************************************************/
-class nsDiskCacheBlockFile {
- public:
-  nsDiskCacheBlockFile()
-      : mFD(nullptr),
-        mBitMap(nullptr),
-        mBlockSize(0),
-        mBitMapWords(0),
-        mFileSize(0),
-        mBitMapDirty(false) {}
-  ~nsDiskCacheBlockFile() { (void)Close(true); }
-
-  nsresult Open(nsIFile *blockFile, uint32_t blockSize, uint32_t bitMapSize,
-                nsDiskCache::CorruptCacheInfo *corruptInfo);
-  nsresult Close(bool flush);
-
-  /*
-   * Trim
-   * Truncates the block file to the end of the last allocated block.
-   */
-  nsresult Trim() { return nsDiskCache::Truncate(mFD, CalcBlockFileSize()); }
-  nsresult DeallocateBlocks(int32_t startBlock, int32_t numBlocks);
-  nsresult WriteBlocks(void *buffer, uint32_t size, int32_t numBlocks,
-                       int32_t *startBlock);
-  nsresult ReadBlocks(void *buffer, int32_t startBlock, int32_t numBlocks,
-                      int32_t *bytesRead);
-
-  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
-
- private:
-  nsresult FlushBitMap();
-  int32_t AllocateBlocks(int32_t numBlocks);
-  nsresult VerifyAllocation(int32_t startBlock, int32_t numBLocks);
-  uint32_t CalcBlockFileSize();
-  bool Write(int32_t offset, const void *buf, int32_t amount);
-
-  /**
-   *  Data members
-   */
-  PRFileDesc *mFD;
-  uint32_t *mBitMap;  // XXX future: array of bit map blocks
-  uint32_t mBlockSize;
-  uint32_t mBitMapWords;
-  int32_t mFileSize;
-  bool mBitMapDirty;
-};
-
-#endif  // _nsDiskCacheBlockFile_h_
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheDevice.cpp
+++ /dev/null
@@ -1,1069 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <limits.h>
-
-#include "mozilla/DebugOnly.h"
-
-#include "nsCache.h"
-#include "nsIMemoryReporter.h"
-
-// include files for ftruncate (or equivalent)
-#if defined(XP_UNIX)
-#  include <unistd.h>
-#elif defined(XP_WIN)
-#  include <windows.h>
-#else
-// XXX add necessary include file for ftruncate (or equivalent)
-#endif
-
-#include "prthread.h"
-
-#include "private/pprio.h"
-
-#include "nsDiskCacheDevice.h"
-#include "nsDiskCacheEntry.h"
-#include "nsDiskCacheMap.h"
-#include "nsDiskCacheStreams.h"
-
-#include "nsDiskCache.h"
-
-#include "nsCacheService.h"
-
-#include "nsDeleteDir.h"
-
-#include "nsICacheVisitor.h"
-#include "nsReadableUtils.h"
-#include "nsIInputStream.h"
-#include "nsIOutputStream.h"
-#include "nsCRT.h"
-#include "nsCOMArray.h"
-#include "nsISimpleEnumerator.h"
-
-#include "nsThreadUtils.h"
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/Telemetry.h"
-
-static const char DISK_CACHE_DEVICE_ID[] = {"disk"};
-using namespace mozilla;
-
-class nsDiskCacheDeviceDeactivateEntryEvent : public Runnable {
- public:
-  nsDiskCacheDeviceDeactivateEntryEvent(nsDiskCacheDevice* device,
-                                        nsCacheEntry* entry,
-                                        nsDiskCacheBinding* binding)
-      : mozilla::Runnable("nsDiskCacheDeviceDeactivateEntryEvent"),
-        mCanceled(false),
-        mEntry(entry),
-        mDevice(device),
-        mBinding(binding) {}
-
-  NS_IMETHOD Run() override {
-    nsCacheServiceAutoLock lock;
-    CACHE_LOG_DEBUG(("nsDiskCacheDeviceDeactivateEntryEvent[%p]\n", this));
-    if (!mCanceled) {
-      (void)mDevice->DeactivateEntry_Private(mEntry, mBinding);
-    }
-    return NS_OK;
-  }
-
-  void CancelEvent() { mCanceled = true; }
-
- private:
-  bool mCanceled;
-  nsCacheEntry* mEntry;
-  nsDiskCacheDevice* mDevice;
-  nsDiskCacheBinding* mBinding;
-};
-
-class nsEvictDiskCacheEntriesEvent : public Runnable {
- public:
-  explicit nsEvictDiskCacheEntriesEvent(nsDiskCacheDevice* device)
-      : mozilla::Runnable("nsEvictDiskCacheEntriesEvent"), mDevice(device) {}
-
-  NS_IMETHOD Run() override {
-    nsCacheServiceAutoLock lock;
-    mDevice->EvictDiskCacheEntries(mDevice->mCacheCapacity);
-    return NS_OK;
-  }
-
- private:
-  nsDiskCacheDevice* mDevice;
-};
-
-/******************************************************************************
- *  nsDiskCacheEvictor
- *
- *  Helper class for nsDiskCacheDevice.
- *
- *****************************************************************************/
-
-class nsDiskCacheEvictor : public nsDiskCacheRecordVisitor {
- public:
-  nsDiskCacheEvictor(nsDiskCacheMap* cacheMap, nsDiskCacheBindery* cacheBindery,
-                     uint32_t targetSize, const char* clientID)
-      : mCacheMap(cacheMap),
-        mBindery(cacheBindery),
-        mTargetSize(targetSize),
-        mClientID(clientID) {
-    mClientIDSize = clientID ? strlen(clientID) : 0;
-  }
-
-  virtual int32_t VisitRecord(nsDiskCacheRecord* mapRecord) override;
-
- private:
-  nsDiskCacheMap* mCacheMap;
-  nsDiskCacheBindery* mBindery;
-  uint32_t mTargetSize;
-  const char* mClientID;
-  uint32_t mClientIDSize;
-};
-
-int32_t nsDiskCacheEvictor::VisitRecord(nsDiskCacheRecord* mapRecord) {
-  if (mCacheMap->TotalSize() < mTargetSize) return kStopVisitingRecords;
-
-  if (mClientID) {
-    // we're just evicting records for a specific client
-    nsDiskCacheEntry* diskEntry = mCacheMap->ReadDiskCacheEntry(mapRecord);
-    if (!diskEntry) return kVisitNextRecord;  // XXX or delete record?
-
-    // Compare clientID's without malloc
-    if ((diskEntry->mKeySize <= mClientIDSize) ||
-        (diskEntry->Key()[mClientIDSize] != ':') ||
-        (memcmp(diskEntry->Key(), mClientID, mClientIDSize) != 0)) {
-      return kVisitNextRecord;  // clientID doesn't match, skip it
-    }
-  }
-
-  nsDiskCacheBinding* binding =
-      mBindery->FindActiveBinding(mapRecord->HashNumber());
-  if (binding) {
-    // If the entry is pending deactivation, cancel deactivation and doom
-    // the entry
-    if (binding->mDeactivateEvent) {
-      binding->mDeactivateEvent->CancelEvent();
-      binding->mDeactivateEvent = nullptr;
-    }
-    // We are currently using this entry, so all we can do is doom it.
-    // Since we're enumerating the records, we don't want to call
-    // DeleteRecord when nsCacheService::DoomEntry() calls us back.
-    binding->mDoomed = true;  // mark binding record as 'deleted'
-    nsCacheService::DoomEntry(binding->mCacheEntry);
-  } else {
-    // entry not in use, just delete storage because we're enumerating the
-    // records
-    (void)mCacheMap->DeleteStorage(mapRecord);
-  }
-
-  return kDeleteRecordAndContinue;  // this will REALLY delete the record
-}
-
-/******************************************************************************
- *  nsDiskCacheDeviceInfo
- *****************************************************************************/
-
-class nsDiskCacheDeviceInfo : public nsICacheDeviceInfo {
- public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSICACHEDEVICEINFO
-
-  explicit nsDiskCacheDeviceInfo(nsDiskCacheDevice* device) : mDevice(device) {}
-
- private:
-  virtual ~nsDiskCacheDeviceInfo() = default;
-
-  nsDiskCacheDevice* mDevice;
-};
-
-NS_IMPL_ISUPPORTS(nsDiskCacheDeviceInfo, nsICacheDeviceInfo)
-
-NS_IMETHODIMP nsDiskCacheDeviceInfo::GetDescription(nsACString& aDescription) {
-  aDescription.AssignLiteral("Disk cache device");
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheDeviceInfo::GetUsageReport(nsACString& aUsageReport) {
-  nsCString buffer;
-
-  buffer.AssignLiteral(
-      "  <tr>\n"
-      "    <th>Cache Directory:</th>\n"
-      "    <td>");
-  nsCOMPtr<nsIFile> cacheDir;
-  nsAutoString path;
-  mDevice->getCacheDirectory(getter_AddRefs(cacheDir));
-  nsresult rv = cacheDir->GetPath(path);
-  if (NS_SUCCEEDED(rv)) {
-    AppendUTF16toUTF8(path, buffer);
-  } else {
-    buffer.AppendLiteral("directory unavailable");
-  }
-  buffer.AppendLiteral(
-      "</td>\n"
-      "  </tr>\n");
-
-  aUsageReport.Assign(buffer);
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheDeviceInfo::GetEntryCount(uint32_t* aEntryCount) {
-  NS_ENSURE_ARG_POINTER(aEntryCount);
-  *aEntryCount = mDevice->getEntryCount();
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheDeviceInfo::GetTotalSize(uint32_t* aTotalSize) {
-  NS_ENSURE_ARG_POINTER(aTotalSize);
-  // Returned unit's are in bytes
-  *aTotalSize = mDevice->getCacheSize() * 1024;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheDeviceInfo::GetMaximumSize(uint32_t* aMaximumSize) {
-  NS_ENSURE_ARG_POINTER(aMaximumSize);
-  // Returned unit's are in bytes
-  *aMaximumSize = mDevice->getCacheCapacity() * 1024;
-  return NS_OK;
-}
-
-/******************************************************************************
- *  nsDiskCache
- *****************************************************************************/
-
-/**
- *  nsDiskCache::Hash(const char * key, PLDHashNumber initval)
- *
- *  See http://burtleburtle.net/bob/hash/evahash.html for more information
- *  about this hash function.
- *
- *  This algorithm of this method implies nsDiskCacheRecords will be stored
- *  in a certain order on disk.  If the algorithm changes, existing cache
- *  map files may become invalid, and therefore the kCurrentVersion needs
- *  to be revised.
- */
-
-static inline void hashmix(uint32_t& a, uint32_t& b, uint32_t& c) {
-  a -= b;
-  a -= c;
-  a ^= (c >> 13);
-  b -= c;
-  b -= a;
-  b ^= (a << 8);
-  c -= a;
-  c -= b;
-  c ^= (b >> 13);
-  a -= b;
-  a -= c;
-  a ^= (c >> 12);
-  b -= c;
-  b -= a;
-  b ^= (a << 16);
-  c -= a;
-  c -= b;
-  c ^= (b >> 5);
-  a -= b;
-  a -= c;
-  a ^= (c >> 3);
-  b -= c;
-  b -= a;
-  b ^= (a << 10);
-  c -= a;
-  c -= b;
-  c ^= (b >> 15);
-}
-
-PLDHashNumber nsDiskCache::Hash(const char* key, PLDHashNumber initval) {
-  const uint8_t* k = reinterpret_cast<const uint8_t*>(key);
-  uint32_t a, b, c, len, length;
-
-  length = strlen(key);
-  /* Set up the internal state */
-  len = length;
-  a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
-  c = initval;        /* variable initialization of internal state */
-
-  /*---------------------------------------- handle most of the key */
-  while (len >= 12) {
-    a += k[0] + (uint32_t(k[1]) << 8) + (uint32_t(k[2]) << 16) +
-         (uint32_t(k[3]) << 24);
-    b += k[4] + (uint32_t(k[5]) << 8) + (uint32_t(k[6]) << 16) +
-         (uint32_t(k[7]) << 24);
-    c += k[8] + (uint32_t(k[9]) << 8) + (uint32_t(k[10]) << 16) +
-         (uint32_t(k[11]) << 24);
-    hashmix(a, b, c);
-    k += 12;
-    len -= 12;
-  }
-
-  /*------------------------------------- handle the last 11 bytes */
-  c += length;
-  switch (len) { /* all the case statements fall through */
-    case 11:
-      c += (uint32_t(k[10]) << 24);
-      MOZ_FALLTHROUGH;
-    case 10:
-      c += (uint32_t(k[9]) << 16);
-      MOZ_FALLTHROUGH;
-    case 9:
-      c += (uint32_t(k[8]) << 8);
-      MOZ_FALLTHROUGH;
-    /* the low-order byte of c is reserved for the length */
-    case 8:
-      b += (uint32_t(k[7]) << 24);
-      MOZ_FALLTHROUGH;
-    case 7:
-      b += (uint32_t(k[6]) << 16);
-      MOZ_FALLTHROUGH;
-    case 6:
-      b += (uint32_t(k[5]) << 8);
-      MOZ_FALLTHROUGH;
-    case 5:
-      b += k[4];
-      MOZ_FALLTHROUGH;
-    case 4:
-      a += (uint32_t(k[3]) << 24);
-      MOZ_FALLTHROUGH;
-    case 3:
-      a += (uint32_t(k[2]) << 16);
-      MOZ_FALLTHROUGH;
-    case 2:
-      a += (uint32_t(k[1]) << 8);
-      MOZ_FALLTHROUGH;
-    case 1:
-      a += k[0];
-      /* case 0: nothing left to add */
-  }
-  hashmix(a, b, c);
-
-  return c;
-}
-
-nsresult nsDiskCache::Truncate(PRFileDesc* fd, uint32_t newEOF) {
-  // use modified SetEOF from nsFileStreams::SetEOF()
-
-#if defined(XP_UNIX)
-  if (ftruncate(PR_FileDesc2NativeHandle(fd), newEOF) != 0) {
-    NS_ERROR("ftruncate failed");
-    return NS_ERROR_FAILURE;
-  }
-
-#elif defined(XP_WIN)
-  int32_t cnt = PR_Seek(fd, newEOF, PR_SEEK_SET);
-  if (cnt == -1) return NS_ERROR_FAILURE;
-  if (!SetEndOfFile((HANDLE)PR_FileDesc2NativeHandle(fd))) {
-    NS_ERROR("SetEndOfFile failed");
-    return NS_ERROR_FAILURE;
-  }
-
-#else
-  // add implementations for other platforms here
-#endif
-  return NS_OK;
-}
-
-/******************************************************************************
- *  nsDiskCacheDevice
- *****************************************************************************/
-
-nsDiskCacheDevice::nsDiskCacheDevice()
-    : mCacheCapacity(0),
-      mMaxEntrySize(-1)  // -1 means "no limit"
-      ,
-      mInitialized(false),
-      mClearingDiskCache(false) {}
-
-nsDiskCacheDevice::~nsDiskCacheDevice() { Shutdown(); }
-
-/**
- *  methods of nsCacheDevice
- */
-nsresult nsDiskCacheDevice::Init() {
-  nsresult rv;
-
-  if (Initialized()) {
-    NS_ERROR("Disk cache already initialized!");
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  if (!mCacheDirectory) return NS_ERROR_FAILURE;
-
-  mBindery.Init();
-
-  // Open Disk Cache
-  rv = OpenDiskCache();
-  if (NS_FAILED(rv)) {
-    (void)mCacheMap.Close(false);
-    return rv;
-  }
-
-  mInitialized = true;
-  return NS_OK;
-}
-
-/**
- *  NOTE: called while holding the cache service lock
- */
-nsresult nsDiskCacheDevice::Shutdown() {
-  nsCacheService::AssertOwnsLock();
-
-  nsresult rv = Shutdown_Private(true);
-  if (NS_FAILED(rv)) return rv;
-
-  return NS_OK;
-}
-
-nsresult nsDiskCacheDevice::Shutdown_Private(bool flush) {
-  CACHE_LOG_DEBUG(("CACHE: disk Shutdown_Private [%u]\n", flush));
-
-  if (Initialized()) {
-    // check cache limits in case we need to evict.
-    EvictDiskCacheEntries(mCacheCapacity);
-
-    // At this point there may be a number of pending cache-requests on the
-    // cache-io thread. Wait for all these to run before we wipe out our
-    // datastructures (see bug #620660)
-    (void)nsCacheService::SyncWithCacheIOThread();
-
-    // write out persistent information about the cache.
-    (void)mCacheMap.Close(flush);
-
-    mBindery.Reset();
-
-    mInitialized = false;
-  }
-
-  return NS_OK;
-}
-
-const char* nsDiskCacheDevice::GetDeviceID() { return DISK_CACHE_DEVICE_ID; }
-
-/**
- *  FindEntry -
- *
- *      cases:  key not in disk cache, hash number free
- *              key not in disk cache, hash number used
- *              key in disk cache
- *
- *  NOTE: called while holding the cache service lock
- */
-nsCacheEntry* nsDiskCacheDevice::FindEntry(nsCString* key, bool* collision) {
-  Telemetry::AutoTimer<Telemetry::CACHE_DISK_SEARCH_2> timer;
-  if (!Initialized()) return nullptr;  // NS_ERROR_NOT_INITIALIZED
-  if (mClearingDiskCache) return nullptr;
-  nsDiskCacheRecord record;
-  nsDiskCacheBinding* binding = nullptr;
-  PLDHashNumber hashNumber = nsDiskCache::Hash(key->get());
-
-  *collision = false;
-
-  binding = mBindery.FindActiveBinding(hashNumber);
-  if (binding) {
-    if (!binding->mCacheEntry->Key()->Equals(*key)) {
-      *collision = true;
-      return nullptr;
-    }
-    if (binding->mDeactivateEvent) {
-      binding->mDeactivateEvent->CancelEvent();
-      binding->mDeactivateEvent = nullptr;
-      CACHE_LOG_DEBUG(
-          ("CACHE: reusing deactivated entry %p "
-           "req-key=%s  entry-key=%s\n",
-           binding->mCacheEntry, key->get(),
-           binding->mCacheEntry->Key()->get()));
-
-      return binding->mCacheEntry;  // just return this one, observing that
-                                    // FindActiveBinding() does not return
-                                    // bindings to doomed entries
-    }
-  }
-  binding = nullptr;
-
-  // lookup hash number in cache map
-  nsresult rv = mCacheMap.FindRecord(hashNumber, &record);
-  if (NS_FAILED(rv)) return nullptr;  // XXX log error?
-
-  nsDiskCacheEntry* diskEntry = mCacheMap.ReadDiskCacheEntry(&record);
-  if (!diskEntry) return nullptr;
-
-  // compare key to be sure
-  if (!key->Equals(diskEntry->Key())) {
-    *collision = true;
-    return nullptr;
-  }
-
-  nsCacheEntry* entry = diskEntry->CreateCacheEntry(this);
-  if (entry) {
-    binding = mBindery.CreateBinding(entry, &record);
-    if (!binding) {
-      delete entry;
-      entry = nullptr;
-    }
-  }
-
-  if (!entry) {
-    (void)mCacheMap.DeleteStorage(&record);
-    (void)mCacheMap.DeleteRecord(&record);
-  }
-
-  return entry;
-}
-
-/**
- *  NOTE: called while holding the cache service lock
- */
-nsresult nsDiskCacheDevice::DeactivateEntry(nsCacheEntry* entry) {
-  nsDiskCacheBinding* binding = GetCacheEntryBinding(entry);
-  if (!IsValidBinding(binding)) return NS_ERROR_UNEXPECTED;
-
-  CACHE_LOG_DEBUG(("CACHE: disk DeactivateEntry [%p %x]\n", entry,
-                   binding->mRecord.HashNumber()));
-
-  nsDiskCacheDeviceDeactivateEntryEvent* event =
-      new nsDiskCacheDeviceDeactivateEntryEvent(this, entry, binding);
-
-  // ensure we can cancel the event via the binding later if necessary
-  binding->mDeactivateEvent = event;
-
-  DebugOnly<nsresult> rv = nsCacheService::DispatchToCacheIOThread(event);
-  NS_ASSERTION(NS_SUCCEEDED(rv),
-               "DeactivateEntry: Failed dispatching "
-               "deactivation event");
-  return NS_OK;
-}
-
-/**
- *  NOTE: called while holding the cache service lock
- */
-nsresult nsDiskCacheDevice::DeactivateEntry_Private(
-    nsCacheEntry* entry, nsDiskCacheBinding* binding) {
-  nsresult rv = NS_OK;
-  if (entry->IsDoomed()) {
-    // delete data, entry, record from disk for entry
-    rv = mCacheMap.DeleteStorage(&binding->mRecord);
-
-  } else {
-    // save stuff to disk for entry
-    rv = mCacheMap.WriteDiskCacheEntry(binding);
-    if (NS_FAILED(rv)) {
-      // clean up as best we can
-      (void)mCacheMap.DeleteStorage(&binding->mRecord);
-      (void)mCacheMap.DeleteRecord(&binding->mRecord);
-      binding->mDoomed = true;  // record is no longer in cache map
-    }
-  }
-
-  mBindery.RemoveBinding(
-      binding);  // extract binding from collision detection stuff
-  delete entry;  // which will release binding
-  return rv;
-}
-
-/**
- * BindEntry()
- *      no hash number collision -> no problem
- *      collision
- *          record not active -> evict, no problem
- *          record is active
- *              record is already doomed -> record shouldn't have been in map,
- * no problem record is not doomed -> doom, and replace record in map
- *
- *              walk matching hashnumber list to find lowest generation number
- *              take generation number from other (data/meta) location,
- *                  or walk active list
- *
- *  NOTE: called while holding the cache service lock
- */
-nsresult nsDiskCacheDevice::BindEntry(nsCacheEntry* entry) {
-  if (!Initialized()) return NS_ERROR_NOT_INITIALIZED;
-  if (mClearingDiskCache) return NS_ERROR_NOT_AVAILABLE;
-  nsresult rv = NS_OK;
-  nsDiskCacheRecord record, oldRecord;
-  nsDiskCacheBinding* binding;
-  PLDHashNumber hashNumber = nsDiskCache::Hash(entry->Key()->get());
-
-  // Find out if there is already an active binding for this hash. If yes it
-  // should have another key since BindEntry() shouldn't be called twice for
-  // the same entry. Doom the old entry, the new one will get another
-  // generation number so files won't collide.
-  binding = mBindery.FindActiveBinding(hashNumber);
-  if (binding) {
-    NS_ASSERTION(!binding->mCacheEntry->Key()->Equals(*entry->Key()),
-                 "BindEntry called for already bound entry!");
-    // If the entry is pending deactivation, cancel deactivation
-    if (binding->mDeactivateEvent) {
-      binding->mDeactivateEvent->CancelEvent();
-      binding->mDeactivateEvent = nullptr;
-    }
-    nsCacheService::DoomEntry(binding->mCacheEntry);
-    binding = nullptr;
-  }
-
-  // Lookup hash number in cache map. There can be a colliding inactive entry.
-  // See bug #321361 comment 21 for the scenario. If there is such entry,
-  // delete it.
-  rv = mCacheMap.FindRecord(hashNumber, &record);
-  if (NS_SUCCEEDED(rv)) {
-    nsDiskCacheEntry* diskEntry = mCacheMap.ReadDiskCacheEntry(&record);
-    if (diskEntry) {
-      // compare key to be sure
-      if (!entry->Key()->Equals(diskEntry->Key())) {
-        mCacheMap.DeleteStorage(&record);
-        rv = mCacheMap.DeleteRecord(&record);
-        if (NS_FAILED(rv)) return rv;
-      }
-    }
-    record = nsDiskCacheRecord();
-  }
-
-  // create a new record for this entry
-  record.SetHashNumber(nsDiskCache::Hash(entry->Key()->get()));
-  record.SetEvictionRank(ULONG_MAX - SecondsFromPRTime(PR_Now()));
-
-  CACHE_LOG_DEBUG(
-      ("CACHE: disk BindEntry [%p %x]\n", entry, record.HashNumber()));
-
-  if (!entry->IsDoomed()) {
-    // if entry isn't doomed, add it to the cache map
-    rv =
-        mCacheMap.AddRecord(&record, &oldRecord);  // deletes old record, if any
-    if (NS_FAILED(rv)) return rv;
-
-    uint32_t oldHashNumber = oldRecord.HashNumber();
-    if (oldHashNumber) {
-      // gotta evict this one first
-      nsDiskCacheBinding* oldBinding =
-          mBindery.FindActiveBinding(oldHashNumber);
-      if (oldBinding) {
-        // XXX if debug : compare keys for hashNumber collision
-
-        if (!oldBinding->mCacheEntry->IsDoomed()) {
-          // If the old entry is pending deactivation, cancel deactivation
-          if (oldBinding->mDeactivateEvent) {
-            oldBinding->mDeactivateEvent->CancelEvent();
-            oldBinding->mDeactivateEvent = nullptr;
-          }
-          // we've got a live one!
-          nsCacheService::DoomEntry(oldBinding->mCacheEntry);
-          // storage will be delete when oldBinding->mCacheEntry is Deactivated
-        }
-      } else {
-        // delete storage
-        // XXX if debug : compare keys for hashNumber collision
-        rv = mCacheMap.DeleteStorage(&oldRecord);
-        if (NS_FAILED(rv)) return rv;  // XXX delete record we just added?
-      }
-    }
-  }
-
-  // Make sure this entry has its associated nsDiskCacheBinding attached.
-  binding = mBindery.CreateBinding(entry, &record);
-  NS_ASSERTION(binding, "nsDiskCacheDevice::BindEntry");
-  if (!binding) return NS_ERROR_OUT_OF_MEMORY;
-  NS_ASSERTION(binding->mRecord.ValidRecord(), "bad cache map record");
-
-  return NS_OK;
-}
-
-/**
- *  NOTE: called while holding the cache service lock
- */
-void nsDiskCacheDevice::DoomEntry(nsCacheEntry* entry) {
-  CACHE_LOG_DEBUG(("CACHE: disk DoomEntry [%p]\n", entry));
-
-  nsDiskCacheBinding* binding = GetCacheEntryBinding(entry);
-  NS_ASSERTION(binding, "DoomEntry: binding == nullptr");
-  if (!binding) return;
-
-  if (!binding->mDoomed) {
-    // so it can't be seen by FindEntry() ever again.
-#ifdef DEBUG
-    nsresult rv =
-#endif
-        mCacheMap.DeleteRecord(&binding->mRecord);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "DeleteRecord failed.");
-    binding->mDoomed = true;  // record in no longer in cache map
-  }
-}
-
-/**
- *  NOTE: called while holding the cache service lock
- */
-nsresult nsDiskCacheDevice::OpenInputStreamForEntry(nsCacheEntry* entry,
-                                                    nsCacheAccessMode mode,
-                                                    uint32_t offset,
-                                                    nsIInputStream** result) {
-  CACHE_LOG_DEBUG(("CACHE: disk OpenInputStreamForEntry [%p %x %u]\n", entry,
-                   mode, offset));
-
-  NS_ENSURE_ARG_POINTER(entry);
-  NS_ENSURE_ARG_POINTER(result);
-
-  nsresult rv;
-  nsDiskCacheBinding* binding = GetCacheEntryBinding(entry);
-  if (!IsValidBinding(binding)) return NS_ERROR_UNEXPECTED;
-
-  NS_ASSERTION(binding->mCacheEntry == entry,
-               "binding & entry don't point to each other");
-
-  rv = binding->EnsureStreamIO();
-  if (NS_FAILED(rv)) return rv;
-
-  return binding->mStreamIO->GetInputStream(offset, result);
-}
-
-/**
- *  NOTE: called while holding the cache service lock
- */
-nsresult nsDiskCacheDevice::OpenOutputStreamForEntry(nsCacheEntry* entry,
-                                                     nsCacheAccessMode mode,
-                                                     uint32_t offset,
-                                                     nsIOutputStream** result) {
-  CACHE_LOG_DEBUG(("CACHE: disk OpenOutputStreamForEntry [%p %x %u]\n", entry,
-                   mode, offset));
-
-  NS_ENSURE_ARG_POINTER(entry);
-  NS_ENSURE_ARG_POINTER(result);
-
-  nsresult rv;
-  nsDiskCacheBinding* binding = GetCacheEntryBinding(entry);
-  if (!IsValidBinding(binding)) return NS_ERROR_UNEXPECTED;
-
-  NS_ASSERTION(binding->mCacheEntry == entry,
-               "binding & entry don't point to each other");
-
-  rv = binding->EnsureStreamIO();
-  if (NS_FAILED(rv)) return rv;
-
-  return binding->mStreamIO->GetOutputStream(offset, result);
-}
-
-/**
- *  NOTE: called while holding the cache service lock
- */
-nsresult nsDiskCacheDevice::GetFileForEntry(nsCacheEntry* entry,
-                                            nsIFile** result) {
-  NS_ENSURE_ARG_POINTER(result);
-  *result = nullptr;
-
-  nsresult rv;
-
-  nsDiskCacheBinding* binding = GetCacheEntryBinding(entry);
-  if (!IsValidBinding(binding)) return NS_ERROR_UNEXPECTED;
-
-  // check/set binding->mRecord for separate file, sync w/mCacheMap
-  if (binding->mRecord.DataLocationInitialized()) {
-    if (binding->mRecord.DataFile() != 0)
-      return NS_ERROR_NOT_AVAILABLE;  // data not stored as separate file
-
-    NS_ASSERTION(binding->mRecord.DataFileGeneration() == binding->mGeneration,
-                 "error generations out of sync");
-  } else {
-    binding->mRecord.SetDataFileGeneration(binding->mGeneration);
-    binding->mRecord.SetDataFileSize(0);  // 1k minimum
-    if (!binding->mDoomed) {
-      // record stored in cache map, so update it
-      rv = mCacheMap.UpdateRecord(&binding->mRecord);
-      if (NS_FAILED(rv)) return rv;
-    }
-  }
-
-  nsCOMPtr<nsIFile> file;
-  rv = mCacheMap.GetFileForDiskCacheRecord(
-      &binding->mRecord, nsDiskCache::kData, false, getter_AddRefs(file));
-  if (NS_FAILED(rv)) return rv;
-
-  NS_IF_ADDREF(*result = file);
-  return NS_OK;
-}
-
-/**
- *  This routine will get called every time an open descriptor is written to.
- *
- *  NOTE: called while holding the cache service lock
- */
-nsresult nsDiskCacheDevice::OnDataSizeChange(nsCacheEntry* entry,
-                                             int32_t deltaSize) {
-  CACHE_LOG_DEBUG(("CACHE: disk OnDataSizeChange [%p %d]\n", entry, deltaSize));
-
-  // If passed a negative value, then there's nothing to do.
-  if (deltaSize < 0) return NS_OK;
-
-  nsDiskCacheBinding* binding = GetCacheEntryBinding(entry);
-  if (!IsValidBinding(binding)) return NS_ERROR_UNEXPECTED;
-
-  NS_ASSERTION(binding->mRecord.ValidRecord(), "bad record");
-
-  uint32_t newSize = entry->DataSize() + deltaSize;
-  uint32_t newSizeK = ((newSize + 0x3FF) >> 10);
-
-  // If the new size is larger than max. file size or larger than
-  // 1/8 the cache capacity (which is in KiB's), doom the entry and abort.
-  if (EntryIsTooBig(newSize)) {
-#ifdef DEBUG
-    nsresult rv =
-#endif
-        nsCacheService::DoomEntry(entry);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "DoomEntry() failed.");
-    return NS_ERROR_ABORT;
-  }
-
-  uint32_t sizeK = ((entry->DataSize() + 0x03FF) >> 10);  // round up to next 1k
-
-  // In total count we ignore anything over kMaxDataSizeK (bug #651100), so
-  // the target capacity should be calculated the same way.
-  if (sizeK > kMaxDataSizeK) sizeK = kMaxDataSizeK;
-  if (newSizeK > kMaxDataSizeK) newSizeK = kMaxDataSizeK;
-
-  // pre-evict entries to make space for new data
-  uint32_t targetCapacity = mCacheCapacity > (newSizeK - sizeK)
-                                ? mCacheCapacity - (newSizeK - sizeK)
-                                : 0;
-  EvictDiskCacheEntries(targetCapacity);
-
-  return NS_OK;
-}
-
-/******************************************************************************
- *  EntryInfoVisitor
- *****************************************************************************/
-class EntryInfoVisitor : public nsDiskCacheRecordVisitor {
- public:
-  EntryInfoVisitor(nsDiskCacheMap* cacheMap, nsICacheVisitor* visitor)
-      : mCacheMap(cacheMap), mVisitor(visitor) {}
-
-  virtual int32_t VisitRecord(nsDiskCacheRecord* mapRecord) override {
-    // XXX optimization: do we have this record in memory?
-
-    // read in the entry (metadata)
-    nsDiskCacheEntry* diskEntry = mCacheMap->ReadDiskCacheEntry(mapRecord);
-    if (!diskEntry) {
-      return kVisitNextRecord;
-    }
-
-    // create nsICacheEntryInfo
-    nsDiskCacheEntryInfo* entryInfo =
-        new nsDiskCacheEntryInfo(DISK_CACHE_DEVICE_ID, diskEntry);
-    if (!entryInfo) {
-      return kStopVisitingRecords;
-    }
-    nsCOMPtr<nsICacheEntryInfo> ref(entryInfo);
-
-    bool keepGoing;
-    (void)mVisitor->VisitEntry(DISK_CACHE_DEVICE_ID, entryInfo, &keepGoing);
-    return keepGoing ? kVisitNextRecord : kStopVisitingRecords;
-  }
-
- private:
-  nsDiskCacheMap* mCacheMap;
-  nsICacheVisitor* mVisitor;
-};
-
-nsresult nsDiskCacheDevice::Visit(nsICacheVisitor* visitor) {
-  if (!Initialized()) return NS_ERROR_NOT_INITIALIZED;
-  nsDiskCacheDeviceInfo* deviceInfo = new nsDiskCacheDeviceInfo(this);
-  nsCOMPtr<nsICacheDeviceInfo> ref(deviceInfo);
-
-  bool keepGoing;
-  nsresult rv =
-      visitor->VisitDevice(DISK_CACHE_DEVICE_ID, deviceInfo, &keepGoing);
-  if (NS_FAILED(rv)) return rv;
-
-  if (keepGoing) {
-    EntryInfoVisitor infoVisitor(&mCacheMap, visitor);
-    return mCacheMap.VisitRecords(&infoVisitor);
-  }
-
-  return NS_OK;
-}
-
-// Max allowed size for an entry is currently MIN(mMaxEntrySize, 1/8
-// CacheCapacity)
-bool nsDiskCacheDevice::EntryIsTooBig(int64_t entrySize) {
-  if (mMaxEntrySize == -1)  // no limit
-    return entrySize > (static_cast<int64_t>(mCacheCapacity) * 1024 / 8);
-
-  return entrySize > mMaxEntrySize ||
-         entrySize > (static_cast<int64_t>(mCacheCapacity) * 1024 / 8);
-}
-
-nsresult nsDiskCacheDevice::EvictEntries(const char* clientID) {
-  CACHE_LOG_DEBUG(("CACHE: disk EvictEntries [%s]\n", clientID));
-
-  if (!Initialized()) return NS_ERROR_NOT_INITIALIZED;
-  nsresult rv;
-
-  if (clientID == nullptr) {
-    // we're clearing the entire disk cache
-    rv = ClearDiskCache();
-    if (rv != NS_ERROR_CACHE_IN_USE) return rv;
-  }
-
-  nsDiskCacheEvictor evictor(&mCacheMap, &mBindery, 0, clientID);
-  rv = mCacheMap.VisitRecords(&evictor);
-
-  if (clientID == nullptr)  // we tried to clear the entire cache
-    rv = mCacheMap.Trim();  // so trim cache block files (if possible)
-  return rv;
-}
-
-/**
- *  private methods
- */
-
-nsresult nsDiskCacheDevice::OpenDiskCache() {
-  Telemetry::AutoTimer<Telemetry::NETWORK_DISK_CACHE_OPEN> timer;
-  // if we don't have a cache directory, create one and open it
-  bool exists;
-  nsresult rv = mCacheDirectory->Exists(&exists);
-  if (NS_FAILED(rv)) return rv;
-
-  if (exists) {
-    // Try opening cache map file.
-    nsDiskCache::CorruptCacheInfo corruptInfo;
-    rv = mCacheMap.Open(mCacheDirectory, &corruptInfo);
-
-    if (rv == NS_ERROR_ALREADY_INITIALIZED) {
-      NS_WARNING("nsDiskCacheDevice::OpenDiskCache: already open!");
-    } else if (NS_FAILED(rv)) {
-      // Consider cache corrupt: delete it
-      // delay delete by 1 minute to avoid IO thrash at startup
-      rv = nsDeleteDir::DeleteDir(mCacheDirectory, true, 60000);
-      if (NS_FAILED(rv)) return rv;
-      exists = false;
-    }
-  }
-
-  // if we don't have a cache directory, create one and open it
-  if (!exists) {
-    rv = mCacheDirectory->Create(nsIFile::DIRECTORY_TYPE, 0777);
-    CACHE_LOG_PATH(LogLevel::Info, "\ncreate cache directory: %s\n",
-                   mCacheDirectory);
-    CACHE_LOG_INFO(("mCacheDirectory->Create() = %" PRIx32 "\n",
-                    static_cast<uint32_t>(rv)));
-    if (NS_FAILED(rv)) return rv;
-
-    // reopen the cache map
-    nsDiskCache::CorruptCacheInfo corruptInfo;
-    rv = mCacheMap.Open(mCacheDirectory, &corruptInfo);
-    if (NS_FAILED(rv)) return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult nsDiskCacheDevice::ClearDiskCache() {
-  if (mBindery.ActiveBindings()) return NS_ERROR_CACHE_IN_USE;
-
-  mClearingDiskCache = true;
-
-  nsresult rv = Shutdown_Private(false);  // false: don't bother flushing
-  if (NS_FAILED(rv)) return rv;
-
-  mClearingDiskCache = false;
-
-  // If the disk cache directory is already gone, then it's not an error if
-  // we fail to delete it ;-)
-  rv = nsDeleteDir::DeleteDir(mCacheDirectory, true);
-  if (NS_FAILED(rv) && rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) return rv;
-
-  return Init();
-}
-
-nsresult nsDiskCacheDevice::EvictDiskCacheEntries(uint32_t targetCapacity) {
-  CACHE_LOG_DEBUG(("CACHE: disk EvictDiskCacheEntries [%u]\n", targetCapacity));
-
-  NS_ASSERTION(targetCapacity > 0, "oops");
-
-  if (mCacheMap.TotalSize() < targetCapacity) return NS_OK;
-
-  // targetCapacity is in KiB's
-  nsDiskCacheEvictor evictor(&mCacheMap, &mBindery, targetCapacity, nullptr);
-  return mCacheMap.EvictRecords(&evictor);
-}
-
-/**
- *  methods for prefs
- */
-
-void nsDiskCacheDevice::SetCacheParentDirectory(nsIFile* parentDir) {
-  nsresult rv;
-  bool exists;
-
-  if (Initialized()) {
-    NS_ASSERTION(false, "Cannot switch cache directory when initialized");
-    return;
-  }
-
-  if (!parentDir) {
-    mCacheDirectory = nullptr;
-    return;
-  }
-
-  // ensure parent directory exists
-  rv = parentDir->Exists(&exists);
-  if (NS_SUCCEEDED(rv) && !exists)
-    rv = parentDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
-  if (NS_FAILED(rv)) return;
-
-  // ensure cache directory exists
-  nsCOMPtr<nsIFile> directory;
-
-  rv = parentDir->Clone(getter_AddRefs(directory));
-  if (NS_FAILED(rv)) return;
-  rv = directory->AppendNative(NS_LITERAL_CSTRING("Cache"));
-  if (NS_FAILED(rv)) return;
-
-  mCacheDirectory = directory;
-}
-
-void nsDiskCacheDevice::getCacheDirectory(nsIFile** result) {
-  *result = mCacheDirectory;
-  NS_IF_ADDREF(*result);
-}
-
-/**
- *  NOTE: called while holding the cache service lock
- */
-void nsDiskCacheDevice::SetCapacity(uint32_t 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);
-    }
-  }
-  // Let cache map know of the new capacity
-  mCacheMap.NotifyCapacityChange(capacity);
-}
-
-uint32_t nsDiskCacheDevice::getCacheCapacity() { return mCacheCapacity; }
-
-uint32_t nsDiskCacheDevice::getCacheSize() { return mCacheMap.TotalSize(); }
-
-uint32_t nsDiskCacheDevice::getEntryCount() { return mCacheMap.EntryCount(); }
-
-void nsDiskCacheDevice::SetMaxEntrySize(int32_t maxSizeInKilobytes) {
-  // Internal units are bytes. Changing this only takes effect *after* the
-  // change and has no consequences for existing cache-entries
-  if (maxSizeInKilobytes >= 0)
-    mMaxEntrySize = maxSizeInKilobytes * 1024;
-  else
-    mMaxEntrySize = -1;
-}
-
-size_t nsDiskCacheDevice::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) {
-  size_t usage = aMallocSizeOf(this);
-
-  usage += mCacheMap.SizeOfExcludingThis(aMallocSizeOf);
-  usage += mBindery.SizeOfExcludingThis(aMallocSizeOf);
-
-  return usage;
-}
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheDevice.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _nsDiskCacheDevice_h_
-#define _nsDiskCacheDevice_h_
-
-#include "mozilla/MemoryReporting.h"
-#include "nsCacheDevice.h"
-#include "nsDiskCacheBinding.h"
-#include "nsDiskCacheBlockFile.h"
-#include "nsDiskCacheEntry.h"
-
-#include "nsIFile.h"
-#include "nsIObserver.h"
-#include "nsCOMArray.h"
-
-class nsDiskCacheMap;
-
-class nsDiskCacheDevice final : public nsCacheDevice {
- public:
-  nsDiskCacheDevice();
-  virtual ~nsDiskCacheDevice();
-
-  virtual nsresult Init() override;
-  virtual nsresult Shutdown() override;
-
-  virtual const char *GetDeviceID(void) override;
-  virtual nsCacheEntry *FindEntry(nsCString *key, bool *collision) override;
-  virtual nsresult DeactivateEntry(nsCacheEntry *entry) override;
-  virtual nsresult BindEntry(nsCacheEntry *entry) override;
-  virtual void DoomEntry(nsCacheEntry *entry) override;
-
-  virtual nsresult OpenInputStreamForEntry(nsCacheEntry *entry,
-                                           nsCacheAccessMode mode,
-                                           uint32_t offset,
-                                           nsIInputStream **result) override;
-
-  virtual nsresult OpenOutputStreamForEntry(nsCacheEntry *entry,
-                                            nsCacheAccessMode mode,
-                                            uint32_t offset,
-                                            nsIOutputStream **result) override;
-
-  virtual nsresult GetFileForEntry(nsCacheEntry *entry,
-                                   nsIFile **result) override;
-
-  virtual nsresult OnDataSizeChange(nsCacheEntry *entry,
-                                    int32_t deltaSize) override;
-
-  virtual nsresult Visit(nsICacheVisitor *visitor) override;
-
-  virtual nsresult EvictEntries(const char *clientID) override;
-
-  bool EntryIsTooBig(int64_t entrySize);
-
-  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
-
-  /**
-   * Preference accessors
-   */
-  void SetCacheParentDirectory(nsIFile *parentDir);
-  void SetCapacity(uint32_t capacity);
-  void SetMaxEntrySize(int32_t maxSizeInKilobytes);
-
-  /* private: */
-
-  void getCacheDirectory(nsIFile **result);
-  uint32_t getCacheCapacity();
-  uint32_t getCacheSize();
-  uint32_t getEntryCount();
-
-  nsDiskCacheMap *CacheMap() { return &mCacheMap; }
-
- private:
-  friend class nsDiskCacheDeviceDeactivateEntryEvent;
-  friend class nsEvictDiskCacheEntriesEvent;
-  friend class nsDiskCacheMap;
-  /**
-   *  Private methods
-   */
-
-  inline bool IsValidBinding(nsDiskCacheBinding *binding) {
-    NS_ASSERTION(binding, "  binding == nullptr");
-    NS_ASSERTION(binding->mDeactivateEvent == nullptr,
-                 "  entry in process of deactivation");
-    return (binding && !binding->mDeactivateEvent);
-  }
-
-  bool Initialized() { return mInitialized; }
-
-  nsresult Shutdown_Private(bool flush);
-  nsresult DeactivateEntry_Private(nsCacheEntry *entry,
-                                   nsDiskCacheBinding *binding);
-
-  nsresult OpenDiskCache();
-  nsresult ClearDiskCache();
-
-  nsresult EvictDiskCacheEntries(uint32_t targetCapacity);
-
-  /**
-   *  Member variables
-   */
-  nsCOMPtr<nsIFile> mCacheDirectory;
-  nsDiskCacheBindery mBindery;
-  uint32_t mCacheCapacity;  // Unit is KiB's
-  int32_t mMaxEntrySize;    // Unit is bytes internally
-  // XXX need soft/hard limits, currentTotal
-  nsDiskCacheMap mCacheMap;
-  bool mInitialized;
-  bool mClearingDiskCache;
-};
-
-#endif  // _nsDiskCacheDevice_h_
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -11,16 +11,17 @@
 #include "mozilla/Sprintf.h"
 #include "mozilla/ThreadLocal.h"
 
 #include "nsCache.h"
 #include "nsDiskCache.h"
 #include "nsDiskCacheDeviceSQL.h"
 #include "nsCacheService.h"
 #include "nsApplicationCache.h"
+#include "../cache2/CacheHashUtils.h"
 
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsIURI.h"
 #include "nsAutoPtr.h"
 #include "nsEscape.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
@@ -137,18 +138,18 @@ class EvictionObserver {
  *
  *  This algorithm of this method implies nsOfflineCacheRecords will be stored
  *  in a certain order on disk.  If the algorithm changes, existing cache
  *  map files may become invalid, and therefore the kCurrentVersion needs
  *  to be revised.
  */
 static uint64_t DCacheHash(const char *key) {
   // initval 0x7416f295 was chosen randomly
-  return (uint64_t(nsDiskCache::Hash(key, 0)) << 32) |
-         nsDiskCache::Hash(key, 0x7416f295);
+  return (uint64_t(CacheHash::Hash(key, strlen(key), 0)) << 32) |
+         CacheHash::Hash(key, strlen(key), 0x7416f295);
 }
 
 /******************************************************************************
  * nsOfflineCacheEvictionFunction
  */
 
 NS_IMPL_ISUPPORTS(nsOfflineCacheEvictionFunction, mozIStorageFunction)
 
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheEntry.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsCache.h"
-#include "nsDiskCache.h"
-#include "nsDiskCacheEntry.h"
-#include "nsDiskCacheBinding.h"
-#include "nsCRT.h"
-
-#include "nsISerializable.h"
-#include "nsSerializationHelper.h"
-
-/******************************************************************************
- *  nsDiskCacheEntry
- *****************************************************************************/
-
-/**
- *  CreateCacheEntry()
- *
- *  Creates an nsCacheEntry and sets all fields except for the binding.
- */
-nsCacheEntry *nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice *device) {
-  nsCacheEntry *entry = nullptr;
-  nsresult rv = nsCacheEntry::Create(Key(), nsICache::STREAM_BASED,
-                                     nsICache::STORE_ON_DISK, device, &entry);
-  if (NS_FAILED(rv) || !entry) return nullptr;
-
-  entry->SetFetchCount(mFetchCount);
-  entry->SetLastFetched(mLastFetched);
-  entry->SetLastModified(mLastModified);
-  entry->SetExpirationTime(mExpirationTime);
-  entry->SetCacheDevice(device);
-  // XXX why does nsCacheService have to fill out device in BindEntry()?
-  entry->SetDataSize(mDataSize);
-
-  rv = entry->UnflattenMetaData(MetaData(), mMetaDataSize);
-  if (NS_FAILED(rv)) {
-    delete entry;
-    return nullptr;
-  }
-
-  // Restore security info, if present
-  const char *info = entry->GetMetaDataElement("security-info");
-  if (info) {
-    nsCOMPtr<nsISupports> infoObj;
-    rv =
-        NS_DeserializeObject(nsDependentCString(info), getter_AddRefs(infoObj));
-    if (NS_FAILED(rv)) {
-      delete entry;
-      return nullptr;
-    }
-    entry->SetSecurityInfo(infoObj);
-  }
-
-  return entry;
-}
-
-/******************************************************************************
- *  nsDiskCacheEntryInfo
- *****************************************************************************/
-
-NS_IMPL_ISUPPORTS(nsDiskCacheEntryInfo, nsICacheEntryInfo)
-
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(nsACString &aClientID) {
-  return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->Key()), aClientID);
-}
-
-extern const char DISK_CACHE_DEVICE_ID[];
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(nsACString &aDeviceID) {
-  aDeviceID.Assign(mDeviceID);
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(nsACString &clientKey) {
-  return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->Key()),
-                               clientKey);
-}
-
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetFetchCount(int32_t *aFetchCount) {
-  NS_ENSURE_ARG_POINTER(aFetchCount);
-  *aFetchCount = mDiskEntry->mFetchCount;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastFetched(uint32_t *aLastFetched) {
-  NS_ENSURE_ARG_POINTER(aLastFetched);
-  *aLastFetched = mDiskEntry->mLastFetched;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastModified(uint32_t *aLastModified) {
-  NS_ENSURE_ARG_POINTER(aLastModified);
-  *aLastModified = mDiskEntry->mLastModified;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetExpirationTime(
-    uint32_t *aExpirationTime) {
-  NS_ENSURE_ARG_POINTER(aExpirationTime);
-  *aExpirationTime = mDiskEntry->mExpirationTime;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheEntryInfo::IsStreamBased(bool *aStreamBased) {
-  NS_ENSURE_ARG_POINTER(aStreamBased);
-  *aStreamBased = true;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetDataSize(uint32_t *aDataSize) {
-  NS_ENSURE_ARG_POINTER(aDataSize);
-  *aDataSize = mDiskEntry->mDataSize;
-  return NS_OK;
-}
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheEntry.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _nsDiskCacheEntry_h_
-#define _nsDiskCacheEntry_h_
-
-#include "nsDiskCacheMap.h"
-
-#include "nsCacheEntry.h"
-
-/******************************************************************************
- *  nsDiskCacheEntry
- *****************************************************************************/
-struct nsDiskCacheEntry {
-  uint32_t mHeaderVersion;  // useful for stand-alone metadata files
-  uint32_t mMetaLocation;   // for verification
-  int32_t mFetchCount;
-  uint32_t mLastFetched;
-  uint32_t mLastModified;
-  uint32_t mExpirationTime;
-  uint32_t mDataSize;
-  uint32_t mKeySize;       // includes terminating null byte
-  uint32_t mMetaDataSize;  // includes terminating null byte
-  // followed by key data (mKeySize bytes)
-  // followed by meta data (mMetaDataSize bytes)
-
-  uint32_t Size() {
-    return sizeof(nsDiskCacheEntry) + mKeySize + mMetaDataSize;
-  }
-
-  char* Key() {
-    return reinterpret_cast<char*>(this) + sizeof(nsDiskCacheEntry);
-  }
-
-  char* MetaData() { return Key() + mKeySize; }
-
-  nsCacheEntry* CreateCacheEntry(nsCacheDevice* device);
-
-  void Swap()  // host to network (memory to disk)
-  {
-#if defined(IS_LITTLE_ENDIAN)
-    mHeaderVersion = htonl(mHeaderVersion);
-    mMetaLocation = htonl(mMetaLocation);
-    mFetchCount = htonl(mFetchCount);
-    mLastFetched = htonl(mLastFetched);
-    mLastModified = htonl(mLastModified);
-    mExpirationTime = htonl(mExpirationTime);
-    mDataSize = htonl(mDataSize);
-    mKeySize = htonl(mKeySize);
-    mMetaDataSize = htonl(mMetaDataSize);
-#endif
-  }
-
-  void Unswap()  // network to host (disk to memory)
-  {
-#if defined(IS_LITTLE_ENDIAN)
-    mHeaderVersion = ntohl(mHeaderVersion);
-    mMetaLocation = ntohl(mMetaLocation);
-    mFetchCount = ntohl(mFetchCount);
-    mLastFetched = ntohl(mLastFetched);
-    mLastModified = ntohl(mLastModified);
-    mExpirationTime = ntohl(mExpirationTime);
-    mDataSize = ntohl(mDataSize);
-    mKeySize = ntohl(mKeySize);
-    mMetaDataSize = ntohl(mMetaDataSize);
-#endif
-  }
-};
-
-/******************************************************************************
- *  nsDiskCacheEntryInfo
- *****************************************************************************/
-class nsDiskCacheEntryInfo : public nsICacheEntryInfo {
- public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSICACHEENTRYINFO
-
-  nsDiskCacheEntryInfo(const char* deviceID, nsDiskCacheEntry* diskEntry)
-      : mDeviceID(deviceID), mDiskEntry(diskEntry) {}
-
-  const char* Key() { return mDiskEntry->Key(); }
-
- private:
-  virtual ~nsDiskCacheEntryInfo() = default;
-
-  const char* mDeviceID;
-  nsDiskCacheEntry* mDiskEntry;
-};
-
-#endif /* _nsDiskCacheEntry_h_ */
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheMap.cpp
+++ /dev/null
@@ -1,1314 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=4 sw=2 sts=2 cin et: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsCache.h"
-#include "nsDiskCacheMap.h"
-#include "nsDiskCacheBinding.h"
-#include "nsDiskCacheEntry.h"
-#include "nsDiskCacheDevice.h"
-#include "nsCacheService.h"
-
-#include <string.h>
-#include "nsPrintfCString.h"
-
-#include "nsISerializable.h"
-#include "nsSerializationHelper.h"
-
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/Sprintf.h"
-#include "mozilla/Telemetry.h"
-#include <algorithm>
-
-using namespace mozilla;
-
-/******************************************************************************
- *  nsDiskCacheMap
- *****************************************************************************/
-
-/**
- *  File operations
- */
-
-nsresult nsDiskCacheMap::Open(nsIFile *cacheDirectory,
-                              nsDiskCache::CorruptCacheInfo *corruptInfo) {
-  NS_ENSURE_ARG_POINTER(corruptInfo);
-
-  // Assume we have an unexpected error until we find otherwise.
-  *corruptInfo = nsDiskCache::kUnexpectedError;
-  NS_ENSURE_ARG_POINTER(cacheDirectory);
-  if (mMapFD) return NS_ERROR_ALREADY_INITIALIZED;
-
-  mCacheDirectory = cacheDirectory;  // save a reference for ourselves
-
-  // create nsIFile for _CACHE_MAP_
-  nsresult rv;
-  nsCOMPtr<nsIFile> file;
-  rv = cacheDirectory->Clone(getter_AddRefs(file));
-  rv = file->AppendNative(NS_LITERAL_CSTRING("_CACHE_MAP_"));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // open the file - restricted to user, the data could be confidential
-  rv = file->OpenNSPRFileDesc(PR_RDWR | PR_CREATE_FILE, 00600, &mMapFD);
-  if (NS_FAILED(rv)) {
-    *corruptInfo = nsDiskCache::kOpenCacheMapError;
-    NS_WARNING("Could not open cache map file");
-    return NS_ERROR_FILE_CORRUPTED;
-  }
-
-  bool cacheFilesExist = CacheFilesExist();
-  rv = NS_ERROR_FILE_CORRUPTED;  // presume the worst
-  uint32_t mapSize = PR_Available(mMapFD);
-
-  if (NS_FAILED(InitCacheClean(cacheDirectory, corruptInfo))) {
-    // corruptInfo is set in the call to InitCacheClean
-    goto error_exit;
-  }
-
-  // check size of map file
-  if (mapSize == 0) {  // creating a new _CACHE_MAP_
-
-    // block files shouldn't exist if we're creating the _CACHE_MAP_
-    if (cacheFilesExist) {
-      *corruptInfo = nsDiskCache::kBlockFilesShouldNotExist;
-      goto error_exit;
-    }
-
-    if (NS_FAILED(CreateCacheSubDirectories())) {
-      *corruptInfo = nsDiskCache::kCreateCacheSubdirectories;
-      goto error_exit;
-    }
-
-    // create the file - initialize in memory
-    memset(&mHeader, 0, sizeof(nsDiskCacheHeader));
-    mHeader.mVersion = nsDiskCache::kCurrentVersion;
-    mHeader.mRecordCount = kMinRecordCount;
-    mRecordArray = (nsDiskCacheRecord *)calloc(mHeader.mRecordCount,
-                                               sizeof(nsDiskCacheRecord));
-    if (!mRecordArray) {
-      *corruptInfo = nsDiskCache::kOutOfMemory;
-      rv = NS_ERROR_OUT_OF_MEMORY;
-      goto error_exit;
-    }
-  } else if (mapSize >=
-             sizeof(nsDiskCacheHeader)) {  // read existing _CACHE_MAP_
-
-    // if _CACHE_MAP_ exists, so should the block files
-    if (!cacheFilesExist) {
-      *corruptInfo = nsDiskCache::kBlockFilesShouldExist;
-      goto error_exit;
-    }
-
-    CACHE_LOG_DEBUG(
-        ("CACHE: nsDiskCacheMap::Open [this=%p] reading map", this));
-
-    // read the header
-    uint32_t bytesRead = PR_Read(mMapFD, &mHeader, sizeof(nsDiskCacheHeader));
-    if (sizeof(nsDiskCacheHeader) != bytesRead) {
-      *corruptInfo = nsDiskCache::kHeaderSizeNotRead;
-      goto error_exit;
-    }
-    mHeader.Unswap();
-
-    if (mHeader.mIsDirty) {
-      *corruptInfo = nsDiskCache::kHeaderIsDirty;
-      goto error_exit;
-    }
-
-    if (mHeader.mVersion != nsDiskCache::kCurrentVersion) {
-      *corruptInfo = nsDiskCache::kVersionMismatch;
-      goto error_exit;
-    }
-
-    uint32_t recordArraySize = mHeader.mRecordCount * sizeof(nsDiskCacheRecord);
-    if (mapSize < recordArraySize + sizeof(nsDiskCacheHeader)) {
-      *corruptInfo = nsDiskCache::kRecordsIncomplete;
-      goto error_exit;
-    }
-
-    // Get the space for the records
-    mRecordArray = (nsDiskCacheRecord *)malloc(recordArraySize);
-    if (!mRecordArray) {
-      *corruptInfo = nsDiskCache::kOutOfMemory;
-      rv = NS_ERROR_OUT_OF_MEMORY;
-      goto error_exit;
-    }
-
-    // Read the records
-    bytesRead = PR_Read(mMapFD, mRecordArray, recordArraySize);
-    if (bytesRead < recordArraySize) {
-      *corruptInfo = nsDiskCache::kNotEnoughToRead;
-      goto error_exit;
-    }
-
-    // Unswap each record
-    int32_t total = 0;
-    for (int32_t i = 0; i < mHeader.mRecordCount; ++i) {
-      if (mRecordArray[i].HashNumber()) {
-#if defined(IS_LITTLE_ENDIAN)
-        mRecordArray[i].Unswap();
-#endif
-        total++;
-      }
-    }
-
-    // verify entry count
-    if (total != mHeader.mEntryCount) {
-      *corruptInfo = nsDiskCache::kEntryCountIncorrect;
-      goto error_exit;
-    }
-
-  } else {
-    *corruptInfo = nsDiskCache::kHeaderIncomplete;
-    goto error_exit;
-  }
-
-  rv = OpenBlockFiles(corruptInfo);
-  if (NS_FAILED(rv)) {
-    // corruptInfo is set in the call to OpenBlockFiles
-    goto error_exit;
-  }
-
-  // set dirty bit and flush header
-  mHeader.mIsDirty = true;
-  rv = FlushHeader();
-  if (NS_FAILED(rv)) {
-    *corruptInfo = nsDiskCache::kFlushHeaderError;
-    goto error_exit;
-  }
-
-  Telemetry::Accumulate(Telemetry::HTTP_DISK_CACHE_OVERHEAD,
-                        (uint32_t)SizeOfExcludingThis(moz_malloc_size_of));
-
-  *corruptInfo = nsDiskCache::kNotCorrupt;
-  return NS_OK;
-
-error_exit:
-  (void)Close(false);
-
-  return rv;
-}
-
-nsresult nsDiskCacheMap::Close(bool flush) {
-  nsCacheService::AssertOwnsLock();
-  nsresult rv = NS_OK;
-
-  // Cancel any pending cache validation event, the FlushRecords call below
-  // will validate the cache.
-  if (mCleanCacheTimer) {
-    mCleanCacheTimer->Cancel();
-  }
-
-  // If cache map file and its block files are still open, close them
-  if (mMapFD) {
-    // close block files
-    rv = CloseBlockFiles(flush);
-    if (NS_SUCCEEDED(rv) && flush && mRecordArray) {
-      // write the map records
-      rv = FlushRecords(false);  // don't bother swapping buckets back
-      if (NS_SUCCEEDED(rv)) {
-        // clear dirty bit
-        mHeader.mIsDirty = false;
-        rv = FlushHeader();
-      }
-    }
-    if ((PR_Close(mMapFD) != PR_SUCCESS) && (NS_SUCCEEDED(rv)))
-      rv = NS_ERROR_UNEXPECTED;
-
-    mMapFD = nullptr;
-  }
-
-  if (mCleanFD) {
-    PR_Close(mCleanFD);
-    mCleanFD = nullptr;
-  }
-
-  free(mRecordArray);
-  mRecordArray = nullptr;
-  free(mBuffer);
-  mBuffer = nullptr;
-  mBufferSize = 0;
-  return rv;
-}
-
-nsresult nsDiskCacheMap::Trim() {
-  nsresult rv, rv2 = NS_OK;
-  for (auto &block : mBlockFile) {
-    rv = block.Trim();
-    if (NS_FAILED(rv)) rv2 = rv;  // if one or more errors, report at least one
-  }
-  // Try to shrink the records array
-  rv = ShrinkRecords();
-  if (NS_FAILED(rv)) rv2 = rv;  // if one or more errors, report at least one
-  return rv2;
-}
-
-nsresult nsDiskCacheMap::FlushHeader() {
-  if (!mMapFD) return NS_ERROR_NOT_AVAILABLE;
-
-  // seek to beginning of cache map
-  int32_t filePos = PR_Seek(mMapFD, 0, PR_SEEK_SET);
-  if (filePos != 0) return NS_ERROR_UNEXPECTED;
-
-  // write the header
-  mHeader.Swap();
-  int32_t bytesWritten = PR_Write(mMapFD, &mHeader, sizeof(nsDiskCacheHeader));
-  mHeader.Unswap();
-  if (sizeof(nsDiskCacheHeader) != bytesWritten) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  PRStatus err = PR_Sync(mMapFD);
-  if (err != PR_SUCCESS) return NS_ERROR_UNEXPECTED;
-
-  // If we have a clean header then revalidate the cache clean file
-  if (!mHeader.mIsDirty) {
-    RevalidateCache();
-  }
-
-  return NS_OK;
-}
-
-nsresult nsDiskCacheMap::FlushRecords(bool unswap) {
-  if (!mMapFD) return NS_ERROR_NOT_AVAILABLE;
-
-  // seek to beginning of buckets
-  int32_t filePos = PR_Seek(mMapFD, sizeof(nsDiskCacheHeader), PR_SEEK_SET);
-  if (filePos != sizeof(nsDiskCacheHeader)) return NS_ERROR_UNEXPECTED;
-
-#if defined(IS_LITTLE_ENDIAN)
-  // Swap each record
-  for (int32_t i = 0; i < mHeader.mRecordCount; ++i) {
-    if (mRecordArray[i].HashNumber()) mRecordArray[i].Swap();
-  }
-#endif
-
-  int32_t recordArraySize = sizeof(nsDiskCacheRecord) * mHeader.mRecordCount;
-
-  int32_t bytesWritten = PR_Write(mMapFD, mRecordArray, recordArraySize);
-  if (bytesWritten != recordArraySize) return NS_ERROR_UNEXPECTED;
-
-#if defined(IS_LITTLE_ENDIAN)
-  if (unswap) {
-    // Unswap each record
-    for (int32_t i = 0; i < mHeader.mRecordCount; ++i) {
-      if (mRecordArray[i].HashNumber()) mRecordArray[i].Unswap();
-    }
-  }
-#endif
-
-  return NS_OK;
-}
-
-/**
- *  Record operations
- */
-
-uint32_t nsDiskCacheMap::GetBucketRank(uint32_t bucketIndex,
-                                       uint32_t targetRank) {
-  nsDiskCacheRecord *records = GetFirstRecordInBucket(bucketIndex);
-  uint32_t rank = 0;
-
-  for (int i = mHeader.mBucketUsage[bucketIndex] - 1; i >= 0; i--) {
-    if ((rank < records[i].EvictionRank()) &&
-        ((targetRank == 0) || (records[i].EvictionRank() < targetRank)))
-      rank = records[i].EvictionRank();
-  }
-  return rank;
-}
-
-nsresult nsDiskCacheMap::GrowRecords() {
-  if (mHeader.mRecordCount >= mMaxRecordCount) return NS_OK;
-  CACHE_LOG_DEBUG(("CACHE: GrowRecords\n"));
-
-  // Resize the record array
-  int32_t newCount = mHeader.mRecordCount << 1;
-  if (newCount > mMaxRecordCount) newCount = mMaxRecordCount;
-  nsDiskCacheRecord *newArray = (nsDiskCacheRecord *)realloc(
-      mRecordArray, newCount * sizeof(nsDiskCacheRecord));
-  if (!newArray) return NS_ERROR_OUT_OF_MEMORY;
-
-  // Space out the buckets
-  uint32_t oldRecordsPerBucket = GetRecordsPerBucket();
-  uint32_t newRecordsPerBucket = newCount / kBuckets;
-  // Work from back to space out each bucket to the new array
-  for (int bucketIndex = kBuckets - 1; bucketIndex >= 0; --bucketIndex) {
-    // Move bucket
-    nsDiskCacheRecord *newRecords =
-        newArray + bucketIndex * newRecordsPerBucket;
-    const uint32_t count = mHeader.mBucketUsage[bucketIndex];
-    memmove(newRecords, newArray + bucketIndex * oldRecordsPerBucket,
-            count * sizeof(nsDiskCacheRecord));
-    // clear unused records
-    memset(newRecords + count, 0,
-           (newRecordsPerBucket - count) * sizeof(nsDiskCacheRecord));
-  }
-
-  // Set as the new record array
-  mRecordArray = newArray;
-  mHeader.mRecordCount = newCount;
-
-  InvalidateCache();
-
-  return NS_OK;
-}
-
-nsresult nsDiskCacheMap::ShrinkRecords() {
-  if (mHeader.mRecordCount <= kMinRecordCount) return NS_OK;
-  CACHE_LOG_DEBUG(("CACHE: ShrinkRecords\n"));
-
-  // Verify if we can shrink the record array: all buckets must be less than
-  // 1/2 filled
-  uint32_t maxUsage = 0, bucketIndex;
-  for (bucketIndex = 0; bucketIndex < kBuckets; ++bucketIndex) {
-    if (maxUsage < mHeader.mBucketUsage[bucketIndex])
-      maxUsage = mHeader.mBucketUsage[bucketIndex];
-  }
-  // Determine new bucket size, halve size until maxUsage
-  uint32_t oldRecordsPerBucket = GetRecordsPerBucket();
-  uint32_t newRecordsPerBucket = oldRecordsPerBucket;
-  while (maxUsage < (newRecordsPerBucket >> 1)) newRecordsPerBucket >>= 1;
-  if (newRecordsPerBucket < (kMinRecordCount / kBuckets))
-    newRecordsPerBucket = (kMinRecordCount / kBuckets);
-  NS_ASSERTION(newRecordsPerBucket <= oldRecordsPerBucket,
-               "ShrinkRecords() can't grow records!");
-  if (newRecordsPerBucket == oldRecordsPerBucket) return NS_OK;
-  // Move the buckets close to each other
-  for (bucketIndex = 1; bucketIndex < kBuckets; ++bucketIndex) {
-    // Move bucket
-    memmove(mRecordArray + bucketIndex * newRecordsPerBucket,
-            mRecordArray + bucketIndex * oldRecordsPerBucket,
-            newRecordsPerBucket * sizeof(nsDiskCacheRecord));
-  }
-
-  // Shrink the record array memory block itself
-  uint32_t newCount = newRecordsPerBucket * kBuckets;
-  nsDiskCacheRecord *newArray = (nsDiskCacheRecord *)realloc(
-      mRecordArray, newCount * sizeof(nsDiskCacheRecord));
-  if (!newArray) return NS_ERROR_OUT_OF_MEMORY;
-
-  // Set as the new record array
-  mRecordArray = newArray;
-  mHeader.mRecordCount = newCount;
-
-  InvalidateCache();
-
-  return NS_OK;
-}
-
-nsresult nsDiskCacheMap::AddRecord(nsDiskCacheRecord *mapRecord,
-                                   nsDiskCacheRecord *oldRecord) {
-  CACHE_LOG_DEBUG(("CACHE: AddRecord [%x]\n", mapRecord->HashNumber()));
-
-  const uint32_t hashNumber = mapRecord->HashNumber();
-  const uint32_t bucketIndex = GetBucketIndex(hashNumber);
-  const uint32_t count = mHeader.mBucketUsage[bucketIndex];
-
-  oldRecord->SetHashNumber(0);  // signify no record
-
-  if (count == GetRecordsPerBucket()) {
-    // Ignore failure to grow the record space, we will then reuse old records
-    GrowRecords();
-  }
-
-  nsDiskCacheRecord *records = GetFirstRecordInBucket(bucketIndex);
-  if (count < GetRecordsPerBucket()) {
-    // stick the new record at the end
-    records[count] = *mapRecord;
-    mHeader.mEntryCount++;
-    mHeader.mBucketUsage[bucketIndex]++;
-    if (mHeader.mEvictionRank[bucketIndex] < mapRecord->EvictionRank())
-      mHeader.mEvictionRank[bucketIndex] = mapRecord->EvictionRank();
-    InvalidateCache();
-  } else {
-    // Find the record with the highest eviction rank
-    nsDiskCacheRecord *mostEvictable = &records[0];
-    for (int i = count - 1; i > 0; i--) {
-      if (records[i].EvictionRank() > mostEvictable->EvictionRank())
-        mostEvictable = &records[i];
-    }
-    *oldRecord = *mostEvictable;  // i == GetRecordsPerBucket(), so
-                                  // evict the mostEvictable
-    *mostEvictable = *mapRecord;  // replace it with the new record
-    // check if we need to update mostEvictable entry in header
-    if (mHeader.mEvictionRank[bucketIndex] < mapRecord->EvictionRank())
-      mHeader.mEvictionRank[bucketIndex] = mapRecord->EvictionRank();
-    if (oldRecord->EvictionRank() >= mHeader.mEvictionRank[bucketIndex])
-      mHeader.mEvictionRank[bucketIndex] = GetBucketRank(bucketIndex, 0);
-    InvalidateCache();
-  }
-
-  NS_ASSERTION(
-      mHeader.mEvictionRank[bucketIndex] == GetBucketRank(bucketIndex, 0),
-      "eviction rank out of sync");
-  return NS_OK;
-}
-
-nsresult nsDiskCacheMap::UpdateRecord(nsDiskCacheRecord *mapRecord) {
-  CACHE_LOG_DEBUG(("CACHE: UpdateRecord [%x]\n", mapRecord->HashNumber()));
-
-  const uint32_t hashNumber = mapRecord->HashNumber();
-  const uint32_t bucketIndex = GetBucketIndex(hashNumber);
-  nsDiskCacheRecord *records = GetFirstRecordInBucket(bucketIndex);
-
-  for (int i = mHeader.mBucketUsage[bucketIndex] - 1; i >= 0; i--) {
-    if (records[i].HashNumber() == hashNumber) {
-      const uint32_t oldRank = records[i].EvictionRank();
-
-      // stick the new record here
-      records[i] = *mapRecord;
-
-      // update eviction rank in header if necessary
-      if (mHeader.mEvictionRank[bucketIndex] < mapRecord->EvictionRank())
-        mHeader.mEvictionRank[bucketIndex] = mapRecord->EvictionRank();
-      else if (mHeader.mEvictionRank[bucketIndex] == oldRank)
-        mHeader.mEvictionRank[bucketIndex] = GetBucketRank(bucketIndex, 0);
-
-      InvalidateCache();
-
-      NS_ASSERTION(
-          mHeader.mEvictionRank[bucketIndex] == GetBucketRank(bucketIndex, 0),
-          "eviction rank out of sync");
-      return NS_OK;
-    }
-  }
-  MOZ_ASSERT_UNREACHABLE("record not found");
-  return NS_ERROR_UNEXPECTED;
-}
-
-nsresult nsDiskCacheMap::FindRecord(uint32_t hashNumber,
-                                    nsDiskCacheRecord *result) {
-  const uint32_t bucketIndex = GetBucketIndex(hashNumber);
-  nsDiskCacheRecord *records = GetFirstRecordInBucket(bucketIndex);
-
-  for (int i = mHeader.mBucketUsage[bucketIndex] - 1; i >= 0; i--) {
-    if (records[i].HashNumber() == hashNumber) {
-      *result = records[i];  // copy the record
-      NS_ASSERTION(result->ValidRecord(), "bad cache map record");
-      return NS_OK;
-    }
-  }
-  return NS_ERROR_CACHE_KEY_NOT_FOUND;
-}
-
-nsresult nsDiskCacheMap::DeleteRecord(nsDiskCacheRecord *mapRecord) {
-  CACHE_LOG_DEBUG(("CACHE: DeleteRecord [%x]\n", mapRecord->HashNumber()));
-
-  const uint32_t hashNumber = mapRecord->HashNumber();
-  const uint32_t bucketIndex = GetBucketIndex(hashNumber);
-  nsDiskCacheRecord *records = GetFirstRecordInBucket(bucketIndex);
-  uint32_t last = mHeader.mBucketUsage[bucketIndex] - 1;
-
-  for (int i = last; i >= 0; i--) {
-    if (records[i].HashNumber() == hashNumber) {
-      // found it, now delete it.
-      uint32_t evictionRank = records[i].EvictionRank();
-      NS_ASSERTION(evictionRank == mapRecord->EvictionRank(),
-                   "evictionRank out of sync");
-      // if not the last record, shift last record into opening
-      records[i] = records[last];
-      records[last].SetHashNumber(0);  // clear last record
-      mHeader.mBucketUsage[bucketIndex] = last;
-      mHeader.mEntryCount--;
-
-      // update eviction rank
-      uint32_t bucketIndex = GetBucketIndex(mapRecord->HashNumber());
-      if (mHeader.mEvictionRank[bucketIndex] <= evictionRank) {
-        mHeader.mEvictionRank[bucketIndex] = GetBucketRank(bucketIndex, 0);
-      }
-
-      InvalidateCache();
-
-      NS_ASSERTION(
-          mHeader.mEvictionRank[bucketIndex] == GetBucketRank(bucketIndex, 0),
-          "eviction rank out of sync");
-      return NS_OK;
-    }
-  }
-  return NS_ERROR_UNEXPECTED;
-}
-
-int32_t nsDiskCacheMap::VisitEachRecord(uint32_t bucketIndex,
-                                        nsDiskCacheRecordVisitor *visitor,
-                                        uint32_t evictionRank) {
-  int32_t rv = kVisitNextRecord;
-  uint32_t count = mHeader.mBucketUsage[bucketIndex];
-  nsDiskCacheRecord *records = GetFirstRecordInBucket(bucketIndex);
-
-  // call visitor for each entry (matching any eviction rank)
-  for (int i = count - 1; i >= 0; i--) {
-    if (evictionRank > records[i].EvictionRank()) continue;
-
-    rv = visitor->VisitRecord(&records[i]);
-    if (rv == kStopVisitingRecords) break;  // Stop visiting records
-
-    if (rv == kDeleteRecordAndContinue) {
-      --count;
-      records[i] = records[count];
-      records[count].SetHashNumber(0);
-      InvalidateCache();
-    }
-  }
-
-  if (mHeader.mBucketUsage[bucketIndex] - count != 0) {
-    mHeader.mEntryCount -= mHeader.mBucketUsage[bucketIndex] - count;
-    mHeader.mBucketUsage[bucketIndex] = count;
-    // recalc eviction rank
-    mHeader.mEvictionRank[bucketIndex] = GetBucketRank(bucketIndex, 0);
-  }
-  NS_ASSERTION(
-      mHeader.mEvictionRank[bucketIndex] == GetBucketRank(bucketIndex, 0),
-      "eviction rank out of sync");
-
-  return rv;
-}
-
-/**
- *  VisitRecords
- *
- *  Visit every record in cache map in the most convenient order
- */
-nsresult nsDiskCacheMap::VisitRecords(nsDiskCacheRecordVisitor *visitor) {
-  for (int bucketIndex = 0; bucketIndex < kBuckets; ++bucketIndex) {
-    if (VisitEachRecord(bucketIndex, visitor, 0) == kStopVisitingRecords) break;
-  }
-  return NS_OK;
-}
-
-/**
- *  EvictRecords
- *
- *  Just like VisitRecords, but visits the records in order of their eviction
- *  rank
- */
-nsresult nsDiskCacheMap::EvictRecords(nsDiskCacheRecordVisitor *visitor) {
-  uint32_t tempRank[kBuckets];
-  int bucketIndex = 0;
-
-  // copy eviction rank array
-  for (bucketIndex = 0; bucketIndex < kBuckets; ++bucketIndex)
-    tempRank[bucketIndex] = mHeader.mEvictionRank[bucketIndex];
-
-  // Maximum number of iterations determined by number of records
-  // as a safety limiter for the loop. Use a copy of mHeader.mEntryCount since
-  // the value could decrease if some entry is evicted.
-  int32_t entryCount = mHeader.mEntryCount;
-  for (int n = 0; n < entryCount; ++n) {
-    // find bucket with highest eviction rank
-    uint32_t rank = 0;
-    for (int i = 0; i < kBuckets; ++i) {
-      if (rank < tempRank[i]) {
-        rank = tempRank[i];
-        bucketIndex = i;
-      }
-    }
-
-    if (rank == 0) break;  // we've examined all the records
-
-    // visit records in bucket with eviction ranks >= target eviction rank
-    if (VisitEachRecord(bucketIndex, visitor, rank) == kStopVisitingRecords)
-      break;
-
-    // find greatest rank less than 'rank'
-    tempRank[bucketIndex] = GetBucketRank(bucketIndex, rank);
-  }
-  return NS_OK;
-}
-
-nsresult nsDiskCacheMap::OpenBlockFiles(
-    nsDiskCache::CorruptCacheInfo *corruptInfo) {
-  NS_ENSURE_ARG_POINTER(corruptInfo);
-
-  // create nsIFile for block file
-  nsCOMPtr<nsIFile> blockFile;
-  nsresult rv = NS_OK;
-  *corruptInfo = nsDiskCache::kUnexpectedError;
-
-  for (int i = 0; i < kNumBlockFiles; ++i) {
-    rv = GetBlockFileForIndex(i, getter_AddRefs(blockFile));
-    if (NS_FAILED(rv)) {
-      *corruptInfo = nsDiskCache::kCouldNotGetBlockFileForIndex;
-      break;
-    }
-
-    uint32_t blockSize =
-        GetBlockSizeForIndex(i + 1);  // +1 to match file selectors 1,2,3
-    uint32_t bitMapSize = GetBitMapSizeForIndex(i + 1);
-    rv = mBlockFile[i].Open(blockFile, blockSize, bitMapSize, corruptInfo);
-    if (NS_FAILED(rv)) {
-      // corruptInfo was set inside the call to mBlockFile[i].Open
-      break;
-    }
-  }
-  // close all files in case of any error
-  if (NS_FAILED(rv))
-    (void)CloseBlockFiles(false);  // we already have an error to report
-
-  return rv;
-}
-
-nsresult nsDiskCacheMap::CloseBlockFiles(bool flush) {
-  nsresult rv, rv2 = NS_OK;
-  for (auto &block : mBlockFile) {
-    rv = block.Close(flush);
-    if (NS_FAILED(rv)) rv2 = rv;  // if one or more errors, report at least one
-  }
-  return rv2;
-}
-
-bool nsDiskCacheMap::CacheFilesExist() {
-  nsCOMPtr<nsIFile> blockFile;
-  nsresult rv;
-
-  for (int i = 0; i < kNumBlockFiles; ++i) {
-    bool exists;
-    rv = GetBlockFileForIndex(i, getter_AddRefs(blockFile));
-    if (NS_FAILED(rv)) return false;
-
-    rv = blockFile->Exists(&exists);
-    if (NS_FAILED(rv) || !exists) return false;
-  }
-
-  return true;
-}
-
-nsresult nsDiskCacheMap::CreateCacheSubDirectories() {
-  if (!mCacheDirectory) return NS_ERROR_UNEXPECTED;
-
-  for (int32_t index = 0; index < 16; index++) {
-    nsCOMPtr<nsIFile> file;
-    nsresult rv = mCacheDirectory->Clone(getter_AddRefs(file));
-    if (NS_FAILED(rv)) return rv;
-
-    rv = file->AppendNative(nsPrintfCString("%X", index));
-    if (NS_FAILED(rv)) return rv;
-
-    rv = file->Create(nsIFile::DIRECTORY_TYPE, 0700);
-    if (NS_FAILED(rv)) return rv;
-  }
-
-  return NS_OK;
-}
-
-nsDiskCacheEntry *nsDiskCacheMap::ReadDiskCacheEntry(
-    nsDiskCacheRecord *record) {
-  CACHE_LOG_DEBUG(("CACHE: ReadDiskCacheEntry [%x]\n", record->HashNumber()));
-
-  nsresult rv = NS_ERROR_UNEXPECTED;
-  nsDiskCacheEntry *diskEntry = nullptr;
-  uint32_t metaFile = record->MetaFile();
-  int32_t bytesRead = 0;
-
-  if (!record->MetaLocationInitialized()) return nullptr;
-
-  if (metaFile == 0) {  // entry/metadata stored in separate file
-    // open and read the file
-    nsCOMPtr<nsIFile> file;
-    rv = GetLocalFileForDiskCacheRecord(record, nsDiskCache::kMetaData, false,
-                                        getter_AddRefs(file));
-    NS_ENSURE_SUCCESS(rv, nullptr);
-
-    CACHE_LOG_DEBUG(
-        ("CACHE: nsDiskCacheMap::ReadDiskCacheEntry"
-         "[this=%p] reading disk cache entry",
-         this));
-
-    PRFileDesc *fd = nullptr;
-
-    // open the file - restricted to user, the data could be confidential
-    rv = file->OpenNSPRFileDesc(PR_RDONLY, 00600, &fd);
-    NS_ENSURE_SUCCESS(rv, nullptr);
-
-    int32_t fileSize = PR_Available(fd);
-    if (fileSize < 0) {
-      // an error occurred. We could call PR_GetError(), but how would that
-      // help?
-      rv = NS_ERROR_UNEXPECTED;
-    } else {
-      rv = EnsureBuffer(fileSize);
-      if (NS_SUCCEEDED(rv)) {
-        bytesRead = PR_Read(fd, mBuffer, fileSize);
-        if (bytesRead < fileSize) {
-          rv = NS_ERROR_UNEXPECTED;
-        }
-      }
-    }
-    PR_Close(fd);
-    NS_ENSURE_SUCCESS(rv, nullptr);
-
-  } else if (metaFile < (kNumBlockFiles + 1)) {
-    // entry/metadata stored in cache block file
-
-    // allocate buffer
-    uint32_t blockCount = record->MetaBlockCount();
-    bytesRead = blockCount * GetBlockSizeForIndex(metaFile);
-
-    rv = EnsureBuffer(bytesRead);
-    NS_ENSURE_SUCCESS(rv, nullptr);
-
-    // read diskEntry, note when the blocks are at the end of file,
-    // bytesRead may be less than blockSize*blockCount.
-    // But the bytesRead should at least agree with the real disk entry size.
-    rv = mBlockFile[metaFile - 1].ReadBlocks(mBuffer, record->MetaStartBlock(),
-                                             blockCount, &bytesRead);
-    NS_ENSURE_SUCCESS(rv, nullptr);
-  }
-  diskEntry = (nsDiskCacheEntry *)mBuffer;
-  diskEntry->Unswap();  // disk to memory
-  // Check if calculated size agrees with bytesRead
-  if (bytesRead < 0 || (uint32_t)bytesRead < diskEntry->Size()) return nullptr;
-
-  // Return the buffer containing the diskEntry structure
-  return diskEntry;
-}
-
-/**
- *  CreateDiskCacheEntry(nsCacheEntry * entry)
- *
- *  Prepare an nsCacheEntry for writing to disk
- */
-nsDiskCacheEntry *nsDiskCacheMap::CreateDiskCacheEntry(
-    nsDiskCacheBinding *binding, uint32_t *aSize) {
-  nsCacheEntry *entry = binding->mCacheEntry;
-  if (!entry) return nullptr;
-
-  // Store security info, if it is serializable
-  nsCOMPtr<nsISupports> infoObj = entry->SecurityInfo();
-  nsCOMPtr<nsISerializable> serializable = do_QueryInterface(infoObj);
-  if (infoObj && !serializable) return nullptr;
-  if (serializable) {
-    nsCString info;
-    nsresult rv = NS_SerializeToString(serializable, info);
-    if (NS_FAILED(rv)) return nullptr;
-    rv = entry->SetMetaDataElement("security-info", info.get());
-    if (NS_FAILED(rv)) return nullptr;
-  }
-
-  uint32_t keySize = entry->Key()->Length() + 1;
-  uint32_t metaSize = entry->MetaDataSize();
-  uint32_t size = sizeof(nsDiskCacheEntry) + keySize + metaSize;
-
-  if (aSize) *aSize = size;
-
-  nsresult rv = EnsureBuffer(size);
-  if (NS_FAILED(rv)) return nullptr;
-
-  nsDiskCacheEntry *diskEntry = (nsDiskCacheEntry *)mBuffer;
-  diskEntry->mHeaderVersion = nsDiskCache::kCurrentVersion;
-  diskEntry->mMetaLocation = binding->mRecord.MetaLocation();
-  diskEntry->mFetchCount = entry->FetchCount();
-  diskEntry->mLastFetched = entry->LastFetched();
-  diskEntry->mLastModified = entry->LastModified();
-  diskEntry->mExpirationTime = entry->ExpirationTime();
-  diskEntry->mDataSize = entry->DataSize();
-  diskEntry->mKeySize = keySize;
-  diskEntry->mMetaDataSize = metaSize;
-
-  memcpy(diskEntry->Key(), entry->Key()->get(), keySize);
-
-  rv = entry->FlattenMetaData(diskEntry->MetaData(), metaSize);
-  if (NS_FAILED(rv)) return nullptr;
-
-  return diskEntry;
-}
-
-nsresult nsDiskCacheMap::WriteDiskCacheEntry(nsDiskCacheBinding *binding) {
-  CACHE_LOG_DEBUG(
-      ("CACHE: WriteDiskCacheEntry [%x]\n", binding->mRecord.HashNumber()));
-
-  nsresult rv = NS_OK;
-  uint32_t size;
-  nsDiskCacheEntry *diskEntry = CreateDiskCacheEntry(binding, &size);
-  if (!diskEntry) return NS_ERROR_UNEXPECTED;
-
-  uint32_t fileIndex = CalculateFileIndex(size);
-
-  // Deallocate old storage if necessary
-  if (binding->mRecord.MetaLocationInitialized()) {
-    // we have existing storage
-
-    if ((binding->mRecord.MetaFile() == 0) &&
-        (fileIndex == 0)) {  // keeping the separate file
-      // just decrement total
-      DecrementTotalSize(binding->mRecord.MetaFileSize());
-      NS_ASSERTION(
-          binding->mRecord.MetaFileGeneration() == binding->mGeneration,
-          "generations out of sync");
-    } else {
-      rv = DeleteStorage(&binding->mRecord, nsDiskCache::kMetaData);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-  }
-
-  binding->mRecord.SetEvictionRank(ULONG_MAX - SecondsFromPRTime(PR_Now()));
-  // write entry data to disk cache block file
-  diskEntry->Swap();
-
-  if (fileIndex != 0) {
-    while (true) {
-      uint32_t blockSize = GetBlockSizeForIndex(fileIndex);
-      uint32_t blocks = ((size - 1) / blockSize) + 1;
-
-      int32_t startBlock;
-      rv = mBlockFile[fileIndex - 1].WriteBlocks(diskEntry, size, blocks,
-                                                 &startBlock);
-      if (NS_SUCCEEDED(rv)) {
-        // update binding and cache map record
-        binding->mRecord.SetMetaBlocks(fileIndex, startBlock, blocks);
-
-        rv = UpdateRecord(&binding->mRecord);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        // XXX we should probably write out bucket ourselves
-
-        IncrementTotalSize(blocks, blockSize);
-        break;
-      }
-
-      if (fileIndex == kNumBlockFiles) {
-        fileIndex = 0;  // write data to separate file
-        break;
-      }
-
-      // try next block file
-      fileIndex++;
-    }
-  }
-
-  if (fileIndex == 0) {
-    // Write entry data to separate file
-    uint32_t metaFileSizeK = ((size + 0x03FF) >> 10);  // round up to nearest 1k
-    if (metaFileSizeK > kMaxDataSizeK) metaFileSizeK = kMaxDataSizeK;
-
-    binding->mRecord.SetMetaFileGeneration(binding->mGeneration);
-    binding->mRecord.SetMetaFileSize(metaFileSizeK);
-    rv = UpdateRecord(&binding->mRecord);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIFile> localFile;
-    rv = GetLocalFileForDiskCacheRecord(&binding->mRecord,
-                                        nsDiskCache::kMetaData, true,
-                                        getter_AddRefs(localFile));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // open the file
-    PRFileDesc *fd;
-    // open the file - restricted to user, the data could be confidential
-    rv = localFile->OpenNSPRFileDesc(PR_RDWR | PR_TRUNCATE | PR_CREATE_FILE,
-                                     00600, &fd);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // write the file
-    int32_t bytesWritten = PR_Write(fd, diskEntry, size);
-
-    PRStatus err = PR_Close(fd);
-    if ((bytesWritten != (int32_t)size) || (err != PR_SUCCESS)) {
-      return NS_ERROR_UNEXPECTED;
-    }
-
-    IncrementTotalSize(metaFileSizeK);
-  }
-
-  return rv;
-}
-
-nsresult nsDiskCacheMap::ReadDataCacheBlocks(nsDiskCacheBinding *binding,
-                                             char *buffer, uint32_t size) {
-  CACHE_LOG_DEBUG(("CACHE: ReadDataCacheBlocks [%x size=%u]\n",
-                   binding->mRecord.HashNumber(), size));
-
-  uint32_t fileIndex = binding->mRecord.DataFile();
-  int32_t readSize = size;
-
-  nsresult rv = mBlockFile[fileIndex - 1].ReadBlocks(
-      buffer, binding->mRecord.DataStartBlock(),
-      binding->mRecord.DataBlockCount(), &readSize);
-  NS_ENSURE_SUCCESS(rv, rv);
-  if (readSize < (int32_t)size) {
-    rv = NS_ERROR_UNEXPECTED;
-  }
-  return rv;
-}
-
-nsresult nsDiskCacheMap::WriteDataCacheBlocks(nsDiskCacheBinding *binding,
-                                              char *buffer, uint32_t size) {
-  CACHE_LOG_DEBUG(("CACHE: WriteDataCacheBlocks [%x size=%u]\n",
-                   binding->mRecord.HashNumber(), size));
-
-  nsresult rv = NS_OK;
-
-  // determine block file & number of blocks
-  uint32_t fileIndex = CalculateFileIndex(size);
-  uint32_t blockCount = 0;
-  int32_t startBlock = 0;
-
-  if (size > 0) {
-    // if fileIndex is 0, bad things happen below, which makes gcc 4.7
-    // complain, but it's not supposed to happen. See bug 854105.
-    MOZ_ASSERT(fileIndex);
-    while (fileIndex) {
-      uint32_t blockSize = GetBlockSizeForIndex(fileIndex);
-      blockCount = ((size - 1) / blockSize) + 1;
-
-      rv = mBlockFile[fileIndex - 1].WriteBlocks(buffer, size, blockCount,
-                                                 &startBlock);
-      if (NS_SUCCEEDED(rv)) {
-        IncrementTotalSize(blockCount, blockSize);
-        break;
-      }
-
-      if (fileIndex == kNumBlockFiles) return rv;
-
-      fileIndex++;
-    }
-  }
-
-  // update binding and cache map record
-  binding->mRecord.SetDataBlocks(fileIndex, startBlock, blockCount);
-  if (!binding->mDoomed) {
-    rv = UpdateRecord(&binding->mRecord);
-  }
-  return rv;
-}
-
-nsresult nsDiskCacheMap::DeleteStorage(nsDiskCacheRecord *record) {
-  nsresult rv1 = DeleteStorage(record, nsDiskCache::kData);
-  nsresult rv2 = DeleteStorage(record, nsDiskCache::kMetaData);
-  return NS_FAILED(rv1) ? rv1 : rv2;
-}
-
-nsresult nsDiskCacheMap::DeleteStorage(nsDiskCacheRecord *record,
-                                       bool metaData) {
-  CACHE_LOG_DEBUG(
-      ("CACHE: DeleteStorage [%x %u]\n", record->HashNumber(), metaData));
-
-  nsresult rv = NS_ERROR_UNEXPECTED;
-  uint32_t fileIndex = metaData ? record->MetaFile() : record->DataFile();
-  nsCOMPtr<nsIFile> file;
-
-  if (fileIndex == 0) {
-    // delete the file
-    uint32_t sizeK = metaData ? record->MetaFileSize() : record->DataFileSize();
-    // XXX if sizeK == USHRT_MAX, stat file for actual size
-
-    rv = GetFileForDiskCacheRecord(record, metaData, false,
-                                   getter_AddRefs(file));
-    if (NS_SUCCEEDED(rv)) {
-      rv = file->Remove(false);  // false == non-recursive
-    }
-    DecrementTotalSize(sizeK);
-
-  } else if (fileIndex < (kNumBlockFiles + 1)) {
-    // deallocate blocks
-    uint32_t startBlock =
-        metaData ? record->MetaStartBlock() : record->DataStartBlock();
-    uint32_t blockCount =
-        metaData ? record->MetaBlockCount() : record->DataBlockCount();
-
-    rv = mBlockFile[fileIndex - 1].DeallocateBlocks(startBlock, blockCount);
-    DecrementTotalSize(blockCount, GetBlockSizeForIndex(fileIndex));
-  }
-  if (metaData)
-    record->ClearMetaLocation();
-  else
-    record->ClearDataLocation();
-
-  return rv;
-}
-
-nsresult nsDiskCacheMap::GetFileForDiskCacheRecord(nsDiskCacheRecord *record,
-                                                   bool meta, bool createPath,
-                                                   nsIFile **result) {
-  if (!mCacheDirectory) return NS_ERROR_NOT_AVAILABLE;
-
-  nsCOMPtr<nsIFile> file;
-  nsresult rv = mCacheDirectory->Clone(getter_AddRefs(file));
-  if (NS_FAILED(rv)) return rv;
-
-  uint32_t hash = record->HashNumber();
-
-  // The file is stored under subdirectories according to the hash number:
-  // 0x01234567 -> 0/12/
-  rv = file->AppendNative(nsPrintfCString("%X", hash >> 28));
-  if (NS_FAILED(rv)) return rv;
-  rv = file->AppendNative(nsPrintfCString("%02X", (hash >> 20) & 0xFF));
-  if (NS_FAILED(rv)) return rv;
-
-  bool exists;
-  if (createPath && (NS_FAILED(file->Exists(&exists)) || !exists)) {
-    rv = file->Create(nsIFile::DIRECTORY_TYPE, 0700);
-    if (NS_FAILED(rv)) return rv;
-  }
-
-  int16_t generation = record->Generation();
-  char name[32];
-  // Cut the beginning of the hash that was used in the path
-  ::SprintfLiteral(name, "%05X%c%02X", hash & 0xFFFFF, (meta ? 'm' : 'd'),
-                   generation);
-  rv = file->AppendNative(nsDependentCString(name));
-  if (NS_FAILED(rv)) return rv;
-
-  NS_IF_ADDREF(*result = file);
-  return rv;
-}
-
-nsresult nsDiskCacheMap::GetLocalFileForDiskCacheRecord(
-    nsDiskCacheRecord *record, bool meta, bool createPath, nsIFile **result) {
-  nsCOMPtr<nsIFile> file;
-  nsresult rv =
-      GetFileForDiskCacheRecord(record, meta, createPath, getter_AddRefs(file));
-  if (NS_FAILED(rv)) return rv;
-
-  NS_IF_ADDREF(*result = file);
-  return rv;
-}
-
-nsresult nsDiskCacheMap::GetBlockFileForIndex(uint32_t index,
-                                              nsIFile **result) {
-  if (!mCacheDirectory) return NS_ERROR_NOT_AVAILABLE;
-
-  nsCOMPtr<nsIFile> file;
-  nsresult rv = mCacheDirectory->Clone(getter_AddRefs(file));
-  if (NS_FAILED(rv)) return rv;
-
-  char name[32];
-  ::SprintfLiteral(name, "_CACHE_%03d_", index + 1);
-  rv = file->AppendNative(nsDependentCString(name));
-  if (NS_FAILED(rv)) return rv;
-
-  NS_IF_ADDREF(*result = file);
-
-  return rv;
-}
-
-uint32_t nsDiskCacheMap::CalculateFileIndex(uint32_t size) {
-  // We prefer to use block file with larger block if the wasted space would
-  // be the same. E.g. store entry with size of 3073 bytes in 1 4K-block
-  // instead of in 4 1K-blocks.
-
-  if (size <= 3 * BLOCK_SIZE_FOR_INDEX(1)) return 1;
-  if (size <= 3 * BLOCK_SIZE_FOR_INDEX(2)) return 2;
-  if (size <= 4 * BLOCK_SIZE_FOR_INDEX(3)) return 3;
-  return 0;
-}
-
-nsresult nsDiskCacheMap::EnsureBuffer(uint32_t bufSize) {
-  if (mBufferSize < bufSize) {
-    char *buf = (char *)realloc(mBuffer, bufSize);
-    if (!buf) {
-      mBufferSize = 0;
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-    mBuffer = buf;
-    mBufferSize = bufSize;
-  }
-  return NS_OK;
-}
-
-void nsDiskCacheMap::NotifyCapacityChange(uint32_t capacity) {
-  // Heuristic 1. average cache entry size is probably around 1KB
-  // Heuristic 2. we don't want more than 32MB reserved to store the record
-  //              map in memory.
-  const int32_t RECORD_COUNT_LIMIT =
-      32 * 1024 * 1024 / sizeof(nsDiskCacheRecord);
-  int32_t maxRecordCount = std::min(int32_t(capacity), RECORD_COUNT_LIMIT);
-  if (mMaxRecordCount < maxRecordCount) {
-    // We can only grow
-    mMaxRecordCount = maxRecordCount;
-  }
-}
-
-size_t nsDiskCacheMap::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) {
-  size_t usage = aMallocSizeOf(mRecordArray);
-
-  usage += aMallocSizeOf(mBuffer);
-  usage += aMallocSizeOf(mMapFD);
-  usage += aMallocSizeOf(mCleanFD);
-  usage += aMallocSizeOf(mCacheDirectory);
-  usage += aMallocSizeOf(mCleanCacheTimer);
-
-  for (auto &block : mBlockFile) {
-    usage += block.SizeOfExcludingThis(aMallocSizeOf);
-  }
-
-  return usage;
-}
-
-nsresult nsDiskCacheMap::InitCacheClean(
-    nsIFile *cacheDirectory, nsDiskCache::CorruptCacheInfo *corruptInfo) {
-  // The _CACHE_CLEAN_ file will be used in the future to determine
-  // if the cache is clean or not.
-  bool cacheCleanFileExists = false;
-  nsCOMPtr<nsIFile> cacheCleanFile;
-  nsresult rv = cacheDirectory->GetParent(getter_AddRefs(cacheCleanFile));
-  if (NS_SUCCEEDED(rv)) {
-    rv = cacheCleanFile->AppendNative(NS_LITERAL_CSTRING("_CACHE_CLEAN_"));
-    if (NS_SUCCEEDED(rv)) {
-      // Check if the file already exists, if it does, we will later read the
-      // value and report it to telemetry.
-      cacheCleanFile->Exists(&cacheCleanFileExists);
-    }
-  }
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Could not build cache clean file path");
-    *corruptInfo = nsDiskCache::kCacheCleanFilePathError;
-    return rv;
-  }
-
-  // Make sure the _CACHE_CLEAN_ file exists
-  rv = cacheCleanFile->OpenNSPRFileDesc(PR_RDWR | PR_CREATE_FILE, 00600,
-                                        &mCleanFD);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Could not open cache clean file");
-    *corruptInfo = nsDiskCache::kCacheCleanOpenFileError;
-    return rv;
-  }
-
-  if (cacheCleanFileExists) {
-    char clean = '0';
-    int32_t bytesRead = PR_Read(mCleanFD, &clean, 1);
-    if (bytesRead != 1) {
-      NS_WARNING("Could not read _CACHE_CLEAN_ file contents");
-    }
-  }
-
-  // Create a timer that will be used to validate the cache
-  // as long as an activity threshold was met
-  mCleanCacheTimer =
-      NS_NewTimer(nsCacheService::GlobalInstance()->mCacheIOThread);
-  rv = mCleanCacheTimer ? ResetCacheTimer() : NS_ERROR_OUT_OF_MEMORY;
-
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Could not create cache clean timer");
-    mCleanCacheTimer = nullptr;
-    *corruptInfo = nsDiskCache::kCacheCleanTimerError;
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-nsresult nsDiskCacheMap::WriteCacheClean(bool clean) {
-  nsCacheService::AssertOwnsLock();
-  if (!mCleanFD) {
-    NS_WARNING("Cache clean file is not open!");
-    return NS_ERROR_FAILURE;
-  }
-
-  CACHE_LOG_DEBUG(("CACHE: WriteCacheClean: %d\n", clean ? 1 : 0));
-  // I'm using a simple '1' or '0' to denote cache clean
-  // since it can be edited easily by any text editor for testing.
-  char data = clean ? '1' : '0';
-  int32_t filePos = PR_Seek(mCleanFD, 0, PR_SEEK_SET);
-  if (filePos != 0) {
-    NS_WARNING("Could not seek in cache clean file!");
-    return NS_ERROR_FAILURE;
-  }
-  int32_t bytesWritten = PR_Write(mCleanFD, &data, 1);
-  if (bytesWritten != 1) {
-    NS_WARNING("Could not write cache clean file!");
-    return NS_ERROR_FAILURE;
-  }
-  PRStatus err = PR_Sync(mCleanFD);
-  if (err != PR_SUCCESS) {
-    NS_WARNING("Could not flush cache clean file!");
-  }
-
-  return NS_OK;
-}
-
-nsresult nsDiskCacheMap::InvalidateCache() {
-  nsCacheService::AssertOwnsLock();
-  CACHE_LOG_DEBUG(("CACHE: InvalidateCache\n"));
-  nsresult rv;
-
-  if (!mIsDirtyCacheFlushed) {
-    rv = WriteCacheClean(false);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    mIsDirtyCacheFlushed = true;
-  }
-
-  rv = ResetCacheTimer();
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return NS_OK;
-}
-
-nsresult nsDiskCacheMap::ResetCacheTimer(int32_t timeout) {
-  mCleanCacheTimer->Cancel();
-  nsresult rv = mCleanCacheTimer->InitWithNamedFuncCallback(
-      RevalidateTimerCallback, nullptr, timeout, nsITimer::TYPE_ONE_SHOT,
-      "nsDiskCacheMap::ResetCacheTimer");
-  NS_ENSURE_SUCCESS(rv, rv);
-  mLastInvalidateTime = PR_IntervalNow();
-
-  return rv;
-}
-
-void nsDiskCacheMap::RevalidateTimerCallback(nsITimer *aTimer, void *arg) {
-  nsCacheServiceAutoLock lock;
-  if (!nsCacheService::gService->mDiskDevice ||
-      !nsCacheService::gService->mDiskDevice->Initialized()) {
-    return;
-  }
-
-  nsDiskCacheMap *diskCacheMap =
-      &nsCacheService::gService->mDiskDevice->mCacheMap;
-
-  // If we have less than kRevalidateCacheTimeout since the last timer was
-  // issued then another thread called InvalidateCache.  This won't catch
-  // all cases where we wanted to cancel the timer, but under the lock it
-  // is always OK to revalidate as long as IsCacheInSafeState() returns
-  // true.  We just want to avoid revalidating when we can to reduce IO
-  // and this check will do that.
-  uint32_t delta = PR_IntervalToMilliseconds(
-                       PR_IntervalNow() - diskCacheMap->mLastInvalidateTime) +
-                   kRevalidateCacheTimeoutTolerance;
-  if (delta < kRevalidateCacheTimeout) {
-    diskCacheMap->ResetCacheTimer();
-    return;
-  }
-
-  nsresult rv = diskCacheMap->RevalidateCache();
-  if (NS_FAILED(rv)) {
-    diskCacheMap->ResetCacheTimer(kRevalidateCacheErrorTimeout);
-  }
-}
-
-bool nsDiskCacheMap::IsCacheInSafeState() {
-  return nsCacheService::GlobalInstance()->IsDoomListEmpty();
-}
-
-nsresult nsDiskCacheMap::RevalidateCache() {
-  CACHE_LOG_DEBUG(("CACHE: RevalidateCache\n"));
-  nsresult rv;
-
-  if (!IsCacheInSafeState()) {
-    CACHE_LOG_DEBUG(
-        ("CACHE: Revalidation should not performed because "
-         "cache not in a safe state\n"));
-    // Normally we would return an error here, but there is a bug where
-    // the doom list sometimes gets an entry 'stuck' and doens't clear it
-    // until browser shutdown.  So we allow revalidation for the time being
-    // to get proper telemetry data of how much the cache corruption plan
-    // would help.
-  }
-
-  // If telemetry data shows it is worth it, we'll be flushing headers and
-  // records before flushing the clean cache file.
-
-  // Write out the _CACHE_CLEAN_ file with '1'
-  rv = WriteCacheClean(true);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  mIsDirtyCacheFlushed = false;
-
-  return NS_OK;
-}
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheMap.h
+++ /dev/null
@@ -1,543 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=4 sw=2 sts=2 cin et: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _nsDiskCacheMap_h_
-#define _nsDiskCacheMap_h_
-
-#include "mozilla/MemoryReporting.h"
-#include <limits.h>
-
-#include "prnetdb.h"
-#include "nsDebug.h"
-#include "nsError.h"
-#include "nsIFile.h"
-#include "nsITimer.h"
-
-#include "nsDiskCache.h"
-#include "nsDiskCacheBlockFile.h"
-
-class nsDiskCacheBinding;
-struct nsDiskCacheEntry;
-
-// clang-format off
-/******************************************************************************
- *  nsDiskCacheRecord
- *
- *   Cache Location Format
- *
- *    1000 0000 0000 0000 0000 0000 0000 0000 : initialized bit
- *
- *    0011 0000 0000 0000 0000 0000 0000 0000 : File Selector (0 = separate file)
- *    0000 0011 0000 0000 0000 0000 0000 0000 : number of extra contiguous blocks 1-4
- *    0100 1100 0000 0000 0000 0000 0000 0000 : reserved bits
- *    0000 0000 1111 1111 1111 1111 1111 1111 : block#  0-16777216 (2^24)
- *
- *    0000 0000 1111 1111 1111 1111 0000 0000 : eFileSizeMask (size of file in k: see note)
- *    0000 0000 0000 0000 0000 0000 1111 1111 : eFileGenerationMask
- *
- *  File Selector:
- *      0 = separate file on disk
- *      1 = 256 byte block file
- *      2 = 1k block file
- *      3 = 4k block file
- *
- *  eFileSizeMask note:  Files larger than 65535 KiB have this limit stored in
- *                       the location.  The file itself must be examined to
- *                       determine its actual size if necessary.
- *
- *****************************************************************************/
-// clang-format on
-
-/*
-  We have 3 block files with roughly the same max size (32MB)
-    1 - block size 256B, number of blocks 131072
-    2 - block size  1kB, number of blocks  32768
-    3 - block size  4kB, number of blocks   8192
-*/
-#define kNumBlockFiles 3
-#define SIZE_SHIFT(idx) (2 * ((idx)-1))
-#define BLOCK_SIZE_FOR_INDEX(idx) ((idx) ? (256 << SIZE_SHIFT(idx)) : 0)
-#define BITMAP_SIZE_FOR_INDEX(idx) ((idx) ? (131072 >> SIZE_SHIFT(idx)) : 0)
-
-// Min and max values for the number of records in the DiskCachemap
-#define kMinRecordCount 512
-
-#define kSeparateFile 0
-#define kBuckets (1 << 5)  // must be a power of 2!
-
-// Maximum size in K which can be stored in the location (see eFileSizeMask).
-// Both data and metadata can be larger, but only up to kMaxDataSizeK can be
-// counted into total cache size. I.e. if there are entries where either data or
-// metadata is larger than kMaxDataSizeK, the total cache size will be
-// inaccurate (smaller) than the actual cache size. The alternative is to stat
-// the files to find the real size, which was decided against for performance
-// reasons. See bug #651100 comment #21.
-#define kMaxDataSizeK 0xFFFF
-
-// preallocate up to 1MB of separate cache file
-#define kPreallocateLimit 1 * 1024 * 1024
-
-// The minimum amount of milliseconds to wait before re-attempting to
-// revalidate the cache.
-#define kRevalidateCacheTimeout 3000
-#define kRevalidateCacheTimeoutTolerance 10
-#define kRevalidateCacheErrorTimeout 1000
-
-class nsDiskCacheRecord {
- private:
-  uint32_t mHashNumber;
-  uint32_t mEvictionRank;
-  uint32_t mDataLocation;
-  uint32_t mMetaLocation;
-
-  enum {
-    eLocationInitializedMask = 0x80000000,
-
-    eLocationSelectorMask = 0x30000000,
-    eLocationSelectorOffset = 28,
-
-    eExtraBlocksMask = 0x03000000,
-    eExtraBlocksOffset = 24,
-
-    eReservedMask = 0x4C000000,
-
-    eBlockNumberMask = 0x00FFFFFF,
-
-    eFileSizeMask = 0x00FFFF00,
-    eFileSizeOffset = 8,
-    eFileGenerationMask = 0x000000FF,
-    eFileReservedMask = 0x4F000000
-
-  };
-
- public:
-  nsDiskCacheRecord()
-      : mHashNumber(0), mEvictionRank(0), mDataLocation(0), mMetaLocation(0) {}
-
-  bool ValidRecord() {
-    if ((mDataLocation & eReservedMask) || (mMetaLocation & eReservedMask))
-      return false;
-    return true;
-  }
-
-  // HashNumber accessors
-  uint32_t HashNumber() const { return mHashNumber; }
-  void SetHashNumber(uint32_t hashNumber) { mHashNumber = hashNumber; }
-
-  // EvictionRank accessors
-  uint32_t EvictionRank() const { return mEvictionRank; }
-  void SetEvictionRank(uint32_t rank) { mEvictionRank = rank ? rank : 1; }
-
-  // DataLocation accessors
-  bool DataLocationInitialized() const {
-    return 0 != (mDataLocation & eLocationInitializedMask);
-  }
-  void ClearDataLocation() { mDataLocation = 0; }
-
-  uint32_t DataFile() const {
-    return (uint32_t)(mDataLocation & eLocationSelectorMask) >>
-           eLocationSelectorOffset;
-  }
-
-  void SetDataBlocks(uint32_t index, uint32_t startBlock, uint32_t blockCount) {
-    // clear everything
-    mDataLocation = 0;
-
-    // set file index
-    NS_ASSERTION(index < (kNumBlockFiles + 1), "invalid location index");
-    NS_ASSERTION(index > 0, "invalid location index");
-    mDataLocation |= (index << eLocationSelectorOffset) & eLocationSelectorMask;
-
-    // set startBlock
-    NS_ASSERTION(startBlock == (startBlock & eBlockNumberMask),
-                 "invalid block number");
-    mDataLocation |= startBlock & eBlockNumberMask;
-
-    // set blockCount
-    NS_ASSERTION((blockCount >= 1) && (blockCount <= 4), "invalid block count");
-    --blockCount;
-    mDataLocation |= (blockCount << eExtraBlocksOffset) & eExtraBlocksMask;
-
-    mDataLocation |= eLocationInitializedMask;
-  }
-
-  uint32_t DataBlockCount() const {
-    return (uint32_t)((mDataLocation & eExtraBlocksMask) >>
-                      eExtraBlocksOffset) +
-           1;
-  }
-
-  uint32_t DataStartBlock() const { return (mDataLocation & eBlockNumberMask); }
-
-  uint32_t DataBlockSize() const { return BLOCK_SIZE_FOR_INDEX(DataFile()); }
-
-  uint32_t DataFileSize() const {
-    return (mDataLocation & eFileSizeMask) >> eFileSizeOffset;
-  }
-  void SetDataFileSize(uint32_t size) {
-    NS_ASSERTION((mDataLocation & eFileReservedMask) == 0, "bad location");
-    mDataLocation &= ~eFileSizeMask;  // clear eFileSizeMask
-    mDataLocation |= (size << eFileSizeOffset) & eFileSizeMask;
-  }
-
-  uint8_t DataFileGeneration() const {
-    return (mDataLocation & eFileGenerationMask);
-  }
-
-  void SetDataFileGeneration(uint8_t generation) {
-    // clear everything, (separate file index = 0)
-    mDataLocation = 0;
-    mDataLocation |= generation & eFileGenerationMask;
-    mDataLocation |= eLocationInitializedMask;
-  }
-
-  // MetaLocation accessors
-  bool MetaLocationInitialized() const {
-    return 0 != (mMetaLocation & eLocationInitializedMask);
-  }
-  void ClearMetaLocation() { mMetaLocation = 0; }
-  uint32_t MetaLocation() const { return mMetaLocation; }
-
-  uint32_t MetaFile() const {
-    return (uint32_t)(mMetaLocation & eLocationSelectorMask) >>
-           eLocationSelectorOffset;
-  }
-
-  void SetMetaBlocks(uint32_t index, uint32_t startBlock, uint32_t blockCount) {
-    // clear everything
-    mMetaLocation = 0;
-
-    // set file index
-    NS_ASSERTION(index < (kNumBlockFiles + 1), "invalid location index");
-    NS_ASSERTION(index > 0, "invalid location index");
-    mMetaLocation |= (index << eLocationSelectorOffset) & eLocationSelectorMask;
-
-    // set startBlock
-    NS_ASSERTION(startBlock == (startBlock & eBlockNumberMask),
-                 "invalid block number");
-    mMetaLocation |= startBlock & eBlockNumberMask;
-
-    // set blockCount
-    NS_ASSERTION((blockCount >= 1) && (blockCount <= 4), "invalid block count");
-    --blockCount;
-    mMetaLocation |= (blockCount << eExtraBlocksOffset) & eExtraBlocksMask;
-
-    mMetaLocation |= eLocationInitializedMask;
-  }
-
-  uint32_t MetaBlockCount() const {
-    return (uint32_t)((mMetaLocation & eExtraBlocksMask) >>
-                      eExtraBlocksOffset) +
-           1;
-  }
-
-  uint32_t MetaStartBlock() const { return (mMetaLocation & eBlockNumberMask); }
-
-  uint32_t MetaBlockSize() const { return BLOCK_SIZE_FOR_INDEX(MetaFile()); }
-
-  uint32_t MetaFileSize() const {
-    return (mMetaLocation & eFileSizeMask) >> eFileSizeOffset;
-  }
-  void SetMetaFileSize(uint32_t size) {
-    mMetaLocation &= ~eFileSizeMask;  // clear eFileSizeMask
-    mMetaLocation |= (size << eFileSizeOffset) & eFileSizeMask;
-  }
-
-  uint8_t MetaFileGeneration() const {
-    return (mMetaLocation & eFileGenerationMask);
-  }
-
-  void SetMetaFileGeneration(uint8_t generation) {
-    // clear everything, (separate file index = 0)
-    mMetaLocation = 0;
-    mMetaLocation |= generation & eFileGenerationMask;
-    mMetaLocation |= eLocationInitializedMask;
-  }
-
-  uint8_t Generation() const {
-    if ((mDataLocation & eLocationInitializedMask) && (DataFile() == 0))
-      return DataFileGeneration();
-
-    if ((mMetaLocation & eLocationInitializedMask) && (MetaFile() == 0))
-      return MetaFileGeneration();
-
-    return 0;  // no generation
-  }
-
-#if defined(IS_LITTLE_ENDIAN)
-  void Swap() {
-    mHashNumber = htonl(mHashNumber);
-    mEvictionRank = htonl(mEvictionRank);
-    mDataLocation = htonl(mDataLocation);
-    mMetaLocation = htonl(mMetaLocation);
-  }
-#endif
-
-#if defined(IS_LITTLE_ENDIAN)
-  void Unswap() {
-    mHashNumber = ntohl(mHashNumber);
-    mEvictionRank = ntohl(mEvictionRank);
-    mDataLocation = ntohl(mDataLocation);
-    mMetaLocation = ntohl(mMetaLocation);
-  }
-#endif
-};
-
-/******************************************************************************
- *  nsDiskCacheRecordVisitor
- *****************************************************************************/
-
-enum {
-  kDeleteRecordAndContinue = -1,
-  kStopVisitingRecords = 0,
-  kVisitNextRecord = 1
-};
-
-class nsDiskCacheRecordVisitor {
- public:
-  virtual int32_t VisitRecord(nsDiskCacheRecord *mapRecord) = 0;
-};
-
-/******************************************************************************
- *  nsDiskCacheHeader
- *****************************************************************************/
-
-struct nsDiskCacheHeader {
-  uint32_t mVersion;                 // cache version.
-  uint32_t mDataSize;                // size of cache in units of 1024bytes.
-  int32_t mEntryCount;               // number of entries stored in cache.
-  uint32_t mIsDirty;                 // dirty flag.
-  int32_t mRecordCount;              // Number of records
-  uint32_t mEvictionRank[kBuckets];  // Highest EvictionRank of the bucket
-  uint32_t mBucketUsage[kBuckets];   // Number of used entries in the bucket
-
-  nsDiskCacheHeader()
-      : mVersion(nsDiskCache::kCurrentVersion),
-        mDataSize(0),
-        mEntryCount(0),
-        mIsDirty(true),
-        mRecordCount(0) {}
-
-  void Swap() {
-#if defined(IS_LITTLE_ENDIAN)
-    mVersion = htonl(mVersion);
-    mDataSize = htonl(mDataSize);
-    mEntryCount = htonl(mEntryCount);
-    mIsDirty = htonl(mIsDirty);
-    mRecordCount = htonl(mRecordCount);
-
-    for (uint32_t i = 0; i < kBuckets; i++) {
-      mEvictionRank[i] = htonl(mEvictionRank[i]);
-      mBucketUsage[i] = htonl(mBucketUsage[i]);
-    }
-#endif
-  }
-
-  void Unswap() {
-#if defined(IS_LITTLE_ENDIAN)
-    mVersion = ntohl(mVersion);
-    mDataSize = ntohl(mDataSize);
-    mEntryCount = ntohl(mEntryCount);
-    mIsDirty = ntohl(mIsDirty);
-    mRecordCount = ntohl(mRecordCount);
-
-    for (uint32_t i = 0; i < kBuckets; i++) {
-      mEvictionRank[i] = ntohl(mEvictionRank[i]);
-      mBucketUsage[i] = ntohl(mBucketUsage[i]);
-    }
-#endif
-  }
-};
-
-/******************************************************************************
- *  nsDiskCacheMap
- *****************************************************************************/
-
-class nsDiskCacheMap {
- public:
-  nsDiskCacheMap()
-      : mCacheDirectory(nullptr),
-        mMapFD(nullptr),
-        mCleanFD(nullptr),
-        mRecordArray(nullptr),
-        mBufferSize(0),
-        mBuffer(nullptr),
-        mMaxRecordCount(16384),  // this default value won't matter
-        mIsDirtyCacheFlushed(false),
-        mLastInvalidateTime(0) {}
-
-  ~nsDiskCacheMap() { (void)Close(true); }
-
-  /**
-   *  File Operations
-   *
-   *  Open
-   *
-   *  Creates a new cache map file if one doesn't exist.
-   *  Returns error if it detects change in format or cache wasn't closed.
-   */
-  nsresult Open(nsIFile *cacheDirectory,
-                nsDiskCache::CorruptCacheInfo *corruptInfo);
-  nsresult Close(bool flush);
-  nsresult Trim();
-
-  nsresult FlushHeader();
-  nsresult FlushRecords(bool unswap);
-
-  void NotifyCapacityChange(uint32_t capacity);
-
-  /**
-   *  Record operations
-   */
-  nsresult AddRecord(nsDiskCacheRecord *mapRecord,
-                     nsDiskCacheRecord *oldRecord);
-  nsresult UpdateRecord(nsDiskCacheRecord *mapRecord);
-  nsresult FindRecord(uint32_t hashNumber, nsDiskCacheRecord *mapRecord);
-  nsresult DeleteRecord(nsDiskCacheRecord *mapRecord);
-  nsresult VisitRecords(nsDiskCacheRecordVisitor *visitor);
-  nsresult EvictRecords(nsDiskCacheRecordVisitor *visitor);
-
-  /**
-   *  Disk Entry operations
-   */
-  nsresult DeleteStorage(nsDiskCacheRecord *record);
-
-  nsresult GetFileForDiskCacheRecord(nsDiskCacheRecord *record, bool meta,
-                                     bool createPath, nsIFile **result);
-
-  nsresult GetLocalFileForDiskCacheRecord(nsDiskCacheRecord *record, bool meta,
-                                          bool createPath, nsIFile **result);
-
-  // On success, this returns the buffer owned by nsDiskCacheMap,
-  // so it must not be deleted by the caller.
-  nsDiskCacheEntry *ReadDiskCacheEntry(nsDiskCacheRecord *record);
-
-  nsresult WriteDiskCacheEntry(nsDiskCacheBinding *binding);
-
-  nsresult ReadDataCacheBlocks(nsDiskCacheBinding *binding, char *buffer,
-                               uint32_t size);
-  nsresult WriteDataCacheBlocks(nsDiskCacheBinding *binding, char *buffer,
-                                uint32_t size);
-  nsresult DeleteStorage(nsDiskCacheRecord *record, bool metaData);
-
-  /**
-   *  Statistical Operations
-   */
-  void IncrementTotalSize(uint32_t delta) {
-    mHeader.mDataSize += delta;
-    mHeader.mIsDirty = true;
-  }
-
-  void DecrementTotalSize(uint32_t delta) {
-    NS_ASSERTION(mHeader.mDataSize >= delta, "disk cache size negative?");
-    mHeader.mDataSize =
-        mHeader.mDataSize > delta ? mHeader.mDataSize - delta : 0;
-    mHeader.mIsDirty = true;
-  }
-
-  inline void IncrementTotalSize(uint32_t blocks, uint32_t blockSize) {
-    // Round up to nearest K
-    IncrementTotalSize(((blocks * blockSize) + 0x03FF) >> 10);
-  }
-
-  inline void DecrementTotalSize(uint32_t blocks, uint32_t blockSize) {
-    // Round up to nearest K
-    DecrementTotalSize(((blocks * blockSize) + 0x03FF) >> 10);
-  }
-
-  uint32_t TotalSize() { return mHeader.mDataSize; }
-
-  int32_t EntryCount() { return mHeader.mEntryCount; }
-
-  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
-
- private:
-  /**
-   *  Private methods
-   */
-  nsresult OpenBlockFiles(nsDiskCache::CorruptCacheInfo *corruptInfo);
-  nsresult CloseBlockFiles(bool flush);
-  bool CacheFilesExist();
-
-  nsresult CreateCacheSubDirectories();
-
-  uint32_t CalculateFileIndex(uint32_t size);
-
-  nsresult GetBlockFileForIndex(uint32_t index, nsIFile **result);
-  uint32_t GetBlockSizeForIndex(uint32_t index) const {
-    return BLOCK_SIZE_FOR_INDEX(index);
-  }
-  uint32_t GetBitMapSizeForIndex(uint32_t index) const {
-    return BITMAP_SIZE_FOR_INDEX(index);
-  }
-
-  // returns the bucket number
-  uint32_t GetBucketIndex(uint32_t hashNumber) const {
-    return (hashNumber & (kBuckets - 1));
-  }
-
-  // Gets the size of the bucket (in number of records)
-  uint32_t GetRecordsPerBucket() const {
-    return mHeader.mRecordCount / kBuckets;
-  }
-
-  // Gets the first record in the bucket
-  nsDiskCacheRecord *GetFirstRecordInBucket(uint32_t bucket) const {
-    return mRecordArray + bucket * GetRecordsPerBucket();
-  }
-
-  uint32_t GetBucketRank(uint32_t bucketIndex, uint32_t targetRank);
-
-  int32_t VisitEachRecord(uint32_t bucketIndex,
-                          nsDiskCacheRecordVisitor *visitor,
-                          uint32_t evictionRank);
-
-  nsresult GrowRecords();
-  nsresult ShrinkRecords();
-
-  nsresult EnsureBuffer(uint32_t bufSize);
-
-  // The returned structure will point to the buffer owned by nsDiskCacheMap,
-  // so it must not be deleted by the caller.
-  nsDiskCacheEntry *CreateDiskCacheEntry(nsDiskCacheBinding *binding,
-                                         uint32_t *size);
-
-  // Initializes the _CACHE_CLEAN_ related functionality
-  nsresult InitCacheClean(nsIFile *cacheDirectory,
-                          nsDiskCache::CorruptCacheInfo *corruptInfo);
-  // Writes out a value of '0' or '1' in the _CACHE_CLEAN_ file
-  nsresult WriteCacheClean(bool clean);
-  // Resets the timout for revalidating the cache
-  nsresult ResetCacheTimer(int32_t timeout = kRevalidateCacheTimeout);
-  // Invalidates the cache, calls WriteCacheClean and ResetCacheTimer
-  nsresult InvalidateCache();
-  // Determines if the cache is in a safe state
-  bool IsCacheInSafeState();
-  // Revalidates the cache by writting out the header, records, and finally
-  // by calling WriteCacheClean(true).
-  nsresult RevalidateCache();
-  // Timer which revalidates the cache
-  static void RevalidateTimerCallback(nsITimer *aTimer, void *arg);
-
-  /**
-   *  data members
-   */
- private:
-  nsCOMPtr<nsITimer> mCleanCacheTimer;
-  nsCOMPtr<nsIFile> mCacheDirectory;
-  PRFileDesc *mMapFD;
-  PRFileDesc *mCleanFD;
-  nsDiskCacheRecord *mRecordArray;
-  nsDiskCacheBlockFile mBlockFile[kNumBlockFiles];
-  uint32_t mBufferSize;
-  char *mBuffer;
-  nsDiskCacheHeader mHeader;
-  int32_t mMaxRecordCount;
-  bool mIsDirtyCacheFlushed;
-  PRIntervalTime mLastInvalidateTime;
-};
-
-#endif  // _nsDiskCacheMap_h_
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheStreams.cpp
+++ /dev/null
@@ -1,629 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsCache.h"
-#include "nsDiskCache.h"
-#include "nsDiskCacheDevice.h"
-#include "nsDiskCacheStreams.h"
-#include "nsCacheService.h"
-#include "mozilla/FileUtils.h"
-#include "nsThreadUtils.h"
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/Telemetry.h"
-#include "mozilla/TimeStamp.h"
-#include <algorithm>
-
-// we pick 16k as the max buffer size because that is the threshold above which
-//      we are unable to store the data in the cache block files
-//      see nsDiskCacheMap.[cpp,h]
-#define kMaxBufferSize (16 * 1024)
-
-// Assumptions:
-//      - cache descriptors live for life of streams
-//      - streams will only be used by FileTransport,
-//         they will not be directly accessible to clients
-//      - overlapped I/O is NOT supported
-
-/******************************************************************************
- *  nsDiskCacheInputStream
- *****************************************************************************/
-class nsDiskCacheInputStream : public nsIInputStream {
- public:
-  nsDiskCacheInputStream(nsDiskCacheStreamIO *parent, PRFileDesc *fileDesc,
-                         const char *buffer, uint32_t endOfStream);
-
-  NS_DECL_THREADSAFE_ISUPPORTS
-  NS_DECL_NSIINPUTSTREAM
-
- private:
-  virtual ~nsDiskCacheInputStream();
-
-  nsDiskCacheStreamIO *mStreamIO;  // backpointer to parent
-  PRFileDesc *mFD;
-  const char *mBuffer;
-  uint32_t mStreamEnd;
-  uint32_t mPos;  // stream position
-  bool mClosed;
-};
-
-NS_IMPL_ISUPPORTS(nsDiskCacheInputStream, nsIInputStream)
-
-nsDiskCacheInputStream::nsDiskCacheInputStream(nsDiskCacheStreamIO *parent,
-                                               PRFileDesc *fileDesc,
-                                               const char *buffer,
-                                               uint32_t endOfStream)
-    : mStreamIO(parent),
-      mFD(fileDesc),
-      mBuffer(buffer),
-      mStreamEnd(endOfStream),
-      mPos(0),
-      mClosed(false) {
-  NS_ADDREF(mStreamIO);
-  mStreamIO->IncrementInputStreamCount();
-}
-
-nsDiskCacheInputStream::~nsDiskCacheInputStream() {
-  Close();
-  mStreamIO->DecrementInputStreamCount();
-  NS_RELEASE(mStreamIO);
-}
-
-NS_IMETHODIMP
-nsDiskCacheInputStream::Close() {
-  if (!mClosed) {
-    if (mFD) {
-      (void)PR_Close(mFD);
-      mFD = nullptr;
-    }
-    mClosed = true;
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDiskCacheInputStream::Available(uint64_t *bytesAvailable) {
-  if (mClosed) return NS_BASE_STREAM_CLOSED;
-  if (mStreamEnd < mPos) return NS_ERROR_UNEXPECTED;
-
-  *bytesAvailable = mStreamEnd - mPos;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDiskCacheInputStream::Read(char *buffer, uint32_t count,
-                             uint32_t *bytesRead) {
-  *bytesRead = 0;
-
-  if (mClosed) {
-    CACHE_LOG_DEBUG(
-        ("CACHE: nsDiskCacheInputStream::Read "
-         "[stream=%p] stream was closed",
-         this));
-    return NS_OK;
-  }
-
-  if (mPos == mStreamEnd) {
-    CACHE_LOG_DEBUG(
-        ("CACHE: nsDiskCacheInputStream::Read "
-         "[stream=%p] stream at end of file",
-         this));
-    return NS_OK;
-  }
-  if (mPos > mStreamEnd) {
-    CACHE_LOG_DEBUG(
-        ("CACHE: nsDiskCacheInputStream::Read "
-         "[stream=%p] stream past end of file (!)",
-         this));
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  if (count > mStreamEnd - mPos) count = mStreamEnd - mPos;
-
-  if (mFD) {
-    // just read from file
-    int32_t result = PR_Read(mFD, buffer, count);
-    if (result < 0) {
-      nsresult rv = NS_ErrorAccordingToNSPR();
-      CACHE_LOG_DEBUG(
-          ("CACHE: nsDiskCacheInputStream::Read PR_Read failed"
-           "[stream=%p, rv=%d, NSPR error %s",
-           this, int(rv), PR_ErrorToName(PR_GetError())));
-      return rv;
-    }
-
-    mPos += (uint32_t)result;
-    *bytesRead = (uint32_t)result;
-
-  } else if (mBuffer) {
-    // read data from mBuffer
-    memcpy(buffer, mBuffer + mPos, count);
-    mPos += count;
-    *bytesRead = count;
-  } else {
-    // no data source for input stream
-  }
-
-  CACHE_LOG_DEBUG(
-      ("CACHE: nsDiskCacheInputStream::Read "
-       "[stream=%p, count=%ud, byteRead=%ud] ",
-       this, unsigned(count), unsigned(*bytesRead)));
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDiskCacheInputStream::ReadSegments(nsWriteSegmentFun writer, void *closure,
-                                     uint32_t count, uint32_t *bytesRead) {
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsDiskCacheInputStream::IsNonBlocking(bool *nonBlocking) {
-  *nonBlocking = false;
-  return NS_OK;
-}
-
-/******************************************************************************
- *  nsDiskCacheStreamIO
- *****************************************************************************/
-NS_IMPL_ISUPPORTS(nsDiskCacheStreamIO, nsIOutputStream)
-
-nsDiskCacheStreamIO::nsDiskCacheStreamIO(nsDiskCacheBinding *binding)
-    : mBinding(binding),
-      mInStreamCount(0),
-      mFD(nullptr),
-      mStreamEnd(0),
-      mBufSize(0),
-      mBuffer(nullptr),
-      mOutputStreamIsOpen(false) {
-  mDevice = (nsDiskCacheDevice *)mBinding->mCacheEntry->CacheDevice();
-
-  // acquire "death grip" on cache service
-  nsCacheService *service = nsCacheService::GlobalInstance();
-  NS_ADDREF(service);
-}
-
-nsDiskCacheStreamIO::~nsDiskCacheStreamIO() {
-  nsCacheService::AssertOwnsLock();
-
-  // Close the outputstream
-  if (mBinding && mOutputStreamIsOpen) {
-    (void)CloseOutputStream();
-  }
-
-  // release "death grip" on cache service
-  nsCacheService *service = nsCacheService::GlobalInstance();
-  NS_RELEASE(service);
-
-  // assert streams closed
-  NS_ASSERTION(!mOutputStreamIsOpen, "output stream still open");
-  NS_ASSERTION(mInStreamCount == 0, "input stream still open");
-  NS_ASSERTION(!mFD, "file descriptor not closed");
-
-  DeleteBuffer();
-}
-
-// NOTE: called with service lock held
-nsresult nsDiskCacheStreamIO::GetInputStream(uint32_t offset,
-                                             nsIInputStream **inputStream) {
-  NS_ENSURE_ARG_POINTER(inputStream);
-  NS_ENSURE_TRUE(offset == 0, NS_ERROR_NOT_IMPLEMENTED);
-
-  *inputStream = nullptr;
-
-  if (!mBinding) return NS_ERROR_NOT_AVAILABLE;
-
-  if (mOutputStreamIsOpen) {
-    NS_WARNING("already have an output stream open");
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-
-  nsresult rv;
-  PRFileDesc *fd = nullptr;
-
-  mStreamEnd = mBinding->mCacheEntry->DataSize();
-  if (mStreamEnd == 0) {
-    // there's no data to read
-    NS_ASSERTION(!mBinding->mRecord.DataLocationInitialized(),
-                 "storage allocated for zero data size");
-  } else if (mBinding->mRecord.DataFile() == 0) {
-    // open file desc for data
-    rv = OpenCacheFile(PR_RDONLY, &fd);
-    if (NS_FAILED(rv)) return rv;  // unable to open file
-    NS_ASSERTION(fd, "cache stream lacking open file.");
-
-  } else if (!mBuffer) {
-    // read block file for data
-    rv = ReadCacheBlocks(mStreamEnd);
-    if (NS_FAILED(rv)) return rv;
-  }
-  // else, mBuffer already contains all of the data (left over from a
-  // previous block-file read or write).
-
-  NS_ASSERTION(!(fd && mBuffer), "ambiguous data sources for input stream");
-
-  // create a new input stream
-  nsDiskCacheInputStream *inStream =
-      new nsDiskCacheInputStream(this, fd, mBuffer, mStreamEnd);
-  if (!inStream) return NS_ERROR_OUT_OF_MEMORY;
-
-  NS_ADDREF(*inputStream = inStream);
-  return NS_OK;
-}
-
-// NOTE: called with service lock held
-nsresult nsDiskCacheStreamIO::GetOutputStream(uint32_t offset,
-                                              nsIOutputStream **outputStream) {
-  NS_ENSURE_ARG_POINTER(outputStream);
-  *outputStream = nullptr;
-
-  if (!mBinding) return NS_ERROR_NOT_AVAILABLE;
-
-  NS_ASSERTION(!mOutputStreamIsOpen, "already have an output stream open");
-  NS_ASSERTION(mInStreamCount == 0, "we already have input streams open");
-  if (mOutputStreamIsOpen || mInStreamCount) return NS_ERROR_NOT_AVAILABLE;
-
-  mStreamEnd = mBinding->mCacheEntry->DataSize();
-
-  // Inits file or buffer and truncate at the desired offset
-  nsresult rv = SeekAndTruncate(offset);
-  if (NS_FAILED(rv)) return rv;
-
-  mOutputStreamIsOpen = true;
-  NS_ADDREF(*outputStream = this);
-  return NS_OK;
-}
-
-nsresult nsDiskCacheStreamIO::ClearBinding() {
-  nsresult rv = NS_OK;
-  if (mBinding && mOutputStreamIsOpen) rv = CloseOutputStream();
-  mBinding = nullptr;
-  return rv;
-}
-
-NS_IMETHODIMP
-nsDiskCacheStreamIO::Close() {
-  if (!mOutputStreamIsOpen) return NS_OK;
-
-  // grab service lock
-  nsCacheServiceAutoLock lock;
-
-  if (!mBinding) {  // if we're severed, just clear member variables
-    mOutputStreamIsOpen = false;
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-
-  nsresult rv = CloseOutputStream();
-  if (NS_FAILED(rv)) NS_WARNING("CloseOutputStream() failed");
-
-  return rv;
-}
-
-nsresult nsDiskCacheStreamIO::CloseOutputStream() {
-  NS_ASSERTION(mBinding, "oops");
-
-  CACHE_LOG_DEBUG(("CACHE: CloseOutputStream [%x doomed=%u]\n",
-                   mBinding->mRecord.HashNumber(), mBinding->mDoomed));
-
-  // Mark outputstream as closed, even if saving the stream fails
-  mOutputStreamIsOpen = false;
-
-  // When writing to a file, just close the file
-  if (mFD) {
-    (void)PR_Close(mFD);
-    mFD = nullptr;
-    return NS_OK;
-  }
-
-  // write data to cache blocks, or flush mBuffer to file
-  NS_ASSERTION(mStreamEnd <= kMaxBufferSize, "stream is bigger than buffer");
-
-  nsDiskCacheMap *cacheMap = mDevice->CacheMap();  // get map reference
-  nsDiskCacheRecord *record = &mBinding->mRecord;
-  nsresult rv = NS_OK;
-
-  // delete existing storage
-  if (record->DataLocationInitialized()) {
-    rv = cacheMap->DeleteStorage(record, nsDiskCache::kData);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // Only call UpdateRecord when there is no data to write,
-    // because WriteDataCacheBlocks / FlushBufferToFile calls it.
-    if ((mStreamEnd == 0) && (!mBinding->mDoomed)) {
-      rv = cacheMap->UpdateRecord(record);
-      if (NS_FAILED(rv)) {
-        NS_WARNING("cacheMap->UpdateRecord() failed.");
-        return rv;  // XXX doom cache entry
-      }
-    }
-  }
-
-  if (mStreamEnd == 0) return NS_OK;  // nothing to write
-
-  // try to write to the cache blocks
-  rv = cacheMap->WriteDataCacheBlocks(mBinding, mBuffer, mStreamEnd);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("WriteDataCacheBlocks() failed.");
-
-    // failed to store in cacheblocks, save as separate file
-    rv = FlushBufferToFile();  // initializes DataFileLocation() if necessary
-    if (mFD) {
-      UpdateFileSize();
-      (void)PR_Close(mFD);
-      mFD = nullptr;
-    } else
-      NS_WARNING("no file descriptor");
-  }
-
-  return rv;
-}
-
-// assumptions:
-//      only one thread writing at a time
-//      never have both output and input streams open
-//      OnDataSizeChanged() will have already been called to update
-//      entry->DataSize()
-
-NS_IMETHODIMP
-nsDiskCacheStreamIO::Write(const char *buffer, uint32_t count,
-                           uint32_t *bytesWritten) {
-  NS_ENSURE_ARG_POINTER(buffer);
-  NS_ENSURE_ARG_POINTER(bytesWritten);
-  if (!mOutputStreamIsOpen) return NS_BASE_STREAM_CLOSED;
-
-  *bytesWritten = 0;  // always initialize to zero in case of errors
-
-  NS_ASSERTION(count, "Write called with count of zero");
-  if (count == 0) {
-    return NS_OK;  // nothing to write
-  }
-
-  // grab service lock
-  nsCacheServiceAutoLock lock;
-  if (!mBinding) return NS_ERROR_NOT_AVAILABLE;
-
-  if (mInStreamCount) {
-    // we have open input streams already
-    // this is an error until we support overlapped I/O
-    NS_WARNING("Attempting to write to cache entry with open input streams.\n");
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-
-  // Not writing to file, and it will fit in the cachedatablocks?
-  if (!mFD && (mStreamEnd + count <= kMaxBufferSize)) {
-    // We have more data than the current buffer size?
-    if ((mStreamEnd + count > mBufSize) && (mBufSize < kMaxBufferSize)) {
-      // Increase buffer to the maximum size.
-      mBuffer = (char *)moz_xrealloc(mBuffer, kMaxBufferSize);
-      mBufSize = kMaxBufferSize;
-    }
-
-    // Store in the buffer but only if it fits
-    if (mStreamEnd + count <= mBufSize) {
-      memcpy(mBuffer + mStreamEnd, buffer, count);
-      mStreamEnd += count;
-      *bytesWritten = count;
-      return NS_OK;
-    }
-  }
-
-  // There are more bytes than fit in the buffer/cacheblocks, switch to file
-  if (!mFD) {
-    // Opens a cache file and write the buffer to it
-    nsresult rv = FlushBufferToFile();
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-  // Write directly to the file
-  if (PR_Write(mFD, buffer, count) != (int32_t)count) {
-    NS_WARNING("failed to write all data");
-    return NS_ERROR_UNEXPECTED;  // NS_ErrorAccordingToNSPR()
-  }
-  mStreamEnd += count;
-  *bytesWritten = count;
-
-  UpdateFileSize();
-  NS_ASSERTION(mBinding->mCacheEntry->DataSize() == mStreamEnd, "bad stream");
-
-  return NS_OK;
-}
-
-void nsDiskCacheStreamIO::UpdateFileSize() {
-  NS_ASSERTION(
-      mFD, "nsDiskCacheStreamIO::UpdateFileSize should not have been called");
-
-  nsDiskCacheRecord *record = &mBinding->mRecord;
-  const uint32_t oldSizeK = record->DataFileSize();
-  uint32_t newSizeK = (mStreamEnd + 0x03FF) >> 10;
-
-  // make sure the size won't overflow (bug #651100)
-  if (newSizeK > kMaxDataSizeK) newSizeK = kMaxDataSizeK;
-
-  if (newSizeK == oldSizeK) return;
-
-  record->SetDataFileSize(newSizeK);
-
-  // update cache size totals
-  nsDiskCacheMap *cacheMap = mDevice->CacheMap();
-  cacheMap->DecrementTotalSize(oldSizeK);  // decrement old size
-  cacheMap->IncrementTotalSize(newSizeK);  // increment new size
-
-  if (!mBinding->mDoomed) {
-    nsresult rv = cacheMap->UpdateRecord(record);
-    if (NS_FAILED(rv)) {
-      NS_WARNING("cacheMap->UpdateRecord() failed.");
-      // XXX doom cache entry?
-    }
-  }
-}
-
-nsresult nsDiskCacheStreamIO::OpenCacheFile(int flags, PRFileDesc **fd) {
-  NS_ENSURE_ARG_POINTER(fd);
-
-  CACHE_LOG_DEBUG(("nsDiskCacheStreamIO::OpenCacheFile"));
-
-  nsresult rv;
-  nsDiskCacheMap *cacheMap = mDevice->CacheMap();
-  nsCOMPtr<nsIFile> localFile;
-
-  rv = cacheMap->GetLocalFileForDiskCacheRecord(
-      &mBinding->mRecord, nsDiskCache::kData, !!(flags & PR_CREATE_FILE),
-      getter_AddRefs(localFile));
-  if (NS_FAILED(rv)) return rv;
-
-  // create PRFileDesc for input stream - the 00600 is just for consistency
-  return localFile->OpenNSPRFileDesc(flags, 00600, fd);
-}
-
-nsresult nsDiskCacheStreamIO::ReadCacheBlocks(uint32_t bufferSize) {
-  NS_ASSERTION(mStreamEnd == mBinding->mCacheEntry->DataSize(), "bad stream");
-  NS_ASSERTION(bufferSize <= kMaxBufferSize, "bufferSize too large for buffer");
-  NS_ASSERTION(mStreamEnd <= bufferSize, "data too large for buffer");
-
-  nsDiskCacheRecord *record = &mBinding->mRecord;
-  if (!record->DataLocationInitialized()) return NS_OK;
-
-  NS_ASSERTION(record->DataFile() != kSeparateFile,
-               "attempt to read cache blocks on separate file");
-
-  if (!mBuffer) {
-    mBuffer = (char *)moz_xmalloc(bufferSize);
-    mBufSize = bufferSize;
-  }
-
-  // read data stored in cache block files
-  nsDiskCacheMap *map = mDevice->CacheMap();  // get map reference
-  return map->ReadDataCacheBlocks(mBinding, mBuffer, mStreamEnd);
-}
-
-nsresult nsDiskCacheStreamIO::FlushBufferToFile() {
-  nsresult rv;
-  nsDiskCacheRecord *record = &mBinding->mRecord;
-
-  if (!mFD) {
-    if (record->DataLocationInitialized() && (record->DataFile() > 0)) {
-      // remove cache block storage
-      nsDiskCacheMap *cacheMap = mDevice->CacheMap();
-      rv = cacheMap->DeleteStorage(record, nsDiskCache::kData);
-      if (NS_FAILED(rv)) return rv;
-    }
-    record->SetDataFileGeneration(mBinding->mGeneration);
-
-    // allocate file
-    rv = OpenCacheFile(PR_RDWR | PR_CREATE_FILE, &mFD);
-    if (NS_FAILED(rv)) return rv;
-
-    int64_t dataSize = mBinding->mCacheEntry->PredictedDataSize();
-    if (dataSize != -1)
-      mozilla::fallocate(mFD, std::min<int64_t>(dataSize, kPreallocateLimit));
-  }
-
-  // write buffer to the file when there is data in it
-  if (mStreamEnd > 0) {
-    if (!mBuffer) {
-      MOZ_CRASH("Fix me!");
-    }
-    if (PR_Write(mFD, mBuffer, mStreamEnd) != (int32_t)mStreamEnd) {
-      NS_WARNING("failed to flush all data");
-      return NS_ERROR_UNEXPECTED;  // NS_ErrorAccordingToNSPR()
-    }
-  }
-
-  // buffer is no longer valid
-  DeleteBuffer();
-
-  return NS_OK;
-}
-
-void nsDiskCacheStreamIO::DeleteBuffer() {
-  if (mBuffer) {
-    free(mBuffer);
-    mBuffer = nullptr;
-    mBufSize = 0;
-  }
-}
-
-size_t nsDiskCacheStreamIO::SizeOfIncludingThis(
-    mozilla::MallocSizeOf aMallocSizeOf) {
-  size_t usage = aMallocSizeOf(this);
-
-  usage += aMallocSizeOf(mFD);
-  usage += aMallocSizeOf(mBuffer);
-
-  return usage;
-}
-
-nsresult nsDiskCacheStreamIO::SeekAndTruncate(uint32_t offset) {
-  if (!mBinding) return NS_ERROR_NOT_AVAILABLE;
-
-  if (uint32_t(offset) > mStreamEnd) return NS_ERROR_FAILURE;
-
-  // Set the current end to the desired offset
-  mStreamEnd = offset;
-
-  // Currently stored in file?
-  if (mBinding->mRecord.DataLocationInitialized() &&
-      (mBinding->mRecord.DataFile() == 0)) {
-    if (!mFD) {
-      // we need an mFD, we better open it now
-      nsresult rv = OpenCacheFile(PR_RDWR | PR_CREATE_FILE, &mFD);
-      if (NS_FAILED(rv)) return rv;
-    }
-    if (offset) {
-      if (PR_Seek(mFD, offset, PR_SEEK_SET) == -1)
-        return NS_ErrorAccordingToNSPR();
-    }
-    nsDiskCache::Truncate(mFD, offset);
-    UpdateFileSize();
-
-    // When we starting at zero again, close file and start with buffer.
-    // If offset is non-zero (and within buffer) an option would be
-    // to read the file into the buffer, but chance is high that it is
-    // rewritten to the file anyway.
-    if (offset == 0) {
-      // close file descriptor
-      (void)PR_Close(mFD);
-      mFD = nullptr;
-    }
-    return NS_OK;
-  }
-
-  // read data into mBuffer if not read yet.
-  if (offset && !mBuffer) {
-    nsresult rv = ReadCacheBlocks(kMaxBufferSize);
-    if (NS_FAILED(rv)) return rv;
-  }
-
-  // stream buffer sanity check
-  NS_ASSERTION(mStreamEnd <= kMaxBufferSize, "bad stream");
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDiskCacheStreamIO::Flush() {
-  if (!mOutputStreamIsOpen) return NS_BASE_STREAM_CLOSED;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDiskCacheStreamIO::WriteFrom(nsIInputStream *inStream, uint32_t count,
-                               uint32_t *bytesWritten) {
-  MOZ_ASSERT_UNREACHABLE("WriteFrom");
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsDiskCacheStreamIO::WriteSegments(nsReadSegmentFun reader, void *closure,
-                                   uint32_t count, uint32_t *bytesWritten) {
-  MOZ_ASSERT_UNREACHABLE("WriteSegments");
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsDiskCacheStreamIO::IsNonBlocking(bool *nonBlocking) {
-  *nonBlocking = false;
-  return NS_OK;
-}
deleted file mode 100644
--- a/netwerk/cache/nsDiskCacheStreams.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _nsDiskCacheStreams_h_
-#define _nsDiskCacheStreams_h_
-
-#include "mozilla/MemoryReporting.h"
-#include "nsDiskCacheBinding.h"
-
-#include "nsCache.h"
-
-#include "nsIInputStream.h"
-#include "nsIOutputStream.h"
-
-#include "mozilla/Atomics.h"
-
-class nsDiskCacheDevice;
-
-class nsDiskCacheStreamIO : public nsIOutputStream {
- public:
-  explicit nsDiskCacheStreamIO(nsDiskCacheBinding* binding);
-
-  NS_DECL_THREADSAFE_ISUPPORTS
-  NS_DECL_NSIOUTPUTSTREAM
-
-  nsresult GetInputStream(uint32_t offset, nsIInputStream** inputStream);
-  nsresult GetOutputStream(uint32_t offset, nsIOutputStream** outputStream);
-
-  nsresult ClearBinding();
-
-  void IncrementInputStreamCount() { mInStreamCount++; }
-  void DecrementInputStreamCount() {
-    mInStreamCount--;
-    NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative");
-  }
-
-  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
-
-  // GCC 2.95.2 requires this to be defined, although we never call it.
-  // and OS/2 requires that it not be private
-  nsDiskCacheStreamIO()
-      : mBinding(nullptr),
-        mDevice(nullptr),
-        mFD(nullptr),
-        mStreamEnd(0),
-        mBufSize(0),
-        mBuffer(nullptr),
-        mOutputStreamIsOpen(false) {
-    MOZ_ASSERT_UNREACHABLE("oops");
-  }
-
- private:
-  virtual ~nsDiskCacheStreamIO();
-
-  nsresult OpenCacheFile(int flags, PRFileDesc** fd);
-  nsresult ReadCacheBlocks(uint32_t bufferSize);
-  nsresult FlushBufferToFile();
-  void UpdateFileSize();
-  void DeleteBuffer();
-  nsresult CloseOutputStream();
-  nsresult SeekAndTruncate(uint32_t offset);
-
-  nsDiskCacheBinding* mBinding;  // not an owning reference
-  nsDiskCacheDevice* mDevice;
-  mozilla::Atomic<int32_t> mInStreamCount;
-  PRFileDesc* mFD;
-
-  uint32_t mStreamEnd;  // current size of data
-  uint32_t mBufSize;    // current end of buffer
-  char* mBuffer;
-  bool mOutputStreamIsOpen;
-};
-
-#endif  // _nsDiskCacheStreams_h_
deleted file mode 100644
--- a/netwerk/cache/nsMemoryCacheDevice.cpp
+++ /dev/null
@@ -1,519 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsCache.h"
-#include "nsMemoryCacheDevice.h"
-#include "nsCacheService.h"
-#include "nsICacheService.h"
-#include "nsICacheVisitor.h"
-#include "nsIStorageStream.h"
-#include "nsCRT.h"
-#include "nsReadableUtils.h"
-#include "mozilla/IntegerPrintfMacros.h"
-#include "mozilla/MathAlgorithms.h"
-#include "mozilla/Telemetry.h"
-#include <algorithm>
-
-// The memory cache implements the "LRU-SP" caching algorithm
-// described in "LRU-SP: A Size-Adjusted and Popularity-Aware LRU Replacement
-// Algorithm for Web Caching" by Kai Cheng and Yahiko Kambayashi.
-
-// We keep kQueueCount LRU queues, which should be about ceil(log2(mHardLimit))
-// The queues hold exponentially increasing ranges of floor(log2((size/nref)))
-// values for entries.
-// Entries larger than 2^(kQueueCount-1) go in the last queue.
-// Entries with no expiration go in the first queue.
-
-const char* gMemoryDeviceID = "memory";
-using namespace mozilla;
-
-nsMemoryCacheDevice::nsMemoryCacheDevice()
-    : mInitialized(false),
-      mHardLimit(4 * 1024 * 1024),        // default, if no pref
-      mSoftLimit((mHardLimit * 9) / 10),  // default, if no pref
-      mTotalSize(0),
-      mInactiveSize(0),
-      mEntryCount(0),
-      mMaxEntryCount(0),
-      mMaxEntrySize(-1)  // -1 means "no limit"
-{
-  for (auto& eviction : mEvictionList) PR_INIT_CLIST(&eviction);
-}
-
-nsMemoryCacheDevice::~nsMemoryCacheDevice() { Shutdown(); }
-
-nsresult nsMemoryCacheDevice::Init() {
-  if (mInitialized) return NS_ERROR_ALREADY_INITIALIZED;
-
-  mMemCacheEntries.Init();
-  mInitialized = true;
-  return NS_OK;
-}
-
-nsresult nsMemoryCacheDevice::Shutdown() {
-  NS_ASSERTION(mInitialized, "### attempting shutdown while not initialized");
-  NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
-
-  mMemCacheEntries.Shutdown();
-
-  // evict all entries
-  nsCacheEntry *entry, *next;
-
-  for (int i = kQueueCount - 1; i >= 0; --i) {
-    entry = (nsCacheEntry*)PR_LIST_HEAD(&mEvictionList[i]);
-    while (entry != &mEvictionList[i]) {
-      NS_ASSERTION(!entry->IsInUse(), "### shutting down with active entries");
-      next = (nsCacheEntry*)PR_NEXT_LINK(entry);
-      PR_REMOVE_AND_INIT_LINK(entry);
-
-      // update statistics
-      int32_t memoryRecovered = (int32_t)entry->DataSize();
-      mTotalSize -= memoryRecovered;
-      mInactiveSize -= memoryRecovered;
-      --mEntryCount;
-
-      delete entry;
-      entry = next;
-    }
-  }
-
-  /*
-   * we're not factoring in changes to meta data yet...
-   *  NS_ASSERTION(mTotalSize == 0, "### mem cache leaking entries?");
-   */
-  NS_ASSERTION(mInactiveSize == 0, "### mem cache leaking entries?");
-  NS_ASSERTION(mEntryCount == 0, "### mem cache leaking entries?");
-
-  mInitialized = false;
-
-  return NS_OK;
-}
-
-const char* nsMemoryCacheDevice::GetDeviceID() { return gMemoryDeviceID; }
-
-nsCacheEntry* nsMemoryCacheDevice::FindEntry(nsCString* key, bool* collision) {
-  mozilla::Telemetry::AutoTimer<mozilla::Telemetry::CACHE_MEMORY_SEARCH_2>
-      timer;
-  nsCacheEntry* entry = mMemCacheEntries.GetEntry(key);
-  if (!entry) return nullptr;
-
-  // move entry to the tail of an eviction list
-  PR_REMOVE_AND_INIT_LINK(entry);
-  PR_APPEND_LINK(entry, &mEvictionList[EvictionList(entry, 0)]);
-
-  mInactiveSize -= entry->DataSize();
-
-  return entry;
-}
-
-nsresult nsMemoryCacheDevice::DeactivateEntry(nsCacheEntry* entry) {
-  CACHE_LOG_DEBUG(
-      ("nsMemoryCacheDevice::DeactivateEntry for entry 0x%p\n", entry));
-  if (entry->IsDoomed()) {
-#ifdef DEBUG
-    // XXX verify we've removed it from mMemCacheEntries & eviction list
-#endif
-    delete entry;
-    CACHE_LOG_DEBUG(("deleted doomed entry 0x%p\n", entry));
-    return NS_OK;
-  }
-
-#ifdef DEBUG
-  nsCacheEntry* ourEntry = mMemCacheEntries.GetEntry(entry->Key());
-  NS_ASSERTION(ourEntry, "DeactivateEntry called for an entry we don't have!");
-  NS_ASSERTION(entry == ourEntry, "entry doesn't match ourEntry");
-  if (ourEntry != entry) return NS_ERROR_INVALID_POINTER;
-#endif
-
-  mInactiveSize += entry->DataSize();
-  EvictEntriesIfNecessary();
-
-  return NS_OK;
-}
-
-nsresult nsMemoryCacheDevice::BindEntry(nsCacheEntry* entry) {
-  if (!entry->IsDoomed()) {
-    NS_ASSERTION(PR_CLIST_IS_EMPTY(entry), "entry is already on a list!");
-
-    // append entry to the eviction list
-    PR_APPEND_LINK(entry, &mEvictionList[EvictionList(entry, 0)]);
-
-    // add entry to hashtable of mem cache entries
-    nsresult rv = mMemCacheEntries.AddEntry(entry);
-    if (NS_FAILED(rv)) {
-      PR_REMOVE_AND_INIT_LINK(entry);
-      return rv;
-    }
-
-    // add size of entry to memory totals
-    ++mEntryCount;
-    if (mMaxEntryCount < mEntryCount) mMaxEntryCount = mEntryCount;
-
-    mTotalSize += entry->DataSize();
-    EvictEntriesIfNecessary();
-  }
-
-  return NS_OK;
-}
-
-void nsMemoryCacheDevice::DoomEntry(nsCacheEntry* entry) {
-#ifdef DEBUG
-  // debug code to verify we have entry
-  nsCacheEntry* hashEntry = mMemCacheEntries.GetEntry(entry->Key());
-  if (!hashEntry)
-    NS_WARNING("no entry for key");
-  else if (entry != hashEntry)
-    NS_WARNING("entry != hashEntry");
-#endif
-  CACHE_LOG_DEBUG(("Dooming entry 0x%p in memory cache\n", entry));
-  EvictEntry(entry, DO_NOT_DELETE_ENTRY);
-}
-
-nsresult nsMemoryCacheDevice::OpenInputStreamForEntry(nsCacheEntry* entry,
-                                                      nsCacheAccessMode mode,
-                                                      uint32_t offset,
-                                                      nsIInputStream** result) {
-  NS_ENSURE_ARG_POINTER(entry);
-  NS_ENSURE_ARG_POINTER(result);
-
-  nsCOMPtr<nsIStorageStream> storage;
-  nsresult rv;
-
-  nsISupports* data = entry->Data();
-  if (data) {
-    storage = do_QueryInterface(data, &rv);
-    if (NS_FAILED(rv)) return rv;
-  } else {
-    rv = NS_NewStorageStream(4096, uint32_t(-1), getter_AddRefs(storage));
-    if (NS_FAILED(rv)) return rv;
-    entry->SetData(storage);
-  }
-
-  return storage->NewInputStream(offset, result);
-}
-
-nsresult nsMemoryCacheDevice::OpenOutputStreamForEntry(
-    nsCacheEntry* entry, nsCacheAccessMode mode, uint32_t offset,
-    nsIOutputStream** result) {
-  NS_ENSURE_ARG_POINTER(entry);
-  NS_ENSURE_ARG_POINTER(result);
-
-  nsCOMPtr<nsIStorageStream> storage;
-  nsresult rv;
-
-  nsISupports* data = entry->Data();
-  if (data) {
-    storage = do_QueryInterface(data, &rv);
-    if (NS_FAILED(rv)) return rv;
-  } else {
-    rv = NS_NewStorageStream(4096, uint32_t(-1), getter_AddRefs(storage));
-    if (NS_FAILED(rv)) return rv;
-    entry->SetData(storage);
-  }
-
-  return storage->GetOutputStream(offset, result);
-}
-
-nsresult nsMemoryCacheDevice::GetFileForEntry(nsCacheEntry* entry,
-                                              nsIFile** result) {
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-bool nsMemoryCacheDevice::EntryIsTooBig(int64_t entrySize) {
-  CACHE_LOG_DEBUG(
-      ("nsMemoryCacheDevice::EntryIsTooBig "
-       "[size=%" PRId64 " max=%d soft=%d]\n",
-       entrySize, mMaxEntrySize, mSoftLimit));
-  if (mMaxEntrySize == -1) return entrySize > mSoftLimit;
-
-  return (entrySize > mSoftLimit || entrySize > mMaxEntrySize);
-}
-
-size_t nsMemoryCacheDevice::TotalSize() { return mTotalSize; }
-
-nsresult nsMemoryCacheDevice::OnDataSizeChange(nsCacheEntry* entry,
-                                               int32_t deltaSize) {
-  if (entry->IsStreamData()) {
-    // we have the right to refuse or pre-evict
-    uint32_t newSize = entry->DataSize() + deltaSize;
-    if (EntryIsTooBig(newSize)) {
-#ifdef DEBUG
-      nsresult rv =
-#endif
-          nsCacheService::DoomEntry(entry);
-      NS_ASSERTION(NS_SUCCEEDED(rv), "DoomEntry() failed.");
-      return NS_ERROR_ABORT;
-    }
-  }
-
-  // adjust our totals
-  mTotalSize += deltaSize;
-
-  if (!entry->IsDoomed()) {
-    // move entry to the tail of the appropriate eviction list
-    PR_REMOVE_AND_INIT_LINK(entry);
-    PR_APPEND_LINK(entry, &mEvictionList[EvictionList(entry, deltaSize)]);
-  }
-
-  EvictEntriesIfNecessary();
-  return NS_OK;
-}
-
-void nsMemoryCacheDevice::AdjustMemoryLimits(int32_t softLimit,
-                                             int32_t hardLimit) {
-  mSoftLimit = softLimit;
-  mHardLimit = hardLimit;
-
-  // First, evict entries that won't fit into the new cache size.
-  EvictEntriesIfNecessary();
-}
-
-void nsMemoryCacheDevice::EvictEntry(nsCacheEntry* entry, bool deleteEntry) {
-  CACHE_LOG_DEBUG(("Evicting entry 0x%p from memory cache, deleting: %d\n",
-                   entry, deleteEntry));
-  // remove entry from our hashtable
-  mMemCacheEntries.RemoveEntry(entry);
-
-  // remove entry from the eviction list
-  PR_REMOVE_AND_INIT_LINK(entry);
-
-  // update statistics
-  int32_t memoryRecovered = (int32_t)entry->DataSize();
-  mTotalSize -= memoryRecovered;
-  if (!entry->IsDoomed()) mInactiveSize -= memoryRecovered;
-  --mEntryCount;
-
-  if (deleteEntry) delete entry;
-}
-
-void nsMemoryCacheDevice::EvictEntriesIfNecessary(void) {
-  nsCacheEntry* entry;
-  nsCacheEntry* maxEntry;
-  CACHE_LOG_DEBUG(
-      ("EvictEntriesIfNecessary.  mTotalSize: %d, mHardLimit: %d,"
-       "mInactiveSize: %d, mSoftLimit: %d\n",
-       mTotalSize, mHardLimit, mInactiveSize, mSoftLimit));
-
-  if ((mTotalSize < mHardLimit) && (mInactiveSize < mSoftLimit)) return;
-
-  uint32_t now = SecondsFromPRTime(PR_Now());
-  uint64_t entryCost = 0;
-  uint64_t maxCost = 0;
-  do {
-    // LRU-SP eviction selection: Check the head of each segment (each
-    // eviction list, kept in LRU order) and select the maximal-cost
-    // entry for eviction. Cost is time-since-accessed * size / nref.
-    maxEntry = nullptr;
-    for (int i = kQueueCount - 1; i >= 0; --i) {
-      entry = (nsCacheEntry*)PR_LIST_HEAD(&mEvictionList[i]);
-
-      // If the head of a list is in use, check the next available entry
-      while ((entry != &mEvictionList[i]) && (entry->IsInUse())) {
-        entry = (nsCacheEntry*)PR_NEXT_LINK(entry);
-      }
-
-      if (entry != &mEvictionList[i]) {
-        entryCost = (uint64_t)(now - entry->LastFetched()) * entry->DataSize() /
-                    std::max(1, entry->FetchCount());
-        if (!maxEntry || (entryCost > maxCost)) {
-          maxEntry = entry;
-          maxCost = entryCost;
-        }
-      }
-    }
-    if (maxEntry) {
-      EvictEntry(maxEntry, DELETE_ENTRY);
-    } else {
-      break;
-    }
-  } while ((mTotalSize >= mHardLimit) || (mInactiveSize >= mSoftLimit));
-}
-
-int nsMemoryCacheDevice::EvictionList(nsCacheEntry* entry, int32_t deltaSize) {
-  // favor items which never expire by putting them in the lowest-index queue
-  if (entry->ExpirationTime() == nsICache::NO_EXPIRATION_TIME) return 0;
-
-  // compute which eviction queue this entry should go into,
-  // based on floor(log2(size/nref))
-  int32_t size = deltaSize + (int32_t)entry->DataSize();
-  int32_t fetchCount = std::max(1, entry->FetchCount());
-
-  return std::min((int)mozilla::FloorLog2(size / fetchCount), kQueueCount - 1);
-}
-
-nsresult nsMemoryCacheDevice::Visit(nsICacheVisitor* visitor) {
-  nsMemoryCacheDeviceInfo* deviceInfo = new nsMemoryCacheDeviceInfo(this);
-  nsCOMPtr<nsICacheDeviceInfo> deviceRef(deviceInfo);
-  if (!deviceInfo) return NS_ERROR_OUT_OF_MEMORY;
-
-  bool keepGoing;
-  nsresult rv = visitor->VisitDevice(gMemoryDeviceID, deviceInfo, &keepGoing);
-  if (NS_FAILED(rv)) return rv;
-
-  if (!keepGoing) return NS_OK;
-
-  nsCacheEntry* entry;
-  nsCOMPtr<nsICacheEntryInfo> entryRef;
-
-  for (int i = kQueueCount - 1; i >= 0; --i) {
-    entry = (nsCacheEntry*)PR_LIST_HEAD(&mEvictionList[i]);
-    while (entry != &mEvictionList[i]) {
-      nsCacheEntryInfo* entryInfo = new nsCacheEntryInfo(entry);
-      if (!entryInfo) return NS_ERROR_OUT_OF_MEMORY;
-      entryRef = entryInfo;
-
-      rv = visitor->VisitEntry(gMemoryDeviceID, entryInfo, &keepGoing);
-      entryInfo->DetachEntry();
-      if (NS_FAILED(rv)) return rv;
-      if (!keepGoing) break;
-
-      entry = (nsCacheEntry*)PR_NEXT_LINK(entry);
-    }
-  }
-  return NS_OK;
-}
-
-static bool IsEntryPrivate(nsCacheEntry* entry, void* args) {
-  return entry->IsPrivate();
-}
-
-struct ClientIDArgs {
-  const char* clientID;
-  uint32_t prefixLength;
-};
-
-static bool EntryMatchesClientID(nsCacheEntry* entry, void* args) {
-  const char* clientID = static_cast<ClientIDArgs*>(args)->clientID;
-  uint32_t prefixLength = static_cast<ClientIDArgs*>(args)->prefixLength;
-  const char* key = entry->Key()->get();
-  return !clientID || strncmp(clientID, key, prefixLength) == 0;
-}
-
-nsresult nsMemoryCacheDevice::DoEvictEntries(
-    bool (*matchFn)(nsCacheEntry* entry, void* args), void* args) {
-  nsCacheEntry* entry;
-
-  for (int i = kQueueCount - 1; i >= 0; --i) {
-    PRCList* elem = PR_LIST_HEAD(&mEvictionList[i]);
-    while (elem != &mEvictionList[i]) {
-      entry = (nsCacheEntry*)elem;
-      elem = PR_NEXT_LINK(elem);
-
-      if (!matchFn(entry, args)) continue;
-
-      if (entry->IsInUse()) {
-        nsresult rv = nsCacheService::DoomEntry(entry);
-        if (NS_FAILED(rv)) {
-          CACHE_LOG_WARNING(("memCache->DoEvictEntries() aborted: rv =%" PRIx32,
-                             static_cast<uint32_t>(rv)));
-          return rv;
-        }
-      } else {
-        EvictEntry(entry, DELETE_ENTRY);
-      }
-    }
-  }
-
-  return NS_OK;
-}
-
-nsresult nsMemoryCacheDevice::EvictEntries(const char* clientID) {
-  ClientIDArgs args = {clientID, clientID ? uint32_t(strlen(clientID)) : 0};
-  return DoEvictEntries(&EntryMatchesClientID, &args);
-}
-
-nsresult nsMemoryCacheDevice::EvictPrivateEntries() {
-  return DoEvictEntries(&IsEntryPrivate, nullptr);
-}
-
-// WARNING: SetCapacity can get called before Init()
-void nsMemoryCacheDevice::SetCapacity(int32_t capacity) {
-  int32_t hardLimit = capacity * 1024;  // convert k into bytes
-  int32_t softLimit = (hardLimit * 9) / 10;
-  AdjustMemoryLimits(softLimit, hardLimit);
-}
-
-void nsMemoryCacheDevice::SetMaxEntrySize(int32_t maxSizeInKilobytes) {
-  // Internal unit is bytes. Changing this only takes effect *after* the
-  // change and has no consequences for existing cache-entries
-  if (maxSizeInKilobytes >= 0)
-    mMaxEntrySize = maxSizeInKilobytes * 1024;
-  else
-    mMaxEntrySize = -1;
-}
-
-#ifdef DEBUG
-void nsMemoryCacheDevice::CheckEntryCount() {
-  if (!mInitialized) return;
-
-  int32_t evictionListCount = 0;
-  for (auto& eviction : mEvictionList) {
-    PRCList* elem = PR_LIST_HEAD(&eviction);
-    while (elem != &eviction) {
-      elem = PR_NEXT_LINK(elem);
-      ++evictionListCount;
-    }
-  }
-  NS_ASSERTION(mEntryCount == evictionListCount, "### mem cache badness");
-
-  int32_t entryCount = 0;
-  for (auto iter = mMemCacheEntries.Iter(); !iter.Done(); iter.Next()) {
-    ++entryCount;
-  }
-  NS_ASSERTION(mEntryCount == entryCount, "### mem cache badness");
-}
-#endif
-
-/******************************************************************************
- * nsMemoryCacheDeviceInfo - for implementing about:cache
- *****************************************************************************/
-
-NS_IMPL_ISUPPORTS(nsMemoryCacheDeviceInfo, nsICacheDeviceInfo)
-
-NS_IMETHODIMP
-nsMemoryCacheDeviceInfo::GetDescription(nsACString& aDescription) {
-  aDescription.AssignLiteral("Memory cache device");
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsMemoryCacheDeviceInfo::GetUsageReport(nsACString& aUsageReport) {
-  nsCString buffer;
-
-  buffer.AssignLiteral(
-      "  <tr>\n"
-      "    <th>Inactive storage:</th>\n"
-      "    <td>");
-  buffer.AppendInt(mDevice->mInactiveSize / 1024);
-  buffer.AppendLiteral(
-      " KiB</td>\n"
-      "  </tr>\n");
-
-  aUsageReport.Assign(buffer);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsMemoryCacheDeviceInfo::GetEntryCount(uint32_t* result) {
-  NS_ENSURE_ARG_POINTER(result);
-  // XXX compare calculated count vs. mEntryCount
-  *result = (uint32_t)mDevice->mEntryCount;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsMemoryCacheDeviceInfo::GetTotalSize(uint32_t* result) {
-  NS_ENSURE_ARG_POINTER(result);
-  *result = (uint32_t)mDevice->mTotalSize;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsMemoryCacheDeviceInfo::GetMaximumSize(uint32_t* result) {
-  NS_ENSURE_ARG_POINTER(result);
-  *result = (uint32_t)mDevice->mHardLimit;
-  return NS_OK;
-}
deleted file mode 100644
--- a/netwerk/cache/nsMemoryCacheDevice.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _nsMemoryCacheDevice_h_
-#define _nsMemoryCacheDevice_h_
-
-#include "nsCacheDevice.h"
-#include "PLDHashTable.h"
-#include "nsCacheEntry.h"
-
-class nsMemoryCacheDeviceInfo;
-
-/******************************************************************************
- * nsMemoryCacheDevice
- ******************************************************************************/
-class nsMemoryCacheDevice : public nsCacheDevice {
- public:
-  nsMemoryCacheDevice();
-  virtual ~nsMemoryCacheDevice();
-
-  virtual nsresult Init() override;
-  virtual nsresult Shutdown() override;
-
-  virtual const char* GetDeviceID(void) override;
-
-  virtual nsresult BindEntry(nsCacheEntry* entry) override;
-  virtual nsCacheEntry* FindEntry(nsCString* key, bool* collision) override;
-  virtual void DoomEntry(nsCacheEntry* entry) override;
-  virtual nsresult DeactivateEntry(nsCacheEntry* entry) override;
-
-  virtual nsresult OpenInputStreamForEntry(nsCacheEntry* entry,
-                                           nsCacheAccessMode mode,
-                                           uint32_t offset,
-                                           nsIInputStream** result) override;
-
-  virtual nsresult OpenOutputStreamForEntry(nsCacheEntry* entry,
-                                            nsCacheAccessMode mode,
-                                            uint32_t offset,
-                                            nsIOutputStream** result) override;
-
-  virtual nsresult GetFileForEntry(nsCacheEntry* entry,
-                                   nsIFile** result) override;
-
-  virtual nsresult OnDataSizeChange(nsCacheEntry* entry,
-                                    int32_t deltaSize) override;
-
-  virtual nsresult Visit(nsICacheVisitor* visitor) override;
-
-  virtual nsresult EvictEntries(const char* clientID) override;
-  nsresult EvictPrivateEntries();
-
-  void SetCapacity(int32_t capacity);
-  void SetMaxEntrySize(int32_t maxSizeInKilobytes);
-
-  bool EntryIsTooBig(int64_t entrySize);
-
-  size_t TotalSize();
-
- private:
-  friend class nsMemoryCacheDeviceInfo;
-  enum { DELETE_ENTRY = true, DO_NOT_DELETE_ENTRY = false };
-
-  void AdjustMemoryLimits(int32_t softLimit, int32_t hardLimit);
-  void EvictEntry(nsCacheEntry* entry, bool deleteEntry);
-  void EvictEntriesIfNecessary();
-  int EvictionList(nsCacheEntry* entry, int32_t deltaSize);
-
-  typedef bool (*EvictionMatcherFn)(nsCacheEntry* entry, void* args);
-  nsresult DoEvictEntries(EvictionMatcherFn matchFn, void* args);
-
-#ifdef DEBUG
-  void CheckEntryCount();
-#endif
-  /*
-   *  Data members
-   */
-  enum {
-    kQueueCount = 24  // entries > 2^23 (8Mb) start in last queue
-  };
-
-  nsCacheEntryHashTable mMemCacheEntries;
-  bool mInitialized;
-
-  PRCList mEvictionList[kQueueCount];
-
-  int32_t mHardLimit;
-  int32_t mSoftLimit;
-
-  int32_t mTotalSize;
-  int32_t mInactiveSize;
-
-  int32_t mEntryCount;
-  int32_t mMaxEntryCount;
-  int32_t mMaxEntrySize;  // internal unit is bytes
-
-  // XXX what other stats do we want to keep?
-};
-
-/******************************************************************************
- * nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
- ******************************************************************************/
-class nsMemoryCacheDeviceInfo : public nsICacheDeviceInfo {
- public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSICACHEDEVICEINFO
-
-  explicit nsMemoryCacheDeviceInfo(nsMemoryCacheDevice* device)
-      : mDevice(device) {}
-
- private:
-  virtual ~nsMemoryCacheDeviceInfo() = default;
-  nsMemoryCacheDevice* mDevice;
-};
-
-#endif  // _nsMemoryCacheDevice_h_
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -2837,32 +2837,16 @@
   "CACHE_DEVICE_SEARCH_2": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 10000,
     "n_buckets": 50,
     "description": "Time to search cache (ms)"
   },
-  "CACHE_MEMORY_SEARCH_2": {
-    "record_in_processes": ["main", "content"],
-    "expires_in_version": "default",
-    "kind": "exponential",
-    "high": 10000,
-    "n_buckets": 50,
-    "description": "Time to search memory cache (ms)"
-  },
-  "CACHE_DISK_SEARCH_2": {
-    "record_in_processes": ["main", "content"],
-    "expires_in_version": "default",
-    "kind": "exponential",
-    "high": 10000,
-    "n_buckets": 50,
-    "description": "Time to search disk cache (ms)"
-  },
   "CACHE_OFFLINE_SEARCH_2": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 10000,
     "n_buckets": 50,
     "description": "Time to search offline cache (ms)"
   },
@@ -2894,24 +2878,16 @@
   "HTTP_CONTENT_ENCODING": {
     "record_in_processes": ["main", "content"],
     "alert_emails": ["necko@mozilla.com"],
     "expires_in_version": "never",
     "kind": "enumerated",
     "n_values": 6,
     "description": "encoding removed: 0=unknown, 1=gzip, 2=deflate, 3=brotli"
   },
-  "HTTP_DISK_CACHE_OVERHEAD": {
-    "record_in_processes": ["main", "content"],
-    "expires_in_version": "default",
-    "kind": "exponential",
-    "high": 32000000,
-    "n_buckets": 100,
-    "description": "HTTP Disk cache memory overhead (bytes)"
-  },
   "CACHE_LM_INCONSISTENT": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "never",
     "kind": "boolean",
     "description": "Cache discovered inconsistent last-modified entry"
   },
   "CACHE_SERVICE_LOCK_WAIT_2": {
     "record_in_processes": ["main", "content"],
@@ -4691,24 +4667,16 @@
   },
   "STARTUP_MEASUREMENT_ERRORS": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "default",
     "kind": "enumerated",
     "n_values": 16,
     "description": "Flags errors in startup calculation()"
   },
-  "NETWORK_DISK_CACHE_OPEN": {
-    "record_in_processes": ["main", "content"],
-    "expires_in_version": "default",
-    "kind": "exponential",
-    "high": 10000,
-    "n_buckets": 10,
-    "description": "Time spent opening disk cache (ms)"
-  },
   "NETWORK_DISK_CACHE_TRASHRENAME": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 10000,
     "n_buckets": 10,
     "description": "Time spent renaming bad Cache to Cache.Trash (ms)"
   },
--- a/toolkit/components/telemetry/histogram-whitelists.json
+++ b/toolkit/components/telemetry/histogram-whitelists.json
@@ -12,19 +12,17 @@
     "BROWSER_IS_USER_DEFAULT_ERROR",
     "BROWSER_SET_DEFAULT_ALWAYS_CHECK",
     "BROWSER_SET_DEFAULT_DIALOG_PROMPT_RAWCOUNT",
     "BROWSER_SET_DEFAULT_ERROR",
     "BROWSER_SET_DEFAULT_RESULT",
     "BR_9_2_1_SUBJECT_ALT_NAMES",
     "BR_9_2_2_SUBJECT_COMMON_NAME",
     "CACHE_DEVICE_SEARCH_2",
-    "CACHE_DISK_SEARCH_2",
     "CACHE_LM_INCONSISTENT",
-    "CACHE_MEMORY_SEARCH_2",
     "CACHE_OFFLINE_SEARCH_2",
     "CACHE_SERVICE_LOCK_WAIT_2",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_2",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSASYNCDOOMEVENT_RUN",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSBLOCKONCACHETHREADEVENT_RUN",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSCACHEENTRYDESCRIPTOR_CLOSE",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSCACHEENTRYDESCRIPTOR_DOOM",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSCACHEENTRYDESCRIPTOR_DOOMANDFAILPENDINGREQUESTS",
@@ -192,17 +190,16 @@
     "HTTPCONNMGR_TOTAL_SPECULATIVE_CONN",
     "HTTPCONNMGR_UNUSED_SPECULATIVE_CONN",
     "HTTPCONNMGR_USED_SPECULATIVE_CONN",
     "HTTP_CACHE_DISPOSITION_2_V2",
     "HTTP_CACHE_ENTRY_ALIVE_TIME",
     "HTTP_CACHE_ENTRY_RELOAD_TIME",
     "HTTP_CACHE_ENTRY_REUSE_COUNT",
     "HTTP_CONNECTION_ENTRY_CACHE_HIT_1",
-    "HTTP_DISK_CACHE_OVERHEAD",
     "HTTP_OFFLINE_CACHE_DOCUMENT_LOAD",
     "HTTP_PAGE_CACHE_READ_TIME_V2",
     "HTTP_PAGE_COMPLETE_LOAD_CACHED_V2",
     "HTTP_PAGE_COMPLETE_LOAD_NET_V2",
     "HTTP_PAGE_COMPLETE_LOAD_V2",
     "HTTP_PAGE_DNS_ISSUE_TIME",
     "HTTP_PAGE_FIRST_SENT_TO_LAST_RECEIVED",
     "HTTP_PAGE_OPEN_TO_FIRST_FROM_CACHE_V2",
@@ -294,17 +291,16 @@
     "NETWORK_CACHE_V1_HIT_TIME_MS",
     "NETWORK_CACHE_V1_MISS_TIME_MS",
     "NETWORK_CACHE_V1_TRUNCATE_TIME_MS",
     "NETWORK_CACHE_V2_INPUT_STREAM_STATUS",
     "NETWORK_CACHE_V2_OUTPUT_STREAM_STATUS",
     "NETWORK_DISK_CACHE2_SHUTDOWN_CLEAR_PRIVATE",
     "NETWORK_DISK_CACHE_DELETEDIR",
     "NETWORK_DISK_CACHE_DELETEDIR_SHUTDOWN",
-    "NETWORK_DISK_CACHE_OPEN",
     "NETWORK_DISK_CACHE_SHUTDOWN",
     "NETWORK_DISK_CACHE_SHUTDOWN_CLEAR_PRIVATE",
     "NETWORK_DISK_CACHE_SHUTDOWN_V2",
     "NETWORK_DISK_CACHE_TRASHRENAME",
     "NEWTAB_PAGE_BLOCKED_SITES_COUNT",
     "NEWTAB_PAGE_ENABLED",
     "NEWTAB_PAGE_ENHANCED",
     "NEWTAB_PAGE_PINNED_SITES_COUNT",
@@ -475,19 +471,17 @@
     "BROWSER_SET_DEFAULT_ALWAYS_CHECK",
     "BROWSER_SET_DEFAULT_DIALOG_PROMPT_RAWCOUNT",
     "BROWSER_SET_DEFAULT_ERROR",
     "BROWSER_SET_DEFAULT_RESULT",
     "BR_9_2_1_SUBJECT_ALT_NAMES",
     "BR_9_2_2_SUBJECT_COMMON_NAME",
     "BUCKET_ORDER_ERRORS",
     "CACHE_DEVICE_SEARCH_2",
-    "CACHE_DISK_SEARCH_2",
     "CACHE_LM_INCONSISTENT",
-    "CACHE_MEMORY_SEARCH_2",
     "CACHE_OFFLINE_SEARCH_2",
     "CACHE_SERVICE_LOCK_WAIT_2",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_2",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSASYNCDOOMEVENT_RUN",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSBLOCKONCACHETHREADEVENT_RUN",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSCACHEENTRYDESCRIPTOR_CLOSE",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSCACHEENTRYDESCRIPTOR_DOOM",
     "CACHE_SERVICE_LOCK_WAIT_MAINTHREAD_NSCACHEENTRYDESCRIPTOR_DOOMANDFAILPENDINGREQUESTS",
@@ -730,17 +724,16 @@
     "HTTPCONNMGR_UNUSED_SPECULATIVE_CONN",
     "HTTPCONNMGR_USED_SPECULATIVE_CONN",
     "HTTP_CACHE_DISPOSITION_2_V2",
     "HTTP_CACHE_ENTRY_ALIVE_TIME",
     "HTTP_CACHE_ENTRY_RELOAD_TIME",
     "HTTP_CACHE_ENTRY_REUSE_COUNT",
     "HTTP_CONNECTION_ENTRY_CACHE_HIT_1",
     "HTTP_CONTENT_ENCODING",
-    "HTTP_DISK_CACHE_OVERHEAD",
     "HTTP_OFFLINE_CACHE_DOCUMENT_LOAD",
     "HTTP_PAGE_CACHE_READ_TIME_V2",
     "HTTP_PAGE_COMPLETE_LOAD_CACHED_V2",
     "HTTP_PAGE_COMPLETE_LOAD_NET_V2",
     "HTTP_PAGE_COMPLETE_LOAD_V2",
     "HTTP_PAGE_DNS_ISSUE_TIME",
     "HTTP_PAGE_DNS_LOOKUP_TIME",
     "HTTP_PAGE_FIRST_SENT_TO_LAST_RECEIVED",
@@ -858,17 +851,16 @@
     "NETWORK_CACHE_V1_HIT_TIME_MS",
     "NETWORK_CACHE_V1_MISS_TIME_MS",
     "NETWORK_CACHE_V1_TRUNCATE_TIME_MS",
     "NETWORK_CACHE_V2_INPUT_STREAM_STATUS",
     "NETWORK_CACHE_V2_OUTPUT_STREAM_STATUS",
     "NETWORK_DISK_CACHE2_SHUTDOWN_CLEAR_PRIVATE",
     "NETWORK_DISK_CACHE_DELETEDIR",
     "NETWORK_DISK_CACHE_DELETEDIR_SHUTDOWN",
-    "NETWORK_DISK_CACHE_OPEN",
     "NETWORK_DISK_CACHE_SHUTDOWN",
     "NETWORK_DISK_CACHE_SHUTDOWN_CLEAR_PRIVATE",
     "NETWORK_DISK_CACHE_SHUTDOWN_V2",
     "NETWORK_DISK_CACHE_TRASHRENAME",
     "NEWTAB_PAGE_BLOCKED_SITES_COUNT",
     "NEWTAB_PAGE_ENABLED",
     "NEWTAB_PAGE_ENHANCED",
     "NEWTAB_PAGE_PINNED_SITES_COUNT",
@@ -1284,48 +1276,45 @@
     "GC_MINOR_REASON",
     "GC_MINOR_REASON_LONG",
     "SSL_CT_POLICY_COMPLIANT_CONNECTIONS_BY_CA",
     "SSL_CT_POLICY_NON_COMPLIANT_CONNECTIONS_BY_CA",
     "FX_PAGE_LOAD_MS_2"
   ],
   "expiry_default": [
     "IDLE_NOTIFY_IDLE_MS",
-    "CACHE_MEMORY_SEARCH_2",
     "OSFILE_WORKER_LAUNCH_MS",
     "GEOLOCATION_OSX_SOURCE_IS_MLS",
     "TRANSLATION_OPPORTUNITIES_BY_LANGUAGE",
     "FX_THUMBNAILS_BG_CAPTURE_DONE_REASON_2",
     "TRANSLATED_PAGES",
     "FX_SESSION_RESTORE_SEND_UPDATE_CAUSED_OOM",
     "SSL_PERMANENT_CERT_ERROR_OVERRIDES",
     "FX_THUMBNAILS_BG_QUEUE_SIZE_ON_CAPTURE",
     "AUTO_REJECTED_TRANSLATION_OFFERS",
     "TRANSLATED_CHARACTERS",
     "WEAVE_CONFIGURED",
     "NEWTAB_PAGE_ENABLED",
     "MOZ_SQLITE_OPEN_MS",
     "SHOULD_TRANSLATION_UI_APPEAR",
     "FX_TOTAL_TOP_VISITS",
     "FX_SESSION_RESTORE_NUMBER_OF_EAGER_TABS_RESTORED",
-    "CACHE_DISK_SEARCH_2",
     "FX_THUMBNAILS_BG_CAPTURE_QUEUE_TIME_MS",
     "NEWTAB_PAGE_PINNED_SITES_COUNT",
     "WEAVE_COMPLETE_SUCCESS_COUNT",
     "OSFILE_WRITEATOMIC_JANK_MS",
     "STARTUP_MEASUREMENT_ERRORS",
     "CERT_CHAIN_KEY_SIZE_STATUS",
     "CHANGES_OF_TARGET_LANGUAGE",
     "PDF_VIEWER_TIME_TO_VIEW_MS",
     "MOZ_SQLITE_OTHER_READ_B",
     "TRANSLATION_OPPORTUNITIES",
     "NEWTAB_PAGE_BLOCKED_SITES_COUNT",
     "FX_SESSION_RESTORE_NUMBER_OF_TABS_RESTORED",
     "WEAVE_START_COUNT",
-    "HTTP_DISK_CACHE_OVERHEAD",
     "FX_SESSION_RESTORE_CORRUPT_FILE",
     "FX_TAB_CLICK_MS",
     "LOCALDOMSTORAGE_GETVALUE_BLOCKING_MS",
     "PDF_VIEWER_DOCUMENT_VERSION",
     "FX_SESSION_RESTORE_READ_FILE_MS",
     "CHANGES_OF_DETECTED_LANGUAGE",
     "OSFILE_WORKER_READY_MS",
     "PDF_VIEWER_FORM",
@@ -1355,17 +1344,16 @@
     "SHOULD_AUTO_DETECT_LANGUAGE",
     "A11Y_IATABLE_USAGE_FLAG",
     "LOCALDOMSTORAGE_PRELOAD_PENDING_ON_FIRST_ACCESS",
     "DENIED_TRANSLATION_OFFERS",
     "XUL_CACHE_DISABLED",
     "PAGE_FAULTS_HARD",
     "BROWSERPROVIDER_XUL_IMPORT_BOOKMARKS",
     "PDF_VIEWER_USED",
-    "NETWORK_DISK_CACHE_OPEN",
     "GEOLOCATION_WIN8_SOURCE_IS_MLS"
   ],
   "kind": [
     "A11Y_IATABLE_USAGE_FLAG",
     "A11Y_INSTANTIATED_FLAG",
     "A11Y_ISIMPLEDOM_USAGE_FLAG",
     "ADDON_FORBIDDEN_CPOW_USAGE",
     "ADDON_MANAGER_UPGRADE_UI_SHOWN",