2012-12-17 19:25:10 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-12-17 19:25:10 +00: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 13:16:19 +00:00
|
|
|
// Local includes
|
|
|
|
#include "Client.h"
|
|
|
|
|
|
|
|
// Global includes
|
|
|
|
#include <cstdint>
|
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2021-03-11 05:53:17 +00:00
|
|
|
#include "mozilla/dom/quota/CommonMetadata.h"
|
2020-10-21 13:16:19 +00:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
|
|
|
#include "mozilla/dom/quota/QuotaObject.h"
|
2012-12-17 19:25:10 +00:00
|
|
|
#include "nsFileStreams.h"
|
2020-10-21 13:16:19 +00:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
|
|
|
|
class nsIFile;
|
2012-12-17 19:25:10 +00:00
|
|
|
|
2020-10-21 13:16:19 +00:00
|
|
|
namespace mozilla {
|
|
|
|
class Runnable;
|
|
|
|
}
|
2012-12-17 19:25:10 +00:00
|
|
|
|
2020-12-15 10:26:08 +00:00
|
|
|
namespace mozilla::dom::quota {
|
|
|
|
|
|
|
|
class QuotaObject;
|
2012-12-17 19:25:10 +00:00
|
|
|
|
|
|
|
template <class FileStreamBase>
|
|
|
|
class FileQuotaStream : public FileStreamBase {
|
|
|
|
public:
|
|
|
|
// nsFileStreamBase override
|
|
|
|
NS_IMETHOD
|
2015-03-21 16:28:04 +00:00
|
|
|
SetEOF() override;
|
2012-12-17 19:25:10 +00:00
|
|
|
|
|
|
|
NS_IMETHOD
|
2015-03-21 16:28:04 +00:00
|
|
|
Close() override;
|
2012-12-17 19:25:10 +00:00
|
|
|
|
|
|
|
protected:
|
2020-10-20 11:46:31 +00:00
|
|
|
FileQuotaStream(PersistenceType aPersistenceType,
|
2021-02-12 14:03:28 +00:00
|
|
|
const OriginMetadata& aOriginMetadata,
|
2020-10-20 11:46:31 +00:00
|
|
|
Client::Type aClientType)
|
2019-08-22 13:06:48 +00:00
|
|
|
: mPersistenceType(aPersistenceType),
|
2021-02-12 14:03:28 +00:00
|
|
|
mOriginMetadata(aOriginMetadata),
|
2019-08-22 13:06:48 +00:00
|
|
|
mClientType(aClientType) {}
|
2012-12-17 19:25:10 +00:00
|
|
|
|
|
|
|
// nsFileStreamBase override
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult DoOpen() override;
|
2012-12-17 19:25:10 +00:00
|
|
|
|
2013-09-11 04:18:36 +00:00
|
|
|
PersistenceType mPersistenceType;
|
2021-02-12 14:03:28 +00:00
|
|
|
OriginMetadata mOriginMetadata;
|
2019-08-22 13:06:48 +00:00
|
|
|
Client::Type mClientType;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<QuotaObject> mQuotaObject;
|
2012-12-17 19:25:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class FileStreamBase>
|
|
|
|
class FileQuotaStreamWithWrite : public FileQuotaStream<FileStreamBase> {
|
|
|
|
public:
|
|
|
|
// nsFileStreamBase override
|
|
|
|
NS_IMETHOD
|
2015-03-21 16:28:04 +00:00
|
|
|
Write(const char* aBuf, uint32_t aCount, uint32_t* _retval) override;
|
2012-12-17 19:25:10 +00:00
|
|
|
|
|
|
|
protected:
|
2013-09-11 04:18:36 +00:00
|
|
|
FileQuotaStreamWithWrite(PersistenceType aPersistenceType,
|
2021-02-12 14:03:28 +00:00
|
|
|
const OriginMetadata& aOriginMetadata,
|
2019-08-22 13:06:48 +00:00
|
|
|
Client::Type aClientType)
|
2021-02-12 14:03:28 +00:00
|
|
|
: FileQuotaStream<FileStreamBase>(aPersistenceType, aOriginMetadata,
|
2019-08-22 13:06:48 +00:00
|
|
|
aClientType) {}
|
2012-12-17 19:25:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileInputStream : public FileQuotaStream<nsFileInputStream> {
|
|
|
|
public:
|
2018-02-12 20:44:40 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(FileInputStream,
|
|
|
|
FileQuotaStream<nsFileInputStream>)
|
2012-12-17 19:25:10 +00:00
|
|
|
|
2020-10-20 11:46:31 +00:00
|
|
|
FileInputStream(PersistenceType aPersistenceType,
|
2021-02-12 14:03:28 +00:00
|
|
|
const OriginMetadata& aOriginMetadata,
|
2020-10-20 11:46:31 +00:00
|
|
|
Client::Type aClientType)
|
2021-02-12 14:03:28 +00:00
|
|
|
: FileQuotaStream<nsFileInputStream>(aPersistenceType, aOriginMetadata,
|
2019-08-22 13:06:48 +00:00
|
|
|
aClientType) {}
|
2012-12-17 19:25:10 +00:00
|
|
|
|
2018-08-20 12:32:33 +00:00
|
|
|
private:
|
2012-12-17 19:25:10 +00:00
|
|
|
virtual ~FileInputStream() { Close(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileOutputStream : public FileQuotaStreamWithWrite<nsFileOutputStream> {
|
|
|
|
public:
|
2018-02-12 20:44:40 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(
|
|
|
|
FileOutputStream, FileQuotaStreamWithWrite<nsFileOutputStream>);
|
2012-12-17 19:25:10 +00:00
|
|
|
|
2020-10-20 11:46:31 +00:00
|
|
|
FileOutputStream(PersistenceType aPersistenceType,
|
2021-02-12 14:03:28 +00:00
|
|
|
const OriginMetadata& aOriginMetadata,
|
2020-10-20 11:46:31 +00:00
|
|
|
Client::Type aClientType)
|
|
|
|
: FileQuotaStreamWithWrite<nsFileOutputStream>(
|
2021-02-12 14:03:28 +00:00
|
|
|
aPersistenceType, aOriginMetadata, aClientType) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-08-20 12:32:33 +00:00
|
|
|
private:
|
2012-12-17 19:25:10 +00:00
|
|
|
virtual ~FileOutputStream() { Close(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileStream : public FileQuotaStreamWithWrite<nsFileStream> {
|
|
|
|
public:
|
2018-02-12 20:44:40 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(FileStream,
|
|
|
|
FileQuotaStreamWithWrite<nsFileStream>)
|
2012-12-17 19:25:10 +00:00
|
|
|
|
2020-10-20 11:46:31 +00:00
|
|
|
FileStream(PersistenceType aPersistenceType,
|
2021-02-12 14:03:28 +00:00
|
|
|
const OriginMetadata& aOriginMetadata, Client::Type aClientType)
|
2020-10-20 11:46:31 +00:00
|
|
|
: FileQuotaStreamWithWrite<nsFileStream>(aPersistenceType,
|
2021-02-12 14:03:28 +00:00
|
|
|
aOriginMetadata, aClientType) {}
|
2012-12-17 19:25:10 +00:00
|
|
|
|
2018-08-20 12:32:33 +00:00
|
|
|
private:
|
2012-12-17 19:25:10 +00:00
|
|
|
virtual ~FileStream() { Close(); }
|
|
|
|
};
|
|
|
|
|
2021-01-28 11:12:19 +00:00
|
|
|
Result<NotNull<RefPtr<FileInputStream>>, nsresult> CreateFileInputStream(
|
2021-02-12 14:03:28 +00:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 11:46:31 +00:00
|
|
|
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2021-01-28 11:12:19 +00:00
|
|
|
Result<NotNull<RefPtr<FileOutputStream>>, nsresult> CreateFileOutputStream(
|
2021-02-12 14:03:28 +00:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 11:46:31 +00:00
|
|
|
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2021-01-28 11:12:19 +00:00
|
|
|
Result<NotNull<RefPtr<FileStream>>, nsresult> CreateFileStream(
|
2021-02-12 14:03:28 +00:00
|
|
|
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
|
2020-10-20 11:46:31 +00:00
|
|
|
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags = -1,
|
|
|
|
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
|
2018-08-20 12:32:33 +00:00
|
|
|
|
2020-12-15 10:26:08 +00:00
|
|
|
} // namespace mozilla::dom::quota
|
2012-12-17 19:25:10 +00:00
|
|
|
|
|
|
|
#endif /* mozilla_dom_quota_filestreams_h__ */
|