mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
b3d6afc844
- bits of Bug 571294 - Part 1: Implement selection events (8af4ef3f65) - Bug 1208885 - Remove mozGenericWordUtils; r=smaug (b1a529f772) - fix nsRefPtr/RefPtr (c56979e04d) - Bug 1243657 spellchecker should check if IME composition works as deleting whole text r=ehsan (8b4d4825b9) - Bug 1137544 - New scripts to upgrade en-US.dic to the latest upstream version; r=ehsan (47150b3549) - Bug 1137544 - Upgrade en-US.dic dictionary to upstream version 2015.02.15; r=ehsan (057540f06b) - Bug 1137544 - Generate 5-mozilla-added and 5-mozilla-removed to aid in submitting changes upstream; r=ehsan (f0d6332df3) - Bug 1137544 - Update the en-US dictionary based on the SCOWL 2015.04.24 wordlist using the new scripts (e87b0a0285) - minor test alignment (f3e976adf2) - Bug 1162823 - Do not treat non-Latin words as misspelled; r=ekanan (c298db7251) - Bug 1160730 - Add composited, compositing and compositeness to the en-US dictionary. r=ehsan (7d62babbdb) - Bug 1167912 - Add eldritch to the en-US dictionary. r=ehsan (4d1e08e03b) - Bug 1168802 - Update the en-US dictionary to SCOWL 2015.05.18 (3daa6d0831) - Bug 1183765 - Add crappiness to our en-US dictionary. r=ehsan (54ccd28fa2) - Bug 1192054 - Add subsumption to the en-US dictionary. r=ehsan (8c5aaa92bc) - Bug 1199540 - Update the en-US dictionary to SCOWL 2015.08.24 (cb21d0092d) - Bug 1200508 - Add dialogs to the en-US dictionary. r=ehsan (1e69b4d574) - Bug 1202600 - Add Fukushima to the en-US dictionary. r=ehsan (6ffca1c47b) - Bug 1213765 - Add preliminarily to the en-US dictionary. r=ehsan (cb12d4979b) - Bug 1228174 - Add validator to the en-US dictionary. r=ehsan (b356d7f5cb) - Bug 1199532 - Add disassembly, disassembler to the en-US dictionary. r=ehsan (979bb4f997) - Bug 1235506 - Correct 353 entries in the en-US dictionary. r=ehsan (efb2f4a890) - Bug 1238031 - Fix make-new-dict to use a custom en_US dictionary that adds common variants and accented words. r=ehsan (39464a234f) - Bug 301712 - Remove uncommon proper names, remove unneeded words. r=ehsan (a6ece3925f) - Bug 1240916 - Part 2: Update the en-US dictionary to SCOWL 2016.01.19 (bb059318e5) - Bug 1250430 - Remove SrcDir loader support from devtools. r=jryans (0e77cbd85f) - Bug 1209699 - Add a 'Push' button for service workers in about:debugging. r=jdescottes (a59c681ad1) - Bug 1247203 - Remove useless call to main(). r=jryans (e89b21e72c) - Bug 1247203 - Do not hardcode main module path in Loader.jsm. r=jryans (01d4ca73cc) - Bug 1255266 - create sandbox with system principal. r=jryans,khuey. (0ac3a41816) - Bug 1240804 - Use common instance of Promise.jsm for test harness promise rejection handling. r=ochameau (5f5383e721) - Bug 1248603 - Factor out menu and shortcut creation to dedicated module. r=jryans (2e19c46dba) - Bug 1248603 - Remove support of the appmenu from devtools. r=jryans (3f25c2b181) - Bug 1248603 - Toggle developer toolbar via the menuitem in tests. r=jryans (01d9940116) - bits of Bug 1248603 - Toggle developer toolbar (e062489e6b) - Bug 1248601 - Register the Developer Toolbar dynamically. r=jwalker (d5e63b9e4b) - missing bit of 878412 - Use F12 to open the Toolbox (43c193a82a) - Bug 1252479 - Adding the Developer Dynamically (Bug 1248601) doesn't work in SeaMonkey because it doesn't have a "browser-bottombox" r=ochameau (49fb6e1f17) - Bug 1248601 - Fix focus race due to dynamic XUL insertion. r=jwalker (35831fd629) - Bug 1257178 - Prevent "this._input is undefined" exception when developer toolbar is hidden early. r=jwalker (a8c308acd2) - Bug 1250120 - Change name to Responsive Design Mode in Tools -> Web Developer menu r=jryans (3575acecb2) - Bug 1239317 - Add a Service Workers entry to the Web Developer menu. r=jryans (ce975756b3) - Bug 1219804 - Show last 5 recent bookmarks in the bookmarks menu. r=mak (cfad5e41b2) - Bug 1259398 - Make devtools file-watcher module more generic to watch any directory. r=jlongster (4d37fbf76e) - Bug 1236452 - Fix DOMHelpers.onceDOMReady against already loaded documents. r=jryans (7abfab41c0) - Bug 1259241 - Update demangling library to 1.0.1 to fix a memory leak. r=fitzgen (77450e478c) - Bug 1261092 - Simplify gcli initialization/destruction codepaths. r=jryans,jwalker (b8648df9f1) - Bug 1258309 - Pull ViewHelpers.Prefs into its own module, r=jsantell (2fe2251e2a) - Bug 1260711 - Fix error 'IndexSizeError: Index or size is negative or greater than the allowed amount' when using the animation inspector. r=pbro (4d2508de75) - Bug 1235698 - Increase the timeout of browser_animation_timeline_shows_time_info.js (ae143a305e) - Bug 1253493 - Part1: Show iterationStart to the tooltip. r=pbro (00d72ea7b0) - Bug 1253493 - Part2: Show iterationStart to the GUI. r=pbro (1a5c1c4a93) - Bug 1253494 part 1 - Implement endDelay representation in the animation inspector r=pbro (f5b08cd11d) - Bug 1253494 part 2 - Add tests for endDelay representation r=pbro (d9acd667d8) - Bug 1261561 - Part 1: Fix TimeScale.getAnimationDimensions() to handle multiple iterations. r=pbro (0a1e13cbc9) - Bug 1261561 - Part 2: Add a xpcshell test for TimeScale.getAnimationDimensions(). r=pbro (71a832f3db) - Bug 1168246 - part1: CSS autocomplete picks most popular prop;r=pbrosset (8c9989abd3) - Bug 1168246 - part3: ES lint fixes for inplace-editor and autocomplete-popup;r=pbrosset (66d113f0e2) - Bug 1151413 - Set async caller in DevToolsUtils.executeSoon r=ejpbruel (aa5ee4cbdb) - Bug 1234600 - executeSoon async stacks only when DEBUG_JS_MODULES enabled. r=fitzgen (5e4f771a7a) - Bug 1219028 - Remove use of non-standard Function.prototype.isGenerator from devtools/. r=fitzgen (34327590e6) - Bug 1235458 - Move a bunch of utilities from DevToolsUtils to ThreadSafeDevToolsUtils. r=jsantell (333e190b17) - Bug 1205095 - Unwrap getters in DevToolsUtils.hasSafeGetter. (r=fitzgen) (784e678e66) - Bug 1260589 - Add the ThreadSafeDevToolsUtils.flatten utility; r=jimb a=kwierso (c82b27da22) - Bug 1260938 - Add the ThreadSafeDevToolsUtils.isSet utility; r=jimb a=kwierso (9d5601a39e) - Bug 1262225 - Add actorID to worker fake parent ThreadActor. r=ejpbruel (7e6f761dba) - Bug 1239705 - Add a 'Start' button for service workers in about:debugging. r=ochameau (8bdea0c588) - Bug 1196784 - imageset will use permissions.default.image. r=jdm (9a5669f71f) - Bug 1182727 - Part 16: Fix a bug in build_tar_package (1d8f444eba) - Bug 1182727 - Part 18: Fix building clang on OSX 10.8 and older (a02e1baca5) - Bug 1182727 - Part 19: Fix another stupid mistake in build_tar_package() (87bb241693) - Bug 1261264 - Apply GCC PR64905 to fix miscompilation with -fomit-frame-pointer. r=froydnj (d746a0c878) - missing option, for safety (6fba93dff9) - Bug 1260605 - Remove hack from bug 967556. r=nalexander (9513dbcd26) - Bug 1239789 - Add secondary buffers to zxx_stream::StaticAllocator to handle reentrancy. r=glandium (74b60ffaad) - Bug 1260351 - MozGlue: Build: Add mips support. r=glandium (8a463032f6) - Bug 1249849: Ensure that we can always reach malloc_decl.h even when MOZ_REPLACE_ALLOC is not defined; r=glandium (1a8d0356ac) - Bug 1248915 - TSan: data race on global 'mozilla::net::CacheObserver::sDiskCacheCapacity'. r=honzab.moz, n.nethercote. (86769cd893) - Bug 1249157 - prefapi enums into class enums, explicit conversion, cleanup. r=bsmedberg (1843c09593) - Bug 1251393: Remove a duplicated line. r=me (c2bca1a4f4)
501 lines
15 KiB
C++
501 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 "mozilla/TimeStamp.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
|
|
Atomic<uint32_t,Relaxed> 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;
|
|
|
|
static int32_t const kDefaultMaxShutdownIOLag = 2; // seconds
|
|
int32_t CacheObserver::sMaxShutdownIOLag = kDefaultMaxShutdownIOLag;
|
|
|
|
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::AddAtomicUintVarCache(
|
|
&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);
|
|
|
|
mozilla::Preferences::AddIntVarCache(
|
|
&sMaxShutdownIOLag, "browser.cache.max_shutdown_io_lag", kDefaultMaxShutdownIOLag);
|
|
}
|
|
|
|
// static
|
|
uint32_t 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 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,
|
|
NeckoOriginAttributes 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(NeckoOriginAttributes 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 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;
|
|
}
|
|
|
|
// static
|
|
TimeDuration const& CacheObserver::MaxShutdownIOLag()
|
|
{
|
|
static TimeDuration period = TimeDuration::FromSeconds(sMaxShutdownIOLag);
|
|
return period;
|
|
}
|
|
|
|
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")) {
|
|
NeckoOriginAttributes oa;
|
|
if (!oa.Init(nsDependentString(aData))) {
|
|
NS_ERROR("Could not parse NeckoOriginAttributes 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
|