diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index de102112006b..7dc577801563 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -7206,6 +7206,18 @@ auto QuotaManager::ExecuteInitialization(const Initialization aInitialization, aContext, std::forward(aFunc)); } +template +auto QuotaManager::ExecuteGroupInitialization( + const nsACString& aGroup, const GroupInitialization aInitialization, + const nsACString& aContext, Func&& aFunc) + -> std::invoke_result_t&> { + return quota::ExecuteInitialization( + mInitializationInfo.MutableGroupInitializationInfoRef( + aGroup, CreateIfNonExistent{}), + aInitialization, aContext, std::forward(aFunc)); +} + template auto QuotaManager::ExecuteOriginInitialization( const nsACString& aOrigin, const OriginInitialization aInitialization, diff --git a/dom/quota/InitializationTypes.cpp b/dom/quota/InitializationTypes.cpp index 05a8aa7e3379..69cb96edc1a6 100644 --- a/dom/quota/InitializationTypes.cpp +++ b/dom/quota/InitializationTypes.cpp @@ -42,6 +42,20 @@ nsLiteralCString StringGenerator::GetString( } } +// static +nsLiteralCString StringGenerator::GetString( + const GroupInitialization aGroupInitialization) { + switch (aGroupInitialization) { + case GroupInitialization::PersistentGroup: + return "PersistentGroup"_ns; + case GroupInitialization::TemporaryGroup: + return "TemporaryGroup"_ns; + + default: + MOZ_CRASH("Bad group initialization value!"); + } +} + // static nsLiteralCString StringGenerator::GetString( const OriginInitialization aOriginInitialization) { diff --git a/dom/quota/InitializationTypes.h b/dom/quota/InitializationTypes.h index 8577653dfa60..57e5188035c7 100644 --- a/dom/quota/InitializationTypes.h +++ b/dom/quota/InitializationTypes.h @@ -35,6 +35,12 @@ enum class Initialization { PersistentRepository = 1 << 11, }; +enum class GroupInitialization { + None = 0, + PersistentGroup = 1 << 0, + TemporaryGroup = 1 << 1, +}; + enum class OriginInitialization { None = 0, PersistentOrigin = 1 << 0, @@ -42,6 +48,7 @@ enum class OriginInitialization { }; MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Initialization) +MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(GroupInitialization) MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(OriginInitialization) class StringGenerator final { @@ -49,6 +56,9 @@ class StringGenerator final { // TODO: Use constexpr here once bug 1594094 is addressed. static nsLiteralCString GetString(Initialization aInitialization); + // TODO: Use constexpr here once bug 1594094 is addressed. + static nsLiteralCString GetString(GroupInitialization aGroupInitialization); + // TODO: Use constexpr here once bug 1594094 is addressed. static nsLiteralCString GetString(OriginInitialization aOriginInitialization); }; @@ -56,12 +66,29 @@ class StringGenerator final { using OriginInitializationInfo = FirstInitializationAttempts; +using GroupInitializationInfo = + FirstInitializationAttempts; + class InitializationInfo : public FirstInitializationAttempts { + nsTHashMap + mGroupInitializationInfos; nsTHashMap mOriginInitializationInfos; public: + GroupInitializationInfo& MutableGroupInitializationInfoRef( + const nsACString& aGroup) { + return *mGroupInitializationInfos.Lookup(aGroup); + } + + GroupInitializationInfo& MutableGroupInitializationInfoRef( + const nsACString& aGroup, const CreateIfNonExistent&) { + return mGroupInitializationInfos.LookupOrInsert(aGroup); + } + + void ResetGroupInitializationInfos() { mGroupInitializationInfos.Clear(); } + OriginInitializationInfo& MutableOriginInitializationInfoRef( const nsACString& aOrigin) { return *mOriginInitializationInfos.Lookup(aOrigin); diff --git a/dom/quota/QuotaManager.h b/dom/quota/QuotaManager.h index b73bcc95844e..a94471fc9370 100644 --- a/dom/quota/QuotaManager.h +++ b/dom/quota/QuotaManager.h @@ -792,6 +792,13 @@ class QuotaManager final : public BackgroundThreadObject { -> std::invoke_result_t&>; + template + auto ExecuteGroupInitialization(const nsACString& aGroup, + const GroupInitialization aInitialization, + const nsACString& aContext, Func&& aFunc) + -> std::invoke_result_t&>; + template auto ExecuteOriginInitialization(const nsACString& aOrigin, const OriginInitialization aInitialization,