DirectoryLockInlines.h (1744B)
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/. */ 6 7 #ifndef DOM_QUOTA_DIRECTORYLOCKINLINES_H_ 8 #define DOM_QUOTA_DIRECTORYLOCKINLINES_H_ 9 10 #ifndef DOM_QUOTA_DIRECTORYLOCK_H_ 11 # error Must include DirectoryLock.h first 12 #endif 13 14 #include "mozilla/RefPtr.h" 15 #include "mozilla/dom/quota/DirectoryLockImpl.h" 16 17 namespace mozilla::dom::quota { 18 19 template <typename T> 20 constexpr void SafeDropDirectoryLock(RefPtr<T>& aDirectoryLock) { 21 if (!aDirectoryLock) { 22 return; 23 } 24 25 aDirectoryLock->Drop(); 26 aDirectoryLock = nullptr; 27 } 28 29 template <typename T> 30 constexpr void DropDirectoryLock(RefPtr<T>& aDirectoryLock) { 31 MOZ_ASSERT(aDirectoryLock); 32 33 aDirectoryLock->Drop(); 34 aDirectoryLock = nullptr; 35 } 36 37 template <typename T> 38 constexpr void SafeDropDirectoryLockIfNotDropped(RefPtr<T>& aDirectoryLock) { 39 if (!aDirectoryLock) { 40 return; 41 } 42 43 if (!aDirectoryLock->Dropped()) { 44 aDirectoryLock->Drop(); 45 } 46 aDirectoryLock = nullptr; 47 } 48 49 template <typename T> 50 constexpr void DropDirectoryLockIfNotDropped(RefPtr<T>& aDirectoryLock) { 51 MOZ_ASSERT(aDirectoryLock); 52 53 if (!aDirectoryLock->Dropped()) { 54 aDirectoryLock->Drop(); 55 } 56 aDirectoryLock = nullptr; 57 } 58 59 inline auto MakeBlockedByChecker( 60 const EnumSet<DirectoryLockCategory>& aCategories) { 61 return [aCategories](const DirectoryLockImpl::PrepareInfo& aPrepareInfo) { 62 return aPrepareInfo.IsBlockedBy(aCategories); 63 }; 64 } 65 66 } // namespace mozilla::dom::quota 67 68 #endif // DOM_QUOTA_DIRECTORYLOCKINLINES_H_