1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=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 DOM_QUOTA_CANONICALQUOTAOBJECT_H_
8 #define DOM_QUOTA_CANONICALQUOTAOBJECT_H_
15 #include "mozilla/AlreadyAddRefed.h"
16 #include "mozilla/RefPtr.h"
17 #include "mozilla/dom/quota/Assertions.h"
18 #include "mozilla/dom/quota/QuotaObject.h"
20 #include "nsISupports.h"
21 #include "nsStringFwd.h"
23 // XXX Avoid including this here by moving function bodies to the cpp file.
24 #include "mozilla/dom/quota/QuotaCommon.h"
26 namespace mozilla::dom::quota
{
31 class CanonicalQuotaObject final
: public QuotaObject
{
32 friend class OriginInfo
;
33 friend class QuotaManager
;
35 class StoragePressureRunnable
;
38 NS_IMETHOD_(MozExternalRefCountType
) AddRef() override
;
40 NS_IMETHOD_(MozExternalRefCountType
) Release() override
;
42 const nsAString
& Path() const override
{ return mPath
; }
44 [[nodiscard
]] bool MaybeUpdateSize(int64_t aSize
, bool aTruncate
) override
;
46 bool IncreaseSize(int64_t aDelta
) override
;
48 void DisableQuotaCheck() override
;
50 void EnableQuotaCheck() override
;
53 CanonicalQuotaObject(OriginInfo
* aOriginInfo
, Client::Type aClientType
,
54 const nsAString
& aPath
, int64_t aSize
)
55 : QuotaObject(/* aIsRemote */ false),
56 mOriginInfo(aOriginInfo
),
59 mClientType(aClientType
),
60 mQuotaCheckDisabled(false),
62 MOZ_COUNT_CTOR(CanonicalQuotaObject
);
65 MOZ_COUNTED_DTOR(CanonicalQuotaObject
)
67 already_AddRefed
<QuotaObject
> LockedAddRef() {
68 AssertCurrentThreadOwnsQuotaMutex();
72 RefPtr
<QuotaObject
> result
= dont_AddRef(this);
73 return result
.forget();
76 bool LockedMaybeUpdateSize(int64_t aSize
, bool aTruncate
);
78 mozilla::ThreadSafeAutoRefCnt mRefCnt
;
80 OriginInfo
* mOriginInfo
;
83 Client::Type mClientType
;
84 bool mQuotaCheckDisabled
;
88 } // namespace mozilla::dom::quota
90 #endif // DOM_QUOTA_CANONICALQUOTAOBJECT_H_