Backed out changeset f594e6f00208 (bug 1940883) for causing crashes in bug 1941164.
[gecko.git] / dom / quota / InitializationTypes.h
blob57e5188035c742dfeec13dc49ef73be9d696111b
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_INITIALIZATIONTYPES_H_
8 #define DOM_QUOTA_INITIALIZATIONTYPES_H_
10 #include "mozilla/TypedEnumBits.h"
11 #include "mozilla/dom/quota/FirstInitializationAttempts.h"
12 #include "nsLiteralString.h"
13 #include "nsStringFwd.h"
14 #include "nsTHashMap.h"
16 namespace mozilla {
17 struct CreateIfNonExistent;
20 namespace mozilla::dom::quota {
22 enum class Initialization {
23 None = 0,
24 Storage = 1 << 0,
25 TemporaryStorage = 1 << 1,
26 DefaultRepository = 1 << 2,
27 TemporaryRepository = 1 << 3,
28 UpgradeStorageFrom0_0To1_0 = 1 << 4,
29 UpgradeStorageFrom1_0To2_0 = 1 << 5,
30 UpgradeStorageFrom2_0To2_1 = 1 << 6,
31 UpgradeStorageFrom2_1To2_2 = 1 << 7,
32 UpgradeStorageFrom2_2To2_3 = 1 << 8,
33 UpgradeFromIndexedDBDirectory = 1 << 9,
34 UpgradeFromPersistentStorageDirectory = 1 << 10,
35 PersistentRepository = 1 << 11,
38 enum class GroupInitialization {
39 None = 0,
40 PersistentGroup = 1 << 0,
41 TemporaryGroup = 1 << 1,
44 enum class OriginInitialization {
45 None = 0,
46 PersistentOrigin = 1 << 0,
47 TemporaryOrigin = 1 << 1,
50 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Initialization)
51 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(GroupInitialization)
52 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OriginInitialization)
54 class StringGenerator final {
55 public:
56 // TODO: Use constexpr here once bug 1594094 is addressed.
57 static nsLiteralCString GetString(Initialization aInitialization);
59 // TODO: Use constexpr here once bug 1594094 is addressed.
60 static nsLiteralCString GetString(GroupInitialization aGroupInitialization);
62 // TODO: Use constexpr here once bug 1594094 is addressed.
63 static nsLiteralCString GetString(OriginInitialization aOriginInitialization);
66 using OriginInitializationInfo =
67 FirstInitializationAttempts<OriginInitialization, StringGenerator>;
69 using GroupInitializationInfo =
70 FirstInitializationAttempts<GroupInitialization, StringGenerator>;
72 class InitializationInfo
73 : public FirstInitializationAttempts<Initialization, StringGenerator> {
74 nsTHashMap<nsCStringHashKey, GroupInitializationInfo>
75 mGroupInitializationInfos;
76 nsTHashMap<nsCStringHashKey, OriginInitializationInfo>
77 mOriginInitializationInfos;
79 public:
80 GroupInitializationInfo& MutableGroupInitializationInfoRef(
81 const nsACString& aGroup) {
82 return *mGroupInitializationInfos.Lookup(aGroup);
85 GroupInitializationInfo& MutableGroupInitializationInfoRef(
86 const nsACString& aGroup, const CreateIfNonExistent&) {
87 return mGroupInitializationInfos.LookupOrInsert(aGroup);
90 void ResetGroupInitializationInfos() { mGroupInitializationInfos.Clear(); }
92 OriginInitializationInfo& MutableOriginInitializationInfoRef(
93 const nsACString& aOrigin) {
94 return *mOriginInitializationInfos.Lookup(aOrigin);
97 OriginInitializationInfo& MutableOriginInitializationInfoRef(
98 const nsACString& aOrigin, const CreateIfNonExistent&) {
99 return mOriginInitializationInfos.LookupOrInsert(aOrigin);
102 void ResetOriginInitializationInfos() { mOriginInitializationInfos.Clear(); }
105 } // namespace mozilla::dom::quota
107 #endif // DOM_QUOTA_INITIALIZATIONTYPES_H_