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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_quota_filestreams_h__ michael@0: #define mozilla_dom_quota_filestreams_h__ michael@0: michael@0: #include "QuotaCommon.h" michael@0: michael@0: #include "nsFileStreams.h" michael@0: michael@0: #include "PersistenceType.h" michael@0: #include "QuotaObject.h" michael@0: michael@0: BEGIN_QUOTA_NAMESPACE michael@0: michael@0: template michael@0: class FileQuotaStream : public FileStreamBase michael@0: { michael@0: public: michael@0: // nsFileStreamBase override michael@0: NS_IMETHOD michael@0: SetEOF() MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD michael@0: Close() MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: FileQuotaStream(PersistenceType aPersistenceType, const nsACString& aGroup, michael@0: const nsACString& aOrigin) michael@0: : mPersistenceType(aPersistenceType), mGroup(aGroup), mOrigin(aOrigin) michael@0: { } michael@0: michael@0: // nsFileStreamBase override michael@0: virtual nsresult michael@0: DoOpen() MOZ_OVERRIDE; michael@0: michael@0: PersistenceType mPersistenceType; michael@0: nsCString mGroup; michael@0: nsCString mOrigin; michael@0: nsRefPtr mQuotaObject; michael@0: }; michael@0: michael@0: template michael@0: class FileQuotaStreamWithWrite : public FileQuotaStream michael@0: { michael@0: public: michael@0: // nsFileStreamBase override michael@0: NS_IMETHOD michael@0: Write(const char* aBuf, uint32_t aCount, uint32_t* _retval) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: FileQuotaStreamWithWrite(PersistenceType aPersistenceType, michael@0: const nsACString& aGroup, const nsACString& aOrigin) michael@0: : FileQuotaStream(aPersistenceType, aGroup, aOrigin) michael@0: { } michael@0: }; michael@0: michael@0: class FileInputStream : public FileQuotaStream michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: static already_AddRefed michael@0: Create(PersistenceType aPersistenceType, const nsACString& aGroup, michael@0: const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1, michael@0: int32_t aPerm = -1, int32_t aBehaviorFlags = 0); michael@0: michael@0: private: michael@0: FileInputStream(PersistenceType aPersistenceType, const nsACString& aGroup, michael@0: const nsACString& aOrigin) michael@0: : FileQuotaStream(aPersistenceType, aGroup, aOrigin) michael@0: { } michael@0: michael@0: virtual ~FileInputStream() { michael@0: Close(); michael@0: } michael@0: }; michael@0: michael@0: class FileOutputStream : public FileQuotaStreamWithWrite michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: static already_AddRefed michael@0: Create(PersistenceType aPersistenceType, const nsACString& aGroup, michael@0: const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1, michael@0: int32_t aPerm = -1, int32_t aBehaviorFlags = 0); michael@0: michael@0: private: michael@0: FileOutputStream(PersistenceType aPersistenceType, const nsACString& aGroup, michael@0: const nsACString& aOrigin) michael@0: : FileQuotaStreamWithWrite(aPersistenceType, aGroup, michael@0: aOrigin) michael@0: { } michael@0: michael@0: virtual ~FileOutputStream() { michael@0: Close(); michael@0: } michael@0: }; michael@0: michael@0: class FileStream : public FileQuotaStreamWithWrite michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: static already_AddRefed michael@0: Create(PersistenceType aPersistenceType, const nsACString& aGroup, michael@0: const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1, michael@0: int32_t aPerm = -1, int32_t aBehaviorFlags = 0); michael@0: michael@0: private: michael@0: FileStream(PersistenceType aPersistenceType, const nsACString& aGroup, michael@0: const nsACString& aOrigin) michael@0: : FileQuotaStreamWithWrite(aPersistenceType, aGroup, aOrigin) michael@0: { } michael@0: michael@0: virtual ~FileStream() { michael@0: Close(); michael@0: } michael@0: }; michael@0: michael@0: END_QUOTA_NAMESPACE michael@0: michael@0: #endif /* mozilla_dom_quota_filestreams_h__ */