2013-03-26 04:13:17 -07: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_quota_quotaobject_h__
|
|
|
|
#define mozilla_dom_quota_quotaobject_h__
|
|
|
|
|
|
|
|
#include "mozilla/dom/quota/QuotaCommon.h"
|
|
|
|
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
#include "PersistenceType.h"
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
BEGIN_QUOTA_NAMESPACE
|
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
class GroupInfo;
|
|
|
|
class GroupInfoPair;
|
2013-03-26 04:13:17 -07:00
|
|
|
class OriginInfo;
|
|
|
|
class QuotaManager;
|
|
|
|
|
|
|
|
class QuotaObject
|
|
|
|
{
|
|
|
|
friend class OriginInfo;
|
|
|
|
friend class QuotaManager;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void
|
|
|
|
AddRef();
|
|
|
|
|
|
|
|
void
|
|
|
|
Release();
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateSize(int64_t aSize);
|
|
|
|
|
|
|
|
bool
|
|
|
|
MaybeAllocateMoreSpace(int64_t aOffset, int32_t aCount);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QuotaObject(OriginInfo* aOriginInfo, const nsAString& aPath, int64_t aSize)
|
|
|
|
: mOriginInfo(aOriginInfo), mPath(aPath), mSize(aSize)
|
2013-09-10 21:18:36 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(QuotaObject);
|
|
|
|
}
|
2013-03-26 04:13:17 -07:00
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
~QuotaObject()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(QuotaObject);
|
|
|
|
}
|
2013-03-26 04:13:17 -07:00
|
|
|
|
2013-07-18 19:21:20 -07:00
|
|
|
mozilla::ThreadSafeAutoRefCnt mRefCnt;
|
2013-03-26 04:13:17 -07:00
|
|
|
|
|
|
|
OriginInfo* mOriginInfo;
|
|
|
|
nsString mPath;
|
|
|
|
int64_t mSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OriginInfo
|
|
|
|
{
|
2013-09-10 21:18:36 -07:00
|
|
|
friend class GroupInfo;
|
2013-03-26 04:13:17 -07:00
|
|
|
friend class QuotaManager;
|
|
|
|
friend class QuotaObject;
|
|
|
|
|
|
|
|
public:
|
2013-09-10 21:18:36 -07:00
|
|
|
OriginInfo(GroupInfo* aGroupInfo, const nsACString& aOrigin, uint64_t aLimit,
|
|
|
|
uint64_t aUsage, int64_t aAccessTime)
|
|
|
|
: mGroupInfo(aGroupInfo), mOrigin(aOrigin), mLimit(aLimit), mUsage(aUsage),
|
|
|
|
mAccessTime(aAccessTime)
|
2013-03-26 04:13:17 -07:00
|
|
|
{
|
2013-09-10 21:18:36 -07:00
|
|
|
MOZ_COUNT_CTOR(OriginInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
~OriginInfo()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(OriginInfo);
|
2013-03-26 04:13:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OriginInfo)
|
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
int64_t
|
|
|
|
AccessTime() const
|
|
|
|
{
|
|
|
|
return mAccessTime;
|
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
private:
|
|
|
|
void
|
2013-09-10 21:18:36 -07:00
|
|
|
LockedDecreaseUsage(int64_t aSize);
|
|
|
|
|
|
|
|
void
|
|
|
|
LockedUpdateAccessTime(int64_t aAccessTime)
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
mAccessTime = aAccessTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-26 04:13:17 -07:00
|
|
|
LockedClearOriginInfos()
|
|
|
|
{
|
2013-09-10 21:18:36 -07:00
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
mQuotaObjects.EnumerateRead(ClearOriginInfoCallback, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
ClearOriginInfoCallback(const nsAString& aKey,
|
|
|
|
QuotaObject* aValue, void* aUserArg);
|
|
|
|
|
|
|
|
nsDataHashtable<nsStringHashKey, QuotaObject*> mQuotaObjects;
|
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
GroupInfo* mGroupInfo;
|
2013-03-26 04:13:17 -07:00
|
|
|
nsCString mOrigin;
|
2013-09-10 21:18:36 -07:00
|
|
|
uint64_t mLimit;
|
|
|
|
uint64_t mUsage;
|
|
|
|
int64_t mAccessTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OriginInfoLRUComparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool
|
|
|
|
Equals(const OriginInfo* a, const OriginInfo* b) const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
a && b ? a->AccessTime() == b->AccessTime() : !a && !b ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
LessThan(const OriginInfo* a, const OriginInfo* b) const
|
|
|
|
{
|
|
|
|
return a && b ? a->AccessTime() < b->AccessTime() : b ? true : false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GroupInfo
|
|
|
|
{
|
|
|
|
friend class GroupInfoPair;
|
|
|
|
friend class OriginInfo;
|
|
|
|
friend class QuotaManager;
|
|
|
|
friend class QuotaObject;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GroupInfo(PersistenceType aPersistenceType, const nsACString& aGroup)
|
|
|
|
: mPersistenceType(aPersistenceType), mGroup(aGroup), mUsage(0)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(GroupInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
~GroupInfo()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(GroupInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GroupInfo)
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsForPersistentStorage() const
|
|
|
|
{
|
|
|
|
return mPersistenceType == PERSISTENCE_TYPE_PERSISTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsForTemporaryStorage() const
|
|
|
|
{
|
|
|
|
return mPersistenceType == PERSISTENCE_TYPE_TEMPORARY;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
already_AddRefed<OriginInfo>
|
|
|
|
LockedGetOriginInfo(const nsACString& aOrigin);
|
|
|
|
|
|
|
|
void
|
|
|
|
LockedAddOriginInfo(OriginInfo* aOriginInfo);
|
|
|
|
|
|
|
|
void
|
|
|
|
LockedRemoveOriginInfo(const nsACString& aOrigin);
|
|
|
|
|
|
|
|
void
|
|
|
|
LockedRemoveOriginInfos();
|
|
|
|
|
|
|
|
void
|
|
|
|
LockedRemoveOriginInfosForPattern(const nsACString& aPattern);
|
|
|
|
|
|
|
|
bool
|
|
|
|
LockedHasOriginInfos()
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
return !mOriginInfos.IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<OriginInfo> > mOriginInfos;
|
|
|
|
|
|
|
|
PersistenceType mPersistenceType;
|
|
|
|
nsCString mGroup;
|
|
|
|
uint64_t mUsage;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GroupInfoPair
|
|
|
|
{
|
|
|
|
friend class QuotaManager;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GroupInfoPair()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(GroupInfoPair);
|
|
|
|
}
|
|
|
|
|
|
|
|
~GroupInfoPair()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(GroupInfoPair);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
already_AddRefed<GroupInfo>
|
|
|
|
LockedGetGroupInfo(PersistenceType aPersistenceType)
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
nsRefPtr<GroupInfo> groupInfo =
|
|
|
|
GetGroupInfoForPersistenceType(aPersistenceType);
|
|
|
|
return groupInfo.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LockedSetGroupInfo(GroupInfo* aGroupInfo)
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
nsRefPtr<GroupInfo>& groupInfo =
|
|
|
|
GetGroupInfoForPersistenceType(aGroupInfo->mPersistenceType);
|
|
|
|
groupInfo = aGroupInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LockedClearGroupInfo(PersistenceType aPersistenceType)
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
nsRefPtr<GroupInfo>& groupInfo =
|
|
|
|
GetGroupInfoForPersistenceType(aPersistenceType);
|
|
|
|
groupInfo = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
LockedHasGroupInfos()
|
|
|
|
{
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex();
|
|
|
|
|
|
|
|
return mPersistentStorageGroupInfo || mTemporaryStorageGroupInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<GroupInfo>&
|
|
|
|
GetGroupInfoForPersistenceType(PersistenceType aPersistenceType);
|
|
|
|
|
|
|
|
nsRefPtr<GroupInfo> mPersistentStorageGroupInfo;
|
|
|
|
nsRefPtr<GroupInfo> mTemporaryStorageGroupInfo;
|
2013-03-26 04:13:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_QUOTA_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_quota_quotaobject_h__
|