2011-12-16 07:34:24 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2021-06-01 03:42:47 +00:00
|
|
|
#ifndef DOM_INDEXEDDB_DATABASEFILEMANAGER_H_
|
|
|
|
#define DOM_INDEXEDDB_DATABASEFILEMANAGER_H_
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2021-06-01 08:50:31 +00:00
|
|
|
#include "FileInfoManager.h"
|
2021-03-11 05:53:17 +00:00
|
|
|
#include "mozilla/dom/quota/CommonMetadata.h"
|
2013-09-11 04:18:36 +00:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
2020-06-25 09:30:06 +00:00
|
|
|
#include "mozilla/dom/quota/UsageInfo.h"
|
2020-04-01 09:53:39 +00:00
|
|
|
#include "mozilla/InitializedOnce.h"
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class nsIFile;
|
2011-12-16 07:34:24 +00:00
|
|
|
class mozIStorageConnection;
|
|
|
|
|
2021-06-01 03:42:47 +00:00
|
|
|
namespace mozilla::dom::indexedDB {
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// Implemented in ActorsParent.cpp.
|
2021-06-01 03:42:47 +00:00
|
|
|
class DatabaseFileManager final
|
2021-06-01 08:50:31 +00:00
|
|
|
: public FileInfoManager<DatabaseFileManager>,
|
2021-06-01 03:42:47 +00:00
|
|
|
public AtomicSafeRefCounted<DatabaseFileManager> {
|
2020-03-17 11:50:58 +00:00
|
|
|
using PersistenceType = mozilla::dom::quota::PersistenceType;
|
2021-06-01 08:50:31 +00:00
|
|
|
using FileInfoManager<DatabaseFileManager>::MutexType;
|
2013-03-26 11:13:17 +00:00
|
|
|
|
2020-02-26 10:08:38 +00:00
|
|
|
const PersistenceType mPersistenceType;
|
2021-02-12 14:03:28 +00:00
|
|
|
const quota::OriginMetadata mOriginMetadata;
|
2020-02-26 10:08:38 +00:00
|
|
|
const nsString mDatabaseName;
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2020-04-01 09:53:39 +00:00
|
|
|
LazyInitializedOnce<const nsString> mDirectoryPath;
|
|
|
|
LazyInitializedOnce<const nsString> mJournalDirectoryPath;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-10-28 19:06:54 +00:00
|
|
|
const bool mEnforcingQuota;
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2021-06-01 03:42:47 +00:00
|
|
|
// Lock protecting DatabaseFileManager.mFileInfos.
|
2021-05-31 17:44:19 +00:00
|
|
|
// It's s also used to atomically update DatabaseFileInfo.mRefCnt and
|
|
|
|
// DatabaseFileInfo.mDBRefCnt
|
2020-03-17 11:50:58 +00:00
|
|
|
static MutexType sMutex;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
public:
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] static nsCOMPtr<nsIFile> GetFileForId(nsIFile* aDirectory,
|
|
|
|
int64_t aId);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] static nsCOMPtr<nsIFile> GetCheckedFileForId(
|
|
|
|
nsIFile* aDirectory, int64_t aId);
|
2016-10-25 19:18:58 +00:00
|
|
|
|
2020-04-21 14:40:00 +00:00
|
|
|
static nsresult InitDirectory(nsIFile& aDirectory, nsIFile& aDatabaseFile,
|
2015-05-19 16:25:50 +00:00
|
|
|
const nsACString& aOrigin,
|
|
|
|
uint32_t aTelemetryId);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2020-06-25 09:30:06 +00:00
|
|
|
static Result<quota::FileUsageType, nsresult> GetUsage(nsIFile* aDirectory);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2021-06-01 03:42:47 +00:00
|
|
|
DatabaseFileManager(PersistenceType aPersistenceType,
|
|
|
|
const quota::OriginMetadata& aOriginMetadata,
|
|
|
|
const nsAString& aDatabaseName, bool aEnforcingQuota);
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
PersistenceType Type() const { return mPersistenceType; }
|
|
|
|
|
2021-02-12 14:03:28 +00:00
|
|
|
const quota::OriginMetadata& OriginMetadata() const {
|
|
|
|
return mOriginMetadata;
|
2020-10-20 11:46:31 +00:00
|
|
|
}
|
2013-09-11 04:18:36 +00:00
|
|
|
|
2021-02-12 14:03:28 +00:00
|
|
|
const nsACString& Origin() const { return mOriginMetadata.mOrigin; }
|
2011-12-16 07:34:24 +00:00
|
|
|
|
|
|
|
const nsAString& DatabaseName() const { return mDatabaseName; }
|
|
|
|
|
2014-10-28 19:06:54 +00:00
|
|
|
bool EnforcingQuota() const { return mEnforcingQuota; }
|
|
|
|
|
2020-05-14 09:14:17 +00:00
|
|
|
nsresult Init(nsIFile* aDirectory, mozIStorageConnection& aConnection);
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] nsCOMPtr<nsIFile> GetDirectory();
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] nsCOMPtr<nsIFile> GetCheckedDirectory();
|
2016-10-25 19:18:58 +00:00
|
|
|
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] nsCOMPtr<nsIFile> GetJournalDirectory();
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] nsCOMPtr<nsIFile> EnsureJournalDirectory();
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] nsresult SyncDeleteFile(int64_t aId);
|
2020-03-16 09:48:46 +00:00
|
|
|
|
2020-03-19 14:40:04 +00:00
|
|
|
// XXX When getting rid of FileHelper, this method should be removed/made
|
|
|
|
// private.
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] nsresult SyncDeleteFile(nsIFile& aFile, nsIFile& aJournalFile);
|
2020-03-19 14:40:04 +00:00
|
|
|
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] nsresult AsyncDeleteFile(int64_t aFileId);
|
2020-03-16 09:49:47 +00:00
|
|
|
|
2021-06-01 03:42:47 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(DatabaseFileManager)
|
2012-08-24 18:51:33 +00:00
|
|
|
|
2020-03-17 11:50:58 +00:00
|
|
|
static StaticMutex& Mutex() { return sMutex; }
|
|
|
|
|
2021-06-01 03:42:47 +00:00
|
|
|
~DatabaseFileManager() = default;
|
2011-12-16 07:34:24 +00:00
|
|
|
};
|
|
|
|
|
2021-06-01 03:42:47 +00:00
|
|
|
} // namespace mozilla::dom::indexedDB
|
2011-12-16 07:34:24 +00:00
|
|
|
|
2021-06-01 03:42:47 +00:00
|
|
|
#endif // DOM_INDEXEDDB_DATABASEFILEMANAGER_H_
|