зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1907014 - Make SharedSubResourceCache subclass instance a per-process singleton. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D217709
This commit is contained in:
Родитель
a419c570f0
Коммит
da4b1ab361
|
@ -151,8 +151,8 @@ void SharedScriptCache::Clear(nsIPrincipal* aForPrincipal,
|
|||
}
|
||||
}
|
||||
|
||||
if (sInstance) {
|
||||
sInstance->ClearInProcess(aForPrincipal, aBaseDomain);
|
||||
if (sSingleton) {
|
||||
sSingleton->ClearInProcess(aForPrincipal, aBaseDomain);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -212,8 +212,8 @@ void SharedStyleSheetCache::Clear(nsIPrincipal* aForPrincipal,
|
|||
}
|
||||
}
|
||||
|
||||
if (sInstance) {
|
||||
sInstance->ClearInProcess(aForPrincipal, aBaseDomain);
|
||||
if (sSingleton) {
|
||||
sSingleton->ClearInProcess(aForPrincipal, aBaseDomain);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "mozilla/StoragePrincipalHelper.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -91,21 +92,22 @@ class SharedSubResourceCache {
|
|||
SharedSubResourceCache(SharedSubResourceCache&&) = delete;
|
||||
SharedSubResourceCache() = default;
|
||||
|
||||
static already_AddRefed<Derived> Get() {
|
||||
static Derived* Get() {
|
||||
static_assert(
|
||||
std::is_base_of_v<SharedSubResourceCacheLoadingValueBase<LoadingValue>,
|
||||
LoadingValue>);
|
||||
|
||||
if (sInstance) {
|
||||
return do_AddRef(sInstance);
|
||||
if (sSingleton) {
|
||||
return sSingleton.get();
|
||||
}
|
||||
MOZ_DIAGNOSTIC_ASSERT(!sInstance);
|
||||
RefPtr<Derived> cache = new Derived();
|
||||
cache->Init();
|
||||
sInstance = cache.get();
|
||||
return cache.forget();
|
||||
MOZ_DIAGNOSTIC_ASSERT(!sSingleton);
|
||||
sSingleton = new Derived();
|
||||
sSingleton->Init();
|
||||
return sSingleton.get();
|
||||
}
|
||||
|
||||
static void DeleteSingleton() { sSingleton = nullptr; }
|
||||
|
||||
public:
|
||||
struct Result {
|
||||
Value* mCompleteValue = nullptr;
|
||||
|
@ -159,11 +161,6 @@ class SharedSubResourceCache {
|
|||
protected:
|
||||
void CancelPendingLoadsForLoader(Loader&);
|
||||
|
||||
~SharedSubResourceCache() {
|
||||
MOZ_DIAGNOSTIC_ASSERT(sInstance == this);
|
||||
sInstance = nullptr;
|
||||
}
|
||||
|
||||
struct CompleteSubResource {
|
||||
RefPtr<Value> mResource;
|
||||
uint32_t mExpirationTime = 0;
|
||||
|
@ -188,7 +185,9 @@ class SharedSubResourceCache {
|
|||
nsTHashMap<PrincipalHashKey, uint32_t> mLoaderPrincipalRefCnt;
|
||||
|
||||
protected:
|
||||
inline static Derived* sInstance;
|
||||
// Lazily created in the first Get() call.
|
||||
// The singleton should be deleted by DeleteSingleton() during shutdown.
|
||||
inline static StaticRefPtr<Derived> sSingleton;
|
||||
};
|
||||
|
||||
template <typename Traits, typename Derived>
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "nsXPCOMCIDInternal.h"
|
||||
|
||||
#include "mozilla/dom/JSExecutionManager.h"
|
||||
#include "mozilla/dom/SharedScriptCache.h"
|
||||
#include "mozilla/SharedStyleSheetCache.h"
|
||||
#include "mozilla/layers/ImageBridgeChild.h"
|
||||
#include "mozilla/layers/CompositorBridgeParent.h"
|
||||
|
||||
|
@ -751,6 +753,9 @@ nsresult ShutdownXPCOM(nsIServiceManager* aServMgr) {
|
|||
|
||||
mozilla::ScriptPreloader::DeleteCacheDataSingleton();
|
||||
|
||||
mozilla::dom::SharedScriptCache::DeleteSingleton();
|
||||
mozilla::SharedStyleSheetCache::DeleteSingleton();
|
||||
|
||||
// Release shared memory which might be borrowed by the JS engine.
|
||||
xpc::SelfHostedShmem::Shutdown();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче