mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
159d7b9c2f
- Bug 967693 - Temporarily turn on HTTP cache v2 on for Desktop Firefox Nightly users, r=jduell+ehsan (0fb43bca09)
- Bug 1230939 - check the return of sGlobalEntryTables->Get(aContextKey, &diskEntries). r=mayhemer (da62f5bd04)
- fix header include (52d6efa786)
- Bug 1193605 - Part 3: do not stop non-started service; r=mcmanus (dfe2187f22)
- Bug 1193605 - Part 4: add UUID for listeners; r=mcmanus (fee78fd19d)
- Bug 1214176 - fix typo in _onOffer. r=junior. (b388d1f2a6)
- align test to 1216398 (74d505d1d6)
- Bug 1228457 create pref to allow blocking .onion at dns level rfc 7687 r=valentin.gosu (521aab1e58)
- Bug 1216370 - For safety and searchability, define the nsHostResolver::RES_* enum in terms of the nsIDNSService::RESOLVE_* enum. r=mayhemer (84c22f815f)
- Bug 1194763 - Ensure non-cluster-start flag is set properly for a run-initial supplementary-plane combining mark when shaping text. r=jdaggett (17c3ad163d)
- Bug 1168176 - Mark gfxFontShaper::mFont as MOZ_NON_OWNING_REF. r=jtd (0f3ca78c16)
- Bug 1167403 - Mark gfxFont::GlyphChangeObserver::mFont as MOZ_NON_OWNING_REF. r=jtd (ec77538943)
- align gfxContext to pre-1232822 (part 6) (bb7fa256c9)
- Bug 1231889 - Moz2Dify gfxWindowsNativeDrawing::PaintToContext(). r=mattwoodrow. (69b1d62395)
- Bug 1231864 (part 1) - Remove useless GetCairo() call in gfxWindowsNativeDrawing::BeginNativeDrawing(). r=mattwoodrow. (aa3017c392)
- Bug 1231864 (part 2) - Clean up gfxWindowsNativeDrawing::BeginNativeDrawing(). r=mattwoodrow. (860a81ba59)
- Bug 1225682 - Don't use nsAuto{,C}String as class member variables in gfx/. r=jrmuizel (a1cc11b749)
- Bug 1230611 - Make gfxWindowsPlatform::SupportsApzTouchInput use a pref cache to speed it up. r=dvander (4026e5dfe8)
- Bug 1193842 - Delete touch resampling preference and non resampling paths. r=kats (ff58c7753c)
- Bug 1177335 - Skip resampling if the time difference of touches is less than 2ms. (b98e40343d)
- Bug 1204518 - Fix warnings in widget/gonk/. r=mwu. (ddc13a4c24)
- Bug 1231832. Make IsActive work on Querys that have not begun. r=jgilbert (4b70a8fb0b)
- Bug 1218881. Enforce queries' new availability semantics. r=jgilbert (503bf80f8b)
- Bug 1233858 - Part 1 - ensure Skia's SkGraphics::Init is called from gfxPlatform::Init. r=jmuizelaar (db5fde96b1)
- Bug 1233858 -Part 2 - implement runtime-detected SSE2 optimizations for Skia. r=jmuizelaar (3c9ebaa64d)
- Bug 1233858 - work around Skia __vectorcall bugs on Win32. r=jmuizelaar (b5b5e2bbcf)
- Bug 1222569 - remove unused function from gfxPlatformFontList.cpp; r=Bas (68e1615eb2)
- Bug 1234566: Use LoadLibraryA instead of LoadLibrary in some skia Windows code to allow UNICODE to be defined. r=lsalzman (e45bf51ef7)
- Bug 1156742 Part 1: Change Moz2D recording, so that it can be used in isolation. r=bas (f02fd4992b)
- Bug 1156742 Part 2: Make gfx thebes/gl/2d work with UNICODE defined. r=bas, r=glandium (8fca45d9a3)
- Bug 1156742 Part 3: Add support for FontType::CAIRO to CreateScaledFontForTrueTypeData on Windows. r=bas (863ea539c4)
- Bug 1156742 Part 4: Add an in memory DrawEventRecorder. r=bas (c9196512a1)
- Bug 1156742 Part 5: Add a skeleton RemotePrintJob. r=mconley (aa48df9f32)
- Bug 1156742 Part 6: Add RemotePrintJob to PrintSession and PrintData. r=roc, r=mconley (607a3e6b9b)
- Bug 1233444 - add override declarations for widget/windows/; r=roc (edab847cb0)
- Bug 1156742 Part 7: Refactor nsDeviceContext.cpp to use printing surface for size and nsIDeviceContextSpec for DPI and scale. r=roc (ec6ff3d592)
- Bug 1156742 Part 8: Change gfxWindowsSurface, so that a non-printing surface can be used when recording a print. r=roc (1ab167635e)
- Bug 1156742 Part 9: Add a new nsIDeviceContextSpec for proxied printing. r=roc (11c3909a8f)
- Bug 1156742 Part 10: Allow RemotePrintJob to influence nsPagePrintTimer. r=roc (c658e96338)
- Bug 1156742 Part 11: Allow RemotePrintJobChild to abort the print. r=roc (30f3e9bce4)
- Bug 1156742 Part 12: Record CreateSimilarDrawTarget separately for Moz2D. r=bas (a978b691c3)
- Bug 1156742 Part 13: Create a Moz2D PrintTranslator. r=bas (1eca4e9b33)
- Bug 1156742 Part 14: Complete RemotePrintJob using PrintTranslator. r=mconley (7db80f0ba7)
- Bug 1156742 Part 15: Add pref for turning on printing via the parent process. r=mconley (e3dbf281ea)
- Bug 1156742 Part 16: Add recording and forwarding of Matrix attribute set for Moz2D recording. r=bas (cd5da598ea)
- Bug 1156742 Part 17: Add virtual destructor to RecorededEvent and fix subsequent crash with DWrite playback fonts. r=bas (c20a0b84fc)
- Bug 1156742 Part 18: Fix the way we hold custom font data so that they can be recorded with Moz2D. r=bas (54b4630927)
- Bug 1156742 Part 19: Implement GetFontFileData for ScaledFontWin. r=bas (f1df40b31b)
- Bug 1156742 Part 20: Move Moz2D PreferenceAccess into its own header. r=bas (0afdff8e14)
- Bug 1156742 Part 21: Use GetDirect3D11Device instead of DrawTargetD2D::GetDWriteFactory to determine if DWrite fonts should be used. r=Bas (0c87a5866d)
- Bug 1156742 Part 22: Change ScaledFontDWrite to support creation from TrueType Collection data. r=bas (5f2c607e64)
- Bug 1156742 Part 23: Assert in PrintTranslator when a lookup fails. r=bas (72e24c789f)
- Bug 1156742 Part 24: Add new Recorded event to record font data. r=bas (a0c6f951aa)
- Bug 1156742 Part 25: Flip the big switch and wait for the lightning. r=mconley (082a1a3ede)
- Bug 1203232 - Fix -Wshadow warnings in some ipc/chromium headers. r=njn (018499b8a1)
- Bug 1089837 - Make IPC::Message use MOZ_COUNT_CTOR/DTOR. r=jld (124e011902)
- Bug 1235234 - Fix unintentional switch fallthrough in ipc/chromium/ found by -Wimplicit-fallthrough warning. r=gcp (af37d85c1c)
- Bug 1207498 - Part 2: Remove use of expression closure from tests in toolkit/components/. r=Gijs (98915956bd)
- Bug 1157282 - Add test coverage for telemetry histogram recording. r=gfritzsche (f403b07c7f)
- Bug 1228147: part 1: Add telemetry RecordingEnabled support. r=gfritzsche f=froydnj (610c92394f)
- Bug 1228147: part 2: Add telemetry probe for synchronous scroll. r=kats (6816099c37)
- Bug 1201492 - Remove extended_statistics_ok from Telemetry histograms. r=dexter (f7f991249f)
- Bug 842894 - Support DirectWrite using the Skia backend. r=bas (f2487cf863)
486 lines
15 KiB
C++
486 lines
15 KiB
C++
/* 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 "CacheObserver.h"
|
|
|
|
#include "CacheStorageService.h"
|
|
#include "CacheFileIOManager.h"
|
|
#include "LoadContextInfo.h"
|
|
#include "nsICacheStorage.h"
|
|
#include "nsIObserverService.h"
|
|
#include "mozilla/Services.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "prsystem.h"
|
|
#include <time.h>
|
|
#include <math.h>
|
|
|
|
namespace mozilla {
|
|
namespace net {
|
|
|
|
CacheObserver* CacheObserver::sSelf = nullptr;
|
|
|
|
static uint32_t const kDefaultUseNewCache = 1; // Use the new cache by default
|
|
uint32_t CacheObserver::sUseNewCache = kDefaultUseNewCache;
|
|
|
|
static bool sUseNewCacheTemp = false; // Temp trigger to not lose early adopters
|
|
|
|
static int32_t const kAutoDeleteCacheVersion = -1; // Auto-delete off by default
|
|
static int32_t sAutoDeleteCacheVersion = kAutoDeleteCacheVersion;
|
|
|
|
static int32_t const kDefaultHalfLifeExperiment = -1; // Disabled
|
|
int32_t CacheObserver::sHalfLifeExperiment = kDefaultHalfLifeExperiment;
|
|
|
|
static float const kDefaultHalfLifeHours = 1.0F; // 1 hour
|
|
float CacheObserver::sHalfLifeHours = kDefaultHalfLifeHours;
|
|
|
|
static bool const kDefaultUseDiskCache = true;
|
|
bool CacheObserver::sUseDiskCache = kDefaultUseDiskCache;
|
|
|
|
static bool const kDefaultUseMemoryCache = true;
|
|
bool CacheObserver::sUseMemoryCache = kDefaultUseMemoryCache;
|
|
|
|
static uint32_t const kDefaultMetadataMemoryLimit = 250; // 0.25 MB
|
|
uint32_t CacheObserver::sMetadataMemoryLimit = kDefaultMetadataMemoryLimit;
|
|
|
|
static int32_t const kDefaultMemoryCacheCapacity = -1; // autodetect
|
|
int32_t CacheObserver::sMemoryCacheCapacity = kDefaultMemoryCacheCapacity;
|
|
// Cache of the calculated memory capacity based on the system memory size
|
|
int32_t CacheObserver::sAutoMemoryCacheCapacity = -1;
|
|
|
|
static uint32_t const kDefaultDiskCacheCapacity = 250 * 1024; // 250 MB
|
|
uint32_t CacheObserver::sDiskCacheCapacity = kDefaultDiskCacheCapacity;
|
|
|
|
static uint32_t const kDefaultDiskFreeSpaceSoftLimit = 5 * 1024; // 5MB
|
|
uint32_t CacheObserver::sDiskFreeSpaceSoftLimit = kDefaultDiskFreeSpaceSoftLimit;
|
|
|
|
static uint32_t const kDefaultDiskFreeSpaceHardLimit = 1024; // 1MB
|
|
uint32_t CacheObserver::sDiskFreeSpaceHardLimit = kDefaultDiskFreeSpaceHardLimit;
|
|
|
|
static bool const kDefaultSmartCacheSizeEnabled = false;
|
|
bool CacheObserver::sSmartCacheSizeEnabled = kDefaultSmartCacheSizeEnabled;
|
|
|
|
static uint32_t const kDefaultPreloadChunkCount = 4;
|
|
uint32_t CacheObserver::sPreloadChunkCount = kDefaultPreloadChunkCount;
|
|
|
|
static int32_t const kDefaultMaxMemoryEntrySize = 4 * 1024; // 4 MB
|
|
int32_t CacheObserver::sMaxMemoryEntrySize = kDefaultMaxMemoryEntrySize;
|
|
|
|
static int32_t const kDefaultMaxDiskEntrySize = 50 * 1024; // 50 MB
|
|
int32_t CacheObserver::sMaxDiskEntrySize = kDefaultMaxDiskEntrySize;
|
|
|
|
static uint32_t const kDefaultMaxDiskChunksMemoryUsage = 10 * 1024; // 10MB
|
|
uint32_t CacheObserver::sMaxDiskChunksMemoryUsage = kDefaultMaxDiskChunksMemoryUsage;
|
|
|
|
static uint32_t const kDefaultMaxDiskPriorityChunksMemoryUsage = 10 * 1024; // 10MB
|
|
uint32_t CacheObserver::sMaxDiskPriorityChunksMemoryUsage = kDefaultMaxDiskPriorityChunksMemoryUsage;
|
|
|
|
static uint32_t const kDefaultCompressionLevel = 1;
|
|
uint32_t CacheObserver::sCompressionLevel = kDefaultCompressionLevel;
|
|
|
|
static bool kDefaultSanitizeOnShutdown = false;
|
|
bool CacheObserver::sSanitizeOnShutdown = kDefaultSanitizeOnShutdown;
|
|
|
|
static bool kDefaultClearCacheOnShutdown = false;
|
|
bool CacheObserver::sClearCacheOnShutdown = kDefaultClearCacheOnShutdown;
|
|
|
|
NS_IMPL_ISUPPORTS(CacheObserver,
|
|
nsIObserver,
|
|
nsISupportsWeakReference)
|
|
|
|
// static
|
|
nsresult
|
|
CacheObserver::Init()
|
|
{
|
|
if (sSelf) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
if (!obs) {
|
|
return NS_ERROR_UNEXPECTED;
|
|
}
|
|
|
|
sSelf = new CacheObserver();
|
|
NS_ADDREF(sSelf);
|
|
|
|
obs->AddObserver(sSelf, "prefservice:after-app-defaults", true);
|
|
obs->AddObserver(sSelf, "profile-do-change", true);
|
|
obs->AddObserver(sSelf, "browser-delayed-startup-finished", true);
|
|
obs->AddObserver(sSelf, "profile-before-change", true);
|
|
obs->AddObserver(sSelf, "xpcom-shutdown", true);
|
|
obs->AddObserver(sSelf, "last-pb-context-exited", true);
|
|
obs->AddObserver(sSelf, "clear-origin-data", true);
|
|
obs->AddObserver(sSelf, "memory-pressure", true);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// static
|
|
nsresult
|
|
CacheObserver::Shutdown()
|
|
{
|
|
if (!sSelf) {
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
}
|
|
|
|
NS_RELEASE(sSelf);
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
CacheObserver::AttachToPreferences()
|
|
{
|
|
sAutoDeleteCacheVersion = mozilla::Preferences::GetInt(
|
|
"browser.cache.auto_delete_cache_version", kAutoDeleteCacheVersion);
|
|
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sUseNewCache, "browser.cache.use_new_backend", kDefaultUseNewCache);
|
|
mozilla::Preferences::AddBoolVarCache(
|
|
&sUseNewCacheTemp, "browser.cache.use_new_backend_temp", false);
|
|
|
|
mozilla::Preferences::AddBoolVarCache(
|
|
&sUseDiskCache, "browser.cache.disk.enable", kDefaultUseDiskCache);
|
|
mozilla::Preferences::AddBoolVarCache(
|
|
&sUseMemoryCache, "browser.cache.memory.enable", kDefaultUseMemoryCache);
|
|
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sMetadataMemoryLimit, "browser.cache.disk.metadata_memory_limit", kDefaultMetadataMemoryLimit);
|
|
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sDiskCacheCapacity, "browser.cache.disk.capacity", kDefaultDiskCacheCapacity);
|
|
mozilla::Preferences::AddBoolVarCache(
|
|
&sSmartCacheSizeEnabled, "browser.cache.disk.smart_size.enabled", kDefaultSmartCacheSizeEnabled);
|
|
mozilla::Preferences::AddIntVarCache(
|
|
&sMemoryCacheCapacity, "browser.cache.memory.capacity", kDefaultMemoryCacheCapacity);
|
|
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sDiskFreeSpaceSoftLimit, "browser.cache.disk.free_space_soft_limit", kDefaultDiskFreeSpaceSoftLimit);
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sDiskFreeSpaceHardLimit, "browser.cache.disk.free_space_hard_limit", kDefaultDiskFreeSpaceHardLimit);
|
|
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sPreloadChunkCount, "browser.cache.disk.preload_chunk_count", kDefaultPreloadChunkCount);
|
|
|
|
mozilla::Preferences::AddIntVarCache(
|
|
&sMaxDiskEntrySize, "browser.cache.disk.max_entry_size", kDefaultMaxDiskEntrySize);
|
|
mozilla::Preferences::AddIntVarCache(
|
|
&sMaxMemoryEntrySize, "browser.cache.memory.max_entry_size", kDefaultMaxMemoryEntrySize);
|
|
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sMaxDiskChunksMemoryUsage, "browser.cache.disk.max_chunks_memory_usage", kDefaultMaxDiskChunksMemoryUsage);
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sMaxDiskPriorityChunksMemoryUsage, "browser.cache.disk.max_priority_chunks_memory_usage", kDefaultMaxDiskPriorityChunksMemoryUsage);
|
|
|
|
// http://mxr.mozilla.org/mozilla-central/source/netwerk/cache/nsCacheEntryDescriptor.cpp#367
|
|
mozilla::Preferences::AddUintVarCache(
|
|
&sCompressionLevel, "browser.cache.compression_level", kDefaultCompressionLevel);
|
|
|
|
mozilla::Preferences::GetComplex(
|
|
"browser.cache.disk.parent_directory", NS_GET_IID(nsIFile),
|
|
getter_AddRefs(mCacheParentDirectoryOverride));
|
|
|
|
// First check the default value. If it is at -1, the experient
|
|
// is turned off. If it is at 0, then use the user pref value
|
|
// instead.
|
|
sHalfLifeExperiment = mozilla::Preferences::GetDefaultInt(
|
|
"browser.cache.frecency_experiment", kDefaultHalfLifeExperiment);
|
|
|
|
if (sHalfLifeExperiment == 0) {
|
|
// Default preferences indicate we want to run the experiment,
|
|
// hence read the user value.
|
|
sHalfLifeExperiment = mozilla::Preferences::GetInt(
|
|
"browser.cache.frecency_experiment", sHalfLifeExperiment);
|
|
}
|
|
|
|
if (sHalfLifeExperiment == 0) {
|
|
// The experiment has not yet been initialized but is engaged, do
|
|
// the initialization now.
|
|
srand(time(NULL));
|
|
sHalfLifeExperiment = (rand() % 4) + 1;
|
|
// Store the experiemnt value, since we need it not to change between
|
|
// browser sessions.
|
|
mozilla::Preferences::SetInt(
|
|
"browser.cache.frecency_experiment", sHalfLifeExperiment);
|
|
}
|
|
|
|
switch (sHalfLifeExperiment) {
|
|
case 1: // The experiment is engaged
|
|
sHalfLifeHours = 0.083F; // ~5 mintues
|
|
break;
|
|
case 2:
|
|
sHalfLifeHours = 0.25F; // 15 mintues
|
|
break;
|
|
case 3:
|
|
sHalfLifeHours = 1.0F;
|
|
break;
|
|
case 4:
|
|
sHalfLifeHours = 6.0F;
|
|
break;
|
|
|
|
case -1:
|
|
default: // The experiment is off or broken
|
|
sHalfLifeExperiment = -1;
|
|
sHalfLifeHours = std::max(0.01F, std::min(1440.0F, mozilla::Preferences::GetFloat(
|
|
"browser.cache.frecency_half_life_hours", kDefaultHalfLifeHours)));
|
|
break;
|
|
}
|
|
|
|
mozilla::Preferences::AddBoolVarCache(
|
|
&sSanitizeOnShutdown, "privacy.sanitize.sanitizeOnShutdown", kDefaultSanitizeOnShutdown);
|
|
mozilla::Preferences::AddBoolVarCache(
|
|
&sClearCacheOnShutdown, "privacy.clearOnShutdown.cache", kDefaultClearCacheOnShutdown);
|
|
}
|
|
|
|
// static
|
|
uint32_t const CacheObserver::MemoryCacheCapacity()
|
|
{
|
|
if (sMemoryCacheCapacity >= 0)
|
|
return sMemoryCacheCapacity << 10;
|
|
|
|
if (sAutoMemoryCacheCapacity != -1)
|
|
return sAutoMemoryCacheCapacity;
|
|
|
|
static uint64_t bytes = PR_GetPhysicalMemorySize();
|
|
// 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;
|
|
|
|
int32_t capacity = 0;
|
|
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 <<= 20;
|
|
}
|
|
|
|
// Result is in bytes.
|
|
return sAutoMemoryCacheCapacity = capacity;
|
|
}
|
|
|
|
// static
|
|
bool const CacheObserver::UseNewCache()
|
|
{
|
|
uint32_t useNewCache = sUseNewCache;
|
|
|
|
if (sUseNewCacheTemp)
|
|
useNewCache = 1;
|
|
|
|
switch (useNewCache) {
|
|
case 0: // use the old cache backend
|
|
return false;
|
|
|
|
case 1: // use the new cache backend
|
|
return true;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// static
|
|
void
|
|
CacheObserver::SetDiskCacheCapacity(uint32_t aCapacity)
|
|
{
|
|
sDiskCacheCapacity = aCapacity >> 10;
|
|
|
|
if (!sSelf) {
|
|
return;
|
|
}
|
|
|
|
if (NS_IsMainThread()) {
|
|
sSelf->StoreDiskCacheCapacity();
|
|
} else {
|
|
nsCOMPtr<nsIRunnable> event =
|
|
NS_NewRunnableMethod(sSelf, &CacheObserver::StoreDiskCacheCapacity);
|
|
NS_DispatchToMainThread(event);
|
|
}
|
|
}
|
|
|
|
void
|
|
CacheObserver::StoreDiskCacheCapacity()
|
|
{
|
|
mozilla::Preferences::SetInt("browser.cache.disk.capacity",
|
|
sDiskCacheCapacity);
|
|
}
|
|
|
|
// static
|
|
void CacheObserver::ParentDirOverride(nsIFile** aDir)
|
|
{
|
|
if (NS_WARN_IF(!aDir))
|
|
return;
|
|
|
|
*aDir = nullptr;
|
|
|
|
if (!sSelf)
|
|
return;
|
|
if (!sSelf->mCacheParentDirectoryOverride)
|
|
return;
|
|
|
|
sSelf->mCacheParentDirectoryOverride->Clone(aDir);
|
|
}
|
|
|
|
namespace {
|
|
namespace CacheStorageEvictHelper {
|
|
|
|
nsresult ClearStorage(bool const aPrivate,
|
|
bool const aAnonymous,
|
|
OriginAttributes const &aOa)
|
|
{
|
|
nsresult rv;
|
|
|
|
RefPtr<LoadContextInfo> info = GetLoadContextInfo(aPrivate, aAnonymous, aOa);
|
|
|
|
nsCOMPtr<nsICacheStorage> storage;
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
|
NS_ENSURE_TRUE(service, NS_ERROR_FAILURE);
|
|
|
|
// Clear disk storage
|
|
rv = service->DiskCacheStorage(info, false, getter_AddRefs(storage));
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
rv = storage->AsyncEvictStorage(nullptr);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Clear memory storage
|
|
rv = service->MemoryCacheStorage(info, getter_AddRefs(storage));
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
rv = storage->AsyncEvictStorage(nullptr);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult Run(OriginAttributes const &aOa)
|
|
{
|
|
nsresult rv;
|
|
|
|
// Clear all [private X anonymous] combinations
|
|
rv = ClearStorage(false, false, aOa);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
rv = ClearStorage(false, true, aOa);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
rv = ClearStorage(true, false, aOa);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
rv = ClearStorage(true, true, aOa);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
} // CacheStorageEvictHelper
|
|
} // anon
|
|
|
|
// static
|
|
bool const CacheObserver::EntryIsTooBig(int64_t aSize, bool aUsingDisk)
|
|
{
|
|
// If custom limit is set, check it.
|
|
int64_t preferredLimit = aUsingDisk ? sMaxDiskEntrySize : sMaxMemoryEntrySize;
|
|
|
|
// do not convert to bytes when the limit is -1, which means no limit
|
|
if (preferredLimit > 0) {
|
|
preferredLimit <<= 10;
|
|
}
|
|
|
|
if (preferredLimit != -1 && aSize > preferredLimit)
|
|
return true;
|
|
|
|
// Otherwise (or when in the custom limit), check limit based on the global
|
|
// limit. It's 1/8 (>> 3) of the respective capacity.
|
|
int64_t derivedLimit = aUsingDisk
|
|
? (static_cast<int64_t>(DiskCacheCapacity() >> 3))
|
|
: (static_cast<int64_t>(MemoryCacheCapacity() >> 3));
|
|
|
|
if (aSize > derivedLimit)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
CacheObserver::Observe(nsISupports* aSubject,
|
|
const char* aTopic,
|
|
const char16_t* aData)
|
|
{
|
|
if (!strcmp(aTopic, "prefservice:after-app-defaults")) {
|
|
CacheFileIOManager::Init();
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!strcmp(aTopic, "profile-do-change")) {
|
|
AttachToPreferences();
|
|
CacheFileIOManager::Init();
|
|
CacheFileIOManager::OnProfile();
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!strcmp(aTopic, "browser-delayed-startup-finished")) {
|
|
uint32_t activeVersion = UseNewCache() ? 1 : 0;
|
|
CacheStorageService::CleaupCacheDirectories(sAutoDeleteCacheVersion, activeVersion);
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!strcmp(aTopic, "profile-before-change")) {
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
|
if (service)
|
|
service->Shutdown();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
|
if (service)
|
|
service->Shutdown();
|
|
|
|
CacheFileIOManager::Shutdown();
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!strcmp(aTopic, "last-pb-context-exited")) {
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
|
if (service)
|
|
service->DropPrivateBrowsingEntries();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!strcmp(aTopic, "clear-origin-data")) {
|
|
OriginAttributes oa;
|
|
if (!oa.Init(nsDependentString(aData))) {
|
|
NS_ERROR("Could not parse OriginAttributes JSON in clear-origin-data notification");
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult rv = CacheStorageEvictHelper::Run(oa);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!strcmp(aTopic, "memory-pressure")) {
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
|
if (service)
|
|
service->PurgeFromMemory(nsICacheStorageService::PURGE_EVERYTHING);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
MOZ_ASSERT(false, "Missing observer handler");
|
|
return NS_OK;
|
|
}
|
|
|
|
} // namespace net
|
|
} // namespace mozilla
|