tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 44a56571e6eeaa9b27cd2b7fe76152e7a5696ae0
parent c77b911b545d83eae3f1ecf84effb1591fd6579d
Author: Jan Varga <Jan.Varga@gmail.com>
Date:   Tue, 11 Nov 2025 10:33:15 +0000

Bug 1988590 - QM: Add optional cutoff access time to GetOriginInfosWithZeroUsage; r=asuth,dom-storage-reviewers,jari

This patch enhances GetOriginInfosWithZeroUsage by adding an optional cutoff
access time parameter. When specified, origins whose last-access time is more
recent than the cutoff are excluded from the returned list. This will allow
zero-usage origin cleanup to avoid recently used origins while still
collecting older candidates for removal.

Testing: Covered by existing quota manager tests and by a new xpcshell test
(test_temporaryStorageCleanup.js) added in a follow-up patch for this bug.

Differential Revision: https://phabricator.services.mozilla.com/D266640

Diffstat:
Mdom/quota/ActorsParent.cpp | 6++++--
Mdom/quota/GroupInfoPair.h | 6+++++-
Mdom/quota/GroupInfoPairImpl.h | 8+++++---
Mdom/quota/QuotaManager.h | 14+++++++++++++-
4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp @@ -7969,7 +7969,8 @@ QuotaManager::GetOriginInfosExceedingGlobalLimit() const { } QuotaManager::OriginInfosNestedTraversable -QuotaManager::GetOriginInfosWithZeroUsage() const { +QuotaManager::GetOriginInfosWithZeroUsage( + const Maybe<int64_t>& aCutoffAccessTime) const { MutexAutoLock lock(mQuotaMutex); QuotaManager::OriginInfosNestedTraversable res; @@ -7984,7 +7985,8 @@ QuotaManager::GetOriginInfosWithZeroUsage() const { MOZ_ASSERT(!entry.GetKey().IsEmpty()); MOZ_ASSERT(pair); - pair->MaybeInsertNonPersistedZeroUsageOriginInfos(inserter); + pair->MaybeInsertNonPersistedZeroUsageOriginInfos(inserter, + aCutoffAccessTime); } res.AppendElement(std::move(originInfos)); diff --git a/dom/quota/GroupInfoPair.h b/dom/quota/GroupInfoPair.h @@ -73,8 +73,12 @@ class GroupInfoPair { // Inserts non-persisted origins that also have zero quota-charged usage. // Used by cleanup routines to identify candidate origins for removal. + // + // See QuotaManager::GetOriginInfosWithZeroUsage for the semantics and time + // units of |aCutoffAccessTime|. template <typename Iterator> - void MaybeInsertNonPersistedZeroUsageOriginInfos(Iterator aDest) const; + void MaybeInsertNonPersistedZeroUsageOriginInfos( + Iterator aDest, const Maybe<int64_t>& aCutoffAccessTime) const; private: RefPtr<GroupInfo>& GetGroupInfoForPersistenceType( diff --git a/dom/quota/GroupInfoPairImpl.h b/dom/quota/GroupInfoPairImpl.h @@ -42,9 +42,11 @@ void GroupInfoPair::MaybeInsertNonPersistedOriginInfos(Iterator aDest) const { template <typename Iterator> void GroupInfoPair::MaybeInsertNonPersistedZeroUsageOriginInfos( - Iterator aDest) const { - MaybeInsertOriginInfos(aDest, [](const auto& originInfo) { - return !originInfo->LockedPersisted() && originInfo->LockedUsage() == 0; + Iterator aDest, const Maybe<int64_t>& aCutoffAccessTime) const { + MaybeInsertOriginInfos(aDest, [aCutoffAccessTime](const auto& originInfo) { + return !originInfo->LockedPersisted() && originInfo->LockedUsage() == 0 && + (!aCutoffAccessTime || + originInfo->LockedAccessTime() < *aCutoffAccessTime); }); } diff --git a/dom/quota/QuotaManager.h b/dom/quota/QuotaManager.h @@ -860,7 +860,19 @@ class QuotaManager final : public BackgroundThreadObject { OriginInfosNestedTraversable GetOriginInfosExceedingGlobalLimit() const; - OriginInfosNestedTraversable GetOriginInfosWithZeroUsage() const; + // Returns origins with zero usage. If aCutoffAccessTime is provided, origins + // whose last access time is newer than the cutoff are excluded. + // + // The cutoff time is expressed as an int64_t value in microseconds since the + // Unix epoch (1970-01-01 00:00:00 UTC), matching the format returned by + // PR_Now(). This is the same time unit used throughout Quota Manager for + // access and modification timestamps. + // + // Typically callers compute it as: + // const int64_t cutoff = PR_Now() - (N * PR_USEC_PER_SEC); + // where N is the desired age threshold in seconds (for example, one week). + OriginInfosNestedTraversable GetOriginInfosWithZeroUsage( + const Maybe<int64_t>& aCutoffAccessTime = Nothing()) const; /** * Clears the given set of origins.