2013-03-26 15:13:17 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "QuotaObject.h"
|
|
|
|
|
|
|
|
#include "QuotaManager.h"
|
2013-09-11 08:18:36 +04:00
|
|
|
#include "Utilities.h"
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
USING_QUOTA_NAMESPACE
|
|
|
|
|
|
|
|
void
|
|
|
|
QuotaObject::AddRef()
|
|
|
|
{
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
if (!quotaManager) {
|
|
|
|
NS_ERROR("Null quota manager, this shouldn't happen, possible leak!");
|
|
|
|
|
2013-07-19 06:21:20 +04:00
|
|
|
++mRefCnt;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MutexAutoLock lock(quotaManager->mQuotaMutex);
|
|
|
|
|
|
|
|
++mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QuotaObject::Release()
|
|
|
|
{
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
if (!quotaManager) {
|
|
|
|
NS_ERROR("Null quota manager, this shouldn't happen, possible leak!");
|
|
|
|
|
2013-07-19 06:21:20 +04:00
|
|
|
nsrefcnt count = --mRefCnt;
|
2013-03-26 15:13:17 +04:00
|
|
|
if (count == 0) {
|
|
|
|
mRefCnt = 1;
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(quotaManager->mQuotaMutex);
|
|
|
|
|
|
|
|
--mRefCnt;
|
|
|
|
|
|
|
|
if (mRefCnt > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOriginInfo) {
|
|
|
|
mOriginInfo->mQuotaObjects.Remove(mPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QuotaObject::UpdateSize(int64_t aSize)
|
|
|
|
{
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
|
|
|
|
MutexAutoLock lock(quotaManager->mQuotaMutex);
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
if (!mOriginInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupInfo* groupInfo = mOriginInfo->mGroupInfo;
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
if (mOriginInfo->IsTreatedAsTemporary()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
quotaManager->mTemporaryStorageUsage -= mSize;
|
|
|
|
}
|
|
|
|
groupInfo->mUsage -= mSize;
|
|
|
|
mOriginInfo->mUsage -= mSize;
|
|
|
|
|
|
|
|
mSize = aSize;
|
|
|
|
|
|
|
|
mOriginInfo->mUsage += mSize;
|
|
|
|
groupInfo->mUsage += mSize;
|
2014-11-04 23:44:56 +03:00
|
|
|
if (mOriginInfo->IsTreatedAsTemporary()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
quotaManager->mTemporaryStorageUsage += mSize;
|
2013-03-26 15:13:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
QuotaObject::MaybeAllocateMoreSpace(int64_t aOffset, int32_t aCount)
|
|
|
|
{
|
|
|
|
int64_t end = aOffset + aCount;
|
|
|
|
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
|
|
|
|
MutexAutoLock lock(quotaManager->mQuotaMutex);
|
|
|
|
|
|
|
|
if (mSize >= end || !mOriginInfo) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
GroupInfo* groupInfo = mOriginInfo->mGroupInfo;
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
if (mOriginInfo->IsTreatedAsPersistent()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
uint64_t newUsage = mOriginInfo->mUsage - mSize + end;
|
|
|
|
|
|
|
|
if (newUsage > mOriginInfo->mLimit) {
|
|
|
|
// This will block the thread, but it will also drop the mutex while
|
|
|
|
// waiting. The mutex will be reacquired again when the waiting is
|
|
|
|
// finished.
|
|
|
|
if (!quotaManager->LockedQuotaIsLifted()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Threads raced, the origin info removal has been done by some other
|
|
|
|
// thread.
|
|
|
|
if (!mOriginInfo) {
|
|
|
|
// The other thread could allocate more space.
|
|
|
|
if (end > mSize) {
|
|
|
|
mSize = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString group = mOriginInfo->mGroupInfo->mGroup;
|
|
|
|
nsCString origin = mOriginInfo->mOrigin;
|
|
|
|
|
|
|
|
mOriginInfo->LockedClearOriginInfos();
|
|
|
|
NS_ASSERTION(!mOriginInfo,
|
|
|
|
"Should have cleared in LockedClearOriginInfos!");
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
quotaManager->LockedRemoveQuotaForOrigin(groupInfo->mPersistenceType,
|
2013-09-11 08:18:36 +04:00
|
|
|
group, origin);
|
|
|
|
|
|
|
|
// Some other thread could increase the size without blocking (increasing
|
|
|
|
// the origin usage without hitting the limit), but no more than this one.
|
|
|
|
NS_ASSERTION(mSize < end, "This shouldn't happen!");
|
|
|
|
|
|
|
|
mSize = end;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOriginInfo->mUsage = newUsage;
|
|
|
|
|
|
|
|
groupInfo->mUsage = groupInfo->mUsage - mSize + end;
|
|
|
|
|
|
|
|
mSize = end;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
nsRefPtr<GroupInfo> complementaryGroupInfo =
|
2014-11-28 11:44:12 +03:00
|
|
|
groupInfo->mGroupInfoTriple->LockedGetGroupInfo(
|
2014-11-04 23:44:56 +03:00
|
|
|
ComplementaryPersistenceType(groupInfo->mPersistenceType));
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
uint64_t delta = end - mSize;
|
|
|
|
|
|
|
|
uint64_t newUsage = mOriginInfo->mUsage + delta;
|
|
|
|
|
|
|
|
// Temporary storage has no limit for origin usage (there's a group and the
|
|
|
|
// global limit though).
|
|
|
|
|
|
|
|
uint64_t newGroupUsage = groupInfo->mUsage + delta;
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
uint64_t groupUsage = groupInfo->LockedGetTemporaryUsage();
|
|
|
|
if (complementaryGroupInfo) {
|
|
|
|
groupUsage += complementaryGroupInfo->LockedGetTemporaryUsage();
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
// Temporary storage has a hard limit for group usage (20 % of the global
|
|
|
|
// limit).
|
2014-11-04 23:44:56 +03:00
|
|
|
if (groupUsage + delta > quotaManager->GetGroupLimit()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t newTemporaryStorageUsage = quotaManager->mTemporaryStorageUsage +
|
|
|
|
delta;
|
|
|
|
|
|
|
|
if (newTemporaryStorageUsage > quotaManager->mTemporaryStorageLimit) {
|
|
|
|
// This will block the thread without holding the lock while waitting.
|
|
|
|
|
|
|
|
nsAutoTArray<OriginInfo*, 10> originInfos;
|
|
|
|
uint64_t sizeToBeFreed =
|
|
|
|
quotaManager->LockedCollectOriginsForEviction(delta, originInfos);
|
|
|
|
|
|
|
|
if (!sizeToBeFreed) {
|
2013-03-26 15:13:17 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
NS_ASSERTION(sizeToBeFreed >= delta, "Huh?");
|
|
|
|
|
|
|
|
{
|
|
|
|
MutexAutoUnlock autoUnlock(quotaManager->mQuotaMutex);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < originInfos.Length(); i++) {
|
2014-11-04 23:44:56 +03:00
|
|
|
OriginInfo* originInfo = originInfos[i];
|
|
|
|
|
|
|
|
quotaManager->DeleteFilesForOrigin(
|
|
|
|
originInfo->mGroupInfo->mPersistenceType,
|
|
|
|
originInfo->mOrigin);
|
2013-03-26 15:13:17 +04:00
|
|
|
}
|
2013-09-11 08:18:36 +04:00
|
|
|
}
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
// Relocked.
|
|
|
|
|
|
|
|
NS_ASSERTION(mOriginInfo, "How come?!");
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
nsTArray<OriginParams> origins;
|
2013-09-11 08:18:36 +04:00
|
|
|
for (uint32_t i = 0; i < originInfos.Length(); i++) {
|
|
|
|
OriginInfo* originInfo = originInfos[i];
|
|
|
|
|
|
|
|
NS_ASSERTION(originInfo != mOriginInfo, "Deleted itself!");
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
PersistenceType persistenceType =
|
|
|
|
originInfo->mGroupInfo->mPersistenceType;
|
2013-09-11 08:18:36 +04:00
|
|
|
nsCString group = originInfo->mGroupInfo->mGroup;
|
|
|
|
nsCString origin = originInfo->mOrigin;
|
2014-11-28 11:44:12 +03:00
|
|
|
bool isApp = originInfo->mIsApp;
|
2014-11-04 23:44:56 +03:00
|
|
|
quotaManager->LockedRemoveQuotaForOrigin(persistenceType, group, origin);
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
originInfos[i] = nullptr;
|
|
|
|
#endif
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
origins.AppendElement(OriginParams(persistenceType, origin, isApp));
|
2013-03-26 15:13:17 +04:00
|
|
|
}
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
// We unlocked and relocked several times so we need to recompute all the
|
|
|
|
// essential variables and recheck the group limit.
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
delta = end - mSize;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
newUsage = mOriginInfo->mUsage + delta;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
newGroupUsage = groupInfo->mUsage + delta;
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
groupUsage = groupInfo->LockedGetTemporaryUsage();
|
|
|
|
if (complementaryGroupInfo) {
|
|
|
|
groupUsage += complementaryGroupInfo->LockedGetTemporaryUsage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groupUsage + delta > quotaManager->GetGroupLimit()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
// Unfortunately some other thread increased the group usage in the
|
|
|
|
// meantime and we are not below the group limit anymore.
|
|
|
|
|
|
|
|
// However, the origin eviction must be finalized in this case too.
|
|
|
|
MutexAutoUnlock autoUnlock(quotaManager->mQuotaMutex);
|
|
|
|
|
|
|
|
quotaManager->FinalizeOriginEviction(origins);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
newTemporaryStorageUsage = quotaManager->mTemporaryStorageUsage + delta;
|
|
|
|
|
|
|
|
NS_ASSERTION(newTemporaryStorageUsage <=
|
|
|
|
quotaManager->mTemporaryStorageLimit, "How come?!");
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
// Ok, we successfully freed enough space and the operation can continue
|
|
|
|
// without throwing the quota error.
|
|
|
|
|
|
|
|
mOriginInfo->mUsage = newUsage;
|
|
|
|
groupInfo->mUsage = newGroupUsage;
|
|
|
|
quotaManager->mTemporaryStorageUsage = newTemporaryStorageUsage;;
|
|
|
|
|
|
|
|
// Some other thread could increase the size in the meantime, but no more
|
|
|
|
// than this one.
|
|
|
|
NS_ASSERTION(mSize < end, "This shouldn't happen!");
|
2013-03-26 15:13:17 +04:00
|
|
|
mSize = end;
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
// Finally, release IO thread only objects and allow next synchronized
|
|
|
|
// ops for the evicted origins.
|
|
|
|
MutexAutoUnlock autoUnlock(quotaManager->mQuotaMutex);
|
|
|
|
|
|
|
|
quotaManager->FinalizeOriginEviction(origins);
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOriginInfo->mUsage = newUsage;
|
2013-09-11 08:18:36 +04:00
|
|
|
groupInfo->mUsage = newGroupUsage;
|
|
|
|
quotaManager->mTemporaryStorageUsage = newTemporaryStorageUsage;
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
mSize = end;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
bool
|
|
|
|
OriginInfo::IsTreatedAsPersistent() const
|
|
|
|
{
|
|
|
|
return QuotaManager::IsTreatedAsPersistent(mGroupInfo->mPersistenceType,
|
2014-11-28 11:44:12 +03:00
|
|
|
mIsApp);
|
2014-11-04 23:44:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
OriginInfo::IsTreatedAsTemporary() const
|
|
|
|
{
|
|
|
|
return QuotaManager::IsTreatedAsTemporary(mGroupInfo->mPersistenceType,
|
2014-11-28 11:44:12 +03:00
|
|
|
mIsApp);
|
2014-11-04 23:44:56 +03:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
void
|
2013-09-11 08:18:36 +04:00
|
|
|
OriginInfo::LockedDecreaseUsage(int64_t aSize)
|
2013-03-26 15:13:17 +04:00
|
|
|
{
|
2013-09-11 08:18:36 +04:00
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
mUsage -= aSize;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
mGroupInfo->mUsage -= aSize;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
if (IsTreatedAsTemporary()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
|
|
|
|
quotaManager->mTemporaryStorageUsage -= aSize;
|
|
|
|
}
|
2013-03-26 15:13:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
PLDHashOperator
|
|
|
|
OriginInfo::ClearOriginInfoCallback(const nsAString& aKey,
|
|
|
|
QuotaObject* aValue,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aKey.IsEmpty(), "Empty key!");
|
|
|
|
NS_ASSERTION(aValue, "Null pointer!");
|
|
|
|
|
|
|
|
aValue->mOriginInfo = nullptr;
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
already_AddRefed<OriginInfo>
|
|
|
|
GroupInfo::LockedGetOriginInfo(const nsACString& aOrigin)
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < mOriginInfos.Length(); index++) {
|
|
|
|
nsRefPtr<OriginInfo>& originInfo = mOriginInfos[index];
|
|
|
|
|
|
|
|
if (originInfo->mOrigin == aOrigin) {
|
|
|
|
nsRefPtr<OriginInfo> result = originInfo;
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GroupInfo::LockedAddOriginInfo(OriginInfo* aOriginInfo)
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
NS_ASSERTION(!mOriginInfos.Contains(aOriginInfo),
|
|
|
|
"Replacing an existing entry!");
|
|
|
|
mOriginInfos.AppendElement(aOriginInfo);
|
|
|
|
|
|
|
|
mUsage += aOriginInfo->mUsage;
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
if (aOriginInfo->IsTreatedAsTemporary()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
|
|
|
|
quotaManager->mTemporaryStorageUsage += aOriginInfo->mUsage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GroupInfo::LockedRemoveOriginInfo(const nsACString& aOrigin)
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < mOriginInfos.Length(); index++) {
|
|
|
|
if (mOriginInfos[index]->mOrigin == aOrigin) {
|
|
|
|
mUsage -= mOriginInfos[index]->mUsage;
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
if (mOriginInfos[index]->IsTreatedAsTemporary()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
|
|
|
|
quotaManager->mTemporaryStorageUsage -= mOriginInfos[index]->mUsage;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOriginInfos.RemoveElementAt(index);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GroupInfo::LockedRemoveOriginInfos()
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
for (uint32_t index = mOriginInfos.Length(); index > 0; index--) {
|
2014-11-04 23:44:56 +03:00
|
|
|
OriginInfo* originInfo = mOriginInfos[index - 1];
|
|
|
|
|
|
|
|
mUsage -= originInfo->mUsage;
|
2013-09-11 08:18:36 +04:00
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
if (originInfo->IsTreatedAsTemporary()) {
|
2013-09-11 08:18:36 +04:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "Shouldn't be null!");
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
quotaManager->mTemporaryStorageUsage -= originInfo->mUsage;
|
2013-09-11 08:18:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mOriginInfos.RemoveElementAt(index - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
uint64_t
|
|
|
|
GroupInfo::LockedGetTemporaryUsage()
|
|
|
|
{
|
|
|
|
uint64_t usage = 0;
|
|
|
|
|
|
|
|
for (uint32_t count = mOriginInfos.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
nsRefPtr<OriginInfo>& originInfo = mOriginInfos[index];
|
|
|
|
|
|
|
|
if (originInfo->IsTreatedAsTemporary()) {
|
|
|
|
usage += originInfo->mUsage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GroupInfo::LockedGetTemporaryOriginInfos(nsTArray<OriginInfo*>* aOriginInfos)
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
for (uint32_t count = mOriginInfos.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
nsRefPtr<OriginInfo>& originInfo = mOriginInfos[index];
|
|
|
|
|
|
|
|
if (originInfo->IsTreatedAsTemporary()) {
|
|
|
|
aOriginInfos->AppendElement(originInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GroupInfo::LockedRemoveTemporaryOriginInfos()
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
MOZ_ASSERT(quotaManager);
|
|
|
|
|
|
|
|
for (uint32_t index = mOriginInfos.Length(); index > 0; index--) {
|
|
|
|
OriginInfo* originInfo = mOriginInfos[index - 1];
|
|
|
|
if (originInfo->IsTreatedAsTemporary()) {
|
|
|
|
MOZ_ASSERT(mUsage >= originInfo->mUsage);
|
|
|
|
mUsage -= originInfo->mUsage;
|
|
|
|
|
|
|
|
MOZ_ASSERT(quotaManager->mTemporaryStorageUsage >= originInfo->mUsage);
|
|
|
|
quotaManager->mTemporaryStorageUsage -= originInfo->mUsage;
|
|
|
|
|
|
|
|
mOriginInfos.RemoveElementAt(index - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
nsRefPtr<GroupInfo>&
|
2014-11-28 11:44:12 +03:00
|
|
|
GroupInfoTriple::GetGroupInfoForPersistenceType(
|
|
|
|
PersistenceType aPersistenceType)
|
2013-09-11 08:18:36 +04:00
|
|
|
{
|
|
|
|
switch (aPersistenceType) {
|
|
|
|
case PERSISTENCE_TYPE_PERSISTENT:
|
|
|
|
return mPersistentStorageGroupInfo;
|
|
|
|
case PERSISTENCE_TYPE_TEMPORARY:
|
|
|
|
return mTemporaryStorageGroupInfo;
|
2014-11-28 11:44:12 +03:00
|
|
|
case PERSISTENCE_TYPE_DEFAULT:
|
|
|
|
return mDefaultStorageGroupInfo;
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
case PERSISTENCE_TYPE_INVALID:
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad persistence type value!");
|
|
|
|
return mPersistentStorageGroupInfo;
|
|
|
|
}
|
|
|
|
}
|