From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/indexedDB/DatabaseFileManager.h | 124 ++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 dom/indexedDB/DatabaseFileManager.h (limited to 'dom/indexedDB/DatabaseFileManager.h') diff --git a/dom/indexedDB/DatabaseFileManager.h b/dom/indexedDB/DatabaseFileManager.h new file mode 100644 index 0000000000..57809cb12b --- /dev/null +++ b/dom/indexedDB/DatabaseFileManager.h @@ -0,0 +1,124 @@ +/* -*- 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_INDEXEDDB_DATABASEFILEMANAGER_H_ +#define DOM_INDEXEDDB_DATABASEFILEMANAGER_H_ + +#include "FileInfoManager.h" +#include "IndexedDBCipherKeyManager.h" +#include "mozilla/dom/FlippedOnce.h" +#include "mozilla/dom/quota/CommonMetadata.h" +#include "mozilla/dom/quota/PersistenceType.h" +#include "mozilla/dom/quota/UsageInfo.h" +#include "mozilla/InitializedOnce.h" + +class nsIFile; +class mozIStorageConnection; + +namespace mozilla::dom::indexedDB { + +// Implemented in ActorsParent.cpp. +class DatabaseFileManager final + : public FileInfoManager, + public AtomicSafeRefCounted { + using PersistenceType = mozilla::dom::quota::PersistenceType; + using FileInfoManager::MutexType; + + const PersistenceType mPersistenceType; + const quota::OriginMetadata mOriginMetadata; + const nsString mDatabaseName; + const nsCString mDatabaseID; + + mutable IndexedDBCipherKeyManager mCipherKeyManager; + + LazyInitializedOnce mDirectoryPath; + LazyInitializedOnce mJournalDirectoryPath; + + const bool mEnforcingQuota; + const bool mIsInPrivateBrowsingMode; + + FlippedOnce mInitialized; + + // Lock protecting DatabaseFileManager.mFileInfos. + // It's s also used to atomically update DatabaseFileInfo.mRefCnt and + // DatabaseFileInfo.mDBRefCnt + static MutexType sMutex; + + public: + [[nodiscard]] static nsCOMPtr GetFileForId(nsIFile* aDirectory, + int64_t aId); + + [[nodiscard]] static nsCOMPtr GetCheckedFileForId( + nsIFile* aDirectory, int64_t aId); + + static nsresult InitDirectory(nsIFile& aDirectory, nsIFile& aDatabaseFile, + const nsACString& aOrigin, + uint32_t aTelemetryId); + + template + static Result TraverseFiles( + nsIFile& aDirectory, KnownDirEntryOp&& aKnownDirEntryOp, + UnknownDirEntryOp&& aUnknownDirEntryOp); + + static Result GetUsage(nsIFile* aDirectory); + + DatabaseFileManager(PersistenceType aPersistenceType, + const quota::OriginMetadata& aOriginMetadata, + const nsAString& aDatabaseName, + const nsCString& aDatabaseID, bool aEnforcingQuota, + bool aIsInPrivateBrowsingMode); + + PersistenceType Type() const { return mPersistenceType; } + + const quota::OriginMetadata& OriginMetadata() const { + return mOriginMetadata; + } + + const nsACString& Origin() const { return mOriginMetadata.mOrigin; } + + const nsAString& DatabaseName() const { return mDatabaseName; } + + const nsCString& DatabaseID() const { return mDatabaseID; } + + IndexedDBCipherKeyManager& MutableCipherKeyManagerRef() const { + return mCipherKeyManager; + } + + auto IsInPrivateBrowsingMode() const { return mIsInPrivateBrowsingMode; } + + bool EnforcingQuota() const { return mEnforcingQuota; } + + bool Initialized() const { return mInitialized; } + + nsresult Init(nsIFile* aDirectory, mozIStorageConnection& aConnection); + + [[nodiscard]] nsCOMPtr GetDirectory(); + + [[nodiscard]] nsCOMPtr GetCheckedDirectory(); + + [[nodiscard]] nsCOMPtr GetJournalDirectory(); + + [[nodiscard]] nsCOMPtr EnsureJournalDirectory(); + + [[nodiscard]] nsresult SyncDeleteFile(int64_t aId); + + // XXX When getting rid of FileHelper, this method should be removed/made + // private. + [[nodiscard]] nsresult SyncDeleteFile(nsIFile& aFile, + nsIFile& aJournalFile) const; + + [[nodiscard]] nsresult AsyncDeleteFile(int64_t aFileId); + + MOZ_DECLARE_REFCOUNTED_TYPENAME(DatabaseFileManager) + + static StaticMutex& Mutex() { return sMutex; } + + ~DatabaseFileManager() = default; +}; + +} // namespace mozilla::dom::indexedDB + +#endif // DOM_INDEXEDDB_DATABASEFILEMANAGER_H_ -- cgit v1.2.3