mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1038357 - Add automatic pruning for mForcedValidEntries in CacheStorage Service. r=honzab
This commit is contained in:
parent
23b6485926
commit
0953b4ed83
@ -1074,13 +1074,42 @@ void CacheStorageService::ForceEntryValidFor(nsACString &aCacheEntryKey,
|
||||
{
|
||||
mozilla::MutexAutoLock lock(mLock);
|
||||
|
||||
TimeStamp now = TimeStamp::NowLoRes();
|
||||
ForcedValidEntriesPrune(now);
|
||||
|
||||
// This will be the timeout
|
||||
TimeStamp validUntil = TimeStamp::NowLoRes() +
|
||||
TimeDuration::FromSeconds(aSecondsToTheFuture);
|
||||
TimeStamp validUntil = now + TimeDuration::FromSeconds(aSecondsToTheFuture);
|
||||
|
||||
mForcedValidEntries.Put(aCacheEntryKey, validUntil);
|
||||
}
|
||||
|
||||
namespace { // anon
|
||||
|
||||
PLDHashOperator PruneForcedValidEntries(
|
||||
const nsACString& aKey, TimeStamp& aTimeStamp, void* aClosure)
|
||||
{
|
||||
TimeStamp* now = static_cast<TimeStamp*>(aClosure);
|
||||
if (aTimeStamp < *now) {
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
} // anon
|
||||
|
||||
// Cleans out the old entries in mForcedValidEntries
|
||||
void CacheStorageService::ForcedValidEntriesPrune(TimeStamp &now)
|
||||
{
|
||||
static TimeDuration const oneMinute = TimeDuration::FromSeconds(60);
|
||||
static TimeStamp dontPruneUntil = now + oneMinute;
|
||||
if (now < dontPruneUntil)
|
||||
return;
|
||||
|
||||
mForcedValidEntries.Enumerate(PruneForcedValidEntries, &now);
|
||||
dontPruneUntil = now + oneMinute;
|
||||
}
|
||||
|
||||
void
|
||||
CacheStorageService::OnMemoryConsumptionChange(CacheMemoryConsumer* aConsumer,
|
||||
uint32_t aCurrentMemoryConsumption)
|
||||
|
@ -91,8 +91,9 @@ public:
|
||||
already_AddRefed<nsIEventTarget> Thread() const;
|
||||
mozilla::Mutex& Lock() { return mLock; }
|
||||
|
||||
// Tracks entries that may be forced valid.
|
||||
// Tracks entries that may be forced valid in a pruned hashtable.
|
||||
nsDataHashtable<nsCStringHashKey, TimeStamp> mForcedValidEntries;
|
||||
void ForcedValidEntriesPrune(TimeStamp &now);
|
||||
|
||||
// Helper thread-safe interface to pass entry info, only difference from
|
||||
// nsICacheStorageVisitor is that instead of nsIURI only the uri spec is
|
||||
|
Loading…
Reference in New Issue
Block a user