Bug 1402888 - Remove nsIStreamTransportService::createInputStream startOffset and readLimit params, r=smaug

This commit is contained in:
Andrea Marchesini 2017-09-26 07:21:27 +02:00
Родитель 221ddaa07a
Коммит 86c5c52e0e
8 изменённых файлов: 12 добавлений и 70 удалений

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

@ -224,8 +224,6 @@ FetchStream::RequestDataCallback(JSContext* aCx,
nsCOMPtr<nsITransport> transport;
rv = sts->CreateInputTransport(stream->mOriginalInputStream,
/* aStartOffset */ 0,
/* aReadLimit */ -1,
/* aCloseWhenDone */ true,
getter_AddRefs(transport));
if (NS_WARN_IF(NS_FAILED(rv))) {

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

@ -400,8 +400,6 @@ FileReader::ReadFileContent(Blob& aBlob,
nsCOMPtr<nsITransport> transport;
aRv = sts->CreateInputTransport(stream,
/* aStartOffset */ 0,
/* aReadLimit */ -1,
/* aCloseWhenDone */ true,
getter_AddRefs(transport));
if (NS_WARN_IF(aRv.Failed())) {

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

@ -651,8 +651,6 @@ IPCBlobInputStream::EnsureAsyncRemoteStream()
nsCOMPtr<nsITransport> transport;
rv = sts->CreateInputTransport(mRemoteStream,
/* aStartOffset */ 0,
/* aReadLimit */ -1,
/* aCloseWhenDone */ true,
getter_AddRefs(transport));
if (NS_WARN_IF(NS_FAILED(rv))) {

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

@ -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,

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

@ -18,6 +18,7 @@
#include "nsILoadGroup.h"
#include "nsNetCID.h"
#include "nsStreamUtils.h"
#include "SlicedInputStream.h"
#include <algorithm>
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<nsISeekableStream> 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<nsITransport> 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<nsIInputStream> wrapper;

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

@ -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<nsITransportEventSink> mEventSink;
nsCOMPtr<nsIInputStream> 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<nsISeekableStream> 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<uint32_t>(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);

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

@ -4976,8 +4976,7 @@ nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry, bool startBufferi
nsCOMPtr<nsIStreamTransportService> 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));

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

@ -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"].