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__
|
|
|
|
|
2020-10-21 16:16:19 +03:00
|
|
|
// Local includes
|
|
|
|
#include "Client.h"
|
|
|
|
|
|
|
|
// Global includes
|
|
|
|
#include <cstdint>
|
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2021-02-13 00:43:42 +03:00
|
|
|
#include "mozilla/dom/quota/OriginMetadata.h"
|
2020-10-21 16:16:19 +03:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
|
|
|
#include "mozilla/dom/quota/QuotaObject.h"
|
2012-12-17 23:25:10 +04:00
|
|
|
#include "nsFileStreams.h"
|
2020-10-21 16:16:19 +03:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
class nsIFile;
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2020-10-21 16:16:19 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class Runnable;
|
|
|
|
}
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2020-12-15 13:26:08 +03:00
|
|
|
namespace mozilla::dom::quota {
|
|
|
|
|
|
|
|
class QuotaObject;
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
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:
|
2020-10-20 14:46:31 +03:00
|
|
|
FileQuotaStream(PersistenceType aPersistenceType,
|
2021-02-12 17:03:28 +03:00
|
|
|
const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
Client::Type aClientType)
|
2019-08-22 16:06:48 +03:00
|
|
|
: mPersistenceType(aPersistenceType),
|
2021-02-12 17:03:28 +03:00
|
|
|
mOriginMetadata(aOriginMetadata),
|
2019-08-22 16:06:48 +03:00
|
|
|
mClientType(aClientType) {}
|
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;
|
2021-02-12 17:03:28 +03:00
|
|
|
OriginMetadata mOriginMetadata;
|
2019-08-22 16:06:48 +03:00
|
|
|
Client::Type mClientType;
|
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,
|
2021-02-12 17:03:28 +03:00
|
|
|
const OriginMetadata& aOriginMetadata,
|
2019-08-22 16:06:48 +03:00
|
|
|
Client::Type aClientType)
|
2021-02-12 17:03:28 +03:00
|
|
|
: FileQuotaStream<FileStreamBase>(aPersistenceType, aOriginMetadata,
|
2019-08-22 16:06:48 +03:00
|
|
|
aClientType) {}
|
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
|
|
|
|
2020-10-20 14:46:31 +03:00
|
|
|
FileInputStream(PersistenceType aPersistenceType,
|
2021-02-12 17:03:28 +03:00
|
|
|
const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
Client::Type aClientType)
|
2021-02-12 17:03:28 +03:00
|
|
|
: FileQuotaStream<nsFileInputStream>(aPersistenceType, aOriginMetadata,
|
2019-08-22 16:06:48 +03:00
|
|
|
aClientType) {}
|
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
|
|
|
|
2020-10-20 14:46:31 +03:00
|
|
|
FileOutputStream(PersistenceType aPersistenceType,
|
2021-02-12 17:03:28 +03:00
|
|
|
const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
Client::Type aClientType)
|
|
|
|
: FileQuotaStreamWithWrite<nsFileOutputStream>(
|
2021-02-12 17:03:28 +03:00
|
|
|
aPersistenceType, aOriginMetadata, aClientType) {}
|
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
|
|
|
|
2020-10-20 14:46:31 +03:00
|
|
|
FileStream(PersistenceType aPersistenceType,
|
2021-02-12 17:03:28 +03:00
|
|
|
const OriginMetadata& aOriginMetadata, Client::Type aClientType)
|
2020-10-20 14:46:31 +03:00
|
|
|
: FileQuotaStreamWithWrite<nsFileStream>(aPersistenceType,
|
2021-02-12 17:03:28 +03:00
|
|
|
aOriginMetadata, aClientType) {}
|
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(); }
|
|
|
|
};
|
|
|
|
|
2021-01-28 14:12:19 +03:00
|
|
|
Result<NotNull<RefPtr<FileInputStream>>, nsresult> CreateFileInputStream(
|
2021-02-12 17:03:28 +03:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-01-28 14:12:19 +03:00
|
|
|
Result<NotNull<RefPtr<FileOutputStream>>, nsresult> CreateFileOutputStream(
|
2021-02-12 17:03:28 +03:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-01-28 14:12:19 +03:00
|
|
|
Result<NotNull<RefPtr<FileStream>>, nsresult> CreateFileStream(
|
2021-02-12 17:03:28 +03:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 14:46:31 +03:00
|
|
|
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
2018-08-20 15:32:33 +03:00
|
|
|
|
2020-12-15 13:26:08 +03:00
|
|
|
} // namespace mozilla::dom::quota
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
#endif /* mozilla_dom_quota_filestreams_h__ */
|