mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-15 08:53:07 +09:00
Issue #2653 - Part 5: Simplify and clean up some quota code
Since we no longer need a complex check, we can remove some indirection.
This commit is contained in:
parent
53cab0f8ce
commit
04b285b848
4 changed files with 43 additions and 100 deletions
|
|
@ -444,7 +444,6 @@ public:
|
|||
mWriteParams(aWriteParams),
|
||||
mState(eInitial),
|
||||
mResult(JS::AsmJSCache_InternalError),
|
||||
mEnforcingQuota(true),
|
||||
mDeleteReceived(false),
|
||||
mActorDestroyed(false),
|
||||
mOpened(false)
|
||||
|
|
@ -676,7 +675,6 @@ private:
|
|||
State mState;
|
||||
JS::AsmJSCacheResult mResult;
|
||||
|
||||
bool mEnforcingQuota;
|
||||
bool mDeleteReceived;
|
||||
bool mActorDestroyed;
|
||||
bool mOpened;
|
||||
|
|
@ -699,9 +697,6 @@ ParentRunnable::InitOnMainThread()
|
|||
rv = QuotaManager::GetInfoFromPrincipal(principal, &mSuffix, &mGroup, &mOrigin);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mEnforcingQuota =
|
||||
QuotaManager::IsQuotaEnforced(quota::PERSISTENCE_TYPE_TEMPORARY);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -809,25 +804,23 @@ ParentRunnable::OpenCacheFileForWrite()
|
|||
QuotaManager* qm = QuotaManager::Get();
|
||||
MOZ_ASSERT(qm, "We are on the QuotaManager's IO thread");
|
||||
|
||||
if (mEnforcingQuota) {
|
||||
// Create the QuotaObject before all file IO and keep it alive until caching
|
||||
// completes to get maximum assertion coverage in QuotaManager against
|
||||
// concurrent removal, etc.
|
||||
mQuotaObject = qm->GetQuotaObject(quota::PERSISTENCE_TYPE_TEMPORARY, mGroup, mOrigin, file);
|
||||
NS_ENSURE_STATE(mQuotaObject);
|
||||
// Create the QuotaObject before all file IO and keep it alive until caching
|
||||
// completes to get maximum assertion coverage in QuotaManager against
|
||||
// concurrent removal, etc.
|
||||
mQuotaObject = qm->GetQuotaObject(quota::PERSISTENCE_TYPE_TEMPORARY, mGroup, mOrigin, file);
|
||||
NS_ENSURE_STATE(mQuotaObject);
|
||||
|
||||
if (!mQuotaObject->MaybeUpdateSize(mWriteParams.mSize,
|
||||
/* aTruncate */ false)) {
|
||||
// If the request fails, it might be because mOrigin is using too much
|
||||
// space (MaybeUpdateSize will not evict our own origin since it is
|
||||
// active). Try to make some space by evicting LRU entries until there is
|
||||
// enough space.
|
||||
EvictEntries(mDirectory, mGroup, mOrigin, mWriteParams.mSize, mMetadata);
|
||||
if (!mQuotaObject->MaybeUpdateSize(mWriteParams.mSize,
|
||||
/* aTruncate */ false)) {
|
||||
// If the request fails, it might be because mOrigin is using too much
|
||||
// space (MaybeUpdateSize will not evict our own origin since it is
|
||||
// active). Try to make some space by evicting LRU entries until there is
|
||||
// enough space.
|
||||
EvictEntries(mDirectory, mGroup, mOrigin, mWriteParams.mSize, mMetadata);
|
||||
if (!mQuotaObject->MaybeUpdateSize(mWriteParams.mSize,
|
||||
/* aTruncate */ false)) {
|
||||
mResult = JS::AsmJSCache_QuotaExceeded;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
mResult = JS::AsmJSCache_QuotaExceeded;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -863,13 +856,11 @@ ParentRunnable::OpenCacheFileForRead()
|
|||
QuotaManager* qm = QuotaManager::Get();
|
||||
MOZ_ASSERT(qm, "We are on the QuotaManager's IO thread");
|
||||
|
||||
if (mEnforcingQuota) {
|
||||
// Even though it's not strictly necessary, create the QuotaObject before
|
||||
// all file IO and keep it alive until caching completes to get maximum
|
||||
// assertion coverage in QuotaManager against concurrent removal, etc.
|
||||
mQuotaObject = qm->GetQuotaObject(quota::PERSISTENCE_TYPE_TEMPORARY, mGroup, mOrigin, file);
|
||||
NS_ENSURE_STATE(mQuotaObject);
|
||||
}
|
||||
// Even though it's not strictly necessary, create the QuotaObject before
|
||||
// all file IO and keep it alive until caching completes to get maximum
|
||||
// assertion coverage in QuotaManager against concurrent removal, etc.
|
||||
mQuotaObject = qm->GetQuotaObject(quota::PERSISTENCE_TYPE_TEMPORARY, mGroup, mOrigin, file);
|
||||
NS_ENSURE_STATE(mQuotaObject);
|
||||
|
||||
rv = file->GetFileSize(&mFileSize);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
|
|
|||
|
|
@ -21015,9 +21015,9 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
|
|||
if (State::Initial == mState) {
|
||||
QuotaManager::GetInfoForChrome(&mSuffix, &mGroup, &mOrigin);
|
||||
|
||||
MOZ_ASSERT(!QuotaManager::IsFirstPromptRequired(persistenceType, mOrigin));
|
||||
MOZ_ASSERT(QuotaManager::IsOriginInternal(mOrigin));
|
||||
|
||||
mEnforcingQuota = QuotaManager::IsQuotaEnforced(persistenceType);
|
||||
mEnforcingQuota = false;
|
||||
}
|
||||
|
||||
*aPermission = PermissionRequestBase::kPermissionAllowed;
|
||||
|
|
@ -21046,10 +21046,14 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
|
|||
|
||||
PermissionRequestBase::PermissionValue permission;
|
||||
|
||||
if (QuotaManager::IsFirstPromptRequired(persistenceType, origin)) {
|
||||
rv = PermissionRequestBase::GetCurrentPermission(principal, &permission);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
if (persistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
if (QuotaManager::IsOriginInternal(origin)) {
|
||||
permission = PermissionRequestBase::kPermissionAllowed;
|
||||
} else {
|
||||
rv = PermissionRequestBase::GetCurrentPermission(principal, &permission);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
permission = PermissionRequestBase::kPermissionAllowed;
|
||||
|
|
@ -21061,7 +21065,7 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
|
|||
mGroup = group;
|
||||
mOrigin = origin;
|
||||
|
||||
mEnforcingQuota = QuotaManager::IsQuotaEnforced(persistenceType);
|
||||
mEnforcingQuota = persistenceType != PERSISTENCE_TYPE_PERSISTENT;
|
||||
}
|
||||
|
||||
*aPermission = permission;
|
||||
|
|
|
|||
|
|
@ -1556,18 +1556,6 @@ private:
|
|||
DoProcessOriginDirectories();
|
||||
};
|
||||
|
||||
class OriginKey : public nsAutoCString
|
||||
{
|
||||
public:
|
||||
OriginKey(PersistenceType aPersistenceType,
|
||||
const nsACString& aOrigin)
|
||||
{
|
||||
PersistenceTypeToText(aPersistenceType, *this);
|
||||
Append(':');
|
||||
Append(aOrigin);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
SanitizeOriginString(nsCString& aOrigin)
|
||||
{
|
||||
|
|
@ -1581,18 +1569,6 @@ SanitizeOriginString(nsCString& aOrigin)
|
|||
aOrigin.ReplaceChar(QuotaManager::kReplaceChars, '+');
|
||||
}
|
||||
|
||||
bool
|
||||
IsTreatedAsPersistent(PersistenceType aPersistenceType)
|
||||
{
|
||||
return aPersistenceType == PERSISTENCE_TYPE_PERSISTENT;
|
||||
}
|
||||
|
||||
bool
|
||||
IsTreatedAsTemporary(PersistenceType aPersistenceType)
|
||||
{
|
||||
return !IsTreatedAsPersistent(aPersistenceType);
|
||||
}
|
||||
|
||||
nsresult
|
||||
CloneStoragePath(nsIFile* aBaseDir,
|
||||
const nsAString& aStorageName,
|
||||
|
|
@ -3006,7 +2982,7 @@ QuotaManager::CollectOriginsForEviction(
|
|||
nsTArray<OriginInfo*>& aInactiveOriginInfos)
|
||||
{
|
||||
for (OriginInfo* originInfo : aOriginInfos) {
|
||||
MOZ_ASSERT(IsTreatedAsTemporary(originInfo->mGroupInfo->mPersistenceType));
|
||||
MOZ_ASSERT(originInfo->mGroupInfo->mPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
|
||||
|
||||
OriginScope originScope = OriginScope::FromOrigin(originInfo->mOrigin);
|
||||
|
||||
|
|
@ -3263,7 +3239,7 @@ QuotaManager::InitQuotaForOrigin(PersistenceType aPersistenceType,
|
|||
int64_t aAccessTime)
|
||||
{
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(IsTreatedAsTemporary(aPersistenceType));
|
||||
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
|
||||
|
||||
MutexAutoLock lock(mQuotaMutex);
|
||||
|
||||
|
|
@ -3804,7 +3780,7 @@ QuotaManager::InitializeOrigin(PersistenceType aPersistenceType,
|
|||
|
||||
nsresult rv;
|
||||
|
||||
bool trackQuota = IsQuotaEnforced(aPersistenceType);
|
||||
bool trackQuota = aPersistenceType != PERSISTENCE_TYPE_PERSISTENT;
|
||||
|
||||
// We need to initialize directories of all clients if they exists and also
|
||||
// get the total usage to initialize the quota.
|
||||
|
|
@ -4443,8 +4419,8 @@ QuotaManager::EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
|||
getter_AddRefs(directory));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (IsTreatedAsPersistent(aPersistenceType)) {
|
||||
if (mInitializedOrigins.Contains(OriginKey(aPersistenceType, aOrigin))) {
|
||||
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
if (mInitializedOrigins.Contains(aOrigin)) {
|
||||
directory.forget(aDirectory);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -4496,7 +4472,7 @@ QuotaManager::EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
|||
rv = EnsureDirectory(directory, &created);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (IsTreatedAsPersistent(aPersistenceType)) {
|
||||
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
if (created) {
|
||||
timestamp = PR_Now();
|
||||
|
||||
|
|
@ -4516,9 +4492,8 @@ QuotaManager::EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
|||
aOrigin);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else {
|
||||
bool persistent = aPersistenceType == PERSISTENCE_TYPE_PERSISTENT;
|
||||
rv = GetDirectoryMetadata2WithRestore(directory,
|
||||
persistent,
|
||||
/* aPersistent */ true,
|
||||
×tamp);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
|
|
@ -4530,7 +4505,7 @@ QuotaManager::EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
|||
rv = InitializeOrigin(aPersistenceType, aGroup, aOrigin, timestamp, directory);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mInitializedOrigins.AppendElement(OriginKey(aPersistenceType, aOrigin));
|
||||
mInitializedOrigins.AppendElement(aOrigin);
|
||||
} else if (created) {
|
||||
timestamp = PR_Now();
|
||||
|
||||
|
|
@ -4564,8 +4539,8 @@ QuotaManager::OriginClearCompleted(PersistenceType aPersistenceType,
|
|||
{
|
||||
AssertIsOnIOThread();
|
||||
|
||||
if (IsTreatedAsPersistent(aPersistenceType)) {
|
||||
mInitializedOrigins.RemoveElement(OriginKey(aPersistenceType, aOrigin));
|
||||
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
mInitializedOrigins.RemoveElement(aOrigin);
|
||||
}
|
||||
|
||||
for (uint32_t index = 0; index < Client::TYPE_MAX; index++) {
|
||||
|
|
@ -4791,25 +4766,6 @@ QuotaManager::IsOriginInternal(const nsACString& aOrigin)
|
|||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
bool
|
||||
QuotaManager::IsFirstPromptRequired(PersistenceType aPersistenceType,
|
||||
const nsACString& aOrigin)
|
||||
{
|
||||
if (IsTreatedAsTemporary(aPersistenceType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !IsOriginInternal(aOrigin);
|
||||
}
|
||||
|
||||
// static
|
||||
bool
|
||||
QuotaManager::IsQuotaEnforced(PersistenceType aPersistenceType)
|
||||
{
|
||||
return IsTreatedAsTemporary(aPersistenceType);
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
QuotaManager::ChromeOrigin(nsACString& aOrigin)
|
||||
|
|
@ -5872,9 +5828,8 @@ QuotaUsageRequestBase::GetUsageForOrigin(QuotaManager* aQuotaManager,
|
|||
if (exists && !mCanceled) {
|
||||
bool initialized;
|
||||
|
||||
if (IsTreatedAsPersistent(aPersistenceType)) {
|
||||
nsCString originKey = OriginKey(aPersistenceType, aOrigin);
|
||||
initialized = aQuotaManager->IsOriginInitialized(originKey);
|
||||
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
initialized = aQuotaManager->IsOriginInitialized(mOriginScope.GetOrigin());
|
||||
} else {
|
||||
initialized = aQuotaManager->IsTemporaryStorageInitialized();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -373,13 +373,6 @@ public:
|
|||
static bool
|
||||
IsOriginInternal(const nsACString& aOrigin);
|
||||
|
||||
static bool
|
||||
IsFirstPromptRequired(PersistenceType aPersistenceType,
|
||||
const nsACString& aOrigin);
|
||||
|
||||
static bool
|
||||
IsQuotaEnforced(PersistenceType aPersistenceType);
|
||||
|
||||
static void
|
||||
ChromeOrigin(nsACString& aOrigin);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue