Bug 1694662 - Remove Appcachestorage & oldwrappers r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D106455
This commit is contained in:
Valentin Gosu
2021-04-30 07:20:24 +00:00
parent e0c404c065
commit b48d0f6ea6
32 changed files with 47 additions and 1553 deletions

View File

@@ -261,7 +261,7 @@ var loadContextInfo = Services.loadContextInfo.fromLoadContext(
window.docShell.QueryInterface(Ci.nsILoadContext),
false
);
var diskStorage = cacheService.diskCacheStorage(loadContextInfo, false);
var diskStorage = cacheService.diskCacheStorage(loadContextInfo);
const nsICookiePermission = Ci.nsICookiePermission;

View File

@@ -33,8 +33,7 @@ function promiseNoCacheEntry(filename) {
function Visitor() {}
let storage = Services.cache2.diskCacheStorage(
Services.loadContextInfo.default,
false
Services.loadContextInfo.default
);
storage.asyncVisitStorage(new Visitor(), true /* Do walk entries */);
});

View File

@@ -4970,7 +4970,7 @@ var AboutHomeStartupCache = {
});
let lci = Services.loadContextInfo.default;
let storage = Services.cache2.diskCacheStorage(lci, false);
let storage = Services.cache2.diskCacheStorage(lci);
try {
storage.asyncOpenURI(
this.aboutHomeURI,

View File

@@ -81,7 +81,7 @@ function getCacheStorage(where, lci) {
}
switch (where) {
case "disk":
return Services.cache2.diskCacheStorage(lci, false);
return Services.cache2.diskCacheStorage(lci);
case "memory":
return Services.cache2.memoryCacheStorage(lci);
case "pin":

View File

@@ -67,7 +67,7 @@ function cacheDataForContext(loadContextInfo) {
};
// Visiting the disk cache also visits memory storage so we do not
// need to use Services.cache2.memoryCacheStorage() here.
let storage = Services.cache2.diskCacheStorage(loadContextInfo, false);
let storage = Services.cache2.diskCacheStorage(loadContextInfo);
storage.asyncVisitStorage(cacheVisitor, true);
});
}

View File

@@ -33,7 +33,7 @@ function cacheDataForContext(loadContextInfo) {
};
// Visiting the disk cache also visits memory storage so we do not
// need to use Services.cache2.memoryCacheStorage() here.
let storage = Services.cache2.diskCacheStorage(loadContextInfo, false);
let storage = Services.cache2.diskCacheStorage(loadContextInfo);
storage.asyncVisitStorage(cacheVisitor, true);
});
}

View File

@@ -152,7 +152,7 @@ function getFormHistoryCount() {
function storeCache(aURL, aContent) {
let cache = Services.cache2;
let storage = cache.diskCacheStorage(Services.loadContextInfo.default, false);
let storage = cache.diskCacheStorage(Services.loadContextInfo.default);
return new Promise(resolve => {
let storeCacheListener = {
@@ -195,7 +195,7 @@ function storeCache(aURL, aContent) {
function checkCache(aURL) {
let cache = Services.cache2;
let storage = cache.diskCacheStorage(Services.loadContextInfo.default, false);
let storage = cache.diskCacheStorage(Services.loadContextInfo.default);
return new Promise(resolve => {
let checkCacheListener = {

View File

@@ -34,14 +34,12 @@ function getStorageEntryCount(device, goon) {
switch (device) {
case "private":
storage = Services.cache2.diskCacheStorage(
Services.loadContextInfo.private,
false
Services.loadContextInfo.private
);
break;
case "regular":
storage = Services.cache2.diskCacheStorage(
Services.loadContextInfo.default,
false
Services.loadContextInfo.default
);
break;
default:

View File

@@ -53,7 +53,7 @@ function checkDiskCacheFor(host) {
onCacheEntryInfo: function(uri) {
const urispec = uri.asciiSpec;
info(urispec);
foundPrivateData |= urispec.includes(host);
foundPrivateData = foundPrivateData || urispec.includes(host);
},
onCacheEntryVisitCompleted: function() {
is(foundPrivateData, false, "web content present in disk cache");
@@ -63,8 +63,7 @@ function checkDiskCacheFor(host) {
function Visitor() {}
const storage = Services.cache2.diskCacheStorage(
Services.loadContextInfo.default,
false
Services.loadContextInfo.default
);
storage.asyncVisitStorage(
new Visitor(),

View File

@@ -38,7 +38,7 @@ exports.CacheEntry = {
// Get default load context if we can't fetch.
loadContext = Services.loadContextInfo.default;
}
this.cacheSession = cacheService.diskCacheStorage(loadContext, false);
this.cacheSession = cacheService.diskCacheStorage(loadContext);
this.isCacheSessionInitialized = true;
}
} catch (e) {

View File

@@ -589,7 +589,7 @@ Predictor::PredictNative(nsIURI* targetURI, nsIURI* sourceURI,
RefPtr<LoadContextInfo> lci = new LoadContextInfo(false, originAttributes);
nsresult rv = mCacheStorageService->DiskCacheStorage(
lci, false, getter_AddRefs(cacheDiskStorage));
lci, getter_AddRefs(cacheDiskStorage));
NS_ENSURE_SUCCESS(rv, rv);
uint32_t openFlags =
@@ -738,7 +738,7 @@ bool Predictor::PredictForPageload(nsICacheEntry* entry, nsIURI* targetURI,
nsCOMPtr<nsICacheStorage> cacheDiskStorage;
rv = mCacheStorageService->DiskCacheStorage(
lci, false, getter_AddRefs(cacheDiskStorage));
lci, getter_AddRefs(cacheDiskStorage));
NS_ENSURE_SUCCESS(rv, false);
PREDICTOR_LOG((" Predict redirect uri=%s action=%p",
@@ -1352,7 +1352,7 @@ Predictor::LearnNative(nsIURI* targetURI, nsIURI* sourceURI,
RefPtr<LoadContextInfo> lci = new LoadContextInfo(false, originAttributes);
rv = mCacheStorageService->DiskCacheStorage(lci, false,
rv = mCacheStorageService->DiskCacheStorage(lci,
getter_AddRefs(cacheDiskStorage));
NS_ENSURE_SUCCESS(rv, rv);
@@ -1841,7 +1841,7 @@ Predictor::Resetter::OnCacheEntryInfo(nsIURI* uri, const nsACString& idEnhance,
nsCOMPtr<nsICacheStorage> cacheDiskStorage;
rv = mPredictor->mCacheStorageService->DiskCacheStorage(
aInfo, false, getter_AddRefs(cacheDiskStorage));
aInfo, getter_AddRefs(cacheDiskStorage));
NS_ENSURE_SUCCESS(rv, rv);
cacheDiskStorage->AsyncDoomURI(uri, idEnhance, nullptr);
@@ -1884,7 +1884,7 @@ Predictor::Resetter::OnCacheEntryVisitCompleted() {
nsCOMPtr<nsICacheStorage> cacheDiskStorage;
rv = mPredictor->mCacheStorageService->DiskCacheStorage(
infosToVisit[i], false, getter_AddRefs(cacheDiskStorage));
infosToVisit[i], getter_AddRefs(cacheDiskStorage));
NS_ENSURE_SUCCESS(rv, rv);
urisToVisit[i]->GetAsciiSpec(u);
@@ -2277,7 +2277,7 @@ void Predictor::UpdateCacheabilityInternal(
RefPtr<LoadContextInfo> lci = new LoadContextInfo(false, originAttributes);
rv = mCacheStorageService->DiskCacheStorage(lci, false,
rv = mCacheStorageService->DiskCacheStorage(lci,
getter_AddRefs(cacheDiskStorage));
if (NS_FAILED(rv)) {
PREDICTOR_LOG((" cannot get disk cache storage"));

View File

@@ -1,156 +0,0 @@
/* 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 "CacheLog.h"
#include "AppCacheStorage.h"
#include "CacheStorageService.h"
#include "OldWrappers.h"
#include "nsICacheEntryDoomCallback.h"
#include "nsCacheService.h"
#include "nsIApplicationCache.h"
#include "nsIApplicationCacheService.h"
#include "nsIURI.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
namespace mozilla::net {
AppCacheStorage::AppCacheStorage(nsILoadContextInfo* aInfo,
nsIApplicationCache* aAppCache)
: CacheStorage(aInfo, true /* disk */, false /* lookup app cache */,
false /* skip size check */, false /* pin */),
mAppCache(aAppCache) {}
AppCacheStorage::~AppCacheStorage() {
ProxyReleaseMainThread("AppCacheStorage::mAppCache", mAppCache);
}
NS_IMETHODIMP AppCacheStorage::AsyncOpenURI(
nsIURI* aURI, const nsACString& aIdExtension, uint32_t aFlags,
nsICacheEntryOpenCallback* aCallback) {
if (!CacheStorageService::Self()) {
return NS_ERROR_NOT_INITIALIZED;
}
if (!LoadInfo()) {
return NS_ERROR_CACHE_KEY_NOT_FOUND;
}
NS_ENSURE_ARG(aURI);
NS_ENSURE_ARG(aCallback);
nsresult rv;
nsCOMPtr<nsIApplicationCache> appCache = mAppCache;
if (!appCache) {
rv = ChooseApplicationCache(aURI, getter_AddRefs(appCache));
NS_ENSURE_SUCCESS(rv, rv);
}
if (!appCache) {
LOG(
("AppCacheStorage::AsyncOpenURI entry not found in any appcache, "
"giving up"));
aCallback->OnCacheEntryAvailable(nullptr, false,
NS_ERROR_CACHE_KEY_NOT_FOUND);
return NS_OK;
}
nsCOMPtr<nsIURI> noRefURI;
rv = NS_GetURIWithoutRef(aURI, getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString cacheKey;
rv = noRefURI->GetAsciiSpec(cacheKey);
NS_ENSURE_SUCCESS(rv, rv);
// This is the only way how to recognize appcache data by the anonymous
// flag. There is no way to switch to e.g. a different session, because
// there is just a single session for an appcache version (identified
// by the client id).
if (LoadInfo()->IsAnonymous()) {
cacheKey = "anon&"_ns + cacheKey;
}
nsAutoCString scheme;
rv = noRefURI->GetScheme(scheme);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<_OldCacheLoad> appCacheLoad = new _OldCacheLoad(
scheme, cacheKey, aCallback, appCache, LoadInfo(), WriteToDisk(), aFlags);
rv = appCacheLoad->Start();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP AppCacheStorage::OpenTruncate(nsIURI* aURI,
const nsACString& aIdExtension,
nsICacheEntry** aCacheEntry) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP AppCacheStorage::Exists(nsIURI* aURI,
const nsACString& aIdExtension,
bool* aResult) {
*aResult = false;
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP AppCacheStorage::AsyncDoomURI(
nsIURI* aURI, const nsACString& aIdExtension,
nsICacheEntryDoomCallback* aCallback) {
if (!CacheStorageService::Self()) return NS_ERROR_NOT_INITIALIZED;
if (!mAppCache) {
return NS_ERROR_NOT_AVAILABLE;
}
if (!LoadInfo()) {
return NS_ERROR_CACHE_KEY_NOT_FOUND;
}
RefPtr<_OldStorage> old = new _OldStorage(LoadInfo(), WriteToDisk(),
LookupAppCache(), true, mAppCache);
return old->AsyncDoomURI(aURI, aIdExtension, aCallback);
}
NS_IMETHODIMP AppCacheStorage::AsyncEvictStorage(
nsICacheEntryDoomCallback* aCallback) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP AppCacheStorage::AsyncVisitStorage(
nsICacheStorageVisitor* aVisitor, bool aVisitEntries) {
if (!CacheStorageService::Self()) {
return NS_ERROR_NOT_INITIALIZED;
}
LOG(("AppCacheStorage::AsyncVisitStorage [this=%p, cb=%p]", this, aVisitor));
nsresult rv;
nsCOMPtr<nsICacheService> serv =
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<_OldVisitCallbackWrapper> cb = new _OldVisitCallbackWrapper(
"offline", aVisitor, aVisitEntries, LoadInfo());
rv = nsCacheService::GlobalInstance()->VisitEntriesInternal(cb);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP AppCacheStorage::GetCacheIndexEntryAttrs(
nsIURI* aURI, const nsACString& aIdExtension, bool* aHasAltData,
uint32_t* aSizeInKB) {
return NS_ERROR_NOT_IMPLEMENTED;
}
} // namespace mozilla::net

View File

@@ -1,35 +0,0 @@
/* 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 AppCacheStorage__h__
#define AppCacheStorage__h__
#include "CacheStorage.h"
#include "nsCOMPtr.h"
#include "nsILoadContextInfo.h"
#include "nsIApplicationCache.h"
class nsIApplicationCache;
namespace mozilla {
namespace net {
class AppCacheStorage : public CacheStorage {
NS_INLINE_DECL_REFCOUNTING_INHERITED(AppCacheStorage, CacheStorage)
NS_DECL_NSICACHESTORAGE
public:
AppCacheStorage(nsILoadContextInfo* aInfo, nsIApplicationCache* aAppCache);
private:
virtual ~AppCacheStorage();
nsCOMPtr<nsIApplicationCache> mAppCache;
};
} // namespace net
} // namespace mozilla
#endif

View File

@@ -8,12 +8,8 @@
#include "CacheEntry.h"
#include "CacheObserver.h"
#include "OldWrappers.h"
#include "nsICacheEntryDoomCallback.h"
#include "nsIApplicationCache.h"
#include "nsIApplicationCacheService.h"
#include "nsIURI.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
@@ -24,11 +20,9 @@ namespace mozilla::net {
NS_IMPL_ISUPPORTS(CacheStorage, nsICacheStorage)
CacheStorage::CacheStorage(nsILoadContextInfo* aInfo, bool aAllowDisk,
bool aLookupAppCache, bool aSkipSizeCheck,
bool aPinning)
bool aSkipSizeCheck, bool aPinning)
: mLoadContextInfo(aInfo ? GetLoadContextInfo(aInfo) : nullptr),
mWriteToDisk(aAllowDisk),
mLookupAppCache(aLookupAppCache),
mSkipSizeCheck(aSkipSizeCheck),
mPinning(aPinning) {}
@@ -65,32 +59,6 @@ NS_IMETHODIMP CacheStorage::AsyncOpenURI(nsIURI* aURI,
rv = noRefURI->GetAsciiSpec(asciiSpec);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIApplicationCache> appCache;
if (LookupAppCache()) {
rv = ChooseApplicationCache(noRefURI, getter_AddRefs(appCache));
NS_ENSURE_SUCCESS(rv, rv);
if (appCache) {
// From a chosen appcache open only as readonly
aFlags &= ~nsICacheStorage::OPEN_TRUNCATE;
}
}
if (appCache) {
nsAutoCString scheme;
rv = noRefURI->GetScheme(scheme);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<_OldCacheLoad> appCacheLoad =
new _OldCacheLoad(scheme, asciiSpec, aCallback, appCache, LoadInfo(),
WriteToDisk(), aFlags);
rv = appCacheLoad->Start();
NS_ENSURE_SUCCESS(rv, rv);
LOG(("CacheStorage::AsyncOpenURI loading from appcache"));
return NS_OK;
}
RefPtr<CacheEntryHandle> entry;
rv = CacheStorageService::Self()->AddStorageEntry(
this, asciiSpec, aIdExtension,
@@ -228,11 +196,4 @@ NS_IMETHODIMP CacheStorage::AsyncVisitStorage(nsICacheStorageVisitor* aVisitor,
return NS_OK;
}
// Internal
nsresult CacheStorage::ChooseApplicationCache(nsIURI* aURI,
nsIApplicationCache** aCache) {
return NS_ERROR_NOT_IMPLEMENTED;
}
} // namespace mozilla::net

View File

@@ -13,10 +13,8 @@
#include "nsThreadUtils.h"
#include "nsCOMPtr.h"
#include "nsILoadContextInfo.h"
#include "nsIApplicationCache.h"
class nsIURI;
class nsIApplicationCache;
namespace mozilla {
namespace net {
@@ -41,17 +39,14 @@ class CacheStorage : public nsICacheStorage {
NS_DECL_NSICACHESTORAGE
public:
CacheStorage(nsILoadContextInfo* aInfo, bool aAllowDisk, bool aLookupAppCache,
bool aSkipSizeCheck, bool aPinning);
CacheStorage(nsILoadContextInfo* aInfo, bool aAllowDisk, bool aSkipSizeCheck,
bool aPinning);
protected:
virtual ~CacheStorage() = default;
nsresult ChooseApplicationCache(nsIURI* aURI, nsIApplicationCache** aCache);
RefPtr<LoadContextInfo> mLoadContextInfo;
bool mWriteToDisk : 1;
bool mLookupAppCache : 1;
bool mSkipSizeCheck : 1;
bool mPinning : 1;
@@ -61,7 +56,6 @@ class CacheStorage : public nsICacheStorage {
return mWriteToDisk &&
(!mLoadContextInfo || !mLoadContextInfo->IsPrivate());
}
bool LookupAppCache() const { return mLookupAppCache; }
bool SkipSizeCheck() const { return mSkipSizeCheck; }
bool Pinning() const { return mPinning; }
};

View File

@@ -11,11 +11,9 @@
#include "CacheIndex.h"
#include "CacheIndexIterator.h"
#include "CacheStorage.h"
#include "AppCacheStorage.h"
#include "CacheEntry.h"
#include "CacheFileUtils.h"
#include "OldWrappers.h"
#include "nsCacheService.h"
#include "nsDeleteDir.h"
@@ -672,7 +670,7 @@ nsresult ClearStorage(bool const aPrivate, bool const aAnonymous,
NS_ENSURE_TRUE(service, NS_ERROR_FAILURE);
// Clear disk storage
rv = service->DiskCacheStorage(info, false, getter_AddRefs(storage));
rv = service->DiskCacheStorage(info, getter_AddRefs(storage));
NS_ENSURE_SUCCESS(rv, rv);
rv = storage->AsyncEvictStorage(nullptr);
NS_ENSURE_SUCCESS(rv, rv);
@@ -711,14 +709,13 @@ NS_IMETHODIMP CacheStorageService::MemoryCacheStorage(
NS_ENSURE_ARG(_retval);
nsCOMPtr<nsICacheStorage> storage =
new CacheStorage(aLoadContextInfo, false, false, false, false);
new CacheStorage(aLoadContextInfo, false, false, false);
storage.forget(_retval);
return NS_OK;
}
NS_IMETHODIMP CacheStorageService::DiskCacheStorage(
nsILoadContextInfo* aLoadContextInfo, bool aLookupAppCache,
nsICacheStorage** _retval) {
nsILoadContextInfo* aLoadContextInfo, nsICacheStorage** _retval) {
NS_ENSURE_ARG(_retval);
// TODO save some heap granularity - cache commonly used storages.
@@ -727,9 +724,8 @@ NS_IMETHODIMP CacheStorageService::DiskCacheStorage(
// in memory.
bool useDisk = CacheObserver::UseDiskCache();
nsCOMPtr<nsICacheStorage> storage =
new CacheStorage(aLoadContextInfo, useDisk, aLookupAppCache,
false /* size limit */, false /* don't pin */);
nsCOMPtr<nsICacheStorage> storage = new CacheStorage(
aLoadContextInfo, useDisk, false /* size limit */, false /* don't pin */);
storage.forget(_retval);
return NS_OK;
}
@@ -744,9 +740,9 @@ NS_IMETHODIMP CacheStorageService::PinningCacheStorage(
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsICacheStorage> storage = new CacheStorage(
aLoadContextInfo, true /* use disk */, false /* no appcache */,
true /* ignore size checks */, true /* pin */);
nsCOMPtr<nsICacheStorage> storage =
new CacheStorage(aLoadContextInfo, true /* use disk */,
true /* ignore size checks */, true /* pin */);
storage.forget(_retval);
return NS_OK;
}
@@ -757,7 +753,7 @@ NS_IMETHODIMP CacheStorageService::SynthesizedCacheStorage(
NS_ENSURE_ARG(_retval);
nsCOMPtr<nsICacheStorage> storage =
new CacheStorage(aLoadContextInfo, false, false,
new CacheStorage(aLoadContextInfo, false,
true /* skip size checks for synthesized cache */,
false /* no pinning */);
storage.forget(_retval);

View File

@@ -1,983 +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/. */
// Stuff to link the old imp to the new api - will go away!
#include "CacheLog.h"
#include "OldWrappers.h"
#include "CacheStorage.h"
#include "CacheStorageService.h"
#include "LoadContextInfo.h"
#include "nsCacheService.h"
#include "nsIURI.h"
#include "nsICacheSession.h"
#include "nsIApplicationCache.h"
#include "nsIApplicationCacheService.h"
#include "nsIStreamTransportService.h"
#include "nsIFile.h"
#include "nsICacheEntryDoomCallback.h"
#include "nsICacheListener.h"
#include "nsICacheStorageVisitor.h"
#include "nsServiceManagerUtils.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsProxyRelease.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Telemetry.h"
static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID);
static uint32_t const CHECK_MULTITHREADED =
nsICacheStorage::CHECK_MULTITHREADED;
namespace mozilla {
namespace net {
namespace {
// Fires the doom callback back on the main thread
// after the cache I/O thread is looped.
class DoomCallbackSynchronizer : public Runnable {
public:
explicit DoomCallbackSynchronizer(nsICacheEntryDoomCallback* cb)
: Runnable("net::DoomCallbackSynchronizer"), mCB(cb) {}
nsresult Dispatch();
private:
virtual ~DoomCallbackSynchronizer() = default;
NS_DECL_NSIRUNNABLE
nsCOMPtr<nsICacheEntryDoomCallback> mCB;
};
nsresult DoomCallbackSynchronizer::Dispatch() {
nsresult rv;
nsCOMPtr<nsICacheService> serv =
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIEventTarget> eventTarget;
rv = serv->GetCacheIOTarget(getter_AddRefs(eventTarget));
NS_ENSURE_SUCCESS(rv, rv);
rv = eventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP DoomCallbackSynchronizer::Run() {
if (!NS_IsMainThread()) {
NS_DispatchToMainThread(this);
} else {
if (mCB) mCB->OnCacheEntryDoomed(NS_OK);
}
return NS_OK;
}
// Receives doom callback from the old API and forwards to the new API
class DoomCallbackWrapper : public nsICacheListener {
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSICACHELISTENER
explicit DoomCallbackWrapper(nsICacheEntryDoomCallback* cb) : mCB(cb) {}
private:
virtual ~DoomCallbackWrapper() = default;
nsCOMPtr<nsICacheEntryDoomCallback> mCB;
};
NS_IMPL_ISUPPORTS(DoomCallbackWrapper, nsICacheListener);
NS_IMETHODIMP DoomCallbackWrapper::OnCacheEntryAvailable(
nsICacheEntryDescriptor* descriptor, nsCacheAccessMode accessGranted,
nsresult status) {
return NS_OK;
}
NS_IMETHODIMP DoomCallbackWrapper::OnCacheEntryDoomed(nsresult status) {
if (!mCB) return NS_ERROR_NULL_POINTER;
mCB->OnCacheEntryDoomed(status);
mCB = nullptr;
return NS_OK;
}
} // namespace
// _OldVisitCallbackWrapper
// Receives visit callbacks from the old API and forwards it to the new API
NS_IMPL_ISUPPORTS(_OldVisitCallbackWrapper, nsICacheVisitor)
_OldVisitCallbackWrapper::~_OldVisitCallbackWrapper() {
if (!mHit) {
// The device has not been found, to not break the chain, simulate
// storage info callback.
mCB->OnCacheStorageInfo(0, 0, 0, nullptr);
}
if (mVisitEntries) {
mCB->OnCacheEntryVisitCompleted();
}
}
NS_IMETHODIMP _OldVisitCallbackWrapper::VisitDevice(
const char* deviceID, nsICacheDeviceInfo* deviceInfo, bool* _retval) {
if (!mCB) return NS_ERROR_NULL_POINTER;
*_retval = false;
if (strcmp(deviceID, mDeviceID)) {
// Not the device we want to visit
return NS_OK;
}
mHit = true;
nsresult rv;
uint32_t capacity;
rv = deviceInfo->GetMaximumSize(&capacity);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFile> dir;
if (!strcmp(mDeviceID, "disk")) {
nsCacheService::GetDiskCacheDirectory(getter_AddRefs(dir));
} else if (!strcmp(mDeviceID, "offline")) {
nsCacheService::GetAppCacheDirectory(getter_AddRefs(dir));
}
if (mLoadInfo && mLoadInfo->IsAnonymous()) {
// Anonymous visiting reports 0, 0 since we cannot count that
// early the number of anon entries.
mCB->OnCacheStorageInfo(0, 0, capacity, dir);
} else {
// Non-anon visitor counts all non-anon + ALL ANON entries,
// there is no way to determine the number of entries when
// using the old cache APIs - there is no concept of anonymous
// storage.
uint32_t entryCount;
rv = deviceInfo->GetEntryCount(&entryCount);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t totalSize;
rv = deviceInfo->GetTotalSize(&totalSize);
NS_ENSURE_SUCCESS(rv, rv);
mCB->OnCacheStorageInfo(entryCount, totalSize, capacity, dir);
}
*_retval = mVisitEntries;
return NS_OK;
}
NS_IMETHODIMP _OldVisitCallbackWrapper::VisitEntry(const char* deviceID,
nsICacheEntryInfo* entryInfo,
bool* _retval) {
MOZ_ASSERT(!strcmp(deviceID, mDeviceID));
nsresult rv;
*_retval = true;
// Read all informative properties from the entry.
nsAutoCString clientId;
rv = entryInfo->GetClientID(clientId);
if (NS_FAILED(rv)) return NS_OK;
if (mLoadInfo->IsPrivate() !=
StringBeginsWith(clientId, "HTTP-memory-only-PB"_ns)) {
return NS_OK;
}
nsAutoCString cacheKey, enhanceId;
rv = entryInfo->GetKey(cacheKey);
if (NS_FAILED(rv)) return NS_OK;
if (StringBeginsWith(cacheKey, "anon&"_ns)) {
if (!mLoadInfo->IsAnonymous()) return NS_OK;
cacheKey = Substring(cacheKey, 5, cacheKey.Length());
} else if (mLoadInfo->IsAnonymous()) {
return NS_OK;
}
if (StringBeginsWith(cacheKey, "id="_ns)) {
int32_t uriSpecEnd = cacheKey.Find("&uri=");
if (uriSpecEnd == kNotFound) // Corrupted, ignore
return NS_OK;
enhanceId = Substring(cacheKey, 3, uriSpecEnd - 3);
cacheKey = Substring(cacheKey, uriSpecEnd + 1, cacheKey.Length());
}
if (StringBeginsWith(cacheKey, "uri="_ns)) {
cacheKey = Substring(cacheKey, 4, cacheKey.Length());
}
nsCOMPtr<nsIURI> uri;
// cacheKey is strip of any prefixes
rv = NS_NewURI(getter_AddRefs(uri), cacheKey);
if (NS_FAILED(rv)) return NS_OK;
uint32_t dataSize;
if (NS_FAILED(entryInfo->GetDataSize(&dataSize))) dataSize = 0;
int32_t fetchCount;
if (NS_FAILED(entryInfo->GetFetchCount(&fetchCount))) fetchCount = 0;
uint32_t expirationTime;
if (NS_FAILED(entryInfo->GetExpirationTime(&expirationTime)))
expirationTime = 0;
uint32_t lastModified;
if (NS_FAILED(entryInfo->GetLastModified(&lastModified))) lastModified = 0;
// Send them to the consumer.
rv = mCB->OnCacheEntryInfo(uri, enhanceId, (int64_t)dataSize, fetchCount,
lastModified, expirationTime, false, mLoadInfo);
*_retval = NS_SUCCEEDED(rv);
return NS_OK;
}
// _OldGetDiskConsumption
// static
nsresult _OldGetDiskConsumption::Get(
nsICacheStorageConsumptionObserver* aCallback) {
nsresult rv;
nsCOMPtr<nsICacheService> serv =
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<_OldGetDiskConsumption> cb = new _OldGetDiskConsumption(aCallback);
// _OldGetDiskConsumption stores the found size value, but until dispatched
// to the main thread it doesn't call on the consupmtion observer. See bellow.
rv = serv->VisitEntries(cb);
NS_ENSURE_SUCCESS(rv, rv);
// We are called from CacheStorageService::AsyncGetDiskConsumption whose IDL
// documentation claims the callback is always delievered asynchronously
// back to the main thread. Despite we know the result synchronosusly when
// querying the old cache, we need to stand the word and dispatch the result
// to the main thread asynchronously. Hence the dispatch here.
return NS_DispatchToMainThread(cb);
}
NS_IMPL_ISUPPORTS_INHERITED(_OldGetDiskConsumption, Runnable, nsICacheVisitor)
_OldGetDiskConsumption::_OldGetDiskConsumption(
nsICacheStorageConsumptionObserver* aCallback)
: Runnable("net::_OldGetDiskConsumption"), mCallback(aCallback), mSize(0) {}
NS_IMETHODIMP
_OldGetDiskConsumption::Run() {
mCallback->OnNetworkCacheDiskConsumption(mSize);
return NS_OK;
}
NS_IMETHODIMP
_OldGetDiskConsumption::VisitDevice(const char* deviceID,
nsICacheDeviceInfo* deviceInfo,
bool* _retval) {
if (!strcmp(deviceID, "disk")) {
uint32_t size;
nsresult rv = deviceInfo->GetTotalSize(&size);
if (NS_SUCCEEDED(rv)) mSize = (int64_t)size;
}
*_retval = false;
return NS_OK;
}
NS_IMETHODIMP
_OldGetDiskConsumption::VisitEntry(const char* deviceID,
nsICacheEntryInfo* entryInfo,
bool* _retval) {
MOZ_CRASH("Unexpected");
return NS_OK;
}
// _OldCacheEntryWrapper
_OldCacheEntryWrapper::_OldCacheEntryWrapper(nsICacheEntryDescriptor* desc)
: mOldDesc(desc), mOldInfo(desc), mCacheEntryId(CacheEntry::GetNextId()) {
LOG(("Creating _OldCacheEntryWrapper %p for descriptor %p", this, desc));
}
_OldCacheEntryWrapper::_OldCacheEntryWrapper(nsICacheEntryInfo* info)
: mOldDesc(nullptr),
mOldInfo(info),
mCacheEntryId(CacheEntry::GetNextId()) {
LOG(("Creating _OldCacheEntryWrapper %p for info %p", this, info));
}
_OldCacheEntryWrapper::~_OldCacheEntryWrapper() {
LOG(("Destroying _OldCacheEntryWrapper %p for descriptor %p", this,
mOldInfo.get()));
}
NS_IMETHODIMP _OldCacheEntryWrapper::GetIsForcedValid(bool* aIsForcedValid) {
// Unused stub
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP _OldCacheEntryWrapper::ForceValidFor(
uint32_t aSecondsToTheFuture) {
// Unused stub
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMPL_ISUPPORTS(_OldCacheEntryWrapper, nsICacheEntry)
NS_IMETHODIMP _OldCacheEntryWrapper::AsyncDoom(
nsICacheEntryDoomCallback* listener) {
RefPtr<DoomCallbackWrapper> cb =
listener ? new DoomCallbackWrapper(listener) : nullptr;
return AsyncDoom(cb);
}
NS_IMETHODIMP _OldCacheEntryWrapper::GetDataSize(int64_t* aSize) {
uint32_t size;
nsresult rv = GetDataSize(&size);
if (NS_FAILED(rv)) return rv;
*aSize = size;
return NS_OK;
}
NS_IMETHODIMP _OldCacheEntryWrapper::GetAltDataSize(int64_t* aSize) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP _OldCacheEntryWrapper::GetAltDataType(nsACString& aType) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP _OldCacheEntryWrapper::GetPersistent(bool* aPersistToDisk) {
if (!mOldDesc) {
return NS_ERROR_NULL_POINTER;
}
nsresult rv;
nsCacheStoragePolicy policy;
rv = mOldDesc->GetStoragePolicy(&policy);
NS_ENSURE_SUCCESS(rv, rv);
*aPersistToDisk = policy != nsICache::STORE_IN_MEMORY;
return NS_OK;
}
NS_IMETHODIMP _OldCacheEntryWrapper::Recreate(bool aMemoryOnly,
nsICacheEntry** aResult) {
NS_ENSURE_TRUE(mOldDesc, NS_ERROR_NOT_AVAILABLE);
nsCacheAccessMode mode;
nsresult rv = mOldDesc->GetAccessGranted(&mode);
NS_ENSURE_SUCCESS(rv, rv);
if (!(mode & nsICache::ACCESS_WRITE)) return NS_ERROR_NOT_AVAILABLE;
LOG(("_OldCacheEntryWrapper::Recreate [this=%p]", this));
if (aMemoryOnly) mOldDesc->SetStoragePolicy(nsICache::STORE_IN_MEMORY);
nsCOMPtr<nsICacheEntry> self(this);
self.forget(aResult);
return NS_OK;
}
NS_IMETHODIMP _OldCacheEntryWrapper::OpenInputStream(int64_t offset,
nsIInputStream** _retval) {
if (offset > PR_UINT32_MAX) return NS_ERROR_INVALID_ARG;
return OpenInputStream(uint32_t(offset), _retval);
}
NS_IMETHODIMP _OldCacheEntryWrapper::OpenOutputStream(
int64_t offset, int64_t predictedSize, nsIOutputStream** _retval) {
if (offset > PR_UINT32_MAX) return NS_ERROR_INVALID_ARG;
return OpenOutputStream(uint32_t(offset), _retval);
}
NS_IMETHODIMP _OldCacheEntryWrapper::MaybeMarkValid() {
LOG(("_OldCacheEntryWrapper::MaybeMarkValid [this=%p]", this));
NS_ENSURE_TRUE(mOldDesc, NS_ERROR_NULL_POINTER);
nsCacheAccessMode mode;
nsresult rv = mOldDesc->GetAccessGranted(&mode);
NS_ENSURE_SUCCESS(rv, rv);
if (mode & nsICache::ACCESS_WRITE) {
LOG(("Marking cache entry valid [entry=%p, descr=%p]", this, mOldDesc));
return mOldDesc->MarkValid();
}
LOG(("Not marking read-only cache entry valid [entry=%p, descr=%p]", this,
mOldDesc));
return NS_OK;
}
NS_IMETHODIMP _OldCacheEntryWrapper::HasWriteAccess(bool aWriteAllowed_unused,
bool* aWriteAccess) {
NS_ENSURE_TRUE(mOldDesc, NS_ERROR_NULL_POINTER);
NS_ENSURE_ARG(aWriteAccess);
nsCacheAccessMode mode;
nsresult rv = mOldDesc->GetAccessGranted(&mode);
NS_ENSURE_SUCCESS(rv, rv);
*aWriteAccess = !!(mode & nsICache::ACCESS_WRITE);
LOG(("_OldCacheEntryWrapper::HasWriteAccess [this=%p, write-access=%d]", this,
*aWriteAccess));
return NS_OK;
}
namespace {
class MetaDataVisitorWrapper : public nsICacheMetaDataVisitor {
virtual ~MetaDataVisitorWrapper() = default;
NS_DECL_ISUPPORTS
NS_DECL_NSICACHEMETADATAVISITOR
explicit MetaDataVisitorWrapper(nsICacheEntryMetaDataVisitor* cb) : mCB(cb) {}
nsCOMPtr<nsICacheEntryMetaDataVisitor> mCB;
};
NS_IMPL_ISUPPORTS(MetaDataVisitorWrapper, nsICacheMetaDataVisitor)
NS_IMETHODIMP
MetaDataVisitorWrapper::VisitMetaDataElement(char const* key, char const* value,
bool* goon) {
*goon = true;
return mCB->OnMetaDataElement(key, value);
}
} // namespace
NS_IMETHODIMP _OldCacheEntryWrapper::VisitMetaData(
nsICacheEntryMetaDataVisitor* cb) {
RefPtr<MetaDataVisitorWrapper> w = new MetaDataVisitorWrapper(cb);
return mOldDesc->VisitMetaData(w);
}
namespace {
void GetCacheSessionNameForStoragePolicy(const nsACString& scheme,
nsCacheStoragePolicy storagePolicy,
bool isPrivate,
OriginAttributes const* originAttribs,
nsACString& sessionName) {
MOZ_ASSERT(!isPrivate || storagePolicy == nsICache::STORE_IN_MEMORY);
// HTTP
if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https")) {
switch (storagePolicy) {
case nsICache::STORE_IN_MEMORY:
if (isPrivate)
sessionName.AssignLiteral("HTTP-memory-only-PB");
else
sessionName.AssignLiteral("HTTP-memory-only");
break;
case nsICache::STORE_OFFLINE:
// XXX This is actually never used, only added to prevent
// any compatibility damage.
sessionName.AssignLiteral("HTTP-offline");
break;
default:
sessionName.AssignLiteral("HTTP");
break;
}
}
// FTP
else if (scheme.EqualsLiteral("ftp")) {
if (isPrivate)
sessionName.AssignLiteral("FTP-private");
else
sessionName.AssignLiteral("FTP");
}
// all remaining URL scheme
else {
// Since with the new API a consumer cannot specify its own session name
// and partitioning of the cache is handled stricly only by the cache
// back-end internally, we will use a separate session name to pretend
// functionality of the new API wrapping the Darin's cache for all other
// URL schemes.
// Deliberately omitting |anonymous| since other session types don't
// recognize it too.
sessionName.AssignLiteral("other");
if (isPrivate) sessionName.AppendLiteral("-private");
}
nsAutoCString suffix;
originAttribs->CreateSuffix(suffix);
sessionName.Append(suffix);
}
nsresult GetCacheSession(const nsACString& aScheme, bool aWriteToDisk,
nsILoadContextInfo* aLoadInfo,
nsIApplicationCache* aAppCache,
nsICacheSession** _result) {
nsresult rv;
nsCacheStoragePolicy storagePolicy;
if (aAppCache)
storagePolicy = nsICache::STORE_OFFLINE;
else if (!aWriteToDisk || aLoadInfo->IsPrivate())
storagePolicy = nsICache::STORE_IN_MEMORY;
else
storagePolicy = nsICache::STORE_ANYWHERE;
nsAutoCString clientId;
if (aAppCache) {
aAppCache->GetClientID(clientId);
} else {
GetCacheSessionNameForStoragePolicy(
aScheme, storagePolicy, aLoadInfo->IsPrivate(),
aLoadInfo->OriginAttributesPtr(), clientId);
}
LOG((" GetCacheSession for client=%s, policy=%d", clientId.get(),
storagePolicy));
nsCOMPtr<nsICacheService> serv =
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICacheSession> session;
rv = nsCacheService::GlobalInstance()->CreateSessionInternal(
clientId.get(), storagePolicy, nsICache::STREAM_BASED,
getter_AddRefs(session));
NS_ENSURE_SUCCESS(rv, rv);
rv = session->SetIsPrivate(aLoadInfo->IsPrivate());
NS_ENSURE_SUCCESS(rv, rv);
rv = session->SetDoomEntriesIfExpired(false);
NS_ENSURE_SUCCESS(rv, rv);
if (aAppCache) {
nsCOMPtr<nsIFile> profileDirectory;
aAppCache->GetProfileDirectory(getter_AddRefs(profileDirectory));
if (profileDirectory) rv = session->SetProfileDirectory(profileDirectory);
NS_ENSURE_SUCCESS(rv, rv);
}
session.forget(_result);
return NS_OK;
}
} // namespace
NS_IMPL_ISUPPORTS_INHERITED(_OldCacheLoad, Runnable, nsICacheListener)
_OldCacheLoad::_OldCacheLoad(const nsACString& aScheme,
const nsACString& aCacheKey,
nsICacheEntryOpenCallback* aCallback,
nsIApplicationCache* aAppCache,
nsILoadContextInfo* aLoadInfo, bool aWriteToDisk,
uint32_t aFlags)
: Runnable("net::_OldCacheLoad"),
mScheme(aScheme),
mCacheKey(aCacheKey),
mCallback(aCallback),
mLoadInfo(GetLoadContextInfo(aLoadInfo)),
mFlags(aFlags),
mWriteToDisk(aWriteToDisk),
mNew(true),
mOpening(true),
mSync(false),
mStatus(NS_ERROR_UNEXPECTED),
mRunCount(0),
mAppCache(aAppCache) {}
_OldCacheLoad::~_OldCacheLoad() {
ProxyReleaseMainThread("_OldCacheLoad::mAppCache", mAppCache);
}
nsresult _OldCacheLoad::Start() {
LOG(("_OldCacheLoad::Start [this=%p, key=%s]", this, mCacheKey.get()));
mLoadStart = mozilla::TimeStamp::Now();
nsresult rv;
// Consumers that can invoke this code as first and off the main thread
// are responsible for initiating these two services on the main thread.
// Currently no one does that.
// XXX: Start the cache service; otherwise DispatchToCacheIOThread will
// fail.
nsCOMPtr<nsICacheService> service =
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
// Ensure the stream transport service gets initialized on the main thread
if (NS_SUCCEEDED(rv) && NS_IsMainThread()) {
nsCOMPtr<nsIStreamTransportService> sts =
do_GetService(kStreamTransportServiceCID, &rv);
}
if (NS_SUCCEEDED(rv)) {
rv = service->GetCacheIOTarget(getter_AddRefs(mCacheThread));
}
if (NS_SUCCEEDED(rv)) {
bool onCacheTarget;
rv = mCacheThread->IsOnCurrentThread(&onCacheTarget);
if (NS_SUCCEEDED(rv) && onCacheTarget) {
mSync = true;
}
}
if (NS_SUCCEEDED(rv)) {
if (mSync) {
rv = Run();
} else {
rv = mCacheThread->Dispatch(this, NS_DISPATCH_NORMAL);
}
}
return rv;
}
NS_IMETHODIMP
_OldCacheLoad::Run() {
LOG(("_OldCacheLoad::Run [this=%p, key=%s, cb=%p]", this, mCacheKey.get(),
mCallback.get()));
nsresult rv;
if (mOpening) {
mOpening = false;
nsCOMPtr<nsICacheSession> session;
rv = GetCacheSession(mScheme, mWriteToDisk, mLoadInfo, mAppCache,
getter_AddRefs(session));
if (NS_SUCCEEDED(rv)) {
// AsyncOpenCacheEntry isn't really async when its called on the
// cache service thread.
nsCacheAccessMode cacheAccess;
if (mFlags & nsICacheStorage::OPEN_TRUNCATE)
cacheAccess = nsICache::ACCESS_WRITE;
else if ((mFlags & nsICacheStorage::OPEN_READONLY) || mAppCache)
cacheAccess = nsICache::ACCESS_READ;
else
cacheAccess = nsICache::ACCESS_READ_WRITE;
LOG((" session->AsyncOpenCacheEntry with access=%d", cacheAccess));
bool bypassBusy = mFlags & nsICacheStorage::OPEN_BYPASS_IF_BUSY;
if (mSync && cacheAccess == nsICache::ACCESS_WRITE) {
nsCOMPtr<nsICacheEntryDescriptor> entry;
rv = session->OpenCacheEntry(mCacheKey, cacheAccess, bypassBusy,
getter_AddRefs(entry));
nsCacheAccessMode grantedAccess = 0;
if (NS_SUCCEEDED(rv)) {
entry->GetAccessGranted(&grantedAccess);
}
return OnCacheEntryAvailable(entry, grantedAccess, rv);
}
rv = session->AsyncOpenCacheEntry(mCacheKey, cacheAccess, this,
bypassBusy);
if (NS_SUCCEEDED(rv)) return NS_OK;
}
// Opening failed, propagate the error to the consumer
LOG((" Opening cache entry failed with rv=0x%08" PRIx32,
static_cast<uint32_t>(rv)));
mStatus = rv;
mNew = false;
NS_DispatchToMainThread(this);
} else {
if (!mCallback) {
LOG((" duplicate call, bypassed"));
return NS_OK;
}
if (NS_SUCCEEDED(mStatus)) {
if (mFlags & nsICacheStorage::OPEN_TRUNCATE) {
mozilla::Telemetry::AccumulateTimeDelta(
mozilla::Telemetry::NETWORK_CACHE_V1_TRUNCATE_TIME_MS, mLoadStart);
} else if (mNew) {
mozilla::Telemetry::AccumulateTimeDelta(
mozilla::Telemetry::NETWORK_CACHE_V1_MISS_TIME_MS, mLoadStart);
} else {
mozilla::Telemetry::AccumulateTimeDelta(
mozilla::Telemetry::NETWORK_CACHE_V1_HIT_TIME_MS, mLoadStart);
}
}
if (!(mFlags & CHECK_MULTITHREADED)) Check();
// break cycles
nsCOMPtr<nsICacheEntryOpenCallback> cb = std::move(mCallback);
mCacheThread = nullptr;
nsCOMPtr<nsICacheEntry> entry = std::move(mCacheEntry);
rv = cb->OnCacheEntryAvailable(entry, mNew, mStatus);
if (NS_FAILED(rv) && entry) {
LOG((" cb->OnCacheEntryAvailable failed with rv=0x%08" PRIx32,
static_cast<uint32_t>(rv)));
if (mNew)
entry->AsyncDoom(nullptr);
else
entry->Close();
}
}
return rv;
}
NS_IMETHODIMP
_OldCacheLoad::OnCacheEntryAvailable(nsICacheEntryDescriptor* entry,
nsCacheAccessMode access,
nsresult status) {
LOG(
("_OldCacheLoad::OnCacheEntryAvailable [this=%p, ent=%p, cb=%p, "
"appcache=%p, access=%x]",
this, entry, mCallback.get(), mAppCache.get(), access));
// XXX Bug 759805: Sometimes we will call this method directly from
// HttpCacheQuery::Run when AsyncOpenCacheEntry fails, but
// AsyncOpenCacheEntry will also call this method. As a workaround, we just
// ensure we only execute this code once.
NS_ENSURE_TRUE(mRunCount == 0, NS_ERROR_UNEXPECTED);
++mRunCount;
mCacheEntry = entry ? new _OldCacheEntryWrapper(entry) : nullptr;
mStatus = status;
mNew = access == nsICache::ACCESS_WRITE;
if (mFlags & CHECK_MULTITHREADED) Check();
if (mSync) return Run();
return NS_DispatchToMainThread(this);
}
void _OldCacheLoad::Check() {
if (!mCacheEntry) return;
if (mNew) return;
uint32_t result;
nsresult rv = mCallback->OnCacheEntryCheck(mCacheEntry, &result);
LOG((" OnCacheEntryCheck result ent=%p, cb=%p, appcache=%p, rv=0x%08" PRIx32
", result=%d",
mCacheEntry.get(), mCallback.get(), mAppCache.get(),
static_cast<uint32_t>(rv), result));
if (NS_FAILED(rv)) {
NS_WARNING("cache check failed");
}
if (NS_FAILED(rv) || result == nsICacheEntryOpenCallback::ENTRY_NOT_WANTED) {
mCacheEntry->Close();
mCacheEntry = nullptr;
mStatus = NS_ERROR_CACHE_KEY_NOT_FOUND;
}
}
NS_IMETHODIMP
_OldCacheLoad::OnCacheEntryDoomed(nsresult) { return NS_ERROR_NOT_IMPLEMENTED; }
// nsICacheStorage old cache wrapper
NS_IMPL_ISUPPORTS(_OldStorage, nsICacheStorage)
_OldStorage::_OldStorage(nsILoadContextInfo* aInfo, bool aAllowDisk,
bool aLookupAppCache, bool aOfflineStorage,
nsIApplicationCache* aAppCache)
: mLoadInfo(GetLoadContextInfo(aInfo)),
mAppCache(aAppCache),
mWriteToDisk(aAllowDisk),
mLookupAppCache(aLookupAppCache),
mOfflineStorage(aOfflineStorage) {}
_OldStorage::~_OldStorage() = default;
NS_IMETHODIMP _OldStorage::AsyncOpenURI(nsIURI* aURI,
const nsACString& aIdExtension,
uint32_t aFlags,
nsICacheEntryOpenCallback* aCallback) {
NS_ENSURE_ARG(aURI);
NS_ENSURE_ARG(aCallback);
#ifdef MOZ_LOGGING
nsAutoCString uriSpec;
aURI->GetAsciiSpec(uriSpec);
LOG(("_OldStorage::AsyncOpenURI [this=%p, uri=%s, ide=%s, flags=%x]", this,
uriSpec.get(), aIdExtension.BeginReading(), aFlags));
#endif
nsresult rv;
nsAutoCString cacheKey, scheme;
rv = AssembleCacheKey(aURI, aIdExtension, cacheKey, scheme);
NS_ENSURE_SUCCESS(rv, rv);
if (!mAppCache && (mLookupAppCache || mOfflineStorage)) {
rv = ChooseApplicationCache(cacheKey, getter_AddRefs(mAppCache));
NS_ENSURE_SUCCESS(rv, rv);
if (mAppCache) {
// From a chosen appcache open only as readonly
aFlags &= ~nsICacheStorage::OPEN_TRUNCATE;
}
}
RefPtr<_OldCacheLoad> cacheLoad = new _OldCacheLoad(
scheme, cacheKey, aCallback, mAppCache, mLoadInfo, mWriteToDisk, aFlags);
rv = cacheLoad->Start();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP _OldStorage::OpenTruncate(nsIURI* aURI,
const nsACString& aIdExtension,
nsICacheEntry** aCacheEntry) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP _OldStorage::Exists(nsIURI* aURI, const nsACString& aIdExtension,
bool* aResult) {
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP _OldStorage::AsyncDoomURI(nsIURI* aURI,
const nsACString& aIdExtension,
nsICacheEntryDoomCallback* aCallback) {
LOG(("_OldStorage::AsyncDoomURI"));
nsresult rv;
nsAutoCString cacheKey, scheme;
rv = AssembleCacheKey(aURI, aIdExtension, cacheKey, scheme);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICacheSession> session;
rv = GetCacheSession(scheme, mWriteToDisk, mLoadInfo, mAppCache,
getter_AddRefs(session));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<DoomCallbackWrapper> cb =
aCallback ? new DoomCallbackWrapper(aCallback) : nullptr;
rv = session->DoomEntry(cacheKey, cb);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP _OldStorage::AsyncEvictStorage(
nsICacheEntryDoomCallback* aCallback) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP _OldStorage::AsyncVisitStorage(nsICacheStorageVisitor* aVisitor,
bool aVisitEntries) {
LOG(("_OldStorage::AsyncVisitStorage"));
NS_ENSURE_ARG(aVisitor);
nsresult rv;
nsCOMPtr<nsICacheService> serv =
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
char* deviceID;
if (mAppCache || mOfflineStorage) {
deviceID = const_cast<char*>("offline");
} else if (!mWriteToDisk || mLoadInfo->IsPrivate()) {
deviceID = const_cast<char*>("memory");
} else {
deviceID = const_cast<char*>("disk");
}
RefPtr<_OldVisitCallbackWrapper> cb = new _OldVisitCallbackWrapper(
deviceID, aVisitor, aVisitEntries, mLoadInfo);
rv = nsCacheService::GlobalInstance()->VisitEntriesInternal(cb);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP _OldStorage::GetCacheIndexEntryAttrs(
nsIURI* aURI, const nsACString& aIdExtension, bool* aHasAltData,
uint32_t* aSizeInKB) {
return NS_ERROR_NOT_IMPLEMENTED;
}
// Internal
nsresult _OldStorage::AssembleCacheKey(nsIURI* aURI,
nsACString const& aIdExtension,
nsACString& aCacheKey,
nsACString& aScheme) {
// Copied from nsHttpChannel::AssembleCacheKey
aCacheKey.Truncate();
nsresult rv;
rv = aURI->GetScheme(aScheme);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString uriSpec;
if (aScheme.EqualsLiteral("http") || aScheme.EqualsLiteral("https")) {
if (mLoadInfo->IsAnonymous()) {
aCacheKey.AssignLiteral("anon&");
}
if (!aIdExtension.IsEmpty()) {
aCacheKey.AppendPrintf("id=%s&", aIdExtension.BeginReading());
}
nsCOMPtr<nsIURI> noRefURI;
rv = NS_GetURIWithoutRef(aURI, getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
rv = noRefURI->GetAsciiSpec(uriSpec);
NS_ENSURE_SUCCESS(rv, rv);
if (!aCacheKey.IsEmpty()) {
aCacheKey.AppendLiteral("uri=");
}
} else {
rv = aURI->GetAsciiSpec(uriSpec);
NS_ENSURE_SUCCESS(rv, rv);
}
aCacheKey.Append(uriSpec);
return NS_OK;
}
nsresult _OldStorage::ChooseApplicationCache(const nsACString& cacheKey,
nsIApplicationCache** aCache) {
return NS_ERROR_NOT_IMPLEMENTED;
}
} // namespace net
} // namespace mozilla

View File

@@ -1,268 +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/. */
// Stuff to link the old imp to the new api - will go away!
#ifndef OLDWRAPPERS__H__
#define OLDWRAPPERS__H__
#include "nsICacheEntry.h"
#include "nsICacheListener.h"
#include "nsICacheStorage.h"
#include "nsCOMPtr.h"
#include "nsICacheEntryOpenCallback.h"
#include "nsICacheEntryDescriptor.h"
#include "nsICacheStorageVisitor.h"
#include "nsThreadUtils.h"
#include "mozilla/TimeStamp.h"
class nsIURI;
class nsICacheEntryOpenCallback;
class nsICacheStorageConsumptionObserver;
class nsIApplicationCache;
class nsILoadContextInfo;
namespace mozilla {
namespace net {
class CacheStorage;
class _OldCacheEntryWrapper : public nsICacheEntry {
public:
NS_DECL_THREADSAFE_ISUPPORTS
// nsICacheEntryDescriptor
NS_IMETHOD SetExpirationTime(uint32_t expirationTime) override {
return !mOldDesc ? NS_ERROR_NULL_POINTER
: mOldDesc->SetExpirationTime(expirationTime);
}
nsresult OpenInputStream(uint32_t offset, nsIInputStream** _retval) {
return !mOldDesc ? NS_ERROR_NULL_POINTER
: mOldDesc->OpenInputStream(offset, _retval);
}
nsresult OpenOutputStream(uint32_t offset, nsIOutputStream** _retval) {
return !mOldDesc ? NS_ERROR_NULL_POINTER
: mOldDesc->OpenOutputStream(offset, _retval);
}
NS_IMETHOD OpenAlternativeOutputStream(
const nsACString& type, int64_t predictedSize,
nsIAsyncOutputStream** _retval) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD OpenAlternativeInputStream(const nsACString& type,
nsIInputStream** _retval) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD GetSecurityInfo(nsISupports** aSecurityInfo) override {
return !mOldDesc ? NS_ERROR_NULL_POINTER
: mOldDesc->GetSecurityInfo(aSecurityInfo);
}
NS_IMETHOD SetSecurityInfo(nsISupports* aSecurityInfo) override {
return !mOldDesc ? NS_ERROR_NULL_POINTER
: mOldDesc->SetSecurityInfo(aSecurityInfo);
}
NS_IMETHOD GetStorageDataSize(uint32_t* aStorageDataSize) override {
return !mOldDesc ? NS_ERROR_NULL_POINTER
: mOldDesc->GetStorageDataSize(aStorageDataSize);
}
nsresult AsyncDoom(nsICacheListener* listener) {
return !mOldDesc ? NS_ERROR_NULL_POINTER : mOldDesc->AsyncDoom(listener);
}
NS_IMETHOD MarkValid(void) override {
return !mOldDesc ? NS_ERROR_NULL_POINTER : mOldDesc->MarkValid();
}
NS_IMETHOD Close(void) override {
return !mOldDesc ? NS_ERROR_NULL_POINTER : mOldDesc->Close();
}
NS_IMETHOD GetMetaDataElement(const char* key, char** _retval) override {
return !mOldDesc ? NS_ERROR_NULL_POINTER
: mOldDesc->GetMetaDataElement(key, _retval);
}
NS_IMETHOD SetMetaDataElement(const char* key, const char* value) override {
return !mOldDesc ? NS_ERROR_NULL_POINTER
: mOldDesc->SetMetaDataElement(key, value);
}
NS_IMETHOD GetDiskStorageSizeInKB(uint32_t* aDiskStorageSize) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsICacheEntryInfo
NS_IMETHOD GetKey(nsACString& aKey) override {
return mOldInfo->GetKey(aKey);
}
NS_IMETHOD GetCacheEntryId(uint64_t* aCacheEntryId) override {
*aCacheEntryId = mCacheEntryId;
return NS_OK;
}
NS_IMETHOD GetFetchCount(int32_t* aFetchCount) override {
return mOldInfo->GetFetchCount(aFetchCount);
}
NS_IMETHOD GetLastFetched(uint32_t* aLastFetched) override {
return mOldInfo->GetLastFetched(aLastFetched);
}
NS_IMETHOD GetLastModified(uint32_t* aLastModified) override {
return mOldInfo->GetLastModified(aLastModified);
}
NS_IMETHOD GetExpirationTime(uint32_t* aExpirationTime) override {
return mOldInfo->GetExpirationTime(aExpirationTime);
}
nsresult GetDataSize(uint32_t* aDataSize) {
return mOldInfo->GetDataSize(aDataSize);
}
NS_IMETHOD GetOnStartTime(uint64_t* aTime) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD GetOnStopTime(uint64_t* aTime) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD SetNetworkTimes(uint64_t aOnStartTime,
uint64_t aOnStopTime) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD SetContentType(uint8_t aContentType) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD GetLoadContextInfo(nsILoadContextInfo** aInfo) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD Dismiss() override { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD AsyncDoom(nsICacheEntryDoomCallback* listener) override;
NS_IMETHOD GetPersistent(bool* aPersistToDisk) override;
NS_IMETHOD GetIsForcedValid(bool* aIsForcedValid) override;
NS_IMETHOD ForceValidFor(uint32_t aSecondsToTheFuture) override;
NS_IMETHOD SetValid() override { return NS_OK; }
NS_IMETHOD MetaDataReady() override { return NS_OK; }
NS_IMETHOD Recreate(bool, nsICacheEntry**) override;
NS_IMETHOD GetDataSize(int64_t* size) override;
NS_IMETHOD GetAltDataSize(int64_t* size) override;
NS_IMETHOD GetAltDataType(nsACString& aType) override;
NS_IMETHOD OpenInputStream(int64_t offset, nsIInputStream** _retval) override;
NS_IMETHOD OpenOutputStream(int64_t offset, int64_t predictedSize,
nsIOutputStream** _retval) override;
NS_IMETHOD MaybeMarkValid() override;
NS_IMETHOD HasWriteAccess(bool aWriteOnly, bool* aWriteAccess) override;
NS_IMETHOD VisitMetaData(nsICacheEntryMetaDataVisitor*) override;
explicit _OldCacheEntryWrapper(nsICacheEntryDescriptor* desc);
explicit _OldCacheEntryWrapper(nsICacheEntryInfo* info);
private:
virtual ~_OldCacheEntryWrapper();
_OldCacheEntryWrapper() = delete;
nsICacheEntryDescriptor* mOldDesc; // ref holded in mOldInfo
nsCOMPtr<nsICacheEntryInfo> mOldInfo;
const uint64_t mCacheEntryId;
};
class _OldCacheLoad : public Runnable, public nsICacheListener {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIRUNNABLE
NS_DECL_NSICACHELISTENER
_OldCacheLoad(const nsACString& aScheme, const nsACString& aCacheKey,
nsICacheEntryOpenCallback* aCallback,
nsIApplicationCache* aAppCache, nsILoadContextInfo* aLoadInfo,
bool aWriteToDisk, uint32_t aFlags);
nsresult Start();
protected:
virtual ~_OldCacheLoad();
private:
void Check();
nsCOMPtr<nsIEventTarget> mCacheThread;
nsCString const mScheme;
nsCString const mCacheKey;
nsCOMPtr<nsICacheEntryOpenCallback> mCallback;
nsCOMPtr<nsILoadContextInfo> mLoadInfo;
uint32_t const mFlags;
bool const mWriteToDisk : 1;
bool mNew : 1;
bool mOpening : 1;
bool mSync : 1;
nsCOMPtr<nsICacheEntry> mCacheEntry;
nsresult mStatus;
uint32_t mRunCount;
nsCOMPtr<nsIApplicationCache> mAppCache;
mozilla::TimeStamp mLoadStart;
};
class _OldStorage : public nsICacheStorage {
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSICACHESTORAGE
public:
_OldStorage(nsILoadContextInfo* aInfo, bool aAllowDisk, bool aLookupAppCache,
bool aOfflineStorage, nsIApplicationCache* aAppCache);
private:
virtual ~_OldStorage();
nsresult AssembleCacheKey(nsIURI* aURI, nsACString const& aIdExtension,
nsACString& aCacheKey, nsACString& aScheme);
nsresult ChooseApplicationCache(const nsACString& cacheKey,
nsIApplicationCache** aCache);
nsCOMPtr<nsILoadContextInfo> mLoadInfo;
nsCOMPtr<nsIApplicationCache> mAppCache;
bool const mWriteToDisk : 1;
bool const mLookupAppCache : 1;
bool const mOfflineStorage : 1;
};
class _OldVisitCallbackWrapper : public nsICacheVisitor {
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSICACHEVISITOR
_OldVisitCallbackWrapper(char const* deviceID, nsICacheStorageVisitor* cb,
bool visitEntries, nsILoadContextInfo* aInfo)
: mCB(cb),
mVisitEntries(visitEntries),
mDeviceID(deviceID),
mLoadInfo(aInfo),
mHit(false) {}
private:
virtual ~_OldVisitCallbackWrapper();
nsCOMPtr<nsICacheStorageVisitor> mCB;
bool mVisitEntries;
char const* mDeviceID;
nsCOMPtr<nsILoadContextInfo> mLoadInfo;
bool mHit; // set to true when the device was found
};
class _OldGetDiskConsumption : public Runnable, public nsICacheVisitor {
public:
static nsresult Get(nsICacheStorageConsumptionObserver* aCallback);
private:
explicit _OldGetDiskConsumption(
nsICacheStorageConsumptionObserver* aCallback);
virtual ~_OldGetDiskConsumption() = default;
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSICACHEVISITOR
NS_DECL_NSIRUNNABLE
nsCOMPtr<nsICacheStorageConsumptionObserver> mCallback;
int64_t mSize;
};
} // namespace net
} // namespace mozilla
#endif

View File

@@ -47,7 +47,6 @@ UNIFIED_SOURCES += [
"CacheLog.cpp",
"CacheObserver.cpp",
"CacheStorageService.cpp",
"OldWrappers.cpp",
]
LOCAL_INCLUDES += [

View File

@@ -36,13 +36,8 @@ interface nsICacheStorageService : nsISupports
/**
* Get storage where entries will be written to disk when not forbidden by
* response headers.
*
* @param aLookupAppCache
* When set true (for top level document loading channels) app cache will
* be first to check on to find entries in.
*/
nsICacheStorage diskCacheStorage(in nsILoadContextInfo aLoadContextInfo,
in bool aLookupAppCache);
nsICacheStorage diskCacheStorage(in nsILoadContextInfo aLoadContextInfo);
/**
* Get storage where entries will be written to disk and marked as pinned.

View File

@@ -214,8 +214,7 @@ nsresult nsAboutCache::GetStorage(nsACString const& storageName,
nsCOMPtr<nsICacheStorage> cacheStorage;
if (storageName == "disk") {
rv = cacheService->DiskCacheStorage(loadInfo, false,
getter_AddRefs(cacheStorage));
rv = cacheService->DiskCacheStorage(loadInfo, getter_AddRefs(cacheStorage));
} else if (storageName == "memory") {
rv = cacheService->MemoryCacheStorage(loadInfo,
getter_AddRefs(cacheStorage));

View File

@@ -60,7 +60,7 @@ nsresult CachePushChecker::DoCheck() {
RefPtr<LoadContextInfo> lci = GetLoadContextInfo(false, mOriginAttributes);
nsCOMPtr<nsICacheStorage> ds;
rv = css->DiskCacheStorage(lci, false, getter_AddRefs(ds));
rv = css->DiskCacheStorage(lci, getter_AddRefs(ds));
if (NS_FAILED(rv)) {
return rv;
}

View File

@@ -3440,7 +3440,7 @@ nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) {
} else {
// Try to race only if we use disk cache storage
maybeRCWN = mRequestHead.IsSafeMethod();
rv = cacheStorageService->DiskCacheStorage(info, /* lookupAppcache */ false,
rv = cacheStorageService->DiskCacheStorage(info,
getter_AddRefs(cacheStorage));
}
NS_ENSURE_SUCCESS(rv, rv);
@@ -4534,7 +4534,7 @@ void nsHttpChannel::MaybeCreateCacheEntryWhenRCWN() {
nsCOMPtr<nsICacheStorage> cacheStorage;
RefPtr<LoadContextInfo> info = GetLoadContextInfo(this);
Unused << cacheStorageService->DiskCacheStorage(info, false,
Unused << cacheStorageService->DiskCacheStorage(info,
getter_AddRefs(cacheStorage));
if (!cacheStorage) {
return;
@@ -8317,7 +8317,7 @@ void nsHttpChannel::DoInvalidateCacheEntry(nsIURI* aURI) {
nsCOMPtr<nsICacheStorage> cacheStorage;
if (NS_SUCCEEDED(rv)) {
RefPtr<LoadContextInfo> info = GetLoadContextInfo(this);
rv = cacheStorageService->DiskCacheStorage(info, false,
rv = cacheStorageService->DiskCacheStorage(info,
getter_AddRefs(cacheStorage));
}

View File

@@ -29,7 +29,7 @@ function evict_cache_entries(where) {
}
if (clearDisk) {
storage = svc.diskCacheStorage(Services.loadContextInfo.default, false);
storage = svc.diskCacheStorage(Services.loadContextInfo.default);
storage.asyncEvictStorage(null);
}
}
@@ -48,7 +48,7 @@ function getCacheStorage(where, lci) {
var svc = get_cache_service();
switch (where) {
case "disk":
return svc.diskCacheStorage(lci, false);
return svc.diskCacheStorage(lci);
case "memory":
return svc.memoryCacheStorage(lci);
case "pin":

View File

@@ -10,7 +10,7 @@
function doom(url, callback) {
get_cache_service()
.diskCacheStorage(Services.loadContextInfo.default, false)
.diskCacheStorage(Services.loadContextInfo.default)
.asyncDoomURI(createURI(url), "", {
onCacheEntryDoomed(result) {
callback(result);

View File

@@ -173,10 +173,7 @@ var prepListener = {
};
function open_and_continue(uris, continueCallback) {
var ds = Services.cache2.diskCacheStorage(
Services.loadContextInfo.default,
false
);
var ds = Services.cache2.diskCacheStorage(Services.loadContextInfo.default);
prepListener.init(uris.length, continueCallback);
for (var i = 0; i < uris.length; ++i) {

View File

@@ -32,7 +32,7 @@ async function checkCache(suffixes, originAttributes) {
};
// Visiting the disk cache also visits memory storage so we do not
// need to use Services.cache2.memoryCacheStorage() here.
let storage = Services.cache2.diskCacheStorage(loadContextInfo, false);
let storage = Services.cache2.diskCacheStorage(loadContextInfo);
storage.asyncVisitStorage(cacheVisitor, true);
});

View File

@@ -41,7 +41,7 @@ async function checkCache(originAttributes) {
};
// Visiting the disk cache also visits memory storage so we do not
// need to use Services.cache2.memoryCacheStorage() here.
let storage = Services.cache2.diskCacheStorage(loadContextInfo, false);
let storage = Services.cache2.diskCacheStorage(loadContextInfo);
storage.asyncVisitStorage(cacheVisitor, true);
});

View File

@@ -41,7 +41,7 @@ async function checkCache(originAttributes) {
};
// Visiting the disk cache also visits memory storage so we do not
// need to use Services.cache2.memoryCacheStorage() here.
let storage = Services.cache2.diskCacheStorage(loadContextInfo, false);
let storage = Services.cache2.diskCacheStorage(loadContextInfo);
storage.asyncVisitStorage(cacheVisitor, true);
});

View File

@@ -949,7 +949,7 @@ const AboutHomeStartupCacheCleaner = {
return new Promise((aResolve, aReject) => {
let lci = Services.loadContextInfo.default;
let storage = Services.cache2.diskCacheStorage(lci, false);
let storage = Services.cache2.diskCacheStorage(lci);
let uri = Services.io.newURI("about:home");
try {
storage.asyncDoomURI(uri, "", {

View File

@@ -243,7 +243,7 @@ var SiteDataTestUtils = {
_getCacheStorage(where, lci) {
switch (where) {
case "disk":
return Services.cache2.diskCacheStorage(lci, false);
return Services.cache2.diskCacheStorage(lci);
case "memory":
return Services.cache2.memoryCacheStorage(lci);
case "pin":

View File

@@ -24,8 +24,7 @@ function countCacheEntries() {
info("Enumerating cache entries");
return new Promise(resolve => {
let storage = Services.cache2.diskCacheStorage(
Services.loadContextInfo.default,
false
Services.loadContextInfo.default
);
storage.asyncVisitStorage(
{