зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1409329 - NS_NewBufferedOutputStream should take the ownership of the outputStream, r=smaug
This commit is contained in:
Родитель
c9234eab7c
Коммит
fe04c2050c
|
@ -2321,8 +2321,9 @@ nsWebBrowserPersist::MakeOutputStreamFromFile(
|
|||
rv = fileOutputStream->Init(aFile, ioFlags, -1, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*aOutputStream = NS_BufferOutputStream(fileOutputStream,
|
||||
BUFFERED_OUTPUT_SIZE).take();
|
||||
rv = NS_NewBufferedOutputStream(aOutputStream, fileOutputStream.forget(),
|
||||
BUFFERED_OUTPUT_SIZE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mPersistFlags & PERSIST_FLAGS_CLEANUP_ON_FAILURE)
|
||||
{
|
||||
|
|
|
@ -664,8 +664,8 @@ RespondWithHandler::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValu
|
|||
// objects which may or many not play well with NS_InputStreamIsBuffered().
|
||||
if (!NS_OutputStreamIsBuffered(responseBody)) {
|
||||
nsCOMPtr<nsIOutputStream> buffered;
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(buffered), responseBody,
|
||||
kCopySegmentSize);
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(buffered),
|
||||
responseBody.forget(), kCopySegmentSize);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public:
|
|||
// Get a buffered output stream 4096 bytes big, to optimize writes.
|
||||
nsCOMPtr<nsIOutputStream> bufferedOutputStream;
|
||||
res = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
|
||||
outStream, 4096);
|
||||
outStream.forget(), 4096);
|
||||
if (NS_FAILED(res)) {
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -270,9 +270,9 @@ NS_IMETHODIMP nsZipWriter::Open(nsIFile *aFile, int32_t aIoFlags)
|
|||
return rv;
|
||||
}
|
||||
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(mStream), stream, 64 * 1024);
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(mStream), stream.forget(),
|
||||
64 * 1024);
|
||||
if (NS_FAILED(rv)) {
|
||||
stream->Close();
|
||||
mHeaders.Clear();
|
||||
mEntryHash.Clear();
|
||||
return rv;
|
||||
|
|
|
@ -3534,7 +3534,7 @@ public:
|
|||
}
|
||||
|
||||
rv = NS_NewBufferedOutputStream(
|
||||
getter_AddRefs(outStream), outStreamSink, 4096);
|
||||
getter_AddRefs(outStream), outStreamSink.forget(), 4096);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -620,10 +620,9 @@ BackgroundFileSaver::ProcessStateChange()
|
|||
PR_WRONLY | creationIoFlags, 0600);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
outputStream = NS_BufferOutputStream(outputStream, BUFFERED_IO_SIZE);
|
||||
if (!outputStream) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(outputStream),
|
||||
outputStream.forget(), BUFFERED_IO_SIZE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Wrap the output stream so that it feeds the digest context if needed.
|
||||
if (mDigestContext) {
|
||||
|
|
|
@ -1337,38 +1337,24 @@ NS_NewLocalFileStream(nsIFileStream **result,
|
|||
}
|
||||
|
||||
nsresult
|
||||
NS_NewBufferedOutputStream(nsIOutputStream **result,
|
||||
nsIOutputStream *str,
|
||||
uint32_t bufferSize)
|
||||
NS_NewBufferedOutputStream(nsIOutputStream** aResult,
|
||||
already_AddRefed<nsIOutputStream> aOutputStream,
|
||||
uint32_t aBufferSize)
|
||||
{
|
||||
nsCOMPtr<nsIOutputStream> outputStream = Move(aOutputStream);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIBufferedOutputStream> out =
|
||||
do_CreateInstance(NS_BUFFEREDOUTPUTSTREAM_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = out->Init(str, bufferSize);
|
||||
rv = out->Init(outputStream, aBufferSize);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
out.forget(result);
|
||||
out.forget(aResult);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIOutputStream>
|
||||
NS_BufferOutputStream(nsIOutputStream *aOutputStream,
|
||||
uint32_t aBufferSize)
|
||||
{
|
||||
NS_ASSERTION(aOutputStream, "No output stream given!");
|
||||
|
||||
nsCOMPtr<nsIOutputStream> bos;
|
||||
nsresult rv = NS_NewBufferedOutputStream(getter_AddRefs(bos), aOutputStream,
|
||||
aBufferSize);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return bos.forget();
|
||||
|
||||
bos = aOutputStream;
|
||||
return bos.forget();
|
||||
}
|
||||
|
||||
MOZ_MUST_USE nsresult
|
||||
NS_NewBufferedInputStream(nsIInputStream **result,
|
||||
nsIInputStream *str,
|
||||
|
|
|
@ -517,24 +517,10 @@ NS_NewBufferedInputStream(nsIInputStream **result,
|
|||
|
||||
// note: the resulting stream can be QI'ed to nsISafeOutputStream iff the
|
||||
// provided stream supports it.
|
||||
nsresult NS_NewBufferedOutputStream(nsIOutputStream **result,
|
||||
nsIOutputStream *str,
|
||||
uint32_t bufferSize);
|
||||
nsresult NS_NewBufferedOutputStream(nsIOutputStream** aResult,
|
||||
already_AddRefed<nsIOutputStream> aOutputStream,
|
||||
uint32_t aBufferSize);
|
||||
|
||||
/**
|
||||
* Attempts to buffer a given stream. If this fails, it returns the
|
||||
* passed-in stream.
|
||||
*
|
||||
* @param aOutputStream
|
||||
* The output stream we want to buffer. This cannot be null.
|
||||
* @param aBufferSize
|
||||
* The size of the buffer for the buffered output stream.
|
||||
* @returns an nsIOutputStream that is buffered with the specified buffer size,
|
||||
* or is aOutputStream if creating the new buffered stream failed.
|
||||
*/
|
||||
already_AddRefed<nsIOutputStream>
|
||||
NS_BufferOutputStream(nsIOutputStream *aOutputStream,
|
||||
uint32_t aBufferSize);
|
||||
already_AddRefed<nsIInputStream>
|
||||
NS_BufferInputStream(nsIInputStream *aInputStream,
|
||||
uint32_t aBufferSize);
|
||||
|
|
|
@ -1815,7 +1815,8 @@ nsOfflineCacheDevice::OpenOutputStreamForEntry(nsCacheEntry *entry,
|
|||
|
||||
nsCOMPtr<nsIOutputStream> bufferedOut;
|
||||
nsresult rv =
|
||||
NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 16 * 1024);
|
||||
NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out.forget(),
|
||||
16 * 1024);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
bufferedOut.swap(*result);
|
||||
|
|
|
@ -766,7 +766,8 @@ RDFXMLDataSourceImpl::rdfXMLFlush(nsIURI *aURI)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> bufferedOut;
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 4096);
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut),
|
||||
out.forget(), 4096);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = Serialize(bufferedOut);
|
||||
|
|
|
@ -281,7 +281,8 @@ nsCertOverrideService::Write(const MutexAutoLock& aProofOfLock)
|
|||
|
||||
// get a buffered output stream 4096 bytes big, to optimize writes
|
||||
nsCOMPtr<nsIOutputStream> bufferedOutputStream;
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream), fileOutputStream, 4096);
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
|
||||
fileOutputStream.forget(), 4096);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -275,8 +275,10 @@ VariableLengthPrefixSet::StoreToFile(nsIFile* aFile)
|
|||
}
|
||||
|
||||
// Convert to buffered stream
|
||||
nsCOMPtr<nsIOutputStream> out =
|
||||
NS_BufferOutputStream(localOutFile, std::min(fileSize, MAX_BUFFER_SIZE));
|
||||
nsCOMPtr<nsIOutputStream> out;
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(out), localOutFile.forget(),
|
||||
std::min(fileSize, MAX_BUFFER_SIZE));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mFixedPrefixSet->WritePrefixes(out);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
|
|
@ -385,8 +385,10 @@ nsUrlClassifierPrefixSet::StoreToFile(nsIFile* aFile)
|
|||
}
|
||||
|
||||
// Convert to buffered stream
|
||||
nsCOMPtr<nsIOutputStream> out =
|
||||
NS_BufferOutputStream(localOutFile, std::min(fileSize, MAX_BUFFER_SIZE));
|
||||
nsCOMPtr<nsIOutputStream> out;
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(out), localOutFile.forget(),
|
||||
std::min(fileSize, MAX_BUFFER_SIZE));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = WritePrefixes(out);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
|
Загрузка…
Ссылка в новой задаче