Bug 1402888 - Remove nsIInputStreamPump::Init() offset and limit params, r=smaug

This commit is contained in:
Andrea Marchesini 2017-09-26 07:21:44 +02:00
Родитель 86c5c52e0e
Коммит 53d31f2d9c
26 изменённых файлов: 85 добавлений и 127 удалений

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

@ -472,7 +472,7 @@ FetchBodyConsumer<Derived>::BeginConsumeBodyMainThread()
nsCOMPtr<nsIInputStreamPump> pump;
nsresult rv = NS_NewInputStreamPump(getter_AddRefs(pump),
mBodyStream, -1, -1, 0, 0, false,
mBodyStream, 0, 0, false,
mMainThreadEventTarget);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;

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

@ -991,7 +991,7 @@ TCPSocket::CreateInputStreamPump()
mInputStreamPump = do_CreateInstance("@mozilla.org/network/input-stream-pump;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = mInputStreamPump->Init(mSocketInputStream, -1, -1, 0, 0, false, nullptr);
rv = mInputStreamPump->Init(mSocketInputStream, 0, 0, false, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
uint64_t suspendCount = mSuspendCount;

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

@ -282,7 +282,7 @@ PresentationTCPSessionTransport::CreateInputStreamPump()
return rv;
}
rv = mInputStreamPump->Init(mSocketInputStream, -1, -1, 0, 0, false, nullptr);
rv = mInputStreamPump->Init(mSocketInputStream, 0, 0, false, nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -663,7 +663,7 @@ TCPControlChannel.prototype = {
this._direction); // jshint ignore:line
this._pump = Cc["@mozilla.org/network/input-stream-pump;1"].
createInstance(Ci.nsIInputStreamPump);
this._pump.init(this._input, -1, -1, 0, 0, false);
this._pump.init(this._input, 0, 0, false);
this._pump.asyncRead(this, null);
this._stateMachine.onChannelReady();
},

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

@ -1725,8 +1725,6 @@ CacheScriptLoader::ResolvedCallback(JSContext* aCx,
MOZ_ASSERT(!mPump);
rv = NS_NewInputStreamPump(getter_AddRefs(mPump),
inputStream,
-1, /* default streamPos */
-1, /* default streamLen */
0, /* default segsize */
0, /* default segcount */
false, /* default closeWhenDone */

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

@ -1159,8 +1159,6 @@ CompareCache::ManageValueResult(JSContext* aCx, JS::Handle<JS::Value> aValue)
MOZ_ASSERT(!mPump);
rv = NS_NewInputStreamPump(getter_AddRefs(mPump),
inputStream,
-1, /* default streamPos */
-1, /* default streamLen */
0, /* default segsize */
0, /* default segcount */
false, /* default closeWhenDone */

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

@ -241,7 +241,7 @@ nsIconChannel::AsyncOpen(nsIStreamListener* aListener,
nsCOMPtr<nsIEventTarget> target =
nsContentUtils::GetEventTargetByLoadInfo(mLoadInfo,
mozilla::TaskCategory::Other);
rv = mPump->Init(inStream, int64_t(-1), int64_t(-1), 0, 0, false, target);
rv = mPump->Init(inStream, 0, 0, false, target);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;

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

@ -256,7 +256,7 @@ nsIconChannel::AsyncOpen(nsIStreamListener* aListener,
nsCOMPtr<nsIEventTarget> target =
nsContentUtils::GetEventTargetByLoadInfo(mLoadInfo,
mozilla::TaskCategory::Other);
rv = mPump->Init(inStream, int64_t(-1), int64_t(-1), 0, 0, false, target);
rv = mPump->Init(inStream, 0, 0, false, target);
if (NS_FAILED(rv)) {
mCallbacks = nullptr;
return rv;

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

@ -989,7 +989,7 @@ inline nsresult nsZipWriter::BeginProcessingAddition(nsZipQueueItem* aItem,
if (aItem->mStream) {
nsCOMPtr<nsIInputStreamPump> pump;
rv = NS_NewInputStreamPump(getter_AddRefs(pump), aItem->mStream,
-1, -1, 0, 0, true);
0, 0, true);
NS_ENSURE_SUCCESS(rv, rv);
rv = pump->AsyncRead(stream, nullptr);
@ -1017,8 +1017,7 @@ inline nsresult nsZipWriter::BeginProcessingRemoval(int32_t aPos)
mFile);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStreamPump> pump;
rv = NS_NewInputStreamPump(getter_AddRefs(pump), inputStream, -1, -1, 0,
0, true);
rv = NS_NewInputStreamPump(getter_AddRefs(pump), inputStream, 0, 0, true);
if (NS_FAILED(rv)) {
inputStream->Close();
return rv;

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

@ -80,7 +80,7 @@ function run_test()
// Set up a pump to push data from the file to the stream converter
var pump = Cc["@mozilla.org/network/input-stream-pump;1"].
createInstance(Ci.nsIInputStreamPump);
pump.init(fstream, -1, -1, 0, 0, true);
pump.init(fstream, 0, 0, true);
pump.asyncRead(converter, null);
do_test_pending();
}

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

@ -86,7 +86,7 @@ function run_test()
// Set up a pump to push data from the file to the stream converter
var pump = Cc["@mozilla.org/network/input-stream-pump;1"].
createInstance(Ci.nsIInputStreamPump);
pump.init(fstream, -1, -1, 0, 0, true);
pump.init(fstream, 0, 0, true);
pump.asyncRead(converter, null);
do_test_pending();
}

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

@ -136,7 +136,7 @@ this.NetUtil = {
if (aSource instanceof Ci.nsIInputStream) {
let pump = Cc["@mozilla.org/network/input-stream-pump;1"].
createInstance(Ci.nsIInputStreamPump);
pump.init(aSource, -1, -1, 0, 0, true);
pump.init(aSource, 0, 0, true);
pump.asyncRead(listener, null);
return;
}

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

@ -257,8 +257,8 @@ nsBaseChannel::BeginPumpingData()
// release mPump if we return an error.
nsCOMPtr<nsIEventTarget> target = GetNeckoTarget();
rv = nsInputStreamPump::Create(getter_AddRefs(mPump), stream, -1, -1, 0, 0,
true, target);
rv = nsInputStreamPump::Create(getter_AddRefs(mPump), stream, 0, 0, true,
target);
if (NS_SUCCEEDED(rv)) {
mPumpingData = true;
mRequest = mPump;

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

@ -34,14 +34,6 @@ interface nsIInputStreamPump : nsIRequest
* then it will be QI'd to nsIAsyncInputStream. if the QI succeeds
* then the stream will be read directly. otherwise, it will be read
* on a background thread using the stream transport service.
* @param aStreamPos
* specifies the stream offset from which to start reading. the
* offset value is absolute. pass -1 to specify the current offset.
* NOTE: this parameter is ignored if the underlying stream does not
* implement nsISeekableStream.
* @param aStreamLen
* specifies how much data to read from the stream. pass -1 to read
* all data available in the stream.
* @param aSegmentSize
* if the stream transport service is used, then this parameter
* specifies the segment size for the stream transport's buffer.
@ -56,8 +48,6 @@ interface nsIInputStreamPump : nsIRequest
* a labeled main therad event target.
*/
void init(in nsIInputStream aStream,
in long long aStreamPos,
in long long aStreamLen,
in unsigned long aSegmentSize,
in unsigned long aSegmentCount,
in boolean aCloseWhenDone,

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

@ -18,7 +18,6 @@
#include "nsILoadGroup.h"
#include "nsNetCID.h"
#include "nsStreamUtils.h"
#include "SlicedInputStream.h"
#include <algorithm>
static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID);
@ -37,7 +36,6 @@ static mozilla::LazyLogModule gStreamPumpLog("nsStreamPump");
nsInputStreamPump::nsInputStreamPump()
: mState(STATE_IDLE)
, mStreamOffset(0)
, mStreamLength(UINT64_MAX)
, mStatus(NS_OK)
, mSuspendCount(0)
, mLoadFlags(LOAD_NORMAL)
@ -56,8 +54,6 @@ nsInputStreamPump::~nsInputStreamPump()
nsresult
nsInputStreamPump::Create(nsInputStreamPump **result,
nsIInputStream *stream,
int64_t streamPos,
int64_t streamLen,
uint32_t segsize,
uint32_t segcount,
bool closeWhenDone,
@ -66,8 +62,8 @@ nsInputStreamPump::Create(nsInputStreamPump **result,
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
RefPtr<nsInputStreamPump> pump = new nsInputStreamPump();
if (pump) {
rv = pump->Init(stream, streamPos, streamLen,
segsize, segcount, closeWhenDone, mainThreadTarget);
rv = pump->Init(stream, segsize, segcount, closeWhenDone,
mainThreadTarget);
if (NS_SUCCEEDED(rv)) {
pump.forget(result);
}
@ -298,15 +294,11 @@ nsInputStreamPump::SetLoadGroup(nsILoadGroup *aLoadGroup)
NS_IMETHODIMP
nsInputStreamPump::Init(nsIInputStream *stream,
int64_t streamPos, int64_t streamLen,
uint32_t segsize, uint32_t segcount,
bool closeWhenDone, nsIEventTarget *mainThreadTarget)
{
NS_ENSURE_TRUE(mState == STATE_IDLE, NS_ERROR_IN_PROGRESS);
mStreamOffset = uint64_t(streamPos);
if (int64_t(streamLen) >= int64_t(0))
mStreamLength = uint64_t(streamLen);
mStream = stream;
mSegSize = segsize;
mSegCount = segcount;
@ -332,10 +324,6 @@ 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);
@ -367,8 +355,7 @@ nsInputStreamPump::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
// we only reference the "stream" via mAsyncStream.
mStream = nullptr;
// mStreamOffset now holds the number of bytes currently read. we use this
// to enforce the mStreamLength restriction.
// mStreamOffset now holds the number of bytes currently read.
mStreamOffset = 0;
// grab event queue (we must do this here by contract, since all notifications
@ -566,76 +553,70 @@ nsInputStreamPump::OnStateTransfer()
avail = 0;
}
else if (NS_SUCCEEDED(rv) && avail) {
// figure out how much data to report (XXX detect overflow??)
if (avail > mStreamLength - mStreamOffset)
avail = mStreamLength - mStreamOffset;
// we used to limit avail to 16K - we were afraid some ODA handlers
// might assume they wouldn't get more than 16K at once
// we're removing that limit since it speeds up local file access.
// Now there's an implicit 64K limit of 4 16K segments
// NOTE: ok, so the story is as follows. OnDataAvailable impls
// are by contract supposed to consume exactly |avail| bytes.
// however, many do not... mailnews... stream converters...
// cough, cough. the input stream pump is fairly tolerant
// in this regard; however, if an ODA does not consume any
// data from the stream, then we could potentially end up in
// an infinite loop. we do our best here to try to catch
// such an error. (see bug 189672)
if (avail) {
// we used to limit avail to 16K - we were afraid some ODA handlers
// might assume they wouldn't get more than 16K at once
// we're removing that limit since it speeds up local file access.
// Now there's an implicit 64K limit of 4 16K segments
// NOTE: ok, so the story is as follows. OnDataAvailable impls
// are by contract supposed to consume exactly |avail| bytes.
// however, many do not... mailnews... stream converters...
// cough, cough. the input stream pump is fairly tolerant
// in this regard; however, if an ODA does not consume any
// data from the stream, then we could potentially end up in
// an infinite loop. we do our best here to try to catch
// such an error. (see bug 189672)
// in most cases this QI will succeed (mAsyncStream is almost always
// a nsPipeInputStream, which implements nsISeekableStream::Tell).
int64_t offsetBefore;
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(mBufferedStream);
if (seekable && NS_FAILED(seekable->Tell(&offsetBefore))) {
NS_NOTREACHED("Tell failed on readable stream");
offsetBefore = 0;
}
// in most cases this QI will succeed (mAsyncStream is almost always
// a nsPipeInputStream, which implements nsISeekableStream::Tell).
int64_t offsetBefore;
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(mBufferedStream);
if (seekable && NS_FAILED(seekable->Tell(&offsetBefore))) {
NS_NOTREACHED("Tell failed on readable stream");
offsetBefore = 0;
}
uint32_t odaAvail =
avail > UINT32_MAX ?
UINT32_MAX : uint32_t(avail);
uint32_t odaAvail =
avail > UINT32_MAX ?
UINT32_MAX : uint32_t(avail);
LOG((" calling OnDataAvailable [offset=%" PRIu64 " count=%" PRIu64 "(%u)]\n",
mStreamOffset, avail, odaAvail));
LOG((" calling OnDataAvailable [offset=%" PRIu64 " count=%" PRIu64 "(%u)]\n",
mStreamOffset, avail, odaAvail));
{
// Note: Must exit mutex for call to OnStartRequest to avoid
// deadlocks when calls to RetargetDeliveryTo for multiple
// nsInputStreamPumps are needed (e.g. nsHttpChannel).
RecursiveMutexAutoUnlock unlock(mMutex);
rv = mListener->OnDataAvailable(this, mListenerContext,
mBufferedStream, mStreamOffset,
odaAvail);
}
{
// Note: Must exit mutex for call to OnStartRequest to avoid
// deadlocks when calls to RetargetDeliveryTo for multiple
// nsInputStreamPumps are needed (e.g. nsHttpChannel).
RecursiveMutexAutoUnlock unlock(mMutex);
rv = mListener->OnDataAvailable(this, mListenerContext,
mBufferedStream, mStreamOffset,
odaAvail);
}
// don't enter this code if ODA failed or called Cancel
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(mStatus)) {
// test to see if this ODA failed to consume data
if (seekable) {
// NOTE: if Tell fails, which can happen if the stream is
// now closed, then we assume that everything was read.
int64_t offsetAfter;
if (NS_FAILED(seekable->Tell(&offsetAfter)))
offsetAfter = offsetBefore + odaAvail;
if (offsetAfter > offsetBefore)
mStreamOffset += (offsetAfter - offsetBefore);
else if (mSuspendCount == 0) {
//
// possible infinite loop if we continue pumping data!
//
// NOTE: although not allowed by nsIStreamListener, we
// will allow the ODA impl to Suspend the pump. IMAP
// does this :-(
//
NS_ERROR("OnDataAvailable implementation consumed no data");
mStatus = NS_ERROR_UNEXPECTED;
}
// don't enter this code if ODA failed or called Cancel
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(mStatus)) {
// test to see if this ODA failed to consume data
if (seekable) {
// NOTE: if Tell fails, which can happen if the stream is
// now closed, then we assume that everything was read.
int64_t offsetAfter;
if (NS_FAILED(seekable->Tell(&offsetAfter)))
offsetAfter = offsetBefore + odaAvail;
if (offsetAfter > offsetBefore)
mStreamOffset += (offsetAfter - offsetBefore);
else if (mSuspendCount == 0) {
//
// possible infinite loop if we continue pumping data!
//
// NOTE: although not allowed by nsIStreamListener, we
// will allow the ODA impl to Suspend the pump. IMAP
// does this :-(
//
NS_ERROR("OnDataAvailable implementation consumed no data");
mStatus = NS_ERROR_UNEXPECTED;
}
else
mStreamOffset += odaAvail; // assume ODA behaved well
}
else
mStreamOffset += odaAvail; // assume ODA behaved well
}
}

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

@ -37,8 +37,6 @@ public:
static nsresult
Create(nsInputStreamPump **result,
nsIInputStream *stream,
int64_t streamPos = -1,
int64_t streamLen = -1,
uint32_t segsize = 0,
uint32_t segcount = 0,
bool closeWhenDone = false,

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

@ -709,8 +709,6 @@ NS_NewInputStreamChannel(nsIChannel **outChannel,
nsresult
NS_NewInputStreamPump(nsIInputStreamPump **result,
nsIInputStream *stream,
int64_t streamPos /* = int64_t(-1) */,
int64_t streamLen /* = int64_t(-1) */,
uint32_t segsize /* = 0 */,
uint32_t segcount /* = 0 */,
bool closeWhenDone /* = false */,
@ -720,8 +718,8 @@ NS_NewInputStreamPump(nsIInputStreamPump **result,
nsCOMPtr<nsIInputStreamPump> pump =
do_CreateInstance(NS_INPUTSTREAMPUMP_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = pump->Init(stream, streamPos, streamLen,
segsize, segcount, closeWhenDone, mainThreadTarget);
rv = pump->Init(stream, segsize, segcount, closeWhenDone,
mainThreadTarget);
if (NS_SUCCEEDED(rv)) {
*result = nullptr;
pump.swap(*result);

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

@ -302,8 +302,6 @@ nsresult NS_NewInputStreamChannel(nsIChannel **outChannel,
nsresult NS_NewInputStreamPump(nsIInputStreamPump **result,
nsIInputStream *stream,
int64_t streamPos = int64_t(-1),
int64_t streamLen = int64_t(-1),
uint32_t segsize = 0,
uint32_t segcount = 0,
bool closeWhenDone = false,

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

@ -3537,9 +3537,7 @@ HttpChannelChild::OverrideWithSynthesizedResponse(nsAutoPtr<nsHttpResponseHead>&
MOZ_ASSERT(neckoTarget);
rv = nsInputStreamPump::Create(getter_AddRefs(mSynthesizedResponsePump),
aSynthesizedInput,
int64_t(-1), int64_t(-1), 0, 0, true,
neckoTarget);
aSynthesizedInput, 0, 0, true, neckoTarget);
if (NS_WARN_IF(NS_FAILED(rv))) {
aSynthesizedInput->Close();
return;

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

@ -5115,7 +5115,7 @@ nsHttpChannel::ReadFromCache(bool alreadyMarkedValid)
nsCOMPtr<nsIInputStream> inputStream = mCacheInputStream.forget();
rv = nsInputStreamPump::Create(getter_AddRefs(mCachePump), inputStream,
int64_t(-1), int64_t(-1), 0, 0, true);
0, 0, true);
if (NS_FAILED(rv)) {
inputStream->Close();
return rv;

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

@ -276,8 +276,8 @@ ExtensionStreamGetter::OnStream(nsIInputStream* aStream)
}
nsCOMPtr<nsIInputStreamPump> pump;
nsresult rv = NS_NewInputStreamPump(getter_AddRefs(pump), aStream, -1, -1, 0,
0, false, mMainThreadEventTarget);
nsresult rv = NS_NewInputStreamPump(getter_AddRefs(pump), aStream, 0, 0,
false, mMainThreadEventTarget);
if (NS_FAILED(rv)) {
mChannel->Cancel(NS_BINDING_ABORTED);
return;

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

@ -58,7 +58,7 @@ function pumpReadStream(inputStream, goon)
// non-blocking stream, must read via pump
var pump = Cc["@mozilla.org/network/input-stream-pump;1"]
.createInstance(Ci.nsIInputStreamPump);
pump.init(inputStream, -1, -1, 0, 0, true);
pump.init(inputStream, 0, 0, true);
var data = "";
pump.asyncRead({
onStartRequest: function (aRequest, aContext) { },

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

@ -212,7 +212,7 @@ function promisePumpToSaver(aSourceString, aSaverStreamListener,
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
let pump = Cc["@mozilla.org/network/input-stream-pump;1"]
.createInstance(Ci.nsIInputStreamPump);
pump.init(inputStream, -1, -1, 0, 0, true);
pump.init(inputStream, 0, 0, true);
pump.asyncRead({
onStartRequest: function PPTS_onStartRequest(aRequest, aContext)
{

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

@ -5,7 +5,7 @@ function run_test() {
var pump = Cc["@mozilla.org/network/input-stream-pump;1"].
createInstance(Ci.nsIInputStreamPump);
pump.init(stream, -1, -1, 0, 0, false);
pump.init(stream, 0, 0, false);
// When we pass a null listener argument too asyncRead we expect it to throw
// instead of crashing.

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

@ -145,8 +145,8 @@ public:
MOZ_ASSERT(NS_SUCCEEDED(rv));
if (NS_SUCCEEDED(rv)) {
RefPtr<nsInputStreamPump> pump;
rv = nsInputStreamPump::Create(getter_AddRefs(pump), stream, -1, -1, 0, 0,
true, target);
rv = nsInputStreamPump::Create(getter_AddRefs(pump), stream, 0, 0, true,
target);
MOZ_ASSERT(NS_SUCCEEDED(rv));
if (NS_SUCCEEDED(rv)) {
return pump->AsyncRead(mListener, nullptr);

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

@ -152,7 +152,7 @@ function RemoteMedia(url, listener) {
this._inputStream = this._socket.openInputStream(0, 0, 0);
this._pump = Cc["@mozilla.org/network/input-stream-pump;1"].createInstance(Ci.nsIInputStreamPump);
this._pump.init(this._inputStream, -1, -1, 0, 0, true);
this._pump.init(this._inputStream, 0, 0, true);
this._pump.asyncRead(this, null);
}