mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-01 21:07:30 +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),
|
mWriteParams(aWriteParams),
|
||||||
mState(eInitial),
|
mState(eInitial),
|
||||||
mResult(JS::AsmJSCache_InternalError),
|
mResult(JS::AsmJSCache_InternalError),
|
||||||
mEnforcingQuota(true),
|
|
||||||
mDeleteReceived(false),
|
mDeleteReceived(false),
|
||||||
mActorDestroyed(false),
|
mActorDestroyed(false),
|
||||||
mOpened(false)
|
mOpened(false)
|
||||||
|
|
@ -676,7 +675,6 @@ private:
|
||||||
State mState;
|
State mState;
|
||||||
JS::AsmJSCacheResult mResult;
|
JS::AsmJSCacheResult mResult;
|
||||||
|
|
||||||
bool mEnforcingQuota;
|
|
||||||
bool mDeleteReceived;
|
bool mDeleteReceived;
|
||||||
bool mActorDestroyed;
|
bool mActorDestroyed;
|
||||||
bool mOpened;
|
bool mOpened;
|
||||||
|
|
@ -699,9 +697,6 @@ ParentRunnable::InitOnMainThread()
|
||||||
rv = QuotaManager::GetInfoFromPrincipal(principal, &mSuffix, &mGroup, &mOrigin);
|
rv = QuotaManager::GetInfoFromPrincipal(principal, &mSuffix, &mGroup, &mOrigin);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
mEnforcingQuota =
|
|
||||||
QuotaManager::IsQuotaEnforced(quota::PERSISTENCE_TYPE_TEMPORARY);
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -809,7 +804,6 @@ ParentRunnable::OpenCacheFileForWrite()
|
||||||
QuotaManager* qm = QuotaManager::Get();
|
QuotaManager* qm = QuotaManager::Get();
|
||||||
MOZ_ASSERT(qm, "We are on the QuotaManager's IO thread");
|
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
|
// Create the QuotaObject before all file IO and keep it alive until caching
|
||||||
// completes to get maximum assertion coverage in QuotaManager against
|
// completes to get maximum assertion coverage in QuotaManager against
|
||||||
// concurrent removal, etc.
|
// concurrent removal, etc.
|
||||||
|
|
@ -829,7 +823,6 @@ ParentRunnable::OpenCacheFileForWrite()
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int32_t openFlags = PR_RDWR | PR_TRUNCATE | PR_CREATE_FILE;
|
int32_t openFlags = PR_RDWR | PR_TRUNCATE | PR_CREATE_FILE;
|
||||||
rv = file->OpenNSPRFileDesc(openFlags, 0644, &mFileDesc);
|
rv = file->OpenNSPRFileDesc(openFlags, 0644, &mFileDesc);
|
||||||
|
|
@ -863,13 +856,11 @@ ParentRunnable::OpenCacheFileForRead()
|
||||||
QuotaManager* qm = QuotaManager::Get();
|
QuotaManager* qm = QuotaManager::Get();
|
||||||
MOZ_ASSERT(qm, "We are on the QuotaManager's IO thread");
|
MOZ_ASSERT(qm, "We are on the QuotaManager's IO thread");
|
||||||
|
|
||||||
if (mEnforcingQuota) {
|
|
||||||
// Even though it's not strictly necessary, create the QuotaObject before
|
// Even though it's not strictly necessary, create the QuotaObject before
|
||||||
// all file IO and keep it alive until caching completes to get maximum
|
// all file IO and keep it alive until caching completes to get maximum
|
||||||
// assertion coverage in QuotaManager against concurrent removal, etc.
|
// assertion coverage in QuotaManager against concurrent removal, etc.
|
||||||
mQuotaObject = qm->GetQuotaObject(quota::PERSISTENCE_TYPE_TEMPORARY, mGroup, mOrigin, file);
|
mQuotaObject = qm->GetQuotaObject(quota::PERSISTENCE_TYPE_TEMPORARY, mGroup, mOrigin, file);
|
||||||
NS_ENSURE_STATE(mQuotaObject);
|
NS_ENSURE_STATE(mQuotaObject);
|
||||||
}
|
|
||||||
|
|
||||||
rv = file->GetFileSize(&mFileSize);
|
rv = file->GetFileSize(&mFileSize);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
|
||||||
|
|
@ -21015,9 +21015,9 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
|
||||||
if (State::Initial == mState) {
|
if (State::Initial == mState) {
|
||||||
QuotaManager::GetInfoForChrome(&mSuffix, &mGroup, &mOrigin);
|
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;
|
*aPermission = PermissionRequestBase::kPermissionAllowed;
|
||||||
|
|
@ -21046,11 +21046,15 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
|
||||||
|
|
||||||
PermissionRequestBase::PermissionValue permission;
|
PermissionRequestBase::PermissionValue permission;
|
||||||
|
|
||||||
if (QuotaManager::IsFirstPromptRequired(persistenceType, origin)) {
|
if (persistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||||
|
if (QuotaManager::IsOriginInternal(origin)) {
|
||||||
|
permission = PermissionRequestBase::kPermissionAllowed;
|
||||||
|
} else {
|
||||||
rv = PermissionRequestBase::GetCurrentPermission(principal, &permission);
|
rv = PermissionRequestBase::GetCurrentPermission(principal, &permission);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
permission = PermissionRequestBase::kPermissionAllowed;
|
permission = PermissionRequestBase::kPermissionAllowed;
|
||||||
}
|
}
|
||||||
|
|
@ -21061,7 +21065,7 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
|
||||||
mGroup = group;
|
mGroup = group;
|
||||||
mOrigin = origin;
|
mOrigin = origin;
|
||||||
|
|
||||||
mEnforcingQuota = QuotaManager::IsQuotaEnforced(persistenceType);
|
mEnforcingQuota = persistenceType != PERSISTENCE_TYPE_PERSISTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
*aPermission = permission;
|
*aPermission = permission;
|
||||||
|
|
|
||||||
|
|
@ -1556,18 +1556,6 @@ private:
|
||||||
DoProcessOriginDirectories();
|
DoProcessOriginDirectories();
|
||||||
};
|
};
|
||||||
|
|
||||||
class OriginKey : public nsAutoCString
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OriginKey(PersistenceType aPersistenceType,
|
|
||||||
const nsACString& aOrigin)
|
|
||||||
{
|
|
||||||
PersistenceTypeToText(aPersistenceType, *this);
|
|
||||||
Append(':');
|
|
||||||
Append(aOrigin);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SanitizeOriginString(nsCString& aOrigin)
|
SanitizeOriginString(nsCString& aOrigin)
|
||||||
{
|
{
|
||||||
|
|
@ -1581,18 +1569,6 @@ SanitizeOriginString(nsCString& aOrigin)
|
||||||
aOrigin.ReplaceChar(QuotaManager::kReplaceChars, '+');
|
aOrigin.ReplaceChar(QuotaManager::kReplaceChars, '+');
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
IsTreatedAsPersistent(PersistenceType aPersistenceType)
|
|
||||||
{
|
|
||||||
return aPersistenceType == PERSISTENCE_TYPE_PERSISTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
IsTreatedAsTemporary(PersistenceType aPersistenceType)
|
|
||||||
{
|
|
||||||
return !IsTreatedAsPersistent(aPersistenceType);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
CloneStoragePath(nsIFile* aBaseDir,
|
CloneStoragePath(nsIFile* aBaseDir,
|
||||||
const nsAString& aStorageName,
|
const nsAString& aStorageName,
|
||||||
|
|
@ -3006,7 +2982,7 @@ QuotaManager::CollectOriginsForEviction(
|
||||||
nsTArray<OriginInfo*>& aInactiveOriginInfos)
|
nsTArray<OriginInfo*>& aInactiveOriginInfos)
|
||||||
{
|
{
|
||||||
for (OriginInfo* originInfo : aOriginInfos) {
|
for (OriginInfo* originInfo : aOriginInfos) {
|
||||||
MOZ_ASSERT(IsTreatedAsTemporary(originInfo->mGroupInfo->mPersistenceType));
|
MOZ_ASSERT(originInfo->mGroupInfo->mPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
|
||||||
|
|
||||||
OriginScope originScope = OriginScope::FromOrigin(originInfo->mOrigin);
|
OriginScope originScope = OriginScope::FromOrigin(originInfo->mOrigin);
|
||||||
|
|
||||||
|
|
@ -3263,7 +3239,7 @@ QuotaManager::InitQuotaForOrigin(PersistenceType aPersistenceType,
|
||||||
int64_t aAccessTime)
|
int64_t aAccessTime)
|
||||||
{
|
{
|
||||||
AssertIsOnIOThread();
|
AssertIsOnIOThread();
|
||||||
MOZ_ASSERT(IsTreatedAsTemporary(aPersistenceType));
|
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
|
||||||
|
|
||||||
MutexAutoLock lock(mQuotaMutex);
|
MutexAutoLock lock(mQuotaMutex);
|
||||||
|
|
||||||
|
|
@ -3804,7 +3780,7 @@ QuotaManager::InitializeOrigin(PersistenceType aPersistenceType,
|
||||||
|
|
||||||
nsresult rv;
|
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
|
// We need to initialize directories of all clients if they exists and also
|
||||||
// get the total usage to initialize the quota.
|
// get the total usage to initialize the quota.
|
||||||
|
|
@ -4443,8 +4419,8 @@ QuotaManager::EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
||||||
getter_AddRefs(directory));
|
getter_AddRefs(directory));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (IsTreatedAsPersistent(aPersistenceType)) {
|
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||||
if (mInitializedOrigins.Contains(OriginKey(aPersistenceType, aOrigin))) {
|
if (mInitializedOrigins.Contains(aOrigin)) {
|
||||||
directory.forget(aDirectory);
|
directory.forget(aDirectory);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -4496,7 +4472,7 @@ QuotaManager::EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
||||||
rv = EnsureDirectory(directory, &created);
|
rv = EnsureDirectory(directory, &created);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (IsTreatedAsPersistent(aPersistenceType)) {
|
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||||
if (created) {
|
if (created) {
|
||||||
timestamp = PR_Now();
|
timestamp = PR_Now();
|
||||||
|
|
||||||
|
|
@ -4516,9 +4492,8 @@ QuotaManager::EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
||||||
aOrigin);
|
aOrigin);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
} else {
|
} else {
|
||||||
bool persistent = aPersistenceType == PERSISTENCE_TYPE_PERSISTENT;
|
|
||||||
rv = GetDirectoryMetadata2WithRestore(directory,
|
rv = GetDirectoryMetadata2WithRestore(directory,
|
||||||
persistent,
|
/* aPersistent */ true,
|
||||||
×tamp);
|
×tamp);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
|
|
@ -4530,7 +4505,7 @@ QuotaManager::EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
||||||
rv = InitializeOrigin(aPersistenceType, aGroup, aOrigin, timestamp, directory);
|
rv = InitializeOrigin(aPersistenceType, aGroup, aOrigin, timestamp, directory);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
mInitializedOrigins.AppendElement(OriginKey(aPersistenceType, aOrigin));
|
mInitializedOrigins.AppendElement(aOrigin);
|
||||||
} else if (created) {
|
} else if (created) {
|
||||||
timestamp = PR_Now();
|
timestamp = PR_Now();
|
||||||
|
|
||||||
|
|
@ -4564,8 +4539,8 @@ QuotaManager::OriginClearCompleted(PersistenceType aPersistenceType,
|
||||||
{
|
{
|
||||||
AssertIsOnIOThread();
|
AssertIsOnIOThread();
|
||||||
|
|
||||||
if (IsTreatedAsPersistent(aPersistenceType)) {
|
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||||
mInitializedOrigins.RemoveElement(OriginKey(aPersistenceType, aOrigin));
|
mInitializedOrigins.RemoveElement(aOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t index = 0; index < Client::TYPE_MAX; index++) {
|
for (uint32_t index = 0; index < Client::TYPE_MAX; index++) {
|
||||||
|
|
@ -4791,25 +4766,6 @@ QuotaManager::IsOriginInternal(const nsACString& aOrigin)
|
||||||
return false;
|
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
|
// static
|
||||||
void
|
void
|
||||||
QuotaManager::ChromeOrigin(nsACString& aOrigin)
|
QuotaManager::ChromeOrigin(nsACString& aOrigin)
|
||||||
|
|
@ -5872,9 +5828,8 @@ QuotaUsageRequestBase::GetUsageForOrigin(QuotaManager* aQuotaManager,
|
||||||
if (exists && !mCanceled) {
|
if (exists && !mCanceled) {
|
||||||
bool initialized;
|
bool initialized;
|
||||||
|
|
||||||
if (IsTreatedAsPersistent(aPersistenceType)) {
|
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||||
nsCString originKey = OriginKey(aPersistenceType, aOrigin);
|
initialized = aQuotaManager->IsOriginInitialized(mOriginScope.GetOrigin());
|
||||||
initialized = aQuotaManager->IsOriginInitialized(originKey);
|
|
||||||
} else {
|
} else {
|
||||||
initialized = aQuotaManager->IsTemporaryStorageInitialized();
|
initialized = aQuotaManager->IsTemporaryStorageInitialized();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -373,13 +373,6 @@ public:
|
||||||
static bool
|
static bool
|
||||||
IsOriginInternal(const nsACString& aOrigin);
|
IsOriginInternal(const nsACString& aOrigin);
|
||||||
|
|
||||||
static bool
|
|
||||||
IsFirstPromptRequired(PersistenceType aPersistenceType,
|
|
||||||
const nsACString& aOrigin);
|
|
||||||
|
|
||||||
static bool
|
|
||||||
IsQuotaEnforced(PersistenceType aPersistenceType);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ChromeOrigin(nsACString& aOrigin);
|
ChromeOrigin(nsACString& aOrigin);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue