From 86c5c52e0e7120f74237f6a4f64107a1779e2991 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Tue, 26 Sep 2017 07:21:27 +0200 Subject: [PATCH] Bug 1402888 - Remove nsIStreamTransportService::createInputStream startOffset and readLimit params, r=smaug --- dom/fetch/FetchStream.cpp | 2 - dom/file/FileReader.cpp | 2 - dom/file/ipc/IPCBlobInputStream.cpp | 2 - netwerk/base/nsIStreamTransportService.idl | 9 ----- netwerk/base/nsInputStreamPump.cpp | 19 +++------- netwerk/base/nsStreamTransportService.cpp | 43 ++-------------------- netwerk/protocol/http/nsHttpChannel.cpp | 3 +- toolkit/modules/ZipUtils.jsm | 2 +- 8 files changed, 12 insertions(+), 70 deletions(-) diff --git a/dom/fetch/FetchStream.cpp b/dom/fetch/FetchStream.cpp index 87631b01bcd5..e3ad628646ef 100644 --- a/dom/fetch/FetchStream.cpp +++ b/dom/fetch/FetchStream.cpp @@ -224,8 +224,6 @@ FetchStream::RequestDataCallback(JSContext* aCx, nsCOMPtr transport; rv = sts->CreateInputTransport(stream->mOriginalInputStream, - /* aStartOffset */ 0, - /* aReadLimit */ -1, /* aCloseWhenDone */ true, getter_AddRefs(transport)); if (NS_WARN_IF(NS_FAILED(rv))) { diff --git a/dom/file/FileReader.cpp b/dom/file/FileReader.cpp index 17d38f293519..82b0124a5c29 100644 --- a/dom/file/FileReader.cpp +++ b/dom/file/FileReader.cpp @@ -400,8 +400,6 @@ FileReader::ReadFileContent(Blob& aBlob, nsCOMPtr transport; aRv = sts->CreateInputTransport(stream, - /* aStartOffset */ 0, - /* aReadLimit */ -1, /* aCloseWhenDone */ true, getter_AddRefs(transport)); if (NS_WARN_IF(aRv.Failed())) { diff --git a/dom/file/ipc/IPCBlobInputStream.cpp b/dom/file/ipc/IPCBlobInputStream.cpp index 6d94900a0db2..29095c3ee624 100644 --- a/dom/file/ipc/IPCBlobInputStream.cpp +++ b/dom/file/ipc/IPCBlobInputStream.cpp @@ -651,8 +651,6 @@ IPCBlobInputStream::EnsureAsyncRemoteStream() nsCOMPtr transport; rv = sts->CreateInputTransport(mRemoteStream, - /* aStartOffset */ 0, - /* aReadLimit */ -1, /* aCloseWhenDone */ true, getter_AddRefs(transport)); if (NS_WARN_IF(NS_FAILED(rv))) { diff --git a/netwerk/base/nsIStreamTransportService.idl b/netwerk/base/nsIStreamTransportService.idl index aa743812f103..e82560528a35 100644 --- a/netwerk/base/nsIStreamTransportService.idl +++ b/netwerk/base/nsIStreamTransportService.idl @@ -25,13 +25,6 @@ interface nsIStreamTransportService : nsISupports * @param aStream * The input stream that will be read on a background thread. * This stream must implement "blocking" stream semantics. - * @param aStartOffset - * The input stream will be read starting from this offset. Pass - * -1 to read from the current stream offset. NOTE: this parameter - * is ignored if the stream does not support nsISeekableStream. - * @param aReadLimit - * This parameter limits the number of bytes that will be read from - * the input stream. Pass -1 to read everything. * @param aCloseWhenDone * Specify this flag to have the input stream closed once its * contents have been completely read. @@ -39,8 +32,6 @@ interface nsIStreamTransportService : nsISupports * @return nsITransport instance. */ nsITransport createInputTransport(in nsIInputStream aStream, - in long long aStartOffset, - in long long aReadLimit, in boolean aCloseWhenDone); void InputAvailable(in nsIInputStream aStream, diff --git a/netwerk/base/nsInputStreamPump.cpp b/netwerk/base/nsInputStreamPump.cpp index b097aaa86c4e..b442310a9c21 100644 --- a/netwerk/base/nsInputStreamPump.cpp +++ b/netwerk/base/nsInputStreamPump.cpp @@ -18,6 +18,7 @@ #include "nsILoadGroup.h" #include "nsNetCID.h" #include "nsStreamUtils.h" +#include "SlicedInputStream.h" #include static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID); @@ -331,6 +332,10 @@ nsInputStreamPump::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) // (1) the stream is blocking // (2) the stream does not support nsIAsyncInputStream // + if (mStreamOffset != UINT64_MAX || mStreamLength != UINT64_MAX) { + mStream = new SlicedInputStream(mStream, mStreamOffset, mStreamLength); + mStreamOffset = 0; + } bool nonBlocking; nsresult rv = mStream->IsNonBlocking(&nonBlocking); @@ -338,17 +343,6 @@ nsInputStreamPump::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) if (nonBlocking) { mAsyncStream = do_QueryInterface(mStream); - // - // if the stream supports nsIAsyncInputStream, and if we need to seek - // to a starting offset, then we must do so here. in the non-async - // stream case, the stream transport service will take care of seeking - // for us. - // - if (mAsyncStream && (mStreamOffset != UINT64_MAX)) { - nsCOMPtr seekable = do_QueryInterface(mStream); - if (seekable) - seekable->Seek(nsISeekableStream::NS_SEEK_SET, mStreamOffset); - } } if (!mAsyncStream) { @@ -358,8 +352,7 @@ nsInputStreamPump::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) if (NS_FAILED(rv)) return rv; nsCOMPtr transport; - rv = sts->CreateInputTransport(mStream, mStreamOffset, mStreamLength, - mCloseWhenDone, getter_AddRefs(transport)); + rv = sts->CreateInputTransport(mStream, mCloseWhenDone, getter_AddRefs(transport)); if (NS_FAILED(rv)) return rv; nsCOMPtr wrapper; diff --git a/netwerk/base/nsStreamTransportService.cpp b/netwerk/base/nsStreamTransportService.cpp index 55fc20f0da3e..8a9d63b53bb1 100644 --- a/netwerk/base/nsStreamTransportService.cpp +++ b/netwerk/base/nsStreamTransportService.cpp @@ -39,14 +39,10 @@ public: NS_DECL_NSIINPUTSTREAM nsInputStreamTransport(nsIInputStream *source, - uint64_t offset, - uint64_t limit, bool closeWhenDone) : mSource(source) - , mOffset(offset) - , mLimit(limit) + , mOffset(0) , mCloseWhenDone(closeWhenDone) - , mFirstTime(true) , mInProgress(false) { } @@ -63,9 +59,7 @@ private: nsCOMPtr mEventSink; nsCOMPtr mSource; int64_t mOffset; - int64_t mLimit; bool mCloseWhenDone; - bool mFirstTime; // this variable serves as a lock to prevent the state of the transport // from being modified once the copy is in progress. @@ -160,7 +154,7 @@ nsInputStreamTransport::Close() mSource->Close(); // make additional reads return early... - mOffset = mLimit = 0; + mOffset = 0; return NS_OK; } @@ -173,40 +167,13 @@ nsInputStreamTransport::Available(uint64_t *result) NS_IMETHODIMP nsInputStreamTransport::Read(char *buf, uint32_t count, uint32_t *result) { - if (mFirstTime) { - mFirstTime = false; - if (mOffset != 0) { - // read from current position if offset equal to max - if (mOffset != -1) { - nsCOMPtr seekable = do_QueryInterface(mSource); - if (seekable) - seekable->Seek(nsISeekableStream::NS_SEEK_SET, mOffset); - } - // reset offset to zero so we can use it to enforce limit - mOffset = 0; - } - } - - // limit amount read - uint64_t max = count; - if (mLimit != -1) { - max = mLimit - mOffset; - if (max == 0) { - *result = 0; - return NS_OK; - } - } - - if (count > max) - count = static_cast(max); - nsresult rv = mSource->Read(buf, count, result); if (NS_SUCCEEDED(rv)) { mOffset += *result; if (mEventSink) mEventSink->OnTransportStatus(this, NS_NET_STATUS_READING, mOffset, - mLimit); + -1); } return rv; } @@ -527,13 +494,11 @@ nsStreamTransportService::IsOnCurrentThread(bool *result) NS_IMETHODIMP nsStreamTransportService::CreateInputTransport(nsIInputStream *stream, - int64_t offset, - int64_t limit, bool closeWhenDone, nsITransport **result) { nsInputStreamTransport *trans = - new nsInputStreamTransport(stream, offset, limit, closeWhenDone); + new nsInputStreamTransport(stream, closeWhenDone); if (!trans) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(*result = trans); diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 72e0aa08a9da..6cbf8e21712f 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -4976,8 +4976,7 @@ nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry, bool startBufferi nsCOMPtr sts(services::GetStreamTransportService()); rv = sts ? NS_OK : NS_ERROR_NOT_AVAILABLE; if (NS_SUCCEEDED(rv)) { - rv = sts->CreateInputTransport(stream, int64_t(-1), int64_t(-1), - true, getter_AddRefs(transport)); + rv = sts->CreateInputTransport(stream, true, getter_AddRefs(transport)); } if (NS_SUCCEEDED(rv)) { rv = transport->OpenInputStream(0, 0, 0, getter_AddRefs(wrapper)); diff --git a/toolkit/modules/ZipUtils.jsm b/toolkit/modules/ZipUtils.jsm index 85fca0d0d13f..c90d51a6f4f2 100644 --- a/toolkit/modules/ZipUtils.jsm +++ b/toolkit/modules/ZipUtils.jsm @@ -41,7 +41,7 @@ function saveStreamAsync(aPath, aStream, aFile) { // Read the input stream on a background thread let sts = Cc["@mozilla.org/network/stream-transport-service;1"]. getService(Ci.nsIStreamTransportService); - let transport = sts.createInputTransport(aStream, -1, -1, true); + let transport = sts.createInputTransport(aStream, true); let input = transport.openInputStream(0, 0, 0) .QueryInterface(Ci.nsIAsyncInputStream); let source = Cc["@mozilla.org/binaryinputstream;1"].