Bug 1791723 - Rename FileStream to FileRandomAccessStream; r=necko-reviewers,dom-storage-reviewers,dragana,jesup

Differential Revision: https://phabricator.services.mozilla.com/D157787
This commit is contained in:
Jan Varga 2022-10-12 01:56:16 +00:00
Родитель 71854cdf17
Коммит 4612934b65
17 изменённых файлов: 201 добавлений и 162 удалений

Просмотреть файл

@ -1166,8 +1166,8 @@ already_AddRefed<nsISupports> BackgroundMutableFileParentBase::CreateStream(
}
nsCOMPtr<nsIRandomAccessStream> stream;
rv = NS_NewLocalFileStream(getter_AddRefs(stream), mFile, -1, -1,
nsIFileStream::DEFER_OPEN);
rv = NS_NewLocalFileRandomAccessStream(getter_AddRefs(stream), mFile, -1, -1,
nsIFileRandomAccessStream::DEFER_OPEN);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}

Просмотреть файл

@ -14938,12 +14938,12 @@ already_AddRefed<nsISupports> MutableFile::CreateStream(bool aReadOnly) {
nullptr);
result = NS_ISUPPORTS_CAST(nsIFileInputStream*, stream.get());
} else {
QM_TRY_INSPECT(
const auto& stream,
CreateFileStream(persistenceType, originMetadata, Client::IDB, mFile,
-1, -1, nsIFileStream::DEFER_OPEN),
nullptr);
result = NS_ISUPPORTS_CAST(nsIFileStream*, stream.get());
QM_TRY_INSPECT(const auto& stream,
CreateFileRandomAccessStream(
persistenceType, originMetadata, Client::IDB, mFile, -1,
-1, nsIFileRandomAccessStream::DEFER_OPEN),
nullptr);
result = NS_ISUPPORTS_CAST(nsIFileRandomAccessStream*, stream.get());
}
return result.forget();

Просмотреть файл

@ -2516,7 +2516,8 @@ Result<nsCOMPtr<nsIOutputStream>, nsresult> GetOutputStream(
return nsCOMPtr<nsIOutputStream>();
}
QM_TRY_INSPECT(const auto& stream, NS_NewLocalFileStream(&aFile));
QM_TRY_INSPECT(const auto& stream,
NS_NewLocalFileRandomAccessStream(&aFile));
nsCOMPtr<nsIOutputStream> outputStream = do_QueryInterface(stream);
QM_TRY(OkIf(outputStream), Err(NS_ERROR_FAILURE));

Просмотреть файл

@ -113,11 +113,13 @@ Result<NotNull<RefPtr<FileOutputStream>>, nsresult> CreateFileOutputStream(
return stream;
}
Result<NotNull<RefPtr<FileStream>>, nsresult> CreateFileStream(
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags, int32_t aPerm,
int32_t aBehaviorFlags) {
const auto stream = MakeNotNull<RefPtr<FileStream>>(
Result<NotNull<RefPtr<FileRandomAccessStream>>, nsresult>
CreateFileRandomAccessStream(PersistenceType aPersistenceType,
const OriginMetadata& aOriginMetadata,
Client::Type aClientType, nsIFile* aFile,
int32_t aIOFlags, int32_t aPerm,
int32_t aBehaviorFlags) {
const auto stream = MakeNotNull<RefPtr<FileRandomAccessStream>>(
aPersistenceType, aOriginMetadata, aClientType);
QM_TRY(MOZ_TO_RESULT(stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags)));

Просмотреть файл

@ -103,18 +103,21 @@ class FileOutputStream : public FileQuotaStreamWithWrite<nsFileOutputStream> {
virtual ~FileOutputStream() { Close(); }
};
class FileStream : public FileQuotaStreamWithWrite<nsFileStream> {
class FileRandomAccessStream
: public FileQuotaStreamWithWrite<nsFileRandomAccessStream> {
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(FileStream,
FileQuotaStreamWithWrite<nsFileStream>)
NS_INLINE_DECL_REFCOUNTING_INHERITED(
FileRandomAccessStream,
FileQuotaStreamWithWrite<nsFileRandomAccessStream>)
FileStream(PersistenceType aPersistenceType,
const OriginMetadata& aOriginMetadata, Client::Type aClientType)
: FileQuotaStreamWithWrite<nsFileStream>(aPersistenceType,
aOriginMetadata, aClientType) {}
FileRandomAccessStream(PersistenceType aPersistenceType,
const OriginMetadata& aOriginMetadata,
Client::Type aClientType)
: FileQuotaStreamWithWrite<nsFileRandomAccessStream>(
aPersistenceType, aOriginMetadata, aClientType) {}
private:
virtual ~FileStream() { Close(); }
virtual ~FileRandomAccessStream() { Close(); }
};
Result<NotNull<RefPtr<FileInputStream>>, nsresult> CreateFileInputStream(
@ -127,10 +130,12 @@ Result<NotNull<RefPtr<FileOutputStream>>, nsresult> CreateFileOutputStream(
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags = -1,
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
Result<NotNull<RefPtr<FileStream>>, nsresult> CreateFileStream(
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
Client::Type aClientType, nsIFile* aFile, int32_t aIOFlags = -1,
int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
Result<NotNull<RefPtr<FileRandomAccessStream>>, nsresult>
CreateFileRandomAccessStream(PersistenceType aPersistenceType,
const OriginMetadata& aOriginMetadata,
Client::Type aClientType, nsIFile* aFile,
int32_t aIOFlags = -1, int32_t aPerm = -1,
int32_t aBehaviorFlags = 0);
} // namespace mozilla::dom::quota

Просмотреть файл

@ -24,25 +24,27 @@ async function testSteps() {
let metadataFile = originDir.clone();
metadataFile.append(".metadata-v2");
let fileStream = Cc["@mozilla.org/network/file-stream;1"].createInstance(
Ci.nsIFileStream
);
fileStream.init(metadataFile, -1, -1, 0);
let fileRandomAccessStream = Cc[
"@mozilla.org/network/file-random-access-stream;1"
].createInstance(Ci.nsIFileRandomAccessStream);
fileRandomAccessStream.init(metadataFile, -1, -1, 0);
let binaryInputStream = Cc[
"@mozilla.org/binaryinputstream;1"
].createInstance(Ci.nsIBinaryInputStream);
binaryInputStream.setInputStream(fileStream);
binaryInputStream.setInputStream(fileRandomAccessStream);
let lastAccessTime = binaryInputStream.read64();
let seekableStream = fileStream.QueryInterface(Ci.nsISeekableStream);
let seekableStream = fileRandomAccessStream.QueryInterface(
Ci.nsISeekableStream
);
seekableStream.seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
binaryOutputStream = Cc["@mozilla.org/binaryoutputstream;1"].createInstance(
Ci.nsIBinaryOutputStream
);
binaryOutputStream.setOutputStream(fileStream);
binaryOutputStream.setOutputStream(fileRandomAccessStream);
binaryOutputStream.write64(lastAccessTime + deltaSec * PR_USEC_PER_SEC);

Просмотреть файл

@ -92,11 +92,12 @@ constexpr auto kSDBSuffix = u".sdb"_ns;
class StreamHelper final : public Runnable {
nsCOMPtr<nsIEventTarget> mOwningEventTarget;
nsCOMPtr<nsIFileStream> mFileStream;
nsCOMPtr<nsIFileRandomAccessStream> mFileRandomAccessStream;
nsCOMPtr<nsIRunnable> mCallback;
public:
StreamHelper(nsIFileStream* aFileStream, nsIRunnable* aCallback);
StreamHelper(nsIFileRandomAccessStream* aFileRandomAccessStream,
nsIRunnable* aCallback);
void AsyncClose();
@ -112,7 +113,7 @@ class StreamHelper final : public Runnable {
class Connection final : public PBackgroundSDBConnectionParent {
RefPtr<DirectoryLock> mDirectoryLock;
nsCOMPtr<nsIFileStream> mFileStream;
nsCOMPtr<nsIFileRandomAccessStream> mFileRandomAccessStream;
const PrincipalInfo mPrincipalInfo;
nsCString mOrigin;
nsString mName;
@ -135,10 +136,10 @@ class Connection final : public PBackgroundSDBConnectionParent {
return ToMaybeRef(mDirectoryLock.get());
}
nsIFileStream* GetFileStream() const {
nsIFileRandomAccessStream* GetFileRandomAccessStream() const {
AssertIsOnIOThread();
return mFileStream;
return mFileRandomAccessStream;
}
PersistenceType GetPersistenceType() const { return mPersistenceType; }
@ -167,9 +168,10 @@ class Connection final : public PBackgroundSDBConnectionParent {
void OnRequestFinished();
void OnOpen(const nsACString& aOrigin, const nsAString& aName,
already_AddRefed<DirectoryLock> aDirectoryLock,
already_AddRefed<nsIFileStream> aFileStream);
void OnOpen(
const nsACString& aOrigin, const nsAString& aName,
already_AddRefed<DirectoryLock> aDirectoryLock,
already_AddRefed<nsIFileRandomAccessStream> aFileRandomAccessStream);
void OnClose();
@ -283,7 +285,8 @@ class ConnectionOperationBase : public Runnable,
void DatabaseWork();
// Methods that subclasses must implement.
virtual nsresult DoDatabaseWork(nsIFileStream* aFileStream) = 0;
virtual nsresult DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) = 0;
// Subclasses use this override to set the IPDL response value.
virtual void GetResponse(SDBRequestResponse& aResponse) = 0;
@ -330,11 +333,11 @@ class OpenOp final : public ConnectionOperationBase,
const SDBRequestOpenParams mParams;
RefPtr<DirectoryLock> mDirectoryLock;
nsCOMPtr<nsIFileStream> mFileStream;
nsCOMPtr<nsIFileRandomAccessStream> mFileRandomAccessStream;
// XXX Consider changing this to ClientMetadata.
quota::OriginMetadata mOriginMetadata;
State mState;
bool mFileStreamOpen;
bool mFileRandomAccessStreamOpen;
public:
OpenOp(Connection* aConnection, const SDBRequestParams& aParams);
@ -355,7 +358,8 @@ class OpenOp final : public ConnectionOperationBase,
void StreamClosedCallback();
// ConnectionOperationBase overrides
nsresult DoDatabaseWork(nsIFileStream* aFileStream) override;
nsresult DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) override;
void GetResponse(SDBRequestResponse& aResponse) override;
@ -383,7 +387,8 @@ class SeekOp final : public ConnectionOperationBase {
private:
~SeekOp() override = default;
nsresult DoDatabaseWork(nsIFileStream* aFileStream) override;
nsresult DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) override;
void GetResponse(SDBRequestResponse& aResponse) override;
};
@ -401,7 +406,8 @@ class ReadOp final : public ConnectionOperationBase {
private:
~ReadOp() override = default;
nsresult DoDatabaseWork(nsIFileStream* aFileStream) override;
nsresult DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) override;
void GetResponse(SDBRequestResponse& aResponse) override;
};
@ -421,7 +427,8 @@ class WriteOp final : public ConnectionOperationBase {
private:
~WriteOp() override = default;
nsresult DoDatabaseWork(nsIFileStream* aFileStream) override;
nsresult DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) override;
void GetResponse(SDBRequestResponse& aResponse) override;
};
@ -433,7 +440,8 @@ class CloseOp final : public ConnectionOperationBase {
private:
~CloseOp() override = default;
nsresult DoDatabaseWork(nsIFileStream* aFileStream) override;
nsresult DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) override;
void GetResponse(SDBRequestResponse& aResponse) override;
@ -583,18 +591,19 @@ already_AddRefed<mozilla::dom::quota::Client> CreateQuotaClient() {
* StreamHelper
******************************************************************************/
StreamHelper::StreamHelper(nsIFileStream* aFileStream, nsIRunnable* aCallback)
StreamHelper::StreamHelper(nsIFileRandomAccessStream* aFileRandomAccessStream,
nsIRunnable* aCallback)
: Runnable("dom::StreamHelper"),
mOwningEventTarget(GetCurrentEventTarget()),
mFileStream(aFileStream),
mFileRandomAccessStream(aFileRandomAccessStream),
mCallback(aCallback) {
AssertIsOnBackgroundThread();
MOZ_ASSERT(aFileStream);
MOZ_ASSERT(aFileRandomAccessStream);
MOZ_ASSERT(aCallback);
}
StreamHelper::~StreamHelper() {
MOZ_ASSERT(!mFileStream);
MOZ_ASSERT(!mFileRandomAccessStream);
MOZ_ASSERT(!mCallback);
}
@ -611,8 +620,8 @@ void StreamHelper::AsyncClose() {
void StreamHelper::RunOnBackgroundThread() {
AssertIsOnBackgroundThread();
nsCOMPtr<nsIFileStream> fileStream;
mFileStream.swap(fileStream);
nsCOMPtr<nsIFileRandomAccessStream> fileRandomAccessStream;
mFileRandomAccessStream.swap(fileRandomAccessStream);
nsCOMPtr<nsIRunnable> callback;
mCallback.swap(callback);
@ -622,9 +631,10 @@ void StreamHelper::RunOnBackgroundThread() {
void StreamHelper::RunOnIOThread() {
AssertIsOnIOThread();
MOZ_ASSERT(mFileStream);
MOZ_ASSERT(mFileRandomAccessStream);
nsCOMPtr<nsIInputStream> inputStream = do_QueryInterface(mFileStream);
nsCOMPtr<nsIInputStream> inputStream =
do_QueryInterface(mFileRandomAccessStream);
MOZ_ASSERT(inputStream);
nsresult rv = inputStream->Close();
@ -684,22 +694,23 @@ void Connection::OnRequestFinished() {
MaybeCloseStream();
}
void Connection::OnOpen(const nsACString& aOrigin, const nsAString& aName,
already_AddRefed<DirectoryLock> aDirectoryLock,
already_AddRefed<nsIFileStream> aFileStream) {
void Connection::OnOpen(
const nsACString& aOrigin, const nsAString& aName,
already_AddRefed<DirectoryLock> aDirectoryLock,
already_AddRefed<nsIFileRandomAccessStream> aFileRandomAccessStream) {
AssertIsOnBackgroundThread();
MOZ_ASSERT(!aOrigin.IsEmpty());
MOZ_ASSERT(!aName.IsEmpty());
MOZ_ASSERT(mOrigin.IsEmpty());
MOZ_ASSERT(mName.IsEmpty());
MOZ_ASSERT(!mDirectoryLock);
MOZ_ASSERT(!mFileStream);
MOZ_ASSERT(!mFileRandomAccessStream);
MOZ_ASSERT(!mOpen);
mOrigin = aOrigin;
mName = aName;
mDirectoryLock = aDirectoryLock;
mFileStream = aFileStream;
mFileRandomAccessStream = aFileRandomAccessStream;
mOpen = true;
if (!gOpenConnections) {
@ -713,13 +724,13 @@ void Connection::OnClose() {
AssertIsOnBackgroundThread();
MOZ_ASSERT(!mOrigin.IsEmpty());
MOZ_ASSERT(mDirectoryLock);
MOZ_ASSERT(mFileStream);
MOZ_ASSERT(mFileRandomAccessStream);
MOZ_ASSERT(mOpen);
mOrigin.Truncate();
mName.Truncate();
mDirectoryLock = nullptr;
mFileStream = nullptr;
mFileRandomAccessStream = nullptr;
mOpen = false;
MOZ_ASSERT(gOpenConnections);
@ -757,7 +768,8 @@ void Connection::MaybeCloseStream() {
nsCOMPtr<nsIRunnable> callback = NewRunnableMethod(
"dom::Connection::OnClose", this, &Connection::OnClose);
RefPtr<StreamHelper> helper = new StreamHelper(mFileStream, callback);
RefPtr<StreamHelper> helper =
new StreamHelper(mFileRandomAccessStream, callback);
helper->AsyncClose();
}
}
@ -999,10 +1011,11 @@ void ConnectionOperationBase::DatabaseWork() {
// has crashed.
mResultCode = NS_ERROR_ABORT;
} else {
nsIFileStream* fileStream = mConnection->GetFileStream();
MOZ_ASSERT(fileStream);
nsIFileRandomAccessStream* fileRandomAccessStream =
mConnection->GetFileRandomAccessStream();
MOZ_ASSERT(fileRandomAccessStream);
nsresult rv = DoDatabaseWork(fileStream);
nsresult rv = DoDatabaseWork(fileRandomAccessStream);
if (NS_FAILED(rv)) {
mResultCode = rv;
}
@ -1035,14 +1048,14 @@ OpenOp::OpenOp(Connection* aConnection, const SDBRequestParams& aParams)
: ConnectionOperationBase(aConnection),
mParams(aParams.get_SDBRequestOpenParams()),
mState(State::Initial),
mFileStreamOpen(false) {
mFileRandomAccessStreamOpen(false) {
MOZ_ASSERT(aParams.type() == SDBRequestParams::TSDBRequestOpenParams);
}
OpenOp::~OpenOp() {
MOZ_ASSERT(!mDirectoryLock);
MOZ_ASSERT(!mFileStream);
MOZ_ASSERT(!mFileStreamOpen);
MOZ_ASSERT(!mFileRandomAccessStream);
MOZ_ASSERT(!mFileRandomAccessStreamOpen);
MOZ_ASSERT_IF(OperationMayProceed(),
mState == State::Initial || mState == State::Completed);
}
@ -1136,9 +1149,9 @@ nsresult OpenOp::SendToIOThread() {
return NS_ERROR_ABORT;
}
mFileStream =
new FileStream(GetConnection()->GetPersistenceType(), mOriginMetadata,
mozilla::dom::quota::Client::SDB);
mFileRandomAccessStream = new FileRandomAccessStream(
GetConnection()->GetPersistenceType(), mOriginMetadata,
mozilla::dom::quota::Client::SDB);
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
@ -1157,8 +1170,8 @@ nsresult OpenOp::SendToIOThread() {
nsresult OpenOp::DatabaseWork() {
AssertIsOnIOThread();
MOZ_ASSERT(mState == State::DatabaseWorkOpen);
MOZ_ASSERT(mFileStream);
MOZ_ASSERT(!mFileStreamOpen);
MOZ_ASSERT(mFileRandomAccessStream);
MOZ_ASSERT(!mFileRandomAccessStreamOpen);
if (NS_WARN_IF(QuotaClient::IsShuttingDownOnNonBackgroundThread()) ||
!OperationMayProceed()) {
@ -1230,14 +1243,14 @@ nsresult OpenOp::DatabaseWork() {
return rv;
}
rv = mFileStream->Init(dbFile, PR_RDWR | PR_CREATE_FILE, 0644, 0);
rv = mFileRandomAccessStream->Init(dbFile, PR_RDWR | PR_CREATE_FILE, 0644, 0);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mFileStreamOpen = true;
mFileRandomAccessStreamOpen = true;
rv = DoDatabaseWork(mFileStream);
rv = DoDatabaseWork(mFileRandomAccessStream);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1258,15 +1271,16 @@ void OpenOp::StreamClosedCallback() {
AssertIsOnOwningThread();
MOZ_ASSERT(NS_FAILED(ResultCode()));
MOZ_ASSERT(mDirectoryLock);
MOZ_ASSERT(mFileStream);
MOZ_ASSERT(mFileStreamOpen);
MOZ_ASSERT(mFileRandomAccessStream);
MOZ_ASSERT(mFileRandomAccessStreamOpen);
mDirectoryLock = nullptr;
mFileStream = nullptr;
mFileStreamOpen = false;
mFileRandomAccessStream = nullptr;
mFileRandomAccessStreamOpen = false;
}
nsresult OpenOp::DoDatabaseWork(nsIFileStream* aFileStream) {
nsresult OpenOp::DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) {
AssertIsOnIOThread();
return NS_OK;
@ -1283,25 +1297,26 @@ void OpenOp::OnSuccess() {
MOZ_ASSERT(NS_SUCCEEDED(ResultCode()));
MOZ_ASSERT(!mOriginMetadata.mOrigin.IsEmpty());
MOZ_ASSERT(mDirectoryLock);
MOZ_ASSERT(mFileStream);
MOZ_ASSERT(mFileStreamOpen);
MOZ_ASSERT(mFileRandomAccessStream);
MOZ_ASSERT(mFileRandomAccessStreamOpen);
RefPtr<DirectoryLock> directoryLock;
nsCOMPtr<nsIFileStream> fileStream;
nsCOMPtr<nsIFileRandomAccessStream> fileRandomAccessStream;
mDirectoryLock.swap(directoryLock);
mFileStream.swap(fileStream);
mFileStreamOpen = false;
mFileRandomAccessStream.swap(fileRandomAccessStream);
mFileRandomAccessStreamOpen = false;
GetConnection()->OnOpen(mOriginMetadata.mOrigin, mParams.name(),
directoryLock.forget(), fileStream.forget());
directoryLock.forget(),
fileRandomAccessStream.forget());
}
void OpenOp::Cleanup() {
AssertIsOnOwningThread();
MOZ_ASSERT_IF(mFileStreamOpen, mFileStream);
MOZ_ASSERT_IF(mFileRandomAccessStreamOpen, mFileRandomAccessStream);
if (mFileStream && mFileStreamOpen) {
if (mFileRandomAccessStream && mFileRandomAccessStreamOpen) {
// If we have an initialized file stream then the operation must have failed
// and there must be a directory lock too.
MOZ_ASSERT(NS_FAILED(ResultCode()));
@ -1313,13 +1328,14 @@ void OpenOp::Cleanup() {
NewRunnableMethod("dom::OpenOp::StreamClosedCallback", this,
&OpenOp::StreamClosedCallback);
RefPtr<StreamHelper> helper = new StreamHelper(mFileStream, callback);
RefPtr<StreamHelper> helper =
new StreamHelper(mFileRandomAccessStream, callback);
helper->AsyncClose();
} else {
MOZ_ASSERT(!mFileStreamOpen);
MOZ_ASSERT(!mFileRandomAccessStreamOpen);
mDirectoryLock = nullptr;
mFileStream = nullptr;
mFileRandomAccessStream = nullptr;
}
ConnectionOperationBase::Cleanup();
@ -1411,12 +1427,13 @@ SeekOp::SeekOp(Connection* aConnection, const SDBRequestParams& aParams)
MOZ_ASSERT(aParams.type() == SDBRequestParams::TSDBRequestSeekParams);
}
nsresult SeekOp::DoDatabaseWork(nsIFileStream* aFileStream) {
nsresult SeekOp::DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) {
AssertIsOnIOThread();
MOZ_ASSERT(aFileStream);
MOZ_ASSERT(aFileRandomAccessStream);
nsresult rv =
aFileStream->Seek(nsISeekableStream::NS_SEEK_SET, mParams.offset());
nsresult rv = aFileRandomAccessStream->Seek(nsISeekableStream::NS_SEEK_SET,
mParams.offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -1450,11 +1467,13 @@ bool ReadOp::Init() {
return true;
}
nsresult ReadOp::DoDatabaseWork(nsIFileStream* aFileStream) {
nsresult ReadOp::DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) {
AssertIsOnIOThread();
MOZ_ASSERT(aFileStream);
MOZ_ASSERT(aFileRandomAccessStream);
nsCOMPtr<nsIInputStream> inputStream = do_QueryInterface(aFileStream);
nsCOMPtr<nsIInputStream> inputStream =
do_QueryInterface(aFileRandomAccessStream);
MOZ_ASSERT(inputStream);
nsresult rv;
@ -1536,11 +1555,13 @@ bool WriteOp::Init() {
return true;
}
nsresult WriteOp::DoDatabaseWork(nsIFileStream* aFileStream) {
nsresult WriteOp::DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) {
AssertIsOnIOThread();
MOZ_ASSERT(aFileStream);
MOZ_ASSERT(aFileRandomAccessStream);
nsCOMPtr<nsIOutputStream> outputStream = do_QueryInterface(aFileStream);
nsCOMPtr<nsIOutputStream> outputStream =
do_QueryInterface(aFileRandomAccessStream);
MOZ_ASSERT(outputStream);
nsresult rv;
@ -1581,11 +1602,13 @@ void WriteOp::GetResponse(SDBRequestResponse& aResponse) {
CloseOp::CloseOp(Connection* aConnection)
: ConnectionOperationBase(aConnection) {}
nsresult CloseOp::DoDatabaseWork(nsIFileStream* aFileStream) {
nsresult CloseOp::DoDatabaseWork(
nsIFileRandomAccessStream* aFileRandomAccessStream) {
AssertIsOnIOThread();
MOZ_ASSERT(aFileStream);
MOZ_ASSERT(aFileRandomAccessStream);
nsCOMPtr<nsIInputStream> inputStream = do_QueryInterface(aFileStream);
nsCOMPtr<nsIInputStream> inputStream =
do_QueryInterface(aFileRandomAccessStream);
MOZ_ASSERT(inputStream);
nsresult rv = inputStream->Close();

Просмотреть файл

@ -402,7 +402,7 @@ RefPtr<SyncReadFile> IOUtils::OpenFileForSyncReading(GlobalObject& aGlobal,
return nullptr;
}
RefPtr<nsFileStream> stream = new nsFileStream();
RefPtr<nsFileRandomAccessStream> stream = new nsFileRandomAccessStream();
if (nsresult rv =
stream->Init(file, PR_RDONLY | nsIFile::OS_READAHEAD, 0666, 0);
NS_FAILED(rv)) {
@ -1084,7 +1084,7 @@ Result<IOUtils::JsBuffer, IOUtils::IOError> IOUtils::ReadSync(
const int64_t offset = static_cast<int64_t>(aOffset);
RefPtr<nsFileStream> stream = new nsFileStream();
RefPtr<nsFileRandomAccessStream> stream = new nsFileRandomAccessStream();
if (nsresult rv =
stream->Init(aFile, PR_RDONLY | nsIFile::OS_READAHEAD, 0666, 0);
NS_FAILED(rv)) {
@ -1303,8 +1303,8 @@ Result<uint32_t, IOUtils::IOError> IOUtils::WriteSync(
writeFile->HumanReadablePath().get()));
}
// nsFileStream::Write uses PR_Write under the hood, which accepts a
// *int32_t* for the chunk size.
// nsFileRandomAccessStream::Write uses PR_Write under the hood, which
// accepts a *int32_t* for the chunk size.
uint32_t chunkSize = INT32_MAX;
Span<const char> pendingBytes = bytes;
@ -2651,7 +2651,8 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SyncReadFile, mParent)
SyncReadFile::SyncReadFile(nsISupports* aParent, RefPtr<nsFileStream>&& aStream,
SyncReadFile::SyncReadFile(nsISupports* aParent,
RefPtr<nsFileRandomAccessStream>&& aStream,
int64_t aSize)
: mParent(aParent), mStream(std::move(aStream)), mSize(aSize) {
MOZ_RELEASE_ASSERT(mSize >= 0);

Просмотреть файл

@ -27,7 +27,7 @@
#include "nsTArray.h"
#include "prio.h"
class nsFileStream;
class nsFileRandomAccessStream;
namespace mozilla {
@ -861,7 +861,7 @@ class IOUtils::JsBuffer final {
class SyncReadFile : public nsISupports, public nsWrapperCache {
public:
SyncReadFile(nsISupports* aParent, RefPtr<nsFileStream>&& aStream,
SyncReadFile(nsISupports* aParent, RefPtr<nsFileRandomAccessStream>&& aStream,
int64_t aSize);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@ -880,7 +880,7 @@ class SyncReadFile : public nsISupports, public nsWrapperCache {
virtual ~SyncReadFile();
nsCOMPtr<nsISupports> mParent;
RefPtr<nsFileStream> mStream;
RefPtr<nsFileRandomAccessStream> mStream;
int64_t mSize = 0;
};

Просмотреть файл

@ -869,19 +869,19 @@ nsSafeFileOutputStream::Finish() {
}
////////////////////////////////////////////////////////////////////////////////
// nsFileStream
// nsFileRandomAccessStream
nsresult nsFileStream::Create(REFNSIID aIID, void** aResult) {
RefPtr<nsFileStream> stream = new nsFileStream();
nsresult nsFileRandomAccessStream::Create(REFNSIID aIID, void** aResult) {
RefPtr<nsFileRandomAccessStream> stream = new nsFileRandomAccessStream();
return stream->QueryInterface(aIID, aResult);
}
NS_IMPL_ISUPPORTS_INHERITED(nsFileStream, nsFileStreamBase,
nsIRandomAccessStream, nsIFileStream,
NS_IMPL_ISUPPORTS_INHERITED(nsFileRandomAccessStream, nsFileStreamBase,
nsIRandomAccessStream, nsIFileRandomAccessStream,
nsIInputStream, nsIOutputStream)
NS_IMETHODIMP
nsFileStream::GetInputStream(nsIInputStream** aInputStream) {
nsFileRandomAccessStream::GetInputStream(nsIInputStream** aInputStream) {
nsCOMPtr<nsIInputStream> inputStream(this);
inputStream.forget(aInputStream);
@ -889,20 +889,20 @@ nsFileStream::GetInputStream(nsIInputStream** aInputStream) {
}
NS_IMETHODIMP
nsFileStream::GetOutputStream(nsIOutputStream** aOutputStream) {
nsFileRandomAccessStream::GetOutputStream(nsIOutputStream** aOutputStream) {
nsCOMPtr<nsIOutputStream> outputStream(this);
outputStream.forget(aOutputStream);
return NS_OK;
}
nsIInputStream* nsFileStream::InputStream() { return this; }
nsIInputStream* nsFileRandomAccessStream::InputStream() { return this; }
nsIOutputStream* nsFileStream::OutputStream() { return this; }
nsIOutputStream* nsFileRandomAccessStream::OutputStream() { return this; }
NS_IMETHODIMP
nsFileStream::Init(nsIFile* file, int32_t ioFlags, int32_t perm,
int32_t behaviorFlags) {
nsFileRandomAccessStream::Init(nsIFile* file, int32_t ioFlags, int32_t perm,
int32_t behaviorFlags) {
NS_ENSURE_TRUE(mFD == nullptr, NS_ERROR_ALREADY_INITIALIZED);
NS_ENSURE_TRUE(mState == eUnitialized || mState == eClosed,
NS_ERROR_ALREADY_INITIALIZED);
@ -914,7 +914,7 @@ nsFileStream::Init(nsIFile* file, int32_t ioFlags, int32_t perm,
if (perm <= 0) perm = 0;
return MaybeOpen(file, ioFlags, perm,
mBehaviorFlags & nsIFileStream::DEFER_OPEN);
mBehaviorFlags & nsIFileRandomAccessStream::DEFER_OPEN);
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -251,10 +251,10 @@ class nsSafeFileOutputStream : public nsAtomicFileOutputStream {
////////////////////////////////////////////////////////////////////////////////
class nsFileStream : public nsFileStreamBase,
public nsIFileStream,
public nsIInputStream,
public nsIOutputStream {
class nsFileRandomAccessStream : public nsFileStreamBase,
public nsIFileRandomAccessStream,
public nsIInputStream,
public nsIOutputStream {
public:
static nsresult Create(REFNSIID aIID, void** aResult);
@ -262,7 +262,7 @@ class nsFileStream : public nsFileStreamBase,
NS_FORWARD_NSITELLABLESTREAM(nsFileStreamBase::)
NS_FORWARD_NSISEEKABLESTREAM(nsFileStreamBase::)
NS_DECL_NSIRANDOMACCESSSTREAM
NS_DECL_NSIFILESTREAM
NS_DECL_NSIFILERANDOMACCESSSTREAM
NS_FORWARD_NSIINPUTSTREAM(nsFileStreamBase::)
// Can't use NS_FORWARD_NSIOUTPUTSTREAM due to overlapping methods
@ -282,7 +282,7 @@ class nsFileStream : public nsFileStreamBase,
}
protected:
virtual ~nsFileStream() = default;
virtual ~nsFileRandomAccessStream() = default;
};
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -134,7 +134,7 @@ interface nsIFileOutputStream : nsIOutputStream
* A stream that allows you to read from a file or stream to a file.
*/
[scriptable, builtinclass, uuid(82cf605a-8393-4550-83ab-43cd5578e006)]
interface nsIFileStream : nsIRandomAccessStream
interface nsIFileRandomAccessStream : nsIRandomAccessStream
{
/**
* @param file file to read from or stream to

Просмотреть файл

@ -1300,11 +1300,12 @@ nsresult NS_NewSafeLocalFileOutputStream(nsIOutputStream** result,
return rv;
}
nsresult NS_NewLocalFileStream(nsIRandomAccessStream** result, nsIFile* file,
int32_t ioFlags /* = -1 */,
int32_t perm /* = -1 */,
int32_t behaviorFlags /* = 0 */) {
nsCOMPtr<nsIFileStream> stream = new nsFileStream();
nsresult NS_NewLocalFileRandomAccessStream(nsIRandomAccessStream** result,
nsIFile* file,
int32_t ioFlags /* = -1 */,
int32_t perm /* = -1 */,
int32_t behaviorFlags /* = 0 */) {
nsCOMPtr<nsIFileRandomAccessStream> stream = new nsFileRandomAccessStream();
nsresult rv = stream->Init(file, ioFlags, perm, behaviorFlags);
if (NS_SUCCEEDED(rv)) {
stream.forget(result);
@ -1313,12 +1314,12 @@ nsresult NS_NewLocalFileStream(nsIRandomAccessStream** result, nsIFile* file,
}
mozilla::Result<nsCOMPtr<nsIRandomAccessStream>, nsresult>
NS_NewLocalFileStream(nsIFile* file, int32_t ioFlags /* = -1 */,
int32_t perm /* = -1 */,
int32_t behaviorFlags /* = 0 */) {
NS_NewLocalFileRandomAccessStream(nsIFile* file, int32_t ioFlags /* = -1 */,
int32_t perm /* = -1 */,
int32_t behaviorFlags /* = 0 */) {
nsCOMPtr<nsIRandomAccessStream> stream;
const nsresult rv = NS_NewLocalFileStream(getter_AddRefs(stream), file,
ioFlags, perm, behaviorFlags);
const nsresult rv = NS_NewLocalFileRandomAccessStream(
getter_AddRefs(stream), file, ioFlags, perm, behaviorFlags);
if (NS_SUCCEEDED(rv)) {
return stream;
}

Просмотреть файл

@ -40,7 +40,7 @@ class nsICookieJarSettings;
class nsIDownloadObserver;
class nsIEventTarget;
class nsIFileProtocolHandler;
class nsIFileStream;
class nsIFileRandomAccessStream;
class nsIHttpChannel;
class nsIInputStream;
class nsIInputStreamPump;
@ -514,13 +514,14 @@ nsresult NS_NewSafeLocalFileOutputStream(nsIOutputStream** result,
int32_t perm = -1,
int32_t behaviorFlags = 0);
nsresult NS_NewLocalFileStream(nsIRandomAccessStream** result, nsIFile* file,
int32_t ioFlags = -1, int32_t perm = -1,
int32_t behaviorFlags = 0);
nsresult NS_NewLocalFileRandomAccessStream(nsIRandomAccessStream** result,
nsIFile* file, int32_t ioFlags = -1,
int32_t perm = -1,
int32_t behaviorFlags = 0);
mozilla::Result<nsCOMPtr<nsIRandomAccessStream>, nsresult>
NS_NewLocalFileStream(nsIFile* file, int32_t ioFlags = -1, int32_t perm = -1,
int32_t behaviorFlags = 0);
NS_NewLocalFileRandomAccessStream(nsIFile* file, int32_t ioFlags = -1,
int32_t perm = -1, int32_t behaviorFlags = 0);
[[nodiscard]] nsresult NS_NewBufferedInputStream(
nsIInputStream** aResult, already_AddRefed<nsIInputStream> aInputStream,

Просмотреть файл

@ -161,8 +161,8 @@ Classes = [
},
{
'cid': '{648705e9-757a-4d4b-a5bF-0248e512c309}',
'contract_ids': ['@mozilla.org/network/file-stream;1'],
'legacy_constructor': 'nsFileStream::Create',
'contract_ids': ['@mozilla.org/network/file-random-access-stream;1'],
'legacy_constructor': 'nsFileRandomAccessStream::Create',
'headers': ['nsFileStreams.h'],
},
{

Просмотреть файл

@ -342,8 +342,9 @@
} \
}
#define NS_LOCALFILESTREAM_CONTRACTID "@mozilla.org/network/file-stream;1"
#define NS_LOCALFILESTREAM_CID \
#define NS_LOCALFILERANDOMACCESSSTREAM_CONTRACTID \
"@mozilla.org/network/file-random-access-stream;1"
#define NS_LOCALFILERANDOMACCESSSTREAM_CID \
{ /* 648705e9-757a-4d4b-a5bF-0248e512c309 */ \
0x648705e9, 0x757a, 0x4d4b, { \
0xa5, 0xbF, 0x02, 0x48, 0xe5, 0x12, 0xc3, 0x09 \

Просмотреть файл

@ -1952,14 +1952,15 @@ void WriteFailedProfileLock(nsIFile* aProfileDir) {
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) {
return;
}
nsCOMPtr<nsIRandomAccessStream> fileStream;
rv = NS_NewLocalFileStream(getter_AddRefs(fileStream), file,
PR_RDWR | PR_CREATE_FILE, 0640);
nsCOMPtr<nsIRandomAccessStream> fileRandomAccessStream;
rv = NS_NewLocalFileRandomAccessStream(getter_AddRefs(fileRandomAccessStream),
file, PR_RDWR | PR_CREATE_FILE, 0640);
NS_ENSURE_SUCCESS_VOID(rv);
NS_ENSURE_TRUE_VOID(fileSize <= kMaxFailedProfileLockFileSize);
unsigned int failedLockCount = 0;
if (fileSize > 0) {
nsCOMPtr<nsIInputStream> inStream = do_QueryInterface(fileStream);
nsCOMPtr<nsIInputStream> inStream =
do_QueryInterface(fileRandomAccessStream);
NS_ENSURE_TRUE_VOID(inStream);
if (!GetFailedLockCount(inStream, fileSize, failedLockCount)) {
failedLockCount = 0;
@ -1970,10 +1971,11 @@ void WriteFailedProfileLock(nsIFile* aProfileDir) {
bufStr.AppendInt(static_cast<int>(failedLockCount));
// If we read in an existing failed lock count, we need to reset the file ptr
if (fileSize > 0) {
rv = fileStream->Seek(nsISeekableStream::NS_SEEK_SET, 0);
rv = fileRandomAccessStream->Seek(nsISeekableStream::NS_SEEK_SET, 0);
NS_ENSURE_SUCCESS_VOID(rv);
}
nsCOMPtr<nsIOutputStream> outStream = do_QueryInterface(fileStream);
nsCOMPtr<nsIOutputStream> outStream =
do_QueryInterface(fileRandomAccessStream);
uint32_t bytesLeft = bufStr.Length();
const char* bytes = bufStr.get();
do {
@ -1985,7 +1987,7 @@ void WriteFailedProfileLock(nsIFile* aProfileDir) {
bytes += written;
bytesLeft -= written;
} while (bytesLeft > 0);
fileStream->SetEOF();
fileRandomAccessStream->SetEOF();
}
void InitIOReporting(nsIFile* aXreDir) {