1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_quota_quotaobject_h__
8 #define mozilla_dom_quota_quotaobject_h__
10 #include "mozilla/dom/quota/QuotaCommon.h"
12 #include "nsDataHashtable.h"
14 #include "PersistenceType.h"
25 friend class OriginInfo
;
26 friend class QuotaManager
;
36 UpdateSize(int64_t aSize
);
39 MaybeAllocateMoreSpace(int64_t aOffset
, int32_t aCount
);
42 QuotaObject(OriginInfo
* aOriginInfo
, const nsAString
& aPath
, int64_t aSize
)
43 : mOriginInfo(aOriginInfo
), mPath(aPath
), mSize(aSize
)
45 MOZ_COUNT_CTOR(QuotaObject
);
50 MOZ_COUNT_DTOR(QuotaObject
);
53 mozilla::ThreadSafeAutoRefCnt mRefCnt
;
55 OriginInfo
* mOriginInfo
;
62 friend class GroupInfo
;
63 friend class QuotaManager
;
64 friend class QuotaObject
;
67 OriginInfo(GroupInfo
* aGroupInfo
, const nsACString
& aOrigin
, uint64_t aLimit
,
68 uint64_t aUsage
, int64_t aAccessTime
)
69 : mGroupInfo(aGroupInfo
), mOrigin(aOrigin
), mLimit(aLimit
), mUsage(aUsage
),
70 mAccessTime(aAccessTime
)
72 MOZ_COUNT_CTOR(OriginInfo
);
77 MOZ_COUNT_DTOR(OriginInfo
);
80 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OriginInfo
)
90 LockedDecreaseUsage(int64_t aSize
);
93 LockedUpdateAccessTime(int64_t aAccessTime
)
95 AssertCurrentThreadOwnsQuotaMutex();
97 mAccessTime
= aAccessTime
;
101 LockedClearOriginInfos()
103 AssertCurrentThreadOwnsQuotaMutex();
105 mQuotaObjects
.EnumerateRead(ClearOriginInfoCallback
, nullptr);
108 static PLDHashOperator
109 ClearOriginInfoCallback(const nsAString
& aKey
,
110 QuotaObject
* aValue
, void* aUserArg
);
112 nsDataHashtable
<nsStringHashKey
, QuotaObject
*> mQuotaObjects
;
114 GroupInfo
* mGroupInfo
;
121 class OriginInfoLRUComparator
125 Equals(const OriginInfo
* a
, const OriginInfo
* b
) const
128 a
&& b
? a
->AccessTime() == b
->AccessTime() : !a
&& !b
? true : false;
132 LessThan(const OriginInfo
* a
, const OriginInfo
* b
) const
134 return a
&& b
? a
->AccessTime() < b
->AccessTime() : b
? true : false;
140 friend class GroupInfoPair
;
141 friend class OriginInfo
;
142 friend class QuotaManager
;
143 friend class QuotaObject
;
146 GroupInfo(PersistenceType aPersistenceType
, const nsACString
& aGroup
)
147 : mPersistenceType(aPersistenceType
), mGroup(aGroup
), mUsage(0)
149 MOZ_COUNT_CTOR(GroupInfo
);
154 MOZ_COUNT_DTOR(GroupInfo
);
157 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GroupInfo
)
160 IsForPersistentStorage() const
162 return mPersistenceType
== PERSISTENCE_TYPE_PERSISTENT
;
166 IsForTemporaryStorage() const
168 return mPersistenceType
== PERSISTENCE_TYPE_TEMPORARY
;
172 already_AddRefed
<OriginInfo
>
173 LockedGetOriginInfo(const nsACString
& aOrigin
);
176 LockedAddOriginInfo(OriginInfo
* aOriginInfo
);
179 LockedRemoveOriginInfo(const nsACString
& aOrigin
);
182 LockedRemoveOriginInfos();
185 LockedRemoveOriginInfosForPattern(const nsACString
& aPattern
);
188 LockedHasOriginInfos()
190 AssertCurrentThreadOwnsQuotaMutex();
192 return !mOriginInfos
.IsEmpty();
195 nsTArray
<nsRefPtr
<OriginInfo
> > mOriginInfos
;
197 PersistenceType mPersistenceType
;
204 friend class QuotaManager
;
209 MOZ_COUNT_CTOR(GroupInfoPair
);
214 MOZ_COUNT_DTOR(GroupInfoPair
);
218 already_AddRefed
<GroupInfo
>
219 LockedGetGroupInfo(PersistenceType aPersistenceType
)
221 AssertCurrentThreadOwnsQuotaMutex();
223 nsRefPtr
<GroupInfo
> groupInfo
=
224 GetGroupInfoForPersistenceType(aPersistenceType
);
225 return groupInfo
.forget();
229 LockedSetGroupInfo(GroupInfo
* aGroupInfo
)
231 AssertCurrentThreadOwnsQuotaMutex();
233 nsRefPtr
<GroupInfo
>& groupInfo
=
234 GetGroupInfoForPersistenceType(aGroupInfo
->mPersistenceType
);
235 groupInfo
= aGroupInfo
;
239 LockedClearGroupInfo(PersistenceType aPersistenceType
)
241 AssertCurrentThreadOwnsQuotaMutex();
243 nsRefPtr
<GroupInfo
>& groupInfo
=
244 GetGroupInfoForPersistenceType(aPersistenceType
);
249 LockedHasGroupInfos()
251 AssertCurrentThreadOwnsQuotaMutex();
253 return mPersistentStorageGroupInfo
|| mTemporaryStorageGroupInfo
;
257 GetGroupInfoForPersistenceType(PersistenceType aPersistenceType
);
259 nsRefPtr
<GroupInfo
> mPersistentStorageGroupInfo
;
260 nsRefPtr
<GroupInfo
> mTemporaryStorageGroupInfo
;
265 #endif // mozilla_dom_quota_quotaobject_h__