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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_quota_UsageRequest_h
8 #define mozilla_dom_quota_UsageRequest_h
11 #include "ErrorList.h"
12 #include "mozilla/Assertions.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsIPrincipal.h"
16 #include "nsIQuotaRequests.h"
17 #include "nsISupports.h"
19 class nsIQuotaCallback
;
20 class nsIQuotaUsageCallback
;
23 namespace mozilla::dom::quota
{
25 class QuotaUsageRequestChild
;
27 class RequestBase
: public nsIQuotaRequestBase
{
29 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
32 bool mHaveResultOrErrorCode
;
35 void AssertIsOnOwningThread() const
43 void SetError(nsresult aRv
);
45 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
46 NS_DECL_NSIQUOTAREQUESTBASE
47 NS_DECL_CYCLE_COLLECTION_CLASS(RequestBase
)
52 RequestBase(nsIPrincipal
* aPrincipal
);
54 virtual ~RequestBase() { AssertIsOnOwningThread(); }
56 virtual void FireCallback() = 0;
59 class UsageRequest final
: public RequestBase
, public nsIQuotaUsageRequest
{
60 nsCOMPtr
<nsIQuotaUsageCallback
> mCallback
;
62 nsCOMPtr
<nsIVariant
> mResult
;
64 QuotaUsageRequestChild
* mBackgroundActor
;
69 explicit UsageRequest(nsIQuotaUsageCallback
* aCallback
);
71 UsageRequest(nsIPrincipal
* aPrincipal
, nsIQuotaUsageCallback
* aCallback
);
73 void SetBackgroundActor(QuotaUsageRequestChild
* aBackgroundActor
);
75 void ClearBackgroundActor() {
76 AssertIsOnOwningThread();
78 mBackgroundActor
= nullptr;
81 void SetResult(nsIVariant
* aResult
);
83 NS_DECL_ISUPPORTS_INHERITED
84 NS_FORWARD_NSIQUOTAREQUESTBASE(RequestBase::)
85 NS_DECL_NSIQUOTAUSAGEREQUEST
86 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UsageRequest
, RequestBase
)
91 virtual void FireCallback() override
;
94 class Request final
: public RequestBase
, public nsIQuotaRequest
{
95 nsCOMPtr
<nsIQuotaCallback
> mCallback
;
97 nsCOMPtr
<nsIVariant
> mResult
;
102 explicit Request(nsIPrincipal
* aPrincipal
);
104 explicit Request(nsIQuotaCallback
* aCallback
);
106 void SetResult(nsIVariant
* aResult
);
108 NS_DECL_ISUPPORTS_INHERITED
109 NS_FORWARD_NSIQUOTAREQUESTBASE(RequestBase::)
110 NS_DECL_NSIQUOTAREQUEST
111 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Request
, RequestBase
)
116 virtual void FireCallback() override
;
119 } // namespace mozilla::dom::quota
121 #endif // mozilla_dom_quota_UsageRequest_h