QuotaManagerImpl.h (1837B)
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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_QUOTA_QUOTAMANAGERIMPL_H_ 8 #define DOM_QUOTA_QUOTAMANAGERIMPL_H_ 9 10 #include "GroupInfo.h" 11 #include "GroupInfoPair.h" 12 #include "OriginInfo.h" 13 #include "mozilla/dom/quota/QuotaManager.h" 14 15 namespace mozilla::dom::quota { 16 17 template <typename F> 18 auto QuotaManager::WithOriginInfo(const OriginMetadata& aOriginMetadata, 19 F aFunction) 20 -> std::invoke_result_t<F, const RefPtr<OriginInfo>&> { 21 MutexAutoLock lock(mQuotaMutex); 22 23 RefPtr<OriginInfo> originInfo = 24 LockedGetOriginInfo(aOriginMetadata.mPersistenceType, aOriginMetadata); 25 MOZ_ASSERT(originInfo); 26 27 return aFunction(originInfo); 28 } 29 30 template <typename P> 31 void QuotaManager::CollectPendingOriginsForListing(P aPredicate) { 32 MutexAutoLock lock(mQuotaMutex); 33 34 for (const auto& entry : mGroupInfoPairs) { 35 const auto& pair = entry.GetData(); 36 37 MOZ_ASSERT(!entry.GetKey().IsEmpty()); 38 MOZ_ASSERT(pair); 39 40 RefPtr<GroupInfo> groupInfo = 41 pair->LockedGetGroupInfo(PERSISTENCE_TYPE_DEFAULT); 42 if (groupInfo) { 43 for (const auto& originInfo : groupInfo->mOriginInfos) { 44 if (!originInfo->LockedDirectoryExists()) { 45 aPredicate(originInfo); 46 } 47 } 48 } 49 } 50 } 51 52 template <typename F> 53 void QuotaManager::MaybeRecordQuotaManagerShutdownStepWith(F&& aFunc) { 54 // Callable on any thread. 55 56 if (IsShuttingDown()) { 57 RecordShutdownStep(Nothing{}, std::forward<F>(aFunc)()); 58 } 59 } 60 61 } // namespace mozilla::dom::quota 62 63 #endif // DOM_QUOTA_QUOTAMANAGERIMPL_H_