зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1405976 - PartiallySeekableInputStream must take the ownership of the underlying stream, r=qdot
This commit is contained in:
Родитель
fba4dcca02
Коммит
20fa36b7c1
|
@ -28,9 +28,9 @@ NS_INTERFACE_MAP_BEGIN(PartiallySeekableInputStream)
|
|||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInputStream)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
PartiallySeekableInputStream::PartiallySeekableInputStream(nsIInputStream* aInputStream,
|
||||
PartiallySeekableInputStream::PartiallySeekableInputStream(already_AddRefed<nsIInputStream> aInputStream,
|
||||
uint64_t aBufferSize)
|
||||
: mInputStream(aInputStream)
|
||||
: mInputStream(Move(aInputStream))
|
||||
, mWeakCloneableInputStream(nullptr)
|
||||
, mWeakIPCSerializableInputStream(nullptr)
|
||||
, mWeakAsyncInputStream(nullptr)
|
||||
|
@ -38,29 +38,29 @@ PartiallySeekableInputStream::PartiallySeekableInputStream(nsIInputStream* aInpu
|
|||
, mPos(0)
|
||||
, mClosed(false)
|
||||
{
|
||||
MOZ_ASSERT(aInputStream);
|
||||
MOZ_ASSERT(mInputStream);
|
||||
|
||||
#ifdef DEBUG
|
||||
nsCOMPtr<nsISeekableStream> seekableStream = do_QueryInterface(aInputStream);
|
||||
nsCOMPtr<nsISeekableStream> seekableStream = do_QueryInterface(mInputStream);
|
||||
MOZ_ASSERT(!seekableStream);
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsICloneableInputStream> cloneableStream =
|
||||
do_QueryInterface(aInputStream);
|
||||
if (cloneableStream && SameCOMIdentity(aInputStream, cloneableStream)) {
|
||||
do_QueryInterface(mInputStream);
|
||||
if (cloneableStream && SameCOMIdentity(mInputStream, cloneableStream)) {
|
||||
mWeakCloneableInputStream = cloneableStream;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIIPCSerializableInputStream> serializableStream =
|
||||
do_QueryInterface(aInputStream);
|
||||
do_QueryInterface(mInputStream);
|
||||
if (serializableStream &&
|
||||
SameCOMIdentity(aInputStream, serializableStream)) {
|
||||
SameCOMIdentity(mInputStream, serializableStream)) {
|
||||
mWeakIPCSerializableInputStream = serializableStream;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAsyncInputStream> asyncInputStream =
|
||||
do_QueryInterface(aInputStream);
|
||||
if (asyncInputStream && SameCOMIdentity(aInputStream, asyncInputStream)) {
|
||||
do_QueryInterface(mInputStream);
|
||||
if (asyncInputStream && SameCOMIdentity(mInputStream, asyncInputStream)) {
|
||||
mWeakAsyncInputStream = asyncInputStream;
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ PartiallySeekableInputStream::Clone(nsIInputStream** aResult)
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> stream =
|
||||
new PartiallySeekableInputStream(clonedStream, mBufferSize);
|
||||
new PartiallySeekableInputStream(clonedStream.forget(), mBufferSize);
|
||||
|
||||
stream.forget(aResult);
|
||||
return NS_OK;
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace mozilla {
|
|||
namespace net {
|
||||
|
||||
// A wrapper for making a stream seekable for the first |aBufferSize| bytes.
|
||||
// Note that this object takes the ownership of the underlying stream.
|
||||
|
||||
class PartiallySeekableInputStream final : public nsISeekableStream
|
||||
, public nsIAsyncInputStream
|
||||
|
@ -33,7 +34,7 @@ public:
|
|||
NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM
|
||||
NS_DECL_NSIINPUTSTREAMCALLBACK
|
||||
|
||||
explicit PartiallySeekableInputStream(nsIInputStream* aInputStream,
|
||||
explicit PartiallySeekableInputStream(already_AddRefed<nsIInputStream> aInputStream,
|
||||
uint64_t aBufferSize = 4096);
|
||||
|
||||
private:
|
||||
|
|
|
@ -1068,7 +1068,8 @@ HttpBaseChannel::ExplicitSetUploadStream(nsIInputStream *aStream,
|
|||
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(aStream);
|
||||
if (!seekable) {
|
||||
aStream = new PartiallySeekableInputStream(aStream);
|
||||
nsCOMPtr<nsIInputStream> stream = aStream;
|
||||
aStream = new PartiallySeekableInputStream(stream.forget());
|
||||
}
|
||||
|
||||
mUploadStream = aStream;
|
||||
|
|
|
@ -69,7 +69,7 @@ CreateStream(uint32_t aSize, uint64_t aStreamSize, nsCString& aBuffer)
|
|||
}
|
||||
|
||||
RefPtr<NonSeekableStream> stream = new NonSeekableStream(aBuffer);
|
||||
return new PartiallySeekableInputStream(stream, aStreamSize);
|
||||
return new PartiallySeekableInputStream(stream.forget(), aStreamSize);
|
||||
}
|
||||
|
||||
// Simple reading.
|
||||
|
|
Загрузка…
Ссылка в новой задаче