CanonicalQuotaObject.h (2419B)
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/. */ 6 7 #ifndef DOM_QUOTA_CANONICALQUOTAOBJECT_H_ 8 #define DOM_QUOTA_CANONICALQUOTAOBJECT_H_ 9 10 // Local includes 11 #include "Client.h" 12 13 // Global includes 14 #include <cstdint> 15 16 #include "mozilla/AlreadyAddRefed.h" 17 #include "mozilla/RefPtr.h" 18 #include "mozilla/dom/quota/Assertions.h" 19 #include "mozilla/dom/quota/QuotaObject.h" 20 #include "nsCOMPtr.h" 21 #include "nsISupports.h" 22 #include "nsStringFwd.h" 23 24 // XXX Avoid including this here by moving function bodies to the cpp file. 25 #include "mozilla/dom/quota/QuotaCommon.h" 26 27 namespace mozilla::dom::quota { 28 29 class OriginInfo; 30 class QuotaManager; 31 32 class CanonicalQuotaObject final : public QuotaObject { 33 friend class OriginInfo; 34 friend class QuotaManager; 35 36 class StoragePressureRunnable; 37 38 public: 39 NS_IMETHOD_(MozExternalRefCountType) AddRef() override; 40 41 NS_IMETHOD_(MozExternalRefCountType) Release() override; 42 43 const nsAString& Path() const override { return mPath; } 44 45 [[nodiscard]] bool MaybeUpdateSize(int64_t aSize, bool aTruncate) override; 46 47 bool IncreaseSize(int64_t aDelta) override; 48 49 void DisableQuotaCheck() override; 50 51 void EnableQuotaCheck() override; 52 53 private: 54 CanonicalQuotaObject(OriginInfo* aOriginInfo, Client::Type aClientType, 55 const nsAString& aPath, int64_t aSize) 56 : QuotaObject(/* aIsRemote */ false), 57 mOriginInfo(aOriginInfo), 58 mPath(aPath), 59 mSize(aSize), 60 mClientType(aClientType), 61 mQuotaCheckDisabled(false), 62 mWritingDone(false) { 63 MOZ_COUNT_CTOR(CanonicalQuotaObject); 64 } 65 66 MOZ_COUNTED_DTOR(CanonicalQuotaObject) 67 68 already_AddRefed<QuotaObject> LockedAddRef() { 69 AssertCurrentThreadOwnsQuotaMutex(); 70 71 ++mRefCnt; 72 73 RefPtr<QuotaObject> result = dont_AddRef(this); 74 return result.forget(); 75 } 76 77 bool LockedMaybeUpdateSize(int64_t aSize, bool aTruncate); 78 79 mozilla::ThreadSafeAutoRefCnt mRefCnt; 80 81 OriginInfo* mOriginInfo; 82 nsString mPath; 83 int64_t mSize; 84 Client::Type mClientType; 85 bool mQuotaCheckDisabled; 86 bool mWritingDone; 87 }; 88 89 } // namespace mozilla::dom::quota 90 91 #endif // DOM_QUOTA_CANONICALQUOTAOBJECT_H_