зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1791721 - Create a dedicated interface for read write (input output) streams; r=xpcom-reviewers,necko-reviewers,nika,valentin
Differential Revision: https://phabricator.services.mozilla.com/D157786
This commit is contained in:
Родитель
1245ef6f0b
Коммит
a82e48e896
|
@ -1165,7 +1165,7 @@ already_AddRefed<nsISupports> BackgroundMutableFileParentBase::CreateStream(
|
|||
return stream.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFileStream> stream;
|
||||
nsCOMPtr<nsIRandomAccessStream> stream;
|
||||
rv = NS_NewLocalFileStream(getter_AddRefs(stream), mFile, -1, -1,
|
||||
nsIFileStream::DEFER_OPEN);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
|
|
@ -1415,11 +1415,8 @@ nsresult SeekOp::DoDatabaseWork(nsIFileStream* aFileStream) {
|
|||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aFileStream);
|
||||
|
||||
nsCOMPtr<nsISeekableStream> seekableStream = do_QueryInterface(aFileStream);
|
||||
MOZ_ASSERT(seekableStream);
|
||||
|
||||
nsresult rv =
|
||||
seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, mParams.offset());
|
||||
aFileStream->Seek(nsISeekableStream::NS_SEEK_SET, mParams.offset());
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
|
|
|
@ -876,8 +876,29 @@ nsresult nsFileStream::Create(REFNSIID aIID, void** aResult) {
|
|||
return stream->QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsFileStream, nsFileStreamBase, nsIInputStream,
|
||||
nsIOutputStream, nsIFileStream)
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsFileStream, nsFileStreamBase,
|
||||
nsIRandomAccessStream, nsIFileStream,
|
||||
nsIInputStream, nsIOutputStream)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileStream::GetInputStream(nsIInputStream** aInputStream) {
|
||||
nsCOMPtr<nsIInputStream> inputStream(this);
|
||||
|
||||
inputStream.forget(aInputStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileStream::GetOutputStream(nsIOutputStream** aOutputStream) {
|
||||
nsCOMPtr<nsIOutputStream> outputStream(this);
|
||||
|
||||
outputStream.forget(aOutputStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIInputStream* nsFileStream::InputStream() { return this; }
|
||||
|
||||
nsIOutputStream* nsFileStream::OutputStream() { return this; }
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileStream::Init(nsIFile* file, int32_t ioFlags, int32_t perm,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "nsICloneableInputStream.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIRandomAccessStream.h"
|
||||
#include "nsISafeOutputStream.h"
|
||||
#include "nsISeekableStream.h"
|
||||
#include "nsILineInputStream.h"
|
||||
|
@ -251,13 +252,16 @@ class nsSafeFileOutputStream : public nsAtomicFileOutputStream {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsFileStream : public nsFileStreamBase,
|
||||
public nsIFileStream,
|
||||
public nsIInputStream,
|
||||
public nsIOutputStream,
|
||||
public nsIFileStream {
|
||||
public nsIOutputStream {
|
||||
public:
|
||||
static nsresult Create(REFNSIID aIID, void** aResult);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_FORWARD_NSITELLABLESTREAM(nsFileStreamBase::)
|
||||
NS_FORWARD_NSISEEKABLESTREAM(nsFileStreamBase::)
|
||||
NS_DECL_NSIRANDOMACCESSSTREAM
|
||||
NS_DECL_NSIFILESTREAM
|
||||
NS_FORWARD_NSIINPUTSTREAM(nsFileStreamBase::)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "nsIInputStream.idl"
|
||||
#include "nsIOutputStream.idl"
|
||||
#include "nsIRandomAccessStream.idl"
|
||||
|
||||
interface nsIEventTarget;
|
||||
interface nsIFile;
|
||||
|
@ -133,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 : nsISupports
|
||||
interface nsIFileStream : nsIRandomAccessStream
|
||||
{
|
||||
/**
|
||||
* @param file file to read from or stream to
|
||||
|
|
|
@ -1300,7 +1300,7 @@ nsresult NS_NewSafeLocalFileOutputStream(nsIOutputStream** result,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult NS_NewLocalFileStream(nsIFileStream** result, nsIFile* file,
|
||||
nsresult NS_NewLocalFileStream(nsIRandomAccessStream** result, nsIFile* file,
|
||||
int32_t ioFlags /* = -1 */,
|
||||
int32_t perm /* = -1 */,
|
||||
int32_t behaviorFlags /* = 0 */) {
|
||||
|
@ -1312,10 +1312,11 @@ nsresult NS_NewLocalFileStream(nsIFileStream** result, nsIFile* file,
|
|||
return rv;
|
||||
}
|
||||
|
||||
mozilla::Result<nsCOMPtr<nsIFileStream>, nsresult> NS_NewLocalFileStream(
|
||||
nsIFile* file, int32_t ioFlags /* = -1 */, int32_t perm /* = -1 */,
|
||||
int32_t behaviorFlags /* = 0 */) {
|
||||
nsCOMPtr<nsIFileStream> stream;
|
||||
mozilla::Result<nsCOMPtr<nsIRandomAccessStream>, nsresult>
|
||||
NS_NewLocalFileStream(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);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
|
|
@ -49,6 +49,7 @@ class nsIOutputStream;
|
|||
class nsIParentChannel;
|
||||
class nsIPersistentProperties;
|
||||
class nsIProxyInfo;
|
||||
class nsIRandomAccessStream;
|
||||
class nsIRequestObserver;
|
||||
class nsIStreamListener;
|
||||
class nsIStreamLoader;
|
||||
|
@ -513,13 +514,13 @@ nsresult NS_NewSafeLocalFileOutputStream(nsIOutputStream** result,
|
|||
int32_t perm = -1,
|
||||
int32_t behaviorFlags = 0);
|
||||
|
||||
nsresult NS_NewLocalFileStream(nsIFileStream** result, nsIFile* file,
|
||||
nsresult NS_NewLocalFileStream(nsIRandomAccessStream** result, nsIFile* file,
|
||||
int32_t ioFlags = -1, int32_t perm = -1,
|
||||
int32_t behaviorFlags = 0);
|
||||
|
||||
mozilla::Result<nsCOMPtr<nsIFileStream>, nsresult> NS_NewLocalFileStream(
|
||||
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);
|
||||
|
||||
[[nodiscard]] nsresult NS_NewBufferedInputStream(
|
||||
nsIInputStream** aResult, already_AddRefed<nsIInputStream> aInputStream,
|
||||
|
|
|
@ -1952,7 +1952,7 @@ void WriteFailedProfileLock(nsIFile* aProfileDir) {
|
|||
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) {
|
||||
return;
|
||||
}
|
||||
nsCOMPtr<nsIFileStream> fileStream;
|
||||
nsCOMPtr<nsIRandomAccessStream> fileStream;
|
||||
rv = NS_NewLocalFileStream(getter_AddRefs(fileStream), file,
|
||||
PR_RDWR | PR_CREATE_FILE, 0640);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
@ -1968,11 +1968,9 @@ void WriteFailedProfileLock(nsIFile* aProfileDir) {
|
|||
++failedLockCount;
|
||||
nsAutoCString bufStr;
|
||||
bufStr.AppendInt(static_cast<int>(failedLockCount));
|
||||
nsCOMPtr<nsISeekableStream> seekStream = do_QueryInterface(fileStream);
|
||||
NS_ENSURE_TRUE_VOID(seekStream);
|
||||
// If we read in an existing failed lock count, we need to reset the file ptr
|
||||
if (fileSize > 0) {
|
||||
rv = seekStream->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
||||
rv = fileStream->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
}
|
||||
nsCOMPtr<nsIOutputStream> outStream = do_QueryInterface(fileStream);
|
||||
|
@ -1987,7 +1985,7 @@ void WriteFailedProfileLock(nsIFile* aProfileDir) {
|
|||
bytes += written;
|
||||
bytesLeft -= written;
|
||||
} while (bytesLeft > 0);
|
||||
seekStream->SetEOF();
|
||||
fileStream->SetEOF();
|
||||
}
|
||||
|
||||
void InitIOReporting(nsIFile* aXreDir) {
|
||||
|
|
|
@ -27,6 +27,7 @@ XPIDL_SOURCES += [
|
|||
"nsIObjectOutputStream.idl",
|
||||
"nsIOutputStream.idl",
|
||||
"nsIPipe.idl",
|
||||
"nsIRandomAccessStream.idl",
|
||||
"nsISafeOutputStream.idl",
|
||||
"nsIScriptableBase64Encoder.idl",
|
||||
"nsIScriptableInputStream.idl",
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* 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/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsISeekableStream.idl"
|
||||
|
||||
interface nsIInputStream;
|
||||
interface nsIOutputStream;
|
||||
|
||||
/**
|
||||
* nsIRandomAccessStream
|
||||
*
|
||||
* An interface which supports both reading and writing to a storage starting
|
||||
* at the current offset. Both the input stream and the output stream share the
|
||||
* offset in the stream. Read operations invoked on the input stream start at
|
||||
* the offset and advance it past the bytes read. Write operations invoked on
|
||||
* the output stream start the offset and advance it past the bytes written.
|
||||
* The offset can be set to an arbitrary value prior reading or writting. Each
|
||||
* call to getInputStream or getOutputStream always returns the same object,
|
||||
* rather than creating a new stream. It's recommended for objects implementing
|
||||
* this interface to also implement nsIInputStream and nsIOutputStream, so they
|
||||
* can be easilly used with e.g. NS_AsyncCopy.
|
||||
*/
|
||||
[scriptable, builtinclass, uuid(9b5904a8-886a-420f-a1d8-847de8ffc133)]
|
||||
interface nsIRandomAccessStream : nsISeekableStream
|
||||
{
|
||||
/**
|
||||
* This method always returns the same object.
|
||||
*/
|
||||
nsIInputStream getInputStream();
|
||||
|
||||
/**
|
||||
* This method always returns the same object.
|
||||
*/
|
||||
nsIOutputStream getOutputStream();
|
||||
|
||||
/**
|
||||
* Like getInputStream but infallible.
|
||||
*/
|
||||
[notxpcom, nostdcall] nsIInputStream inputStream();
|
||||
|
||||
/**
|
||||
* Like getOutputStream but infallible.
|
||||
*/
|
||||
[notxpcom, nostdcall] nsIOutputStream outputStream();
|
||||
};
|
Загрузка…
Ссылка в новой задаче