Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / quota / ResolvableNormalOriginOp.h
blob73440c8288dc057df9aa47935ef9ac287b4c9002
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 T>
17 class ResolvableNormalOriginOp : public NormalOriginOperationBase {
18 public:
19 using PromiseType = MozPromise<T, nsresult, false>;
21 RefPtr<PromiseType> OnResults() {
22 AssertIsOnOwningThread();
24 return mPromiseHolder.Ensure(__func__);
27 protected:
28 ResolvableNormalOriginOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
29 const char* aName)
30 : NormalOriginOperationBase(std::move(aQuotaManager), aName) {
31 AssertIsOnOwningThread();
34 virtual ~ResolvableNormalOriginOp() = default;
36 virtual T GetResolveValue() = 0;
38 private:
39 void SendResults() override {
40 #ifdef DEBUG
41 NoteActorDestroyed();
42 #endif
44 if (NS_SUCCEEDED(mResultCode)) {
45 mPromiseHolder.ResolveIfExists(GetResolveValue(), __func__);
46 } else {
47 mPromiseHolder.RejectIfExists(mResultCode, __func__);
51 MozPromiseHolder<PromiseType> mPromiseHolder;
54 } // namespace mozilla::dom::quota
56 #endif // DOM_QUOTA_RESOLVABLENORMALORIGINOP_H_