mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 13:45:27 +00:00
3b0485fcdb
Slightly less than half (93 / 210) of the NS_METHOD instances in the codebase are because of the use of NS_CALLBACK in nsI{Input,Output,UnicharInput},Stream.idl. The use of __stdcall on Win32 isn't important for these callbacks because they are only used as arguments to [noscript] methods. This patch converts them to vanilla |nsresult| functions. It increases the size of xul.dll by about ~600 bytes, which is about 0.001%. --HG-- extra : rebase_source : c15d85298e0975fd030cd8f8f8e54501f453959b
93 lines
2.6 KiB
C++
93 lines
2.6 KiB
C++
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "MemoryDownloader.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
#include "nsIInputStream.h"
|
|
|
|
namespace mozilla {
|
|
namespace net {
|
|
|
|
NS_IMPL_ISUPPORTS(MemoryDownloader,
|
|
nsIStreamListener,
|
|
nsIRequestObserver)
|
|
|
|
MemoryDownloader::MemoryDownloader(IObserver* aObserver)
|
|
: mObserver(aObserver)
|
|
{
|
|
}
|
|
|
|
MemoryDownloader::~MemoryDownloader()
|
|
{
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MemoryDownloader::OnStartRequest(nsIRequest* aRequest, nsISupports* aCtxt)
|
|
{
|
|
MOZ_ASSERT(!mData);
|
|
mData.reset(new FallibleTArray<uint8_t>());
|
|
mStatus = NS_OK;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MemoryDownloader::OnStopRequest(nsIRequest* aRequest,
|
|
nsISupports* aCtxt,
|
|
nsresult aStatus)
|
|
{
|
|
MOZ_ASSERT_IF(NS_FAILED(mStatus), NS_FAILED(aStatus));
|
|
MOZ_ASSERT(!mData == NS_FAILED(mStatus));
|
|
Data data;
|
|
data.swap(mData);
|
|
RefPtr<IObserver> observer;
|
|
observer.swap(mObserver);
|
|
observer->OnDownloadComplete(this, aRequest, aCtxt, aStatus,
|
|
mozilla::Move(data));
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
MemoryDownloader::ConsumeData(nsIInputStream* aIn,
|
|
void* aClosure,
|
|
const char* aFromRawSegment,
|
|
uint32_t aToOffset,
|
|
uint32_t aCount,
|
|
uint32_t* aWriteCount)
|
|
{
|
|
MemoryDownloader* self = static_cast<MemoryDownloader*>(aClosure);
|
|
if (!self->mData->AppendElements(aFromRawSegment, aCount, fallible)) {
|
|
// The error returned by ConsumeData isn't propagated to the
|
|
// return of ReadSegments, so it has to be passed as state.
|
|
self->mStatus = NS_ERROR_OUT_OF_MEMORY;
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
*aWriteCount = aCount;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MemoryDownloader::OnDataAvailable(nsIRequest* aRequest,
|
|
nsISupports* aCtxt,
|
|
nsIInputStream* aInStr,
|
|
uint64_t aSourceOffset,
|
|
uint32_t aCount)
|
|
{
|
|
uint32_t n;
|
|
MOZ_ASSERT(mData);
|
|
nsresult rv = aInStr->ReadSegments(ConsumeData, this, aCount, &n);
|
|
if (NS_SUCCEEDED(mStatus) && NS_FAILED(rv)) {
|
|
mStatus = rv;
|
|
}
|
|
if (NS_WARN_IF(NS_FAILED(mStatus))) {
|
|
mData.reset(nullptr);
|
|
return mStatus;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
} // namespace net
|
|
} // namespace mozilla
|