forked from mirrors/gecko-dev
Bug 1808294 - Add support for directory lock categories; r=dom-storage-reviewers,aiunusov,jari
Differential Revision: https://phabricator.services.mozilla.com/D193105
This commit is contained in:
parent
10b1563488
commit
ca6c95e529
8 changed files with 63 additions and 27 deletions
|
|
@ -12922,7 +12922,7 @@ nsresult Maintenance::OpenDirectory() {
|
|||
->OpenStorageDirectory(
|
||||
Nullable<PersistenceType>(), OriginScope::FromNull(),
|
||||
Nullable<Client::Type>(Client::IDB), /* aExclusive */ false,
|
||||
SomeRef(mPendingDirectoryLock))
|
||||
DirectoryLockCategory::None, SomeRef(mPendingDirectoryLock))
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
[self = RefPtr(this)](
|
||||
const UniversalDirectoryLockPromise::ResolveOrRejectValue&
|
||||
|
|
|
|||
|
|
@ -5058,7 +5058,7 @@ RefPtr<BoolPromise> QuotaManager::TemporaryStorageInitialized() {
|
|||
RefPtr<UniversalDirectoryLockPromise> QuotaManager::OpenStorageDirectory(
|
||||
const Nullable<PersistenceType>& aPersistenceType,
|
||||
const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
|
||||
bool aExclusive,
|
||||
bool aExclusive, DirectoryLockCategory aCategory,
|
||||
Maybe<RefPtr<UniversalDirectoryLock>&> aPendingDirectoryLockOut) {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
|
|
@ -5079,7 +5079,7 @@ RefPtr<UniversalDirectoryLockPromise> QuotaManager::OpenStorageDirectory(
|
|||
|
||||
RefPtr<UniversalDirectoryLock> universalDirectoryLock =
|
||||
CreateDirectoryLockInternal(aPersistenceType, aOriginScope, aClientType,
|
||||
aExclusive);
|
||||
aExclusive, aCategory);
|
||||
|
||||
RefPtr<BoolPromise> universalDirectoryLockPromise =
|
||||
universalDirectoryLock->Acquire();
|
||||
|
|
@ -5193,12 +5193,12 @@ RefPtr<ClientDirectoryLock> QuotaManager::CreateDirectoryLock(
|
|||
RefPtr<UniversalDirectoryLock> QuotaManager::CreateDirectoryLockInternal(
|
||||
const Nullable<PersistenceType>& aPersistenceType,
|
||||
const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
|
||||
bool aExclusive) {
|
||||
bool aExclusive, DirectoryLockCategory aCategory) {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
return DirectoryLockImpl::CreateInternal(WrapNotNullUnchecked(this),
|
||||
aPersistenceType, aOriginScope,
|
||||
aClientType, aExclusive);
|
||||
aClientType, aExclusive, aCategory);
|
||||
}
|
||||
|
||||
Result<std::pair<nsCOMPtr<nsIFile>, bool>, nsresult>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class RefPtr;
|
|||
namespace mozilla::dom::quota {
|
||||
|
||||
class ClientDirectoryLock;
|
||||
enum class DirectoryLockCategory : uint8_t;
|
||||
class OpenDirectoryListener;
|
||||
struct OriginMetadata;
|
||||
|
||||
|
|
@ -30,6 +31,8 @@ class NS_NO_VTABLE DirectoryLock {
|
|||
|
||||
virtual int64_t Id() const = 0;
|
||||
|
||||
virtual DirectoryLockCategory Category() const = 0;
|
||||
|
||||
virtual bool Acquired() const = 0;
|
||||
|
||||
virtual nsTArray<RefPtr<DirectoryLock>> LocksMustWaitFor() const = 0;
|
||||
|
|
|
|||
18
dom/quota/DirectoryLockCategory.h
Normal file
18
dom/quota/DirectoryLockCategory.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef DOM_QUOTA_DIRECTORYLOCKCATEGORY_H_
|
||||
#define DOM_QUOTA_DIRECTORYLOCKCATEGORY_H_
|
||||
|
||||
namespace mozilla::dom::quota {
|
||||
|
||||
enum class DirectoryLockCategory : uint8_t {
|
||||
None = 0,
|
||||
};
|
||||
|
||||
} // namespace mozilla::dom::quota
|
||||
|
||||
#endif // DOM_QUOTA_DIRECTORYLOCKCATEGORY_H_
|
||||
|
|
@ -19,7 +19,8 @@ DirectoryLockImpl::DirectoryLockImpl(
|
|||
const OriginScope& aOriginScope, const nsACString& aStorageOrigin,
|
||||
bool aIsPrivate, const Nullable<Client::Type>& aClientType,
|
||||
const bool aExclusive, const bool aInternal,
|
||||
const ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag)
|
||||
const ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag,
|
||||
const DirectoryLockCategory aCategory)
|
||||
: mQuotaManager(std::move(aQuotaManager)),
|
||||
mPersistenceType(aPersistenceType),
|
||||
mSuffix(aSuffix),
|
||||
|
|
@ -33,6 +34,7 @@ DirectoryLockImpl::DirectoryLockImpl(
|
|||
mInternal(aInternal),
|
||||
mShouldUpdateLockIdTable(aShouldUpdateLockIdTableFlag ==
|
||||
ShouldUpdateLockIdTableFlag::Yes),
|
||||
mCategory(aCategory),
|
||||
mRegistered(false) {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty());
|
||||
|
|
@ -328,13 +330,14 @@ RefPtr<ClientDirectoryLock> DirectoryLockImpl::SpecializeForClient(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DirectoryLockImpl> lock = Create(
|
||||
mQuotaManager, Nullable<PersistenceType>(aPersistenceType),
|
||||
aOriginMetadata.mSuffix, aOriginMetadata.mGroup,
|
||||
OriginScope::FromOrigin(aOriginMetadata.mOrigin),
|
||||
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
|
||||
Nullable<Client::Type>(aClientType),
|
||||
/* aExclusive */ false, mInternal, ShouldUpdateLockIdTableFlag::Yes);
|
||||
RefPtr<DirectoryLockImpl> lock =
|
||||
Create(mQuotaManager, Nullable<PersistenceType>(aPersistenceType),
|
||||
aOriginMetadata.mSuffix, aOriginMetadata.mGroup,
|
||||
OriginScope::FromOrigin(aOriginMetadata.mOrigin),
|
||||
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
|
||||
Nullable<Client::Type>(aClientType),
|
||||
/* aExclusive */ false, mInternal,
|
||||
ShouldUpdateLockIdTableFlag::Yes, mCategory);
|
||||
if (NS_WARN_IF(!Overlaps(*lock))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/dom/FlippedOnce.h"
|
||||
#include "mozilla/dom/quota/CommonMetadata.h"
|
||||
#include "mozilla/dom/quota/DirectoryLock.h"
|
||||
#include "mozilla/dom/quota/DirectoryLockCategory.h"
|
||||
#include "mozilla/dom/quota/OriginScope.h"
|
||||
|
||||
namespace mozilla::dom::quota {
|
||||
|
|
@ -49,6 +50,8 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
|||
|
||||
const bool mShouldUpdateLockIdTable;
|
||||
|
||||
const DirectoryLockCategory mCategory;
|
||||
|
||||
bool mRegistered;
|
||||
FlippedOnce<true> mPending;
|
||||
FlippedOnce<false> mInvalidated;
|
||||
|
|
@ -62,20 +65,21 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
|||
const nsACString& aStorageOrigin, bool aIsPrivate,
|
||||
const Nullable<Client::Type>& aClientType, bool aExclusive,
|
||||
bool aInternal,
|
||||
ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag);
|
||||
ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag,
|
||||
DirectoryLockCategory aCategory);
|
||||
|
||||
static RefPtr<ClientDirectoryLock> Create(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
PersistenceType aPersistenceType,
|
||||
const quota::OriginMetadata& aOriginMetadata, Client::Type aClientType,
|
||||
bool aExclusive) {
|
||||
return Create(std::move(aQuotaManager),
|
||||
Nullable<PersistenceType>(aPersistenceType),
|
||||
aOriginMetadata.mSuffix, aOriginMetadata.mGroup,
|
||||
OriginScope::FromOrigin(aOriginMetadata.mOrigin),
|
||||
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
|
||||
Nullable<Client::Type>(aClientType), aExclusive, false,
|
||||
ShouldUpdateLockIdTableFlag::Yes);
|
||||
return Create(
|
||||
std::move(aQuotaManager), Nullable<PersistenceType>(aPersistenceType),
|
||||
aOriginMetadata.mSuffix, aOriginMetadata.mGroup,
|
||||
OriginScope::FromOrigin(aOriginMetadata.mOrigin),
|
||||
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
|
||||
Nullable<Client::Type>(aClientType), aExclusive, false,
|
||||
ShouldUpdateLockIdTableFlag::Yes, DirectoryLockCategory::None);
|
||||
}
|
||||
|
||||
static RefPtr<OriginDirectoryLock> CreateForEviction(
|
||||
|
|
@ -93,17 +97,18 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
|||
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
|
||||
Nullable<Client::Type>(),
|
||||
/* aExclusive */ true, /* aInternal */ true,
|
||||
ShouldUpdateLockIdTableFlag::No);
|
||||
ShouldUpdateLockIdTableFlag::No, DirectoryLockCategory::None);
|
||||
}
|
||||
|
||||
static RefPtr<UniversalDirectoryLock> CreateInternal(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
const Nullable<PersistenceType>& aPersistenceType,
|
||||
const OriginScope& aOriginScope,
|
||||
const Nullable<Client::Type>& aClientType, bool aExclusive) {
|
||||
const Nullable<Client::Type>& aClientType, bool aExclusive,
|
||||
DirectoryLockCategory aCategory) {
|
||||
return Create(std::move(aQuotaManager), aPersistenceType, ""_ns, ""_ns,
|
||||
aOriginScope, ""_ns, false, aClientType, aExclusive, true,
|
||||
ShouldUpdateLockIdTableFlag::Yes);
|
||||
ShouldUpdateLockIdTableFlag::Yes, aCategory);
|
||||
}
|
||||
|
||||
void AssertIsOnOwningThread() const
|
||||
|
|
@ -178,6 +183,8 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
|||
|
||||
int64_t Id() const override { return mId; }
|
||||
|
||||
DirectoryLockCategory Category() const override { return mCategory; }
|
||||
|
||||
bool Acquired() const override { return mAcquired; }
|
||||
|
||||
nsTArray<RefPtr<DirectoryLock>> LocksMustWaitFor() const override;
|
||||
|
|
@ -259,7 +266,8 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
|||
const OriginScope& aOriginScope, const nsACString& aStorageOrigin,
|
||||
bool aIsPrivate, const Nullable<Client::Type>& aClientType,
|
||||
bool aExclusive, bool aInternal,
|
||||
ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag) {
|
||||
ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag,
|
||||
DirectoryLockCategory aCategory) {
|
||||
MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty());
|
||||
MOZ_ASSERT_IF(!aInternal, !aPersistenceType.IsNull());
|
||||
MOZ_ASSERT_IF(!aInternal,
|
||||
|
|
@ -273,7 +281,7 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
|||
return MakeRefPtr<DirectoryLockImpl>(
|
||||
std::move(aQuotaManager), aPersistenceType, aSuffix, aGroup,
|
||||
aOriginScope, aStorageOrigin, aIsPrivate, aClientType, aExclusive,
|
||||
aInternal, aShouldUpdateLockIdTableFlag);
|
||||
aInternal, aShouldUpdateLockIdTableFlag, aCategory);
|
||||
}
|
||||
|
||||
void AcquireInternal();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include "mozilla/dom/ipc/IdType.h"
|
||||
#include "mozilla/dom/quota/Assertions.h"
|
||||
#include "mozilla/dom/quota/CommonMetadata.h"
|
||||
#include "mozilla/dom/quota/DirectoryLockCategory.h"
|
||||
#include "mozilla/dom/quota/ForwardDecls.h"
|
||||
#include "mozilla/dom/quota/InitializationTypes.h"
|
||||
#include "mozilla/dom/quota/PersistenceType.h"
|
||||
|
|
@ -268,6 +269,7 @@ class QuotaManager final : public BackgroundThreadObject {
|
|||
const Nullable<PersistenceType>& aPersistenceType,
|
||||
const OriginScope& aOriginScope,
|
||||
const Nullable<Client::Type>& aClientType, bool aExclusive,
|
||||
DirectoryLockCategory aCategory = DirectoryLockCategory::None,
|
||||
Maybe<RefPtr<UniversalDirectoryLock>&> aPendingDirectoryLockOut =
|
||||
Nothing());
|
||||
|
||||
|
|
@ -297,7 +299,8 @@ class QuotaManager final : public BackgroundThreadObject {
|
|||
RefPtr<UniversalDirectoryLock> CreateDirectoryLockInternal(
|
||||
const Nullable<PersistenceType>& aPersistenceType,
|
||||
const OriginScope& aOriginScope,
|
||||
const Nullable<Client::Type>& aClientType, bool aExclusive);
|
||||
const Nullable<Client::Type>& aClientType, bool aExclusive,
|
||||
DirectoryLockCategory aCategory = DirectoryLockCategory::None);
|
||||
|
||||
// Collect inactive and the least recently used origins.
|
||||
uint64_t CollectOriginsForEviction(
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ EXPORTS.mozilla.dom.quota += [
|
|||
"DecryptingInputStream.h",
|
||||
"DecryptingInputStream_impl.h",
|
||||
"DirectoryLock.h",
|
||||
"DirectoryLockCategory.h",
|
||||
"DummyCipherStrategy.h",
|
||||
"EncryptedBlock.h",
|
||||
"EncryptingOutputStream.h",
|
||||
|
|
|
|||
Loading…
Reference in a new issue