2012-12-17 23:25:10 +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: */
|
2012-12-17 23:25:10 +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_filestreams_h__
|
|
|
|
#define mozilla_dom_quota_filestreams_h__
|
|
|
|
|
|
|
|
#include "QuotaCommon.h"
|
|
|
|
|
|
|
|
#include "nsFileStreams.h"
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
#include "PersistenceType.h"
|
2013-03-26 15:13:17 +04:00
|
|
|
#include "QuotaObject.h"
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
BEGIN_QUOTA_NAMESPACE
|
|
|
|
|
|
|
|
template <class FileStreamBase>
|
|
|
|
class FileQuotaStream : public FileStreamBase {
|
|
|
|
public:
|
|
|
|
// nsFileStreamBase override
|
|
|
|
NS_IMETHOD
|
2015-03-21 19:28:04 +03:00
|
|
|
SetEOF() override;
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
NS_IMETHOD
|
2015-03-21 19:28:04 +03:00
|
|
|
Close() override;
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
protected:
|
2013-09-11 08:18:36 +04:00
|
|
|
FileQuotaStream(PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin)
|
|
|
|
: mPersistenceType(aPersistenceType), mGroup(aGroup), mOrigin(aOrigin) {}
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
// nsFileStreamBase override
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult DoOpen() override;
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
PersistenceType mPersistenceType;
|
|
|
|
nsCString mGroup;
|
2012-12-17 23:25:10 +04:00
|
|
|
nsCString mOrigin;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<QuotaObject> mQuotaObject;
|
2012-12-17 23:25:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class FileStreamBase>
|
|
|
|
class FileQuotaStreamWithWrite : public FileQuotaStream<FileStreamBase> {
|
|
|
|
public:
|
|
|
|
// nsFileStreamBase override
|
|
|
|
NS_IMETHOD
|
2015-03-21 19:28:04 +03:00
|
|
|
Write(const char* aBuf, uint32_t aCount, uint32_t* _retval) override;
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
protected:
|
2013-09-11 08:18:36 +04:00
|
|
|
FileQuotaStreamWithWrite(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup, const nsACString& aOrigin)
|
|
|
|
: FileQuotaStream<FileStreamBase>(aPersistenceType, aGroup, aOrigin) {}
|
2012-12-17 23:25:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileInputStream : public FileQuotaStream<nsFileInputStream> {
|
|
|
|
public:
|
2018-02-12 23:44:40 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(FileInputStream,
|
|
|
|
FileQuotaStream<nsFileInputStream>)
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
FileInputStream(PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin)
|
|
|
|
: FileQuotaStream<nsFileInputStream>(aPersistenceType, aGroup, aOrigin) {}
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2018-08-20 15:32:33 +03:00
|
|
|
private:
|
2012-12-17 23:25:10 +04:00
|
|
|
virtual ~FileInputStream() { Close(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileOutputStream : public FileQuotaStreamWithWrite<nsFileOutputStream> {
|
|
|
|
public:
|
2018-02-12 23:44:40 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(
|
|
|
|
FileOutputStream, FileQuotaStreamWithWrite<nsFileOutputStream>);
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
FileOutputStream(PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin)
|
|
|
|
: FileQuotaStreamWithWrite<nsFileOutputStream>(aPersistenceType, aGroup,
|
|
|
|
aOrigin) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-20 15:32:33 +03:00
|
|
|
private:
|
2012-12-17 23:25:10 +04:00
|
|
|
virtual ~FileOutputStream() { Close(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileStream : public FileQuotaStreamWithWrite<nsFileStream> {
|
|
|
|
public:
|
2018-02-12 23:44:40 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(FileStream,
|
|
|
|
FileQuotaStreamWithWrite<nsFileStream>)
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
FileStream(PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin)
|
|
|
|
: FileQuotaStreamWithWrite<nsFileStream>(aPersistenceType, aGroup,
|
|
|
|
aOrigin) {}
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2018-08-20 15:32:33 +03:00
|
|
|
private:
|
2012-12-17 23:25:10 +04:00
|
|
|
virtual ~FileStream() { Close(); }
|
|
|
|
};
|
|
|
|
|
2018-08-20 15:32:33 +03:00
|
|
|
already_AddRefed<FileInputStream> CreateFileInputStream(
|
|
|
|
PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-20 15:32:33 +03:00
|
|
|
already_AddRefed<FileOutputStream> CreateFileOutputStream(
|
|
|
|
PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-20 15:32:33 +03:00
|
|
|
already_AddRefed<FileStream> CreateFileStream(
|
|
|
|
PersistenceType aPersistenceType, const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
|
|
|
|
2012-12-17 23:25:10 +04:00
|
|
|
END_QUOTA_NAMESPACE
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_quota_filestreams_h__ */
|