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__
|
|
|
|
|
|
|
|
#include "mozilla/dom/quota/QuotaCommon.h"
|
|
|
|
|
2018-11-29 23:47:24 +03:00
|
|
|
#include "mozilla/dom/LocalStorageCommon.h"
|
2015-06-30 15:59:27 +03:00
|
|
|
#include "mozilla/dom/ipc/IdType.h"
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
#include "PersistenceType.h"
|
|
|
|
|
2017-03-06 20:40:31 +03:00
|
|
|
class nsIFile;
|
2013-03-26 15:13:17 +04:00
|
|
|
class nsIRunnable;
|
|
|
|
|
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"
|
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"
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
BEGIN_QUOTA_NAMESPACE
|
|
|
|
|
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:
|
2019-08-23 07:48:36 +03:00
|
|
|
typedef Atomic<bool> AtomicBool;
|
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,
|
2018-11-29 23:47:24 +03:00
|
|
|
LS,
|
2013-03-26 15:13:17 +04:00
|
|
|
TYPE_MAX
|
|
|
|
};
|
|
|
|
|
2018-11-29 23:47:24 +03:00
|
|
|
static Type TypeMax() {
|
|
|
|
if (CachedNextGenLocalStorageEnabled()) {
|
|
|
|
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
|
|
|
|
2019-08-23 07:49:14 +03:00
|
|
|
static void TypeToText(Type aType, nsAString& aText);
|
2019-08-22 16:06:48 +03:00
|
|
|
|
2019-08-23 07:49:14 +03:00
|
|
|
static void TypeToText(Type aType, nsACString& aText);
|
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);
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin, const AtomicBool& aCanceled) = 0;
|
|
|
|
|
|
|
|
virtual nsresult InitOriginWithoutTracking(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
|
|
|
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(
|
|
|
|
PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin, 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
|
|
|
|
|
|
|
virtual void ReleaseIOThreadObjects() = 0;
|
|
|
|
|
2017-07-18 13:54:20 +03:00
|
|
|
// Methods which are called on the background thread.
|
2015-06-30 15:59:27 +03:00
|
|
|
virtual void AbortOperations(const nsACString& aOrigin) = 0;
|
|
|
|
|
|
|
|
virtual void AbortOperationsForProcess(ContentParentId aContentParentId) = 0;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2015-11-22 12:43:55 +03:00
|
|
|
virtual void StartIdleMaintenance() = 0;
|
|
|
|
|
|
|
|
virtual void StopIdleMaintenance() = 0;
|
2015-04-30 23:46:51 +03:00
|
|
|
|
2015-04-14 11:57:41 +03:00
|
|
|
virtual void ShutdownWorkThreads() = 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
|
|
|
};
|
|
|
|
|
|
|
|
END_QUOTA_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_quota_client_h__
|