Bug 1904562 - Move OriginDirectoryLock to separate files and make it inherit from DirectoryLockImpl; r=dom-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D214848
This commit is contained in:
Jan Varga
2024-10-21 09:31:22 +00:00
parent bb854e20b6
commit 1437944aee
8 changed files with 112 additions and 28 deletions

View File

@@ -98,6 +98,7 @@
#include "mozilla/dom/quota/DirectoryLockInlines.h"
#include "mozilla/dom/quota/FileUtils.h"
#include "mozilla/dom/quota/MozPromiseUtils.h"
#include "mozilla/dom/quota/OriginDirectoryLock.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/PrincipalUtils.h"
#include "mozilla/dom/quota/QuotaManagerImpl.h"
@@ -2048,7 +2049,7 @@ uint64_t QuotaManager::CollectOriginsForEviction(
// operations for them will be delayed (until origin eviction is finalized).
for (const auto& originInfo : inactiveOrigins) {
auto lock = DirectoryLockImpl::CreateForEviction(
auto lock = OriginDirectoryLock::CreateForEviction(
WrapNotNullUnchecked(this), originInfo->mGroupInfo->mPersistenceType,
originInfo->FlattenToOriginMetadata());

View File

@@ -10,7 +10,7 @@
#include "GroupInfoPair.h"
#include "mozilla/dom/StorageActivityService.h"
#include "mozilla/dom/quota/AssertionsImpl.h"
#include "mozilla/dom/quota/DirectoryLock.h"
#include "mozilla/dom/quota/OriginDirectoryLock.h"
#include "mozilla/dom/quota/NotifyUtils.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "mozilla/ipc/BackgroundParent.h"

View File

@@ -77,8 +77,9 @@ class NS_NO_VTABLE DirectoryLock {
virtual void Log() const = 0;
};
// A directory lock specialized for a given origin directory.
class NS_NO_VTABLE OriginDirectoryLock : public DirectoryLock {
// A directory lock specialized for a given client directory (inside an origin
// directory).
class NS_NO_VTABLE ClientDirectoryLock : public DirectoryLock {
public:
// 'Get' prefix is to avoid name collisions with the enum
virtual PersistenceType GetPersistenceType() const = 0;
@@ -86,12 +87,7 @@ class NS_NO_VTABLE OriginDirectoryLock : public DirectoryLock {
virtual quota::OriginMetadata OriginMetadata() const = 0;
virtual const nsACString& Origin() const = 0;
};
// A directory lock specialized for a given client directory (inside an origin
// directory).
class NS_NO_VTABLE ClientDirectoryLock : public OriginDirectoryLock {
public:
virtual Client::Type ClientType() const = 0;
};

View File

@@ -39,6 +39,7 @@ class QuotaManager;
enum class ShouldUpdateLockIdTableFlag { No, Yes };
class DirectoryLockImpl : public ClientDirectoryLock {
friend class OriginDirectoryLock;
friend class QuotaManager;
friend class UniversalDirectoryLock;
@@ -129,7 +130,7 @@ class DirectoryLockImpl : public ClientDirectoryLock {
void Log() const override;
// OriginDirectoryLock interface
// ClientDirectoryLock interface
PersistenceType GetPersistenceType() const override {
MOZ_DIAGNOSTIC_ASSERT(mPersistenceScope.IsValue());
@@ -151,8 +152,6 @@ class DirectoryLockImpl : public ClientDirectoryLock {
return mOriginScope.GetOrigin();
}
// ClientDirectoryLock interface
Client::Type ClientType() const override {
MOZ_DIAGNOSTIC_ASSERT(!mClientType.IsNull());
MOZ_DIAGNOSTIC_ASSERT(mClientType.Value() < Client::TypeMax());
@@ -176,22 +175,6 @@ class DirectoryLockImpl : public ClientDirectoryLock {
DirectoryLockCategory::None);
}
static RefPtr<OriginDirectoryLock> CreateForEviction(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
PersistenceType aPersistenceType,
const quota::OriginMetadata& aOriginMetadata) {
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_INVALID);
MOZ_ASSERT(!aOriginMetadata.mOrigin.IsEmpty());
MOZ_ASSERT(!aOriginMetadata.mStorageOrigin.IsEmpty());
return Create(
std::move(aQuotaManager),
PersistenceScope::CreateFromValue(aPersistenceType),
OriginScope::FromOrigin(aOriginMetadata), Nullable<Client::Type>(),
/* aExclusive */ true, /* aInternal */ true,
ShouldUpdateLockIdTableFlag::No, DirectoryLockCategory::UninitOrigins);
}
static RefPtr<DirectoryLockImpl> Create(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const PersistenceScope& aPersistenceScope,

View File

@@ -0,0 +1,41 @@
/* -*- 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/. */
#include "OriginDirectoryLock.h"
#include <utility>
#include "nsString.h"
#include "mozilla/Assertions.h"
#include "mozilla/NotNull.h"
#include "mozilla/RefPtr.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/quota/CommonMetadata.h"
#include "mozilla/dom/quota/DirectoryLockCategory.h"
#include "mozilla/dom/quota/OriginScope.h"
#include "mozilla/dom/quota/PersistenceScope.h"
#include "mozilla/dom/quota/QuotaManager.h"
namespace mozilla::dom::quota {
// static
RefPtr<OriginDirectoryLock> OriginDirectoryLock::CreateForEviction(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
PersistenceType aPersistenceType,
const quota::OriginMetadata& aOriginMetadata) {
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_INVALID);
MOZ_ASSERT(!aOriginMetadata.mOrigin.IsEmpty());
MOZ_ASSERT(!aOriginMetadata.mStorageOrigin.IsEmpty());
return MakeRefPtr<OriginDirectoryLock>(
std::move(aQuotaManager),
PersistenceScope::CreateFromValue(aPersistenceType),
OriginScope::FromOrigin(aOriginMetadata), Nullable<Client::Type>(),
/* aExclusive */ true, /* aInternal */ true,
ShouldUpdateLockIdTableFlag::No, DirectoryLockCategory::UninitOrigins);
}
} // namespace mozilla::dom::quota

View File

@@ -0,0 +1,60 @@
/* -*- 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_ORIGINDIRECTORYLOCK_H_
#define DOM_QUOTA_ORIGINDIRECTORYLOCK_H_
#include "nsStringFwd.h"
#include "mozilla/dom/quota/DirectoryLockImpl.h"
#include "mozilla/dom/quota/PersistenceType.h"
template <class T>
class RefPtr;
namespace mozilla {
template <typename T>
class MovingNotNull;
} // namespace mozilla
namespace mozilla::dom::quota {
struct OriginMetadata;
class QuotaManager;
// A directory lock specialized for a given origin directory.
class OriginDirectoryLock final : public DirectoryLockImpl {
friend class QuotaManager;
public:
using DirectoryLockImpl::DirectoryLockImpl;
// XXX These getters shouldn't exist in the base class, but since some
// consumers don't use proper casting to OriginDirectoryLock yet, we keep
// them in the base class and have explicit forwarding here.
// 'Get' prefix is to avoid name collisions with the enum
PersistenceType GetPersistenceType() const {
return DirectoryLockImpl::GetPersistenceType();
}
quota::OriginMetadata OriginMetadata() const {
return DirectoryLockImpl::OriginMetadata();
}
const nsACString& Origin() const { return DirectoryLockImpl::Origin(); }
private:
static RefPtr<OriginDirectoryLock> CreateForEviction(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
PersistenceType aPersistenceType,
const quota::OriginMetadata& aOriginMetadata);
};
} // namespace mozilla::dom::quota
#endif // DOM_QUOTA_ORIGINDIRECTORYLOCK_H_

View File

@@ -28,6 +28,7 @@
#include "mozilla/dom/quota/Constants.h"
#include "mozilla/dom/quota/DirectoryLock.h"
#include "mozilla/dom/quota/DirectoryLockInlines.h"
#include "mozilla/dom/quota/OriginDirectoryLock.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/PrincipalUtils.h"
#include "mozilla/dom/quota/PQuota.h"

View File

@@ -67,6 +67,7 @@ EXPORTS.mozilla.dom.quota += [
"NotifyUtils.h",
"NotifyUtilsCommon.h",
"NSSCipherStrategy.h",
"OriginDirectoryLock.h",
"OriginOperationCallbacks.h",
"OriginScope.h",
"PersistenceScope.h",
@@ -122,6 +123,7 @@ UNIFIED_SOURCES += [
"NotifyUtilsCommon.cpp",
"nsIndexedDBProtocolHandler.cpp",
"NSSCipherStrategy.cpp",
"OriginDirectoryLock.cpp",
"OriginInfo.cpp",
"OriginOperationBase.cpp",
"OriginOperations.cpp",