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_ORIGINOPERATIONCALLBACKS_H_
8 #define DOM_QUOTA_ORIGINOPERATIONCALLBACKS_H_
10 #include "mozilla/Maybe.h"
11 #include "mozilla/MozPromise.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/dom/quota/ForwardDecls.h"
15 namespace mozilla::dom::quota
{
17 struct OriginOperationCallbackOptions
{
18 bool mWantWillFinish
= false;
19 bool mWantWillFinishSync
= false;
20 bool mWantDidFinish
= false;
21 bool mWantDidFinishSync
= false;
24 struct OriginOperationCallbacks
{
25 Maybe
<RefPtr
<BoolPromise
>> mWillFinishPromise
;
26 Maybe
<RefPtr
<ExclusiveBoolPromise
>> mWillFinishSyncPromise
;
27 Maybe
<RefPtr
<BoolPromise
>> mDidFinishPromise
;
28 Maybe
<RefPtr
<ExclusiveBoolPromise
>> mDidFinishSyncPromise
;
31 class OriginOperationCallbackHolders
{
33 MozPromiseHolder
<BoolPromise
> mWillFinishPromiseHolder
;
34 MozPromiseHolder
<ExclusiveBoolPromise
> mWillFinishSyncPromiseHolder
;
35 MozPromiseHolder
<BoolPromise
> mDidFinishPromiseHolder
;
36 MozPromiseHolder
<ExclusiveBoolPromise
> mDidFinishSyncPromiseHolder
;
39 OriginOperationCallbacks
GetCallbacks(
40 const OriginOperationCallbackOptions
& aCallbackOptions
) {
41 OriginOperationCallbacks callbacks
;
43 if (aCallbackOptions
.mWantWillFinish
) {
44 callbacks
.mWillFinishPromise
=
45 Some(mWillFinishPromiseHolder
.Ensure(__func__
));
48 if (aCallbackOptions
.mWantWillFinishSync
) {
49 callbacks
.mWillFinishSyncPromise
=
50 Some(mWillFinishSyncPromiseHolder
.Ensure(__func__
));
53 if (aCallbackOptions
.mWantDidFinish
) {
54 callbacks
.mDidFinishPromise
=
55 Some(mDidFinishPromiseHolder
.Ensure(__func__
));
58 if (aCallbackOptions
.mWantDidFinishSync
) {
59 callbacks
.mDidFinishSyncPromise
=
60 Some(mDidFinishSyncPromiseHolder
.Ensure(__func__
));
67 } // namespace mozilla::dom::quota
69 #endif // DOM_QUOTA_ORIGINOPERATIONCALLBACKS_H_