2013-09-20 13:11:25 +04:00
|
|
|
/* 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"
|
2013-11-21 02:20:16 +04:00
|
|
|
#include "LoadContextInfo.h"
|
|
|
|
#include "nsICacheStorage.h"
|
2013-09-20 13:11:25 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2016-01-14 00:11:00 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-09-20 13:11:25 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2016-04-20 12:29:50 +03:00
|
|
|
#include "mozilla/net/NeckoCommon.h"
|
2014-04-06 22:45:18 +04:00
|
|
|
#include "prsystem.h"
|
2014-01-09 03:27:33 +04:00
|
|
|
#include <time.h>
|
2014-04-06 22:45:18 +04:00
|
|
|
#include <math.h>
|
2013-09-20 13:11:25 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2019-03-05 21:43:02 +03:00
|
|
|
StaticRefPtr<CacheObserver> CacheObserver::sSelf;
|
2013-09-20 13:11:25 +04:00
|
|
|
|
2018-01-12 12:51:00 +03:00
|
|
|
static float const kDefaultHalfLifeHours = 24.0F; // 24 hours
|
2015-02-27 18:17:00 +03:00
|
|
|
float CacheObserver::sHalfLifeHours = kDefaultHalfLifeHours;
|
2014-01-09 03:27:33 +04:00
|
|
|
|
2019-01-08 17:28:00 +03:00
|
|
|
// Cache of the calculated memory capacity based on the system memory size in KB
|
2014-04-06 22:45:18 +04:00
|
|
|
int32_t CacheObserver::sAutoMemoryCacheCapacity = -1;
|
|
|
|
|
2014-02-04 04:53:00 +04:00
|
|
|
static uint32_t const kDefaultDiskCacheCapacity = 250 * 1024; // 250 MB
|
2016-03-20 12:08:57 +03:00
|
|
|
Atomic<uint32_t, Relaxed> CacheObserver::sDiskCacheCapacity(
|
|
|
|
kDefaultDiskCacheCapacity);
|
2014-02-04 04:53:00 +04:00
|
|
|
|
2015-02-23 14:24:35 +03:00
|
|
|
static bool kDefaultCacheFSReported = false;
|
|
|
|
bool CacheObserver::sCacheFSReported = kDefaultCacheFSReported;
|
|
|
|
|
2015-06-14 15:13:18 +03:00
|
|
|
static bool kDefaultHashStatsReported = false;
|
|
|
|
bool CacheObserver::sHashStatsReported = kDefaultHashStatsReported;
|
|
|
|
|
2016-06-23 02:18:01 +03:00
|
|
|
Atomic<PRIntervalTime> CacheObserver::sShutdownDemandedTime(
|
|
|
|
PR_INTERVAL_NO_TIMEOUT);
|
2016-01-14 00:11:00 +03:00
|
|
|
|
2019-04-25 15:21:17 +03:00
|
|
|
static uint32_t const kDefaultTelemetryReportID = 0;
|
|
|
|
Atomic<uint32_t, Relaxed> CacheObserver::sTelemetryReportID(
|
|
|
|
kDefaultTelemetryReportID);
|
|
|
|
|
|
|
|
static uint32_t const kDefaultCacheAmountWritten = 0;
|
|
|
|
Atomic<uint32_t, Relaxed> CacheObserver::sCacheAmountWritten(
|
|
|
|
kDefaultCacheAmountWritten);
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(CacheObserver, nsIObserver, nsISupportsWeakReference)
|
2013-09-20 13:11:25 +04:00
|
|
|
|
2014-02-27 03:11:38 +04:00
|
|
|
// static
|
2013-09-20 13:11:25 +04:00
|
|
|
nsresult CacheObserver::Init() {
|
2016-04-20 12:29:50 +03:00
|
|
|
if (IsNeckoChild()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
if (sSelf) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (!obs) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
sSelf = new CacheObserver();
|
|
|
|
|
|
|
|
obs->AddObserver(sSelf, "prefservice:after-app-defaults", true);
|
|
|
|
obs->AddObserver(sSelf, "profile-do-change", true);
|
2014-08-13 17:43:45 +04:00
|
|
|
obs->AddObserver(sSelf, "browser-delayed-startup-finished", true);
|
2013-09-20 13:11:25 +04:00
|
|
|
obs->AddObserver(sSelf, "profile-before-change", true);
|
|
|
|
obs->AddObserver(sSelf, "xpcom-shutdown", true);
|
|
|
|
obs->AddObserver(sSelf, "last-pb-context-exited", true);
|
2016-10-05 12:58:25 +03:00
|
|
|
obs->AddObserver(sSelf, "clear-origin-attributes-data", true);
|
2013-09-20 13:11:25 +04:00
|
|
|
obs->AddObserver(sSelf, "memory-pressure", true);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-27 03:11:38 +04:00
|
|
|
// static
|
2013-09-20 13:11:25 +04:00
|
|
|
nsresult CacheObserver::Shutdown() {
|
|
|
|
if (!sSelf) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2019-03-05 21:43:02 +03:00
|
|
|
sSelf = nullptr;
|
2013-09-20 13:11:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CacheObserver::AttachToPreferences() {
|
2016-03-20 12:08:57 +03:00
|
|
|
mozilla::Preferences::AddAtomicUintVarCache(&sDiskCacheCapacity,
|
2014-02-04 04:53:00 +04:00
|
|
|
"browser.cache.disk.capacity",
|
|
|
|
kDefaultDiskCacheCapacity);
|
2014-07-11 10:25:55 +04:00
|
|
|
|
2014-02-27 03:11:38 +04:00
|
|
|
mozilla::Preferences::GetComplex(
|
|
|
|
"browser.cache.disk.parent_directory", NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(mCacheParentDirectoryOverride));
|
|
|
|
|
2018-01-12 12:51:00 +03:00
|
|
|
sHalfLifeHours = std::max(
|
|
|
|
0.01F, std::min(1440.0F, mozilla::Preferences::GetFloat(
|
|
|
|
"browser.cache.frecency_half_life_hours",
|
|
|
|
kDefaultHalfLifeHours)));
|
2019-04-25 15:21:17 +03:00
|
|
|
mozilla::Preferences::AddAtomicUintVarCache(
|
|
|
|
&sTelemetryReportID, "browser.cache.disk.telemetry_report_ID",
|
|
|
|
kDefaultTelemetryReportID);
|
|
|
|
|
|
|
|
mozilla::Preferences::AddAtomicUintVarCache(
|
|
|
|
&sCacheAmountWritten, "browser.cache.disk.amount_written",
|
|
|
|
kDefaultCacheAmountWritten);
|
2013-09-20 13:11:25 +04:00
|
|
|
}
|
|
|
|
|
2014-04-06 22:45:18 +04:00
|
|
|
// static
|
2016-01-06 04:08:45 +03:00
|
|
|
uint32_t CacheObserver::MemoryCacheCapacity() {
|
2019-07-11 07:11:39 +03:00
|
|
|
if (StaticPrefs::browser_cache_memory_capacity() >= 0) {
|
|
|
|
return StaticPrefs::browser_cache_memory_capacity();
|
|
|
|
}
|
2014-04-06 22:45:18 +04:00
|
|
|
|
|
|
|
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;
|
2019-01-08 17:28:00 +03:00
|
|
|
capacity <<= 10;
|
2014-04-06 22:45:18 +04:00
|
|
|
}
|
|
|
|
|
2019-01-08 17:28:00 +03:00
|
|
|
// Result is in kilobytes.
|
2014-04-06 22:45:18 +04:00
|
|
|
return sAutoMemoryCacheCapacity = capacity;
|
|
|
|
}
|
|
|
|
|
2014-04-22 13:21:00 +04:00
|
|
|
// static
|
|
|
|
void CacheObserver::SetDiskCacheCapacity(uint32_t aCapacity) {
|
2019-01-08 17:28:00 +03:00
|
|
|
sDiskCacheCapacity = aCapacity;
|
2014-04-22 13:21:00 +04:00
|
|
|
|
|
|
|
if (!sSelf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
sSelf->StoreDiskCacheCapacity();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2019-03-05 21:43:02 +03:00
|
|
|
NewRunnableMethod("net::CacheObserver::StoreDiskCacheCapacity",
|
|
|
|
sSelf.get(), &CacheObserver::StoreDiskCacheCapacity);
|
2014-04-22 13:21:00 +04:00
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CacheObserver::StoreDiskCacheCapacity() {
|
|
|
|
mozilla::Preferences::SetInt("browser.cache.disk.capacity",
|
|
|
|
sDiskCacheCapacity);
|
|
|
|
}
|
|
|
|
|
2015-02-23 14:24:35 +03:00
|
|
|
// static
|
|
|
|
void CacheObserver::SetCacheFSReported() {
|
|
|
|
sCacheFSReported = true;
|
|
|
|
|
|
|
|
if (!sSelf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
sSelf->StoreCacheFSReported();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2019-03-05 21:43:02 +03:00
|
|
|
NewRunnableMethod("net::CacheObserver::StoreCacheFSReported",
|
|
|
|
sSelf.get(), &CacheObserver::StoreCacheFSReported);
|
2015-02-23 14:24:35 +03:00
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CacheObserver::StoreCacheFSReported() {
|
|
|
|
mozilla::Preferences::SetInt("browser.cache.disk.filesystem_reported",
|
|
|
|
sCacheFSReported);
|
|
|
|
}
|
|
|
|
|
2015-06-14 15:13:18 +03:00
|
|
|
// static
|
|
|
|
void CacheObserver::SetHashStatsReported() {
|
|
|
|
sHashStatsReported = true;
|
|
|
|
|
|
|
|
if (!sSelf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
sSelf->StoreHashStatsReported();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2019-03-05 21:43:02 +03:00
|
|
|
NewRunnableMethod("net::CacheObserver::StoreHashStatsReported",
|
|
|
|
sSelf.get(), &CacheObserver::StoreHashStatsReported);
|
2015-06-14 15:13:18 +03:00
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CacheObserver::StoreHashStatsReported() {
|
|
|
|
mozilla::Preferences::SetInt("browser.cache.disk.hashstats_reported",
|
|
|
|
sHashStatsReported);
|
|
|
|
}
|
|
|
|
|
2019-04-25 15:21:17 +03:00
|
|
|
// static
|
|
|
|
void CacheObserver::SetTelemetryReportID(uint32_t aTelemetryReportID) {
|
|
|
|
sTelemetryReportID = aTelemetryReportID;
|
|
|
|
|
|
|
|
if (!sSelf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
sSelf->StoreTelemetryReportID();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
NewRunnableMethod("net::CacheObserver::StoreTelemetryReportID",
|
|
|
|
sSelf.get(), &CacheObserver::StoreTelemetryReportID);
|
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CacheObserver::StoreTelemetryReportID() {
|
|
|
|
mozilla::Preferences::SetInt("browser.cache.disk.telemetry_report_ID",
|
|
|
|
sTelemetryReportID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CacheObserver::SetCacheAmountWritten(uint32_t aCacheAmountWritten) {
|
|
|
|
sCacheAmountWritten = aCacheAmountWritten;
|
|
|
|
|
|
|
|
if (!sSelf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
sSelf->StoreCacheAmountWritten();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
NewRunnableMethod("net::CacheObserver::StoreCacheAmountWritten",
|
|
|
|
sSelf.get(), &CacheObserver::StoreCacheAmountWritten);
|
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CacheObserver::StoreCacheAmountWritten() {
|
|
|
|
mozilla::Preferences::SetInt("browser.cache.disk.amount_written",
|
|
|
|
sCacheAmountWritten);
|
|
|
|
}
|
|
|
|
|
2014-02-27 03:11:38 +04:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
namespace {
|
2015-10-11 19:13:09 +03:00
|
|
|
namespace CacheStorageEvictHelper {
|
2013-11-21 02:20:16 +04:00
|
|
|
|
2015-10-11 19:13:09 +03:00
|
|
|
nsresult ClearStorage(bool const aPrivate, bool const aAnonymous,
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes& aOa) {
|
2013-11-21 02:20:16 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2016-08-24 01:07:56 +03:00
|
|
|
aOa.SyncAttributesWithPrivateBrowsing(aPrivate);
|
|
|
|
RefPtr<LoadContextInfo> info = GetLoadContextInfo(aAnonymous, aOa);
|
2013-11-21 02:20:16 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsICacheStorage> storage;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
2013-11-21 02:20:16 +04:00
|
|
|
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);
|
|
|
|
|
2015-10-11 19:13:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
nsresult Run(OriginAttributes& aOa) {
|
2015-10-11 19:13:09 +03:00
|
|
|
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);
|
2013-11-21 02:20:16 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-11 19:13:09 +03:00
|
|
|
} // namespace CacheStorageEvictHelper
|
|
|
|
} // namespace
|
2013-11-21 02:20:16 +04:00
|
|
|
|
2014-02-04 04:53:00 +04:00
|
|
|
// static
|
2016-01-06 04:08:45 +03:00
|
|
|
bool CacheObserver::EntryIsTooBig(int64_t aSize, bool aUsingDisk) {
|
2014-02-04 04:53:00 +04:00
|
|
|
// If custom limit is set, check it.
|
2019-07-11 07:12:36 +03:00
|
|
|
int64_t preferredLimit =
|
2019-07-11 07:12:59 +03:00
|
|
|
aUsingDisk ? MaxDiskEntrySize() : MaxMemoryEntrySize();
|
2015-07-22 16:23:16 +03:00
|
|
|
|
|
|
|
// do not convert to bytes when the limit is -1, which means no limit
|
|
|
|
if (preferredLimit > 0) {
|
|
|
|
preferredLimit <<= 10;
|
|
|
|
}
|
2014-02-04 04:53:00 +04:00
|
|
|
|
|
|
|
if (preferredLimit != -1 && aSize > preferredLimit) return true;
|
|
|
|
|
2014-04-06 22:45:18 +04:00
|
|
|
// Otherwise (or when in the custom limit), check limit based on the global
|
2019-01-08 17:28:00 +03:00
|
|
|
// limit. It's 1/8 of the respective capacity.
|
2014-02-04 04:53:00 +04:00
|
|
|
int64_t derivedLimit =
|
2019-01-08 17:28:00 +03:00
|
|
|
aUsingDisk ? DiskCacheCapacity() : MemoryCacheCapacity();
|
|
|
|
derivedLimit <<= (10 - 3);
|
2014-02-04 04:53:00 +04:00
|
|
|
|
|
|
|
if (aSize > derivedLimit) return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 00:11:00 +03:00
|
|
|
// static
|
2016-05-11 12:46:54 +03:00
|
|
|
bool CacheObserver::IsPastShutdownIOLag() {
|
|
|
|
#ifdef DEBUG
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (sShutdownDemandedTime == PR_INTERVAL_NO_TIMEOUT ||
|
2019-07-11 07:38:36 +03:00
|
|
|
MaxShutdownIOLag() == UINT32_MAX) {
|
2016-05-11 12:46:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const PRIntervalTime kMaxShutdownIOLag =
|
2019-07-11 07:38:36 +03:00
|
|
|
PR_SecondsToInterval(MaxShutdownIOLag());
|
2016-05-11 12:46:54 +03:00
|
|
|
|
|
|
|
if ((PR_IntervalNow() - sShutdownDemandedTime) > kMaxShutdownIOLag) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-01-14 00:11:00 +03:00
|
|
|
}
|
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CacheObserver::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData) {
|
2013-09-20 13:11:25 +04:00
|
|
|
if (!strcmp(aTopic, "prefservice:after-app-defaults")) {
|
|
|
|
CacheFileIOManager::Init();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, "profile-do-change")) {
|
2014-02-04 04:52:58 +04:00
|
|
|
AttachToPreferences();
|
2013-09-20 13:11:25 +04:00
|
|
|
CacheFileIOManager::Init();
|
|
|
|
CacheFileIOManager::OnProfile();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-13 17:43:45 +04:00
|
|
|
if (!strcmp(aTopic, "browser-delayed-startup-finished")) {
|
2017-08-24 11:25:38 +03:00
|
|
|
CacheStorageService::CleaupCacheDirectories();
|
2014-02-05 23:29:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-12 17:36:00 +03:00
|
|
|
if (!strcmp(aTopic, "profile-change-net-teardown") ||
|
|
|
|
!strcmp(aTopic, "profile-before-change") ||
|
|
|
|
!strcmp(aTopic, "xpcom-shutdown")) {
|
2016-05-11 12:46:54 +03:00
|
|
|
if (sShutdownDemandedTime == PR_INTERVAL_NO_TIMEOUT) {
|
|
|
|
sShutdownDemandedTime = PR_IntervalNow();
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
2016-02-12 17:36:00 +03:00
|
|
|
if (service) {
|
2013-09-20 13:11:25 +04:00
|
|
|
service->Shutdown();
|
2016-02-12 17:36:00 +03:00
|
|
|
}
|
2013-09-20 13:11:25 +04:00
|
|
|
|
|
|
|
CacheFileIOManager::Shutdown();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, "last-pb-context-exited")) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
2016-02-12 17:36:00 +03:00
|
|
|
if (service) {
|
2013-09-20 13:11:25 +04:00
|
|
|
service->DropPrivateBrowsingEntries();
|
2016-02-12 17:36:00 +03:00
|
|
|
}
|
2013-09-20 13:11:25 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-10-05 12:58:25 +03:00
|
|
|
if (!strcmp(aTopic, "clear-origin-attributes-data")) {
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes oa;
|
2015-10-11 19:13:09 +03:00
|
|
|
if (!oa.Init(nsDependentString(aData))) {
|
2017-01-12 19:38:48 +03:00
|
|
|
NS_ERROR(
|
|
|
|
"Could not parse OriginAttributes JSON in "
|
|
|
|
"clear-origin-attributes-data notification");
|
2015-10-11 19:13:09 +03:00
|
|
|
return NS_OK;
|
2013-11-21 02:20:16 +04:00
|
|
|
}
|
|
|
|
|
2015-10-11 19:13:09 +03:00
|
|
|
nsresult rv = CacheStorageEvictHelper::Run(oa);
|
2013-11-21 02:20:16 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
if (!strcmp(aTopic, "memory-pressure")) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CacheStorageService> service = CacheStorageService::Self();
|
2013-09-20 13:11:25 +04:00
|
|
|
if (service)
|
|
|
|
service->PurgeFromMemory(nsICacheStorageService::PURGE_EVERYTHING);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-05 23:29:54 +04:00
|
|
|
MOZ_ASSERT(false, "Missing observer handler");
|
2013-09-20 13:11:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|