mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
95a883d65d
This is a complete rewrite of RemoteLazyInputStream to run off of its own toplevel protocol, rather than being managed by other protocols like PBackground or PContent. This should improve performance thanks to no longer needing to operate on a main or worker thread, and due to no longer needing the migration step for the stream actor. This also acts as a step towards no longer requiring a manager actor to serialize input streams, as the type is now actor-agnostic, and should support being sent over IPC between any pair of processes. Differential Revision: https://phabricator.services.mozilla.com/D141040
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
/* 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 "FetchStreamUtils.h"
|
|
|
|
#include "mozilla/NotNull.h"
|
|
#include "mozilla/RemoteLazyInputStreamChild.h"
|
|
#include "mozilla/RemoteLazyInputStreamStorage.h"
|
|
#include "mozilla/dom/FetchTypes.h"
|
|
#include "mozilla/dom/IPCBlob.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsXULAppAPI.h"
|
|
|
|
namespace mozilla::dom {
|
|
|
|
namespace {
|
|
|
|
RefPtr<RemoteLazyInputStreamStorage> GetRemoteLazyInputStreamStorage() {
|
|
auto storageOrErr = RemoteLazyInputStreamStorage::Get();
|
|
MOZ_ASSERT(storageOrErr.isOk());
|
|
return storageOrErr.unwrap();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
NotNull<nsCOMPtr<nsIInputStream>> ToInputStream(
|
|
const ParentToParentStream& aStream) {
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
return WrapNotNull(
|
|
GetRemoteLazyInputStreamStorage()->ForgetStream(aStream.uuid()));
|
|
}
|
|
|
|
NotNull<nsCOMPtr<nsIInputStream>> ToInputStream(
|
|
const ParentToChildStream& aStream) {
|
|
MOZ_ASSERT(XRE_IsContentProcess());
|
|
nsCOMPtr<nsIInputStream> result = aStream.stream();
|
|
return WrapNotNull(result);
|
|
}
|
|
|
|
ParentToParentStream ToParentToParentStream(
|
|
const NotNull<nsCOMPtr<nsIInputStream>>& aStream, int64_t aStreamSize) {
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
ParentToParentStream stream;
|
|
stream.uuid() = nsID::GenerateUUID();
|
|
GetRemoteLazyInputStreamStorage()->AddStream(aStream.get(), stream.uuid());
|
|
return stream;
|
|
}
|
|
|
|
ParentToChildStream ToParentToChildStream(
|
|
const NotNull<nsCOMPtr<nsIInputStream>>& aStream, int64_t aStreamSize,
|
|
NotNull<mozilla::ipc::PBackgroundParent*> aBackgroundParent) {
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
ParentToChildStream result;
|
|
result.stream() = RemoteLazyInputStream::WrapStream(aStream.get());
|
|
return result;
|
|
}
|
|
|
|
ParentToChildStream ToParentToChildStream(
|
|
const ParentToParentStream& aStream, int64_t aStreamSize,
|
|
NotNull<mozilla::ipc::PBackgroundParent*> aBackgroundParent) {
|
|
return ToParentToChildStream(ToInputStream(aStream), aStreamSize,
|
|
aBackgroundParent);
|
|
}
|
|
|
|
} // namespace mozilla::dom
|