Bug 1843752 - Explicitly transfer ownership of queued-up OnDataAvailableParams data buffers, r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D198189
This commit is contained in:
Nika Layzell 2024-01-25 17:18:48 +00:00
parent 61b99402eb
commit aa6fe46883
4 changed files with 15 additions and 17 deletions

View File

@ -1470,7 +1470,7 @@ bool DocumentLoadListener::ResumeSuspendedChannel(
streamListenerFunctions.Clear(); streamListenerFunctions.Clear();
} }
ForwardStreamListenerFunctions(streamListenerFunctions, aListener); ForwardStreamListenerFunctions(std::move(streamListenerFunctions), aListener);
// We don't expect to get new stream listener functions added // We don't expect to get new stream listener functions added
// via re-entrancy. If this ever happens, we should understand // via re-entrancy. If this ever happens, we should understand
@ -2703,7 +2703,7 @@ DocumentLoadListener::OnDataAvailable(nsIRequest* aRequest,
mStreamListenerFunctions.AppendElement(StreamListenerFunction{ mStreamListenerFunctions.AppendElement(StreamListenerFunction{
VariantIndex<1>{}, VariantIndex<1>{},
OnDataAvailableParams{aRequest, data, aOffset, aCount}}); OnDataAvailableParams{aRequest, std::move(data), aOffset, aCount}});
return NS_OK; return NS_OK;
} }

View File

@ -14,28 +14,26 @@
namespace mozilla::net { namespace mozilla::net {
nsresult ForwardStreamListenerFunctions( nsresult ForwardStreamListenerFunctions(nsTArray<StreamListenerFunction> aCalls,
nsTArray<StreamListenerFunction>& aCalls, nsIStreamListener* aParent) { nsIStreamListener* aParent) {
nsresult rv = NS_OK; nsresult rv = NS_OK;
for (auto& variant : aCalls) { for (auto& variant : aCalls) {
variant.match( variant.match(
[&](const OnStartRequestParams& aParams) { [&](OnStartRequestParams& aParams) {
rv = aParent->OnStartRequest(aParams.request); rv = aParent->OnStartRequest(aParams.request);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
aParams.request->Cancel(rv); aParams.request->Cancel(rv);
} }
}, },
[&](const OnDataAvailableParams& aParams) { [&](OnDataAvailableParams& aParams) {
// Don't deliver OnDataAvailable if we've // Don't deliver OnDataAvailable if we've
// already failed. // already failed.
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return; return;
} }
nsCOMPtr<nsIInputStream> stringStream; nsCOMPtr<nsIInputStream> stringStream;
rv = NS_NewByteInputStream( rv = NS_NewCStringInputStream(getter_AddRefs(stringStream),
getter_AddRefs(stringStream), std::move(aParams.data));
Span<const char>(aParams.data.get(), aParams.count),
NS_ASSIGNMENT_DEPEND);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = aParent->OnDataAvailable(aParams.request, stringStream, rv = aParent->OnDataAvailable(aParams.request, stringStream,
aParams.offset, aParams.count); aParams.offset, aParams.count);
@ -44,7 +42,7 @@ nsresult ForwardStreamListenerFunctions(
aParams.request->Cancel(rv); aParams.request->Cancel(rv);
} }
}, },
[&](const OnStopRequestParams& aParams) { [&](OnStopRequestParams& aParams) {
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
aParent->OnStopRequest(aParams.request, aParams.status); aParent->OnStopRequest(aParams.request, aParams.status);
} else { } else {
@ -52,7 +50,7 @@ nsresult ForwardStreamListenerFunctions(
} }
rv = NS_OK; rv = NS_OK;
}, },
[&](const OnAfterLastPartParams& aParams) { [&](OnAfterLastPartParams& aParams) {
nsCOMPtr<nsIMultiPartChannelListener> multiListener = nsCOMPtr<nsIMultiPartChannelListener> multiListener =
do_QueryInterface(aParent); do_QueryInterface(aParent);
if (multiListener) { if (multiListener) {

View File

@ -135,8 +135,8 @@ using StreamListenerFunction =
mozilla::Variant<OnStartRequestParams, OnDataAvailableParams, mozilla::Variant<OnStartRequestParams, OnDataAvailableParams,
OnStopRequestParams, OnAfterLastPartParams>; OnStopRequestParams, OnAfterLastPartParams>;
nsresult ForwardStreamListenerFunctions( nsresult ForwardStreamListenerFunctions(nsTArray<StreamListenerFunction> aCalls,
nsTArray<StreamListenerFunction>& aCalls, nsIStreamListener* aParent); nsIStreamListener* aParent);
} // namespace net } // namespace net
} // namespace mozilla } // namespace mozilla

View File

@ -582,7 +582,7 @@ void EarlyHintPreloader::InvokeStreamListenerFunctions() {
nsTArray<StreamListenerFunction> streamListenerFunctions = nsTArray<StreamListenerFunction> streamListenerFunctions =
std::move(mStreamListenerFunctions); std::move(mStreamListenerFunctions);
ForwardStreamListenerFunctions(streamListenerFunctions, mParent); ForwardStreamListenerFunctions(std::move(streamListenerFunctions), mParent);
// We don't expect to get new stream listener functions added // We don't expect to get new stream listener functions added
// via re-entrancy. If this ever happens, we should understand // via re-entrancy. If this ever happens, we should understand
@ -696,8 +696,8 @@ EarlyHintPreloader::OnDataAvailable(nsIRequest* aRequest,
nsresult rv = NS_ReadInputStreamToString(aInputStream, data, aCount); nsresult rv = NS_ReadInputStreamToString(aInputStream, data, aCount);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mStreamListenerFunctions.AppendElement( mStreamListenerFunctions.AppendElement(AsVariant(
AsVariant(OnDataAvailableParams{aRequest, data, aOffset, aCount})); OnDataAvailableParams{aRequest, std::move(data), aOffset, aCount}));
return NS_OK; return NS_OK;
} }