mirror of
https://github.com/roytam1/basilisk55.git
synced 2026-05-26 15:02:46 +00:00
import from UXP: Issue #2653 - Part 5: Simplify and clean up some quota code (04b285b8)
This commit is contained in:
@@ -351,7 +351,6 @@ public:
|
||||
mWriteParams(aWriteParams),
|
||||
mState(eInitial),
|
||||
mResult(JS::AsmJSCache_InternalError),
|
||||
mEnforcingQuota(true),
|
||||
mDeleteReceived(false),
|
||||
mActorDestroyed(false),
|
||||
mOpened(false)
|
||||
@@ -581,7 +580,6 @@ private:
|
||||
State mState;
|
||||
JS::AsmJSCacheResult mResult;
|
||||
|
||||
bool mEnforcingQuota;
|
||||
bool mDeleteReceived;
|
||||
bool mActorDestroyed;
|
||||
bool mOpened;
|
||||
@@ -604,9 +602,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;
|
||||
}
|
||||
|
||||
@@ -714,25 +709,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -768,13 +761,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);
|
||||
|
||||
@@ -21173,9 +21173,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;
|
||||
@@ -21211,10 +21211,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;
|
||||
@@ -21226,7 +21230,7 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
|
||||
mGroup = group;
|
||||
mOrigin = origin;
|
||||
|
||||
mEnforcingQuota = QuotaManager::IsQuotaEnforced(persistenceType);
|
||||
mEnforcingQuota = persistenceType != PERSISTENCE_TYPE_PERSISTENT;
|
||||
}
|
||||
|
||||
*aPermission = permission;
|
||||
|
||||
+12
-57
@@ -1590,18 +1590,6 @@ private:
|
||||
DoProcessOriginDirectories();
|
||||
};
|
||||
|
||||
class OriginKey : public nsAutoCString
|
||||
{
|
||||
public:
|
||||
OriginKey(PersistenceType aPersistenceType,
|
||||
const nsACString& aOrigin)
|
||||
{
|
||||
PersistenceTypeToText(aPersistenceType, *this);
|
||||
Append(':');
|
||||
Append(aOrigin);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
SanitizeOriginString(nsCString& aOrigin)
|
||||
{
|
||||
@@ -1615,18 +1603,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,
|
||||
@@ -3040,7 +3016,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);
|
||||
|
||||
@@ -3297,7 +3273,7 @@ QuotaManager::InitQuotaForOrigin(PersistenceType aPersistenceType,
|
||||
int64_t aAccessTime)
|
||||
{
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(IsTreatedAsTemporary(aPersistenceType));
|
||||
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
|
||||
|
||||
MutexAutoLock lock(mQuotaMutex);
|
||||
|
||||
@@ -3838,7 +3814,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.
|
||||
@@ -4534,8 +4510,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;
|
||||
}
|
||||
@@ -4616,7 +4592,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();
|
||||
|
||||
@@ -4636,9 +4612,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;
|
||||
@@ -4650,7 +4625,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();
|
||||
|
||||
@@ -4684,8 +4659,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++) {
|
||||
@@ -4911,25 +4886,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)
|
||||
@@ -5992,9 +5948,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();
|
||||
}
|
||||
|
||||
@@ -374,13 +374,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user