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_RESOLVABLENORMALORIGINOP_H_
8 #define DOM_QUOTA_RESOLVABLENORMALORIGINOP_H_
10 #include "NormalOriginOperationBase.h"
12 #include "mozilla/MozPromise.h"
14 namespace mozilla::dom::quota
{
16 template <typename ResolveValueT
, bool IsExclusive
>
17 class ResolvableNormalOriginOp
: public NormalOriginOperationBase
{
19 NS_INLINE_DECL_REFCOUNTING(ResolvableNormalOriginOp
, override
)
21 using PromiseType
= MozPromise
<ResolveValueT
, nsresult
, IsExclusive
>;
23 RefPtr
<PromiseType
> OnResults() {
24 AssertIsOnOwningThread();
26 return mPromiseHolder
.Ensure(__func__
);
30 ResolvableNormalOriginOp(MovingNotNull
<RefPtr
<QuotaManager
>> aQuotaManager
,
32 : NormalOriginOperationBase(std::move(aQuotaManager
), aName
) {
33 AssertIsOnOwningThread();
36 virtual ~ResolvableNormalOriginOp() = default;
38 virtual ResolveValueT
GetResolveValue() = 0;
41 void SendResults() override
{
43 mResultCode
= NS_ERROR_FAILURE
;
46 if (NS_SUCCEEDED(mResultCode
)) {
47 mPromiseHolder
.ResolveIfExists(GetResolveValue(), __func__
);
49 mPromiseHolder
.RejectIfExists(mResultCode
, __func__
);
53 MozPromiseHolder
<PromiseType
> mPromiseHolder
;
56 } // namespace mozilla::dom::quota
58 #endif // DOM_QUOTA_RESOLVABLENORMALORIGINOP_H_