Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / quota / CanonicalQuotaObject.h
blobc47862f8876d383b49c79cdc080dbae1808e0cd2
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_
10 // Local includes
11 #include "Client.h"
13 // Global includes
14 #include <cstdint>
15 #include "mozilla/AlreadyAddRefed.h"
16 #include "mozilla/RefPtr.h"
17 #include "mozilla/dom/quota/Assertions.h"
18 #include "mozilla/dom/quota/QuotaObject.h"
19 #include "nsCOMPtr.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 {
28 class OriginInfo;
29 class QuotaManager;
31 class CanonicalQuotaObject final : public QuotaObject {
32 friend class OriginInfo;
33 friend class QuotaManager;
35 class StoragePressureRunnable;
37 public:
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;
52 private:
53 CanonicalQuotaObject(OriginInfo* aOriginInfo, Client::Type aClientType,
54 const nsAString& aPath, int64_t aSize)
55 : QuotaObject(/* aIsRemote */ false),
56 mOriginInfo(aOriginInfo),
57 mPath(aPath),
58 mSize(aSize),
59 mClientType(aClientType),
60 mQuotaCheckDisabled(false),
61 mWritingDone(false) {
62 MOZ_COUNT_CTOR(CanonicalQuotaObject);
65 MOZ_COUNTED_DTOR(CanonicalQuotaObject)
67 already_AddRefed<QuotaObject> LockedAddRef() {
68 AssertCurrentThreadOwnsQuotaMutex();
70 ++mRefCnt;
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;
81 nsString mPath;
82 int64_t mSize;
83 Client::Type mClientType;
84 bool mQuotaCheckDisabled;
85 bool mWritingDone;
88 } // namespace mozilla::dom::quota
90 #endif // DOM_QUOTA_CANONICALQUOTAOBJECT_H_