michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_quota_client_h__ michael@0: #define mozilla_dom_quota_client_h__ michael@0: michael@0: #include "mozilla/dom/quota/QuotaCommon.h" michael@0: michael@0: #include "PersistenceType.h" michael@0: michael@0: class nsIOfflineStorage; michael@0: class nsIRunnable; michael@0: michael@0: #define IDB_DIRECTORY_NAME "idb" michael@0: #define ASMJSCACHE_DIRECTORY_NAME "asmjs" michael@0: michael@0: BEGIN_QUOTA_NAMESPACE michael@0: michael@0: class OriginOrPatternString; michael@0: class UsageInfo; michael@0: michael@0: // An abstract interface for quota manager clients. michael@0: // Each storage API must provide an implementation of this interface in order michael@0: // to participate in centralized quota and storage handling. michael@0: class Client michael@0: { michael@0: public: michael@0: NS_IMETHOD_(MozExternalRefCountType) michael@0: AddRef() = 0; michael@0: michael@0: NS_IMETHOD_(MozExternalRefCountType) michael@0: Release() = 0; michael@0: michael@0: enum Type { michael@0: IDB = 0, michael@0: //LS, michael@0: //APPCACHE, michael@0: ASMJS, michael@0: TYPE_MAX michael@0: }; michael@0: michael@0: virtual Type michael@0: GetType() = 0; michael@0: michael@0: static nsresult michael@0: TypeToText(Type aType, nsAString& aText) michael@0: { michael@0: switch (aType) { michael@0: case IDB: michael@0: aText.AssignLiteral(IDB_DIRECTORY_NAME); michael@0: break; michael@0: michael@0: case ASMJS: michael@0: aText.AssignLiteral(ASMJSCACHE_DIRECTORY_NAME); michael@0: break; michael@0: michael@0: case TYPE_MAX: michael@0: default: michael@0: NS_NOTREACHED("Bad id value!"); michael@0: return NS_ERROR_UNEXPECTED; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: static nsresult michael@0: TypeFromText(const nsAString& aText, Type& aType) michael@0: { michael@0: if (aText.EqualsLiteral(IDB_DIRECTORY_NAME)) { michael@0: aType = IDB; michael@0: } michael@0: else if (aText.EqualsLiteral(ASMJSCACHE_DIRECTORY_NAME)) { michael@0: aType = ASMJS; michael@0: } michael@0: else { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: // Methods which are called on the IO thred. michael@0: virtual nsresult michael@0: InitOrigin(PersistenceType aPersistenceType, michael@0: const nsACString& aGroup, michael@0: const nsACString& aOrigin, michael@0: UsageInfo* aUsageInfo) = 0; michael@0: michael@0: virtual nsresult michael@0: GetUsageForOrigin(PersistenceType aPersistenceType, michael@0: const nsACString& aGroup, michael@0: const nsACString& aOrigin, michael@0: UsageInfo* aUsageInfo) = 0; michael@0: michael@0: virtual void michael@0: OnOriginClearCompleted(PersistenceType aPersistenceType, michael@0: const OriginOrPatternString& aOriginOrPattern) = 0; michael@0: michael@0: virtual void michael@0: ReleaseIOThreadObjects() = 0; michael@0: michael@0: // Methods which are called on the main thred. michael@0: virtual bool michael@0: IsFileServiceUtilized() = 0; michael@0: michael@0: virtual bool michael@0: IsTransactionServiceActivated() = 0; michael@0: michael@0: virtual void michael@0: WaitForStoragesToComplete(nsTArray& aStorages, michael@0: nsIRunnable* aCallback) = 0; michael@0: michael@0: virtual void michael@0: AbortTransactionsForStorage(nsIOfflineStorage* aStorage) = 0; michael@0: michael@0: virtual bool michael@0: HasTransactionsForStorage(nsIOfflineStorage* aStorage) = 0; michael@0: michael@0: virtual void michael@0: ShutdownTransactionService() = 0; michael@0: michael@0: protected: michael@0: virtual ~Client() michael@0: { } michael@0: }; michael@0: michael@0: END_QUOTA_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_quota_client_h__