mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 22:53:04 +00:00
28941c59ad
- Bug 1226200: Don't assume a TCPSocket has only one managee (and rename LoneManagedOrNull) r=jdm (aa2d0fcc14) - Bug 1227300, Part 1 - Add an alert notification component. r=MattN,wchen (37758ce9ff) - Bug 1230700. Make Notification::ShowInternal explicitly suppress the exception from GetPermissionInternal. r=smaug (9e288cf5ae) - Bug 1225336 - Add telemetry about web notification display/messages. r=wchen,kitcambridge p=vladan# Please enter the commit message for your changes. Lines starting (b2e481691a) - Bug 1219030 - Collect notification management telemetry. r=wchen,MattN; p=ally (c0ba425b4e) - Bug 1212611 - Use system notification for website notifications in Android. r=mfinkle (84985bcf01) - Bug 1227300, Part 2 - Implement showAlert. r=MattN,wchen (33eedc7e91) - Bug 1214305 - Part 0: Ensure site security service is initialized before trying to use DataStorage via IPC. (8bd73f43b0) - Bug 1137681 - Make user agent docshell overrides affect network requests. r=jduell (e8dabb8338) - Bug 1233245 - Propagate the interception information in the non-e10s case for all HTTP redirects, not just the internal ones; r=jdm (6922fddcf8) - Bug 1226444 - Use helper function to identify preloads. r=sicking (d110669f73) - Bug 1214305 - Part 1: Refactor the logic for querying whether a connection should go through a secure upgrade into NS_ShouldSecureUpgrade; r=mcmanus (2d04c78290) - Bug 1137681 - Per-tab user agent emulation. r=bz (4ff70db690) - Bug 1227300, Part 3 - Implement showAlert for the OS X alerts backend. r=mstange (5eb05d0728) - Bug 1227300, Part 4 - Implement showAlert for the libnotify alerts backend. r=karlt (0942fa2764) - Bug 1227300, Part 5 - Implement showAlert for the B2G alerts backend. r=mhenretty (e39581aea5) - Bug 1227300, Part 6 - Use showAlert to display web notifications. r=wchen (ab79eaa0c8) - domBug 1227300, Part 7 - Update test interfaces. a=testonly (387cb62772) - Bug 1214305 - Part 3: Add a nsIInterceptedChannel.secureUpgradedChannelURI helper; r=jdm (811d25bd58) - Bug 1214305 - Part 4: Use the secure upgraded channel URI in ServiceWorkerManager::PrepareFetchEvent; r=jdm (0c44bf527c) - Bug 1214305 - Part 5: Use the secure upgraded channel URI in FetchEventRunnable::Init; r=jdm (a30f239261) - Bug 1214305 - Part 6: Use a non-IPC redirect for synthesized upgraded responses to ensure the response URL is correctly propagated; r=mcmanus (8ba8a5728c) - Bug 1214305 - Part 7: Decide in the child process whether an intercepted channel should go through a secure upgrade; r=mcmanus (93e27decae) - Bug 1198397 - Add a test for interception of requests upgraded through the CSP upgrade-insecure-requests directive; r=jdm (21eb14eb34) - Bug 1214305 - Part 8: Enable secure upgrade service worker tests on e10s; r=jdm (c14f5fb504) - Bug 1214305 - Part 9: Avoid using CPOWs in browser_bug1045902_console_csp_ignore_reflected_xss_message.js; r=billm (1ae179d26b) - Bug 1214305 - Part 10: Clean up global DataStorage references in the child process; r=keeler (ef0b52d049) - Bug 1224771 - Close all web notifications when the originating tab is closed. r=wchen (da295b4ba7) - Bug 1214305 - Part 2: Refactor the logic for obtaining the secure upgraded URI into HttpBaseChannel; r=mcmanus (3346078285) - Bug 1237151 (part 1) - Remove ignored qualifiers in dom/media/gmp/. r=cpearce. (18134820a6) - Bug 1237151 (part 2) - Remove ignored qualifiers in WebRTC-relate code. r=jesup. (effe5bd694) - Bug 1118820 part 1 (style system part) - [css-grid] Implement the 'auto-fill' and 'auto-fit' keywords in the repeat() function. r=dholbert (5db1a577db) - Bug 1118820 part 2a - [css-grid] Add a LineNameMap class that lets us lookup line names with a dynamic number of 'repeat(auto-fill/auto-fit)' tracks taken into account. r=dholbert (3ecf4b53f0) - Bug 1118820 part 2b - [css-grid] Move the static functions FindLine/RFindLine/FindNamedLine into the LineNameMap class (idempotent patch). r=dholbert (efb12c594b) - Bug 1118820 part 2c+2d - [css-grid] Modify the LineNameMap::FindLine/RFindLine/FindNamedLine methods to take line names associated with 'repeat(auto-fill/auto-fit)' tracks into account. Instantiate and pass around a LineNameMap object instead of an array of line name arrays. r=dholbert (a3db750297) - Bug 1118820 part 3a - [css-grid] Modify TrackSizingFunctions to take a dynamic number of 'repeat(auto-fill/auto-fit)' tracks taking into account. r=dholbert (9aa6033332) - Bug 1118820 part 3b - [css-grid] Implement the CalculateRepeatFillCount method that calculates the number of 'repeat(auto-fill/auto-fit)' tracks to use for the given sizes. r=dholbert (cf75fab8a8) - Bug 1118820 part 4 - [css-grid] Provide the sizes to use for CalculateRepeatFillCount. r=dholbert (8184c00dba) - Bug 1118820 part 5 - [css-grid] Remove any empty 'repeat(auto-fit)' tracks at the end of its range and adjust affected grid area line numbers accordingly. r=dholbert (c02ba6a6e3) - Bug 1229165 - [css-grid] Reftests for min/max-width/height properties on the grid container. (725097f878) - Bug 1229999 - [css-grid] Reftest. (51b5bc9535) - Bug 1237151 (part 3) - Remove ignored qualifiers in all remaining code. r=froydnj. (69917ebbad) - more bits of Bug 1178892 - Split the profiler into Core & Gecko files (41bb127b9c) - Bug 1199841 - Restructure private browsing to remember status after OnStopRequest r=jdm (16c2c1044d) - Bug 1233845 - Report an interception error and cancel the HTTP channel when encountering a known topcrash situation. r=ehsan (5d08075110) - Bug 664163 - Fix Get(Local|Remote)(Address|Port) in HttpChannelChild. r=jduell (cbf70af4e8) - Bug 1229177 - Show the tracking protection shield for fetch and XHR requests. r=jduell (5833b3e872) - Bug 1220678 Don't crash when DivertToParent() is called on an intercepted channel. r=jdm (5d7ff6ecc8) - Bug 1220681 P1 Make HttpChannelChild::DivertToParent() work with synthetic responses. r=jdm (67715703ef) - Bug 1169819 Add browser chrome test to validate SW force refresh. r=ehsan (c0b6b3e874) - Bug 1220681 P2 Test synthetic responses that trigger downloads. r=ehsan (c701f3ddb1) - Bug 1220681 P3 Delay diversion on parent side until response head has been synthesized. r=jdm (7c697aacee) - Bug 1220681 P4 Automatically suspend the parent channel after synthesizing the response for diverison. r=jdm (27f31bcb35) - Bug 1220681 P5 Don't double suspend parent channel during synthesized divert to parent. r=jdm (62081d4b56) - Bug 1220681 P6 Use clients.claim() in browser_download.js to avoid worker unregister race. r=jdm (c8de291727) - Bug 1240161 - Remove "only-if-cached" from RequestCache; r=bkelly (283486f584) - Bug 1184550 - Add a mochitest for the Request constructor that tests that the body is set to used after being fetched and then fails on the second fetch with the same Request. r=bkelly (db4a967203) - Bug 1205495 - Correctly use the requests's body and redirect mode in reroute.js; r=nsm (a36a96624a) - Bug 1189656 - Fix fetch-request-fallback test paths. r=bkelly (366c884179) - Bug 1219085 - Import the fetch-request-redirect.https.html test from Blink; r=jdm (bf6b484d82) - Bug 1209081 - Part 1: Implement the "navigate" value for RequestMode; r=bkelly (a22f19d94b) - Bug 1209081 - Part 2: Upgrade the saved Requests in the DOM Cache to reflect the "navigate" RequestMode if they represent navigation content policy types; r=bkelly (60d1da23bb) - Bug 1219469 - Part 1: Revert the error reporting added in bug 1233845; r=jdm (dcc022b9d3) - Bug 1219469 - Part 2: Make HttpChannelParentListener be the controller; r=jdm,jduell (9c5f0dfbe0) - Bug 1229369 - Intercept redirected network fetches that have their request mode set to manual; r=jdm (fb21d86ed2)
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 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;
|
|
}
|
|
|
|
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
|