2013-03-26 15:13:17 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-03-26 15:13:17 +04: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_quota_client_h__
|
|
|
|
#define mozilla_dom_quota_client_h__
|
|
|
|
|
2020-10-21 16:16:19 +03:00
|
|
|
#include "ErrorList.h"
|
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
#include "mozilla/Result.h"
|
2015-06-30 15:59:27 +03:00
|
|
|
#include "mozilla/dom/ipc/IdType.h"
|
2020-10-21 16:16:19 +03:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
2020-12-09 11:13:44 +03:00
|
|
|
#include "nsHashKeys.h"
|
2020-10-21 16:16:19 +03:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsStringFwd.h"
|
2021-03-23 13:36:35 +03:00
|
|
|
#include "nsTHashSet.h"
|
2013-09-11 08:18:36 +04:00
|
|
|
|
2020-12-15 13:26:08 +03:00
|
|
|
// XXX Remove this dependency.
|
|
|
|
#include "mozilla/dom/LocalStorageCommon.h"
|
|
|
|
|
2017-03-06 20:40:31 +03:00
|
|
|
class nsIFile;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-11-19 01:49:53 +04:00
|
|
|
#define IDB_DIRECTORY_NAME "idb"
|
2015-03-02 16:20:00 +03:00
|
|
|
#define DOMCACHE_DIRECTORY_NAME "cache"
|
2018-08-20 15:33:03 +03:00
|
|
|
#define SDB_DIRECTORY_NAME "sdb"
|
2022-08-31 12:35:00 +03:00
|
|
|
#define FILESYSTEM_DIRECTORY_NAME "fs"
|
2018-06-29 10:58:09 +03:00
|
|
|
#define LS_DIRECTORY_NAME "ls"
|
2013-11-19 01:49:53 +04:00
|
|
|
|
2019-03-13 18:59:34 +03:00
|
|
|
// Deprecated
|
|
|
|
#define ASMJSCACHE_DIRECTORY_NAME "asmjs"
|
|
|
|
|
2020-10-21 16:16:19 +03:00
|
|
|
namespace mozilla::dom {
|
|
|
|
template <typename T>
|
|
|
|
struct Nullable;
|
|
|
|
}
|
|
|
|
|
2020-12-15 13:26:08 +03:00
|
|
|
namespace mozilla::dom::quota {
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2021-02-12 17:03:28 +03:00
|
|
|
struct OriginMetadata;
|
2018-11-29 23:49:46 +03:00
|
|
|
class OriginScope;
|
2016-07-18 19:51:54 +03:00
|
|
|
class QuotaManager;
|
2013-09-11 08:18:36 +04:00
|
|
|
class UsageInfo;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
// An abstract interface for quota manager clients.
|
|
|
|
// Each storage API must provide an implementation of this interface in order
|
|
|
|
// to participate in centralized quota and storage handling.
|
|
|
|
class Client {
|
|
|
|
public:
|
2021-08-16 20:05:42 +03:00
|
|
|
using AtomicBool = Atomic<bool>;
|
2017-03-22 14:13:54 +03:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
enum Type {
|
|
|
|
IDB = 0,
|
|
|
|
// APPCACHE,
|
2015-03-02 16:20:00 +03:00
|
|
|
DOMCACHE,
|
2018-08-20 15:33:03 +03:00
|
|
|
SDB,
|
2022-08-31 12:35:00 +03:00
|
|
|
FILESYSTEM,
|
2018-11-29 23:47:24 +03:00
|
|
|
LS,
|
2013-03-26 15:13:17 +04:00
|
|
|
TYPE_MAX
|
|
|
|
};
|
|
|
|
|
2020-12-09 11:13:44 +03:00
|
|
|
class DirectoryLockIdTable final {
|
2021-03-23 13:36:35 +03:00
|
|
|
nsTHashSet<uint64_t> mIds;
|
2020-12-09 11:13:44 +03:00
|
|
|
|
|
|
|
public:
|
2021-03-23 13:36:35 +03:00
|
|
|
void Put(const int64_t aId) { mIds.Insert(aId); }
|
2020-12-09 11:13:44 +03:00
|
|
|
|
|
|
|
bool Has(const int64_t aId) const { return mIds.Contains(aId); }
|
|
|
|
|
|
|
|
bool Filled() const { return mIds.Count(); }
|
|
|
|
};
|
|
|
|
|
2018-11-29 23:47:24 +03:00
|
|
|
static Type TypeMax() {
|
2022-06-07 18:01:54 +03:00
|
|
|
if (NextGenLocalStorageEnabled()) {
|
2018-11-29 23:47:24 +03:00
|
|
|
return TYPE_MAX;
|
|
|
|
}
|
|
|
|
return LS;
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:06:30 +03:00
|
|
|
static bool IsValidType(Type aType);
|
|
|
|
|
2019-08-23 07:49:14 +03:00
|
|
|
static bool TypeToText(Type aType, nsAString& aText, const fallible_t&);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2023-01-10 15:44:14 +03:00
|
|
|
// TODO: Rename other similar methods to use String/CString instead of Text.
|
|
|
|
static nsAutoString TypeToString(Type aType);
|
|
|
|
|
2020-11-30 13:47:02 +03:00
|
|
|
static nsAutoCString TypeToText(Type aType);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2019-08-23 07:49:14 +03:00
|
|
|
static bool TypeFromText(const nsAString& aText, Type& aType,
|
|
|
|
const fallible_t&);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2019-08-23 07:49:14 +03:00
|
|
|
static Type TypeFromText(const nsACString& aText);
|
2018-11-29 23:47:58 +03:00
|
|
|
|
2019-08-25 04:34:37 +03:00
|
|
|
static char TypeToPrefix(Type aType);
|
|
|
|
|
|
|
|
static bool TypeFromPrefix(char aPrefix, Type& aType, const fallible_t&);
|
|
|
|
|
2019-03-13 18:59:34 +03:00
|
|
|
static bool IsDeprecatedClient(const nsAString& aText) {
|
|
|
|
return aText.EqualsLiteral(ASMJSCACHE_DIRECTORY_NAME);
|
|
|
|
}
|
|
|
|
|
2020-12-09 11:13:44 +03:00
|
|
|
template <typename T>
|
|
|
|
static bool IsLockForObjectContainedInLockTable(
|
2021-02-09 13:42:22 +03:00
|
|
|
const T& aObject, const DirectoryLockIdTable& aIds);
|
2020-12-09 11:13:44 +03:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static bool IsLockForObjectAcquiredAndContainedInLockTable(
|
2021-02-09 13:42:22 +03:00
|
|
|
const T& aObject, const DirectoryLockIdTable& aIds);
|
2020-12-09 11:13:44 +03:00
|
|
|
|
2019-08-23 07:49:14 +03:00
|
|
|
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
|
|
|
|
|
|
|
|
virtual Type GetType() = 0;
|
|
|
|
|
2017-07-18 13:54:20 +03:00
|
|
|
// Methods which are called on the IO thread.
|
2017-03-06 20:40:31 +03:00
|
|
|
virtual nsresult UpgradeStorageFrom1_0To2_0(nsIFile* aDirectory) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-03 17:02:27 +03:00
|
|
|
virtual nsresult UpgradeStorageFrom2_0To2_1(nsIFile* aDirectory) {
|
2017-07-18 13:54:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-13 18:59:34 +03:00
|
|
|
virtual nsresult UpgradeStorageFrom2_1To2_2(nsIFile* aDirectory) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-25 12:31:39 +03:00
|
|
|
virtual Result<UsageInfo, nsresult> InitOrigin(
|
2021-02-12 17:03:28 +03:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
const AtomicBool& aCanceled) = 0;
|
2020-06-25 12:31:39 +03:00
|
|
|
|
2020-10-20 14:46:31 +03:00
|
|
|
virtual nsresult InitOriginWithoutTracking(
|
2021-02-12 17:03:28 +03:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
const AtomicBool& aCanceled) = 0;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2020-06-25 11:34:43 +03:00
|
|
|
virtual Result<UsageInfo, nsresult> GetUsageForOrigin(
|
2021-02-12 17:03:28 +03:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
const AtomicBool& aCanceled) = 0;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2018-11-29 23:49:46 +03:00
|
|
|
// This method is called when origins are about to be cleared
|
|
|
|
// (except the case when clearing is triggered by the origin eviction).
|
|
|
|
virtual nsresult AboutToClearOrigins(
|
|
|
|
const Nullable<PersistenceType>& aPersistenceType,
|
|
|
|
const OriginScope& aOriginScope) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
virtual void OnOriginClearCompleted(PersistenceType aPersistenceType,
|
2014-11-28 11:44:12 +03:00
|
|
|
const nsACString& aOrigin) = 0;
|
2013-06-05 12:11:23 +04:00
|
|
|
|
2023-04-26 11:23:13 +03:00
|
|
|
virtual void OnRepositoryClearCompleted(PersistenceType aPersistenceType) = 0;
|
|
|
|
|
2013-06-05 12:11:23 +04:00
|
|
|
virtual void ReleaseIOThreadObjects() = 0;
|
|
|
|
|
2017-07-18 13:54:20 +03:00
|
|
|
// Methods which are called on the background thread.
|
2020-12-09 11:13:44 +03:00
|
|
|
virtual void AbortOperationsForLocks(
|
|
|
|
const DirectoryLockIdTable& aDirectoryLockIds) = 0;
|
2015-06-30 15:59:27 +03:00
|
|
|
|
|
|
|
virtual void AbortOperationsForProcess(ContentParentId aContentParentId) = 0;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2020-12-02 19:38:07 +03:00
|
|
|
virtual void AbortAllOperations() = 0;
|
|
|
|
|
2015-11-22 12:43:55 +03:00
|
|
|
virtual void StartIdleMaintenance() = 0;
|
|
|
|
|
|
|
|
virtual void StopIdleMaintenance() = 0;
|
2015-04-30 23:46:51 +03:00
|
|
|
|
2022-04-14 18:05:36 +03:00
|
|
|
// Both variants just check for QuotaManager::IsShuttingDown()
|
|
|
|
// but assert to be on the right thread.
|
|
|
|
// They must not be used for re-entrance checks.
|
|
|
|
// Deprecated: This distinction is not needed anymore.
|
|
|
|
// QuotaClients should call QuotaManager::IsShuttingDown instead.
|
|
|
|
static bool IsShuttingDownOnBackgroundThread();
|
|
|
|
static bool IsShuttingDownOnNonBackgroundThread();
|
|
|
|
|
2020-12-07 17:49:36 +03:00
|
|
|
// Returns true if there is work that needs to be waited for.
|
|
|
|
bool InitiateShutdownWorkThreads();
|
|
|
|
void FinalizeShutdownWorkThreads();
|
|
|
|
|
2020-12-15 20:15:27 +03:00
|
|
|
virtual nsCString GetShutdownStatus() const = 0;
|
2020-12-07 17:49:36 +03:00
|
|
|
virtual bool IsShutdownCompleted() const = 0;
|
2020-12-15 20:15:27 +03:00
|
|
|
virtual void ForceKillActors() = 0;
|
2020-11-30 13:54:29 +03:00
|
|
|
|
2020-11-26 12:20:03 +03:00
|
|
|
private:
|
|
|
|
virtual void InitiateShutdown() = 0;
|
|
|
|
virtual void FinalizeShutdown() = 0;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
protected:
|
2020-02-12 13:25:22 +03:00
|
|
|
virtual ~Client() = default;
|
2013-03-26 15:13:17 +04:00
|
|
|
};
|
|
|
|
|
2020-12-15 13:26:08 +03:00
|
|
|
} // namespace mozilla::dom::quota
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
#endif // mozilla_dom_quota_client_h__
|