mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1866402 - Further reduce code duplication in QuotaManager::OpenStorageDirectory and QuotaManager::OpenClientDirectory; r=dom-storage-reviewers,jari
Differential Revision: https://phabricator.services.mozilla.com/D223710
This commit is contained in:
parent
61a43c79f8
commit
31af6ee2f0
@ -5163,35 +5163,22 @@ RefPtr<UniversalDirectoryLockPromise> QuotaManager::OpenStorageDirectory(
|
|||||||
nsTArray<RefPtr<BoolPromise>> promises;
|
nsTArray<RefPtr<BoolPromise>> promises;
|
||||||
|
|
||||||
RefPtr<UniversalDirectoryLock> storageDirectoryLock =
|
RefPtr<UniversalDirectoryLock> storageDirectoryLock =
|
||||||
CreateDirectoryLockInternal(PersistenceScope::CreateFromNull(),
|
CreateDirectoryLockForInitialization(
|
||||||
OriginScope::FromNull(),
|
*this, PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
|
||||||
Nullable<Client::Type>(),
|
mStorageInitialized, IsDirectoryLockBlockedByUninitStorageOperation,
|
||||||
/* aExclusive */ false);
|
MakeBackInserter(promises));
|
||||||
|
|
||||||
if (mStorageInitialized &&
|
|
||||||
!IsDirectoryLockBlockedByUninitStorageOperation(storageDirectoryLock)) {
|
|
||||||
storageDirectoryLock = nullptr;
|
|
||||||
} else {
|
|
||||||
promises.AppendElement(storageDirectoryLock->Acquire());
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<UniversalDirectoryLock> temporaryStorageDirectoryLock;
|
RefPtr<UniversalDirectoryLock> temporaryStorageDirectoryLock;
|
||||||
|
|
||||||
if (aInitializeOrigins &&
|
if (aInitializeOrigins &&
|
||||||
MatchesBestEffortPersistenceScope(aPersistenceScope)) {
|
MatchesBestEffortPersistenceScope(aPersistenceScope)) {
|
||||||
temporaryStorageDirectoryLock = CreateDirectoryLockInternal(
|
temporaryStorageDirectoryLock = CreateDirectoryLockForInitialization(
|
||||||
|
*this,
|
||||||
PersistenceScope::CreateFromSet(PERSISTENCE_TYPE_TEMPORARY,
|
PersistenceScope::CreateFromSet(PERSISTENCE_TYPE_TEMPORARY,
|
||||||
PERSISTENCE_TYPE_DEFAULT),
|
PERSISTENCE_TYPE_DEFAULT),
|
||||||
OriginScope::FromNull(), Nullable<Client::Type>(),
|
OriginScope::FromNull(), mTemporaryStorageInitialized,
|
||||||
/* aExclusive */ false);
|
IsDirectoryLockBlockedByUninitStorageOperation,
|
||||||
|
MakeBackInserter(promises));
|
||||||
if (mTemporaryStorageInitialized &&
|
|
||||||
!IsDirectoryLockBlockedByUninitStorageOperation(
|
|
||||||
temporaryStorageDirectoryLock)) {
|
|
||||||
temporaryStorageDirectoryLock = nullptr;
|
|
||||||
} else {
|
|
||||||
promises.AppendElement(temporaryStorageDirectoryLock->Acquire());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<UniversalDirectoryLock> universalDirectoryLock =
|
RefPtr<UniversalDirectoryLock> universalDirectoryLock =
|
||||||
@ -5262,54 +5249,34 @@ RefPtr<ClientDirectoryLockPromise> QuotaManager::OpenClientDirectory(
|
|||||||
nsTArray<RefPtr<BoolPromise>> promises;
|
nsTArray<RefPtr<BoolPromise>> promises;
|
||||||
|
|
||||||
RefPtr<UniversalDirectoryLock> storageDirectoryLock =
|
RefPtr<UniversalDirectoryLock> storageDirectoryLock =
|
||||||
CreateDirectoryLockInternal(PersistenceScope::CreateFromNull(),
|
CreateDirectoryLockForInitialization(
|
||||||
OriginScope::FromNull(),
|
*this, PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
|
||||||
Nullable<Client::Type>(),
|
mStorageInitialized, IsDirectoryLockBlockedByUninitStorageOperation,
|
||||||
/* aExclusive */ false);
|
MakeBackInserter(promises));
|
||||||
|
|
||||||
if (mStorageInitialized &&
|
|
||||||
!IsDirectoryLockBlockedByUninitStorageOperation(storageDirectoryLock)) {
|
|
||||||
storageDirectoryLock = nullptr;
|
|
||||||
} else {
|
|
||||||
promises.AppendElement(storageDirectoryLock->Acquire());
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<UniversalDirectoryLock> temporaryStorageDirectoryLock;
|
RefPtr<UniversalDirectoryLock> temporaryStorageDirectoryLock;
|
||||||
|
|
||||||
if (IsBestEffortPersistenceType(persistenceType)) {
|
if (IsBestEffortPersistenceType(persistenceType)) {
|
||||||
temporaryStorageDirectoryLock = CreateDirectoryLockInternal(
|
temporaryStorageDirectoryLock = CreateDirectoryLockForInitialization(
|
||||||
|
*this,
|
||||||
PersistenceScope::CreateFromSet(PERSISTENCE_TYPE_TEMPORARY,
|
PersistenceScope::CreateFromSet(PERSISTENCE_TYPE_TEMPORARY,
|
||||||
PERSISTENCE_TYPE_DEFAULT),
|
PERSISTENCE_TYPE_DEFAULT),
|
||||||
OriginScope::FromNull(), Nullable<Client::Type>(),
|
OriginScope::FromNull(), mTemporaryStorageInitialized,
|
||||||
/* aExclusive */ false);
|
IsDirectoryLockBlockedByUninitStorageOperation,
|
||||||
|
MakeBackInserter(promises));
|
||||||
if (mTemporaryStorageInitialized &&
|
|
||||||
!IsDirectoryLockBlockedByUninitStorageOperation(
|
|
||||||
temporaryStorageDirectoryLock)) {
|
|
||||||
temporaryStorageDirectoryLock = nullptr;
|
|
||||||
} else {
|
|
||||||
promises.AppendElement(temporaryStorageDirectoryLock->Acquire());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<UniversalDirectoryLock> originDirectoryLock =
|
|
||||||
CreateDirectoryLockInternal(
|
|
||||||
PersistenceScope::CreateFromValue(persistenceType),
|
|
||||||
OriginScope::FromOrigin(aClientMetadata.mOrigin),
|
|
||||||
Nullable<Client::Type>(), /* aExclusive */ false);
|
|
||||||
|
|
||||||
const bool originInitialized =
|
const bool originInitialized =
|
||||||
persistenceType == PERSISTENCE_TYPE_PERSISTENT
|
persistenceType == PERSISTENCE_TYPE_PERSISTENT
|
||||||
? IsPersistentOriginInitialized(principalInfo)
|
? IsPersistentOriginInitialized(principalInfo)
|
||||||
: IsTemporaryOriginInitialized(persistenceType, principalInfo);
|
: IsTemporaryOriginInitialized(persistenceType, principalInfo);
|
||||||
|
|
||||||
if (originInitialized &&
|
RefPtr<UniversalDirectoryLock> originDirectoryLock =
|
||||||
!IsDirectoryLockBlockedByUninitStorageOrUninitOriginsOperation(
|
CreateDirectoryLockForInitialization(
|
||||||
originDirectoryLock)) {
|
*this, PersistenceScope::CreateFromValue(persistenceType),
|
||||||
originDirectoryLock = nullptr;
|
OriginScope::FromOrigin(aClientMetadata.mOrigin), originInitialized,
|
||||||
} else {
|
IsDirectoryLockBlockedByUninitStorageOrUninitOriginsOperation,
|
||||||
promises.AppendElement(originDirectoryLock->Acquire());
|
MakeBackInserter(promises));
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<ClientDirectoryLock> clientDirectoryLock =
|
RefPtr<ClientDirectoryLock> clientDirectoryLock =
|
||||||
CreateDirectoryLock(aClientMetadata, /* aExclusive */ false);
|
CreateDirectoryLock(aClientMetadata, /* aExclusive */ false);
|
||||||
|
@ -14,9 +14,32 @@
|
|||||||
#include "mozilla/dom/quota/DirectoryLock.h"
|
#include "mozilla/dom/quota/DirectoryLock.h"
|
||||||
#include "mozilla/dom/quota/DirectoryLockInlines.h"
|
#include "mozilla/dom/quota/DirectoryLockInlines.h"
|
||||||
#include "mozilla/dom/quota/ForwardDecls.h"
|
#include "mozilla/dom/quota/ForwardDecls.h"
|
||||||
|
#include "mozilla/dom/quota/QuotaManager.h"
|
||||||
|
|
||||||
namespace mozilla::dom::quota {
|
namespace mozilla::dom::quota {
|
||||||
|
|
||||||
|
template <typename UninitChecker, typename PromiseArrayIter>
|
||||||
|
RefPtr<UniversalDirectoryLock> CreateDirectoryLockForInitialization(
|
||||||
|
QuotaManager& aQuotaManager, const PersistenceScope& aPersistenceScope,
|
||||||
|
const OriginScope& aOriginScope, const bool aAlreadyInitialized,
|
||||||
|
UninitChecker&& aUninitChecker, PromiseArrayIter&& aPromiseArrayIter) {
|
||||||
|
RefPtr<UniversalDirectoryLock> directoryLock =
|
||||||
|
aQuotaManager.CreateDirectoryLockInternal(aPersistenceScope, aOriginScope,
|
||||||
|
Nullable<Client::Type>(),
|
||||||
|
/* aExclusive */ false);
|
||||||
|
|
||||||
|
if (aAlreadyInitialized &&
|
||||||
|
!std::forward<UninitChecker>(aUninitChecker)(directoryLock)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto iter = std::forward<PromiseArrayIter>(aPromiseArrayIter);
|
||||||
|
*iter = directoryLock->Acquire();
|
||||||
|
++iter;
|
||||||
|
|
||||||
|
return directoryLock;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Callable>
|
template <typename Callable>
|
||||||
class MaybeInitializeHelper final {
|
class MaybeInitializeHelper final {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user