gecko-dev/dom/quota/ClientDirectoryLock.cpp
Jan Varga 09ab26ccac Bug 1957334 - QM: Add support for special purpose scope (metadata) to ClientStorageScope; r=dom-storage-reviewers,jstutte
`ClientStorageScope` now supports a special purpose scope type for targeting
the metadata file stored alongside client directories.

This allows operations like saving the origin access time to acquire a lock
specifically for the metadata file, instead of locking the entire origin
directory.

The actual changes to locking behavior for access time updates will be made in
a follow-up patch. This patch focuses on enabling support for special purpose
scopes within `ClientStorageScope`.

Differential Revision: https://phabricator.services.mozilla.com/D243632
2025-04-10 10:32:58 +00:00

59 lines
2.4 KiB
C++

/* -*- 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 "ClientDirectoryLock.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/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<ClientDirectoryLock> ClientDirectoryLock::Create(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
PersistenceType aPersistenceType,
const quota::OriginMetadata& aOriginMetadata, Client::Type aClientType,
bool aExclusive) {
return MakeRefPtr<ClientDirectoryLock>(
std::move(aQuotaManager),
PersistenceScope::CreateFromValue(aPersistenceType),
OriginScope::FromOrigin(aOriginMetadata),
ClientStorageScope::CreateFromClient(aClientType), aExclusive, false,
ShouldUpdateLockIdTableFlag::Yes, DirectoryLockCategory::None);
}
// static
RefPtr<ClientDirectoryLock> ClientDirectoryLock::Create(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const PersistenceScope& aPersistenceScope, const OriginScope& aOriginScope,
const ClientStorageScope& aClientStorageScope, bool aExclusive,
bool aInternal, ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag,
DirectoryLockCategory aCategory) {
MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty());
MOZ_ASSERT_IF(!aInternal, aPersistenceScope.IsValue());
MOZ_ASSERT_IF(!aInternal,
aPersistenceScope.GetValue() != PERSISTENCE_TYPE_INVALID);
MOZ_ASSERT_IF(!aInternal, aOriginScope.IsOrigin());
MOZ_ASSERT_IF(!aInternal, aClientStorageScope.IsClient());
MOZ_ASSERT_IF(!aInternal,
aClientStorageScope.GetClientType() < Client::TypeMax());
return MakeRefPtr<ClientDirectoryLock>(
std::move(aQuotaManager), aPersistenceScope, aOriginScope,
aClientStorageScope, aExclusive, aInternal, aShouldUpdateLockIdTableFlag,
aCategory);
}
} // namespace mozilla::dom::quota