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_FIRSTINITIALIZATIONATTEMPTS_H_
8 #define DOM_QUOTA_FIRSTINITIALIZATIONATTEMPTS_H_
12 #include "ErrorList.h"
14 namespace mozilla::dom::quota
{
16 template <typename Initialization
, typename StringGenerator
>
17 class FirstInitializationAttempts
{
18 Initialization mFirstInitializationAttempts
= Initialization::None
;
21 class FirstInitializationAttemptImpl
{
22 using FirstInitializationAttemptsType
=
23 FirstInitializationAttempts
<Initialization
, StringGenerator
>;
25 FirstInitializationAttemptsType
& mOwner
;
26 const Initialization mInitialization
;
29 FirstInitializationAttemptImpl(FirstInitializationAttemptsType
& aOwner
,
30 const Initialization aInitialization
)
31 : mOwner(aOwner
), mInitialization(aInitialization
) {}
33 bool Recorded() const {
34 return mOwner
.FirstInitializationAttemptRecorded(mInitialization
);
37 void Record(const nsresult aRv
) const {
38 mOwner
.RecordFirstInitializationAttempt(mInitialization
, aRv
);
42 template <typename Func
>
43 auto WithFirstInitializationAttempt(const Initialization aInitialization
,
45 -> std::invoke_result_t
<Func
, FirstInitializationAttemptImpl
&&> {
46 return std::forward
<Func
>(aFunc
)(
47 FirstInitializationAttemptImpl(*this, aInitialization
));
50 bool FirstInitializationAttemptRecorded(
51 const Initialization aInitialization
) const {
52 return static_cast<bool>(mFirstInitializationAttempts
& aInitialization
);
55 void RecordFirstInitializationAttempt(const Initialization aInitialization
,
58 void ResetFirstInitializationAttempts() {
59 mFirstInitializationAttempts
= Initialization::None
;
63 template <typename Initialization
, typename StringGenerator
>
64 using FirstInitializationAttempt
= typename FirstInitializationAttempts
<
65 Initialization
, StringGenerator
>::FirstInitializationAttemptImpl
;
67 } // namespace mozilla::dom::quota
69 #endif // DOM_QUOTA_FIRSTINITIALIZATIONATTEMPTS_H_