Backed out 8 changesets (bug 1648141) for build bustages on RemoteLazyInputStreamThread.cpp. CLOSED TREE

Backed out changeset e9b4ca0ee700 (bug 1648141)
Backed out changeset b9bb847cee47 (bug 1648141)
Backed out changeset 11dfce46ec14 (bug 1648141)
Backed out changeset d824d2f67f27 (bug 1648141)
Backed out changeset e5b8292e7095 (bug 1648141)
Backed out changeset c1a3d5fa0c61 (bug 1648141)
Backed out changeset 24fdb83db3cd (bug 1648141)
Backed out changeset 749d894dde52 (bug 1648141)
This commit is contained in:
Razvan Maries 2020-06-29 13:59:16 +03:00
Родитель fa2b0a4ba3
Коммит f7cb24cc7e
71 изменённых файлов: 763 добавлений и 849 удалений

Просмотреть файл

@ -22,6 +22,7 @@ Compositor
Cookie
CrashRep Inject
DDMediaLogs
DOM File
DOMCacheThread
DataChannel IO
DataStorage
@ -63,7 +64,6 @@ ProcessHangMon
ProfSymbolTable
ProfilerChild
ProxyResolution
RemoteLzyStream
RWLockTester
RacingServMan
RemVidChild

Просмотреть файл

@ -5,8 +5,8 @@
include protocol PBackground;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include DOMTypes;

Просмотреть файл

@ -4,10 +4,10 @@
include protocol PClientManager;
include protocol PClientHandleOp;
include protocol PIPCBlobInputStream;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include ClientIPCTypes;
namespace mozilla {

Просмотреть файл

@ -7,10 +7,10 @@ include protocol PClientHandle;
include protocol PClientManagerOp;
include protocol PClientNavigateOp;
include protocol PClientSource;
include protocol PIPCBlobInputStream;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include ClientIPCTypes;
namespace mozilla {

Просмотреть файл

@ -4,10 +4,10 @@
include protocol PClientManager;
include protocol PClientSourceOp;
include protocol PIPCBlobInputStream;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include ClientIPCTypes;
namespace mozilla {

Просмотреть файл

@ -6,7 +6,7 @@ include IPCStream;
include ChannelInfo;
include PBackgroundSharedTypes;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
using HeadersGuardEnum from "mozilla/dom/FetchIPCTypes.h";
using ReferrerPolicy from "mozilla/dom/FetchIPCTypes.h";
@ -26,12 +26,12 @@ struct HeadersEntry {
};
struct ParentToParentStream {
// Used as a key for RemoteLazyInputStreamStorage
// Used as a key for IPCBlobInputStreamStorage
nsID uuid;
};
struct ParentToChildStream {
PRemoteLazyInputStream actor;
PIPCBlobInputStream actor;
};
struct ChildToParentStream {

Просмотреть файл

@ -9,12 +9,12 @@
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/FetchTypes.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/RemoteLazyInputStreamChild.h"
#include "nsIContentPolicy.h"
#include "nsStreamUtils.h"
@ -169,7 +169,7 @@ InternalRequest::InternalRequest(const IPCInternalRequest& aIPCRequest)
// (constructed on the child side).
if (body) {
MOZ_ASSERT(body->type() == BodyStreamVariant::TParentToChildStream);
mBodyStream = static_cast<RemoteLazyInputStreamChild*>(
mBodyStream = static_cast<IPCBlobInputStreamChild*>(
body->get_ParentToChildStream().actorChild())
->CreateStream();
}

Просмотреть файл

@ -9,12 +9,12 @@
#include "mozilla/Assertions.h"
#include "mozilla/RefPtr.h"
#include "mozilla/dom/FetchTypes.h"
#include "mozilla/dom/IPCBlobInputStreamStorage.h"
#include "mozilla/dom/InternalHeaders.h"
#include "mozilla/dom/cache/CacheTypes.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/RandomNum.h"
#include "mozilla/RemoteLazyInputStreamStorage.h"
#include "nsIRandomGenerator.h"
#include "nsStreamUtils.h"
@ -32,7 +32,7 @@ nsCOMPtr<nsIInputStream> TakeStreamFromStorage(
MOZ_ASSERT(aVariant.type() == BodyStreamVariant::TParentToParentStream);
const auto& uuid = aVariant.get_ParentToParentStream().uuid();
auto stream = RemoteLazyInputStreamStorage::Get()->ForgetStream(uuid);
auto stream = IPCBlobInputStreamStorage::Get()->ForgetStream(uuid);
MOZ_ASSERT(stream);
return stream;

Просмотреть файл

@ -6,7 +6,7 @@
#include "TemporaryFileBlobImpl.h"
#include "RemoteLazyInputStreamThread.h"
#include "IPCBlobInputStreamThread.h"
#include "nsFileStreams.h"
#include "nsIFile.h"
#include "nsIFileStreams.h"
@ -76,9 +76,9 @@ class TemporaryFileInputStream final : public nsFileInputStream {
}
~TemporaryFileInputStream() {
// Let's delete the file on the RemoteLazyInputStream Thread.
RefPtr<RemoteLazyInputStreamThread> thread =
RemoteLazyInputStreamThread::GetOrCreate();
// Let's delete the file on the IPCBlob Thread.
RefPtr<IPCBlobInputStreamThread> thread =
IPCBlobInputStreamThread::GetOrCreate();
if (NS_WARN_IF(!thread)) {
return;
}

Просмотреть файл

@ -4,7 +4,7 @@
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
include IPCStream;
include ProtocolTypes;
@ -13,17 +13,6 @@ using struct mozilla::void_t
from "ipc/IPCMessageUtils.h";
namespace mozilla {
union RemoteLazyStream
{
// Parent to Child: The child will receive a RemoteLazyInputStream. Nothing
// can be done with it except retrieving the size.
PRemoteLazyInputStream;
// Child to Parent: Normal serialization.
IPCStream;
};
namespace dom {
// This contains any extra bit for making a File out of a Blob.
@ -41,13 +30,23 @@ struct IPCFile
bool isDirectory;
};
union IPCBlobStream
{
// Parent to Child: The child will receive a IPCBlobInputStream. Nothing
// can be done with it except retrieving the size.
PIPCBlobInputStream;
// Child to Parent: Normal serialization.
IPCStream;
};
struct IPCBlob
{
nsString type;
uint64_t size;
nsString blobImplType;
RemoteLazyStream inputStream;
IPCBlobStream inputStream;
// Nothing is for Blob
IPCFile? file;

Просмотреть файл

@ -4,28 +4,29 @@
* 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 "RemoteLazyInputStream.h"
#include "RemoteLazyInputStreamChild.h"
#include "RemoteLazyInputStreamParent.h"
#include "IPCBlobInputStream.h"
#include "IPCBlobInputStreamChild.h"
#include "IPCBlobInputStreamParent.h"
#include "IPCBlobInputStreamStorage.h"
#include "mozilla/ipc/InputStreamParams.h"
#include "mozilla/net/SocketProcessParent.h"
#include "mozilla/SlicedInputStream.h"
#include "mozilla/NonBlockingAsyncInputStream.h"
#include "IPCBlobInputStreamThread.h"
#include "nsIAsyncInputStream.h"
#include "nsIAsyncOutputStream.h"
#include "nsIPipe.h"
#include "nsNetUtil.h"
#include "nsStreamUtils.h"
#include "nsStringStream.h"
#include "RemoteLazyInputStreamStorage.h"
#include "RemoteLazyInputStreamThread.h"
namespace mozilla {
using namespace dom;
using net::SocketProcessParent;
class RemoteLazyInputStream;
namespace dom {
class IPCBlobInputStream;
namespace {
@ -35,7 +36,7 @@ class InputStreamCallbackRunnable final : public CancelableRunnable {
// null.
static void Execute(nsIInputStreamCallback* aCallback,
nsIEventTarget* aEventTarget,
RemoteLazyInputStream* aStream) {
IPCBlobInputStream* aStream) {
MOZ_ASSERT(aCallback);
RefPtr<InputStreamCallbackRunnable> runnable =
@ -59,7 +60,7 @@ class InputStreamCallbackRunnable final : public CancelableRunnable {
private:
InputStreamCallbackRunnable(nsIInputStreamCallback* aCallback,
RemoteLazyInputStream* aStream)
IPCBlobInputStream* aStream)
: CancelableRunnable("dom::InputStreamCallbackRunnable"),
mCallback(aCallback),
mStream(aStream) {
@ -68,14 +69,14 @@ class InputStreamCallbackRunnable final : public CancelableRunnable {
}
nsCOMPtr<nsIInputStreamCallback> mCallback;
RefPtr<RemoteLazyInputStream> mStream;
RefPtr<IPCBlobInputStream> mStream;
};
class FileMetadataCallbackRunnable final : public CancelableRunnable {
public:
static void Execute(nsIFileMetadataCallback* aCallback,
nsIEventTarget* aEventTarget,
RemoteLazyInputStream* aStream) {
IPCBlobInputStream* aStream) {
MOZ_ASSERT(aCallback);
MOZ_ASSERT(aEventTarget);
@ -96,7 +97,7 @@ class FileMetadataCallbackRunnable final : public CancelableRunnable {
private:
FileMetadataCallbackRunnable(nsIFileMetadataCallback* aCallback,
RemoteLazyInputStream* aStream)
IPCBlobInputStream* aStream)
: CancelableRunnable("dom::FileMetadataCallbackRunnable"),
mCallback(aCallback),
mStream(aStream) {
@ -105,15 +106,15 @@ class FileMetadataCallbackRunnable final : public CancelableRunnable {
}
nsCOMPtr<nsIFileMetadataCallback> mCallback;
RefPtr<RemoteLazyInputStream> mStream;
RefPtr<IPCBlobInputStream> mStream;
};
} // namespace
NS_IMPL_ADDREF(RemoteLazyInputStream);
NS_IMPL_RELEASE(RemoteLazyInputStream);
NS_IMPL_ADDREF(IPCBlobInputStream);
NS_IMPL_RELEASE(IPCBlobInputStream);
NS_INTERFACE_MAP_BEGIN(RemoteLazyInputStream)
NS_INTERFACE_MAP_BEGIN(IPCBlobInputStream)
NS_INTERFACE_MAP_ENTRY(nsIInputStream)
NS_INTERFACE_MAP_ENTRY(nsIAsyncInputStream)
NS_INTERFACE_MAP_ENTRY(nsIInputStreamCallback)
@ -124,25 +125,25 @@ NS_INTERFACE_MAP_BEGIN(RemoteLazyInputStream)
NS_INTERFACE_MAP_ENTRY(nsIAsyncFileMetadata)
NS_INTERFACE_MAP_ENTRY(nsIInputStreamLength)
NS_INTERFACE_MAP_ENTRY(nsIAsyncInputStreamLength)
NS_INTERFACE_MAP_ENTRY(mozIRemoteLazyInputStream)
NS_INTERFACE_MAP_ENTRY(mozIIPCBlobInputStream)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInputStream)
NS_INTERFACE_MAP_END
RemoteLazyInputStream::RemoteLazyInputStream(RemoteLazyInputStreamChild* aActor)
IPCBlobInputStream::IPCBlobInputStream(IPCBlobInputStreamChild* aActor)
: mActor(aActor),
mState(eInit),
mStart(0),
mLength(0),
mConsumed(false),
mMutex("RemoteLazyInputStream::mMutex") {
mMutex("IPCBlobInputStream::mMutex") {
MOZ_ASSERT(aActor);
mLength = aActor->Size();
if (XRE_IsParentProcess()) {
nsCOMPtr<nsIInputStream> stream;
RemoteLazyInputStreamStorage::Get()->GetStream(mActor->ID(), 0, mLength,
getter_AddRefs(stream));
IPCBlobInputStreamStorage::Get()->GetStream(mActor->ID(), 0, mLength,
getter_AddRefs(stream));
if (stream) {
mState = eRunning;
mRemoteStream = stream;
@ -150,12 +151,12 @@ RemoteLazyInputStream::RemoteLazyInputStream(RemoteLazyInputStreamChild* aActor)
}
}
RemoteLazyInputStream::~RemoteLazyInputStream() { Close(); }
IPCBlobInputStream::~IPCBlobInputStream() { Close(); }
// nsIInputStream interface
NS_IMETHODIMP
RemoteLazyInputStream::Available(uint64_t* aLength) {
IPCBlobInputStream::Available(uint64_t* aLength) {
nsCOMPtr<nsIAsyncInputStream> asyncRemoteStream;
{
MutexAutoLock lock(mMutex);
@ -186,8 +187,7 @@ RemoteLazyInputStream::Available(uint64_t* aLength) {
}
NS_IMETHODIMP
RemoteLazyInputStream::Read(char* aBuffer, uint32_t aCount,
uint32_t* aReadCount) {
IPCBlobInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aReadCount) {
nsCOMPtr<nsIAsyncInputStream> asyncRemoteStream;
{
MutexAutoLock lock(mMutex);
@ -227,8 +227,8 @@ RemoteLazyInputStream::Read(char* aBuffer, uint32_t aCount,
}
NS_IMETHODIMP
RemoteLazyInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
uint32_t aCount, uint32_t* aResult) {
IPCBlobInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
uint32_t aCount, uint32_t* aResult) {
nsCOMPtr<nsIAsyncInputStream> asyncRemoteStream;
{
MutexAutoLock lock(mMutex);
@ -270,13 +270,13 @@ RemoteLazyInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
}
NS_IMETHODIMP
RemoteLazyInputStream::IsNonBlocking(bool* aNonBlocking) {
IPCBlobInputStream::IsNonBlocking(bool* aNonBlocking) {
*aNonBlocking = true;
return NS_OK;
}
NS_IMETHODIMP
RemoteLazyInputStream::Close() {
IPCBlobInputStream::Close() {
nsCOMPtr<nsIAsyncInputStream> asyncRemoteStream;
nsCOMPtr<nsIInputStream> remoteStream;
{
@ -313,14 +313,14 @@ RemoteLazyInputStream::Close() {
// nsICloneableInputStream interface
NS_IMETHODIMP
RemoteLazyInputStream::GetCloneable(bool* aCloneable) {
IPCBlobInputStream::GetCloneable(bool* aCloneable) {
MutexAutoLock lock(mMutex);
*aCloneable = mState != eClosed;
return NS_OK;
}
NS_IMETHODIMP
RemoteLazyInputStream::Clone(nsIInputStream** aResult) {
IPCBlobInputStream::Clone(nsIInputStream** aResult) {
MutexAutoLock lock(mMutex);
if (mState == eClosed) {
@ -329,7 +329,7 @@ RemoteLazyInputStream::Clone(nsIInputStream** aResult) {
MOZ_ASSERT(mActor);
RefPtr<RemoteLazyInputStream> stream = mActor->CreateStream();
RefPtr<IPCBlobInputStream> stream = mActor->CreateStream();
if (!stream) {
return NS_ERROR_FAILURE;
}
@ -343,8 +343,8 @@ RemoteLazyInputStream::Clone(nsIInputStream** aResult) {
// nsICloneableInputStreamWithRange interface
NS_IMETHODIMP
RemoteLazyInputStream::CloneWithRange(uint64_t aStart, uint64_t aLength,
nsIInputStream** aResult) {
IPCBlobInputStream::CloneWithRange(uint64_t aStart, uint64_t aLength,
nsIInputStream** aResult) {
MutexAutoLock lock(mMutex);
if (mState == eClosed) {
@ -358,7 +358,7 @@ RemoteLazyInputStream::CloneWithRange(uint64_t aStart, uint64_t aLength,
MOZ_ASSERT(mActor);
RefPtr<RemoteLazyInputStream> stream = mActor->CreateStream();
RefPtr<IPCBlobInputStream> stream = mActor->CreateStream();
if (!stream) {
return NS_ERROR_FAILURE;
}
@ -382,18 +382,17 @@ RemoteLazyInputStream::CloneWithRange(uint64_t aStart, uint64_t aLength,
// nsIAsyncInputStream interface
NS_IMETHODIMP
RemoteLazyInputStream::CloseWithStatus(nsresult aStatus) { return Close(); }
IPCBlobInputStream::CloseWithStatus(nsresult aStatus) { return Close(); }
NS_IMETHODIMP
RemoteLazyInputStream::AsyncWait(nsIInputStreamCallback* aCallback,
uint32_t aFlags, uint32_t aRequestedCount,
nsIEventTarget* aEventTarget) {
IPCBlobInputStream::AsyncWait(nsIInputStreamCallback* aCallback,
uint32_t aFlags, uint32_t aRequestedCount,
nsIEventTarget* aEventTarget) {
nsCOMPtr<nsIAsyncInputStream> asyncRemoteStream;
{
MutexAutoLock lock(mMutex);
// See RemoteLazyInputStream.h for more information about this state
// machine.
// See IPCBlobInputStream.h for more information about this state machine.
switch (mState) {
// First call, we need to retrieve the stream from the parent actor.
@ -459,7 +458,7 @@ RemoteLazyInputStream::AsyncWait(nsIInputStreamCallback* aCallback,
return NS_OK;
}
void RemoteLazyInputStream::StreamReady(
void IPCBlobInputStream::StreamReady(
already_AddRefed<nsIInputStream> aInputStream) {
nsCOMPtr<nsIInputStream> inputStream = std::move(aInputStream);
@ -530,7 +529,7 @@ void RemoteLazyInputStream::StreamReady(
}
}
void RemoteLazyInputStream::InitWithExistingRange(
void IPCBlobInputStream::InitWithExistingRange(
uint64_t aStart, uint64_t aLength, const MutexAutoLock& aProofOfLock) {
MOZ_ASSERT(mActor->Size() >= aStart + aLength);
mStart = aStart;
@ -550,7 +549,7 @@ void RemoteLazyInputStream::InitWithExistingRange(
// nsIInputStreamCallback
NS_IMETHODIMP
RemoteLazyInputStream::OnInputStreamReady(nsIAsyncInputStream* aStream) {
IPCBlobInputStream::OnInputStreamReady(nsIAsyncInputStream* aStream) {
nsCOMPtr<nsIInputStreamCallback> callback;
nsCOMPtr<nsIEventTarget> callbackEventTarget;
{
@ -582,7 +581,7 @@ RemoteLazyInputStream::OnInputStreamReady(nsIAsyncInputStream* aStream) {
// nsIIPCSerializableInputStream
void RemoteLazyInputStream::Serialize(
void IPCBlobInputStream::Serialize(
mozilla::ipc::InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors, bool aDelayedStart,
uint32_t aMaxSize, uint32_t* aSizeUsed,
@ -591,15 +590,14 @@ void RemoteLazyInputStream::Serialize(
*aSizeUsed = 0;
// So far we support only socket process serialization.
MOZ_DIAGNOSTIC_ASSERT(
aManager == SocketProcessParent::GetSingleton(),
"Serializing an RemoteLazyInputStream parent to child is "
"wrong! The caller must be fixed! See IPCBlobUtils.h.");
MOZ_DIAGNOSTIC_ASSERT(aManager == SocketProcessParent::GetSingleton(),
"Serializing an IPCBlobInputStream parent to child is "
"wrong! The caller must be fixed! See IPCBlobUtils.h.");
SocketProcessParent* socketActor = SocketProcessParent::GetSingleton();
nsresult rv;
nsCOMPtr<nsIAsyncInputStream> asyncRemoteStream;
RefPtr<RemoteLazyInputStreamParent> parentActor;
RefPtr<IPCBlobInputStreamParent> parentActor;
{
MutexAutoLock lock(mMutex);
rv = EnsureAsyncRemoteStream(lock);
@ -611,19 +609,19 @@ void RemoteLazyInputStream::Serialize(
MOZ_ASSERT(asyncRemoteStream);
parentActor = RemoteLazyInputStreamParent::Create(asyncRemoteStream, mLength,
0, &rv, socketActor);
parentActor = IPCBlobInputStreamParent::Create(asyncRemoteStream, mLength, 0,
&rv, socketActor);
MOZ_ASSERT(parentActor);
if (!socketActor->SendPRemoteLazyInputStreamConstructor(
if (!socketActor->SendPIPCBlobInputStreamConstructor(
parentActor, parentActor->ID(), parentActor->Size())) {
MOZ_CRASH("The serialization is not supposed to fail");
}
aParams = mozilla::ipc::RemoteLazyInputStreamParams(parentActor);
aParams = mozilla::ipc::IPCBlobInputStreamParams(parentActor);
}
void RemoteLazyInputStream::Serialize(
void IPCBlobInputStream::Serialize(
mozilla::ipc::InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors, bool aDelayedStart,
uint32_t aMaxSize, uint32_t* aSizeUsed,
@ -633,7 +631,7 @@ void RemoteLazyInputStream::Serialize(
MutexAutoLock lock(mMutex);
mozilla::ipc::RemoteLazyInputStreamRef params;
mozilla::ipc::IPCBlobInputStreamRef params;
params.id() = mActor->ID();
params.start() = mStart;
params.length() = mLength;
@ -641,7 +639,7 @@ void RemoteLazyInputStream::Serialize(
aParams = params;
}
bool RemoteLazyInputStream::Deserialize(
bool IPCBlobInputStream::Deserialize(
const mozilla::ipc::InputStreamParams& aParams,
const FileDescriptorArray& aFileDescriptors) {
MOZ_CRASH("This should never be called.");
@ -651,8 +649,8 @@ bool RemoteLazyInputStream::Deserialize(
// nsIAsyncFileMetadata
NS_IMETHODIMP
RemoteLazyInputStream::AsyncFileMetadataWait(nsIFileMetadataCallback* aCallback,
nsIEventTarget* aEventTarget) {
IPCBlobInputStream::AsyncFileMetadataWait(nsIFileMetadataCallback* aCallback,
nsIEventTarget* aEventTarget) {
MOZ_ASSERT(!!aCallback == !!aEventTarget);
// If we have the callback, we must have the event target.
@ -660,7 +658,7 @@ RemoteLazyInputStream::AsyncFileMetadataWait(nsIFileMetadataCallback* aCallback,
return NS_ERROR_FAILURE;
}
// See RemoteLazyInputStream.h for more information about this state machine.
// See IPCBlobInputStream.h for more information about this state machine.
{
MutexAutoLock lock(mMutex);
@ -708,7 +706,7 @@ RemoteLazyInputStream::AsyncFileMetadataWait(nsIFileMetadataCallback* aCallback,
// nsIFileMetadata
NS_IMETHODIMP
RemoteLazyInputStream::GetSize(int64_t* aRetval) {
IPCBlobInputStream::GetSize(int64_t* aRetval) {
nsCOMPtr<nsIFileMetadata> fileMetadata;
{
MutexAutoLock lock(mMutex);
@ -722,7 +720,7 @@ RemoteLazyInputStream::GetSize(int64_t* aRetval) {
}
NS_IMETHODIMP
RemoteLazyInputStream::GetLastModified(int64_t* aRetval) {
IPCBlobInputStream::GetLastModified(int64_t* aRetval) {
nsCOMPtr<nsIFileMetadata> fileMetadata;
{
MutexAutoLock lock(mMutex);
@ -736,7 +734,7 @@ RemoteLazyInputStream::GetLastModified(int64_t* aRetval) {
}
NS_IMETHODIMP
RemoteLazyInputStream::GetFileDescriptor(PRFileDesc** aRetval) {
IPCBlobInputStream::GetFileDescriptor(PRFileDesc** aRetval) {
nsCOMPtr<nsIFileMetadata> fileMetadata;
{
MutexAutoLock lock(mMutex);
@ -749,7 +747,7 @@ RemoteLazyInputStream::GetFileDescriptor(PRFileDesc** aRetval) {
return fileMetadata->GetFileDescriptor(aRetval);
}
nsresult RemoteLazyInputStream::EnsureAsyncRemoteStream(
nsresult IPCBlobInputStream::EnsureAsyncRemoteStream(
const MutexAutoLock& aProofOfLock) {
// We already have an async remote stream.
if (mAsyncRemoteStream) {
@ -806,8 +804,8 @@ nsresult RemoteLazyInputStream::EnsureAsyncRemoteStream(
return rv;
}
RefPtr<RemoteLazyInputStreamThread> thread =
RemoteLazyInputStreamThread::GetOrCreate();
RefPtr<IPCBlobInputStreamThread> thread =
IPCBlobInputStreamThread::GetOrCreate();
if (NS_WARN_IF(!thread)) {
return NS_ERROR_FAILURE;
}
@ -830,7 +828,7 @@ nsresult RemoteLazyInputStream::EnsureAsyncRemoteStream(
// nsIInputStreamLength
NS_IMETHODIMP
RemoteLazyInputStream::Length(int64_t* aLength) {
IPCBlobInputStream::Length(int64_t* aLength) {
MutexAutoLock lock(mMutex);
if (mState == eClosed) {
@ -849,8 +847,8 @@ namespace {
class InputStreamLengthCallbackRunnable final : public CancelableRunnable {
public:
static void Execute(nsIInputStreamLengthCallback* aCallback,
nsIEventTarget* aEventTarget,
RemoteLazyInputStream* aStream, int64_t aLength) {
nsIEventTarget* aEventTarget, IPCBlobInputStream* aStream,
int64_t aLength) {
MOZ_ASSERT(aCallback);
MOZ_ASSERT(aEventTarget);
@ -871,7 +869,7 @@ class InputStreamLengthCallbackRunnable final : public CancelableRunnable {
private:
InputStreamLengthCallbackRunnable(nsIInputStreamLengthCallback* aCallback,
RemoteLazyInputStream* aStream,
IPCBlobInputStream* aStream,
int64_t aLength)
: CancelableRunnable("dom::InputStreamLengthCallbackRunnable"),
mCallback(aCallback),
@ -882,7 +880,7 @@ class InputStreamLengthCallbackRunnable final : public CancelableRunnable {
}
nsCOMPtr<nsIInputStreamLengthCallback> mCallback;
RefPtr<RemoteLazyInputStream> mStream;
RefPtr<IPCBlobInputStream> mStream;
const int64_t mLength;
};
@ -891,8 +889,8 @@ class InputStreamLengthCallbackRunnable final : public CancelableRunnable {
// nsIAsyncInputStreamLength
NS_IMETHODIMP
RemoteLazyInputStream::AsyncLengthWait(nsIInputStreamLengthCallback* aCallback,
nsIEventTarget* aEventTarget) {
IPCBlobInputStream::AsyncLengthWait(nsIInputStreamLengthCallback* aCallback,
nsIEventTarget* aEventTarget) {
// If we have the callback, we must have the event target.
if (NS_WARN_IF(!!aCallback != !!aEventTarget)) {
return NS_ERROR_FAILURE;
@ -921,7 +919,7 @@ RemoteLazyInputStream::AsyncLengthWait(nsIInputStreamLengthCallback* aCallback,
return NS_OK;
}
void RemoteLazyInputStream::LengthReady(int64_t aLength) {
void IPCBlobInputStream::LengthReady(int64_t aLength) {
nsCOMPtr<nsIInputStreamLengthCallback> lengthCallback;
nsCOMPtr<nsIEventTarget> lengthCallbackEventTarget;
@ -954,4 +952,5 @@ void RemoteLazyInputStream::LengthReady(int64_t aLength) {
}
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -4,11 +4,11 @@
* 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/. */
#ifndef mozilla_RemoteLazyInputStream_h
#define mozilla_RemoteLazyInputStream_h
#ifndef mozilla_dom_IPCBlobInputStream_h
#define mozilla_dom_IPCBlobInputStream_h
#include "mozilla/Mutex.h"
#include "mozIRemoteLazyInputStream.h"
#include "mozIIPCBlobInputStream.h"
#include "nsIAsyncInputStream.h"
#include "nsICloneableInputStream.h"
#include "nsIFileStreams.h"
@ -17,8 +17,9 @@
#include "nsCOMPtr.h"
namespace mozilla {
namespace dom {
class RemoteLazyInputStreamChild;
class IPCBlobInputStreamChild;
#define IPCBLOBINPUTSTREAM_IID \
{ \
@ -27,14 +28,14 @@ class RemoteLazyInputStreamChild;
} \
}
class RemoteLazyInputStream final : public nsIAsyncInputStream,
public nsIInputStreamCallback,
public nsICloneableInputStreamWithRange,
public nsIIPCSerializableInputStream,
public nsIAsyncFileMetadata,
public nsIInputStreamLength,
public nsIAsyncInputStreamLength,
public mozIRemoteLazyInputStream {
class IPCBlobInputStream final : public nsIAsyncInputStream,
public nsIInputStreamCallback,
public nsICloneableInputStreamWithRange,
public nsIIPCSerializableInputStream,
public nsIAsyncFileMetadata,
public nsIInputStreamLength,
public nsIAsyncInputStreamLength,
public mozIIPCBlobInputStream {
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIINPUTSTREAM
@ -48,13 +49,13 @@ class RemoteLazyInputStream final : public nsIAsyncInputStream,
NS_DECL_NSIINPUTSTREAMLENGTH
NS_DECL_NSIASYNCINPUTSTREAMLENGTH
explicit RemoteLazyInputStream(RemoteLazyInputStreamChild* aActor);
explicit IPCBlobInputStream(IPCBlobInputStreamChild* aActor);
void StreamReady(already_AddRefed<nsIInputStream> aInputStream);
void LengthReady(int64_t aLength);
// mozIRemoteLazyInputStream
// mozIIPCBlobInputStream
NS_IMETHOD_(nsIInputStream*) GetInternalStream() override {
if (mRemoteStream) {
return mRemoteStream;
@ -68,14 +69,14 @@ class RemoteLazyInputStream final : public nsIAsyncInputStream,
}
private:
~RemoteLazyInputStream();
~IPCBlobInputStream();
nsresult EnsureAsyncRemoteStream(const MutexAutoLock& aProofOfLock);
void InitWithExistingRange(uint64_t aStart, uint64_t aLength,
const MutexAutoLock& aProofOfLock);
RefPtr<RemoteLazyInputStreamChild> mActor;
RefPtr<IPCBlobInputStreamChild> mActor;
// This is the list of possible states.
enum {
@ -125,6 +126,7 @@ class RemoteLazyInputStream final : public nsIAsyncInputStream,
Mutex mMutex;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_RemoteLazyInputStream_h
#endif // mozilla_dom_IPCBlobInputStream_h

Просмотреть файл

@ -4,16 +4,15 @@
* 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 "RemoteLazyInputStreamChild.h"
#include "RemoteLazyInputStreamThread.h"
#include "IPCBlobInputStreamChild.h"
#include "IPCBlobInputStreamThread.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerRef.h"
namespace mozilla {
using namespace dom;
namespace dom {
namespace {
@ -21,7 +20,7 @@ namespace {
// thread.
class ShutdownRunnable final : public CancelableRunnable {
public:
explicit ShutdownRunnable(RemoteLazyInputStreamChild* aActor)
explicit ShutdownRunnable(IPCBlobInputStreamChild* aActor)
: CancelableRunnable("dom::ShutdownRunnable"), mActor(aActor) {}
NS_IMETHOD
@ -31,36 +30,35 @@ class ShutdownRunnable final : public CancelableRunnable {
}
private:
RefPtr<RemoteLazyInputStreamChild> mActor;
RefPtr<IPCBlobInputStreamChild> mActor;
};
// This runnable is used in case StreamNeeded() has been called on a non-owning
// thread.
class StreamNeededRunnable final : public CancelableRunnable {
public:
explicit StreamNeededRunnable(RemoteLazyInputStreamChild* aActor)
explicit StreamNeededRunnable(IPCBlobInputStreamChild* aActor)
: CancelableRunnable("dom::StreamNeededRunnable"), mActor(aActor) {}
NS_IMETHOD
Run() override {
MOZ_ASSERT(
mActor->State() != RemoteLazyInputStreamChild::eActiveMigrating &&
mActor->State() != RemoteLazyInputStreamChild::eInactiveMigrating);
if (mActor->State() == RemoteLazyInputStreamChild::eActive) {
MOZ_ASSERT(mActor->State() != IPCBlobInputStreamChild::eActiveMigrating &&
mActor->State() != IPCBlobInputStreamChild::eInactiveMigrating);
if (mActor->State() == IPCBlobInputStreamChild::eActive) {
mActor->SendStreamNeeded();
}
return NS_OK;
}
private:
RefPtr<RemoteLazyInputStreamChild> mActor;
RefPtr<IPCBlobInputStreamChild> mActor;
};
// When the stream has been received from the parent, we inform the
// RemoteLazyInputStream.
// IPCBlobInputStream.
class StreamReadyRunnable final : public CancelableRunnable {
public:
StreamReadyRunnable(RemoteLazyInputStream* aDestinationStream,
StreamReadyRunnable(IPCBlobInputStream* aDestinationStream,
already_AddRefed<nsIInputStream> aCreatedStream)
: CancelableRunnable("dom::StreamReadyRunnable"),
mDestinationStream(aDestinationStream),
@ -76,7 +74,7 @@ class StreamReadyRunnable final : public CancelableRunnable {
}
private:
RefPtr<RemoteLazyInputStream> mDestinationStream;
RefPtr<IPCBlobInputStream> mDestinationStream;
nsCOMPtr<nsIInputStream> mCreatedStream;
};
@ -84,29 +82,28 @@ class StreamReadyRunnable final : public CancelableRunnable {
// thread.
class LengthNeededRunnable final : public CancelableRunnable {
public:
explicit LengthNeededRunnable(RemoteLazyInputStreamChild* aActor)
explicit LengthNeededRunnable(IPCBlobInputStreamChild* aActor)
: CancelableRunnable("dom::LengthNeededRunnable"), mActor(aActor) {}
NS_IMETHOD
Run() override {
MOZ_ASSERT(
mActor->State() != RemoteLazyInputStreamChild::eActiveMigrating &&
mActor->State() != RemoteLazyInputStreamChild::eInactiveMigrating);
if (mActor->State() == RemoteLazyInputStreamChild::eActive) {
MOZ_ASSERT(mActor->State() != IPCBlobInputStreamChild::eActiveMigrating &&
mActor->State() != IPCBlobInputStreamChild::eInactiveMigrating);
if (mActor->State() == IPCBlobInputStreamChild::eActive) {
mActor->SendLengthNeeded();
}
return NS_OK;
}
private:
RefPtr<RemoteLazyInputStreamChild> mActor;
RefPtr<IPCBlobInputStreamChild> mActor;
};
// When the stream has been received from the parent, we inform the
// RemoteLazyInputStream.
// IPCBlobInputStream.
class LengthReadyRunnable final : public CancelableRunnable {
public:
LengthReadyRunnable(RemoteLazyInputStream* aDestinationStream, int64_t aSize)
LengthReadyRunnable(IPCBlobInputStream* aDestinationStream, int64_t aSize)
: CancelableRunnable("dom::LengthReadyRunnable"),
mDestinationStream(aDestinationStream),
mSize(aSize) {
@ -120,15 +117,15 @@ class LengthReadyRunnable final : public CancelableRunnable {
}
private:
RefPtr<RemoteLazyInputStream> mDestinationStream;
RefPtr<IPCBlobInputStream> mDestinationStream;
int64_t mSize;
};
} // namespace
RemoteLazyInputStreamChild::RemoteLazyInputStreamChild(const nsID& aID,
uint64_t aSize)
: mMutex("RemoteLazyInputStreamChild::mMutex"),
IPCBlobInputStreamChild::IPCBlobInputStreamChild(const nsID& aID,
uint64_t aSize)
: mMutex("IPCBlobInputStreamChild::mMutex"),
mID(aID),
mSize(aSize),
mState(eActive),
@ -142,7 +139,7 @@ RemoteLazyInputStreamChild::RemoteLazyInputStreamChild(const nsID& aID,
}
RefPtr<StrongWorkerRef> workerRef =
StrongWorkerRef::Create(workerPrivate, "RemoteLazyInputStreamChild");
StrongWorkerRef::Create(workerPrivate, "IPCBlobInputStreamChild");
if (!workerRef) {
return;
}
@ -152,12 +149,12 @@ RemoteLazyInputStreamChild::RemoteLazyInputStreamChild(const nsID& aID,
}
}
RemoteLazyInputStreamChild::~RemoteLazyInputStreamChild() = default;
IPCBlobInputStreamChild::~IPCBlobInputStreamChild() = default;
void RemoteLazyInputStreamChild::Shutdown() {
void IPCBlobInputStreamChild::Shutdown() {
MutexAutoLock lock(mMutex);
RefPtr<RemoteLazyInputStreamChild> kungFuDeathGrip = this;
RefPtr<IPCBlobInputStreamChild> kungFuDeathGrip = this;
mWorkerRef = nullptr;
mPendingOperations.Clear();
@ -168,7 +165,7 @@ void RemoteLazyInputStreamChild::Shutdown() {
}
}
void RemoteLazyInputStreamChild::ActorDestroy(
void IPCBlobInputStreamChild::ActorDestroy(
IProtocol::ActorDestroyReason aReason) {
bool migrating = false;
@ -185,16 +182,15 @@ void RemoteLazyInputStreamChild::ActorDestroy(
}
}
RemoteLazyInputStreamChild::ActorState RemoteLazyInputStreamChild::State() {
IPCBlobInputStreamChild::ActorState IPCBlobInputStreamChild::State() {
MutexAutoLock lock(mMutex);
return mState;
}
already_AddRefed<RemoteLazyInputStream>
RemoteLazyInputStreamChild::CreateStream() {
already_AddRefed<IPCBlobInputStream> IPCBlobInputStreamChild::CreateStream() {
bool shouldMigrate = false;
RefPtr<RemoteLazyInputStream> stream;
RefPtr<IPCBlobInputStream> stream;
{
MutexAutoLock lock(mMutex);
@ -206,19 +202,19 @@ RemoteLazyInputStreamChild::CreateStream() {
// The stream is active but maybe it is not running in the DOM-File thread.
// We should migrate it there.
if (mState == eActive &&
!RemoteLazyInputStreamThread::IsOnFileEventTarget(mOwningEventTarget)) {
!IPCBlobInputStreamThread::IsOnFileEventTarget(mOwningEventTarget)) {
MOZ_ASSERT(mStreams.IsEmpty());
shouldMigrate = true;
mState = eActiveMigrating;
RefPtr<RemoteLazyInputStreamThread> thread =
RemoteLazyInputStreamThread::GetOrCreate();
RefPtr<IPCBlobInputStreamThread> thread =
IPCBlobInputStreamThread::GetOrCreate();
MOZ_ASSERT(thread, "We cannot continue without DOMFile thread.");
// Create a new actor object to connect to the target thread.
RefPtr<RemoteLazyInputStreamChild> newActor =
new RemoteLazyInputStreamChild(mID, mSize);
RefPtr<IPCBlobInputStreamChild> newActor =
new IPCBlobInputStreamChild(mID, mSize);
{
MutexAutoLock newActorLock(newActor->mMutex);
@ -228,14 +224,14 @@ RemoteLazyInputStreamChild::CreateStream() {
newActor->mPendingOperations.SwapElements(mPendingOperations);
// Create the actual stream object.
stream = new RemoteLazyInputStream(newActor);
stream = new IPCBlobInputStream(newActor);
newActor->mStreams.AppendElement(stream);
}
// Perform the actual migration.
thread->MigrateActor(newActor);
} else {
stream = new RemoteLazyInputStream(this);
stream = new IPCBlobInputStream(this);
mStreams.AppendElement(stream);
}
}
@ -249,10 +245,10 @@ RemoteLazyInputStreamChild::CreateStream() {
return stream.forget();
}
void RemoteLazyInputStreamChild::ForgetStream(RemoteLazyInputStream* aStream) {
void IPCBlobInputStreamChild::ForgetStream(IPCBlobInputStream* aStream) {
MOZ_ASSERT(aStream);
RefPtr<RemoteLazyInputStreamChild> kungFuDeathGrip = this;
RefPtr<IPCBlobInputStreamChild> kungFuDeathGrip = this;
{
MutexAutoLock lock(mMutex);
@ -272,8 +268,8 @@ void RemoteLazyInputStreamChild::ForgetStream(RemoteLazyInputStream* aStream) {
mOwningEventTarget->Dispatch(runnable, NS_DISPATCH_NORMAL);
}
void RemoteLazyInputStreamChild::StreamNeeded(RemoteLazyInputStream* aStream,
nsIEventTarget* aEventTarget) {
void IPCBlobInputStreamChild::StreamNeeded(IPCBlobInputStream* aStream,
nsIEventTarget* aEventTarget) {
MutexAutoLock lock(mMutex);
if (mState == eInactive) {
@ -303,11 +299,11 @@ void RemoteLazyInputStreamChild::StreamNeeded(RemoteLazyInputStream* aStream,
mOwningEventTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
}
mozilla::ipc::IPCResult RemoteLazyInputStreamChild::RecvStreamReady(
mozilla::ipc::IPCResult IPCBlobInputStreamChild::RecvStreamReady(
const Maybe<IPCStream>& aStream) {
nsCOMPtr<nsIInputStream> stream = mozilla::ipc::DeserializeIPCStream(aStream);
RefPtr<RemoteLazyInputStream> pendingStream;
RefPtr<IPCBlobInputStream> pendingStream;
nsCOMPtr<nsIEventTarget> eventTarget;
{
@ -331,7 +327,7 @@ mozilla::ipc::IPCResult RemoteLazyInputStreamChild::RecvStreamReady(
RefPtr<StreamReadyRunnable> runnable =
new StreamReadyRunnable(pendingStream, stream.forget());
// If RemoteLazyInputStream::AsyncWait() has been executed without passing an
// If IPCBlobInputStream::AsyncWait() has been executed without passing an
// event target, we run the callback synchronous because any thread could be
// result to be the wrong one. See more in nsIAsyncInputStream::asyncWait
// documentation.
@ -344,8 +340,8 @@ mozilla::ipc::IPCResult RemoteLazyInputStreamChild::RecvStreamReady(
return IPC_OK();
}
void RemoteLazyInputStreamChild::LengthNeeded(RemoteLazyInputStream* aStream,
nsIEventTarget* aEventTarget) {
void IPCBlobInputStreamChild::LengthNeeded(IPCBlobInputStream* aStream,
nsIEventTarget* aEventTarget) {
MutexAutoLock lock(mMutex);
if (mState == eInactive) {
@ -375,9 +371,9 @@ void RemoteLazyInputStreamChild::LengthNeeded(RemoteLazyInputStream* aStream,
mOwningEventTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
}
mozilla::ipc::IPCResult RemoteLazyInputStreamChild::RecvLengthReady(
mozilla::ipc::IPCResult IPCBlobInputStreamChild::RecvLengthReady(
const int64_t& aLength) {
RefPtr<RemoteLazyInputStream> pendingStream;
RefPtr<IPCBlobInputStream> pendingStream;
nsCOMPtr<nsIEventTarget> eventTarget;
{
@ -406,15 +402,14 @@ mozilla::ipc::IPCResult RemoteLazyInputStreamChild::RecvLengthReady(
return IPC_OK();
}
void RemoteLazyInputStreamChild::Migrated() {
void IPCBlobInputStreamChild::Migrated() {
MutexAutoLock lock(mMutex);
MOZ_ASSERT(mState == eInactiveMigrating);
mWorkerRef = nullptr;
mOwningEventTarget = GetCurrentSerialEventTarget();
MOZ_ASSERT(
RemoteLazyInputStreamThread::IsOnFileEventTarget(mOwningEventTarget));
MOZ_ASSERT(IPCBlobInputStreamThread::IsOnFileEventTarget(mOwningEventTarget));
// Maybe we have no reasons to keep this actor alive.
if (mStreams.IsEmpty()) {
@ -437,4 +432,5 @@ void RemoteLazyInputStreamChild::Migrated() {
}
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -4,24 +4,22 @@
* 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/. */
#ifndef mozilla_RemoteLazyInputStreamChild_h
#define mozilla_RemoteLazyInputStreamChild_h
#ifndef mozilla_dom_IPCBlobInputStreamChild_h
#define mozilla_dom_IPCBlobInputStreamChild_h
#include "mozilla/PRemoteLazyInputStreamChild.h"
#include "mozilla/RemoteLazyInputStream.h"
#include "mozilla/dom/PIPCBlobInputStreamChild.h"
#include "mozilla/dom/IPCBlobInputStream.h"
#include "mozilla/Mutex.h"
#include "mozilla/UniquePtr.h"
#include "nsTArray.h"
namespace mozilla {
class RemoteLazyInputStream;
namespace dom {
class ThreadSafeWorkerRef;
}
class RemoteLazyInputStreamChild final : public PRemoteLazyInputStreamChild {
class IPCBlobInputStream;
class ThreadSafeWorkerRef;
class IPCBlobInputStreamChild final : public PIPCBlobInputStreamChild {
public:
enum ActorState {
// The actor is connected via IPDL to the parent.
@ -39,29 +37,27 @@ class RemoteLazyInputStreamChild final : public PRemoteLazyInputStreamChild {
eInactiveMigrating,
};
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RemoteLazyInputStreamChild, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IPCBlobInputStreamChild, final)
RemoteLazyInputStreamChild(const nsID& aID, uint64_t aSize);
IPCBlobInputStreamChild(const nsID& aID, uint64_t aSize);
void ActorDestroy(IProtocol::ActorDestroyReason aReason) override;
ActorState State();
already_AddRefed<RemoteLazyInputStream> CreateStream();
already_AddRefed<IPCBlobInputStream> CreateStream();
void ForgetStream(RemoteLazyInputStream* aStream);
void ForgetStream(IPCBlobInputStream* aStream);
const nsID& ID() const { return mID; }
uint64_t Size() const { return mSize; }
void StreamNeeded(RemoteLazyInputStream* aStream,
nsIEventTarget* aEventTarget);
void StreamNeeded(IPCBlobInputStream* aStream, nsIEventTarget* aEventTarget);
mozilla::ipc::IPCResult RecvStreamReady(const Maybe<IPCStream>& aStream);
void LengthNeeded(RemoteLazyInputStream* aStream,
nsIEventTarget* aEventTarget);
void LengthNeeded(IPCBlobInputStream* aStream, nsIEventTarget* aEventTarget);
mozilla::ipc::IPCResult RecvLengthReady(const int64_t& aLength);
@ -70,12 +66,12 @@ class RemoteLazyInputStreamChild final : public PRemoteLazyInputStreamChild {
void Migrated();
private:
~RemoteLazyInputStreamChild();
~IPCBlobInputStreamChild();
// Raw pointers because these streams keep this actor alive. When the last
// stream is unregister, the actor will be deleted. This list is protected by
// mutex.
nsTArray<RemoteLazyInputStream*> mStreams;
nsTArray<IPCBlobInputStream*> mStreams;
// This mutex protects mStreams because that can be touched in any thread.
Mutex mMutex;
@ -87,7 +83,7 @@ class RemoteLazyInputStreamChild final : public PRemoteLazyInputStreamChild {
// This struct and the array are used for creating streams when needed.
struct PendingOperation {
RefPtr<RemoteLazyInputStream> mStream;
RefPtr<IPCBlobInputStream> mStream;
nsCOMPtr<nsIEventTarget> mEventTarget;
enum {
eStreamNeeded,
@ -98,9 +94,10 @@ class RemoteLazyInputStreamChild final : public PRemoteLazyInputStreamChild {
nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
RefPtr<dom::ThreadSafeWorkerRef> mWorkerRef;
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_RemoteLazyInputStreamChild_h
#endif // mozilla_dom_IPCBlobInputStreamChild_h

Просмотреть файл

@ -4,20 +4,20 @@
* 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 "RemoteLazyInputStreamParent.h"
#include "IPCBlobInputStreamParent.h"
#include "IPCBlobInputStreamStorage.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/InputStreamLengthHelper.h"
#include "nsContentUtils.h"
#include "RemoteLazyInputStreamStorage.h"
namespace mozilla {
namespace dom {
template <typename M>
/* static */
already_AddRefed<RemoteLazyInputStreamParent>
RemoteLazyInputStreamParent::Create(nsIInputStream* aInputStream,
uint64_t aSize, uint64_t aChildID,
nsresult* aRv, M* aManager) {
already_AddRefed<IPCBlobInputStreamParent> IPCBlobInputStreamParent::Create(
nsIInputStream* aInputStream, uint64_t aSize, uint64_t aChildID,
nsresult* aRv, M* aManager) {
MOZ_ASSERT(aInputStream);
MOZ_ASSERT(aRv);
@ -27,55 +27,54 @@ RemoteLazyInputStreamParent::Create(nsIInputStream* aInputStream,
return nullptr;
}
RemoteLazyInputStreamStorage::Get()->AddStream(aInputStream, id, aSize,
aChildID);
IPCBlobInputStreamStorage::Get()->AddStream(aInputStream, id, aSize,
aChildID);
RefPtr<RemoteLazyInputStreamParent> parent =
new RemoteLazyInputStreamParent(id, aSize, aManager);
RefPtr<IPCBlobInputStreamParent> parent =
new IPCBlobInputStreamParent(id, aSize, aManager);
return parent.forget();
}
/* static */
already_AddRefed<RemoteLazyInputStreamParent>
RemoteLazyInputStreamParent::Create(const nsID& aID, uint64_t aSize,
PBackgroundParent* aManager) {
RefPtr<RemoteLazyInputStreamParent> actor =
new RemoteLazyInputStreamParent(aID, aSize, aManager);
already_AddRefed<IPCBlobInputStreamParent> IPCBlobInputStreamParent::Create(
const nsID& aID, uint64_t aSize, PBackgroundParent* aManager) {
RefPtr<IPCBlobInputStreamParent> actor =
new IPCBlobInputStreamParent(aID, aSize, aManager);
actor->mCallback = RemoteLazyInputStreamStorage::Get()->TakeCallback(aID);
actor->mCallback = IPCBlobInputStreamStorage::Get()->TakeCallback(aID);
return actor.forget();
}
template already_AddRefed<RemoteLazyInputStreamParent>
RemoteLazyInputStreamParent::Create<mozilla::ipc::PBackgroundParent>(
template already_AddRefed<IPCBlobInputStreamParent>
IPCBlobInputStreamParent::Create<mozilla::ipc::PBackgroundParent>(
nsIInputStream*, uint64_t, uint64_t, nsresult*,
mozilla::ipc::PBackgroundParent*);
/* static */
already_AddRefed<RemoteLazyInputStreamParent>
RemoteLazyInputStreamParent::Create(const nsID& aID, uint64_t aSize,
SocketProcessParent* aManager) {
RefPtr<RemoteLazyInputStreamParent> actor =
new RemoteLazyInputStreamParent(aID, aSize, aManager);
already_AddRefed<IPCBlobInputStreamParent> IPCBlobInputStreamParent::Create(
const nsID& aID, uint64_t aSize, SocketProcessParent* aManager) {
RefPtr<IPCBlobInputStreamParent> actor =
new IPCBlobInputStreamParent(aID, aSize, aManager);
actor->mCallback = RemoteLazyInputStreamStorage::Get()->TakeCallback(aID);
actor->mCallback = IPCBlobInputStreamStorage::Get()->TakeCallback(aID);
return actor.forget();
}
template already_AddRefed<RemoteLazyInputStreamParent>
RemoteLazyInputStreamParent::Create<mozilla::net::SocketProcessParent>(
template already_AddRefed<IPCBlobInputStreamParent>
IPCBlobInputStreamParent::Create<mozilla::net::SocketProcessParent>(
nsIInputStream*, uint64_t, uint64_t, nsresult*,
mozilla::net::SocketProcessParent*);
template already_AddRefed<RemoteLazyInputStreamParent>
RemoteLazyInputStreamParent::Create<ContentParent>(nsIInputStream*, uint64_t,
uint64_t, nsresult*,
ContentParent*);
template already_AddRefed<IPCBlobInputStreamParent>
IPCBlobInputStreamParent::Create<ContentParent>(nsIInputStream*, uint64_t,
uint64_t, nsresult*,
ContentParent*);
RemoteLazyInputStreamParent::RemoteLazyInputStreamParent(
const nsID& aID, uint64_t aSize, ContentParent* aManager)
IPCBlobInputStreamParent::IPCBlobInputStreamParent(const nsID& aID,
uint64_t aSize,
ContentParent* aManager)
: mID(aID),
mSize(aSize),
mContentManager(aManager),
@ -83,8 +82,9 @@ RemoteLazyInputStreamParent::RemoteLazyInputStreamParent(
mSocketProcessManager(nullptr),
mMigrating(false) {}
RemoteLazyInputStreamParent::RemoteLazyInputStreamParent(
const nsID& aID, uint64_t aSize, PBackgroundParent* aManager)
IPCBlobInputStreamParent::IPCBlobInputStreamParent(const nsID& aID,
uint64_t aSize,
PBackgroundParent* aManager)
: mID(aID),
mSize(aSize),
mContentManager(nullptr),
@ -92,7 +92,7 @@ RemoteLazyInputStreamParent::RemoteLazyInputStreamParent(
mSocketProcessManager(nullptr),
mMigrating(false) {}
RemoteLazyInputStreamParent::RemoteLazyInputStreamParent(
IPCBlobInputStreamParent::IPCBlobInputStreamParent(
const nsID& aID, uint64_t aSize, SocketProcessParent* aManager)
: mID(aID),
mSize(aSize),
@ -101,7 +101,7 @@ RemoteLazyInputStreamParent::RemoteLazyInputStreamParent(
mSocketProcessManager(aManager),
mMigrating(false) {}
void RemoteLazyInputStreamParent::ActorDestroy(
void IPCBlobInputStreamParent::ActorDestroy(
IProtocol::ActorDestroyReason aReason) {
MOZ_ASSERT(mContentManager || mPBackgroundManager || mSocketProcessManager);
@ -109,11 +109,10 @@ void RemoteLazyInputStreamParent::ActorDestroy(
mPBackgroundManager = nullptr;
mSocketProcessManager = nullptr;
RefPtr<RemoteLazyInputStreamParentCallback> callback;
RefPtr<IPCBlobInputStreamParentCallback> callback;
mCallback.swap(callback);
RefPtr<RemoteLazyInputStreamStorage> storage =
RemoteLazyInputStreamStorage::Get();
RefPtr<IPCBlobInputStreamStorage> storage = IPCBlobInputStreamStorage::Get();
if (mMigrating) {
if (callback && storage) {
@ -132,20 +131,20 @@ void RemoteLazyInputStreamParent::ActorDestroy(
}
}
void RemoteLazyInputStreamParent::SetCallback(
RemoteLazyInputStreamParentCallback* aCallback) {
void IPCBlobInputStreamParent::SetCallback(
IPCBlobInputStreamParentCallback* aCallback) {
MOZ_ASSERT(aCallback);
MOZ_ASSERT(!mCallback);
mCallback = aCallback;
}
mozilla::ipc::IPCResult RemoteLazyInputStreamParent::RecvStreamNeeded() {
mozilla::ipc::IPCResult IPCBlobInputStreamParent::RecvStreamNeeded() {
MOZ_ASSERT(mContentManager || mPBackgroundManager || mSocketProcessManager);
nsCOMPtr<nsIInputStream> stream;
RemoteLazyInputStreamStorage::Get()->GetStream(mID, 0, mSize,
getter_AddRefs(stream));
IPCBlobInputStreamStorage::Get()->GetStream(mID, 0, mSize,
getter_AddRefs(stream));
if (!stream) {
if (!SendStreamReady(Nothing())) {
return IPC_FAIL(this, "SendStreamReady failed");
@ -178,12 +177,12 @@ mozilla::ipc::IPCResult RemoteLazyInputStreamParent::RecvStreamNeeded() {
return IPC_OK();
}
mozilla::ipc::IPCResult RemoteLazyInputStreamParent::RecvLengthNeeded() {
mozilla::ipc::IPCResult IPCBlobInputStreamParent::RecvLengthNeeded() {
MOZ_ASSERT(mContentManager || mPBackgroundManager || mSocketProcessManager);
nsCOMPtr<nsIInputStream> stream;
RemoteLazyInputStreamStorage::Get()->GetStream(mID, 0, mSize,
getter_AddRefs(stream));
IPCBlobInputStreamStorage::Get()->GetStream(mID, 0, mSize,
getter_AddRefs(stream));
if (!stream) {
if (!SendLengthReady(-1)) {
return IPC_FAIL(this, "SendLengthReady failed");
@ -198,7 +197,7 @@ mozilla::ipc::IPCResult RemoteLazyInputStreamParent::RecvLengthNeeded() {
return IPC_OK();
}
RefPtr<RemoteLazyInputStreamParent> self = this;
RefPtr<IPCBlobInputStreamParent> self = this;
InputStreamLengthHelper::GetAsyncLength(stream, [self](int64_t aLength) {
if (self->mContentManager || self->mPBackgroundManager ||
self->mSocketProcessManager) {
@ -209,21 +208,22 @@ mozilla::ipc::IPCResult RemoteLazyInputStreamParent::RecvLengthNeeded() {
return IPC_OK();
}
mozilla::ipc::IPCResult RemoteLazyInputStreamParent::RecvClose() {
mozilla::ipc::IPCResult IPCBlobInputStreamParent::RecvClose() {
MOZ_ASSERT(mContentManager || mPBackgroundManager || mSocketProcessManager);
Unused << Send__delete__(this);
return IPC_OK();
}
mozilla::ipc::IPCResult RemoteLazyInputStreamParent::Recv__delete__() {
mozilla::ipc::IPCResult IPCBlobInputStreamParent::Recv__delete__() {
MOZ_ASSERT(mContentManager || mPBackgroundManager || mSocketProcessManager);
mMigrating = true;
return IPC_OK();
}
bool RemoteLazyInputStreamParent::HasValidStream() const {
return RemoteLazyInputStreamStorage::Get()->HasStream(mID);
bool IPCBlobInputStreamParent::HasValidStream() const {
return IPCBlobInputStreamStorage::Get()->HasStream(mID);
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -4,50 +4,48 @@
* 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/. */
#ifndef mozilla_RemoteLazyInputStreamParent_h
#define mozilla_RemoteLazyInputStreamParent_h
#ifndef mozilla_dom_IPCBlobInputStreamParent_h
#define mozilla_dom_IPCBlobInputStreamParent_h
#include "mozilla/PRemoteLazyInputStreamParent.h"
#include "mozilla/dom/PIPCBlobInputStreamParent.h"
class nsIInputStream;
namespace mozilla {
namespace dom {
class ContentParent;
}
namespace net {
class SocketProcessParent;
}
class NS_NO_VTABLE RemoteLazyInputStreamParentCallback {
namespace dom {
class NS_NO_VTABLE IPCBlobInputStreamParentCallback {
public:
virtual void ActorDestroyed(const nsID& aID) = 0;
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
protected:
virtual ~RemoteLazyInputStreamParentCallback() = default;
virtual ~IPCBlobInputStreamParentCallback() = default;
};
class RemoteLazyInputStreamParent final : public PRemoteLazyInputStreamParent {
class IPCBlobInputStreamParent final : public PIPCBlobInputStreamParent {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RemoteLazyInputStreamParent, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IPCBlobInputStreamParent, final)
// The size of the inputStream must be passed as argument in order to avoid
// the use of nsIInputStream::Available() which could open a fileDescriptor in
// case the stream is a nsFileStream.
template <typename M>
static already_AddRefed<RemoteLazyInputStreamParent> Create(
static already_AddRefed<IPCBlobInputStreamParent> Create(
nsIInputStream* aInputStream, uint64_t aSize, uint64_t aChildID,
nsresult* aRv, M* aManager);
static already_AddRefed<RemoteLazyInputStreamParent> Create(
static already_AddRefed<IPCBlobInputStreamParent> Create(
const nsID& aID, uint64_t aSize,
mozilla::ipc::PBackgroundParent* aManager);
static already_AddRefed<RemoteLazyInputStreamParent> Create(
static already_AddRefed<IPCBlobInputStreamParent> Create(
const nsID& aID, uint64_t aSize,
mozilla::net::SocketProcessParent* aManager);
@ -57,7 +55,7 @@ class RemoteLazyInputStreamParent final : public PRemoteLazyInputStreamParent {
uint64_t Size() const { return mSize; }
void SetCallback(RemoteLazyInputStreamParentCallback* aCallback);
void SetCallback(IPCBlobInputStreamParentCallback* aCallback);
mozilla::ipc::IPCResult RecvStreamNeeded();
@ -70,31 +68,32 @@ class RemoteLazyInputStreamParent final : public PRemoteLazyInputStreamParent {
bool HasValidStream() const;
private:
RemoteLazyInputStreamParent(const nsID& aID, uint64_t aSize,
mozilla::dom::ContentParent* aManager);
IPCBlobInputStreamParent(const nsID& aID, uint64_t aSize,
ContentParent* aManager);
RemoteLazyInputStreamParent(const nsID& aID, uint64_t aSize,
mozilla::ipc::PBackgroundParent* aManager);
IPCBlobInputStreamParent(const nsID& aID, uint64_t aSize,
mozilla::ipc::PBackgroundParent* aManager);
RemoteLazyInputStreamParent(const nsID& aID, uint64_t aSize,
mozilla::net::SocketProcessParent* aManager);
IPCBlobInputStreamParent(const nsID& aID, uint64_t aSize,
mozilla::net::SocketProcessParent* aManager);
~RemoteLazyInputStreamParent() = default;
~IPCBlobInputStreamParent() = default;
const nsID mID;
const uint64_t mSize;
// Only 1 of these is set. Raw pointer because these managers are keeping
// the parent actor alive. The pointers will be nullified in ActorDestroyed.
mozilla::dom::ContentParent* mContentManager;
ContentParent* mContentManager;
mozilla::ipc::PBackgroundParent* mPBackgroundManager;
mozilla::net::SocketProcessParent* mSocketProcessManager;
RefPtr<RemoteLazyInputStreamParentCallback> mCallback;
RefPtr<IPCBlobInputStreamParentCallback> mCallback;
bool mMigrating;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_RemoteLazyInputStreamParent_h
#endif // mozilla_dom_IPCBlobInputStreamParent_h

Просмотреть файл

@ -4,41 +4,41 @@
* 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 "IPCBlobInputStreamStorage.h"
#include "mozilla/SlicedInputStream.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPtr.h"
#include "nsIPropertyBag2.h"
#include "nsStreamUtils.h"
#include "RemoteLazyInputStreamStorage.h"
namespace mozilla {
using namespace hal;
namespace dom {
namespace {
StaticMutex gMutex;
StaticRefPtr<RemoteLazyInputStreamStorage> gStorage;
StaticRefPtr<IPCBlobInputStreamStorage> gStorage;
} // namespace
NS_INTERFACE_MAP_BEGIN(RemoteLazyInputStreamStorage)
NS_INTERFACE_MAP_BEGIN(IPCBlobInputStreamStorage)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(RemoteLazyInputStreamStorage)
NS_IMPL_RELEASE(RemoteLazyInputStreamStorage)
NS_IMPL_ADDREF(IPCBlobInputStreamStorage)
NS_IMPL_RELEASE(IPCBlobInputStreamStorage)
/* static */
RemoteLazyInputStreamStorage* RemoteLazyInputStreamStorage::Get() {
return gStorage;
}
IPCBlobInputStreamStorage* IPCBlobInputStreamStorage::Get() { return gStorage; }
/* static */
void RemoteLazyInputStreamStorage::Initialize() {
void IPCBlobInputStreamStorage::Initialize() {
MOZ_ASSERT(!gStorage);
gStorage = new RemoteLazyInputStreamStorage();
gStorage = new IPCBlobInputStreamStorage();
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
@ -48,8 +48,8 @@ void RemoteLazyInputStreamStorage::Initialize() {
}
NS_IMETHODIMP
RemoteLazyInputStreamStorage::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
IPCBlobInputStreamStorage::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
if (!strcmp(aTopic, "xpcom-shutdown")) {
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
@ -85,9 +85,9 @@ RemoteLazyInputStreamStorage::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
void RemoteLazyInputStreamStorage::AddStream(nsIInputStream* aInputStream,
const nsID& aID, uint64_t aSize,
uint64_t aChildID) {
void IPCBlobInputStreamStorage::AddStream(nsIInputStream* aInputStream,
const nsID& aID, uint64_t aSize,
uint64_t aChildID) {
MOZ_ASSERT(aInputStream);
StreamData* data = new StreamData();
@ -99,7 +99,7 @@ void RemoteLazyInputStreamStorage::AddStream(nsIInputStream* aInputStream,
mStorage.Put(aID, data);
}
nsCOMPtr<nsIInputStream> RemoteLazyInputStreamStorage::ForgetStream(
nsCOMPtr<nsIInputStream> IPCBlobInputStreamStorage::ForgetStream(
const nsID& aID) {
UniquePtr<StreamData> entry;
@ -113,15 +113,15 @@ nsCOMPtr<nsIInputStream> RemoteLazyInputStreamStorage::ForgetStream(
return std::move(entry->mInputStream);
}
bool RemoteLazyInputStreamStorage::HasStream(const nsID& aID) {
bool IPCBlobInputStreamStorage::HasStream(const nsID& aID) {
mozilla::StaticMutexAutoLock lock(gMutex);
StreamData* data = mStorage.Get(aID);
return !!data;
}
void RemoteLazyInputStreamStorage::GetStream(const nsID& aID, uint64_t aStart,
uint64_t aLength,
nsIInputStream** aInputStream) {
void IPCBlobInputStreamStorage::GetStream(const nsID& aID, uint64_t aStart,
uint64_t aLength,
nsIInputStream** aInputStream) {
*aInputStream = nullptr;
nsCOMPtr<nsIInputStream> inputStream;
@ -175,8 +175,8 @@ void RemoteLazyInputStreamStorage::GetStream(const nsID& aID, uint64_t aStart,
clonedStream.forget(aInputStream);
}
void RemoteLazyInputStreamStorage::StoreCallback(
const nsID& aID, RemoteLazyInputStreamParentCallback* aCallback) {
void IPCBlobInputStreamStorage::StoreCallback(
const nsID& aID, IPCBlobInputStreamParentCallback* aCallback) {
MOZ_ASSERT(aCallback);
mozilla::StaticMutexAutoLock lock(gMutex);
@ -187,17 +187,18 @@ void RemoteLazyInputStreamStorage::StoreCallback(
}
}
already_AddRefed<RemoteLazyInputStreamParentCallback>
RemoteLazyInputStreamStorage::TakeCallback(const nsID& aID) {
already_AddRefed<IPCBlobInputStreamParentCallback>
IPCBlobInputStreamStorage::TakeCallback(const nsID& aID) {
mozilla::StaticMutexAutoLock lock(gMutex);
StreamData* data = mStorage.Get(aID);
if (!data) {
return nullptr;
}
RefPtr<RemoteLazyInputStreamParentCallback> callback;
RefPtr<IPCBlobInputStreamParentCallback> callback;
data->mCallback.swap(callback);
return callback.forget();
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -4,8 +4,8 @@
* 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/. */
#ifndef mozilla_RemoteLazyInputStreamStorage_h
#define mozilla_RemoteLazyInputStreamStorage_h
#ifndef mozilla_dom_IPCBlobInputStreamStorage_h
#define mozilla_dom_IPCBlobInputStreamStorage_h
#include "mozilla/RefPtr.h"
#include "nsClassHashtable.h"
@ -15,10 +15,11 @@ class nsIInputStream;
struct nsID;
namespace mozilla {
namespace dom {
class RemoteLazyInputStreamParentCallback;
class IPCBlobInputStreamParentCallback;
class RemoteLazyInputStreamStorage final : public nsIObserver {
class IPCBlobInputStreamStorage final : public nsIObserver {
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIOBSERVER
@ -26,7 +27,7 @@ class RemoteLazyInputStreamStorage final : public nsIObserver {
// This initializes the singleton and it must be called on the main-thread.
static void Initialize();
static RemoteLazyInputStreamStorage* Get();
static IPCBlobInputStreamStorage* Get();
void AddStream(nsIInputStream* aInputStream, const nsID& aID, uint64_t aSize,
uint64_t aChildID);
@ -41,18 +42,18 @@ class RemoteLazyInputStreamStorage final : public nsIObserver {
nsIInputStream** aInputStream);
void StoreCallback(const nsID& aID,
RemoteLazyInputStreamParentCallback* aCallback);
IPCBlobInputStreamParentCallback* aCallback);
already_AddRefed<RemoteLazyInputStreamParentCallback> TakeCallback(
already_AddRefed<IPCBlobInputStreamParentCallback> TakeCallback(
const nsID& aID);
private:
RemoteLazyInputStreamStorage() = default;
~RemoteLazyInputStreamStorage() = default;
IPCBlobInputStreamStorage() = default;
~IPCBlobInputStreamStorage() = default;
struct StreamData {
nsCOMPtr<nsIInputStream> mInputStream;
RefPtr<RemoteLazyInputStreamParentCallback> mCallback;
RefPtr<IPCBlobInputStreamParentCallback> mCallback;
// This is the Process ID connected with this inputStream. We need to store
// this information in order to delete it if the child crashes/shutdowns.
@ -64,6 +65,7 @@ class RemoteLazyInputStreamStorage final : public nsIObserver {
nsClassHashtable<nsIDHashKey, StreamData> mStorage;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_RemoteLazyInputStreamStorage_h
#endif // mozilla_dom_IPCBlobInputStreamStorage_h

Просмотреть файл

@ -4,7 +4,7 @@
* 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 "RemoteLazyInputStreamThread.h"
#include "IPCBlobInputStreamThread.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/StaticMutex.h"
@ -15,10 +15,14 @@
namespace mozilla {
using namespace ipc;
namespace dom {
namespace {
StaticMutex gRemoteLazyThreadMutex;
StaticRefPtr<RemoteLazyInputStreamThread> gRemoteLazyThread;
StaticMutex gIPCBlobThreadMutex;
StaticRefPtr<IPCBlobInputStreamThread> gIPCBlobThread;
bool gShutdownHasStarted = false;
class ThreadInitializeRunnable final : public Runnable {
@ -27,24 +31,23 @@ class ThreadInitializeRunnable final : public Runnable {
NS_IMETHOD
Run() override {
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
MOZ_ASSERT(gRemoteLazyThread);
gRemoteLazyThread->InitializeOnMainThread();
mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
MOZ_ASSERT(gIPCBlobThread);
gIPCBlobThread->InitializeOnMainThread();
return NS_OK;
}
};
class MigrateActorRunnable final : public Runnable {
public:
explicit MigrateActorRunnable(RemoteLazyInputStreamChild* aActor)
explicit MigrateActorRunnable(IPCBlobInputStreamChild* aActor)
: Runnable("dom::MigrateActorRunnable"), mActor(aActor) {
MOZ_ASSERT(mActor);
}
NS_IMETHOD
Run() override {
MOZ_ASSERT(mActor->State() ==
RemoteLazyInputStreamChild::eInactiveMigrating);
MOZ_ASSERT(mActor->State() == IPCBlobInputStreamChild::eInactiveMigrating);
PBackgroundChild* actorChild =
BackgroundChild::GetOrCreateForCurrentThread();
@ -52,8 +55,8 @@ class MigrateActorRunnable final : public Runnable {
return NS_OK;
}
if (actorChild->SendPRemoteLazyInputStreamConstructor(mActor, mActor->ID(),
mActor->Size())) {
if (actorChild->SendPIPCBlobInputStreamConstructor(mActor, mActor->ID(),
mActor->Size())) {
mActor->Migrated();
}
@ -63,15 +66,15 @@ class MigrateActorRunnable final : public Runnable {
private:
~MigrateActorRunnable() = default;
RefPtr<RemoteLazyInputStreamChild> mActor;
RefPtr<IPCBlobInputStreamChild> mActor;
};
} // namespace
NS_IMPL_ISUPPORTS(RemoteLazyInputStreamThread, nsIObserver, nsIEventTarget)
NS_IMPL_ISUPPORTS(IPCBlobInputStreamThread, nsIObserver, nsIEventTarget)
/* static */
bool RemoteLazyInputStreamThread::IsOnFileEventTarget(
bool IPCBlobInputStreamThread::IsOnFileEventTarget(
nsIEventTarget* aEventTarget) {
MOZ_ASSERT(aEventTarget);
@ -82,40 +85,40 @@ bool RemoteLazyInputStreamThread::IsOnFileEventTarget(
return true;
}
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
return gRemoteLazyThread && aEventTarget == gRemoteLazyThread->mThread;
mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
return gIPCBlobThread && aEventTarget == gIPCBlobThread->mThread;
}
/* static */
RemoteLazyInputStreamThread* RemoteLazyInputStreamThread::Get() {
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
IPCBlobInputStreamThread* IPCBlobInputStreamThread::Get() {
mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
if (gShutdownHasStarted) {
return nullptr;
}
return gRemoteLazyThread;
return gIPCBlobThread;
}
/* static */
RemoteLazyInputStreamThread* RemoteLazyInputStreamThread::GetOrCreate() {
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
IPCBlobInputStreamThread* IPCBlobInputStreamThread::GetOrCreate() {
mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
if (gShutdownHasStarted) {
return nullptr;
}
if (!gRemoteLazyThread) {
gRemoteLazyThread = new RemoteLazyInputStreamThread();
if (!gRemoteLazyThread->Initialize()) {
if (!gIPCBlobThread) {
gIPCBlobThread = new IPCBlobInputStreamThread();
if (!gIPCBlobThread->Initialize()) {
return nullptr;
}
}
return gRemoteLazyThread;
return gIPCBlobThread;
}
bool RemoteLazyInputStreamThread::Initialize() {
bool IPCBlobInputStreamThread::Initialize() {
nsCOMPtr<nsIThread> thread;
nsresult rv = NS_NewNamedThread("DOM File", getter_AddRefs(thread));
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -142,7 +145,7 @@ bool RemoteLazyInputStreamThread::Initialize() {
return true;
}
void RemoteLazyInputStreamThread::InitializeOnMainThread() {
void IPCBlobInputStreamThread::InitializeOnMainThread() {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
@ -158,11 +161,11 @@ void RemoteLazyInputStreamThread::InitializeOnMainThread() {
}
NS_IMETHODIMP
RemoteLazyInputStreamThread::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
IPCBlobInputStreamThread::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
MOZ_ASSERT(!strcmp(aTopic, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID));
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
if (mThread) {
mThread->Shutdown();
@ -170,16 +173,15 @@ RemoteLazyInputStreamThread::Observe(nsISupports* aSubject, const char* aTopic,
}
gShutdownHasStarted = true;
gRemoteLazyThread = nullptr;
gIPCBlobThread = nullptr;
return NS_OK;
}
void RemoteLazyInputStreamThread::MigrateActor(
RemoteLazyInputStreamChild* aActor) {
MOZ_ASSERT(aActor->State() == RemoteLazyInputStreamChild::eInactiveMigrating);
void IPCBlobInputStreamThread::MigrateActor(IPCBlobInputStreamChild* aActor) {
MOZ_ASSERT(aActor->State() == IPCBlobInputStreamChild::eInactiveMigrating);
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
if (gShutdownHasStarted) {
return;
@ -194,8 +196,8 @@ void RemoteLazyInputStreamThread::MigrateActor(
MigrateActorInternal(aActor);
}
void RemoteLazyInputStreamThread::MigrateActorInternal(
RemoteLazyInputStreamChild* aActor) {
void IPCBlobInputStreamThread::MigrateActorInternal(
IPCBlobInputStreamChild* aActor) {
RefPtr<Runnable> runnable = new MigrateActorRunnable(aActor);
mThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
}
@ -203,21 +205,21 @@ void RemoteLazyInputStreamThread::MigrateActorInternal(
// nsIEventTarget
NS_IMETHODIMP_(bool)
RemoteLazyInputStreamThread::IsOnCurrentThreadInfallible() {
IPCBlobInputStreamThread::IsOnCurrentThreadInfallible() {
return mThread->IsOnCurrentThread();
}
NS_IMETHODIMP
RemoteLazyInputStreamThread::IsOnCurrentThread(bool* aRetval) {
IPCBlobInputStreamThread::IsOnCurrentThread(bool* aRetval) {
return mThread->IsOnCurrentThread(aRetval);
}
NS_IMETHODIMP
RemoteLazyInputStreamThread::Dispatch(already_AddRefed<nsIRunnable> aRunnable,
uint32_t aFlags) {
IPCBlobInputStreamThread::Dispatch(already_AddRefed<nsIRunnable> aRunnable,
uint32_t aFlags) {
nsCOMPtr<nsIRunnable> runnable(aRunnable);
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
if (gShutdownHasStarted) {
return NS_ERROR_NOT_INITIALIZED;
@ -227,27 +229,28 @@ RemoteLazyInputStreamThread::Dispatch(already_AddRefed<nsIRunnable> aRunnable,
}
NS_IMETHODIMP
RemoteLazyInputStreamThread::DispatchFromScript(nsIRunnable* aRunnable,
uint32_t aFlags) {
IPCBlobInputStreamThread::DispatchFromScript(nsIRunnable* aRunnable,
uint32_t aFlags) {
nsCOMPtr<nsIRunnable> runnable(aRunnable);
return Dispatch(runnable.forget(), aFlags);
}
NS_IMETHODIMP
RemoteLazyInputStreamThread::DelayedDispatch(already_AddRefed<nsIRunnable>,
uint32_t) {
IPCBlobInputStreamThread::DelayedDispatch(already_AddRefed<nsIRunnable>,
uint32_t) {
return NS_ERROR_NOT_IMPLEMENTED;
}
bool IsOnDOMFileThread() {
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
MOZ_ASSERT(!gShutdownHasStarted);
MOZ_ASSERT(gRemoteLazyThread);
MOZ_ASSERT(gIPCBlobThread);
return gRemoteLazyThread->IsOnCurrentThreadInfallible();
return gIPCBlobThread->IsOnCurrentThreadInfallible();
}
void AssertIsOnDOMFileThread() { MOZ_ASSERT(IsOnDOMFileThread()); }
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -4,10 +4,10 @@
* 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/. */
#ifndef mozilla_RemoteLazyInputStreamThread_h
#define mozilla_RemoteLazyInputStreamThread_h
#ifndef mozilla_dom_IPCBlobInputStreamThread_h
#define mozilla_dom_IPCBlobInputStreamThread_h
#include "mozilla/RemoteLazyInputStreamChild.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
#include "nsIEventTarget.h"
#include "nsIObserver.h"
#include "nsTArray.h"
@ -15,11 +15,12 @@
class nsIThread;
namespace mozilla {
namespace dom {
class RemoteLazyInputStreamChild;
class IPCBlobInputStreamChild;
class RemoteLazyInputStreamThread final : public nsIObserver,
public nsIEventTarget {
class IPCBlobInputStreamThread final : public nsIObserver,
public nsIEventTarget {
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIOBSERVER
@ -27,32 +28,33 @@ class RemoteLazyInputStreamThread final : public nsIObserver,
static bool IsOnFileEventTarget(nsIEventTarget* aEventTarget);
static RemoteLazyInputStreamThread* Get();
static IPCBlobInputStreamThread* Get();
static RemoteLazyInputStreamThread* GetOrCreate();
static IPCBlobInputStreamThread* GetOrCreate();
void MigrateActor(RemoteLazyInputStreamChild* aActor);
void MigrateActor(IPCBlobInputStreamChild* aActor);
bool Initialize();
void InitializeOnMainThread();
private:
~RemoteLazyInputStreamThread() = default;
~IPCBlobInputStreamThread() = default;
void MigrateActorInternal(RemoteLazyInputStreamChild* aActor);
void MigrateActorInternal(IPCBlobInputStreamChild* aActor);
nsCOMPtr<nsIThread> mThread;
// This is populated if MigrateActor() is called before the initialization of
// the thread.
nsTArray<RefPtr<RemoteLazyInputStreamChild>> mPendingActors;
nsTArray<RefPtr<IPCBlobInputStreamChild>> mPendingActors;
};
bool IsOnDOMFileThread();
void AssertIsOnDOMFileThread();
} // namespace dom
} // namespace mozilla
#endif // mozilla_RemoteLazyInputStreamThread_h
#endif // mozilla_dom_IPCBlobInputStreamThread_h

Просмотреть файл

@ -5,10 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "IPCBlobUtils.h"
#include "RemoteLazyInputStream.h"
#include "RemoteLazyInputStreamChild.h"
#include "RemoteLazyInputStreamParent.h"
#include "RemoteLazyInputStreamUtils.h"
#include "IPCBlobInputStream.h"
#include "IPCBlobInputStreamChild.h"
#include "IPCBlobInputStreamParent.h"
#include "IPCBlobInputStreamStorage.h"
#include "mozilla/dom/IPCBlob.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/PBackgroundParent.h"
@ -17,7 +17,6 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "RemoteLazyInputStreamStorage.h"
#include "StreamBlobImpl.h"
#include "prtime.h"
@ -31,21 +30,20 @@ namespace IPCBlobUtils {
already_AddRefed<BlobImpl> Deserialize(const IPCBlob& aIPCBlob) {
nsCOMPtr<nsIInputStream> inputStream;
const RemoteLazyStream& stream = aIPCBlob.inputStream();
const IPCBlobStream& stream = aIPCBlob.inputStream();
switch (stream.type()) {
// Parent to child: when an nsIInputStream is sent from parent to child, the
// child receives a RemoteLazyInputStream actor.
case RemoteLazyStream::TPRemoteLazyInputStreamChild: {
RemoteLazyInputStreamChild* actor =
static_cast<RemoteLazyInputStreamChild*>(
stream.get_PRemoteLazyInputStreamChild());
// child receives a IPCBlobInputStream actor.
case IPCBlobStream::TPIPCBlobInputStreamChild: {
IPCBlobInputStreamChild* actor = static_cast<IPCBlobInputStreamChild*>(
stream.get_PIPCBlobInputStreamChild());
inputStream = actor->CreateStream();
break;
}
// Child to Parent: when a blob is created on the content process send it's
// sent to the parent, we have an IPCStream object.
case RemoteLazyStream::TIPCStream:
case IPCBlobStream::TIPCStream:
MOZ_ASSERT(XRE_IsParentProcess());
inputStream = DeserializeIPCStream(stream.get_IPCStream());
break;
@ -77,6 +75,103 @@ already_AddRefed<BlobImpl> Deserialize(const IPCBlob& aIPCBlob) {
return blobImpl.forget();
}
template <typename M>
nsresult SerializeInputStreamParent(nsIInputStream* aInputStream,
uint64_t aSize, uint64_t aChildID,
PIPCBlobInputStreamParent*& aActorParent,
M* aManager) {
// Parent to Child we always send a IPCBlobInputStream.
MOZ_ASSERT(XRE_IsParentProcess());
nsCOMPtr<nsIInputStream> stream = aInputStream;
// In case this is a IPCBlobInputStream, we don't want to create a loop:
// IPCBlobInputStreamParent -> IPCBlobInputStream ->
// IPCBlobInputStreamParent. Let's use the underlying inputStream instead.
nsCOMPtr<mozIIPCBlobInputStream> ipcBlobInputStream =
do_QueryInterface(aInputStream);
if (ipcBlobInputStream) {
stream = ipcBlobInputStream->GetInternalStream();
// If we don't have an underlying stream, it's better to terminate here
// instead of sending an 'empty' IPCBlobInputStream actor on the other side,
// unable to be used.
if (NS_WARN_IF(!stream)) {
return NS_ERROR_FAILURE;
}
}
nsresult rv;
RefPtr<IPCBlobInputStreamParent> parentActor =
IPCBlobInputStreamParent::Create(stream, aSize, aChildID, &rv, aManager);
if (!parentActor) {
return rv;
}
if (!aManager->SendPIPCBlobInputStreamConstructor(
parentActor, parentActor->ID(), parentActor->Size())) {
return NS_ERROR_FAILURE;
}
aActorParent = parentActor;
return NS_OK;
}
template <typename M>
nsresult SerializeInputStreamChild(nsIInputStream* aInputStream,
IPCBlobStream& aIPCBlob, M* aManager) {
AutoIPCStream ipcStream(true /* delayed start */);
if (!ipcStream.Serialize(aInputStream, aManager)) {
return NS_ERROR_FAILURE;
}
aIPCBlob = ipcStream.TakeValue();
return NS_OK;
}
nsresult SerializeInputStream(nsIInputStream* aInputStream, uint64_t aSize,
PIPCBlobInputStreamParent*& aActorParent,
ContentParent* aManager) {
return SerializeInputStreamParent(aInputStream, aSize, aManager->ChildID(),
aActorParent, aManager);
}
nsresult SerializeInputStream(nsIInputStream* aInputStream, uint64_t aSize,
PIPCBlobInputStreamParent*& aActorParent,
PBackgroundParent* aManager) {
return SerializeInputStreamParent(aInputStream, aSize,
BackgroundParent::GetChildID(aManager),
aActorParent, aManager);
}
nsresult SerializeInputStream(nsIInputStream* aInputStream, uint64_t aSize,
IPCBlobStream& aIPCBlob,
ContentParent* aManager) {
aIPCBlob = (PIPCBlobInputStreamParent*)nullptr;
return SerializeInputStreamParent(aInputStream, aSize, aManager->ChildID(),
aIPCBlob.get_PIPCBlobInputStreamParent(),
aManager);
}
nsresult SerializeInputStream(nsIInputStream* aInputStream, uint64_t aSize,
IPCBlobStream& aIPCBlob,
PBackgroundParent* aManager) {
aIPCBlob = (PIPCBlobInputStreamParent*)nullptr;
return SerializeInputStreamParent(
aInputStream, aSize, BackgroundParent::GetChildID(aManager),
aIPCBlob.get_PIPCBlobInputStreamParent(), aManager);
}
nsresult SerializeInputStream(nsIInputStream* aInputStream, uint64_t aSize,
IPCBlobStream& aIPCBlob, ContentChild* aManager) {
return SerializeInputStreamChild(aInputStream, aIPCBlob, aManager);
}
nsresult SerializeInputStream(nsIInputStream* aInputStream, uint64_t aSize,
IPCBlobStream& aIPCBlob,
PBackgroundChild* aManager) {
return SerializeInputStreamChild(aInputStream, aIPCBlob, aManager);
}
template <typename M>
nsresult SerializeInternal(BlobImpl* aBlobImpl, M* aManager,
IPCBlob& aIPCBlob) {
@ -130,14 +225,12 @@ nsresult SerializeInternal(BlobImpl* aBlobImpl, M* aManager,
return rv.StealNSResult();
}
RemoteLazyStream stream;
rv = RemoteLazyInputStreamUtils::SerializeInputStream(
inputStream, aIPCBlob.size(), stream, aManager);
rv = SerializeInputStream(inputStream, aIPCBlob.size(),
aIPCBlob.inputStream(), aManager);
if (NS_WARN_IF(rv.Failed())) {
return rv.StealNSResult();
}
aIPCBlob.inputStream() = stream;
return NS_OK;
}

Просмотреть файл

@ -48,7 +48,7 @@
* the parent process).
*
* DocumentLoadListener uses blobs to serialize the POST data back to the
* content process (for insertion into session history). This lets it correctly
* content process (for insertion into session history). This lets it correclty
* handle OS files by reference, and avoid copying the underlying buffer data
* unless it is read. This can hopefully be removed once SessionHistory is
* handled in the parent process.
@ -89,34 +89,34 @@
* in order to do some networking, or whatever.
*
* For this reason, IPCBlobUtils uses a particular protocol for serializing
* nsIInputStream parent to child: PRemoteLazyInputStream. This protocol keeps
* the original nsIInputStream alive on the parent side, and gives its size and
* a UUID to the child side. The child side creates a RemoteLazyInputStream and
* that is incapsulated into a StreamBlobImpl.
* nsIInputStream parent to child: PIPCBlobInputStream. This protocol keeps the
* original nsIInputStream alive on the parent side, and gives its size and a
* UUID to the child side. The child side creates a IPCBlobInputStream and that
* is incapsulated into a StreamBlobImpl.
*
* The UUID is useful when the content process sends the same nsIInputStream
* back to the parent process because, the only information it has to share is
* the UUID. Each nsIInputStream sent via PRemoteLazyInputStream, is registered
* into the RemoteLazyInputStreamStorage.
* the UUID. Each nsIInputStream sent via PIPCBlobInputStream, is registered
* into the IPCBlobInputStreamStorage.
*
* On the content process side, RemoteLazyInputStream is a special inputStream:
* On the content process side, IPCBlobInputStream is a special inputStream:
* the only reliable methods are:
* - nsIInputStream.available() - the size is shared by PRemoteLazyInputStream
* - nsIInputStream.available() - the size is shared by PIPCBlobInputStream
* actor.
* - nsIIPCSerializableInputStream.serialize() - we can give back this stream to
* the parent because we know its UUID.
* - nsICloneableInputStream.cloneable() and nsICloneableInputStream.clone() -
* this stream can be cloned. We just need to have a reference of the
* PRemoteLazyInputStream actor and its UUID.
* PIPCBlobInputStream actor and its UUID.
* - nsIAsyncInputStream.asyncWait() - see next section.
*
* Any other method (read, readSegment and so on) will fail if asyncWait() is
* not previously called (see the next section). Basically, this inputStream
* cannot be used synchronously for any 'real' reading operation.
*
* When the parent receives the serialization of a RemoteLazyInputStream, it is
* When the parent receives the serialization of a IPCBlobInputStream, it is
* able to retrieve the correct nsIInputStream using the UUID and
* RemoteLazyInputStreamStorage.
* IPCBlobInputStreamStorage.
*
* Parent to Child Streams, FileReader and BlobURL
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -124,30 +124,30 @@
* The FileReader and BlobURL scenarios are described here.
*
* When content process needs to read data from a Blob sent from the parent
* process, it must do it asynchronously using RemoteLazyInputStream as a
* process, it must do it asynchronously using IPCBlobInputStream as a
* nsIAsyncInputStream stream. This happens calling
* RemoteLazyInputStream.asyncWait(). At that point, the child actor will send a
* IPCBlobInputStream.asyncWait(). At that point, the child actor will send a
* StreamNeeded() IPC message to the parent side. When this is received, the
* parent retrieves the 'real' stream from RemoteLazyInputStreamStorage using
* the UUID, it will serialize the 'real' stream, and it will send it to the
* child side.
* parent retrieves the 'real' stream from IPCBlobInputStreamStorage using the
* UUID, it will serialize the 'real' stream, and it will send it to the child
* side.
*
* When the 'real' stream is received (RecvStreamReady()), the asyncWait
* callback will be executed and, from that moment, any RemoteLazyInputStream
* callback will be executed and, from that moment, any IPCBlobInputStream
* method will be forwarded to the 'real' stream ones. This means that the
* reading will be available.
*
* RemoteLazyInputStream Thread
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* DOM-File Thread
* ~~~~~~~~~~~~~~~
*
* RemoteLazyInputStreamChild actor can be created in any thread (sort of) and
* IPCBlobInputStreamChild actor can be created in any thread (sort of) and
* their top-level IPDL protocol is PBackground. These actors are wrapped by 1
* or more RemoteLazyInputStream objects in order to expose nsIInputStream
* or more IPCBlobInputStream objects in order to expose nsIInputStream
* interface and be thread-safe.
*
* But IPDL actors are not thread-safe and any SendFoo() method must be executed
* on the owning thread. This means that this thread must be kept alive for the
* life-time of the RemoteLazyInputStream.
* life-time of the IPCBlobInputStream.
*
* In doing this, there are 2 main issues:
* a. if a remote Blob is created on a worker (because of a
@ -158,27 +158,27 @@
* used on another thread (note that nsIInputStream could do I/O and usually
* they are used on special I/O threads).
*
* In order to avoid this, RemoteLazyInputStreamChild are 'migrated' to a
* DOM-File thread. This is done in this way:
* In order to avoid this, IPCBlobInputStreamChild are 'migrated' to a DOM-File
* thread. This is done in this way:
*
* 1. If RemoteLazyInputStreamChild actor is not already owned by DOM-File
* thread, it calls Send__delete__ in order to inform the parent side that we
* don't need this IPC channel on the current thread.
* 2. A new RemoteLazyInputStreamChild is created. RemoteLazyInputStreamThread
* is used to assign this actor to the DOM-File thread.
* RemoteLazyInputStreamThread::GetOrCreate() creates the DOM-File thread if
* it doesn't exist yet. Pending operations and RemoteLazyInputStreams are
* moved onto the new actor.
* 3. RemoteLazyInputStreamParent::Recv__delete__ is called on the parent side
* and the parent actor is deleted. Doing this we don't remove the UUID from
* RemoteLazyInputStreamStorage.
* 4. The RemoteLazyInputStream constructor is sent with the new
* RemoteLazyInputStreamChild actor, with the DOM-File thread's PBackground
* as its manager.
* 5. When the new RemoteLazyInputStreamParent actor is created, it will receive
* 1. If IPCBlobInputStreamChild actor is not already owned by DOM-File thread,
* it calls Send__delete__ in order to inform the parent side that we don't
* need this IPC channel on the current thread.
* 2. A new IPCBlobInputStreamChild is created. IPCBlobInputStreamThread is
* used to assign this actor to the DOM-File thread.
* IPCBlobInputStreamThread::GetOrCreate() creates the DOM-File thread if it
* doesn't exist yet. Pending operations and IPCBlobInputStreams are moved
* onto the new actor.
* 3. IPCBlobInputStreamParent::Recv__delete__ is called on the parent side and
* the parent actor is deleted. Doing this we don't remove the UUID from
* IPCBlobInputStreamStorage.
* 4. The IPCBlobInputStream constructor is sent with the new
* IPCBlobInputStreamChild actor, with the DOM-File thread's PBackground as
* its manager.
* 5. When the new IPCBlobInputStreamParent actor is created, it will receive
* the same UUID of the previous parent actor. The nsIInputStream will be
* retrieved from RemoteLazyInputStreamStorage.
* 6. In order to avoid leaks, RemoteLazyInputStreamStorage will monitor child
* retrieved from IPCBlobInputStreamStorage.
* 6. In order to avoid leaks, IPCBlobInputStreamStorage will monitor child
* processes and in case one of them dies, it will release the
* nsIInputStream objects belonging to that process.
*
@ -189,9 +189,9 @@
* IPCBlob and nsIAsyncInputStream
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* RemoteLazyInputStream is always async. If the remote inputStream is not
* async, RemoteLazyInputStream will create a pipe stream around it in order to
* be consistently async.
* IPCBlobInputStream is always async. If the remote inputStream is not async,
* IPCBlobInputStream will create a pipe stream around it in order to be
* consistently async.
*
* Slicing IPCBlob
* ~~~~~~~~~~~~~~~
@ -204,34 +204,33 @@
* inputStream is seekable, the pipe will not be, and in order to reach the
* starting point, SlicedInputStream will do consecutive read()s.
*
* This problem is fixed implmenting nsICloneableWithRange in
* RemoteLazyInputStream and using cloneWithRange() when a StreamBlobImpl is
* sliced. When the remote stream is received, it will be sliced directly.
* This problem is fixed implmenting nsICloneableWithRange in IPCBlobInputStream
* and using cloneWithRange() when a StreamBlobImpl is sliced. When the remote
* stream is received, it will be sliced directly.
*
* If we want to represent the hierarchy of the InputStream classes, instead
* of having: |SlicedInputStream(RemoteLazyInputStream(Async
* Pipe(RemoteStream)))|, we have: |RemoteLazyInputStream(Async
* Pipe(SlicedInputStream(RemoteStream)))|.
* of having: |SlicedInputStream(IPCBlobInputStream(Async Pipe(RemoteStream)))|,
* we have: |IPCBlobInputStream(Async Pipe(SlicedInputStream(RemoteStream)))|.
*
* When RemoteLazyInputStream is serialized and sent to the parent process,
* start and range are sent too and SlicedInputStream is used in the parent side
* as well.
* When IPCBlobInputStream is serialized and sent to the parent process, start
* and range are sent too and SlicedInputStream is used in the parent side as
* well.
*
* Socket Process
* ~~~~~~~~~~~~~~
*
* The socket process is a separate process used to do networking operations.
* When a website sends a blob as the body of a POST/PUT request, we need to
* send the corresponding RemoteLazyInputStream to the socket process.
* send the corresponding IPCBlobInputStream to the socket process.
*
* This is the only serialization of RemoteLazyInputStream from parent to child
* This is the only serialization of IPCBlobInputStream from parent to child
* process and it works _only_ for the socket process. Do not expose this
* serialization to PContent or PBackground or any other top-level IPDL protocol
* without a DOM File peer review!
*
* The main difference between Socket Process is that DOM-File thread is not
* used. Here is a list of reasons:
* - DOM-File moves the ownership of the RemoteLazyInputStream actors to
* - DOM-File moves the ownership of the IPCBlobInputStream actors to
* PBackground, but in the Socket Process we don't have PBackground (yet?)
* - Socket Process is a stable process with a simple life-time configuration:
* we can keep the actors on the main-thread because no Workers are involved.
@ -250,6 +249,7 @@ namespace dom {
class IPCBlob;
class ContentChild;
class ContentParent;
class PIPCBlobInputStreamParent;
namespace IPCBlobUtils {
@ -270,6 +270,14 @@ nsresult Serialize(BlobImpl* aBlobImpl,
mozilla::ipc::PBackgroundParent* aManager,
IPCBlob& aIPCBlob);
nsresult SerializeInputStream(nsIInputStream* aInputStream, uint64_t aSize,
PIPCBlobInputStreamParent*& aActorParent,
ContentParent* aManager);
nsresult SerializeInputStream(nsIInputStream* aInputStream, uint64_t aSize,
PIPCBlobInputStreamParent*& aActorParent,
mozilla::ipc::PBackgroundParent* aManager);
// WARNING: If you pass any actor which does not have P{Content,Background} as
// its toplevel protocol, this method will MOZ_CRASH.
nsresult SerializeUntyped(BlobImpl* aBlobImpl, mozilla::ipc::IProtocol* aActor,

Просмотреть файл

@ -5,7 +5,7 @@
include protocol PBackground;
include protocol PChildToParentStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
include protocol PParentToChildStream;
include IPCBlob;

Просмотреть файл

@ -12,8 +12,9 @@ include protocol PSocketProcess;
include IPCStream;
namespace mozilla {
namespace dom {
refcounted protocol PRemoteLazyInputStream
refcounted protocol PIPCBlobInputStream
{
manager PBackground or PContent or PSocketProcess;
@ -43,4 +44,6 @@ both:
async __delete__();
};
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -5,8 +5,8 @@
include protocol PBackground;
include protocol PChildToParentStream;
include protocol PFileDescriptorSet;
include protocol PIPCBlobInputStream;
include protocol PParentToChildStream;
include protocol PRemoteLazyInputStream;
include IPCBlob;

Просмотреть файл

@ -1,119 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "RemoteLazyInputStreamUtils.h"
#include "RemoteLazyInputStream.h"
#include "RemoteLazyInputStreamChild.h"
#include "RemoteLazyInputStreamParent.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/PBackgroundParent.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "RemoteLazyInputStreamStorage.h"
#include "StreamBlobImpl.h"
namespace mozilla {
namespace {
template <typename M>
nsresult SerializeInputStreamParent(nsIInputStream* aInputStream,
uint64_t aSize, uint64_t aChildID,
PRemoteLazyInputStreamParent*& aActorParent,
M* aManager) {
// Parent to Child we always send a RemoteLazyInputStream.
MOZ_ASSERT(XRE_IsParentProcess());
nsCOMPtr<nsIInputStream> stream = aInputStream;
// In case this is a RemoteLazyInputStream, we don't want to create a loop:
// RemoteLazyInputStreamParent -> RemoteLazyInputStream ->
// RemoteLazyInputStreamParent. Let's use the underlying inputStream instead.
nsCOMPtr<mozIRemoteLazyInputStream> remoteLazyInputStream =
do_QueryInterface(aInputStream);
if (remoteLazyInputStream) {
stream = remoteLazyInputStream->GetInternalStream();
// If we don't have an underlying stream, it's better to terminate here
// instead of sending an 'empty' RemoteLazyInputStream actor on the other
// side, unable to be used.
if (NS_WARN_IF(!stream)) {
return NS_ERROR_FAILURE;
}
}
nsresult rv;
RefPtr<RemoteLazyInputStreamParent> parentActor =
RemoteLazyInputStreamParent::Create(stream, aSize, aChildID, &rv,
aManager);
if (!parentActor) {
return rv;
}
if (!aManager->SendPRemoteLazyInputStreamConstructor(
parentActor, parentActor->ID(), parentActor->Size())) {
return NS_ERROR_FAILURE;
}
aActorParent = parentActor;
return NS_OK;
}
} // anonymous namespace
// static
nsresult RemoteLazyInputStreamUtils::SerializeInputStream(
nsIInputStream* aInputStream, uint64_t aSize, RemoteLazyStream& aOutStream,
ContentParent* aManager) {
PRemoteLazyInputStreamParent* actor = nullptr;
nsresult rv = SerializeInputStreamParent(
aInputStream, aSize, aManager->ChildID(), actor, aManager);
NS_ENSURE_SUCCESS(rv, rv);
aOutStream = actor;
return NS_OK;
}
// static
nsresult RemoteLazyInputStreamUtils::SerializeInputStream(
nsIInputStream* aInputStream, uint64_t aSize, RemoteLazyStream& aOutStream,
PBackgroundParent* aManager) {
PRemoteLazyInputStreamParent* actor = nullptr;
nsresult rv = SerializeInputStreamParent(
aInputStream, aSize, BackgroundParent::GetChildID(aManager), actor,
aManager);
NS_ENSURE_SUCCESS(rv, rv);
aOutStream = actor;
return NS_OK;
}
// static
nsresult RemoteLazyInputStreamUtils::SerializeInputStream(
nsIInputStream* aInputStream, uint64_t aSize, RemoteLazyStream& aOutStream,
ContentChild* aManager) {
AutoIPCStream ipcStream(true /* delayed start */);
if (!ipcStream.Serialize(aInputStream, aManager)) {
return NS_ERROR_FAILURE;
}
aOutStream = ipcStream.TakeValue();
return NS_OK;
}
// static
nsresult RemoteLazyInputStreamUtils::SerializeInputStream(
nsIInputStream* aInputStream, uint64_t aSize, RemoteLazyStream& aOutStream,
PBackgroundChild* aManager) {
AutoIPCStream ipcStream(true /* delayed start */);
if (!ipcStream.Serialize(aInputStream, aManager)) {
return NS_ERROR_FAILURE;
}
aOutStream = ipcStream.TakeValue();
return NS_OK;
}
} // namespace mozilla

Просмотреть файл

@ -1,54 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_RemoteLazyInputStreamUtils_h
#define mozilla_RemoteLazyInputStreamUtils_h
/*
* RemoteLazyInputStream was previously part of the IPCBlob world.
* See IPCBlobUtils.h to know how to use it. As a follow up, the documentation
* will be partially moved here too.
*/
namespace mozilla {
class RemoteLazyStream;
namespace ipc {
class IPCStream;
class PBackgroundChild;
class PBackgroundParent;
} // namespace ipc
namespace dom {
class ContentChild;
class ContentParent;
} // namespace dom
class RemoteLazyInputStreamUtils final {
public:
static nsresult SerializeInputStream(nsIInputStream* aInputStream,
uint64_t aSize,
RemoteLazyStream& aOutStream,
dom::ContentParent* aManager);
static nsresult SerializeInputStream(
nsIInputStream* aInputStream, uint64_t aSize,
RemoteLazyStream& aOutStream, mozilla::ipc::PBackgroundParent* aManager);
static nsresult SerializeInputStream(nsIInputStream* aInputStream,
uint64_t aSize,
RemoteLazyStream& aOutStream,
dom::ContentChild* aManager);
static nsresult SerializeInputStream(
nsIInputStream* aInputStream, uint64_t aSize,
RemoteLazyStream& aOutStream, mozilla::ipc::PBackgroundChild* aManager);
};
} // namespace mozilla
#endif // mozilla_RemoteLazyInputStreamUtils_h

Просмотреть файл

@ -8,7 +8,7 @@ with Files("**"):
BUG_COMPONENT = ("Core", "DOM: File")
XPIDL_SOURCES += [
'mozIRemoteLazyInputStream.idl',
'mozIIPCBlobInputStream.idl',
]
XPIDL_MODULE = 'dom'
@ -16,29 +16,24 @@ XPIDL_MODULE = 'dom'
EXPORTS.mozilla.dom += [
'FileCreatorChild.h',
'FileCreatorParent.h',
'IPCBlobInputStream.h',
'IPCBlobInputStreamChild.h',
'IPCBlobInputStreamParent.h',
'IPCBlobInputStreamStorage.h',
'IPCBlobUtils.h',
'TemporaryIPCBlobChild.h',
'TemporaryIPCBlobParent.h',
]
EXPORTS.mozilla += [
'RemoteLazyInputStream.h',
'RemoteLazyInputStreamChild.h',
'RemoteLazyInputStreamParent.h',
'RemoteLazyInputStreamStorage.h',
'RemoteLazyInputStreamUtils.h',
]
UNIFIED_SOURCES += [
'FileCreatorChild.cpp',
'FileCreatorParent.cpp',
'IPCBlobInputStream.cpp',
'IPCBlobInputStreamChild.cpp',
'IPCBlobInputStreamParent.cpp',
'IPCBlobInputStreamStorage.cpp',
'IPCBlobInputStreamThread.cpp',
'IPCBlobUtils.cpp',
'RemoteLazyInputStream.cpp',
'RemoteLazyInputStreamChild.cpp',
'RemoteLazyInputStreamParent.cpp',
'RemoteLazyInputStreamStorage.cpp',
'RemoteLazyInputStreamThread.cpp',
'RemoteLazyInputStreamUtils.cpp',
'TemporaryIPCBlobChild.cpp',
'TemporaryIPCBlobParent.cpp',
]
@ -47,7 +42,7 @@ IPDL_SOURCES += [
'BlobTypes.ipdlh',
'IPCBlob.ipdlh',
'PFileCreator.ipdl',
'PRemoteLazyInputStream.ipdl',
'PIPCBlobInputStream.ipdl',
'PTemporaryIPCBlob.ipdl',
]

Просмотреть файл

@ -7,11 +7,10 @@
interface nsIInputStream;
/*
* A simple interface to get the underlying stream from an
* RemoteLazyInputStream.
* A simple interface to get the underlying stream from an IPCBlobInputStream.
*/
[scriptable, builtinclass, uuid(4125585f-b0c2-4964-a83c-4b0d99f26d49)]
interface mozIRemoteLazyInputStream : nsISupports
interface mozIIPCBlobInputStream : nsISupports
{
[notxpcom, noscript] nsIInputStream GetInternalStream();
};

Просмотреть файл

@ -6,8 +6,8 @@ include protocol PBackgroundFileRequest;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include IPCBlob;

Просмотреть файл

@ -5,10 +5,10 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include protocol PIPCBlobInputStream;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include IPCBlob;

Просмотреть файл

@ -22,7 +22,7 @@
#include "IndexedDatabaseInlines.h"
#include "js/Array.h" // JS::NewArrayObject, JS::SetArrayLength
#include "js/Date.h" // JS::NewDateObject, JS::TimeClip
#include <mozIRemoteLazyInputStream.h>
#include <mozIIPCBlobInputStream.h>
#include "mozilla/ArrayAlgorithm.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/CycleCollectedJSRuntime.h"
@ -2758,8 +2758,7 @@ nsresult BackgroundRequestChild::PreprocessHelper::ProcessStream() {
// SnappyUncompressInputStream doesn't support reading from async input
// streams.
nsCOMPtr<mozIRemoteLazyInputStream> blobInputStream =
do_QueryInterface(mStream);
nsCOMPtr<mozIIPCBlobInputStream> blobInputStream = do_QueryInterface(mStream);
MOZ_ASSERT(blobInputStream);
nsCOMPtr<nsIInputStream> internalInputStream =

Просмотреть файл

@ -62,6 +62,7 @@
#include "mozilla/dom/indexedDB/PBackgroundIDBTransactionParent.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBVersionChangeTransactionParent.h"
#include "mozilla/dom/indexedDB/PBackgroundIndexedDBUtilsParent.h"
#include "mozilla/dom/IPCBlobInputStreamParent.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/quota/CheckedUnsafePtr.h"
#include "mozilla/dom/quota/Client.h"
@ -76,7 +77,6 @@
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/ipc/PBackground.h"
#include "mozilla/ipc/PBackgroundParent.h"
#include "mozilla/RemoteLazyInputStreamParent.h"
#include "mozilla/Scoped.h"
#include "mozilla/storage/Variant.h"
#include "mozIStorageFunction.h"
@ -6053,7 +6053,7 @@ class Database::StartTransactionOp final
};
class Database::UnmapBlobCallback final
: public RemoteLazyInputStreamParentCallback {
: public IPCBlobInputStreamParentCallback {
SafeRefPtr<Database> mDatabase;
public:
@ -13796,12 +13796,11 @@ void Database::MapBlob(const IPCBlob& aIPCBlob,
SafeRefPtr<FileInfo> aFileInfo) {
AssertIsOnBackgroundThread();
const RemoteLazyStream& stream = aIPCBlob.inputStream();
MOZ_ASSERT(stream.type() == RemoteLazyStream::TPRemoteLazyInputStreamParent);
const IPCBlobStream& stream = aIPCBlob.inputStream();
MOZ_ASSERT(stream.type() == IPCBlobStream::TPIPCBlobInputStreamParent);
RemoteLazyInputStreamParent* actor =
static_cast<RemoteLazyInputStreamParent*>(
stream.get_PRemoteLazyInputStreamParent());
IPCBlobInputStreamParent* actor = static_cast<IPCBlobInputStreamParent*>(
stream.get_PIPCBlobInputStreamParent());
MOZ_ASSERT(!mMappedBlobs.GetWeak(actor->ID()));
mMappedBlobs.Put(actor->ID(), AsRefPtr(std::move(aFileInfo)));
@ -13854,25 +13853,25 @@ void Database::Stringify(nsACString& aResult) const {
SafeRefPtr<FileInfo> Database::GetBlob(const IPCBlob& aIPCBlob) {
AssertIsOnBackgroundThread();
const RemoteLazyStream& stream = aIPCBlob.inputStream();
MOZ_ASSERT(stream.type() == RemoteLazyStream::TIPCStream);
const IPCBlobStream& stream = aIPCBlob.inputStream();
MOZ_ASSERT(stream.type() == IPCBlobStream::TIPCStream);
const IPCStream& ipcStream = stream.get_IPCStream();
const InputStreamParams& inputStreamParams = ipcStream.stream();
if (inputStreamParams.type() !=
InputStreamParams::TRemoteLazyInputStreamParams) {
InputStreamParams::TIPCBlobInputStreamParams) {
return nullptr;
}
const RemoteLazyInputStreamParams& ipcBlobInputStreamParams =
inputStreamParams.get_RemoteLazyInputStreamParams();
const IPCBlobInputStreamParams& ipcBlobInputStreamParams =
inputStreamParams.get_IPCBlobInputStreamParams();
if (ipcBlobInputStreamParams.type() !=
RemoteLazyInputStreamParams::TRemoteLazyInputStreamRef) {
IPCBlobInputStreamParams::TIPCBlobInputStreamRef) {
return nullptr;
}
const nsID& id = ipcBlobInputStreamParams.get_RemoteLazyInputStreamRef().id();
const nsID& id = ipcBlobInputStreamParams.get_IPCBlobInputStreamRef().id();
RefPtr<FileInfo> fileInfo;
if (!mMappedBlobs.Get(id, getter_AddRefs(fileInfo))) {

Просмотреть файл

@ -7,8 +7,8 @@ include protocol PBackgroundIDBVersionChangeTransaction;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include PBackgroundIDBSharedTypes;

Просмотреть файл

@ -10,8 +10,8 @@ include protocol PBackgroundIDBVersionChangeTransaction;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include IPCBlob;
include InputStreamParams;

Просмотреть файл

@ -7,8 +7,8 @@ include protocol PBackgroundIDBVersionChangeTransaction;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include PBackgroundIDBSharedTypes;

Просмотреть файл

@ -6,8 +6,8 @@ include protocol PBackgroundIDBDatabaseFile;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include DOMTypes;
include IPCBlob;

Просмотреть файл

@ -9,8 +9,8 @@ include protocol PBackgroundIDBRequest;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include PBackgroundIDBSharedTypes;

Просмотреть файл

@ -51,6 +51,7 @@
#include "mozilla/dom/ExternalHelperAppChild.h"
#include "mozilla/dom/GetFilesHelper.h"
#include "mozilla/dom/InProcessChild.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSProcessActorBinding.h"
@ -97,7 +98,6 @@
#include "mozilla/PerformanceUtils.h"
#include "mozilla/plugins/PluginInstanceParent.h"
#include "mozilla/plugins/PluginModuleParent.h"
#include "mozilla/RemoteLazyInputStreamChild.h"
#include "mozilla/widget/ScreenManager.h"
#include "mozilla/widget/WidgetMessageUtils.h"
#include "nsBaseDragService.h"
@ -1803,11 +1803,11 @@ bool ContentChild::DeallocPFileDescriptorSetChild(
return true;
}
already_AddRefed<PRemoteLazyInputStreamChild>
ContentChild::AllocPRemoteLazyInputStreamChild(const nsID& aID,
const uint64_t& aSize) {
RefPtr<RemoteLazyInputStreamChild> actor =
new RemoteLazyInputStreamChild(aID, aSize);
already_AddRefed<PIPCBlobInputStreamChild>
ContentChild::AllocPIPCBlobInputStreamChild(const nsID& aID,
const uint64_t& aSize) {
RefPtr<IPCBlobInputStreamChild> actor =
new IPCBlobInputStreamChild(aID, aSize);
return actor.forget();
}

Просмотреть файл

@ -191,8 +191,8 @@ class ContentChild final : public PContentChild,
mozilla::ipc::IPCResult RecvSetProcessSandbox(
const Maybe<FileDescriptor>& aBroker);
already_AddRefed<PRemoteLazyInputStreamChild>
AllocPRemoteLazyInputStreamChild(const nsID& aID, const uint64_t& aSize);
already_AddRefed<PIPCBlobInputStreamChild> AllocPIPCBlobInputStreamChild(
const nsID& aID, const uint64_t& aSize);
PHalChild* AllocPHalChild();
bool DeallocPHalChild(PHalChild*);

Просмотреть файл

@ -96,6 +96,7 @@
#include "mozilla/dom/GeolocationBinding.h"
#include "mozilla/dom/GeolocationPositionError.h"
#include "mozilla/dom/GetFilesHelper.h"
#include "mozilla/dom/IPCBlobInputStreamParent.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSProcessActorBinding.h"
@ -153,7 +154,6 @@
#include "mozilla/net/NeckoParent.h"
#include "mozilla/net/PCookieServiceParent.h"
#include "mozilla/plugins/PluginBridge.h"
#include "mozilla/RemoteLazyInputStreamParent.h"
#include "mozilla/widget/ScreenManager.h"
#include "nsAnonymousTemporaryFile.h"
#include "nsAppRunner.h"

Просмотреть файл

@ -11,7 +11,7 @@ include "mozilla/layers/LayersMessageUtils.h";
include IPCBlob;
include IPCStream;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
include ProtocolTypes;
using struct mozilla::void_t
@ -314,7 +314,7 @@ struct ReplacementChannelConfigInit
nsCString? method;
nsIReferrerInfo referrerInfo;
TimedChannelInfo? timedChannel;
nullable PRemoteLazyInputStream uploadStream;
nullable PIPCBlobInputStream uploadStream;
bool uploadStreamHasHeaders;
nsCString? contentType;
nsCString? contentLength;

Просмотреть файл

@ -16,7 +16,7 @@ include protocol PRemotePrintJob;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
include protocol PPaymentRequest;
include protocol PWindowGlobal;
include protocol PBrowserBridge;

Просмотреть файл

@ -16,7 +16,7 @@ include protocol PHal;
include protocol PHeapSnapshotTempFileHelper;
include protocol PProcessHangMonitor;
include protocol PImageBridge;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
include protocol PLoginReputation;
include protocol PMedia;
include protocol PNecko;
@ -393,7 +393,7 @@ nested(upto inside_cpow) sync protocol PContent
manages PHal;
manages PHandlerService;
manages PHeapSnapshotTempFileHelper;
manages PRemoteLazyInputStream;
manages PIPCBlobInputStream;
manages PMedia;
manages PNecko;
manages POfflineCacheUpdate;
@ -757,7 +757,7 @@ child:
async RefreshScreens(ScreenDetails[] aScreens);
async PRemoteLazyInputStream(nsID aID, uint64_t aSize);
async PIPCBlobInputStream(nsID aID, uint64_t aSize);
/**
* This call takes the set of plugins loaded in the chrome process, and

Просмотреть файл

@ -6,9 +6,9 @@
include protocol PBrowser;
include protocol PChildToParentStream;
include protocol PIPCBlobInputStream;
include protocol PFileDescriptorSet;
include protocol PParentToChildStream;
include protocol PRemoteLazyInputStream;
include IPCBlob;

Просмотреть файл

@ -7,6 +7,7 @@
#include "LSObject.h"
#include "ActorsChild.h"
#include "IPCBlobInputStreamThread.h"
#include "LocalStorageCommon.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/StaticPrefs_dom.h"
@ -18,7 +19,6 @@
#include "nsContentUtils.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsThread.h"
#include "RemoteLazyInputStreamThread.h"
/**
* Automatically cancel and abort synchronous LocalStorage requests (for example
@ -83,16 +83,15 @@ class NestedEventTargetWrapper final : public nsISerialEventTarget {
* The normal life-cycle of this method looks like:
* - Main Thread: LSObject::DoRequestSynchronously creates a RequestHelper and
* invokes StartAndReturnResponse(). It pushes the event queue and Dispatches
* the RequestHelper to the RemoteLazyInputStream thread.
* - RemoteLazyInputStream Thread: RequestHelper::Run is called, invoking
* Start() which invokes LSObject::StartRequest, which gets-or-creates the
* PBackground actor if necessary (which may dispatch a runnable to the nested
* event queue on the main thread), sends LSRequest constructor which is
* provided with a callback reference to the RequestHelper. State advances to
* ResponsePending.
* - RemoteLazyInputStreamThread: LSRequestChild::Recv__delete__ is received,
* which invokes RequestHelepr::OnResponse, advancing the state to Finishing
* and dispatching RequestHelper to its own nested event target.
* the RequestHelper to the DOM File Thread.
* - DOM File Thread: RequestHelper::Run is called, invoking Start() which
* invokes LSObject::StartRequest, which gets-or-creates the PBackground actor
* if necessary (which may dispatch a runnable to the nested event queue on
* the main thread), sends LSRequest constructor which is provided with a
* callback reference to the RequestHelper. State advances to ResponsePending.
* - DOM File Thread:: LSRequestChild::Recv__delete__ is received, which invokes
* RequestHelepr::OnResponse, advancing the state to Finishing and dispatching
* RequestHelper to its own nested event target.
* - Main Thread: RequestHelper::Run is called, invoking Finish() which advances
* the state to Complete and sets mWaiting to false, allowing the nested event
* loop being spun by StartAndReturnResponse to cease spinning and return the
@ -104,12 +103,11 @@ class NestedEventTargetWrapper final : public nsISerialEventTarget {
class RequestHelper final : public Runnable, public LSRequestChildCallback {
enum class State {
/**
* The RequestHelper has been created and dispatched to the
* RemoteLazyInputStream Thread.
* The RequestHelper has been created and dispatched to the DOM File Thread.
*/
Initial,
/**
* Start() has been invoked on the RemoteLazyInputStream Thread and
* Start() has been invoked on the DOM File Thread and
* LSObject::StartRequest has been invoked from there, sending an IPC
* message to PBackground to service the request. We stay in this state
* until a response is received.
@ -219,7 +217,7 @@ void LSObject::Initialize() {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIEventTarget> domFileThread =
RemoteLazyInputStreamThread::GetOrCreate();
IPCBlobInputStreamThread::GetOrCreate();
if (NS_WARN_IF(!domFileThread)) {
return;
}
@ -829,9 +827,9 @@ nsresult LSObject::DoRequestSynchronously(const LSRequestParams& aParams,
RefPtr<RequestHelper> helper = new RequestHelper(this, aParams);
// This will start and finish the request on the RemoteLazyInputStream thread.
// This will start and finish the request on the DOM File thread.
// The owning thread is synchronously blocked while the request is
// asynchronously processed on the RemoteLazyInputStream thread.
// asynchronously processed on the DOM File thread.
nsresult rv = helper->StartAndReturnResponse(aResponse);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -898,7 +896,7 @@ nsresult LSObject::EnsureDatabase() {
uint64_t datastoreId = prepareDatastoreResponse.datastoreId();
// The datastore is now ready on the parent side (prepared by the asynchronous
// request on the RemoteLazyInputStream thread).
// request on the DOM File thread).
// Let's create a direct connection to the datastore (through a database
// actor) from the owning thread.
// Note that we now can't error out, otherwise parent will keep an extra
@ -963,7 +961,7 @@ nsresult LSObject::EnsureObserver() {
uint64_t observerId = prepareObserverResponse.observerId();
// The obsserver is now ready on the parent side (prepared by the asynchronous
// request on the RemoteLazyInputStream thread).
// request on the DOM File thread).
// Let's create a direct connection to the observer (through an observer
// actor) from the owning thread.
// Note that we now can't error out, otherwise parent will keep an extra
@ -1107,8 +1105,8 @@ nsresult RequestHelper::StartAndReturnResponse(LSRequestResponse& aResponse) {
// Normally, we would use the standard way of blocking the thread using
// a monitor.
// The problem is that BackgroundChild::GetOrCreateForCurrentThread()
// called on the RemoteLazyInputStream thread may dispatch a runnable to the
// main thread to finish initialization of PBackground. A monitor would block
// called on the DOM File thread may dispatch a runnable to the main
// thread to finish initialization of PBackground. A monitor would block
// the main thread and the runnable would never get executed causing the
// helper to be stuck in a wait loop.
// However, BackgroundChild::GetOrCreateForCurrentThread() supports passing
@ -1129,8 +1127,8 @@ nsresult RequestHelper::StartAndReturnResponse(LSRequestResponse& aResponse) {
new NestedEventTargetWrapper(mNestedEventTarget);
nsCOMPtr<nsIEventTarget> domFileThread =
XRE_IsParentProcess() ? RemoteLazyInputStreamThread::GetOrCreate()
: RemoteLazyInputStreamThread::Get();
XRE_IsParentProcess() ? IPCBlobInputStreamThread::GetOrCreate()
: IPCBlobInputStreamThread::Get();
if (NS_WARN_IF(!domFileThread)) {
return NS_ERROR_FAILURE;
}
@ -1204,8 +1202,8 @@ nsresult RequestHelper::StartAndReturnResponse(LSRequestResponse& aResponse) {
// We can check mWaiting here because it's only ever touched on the main
// thread.
if (NS_WARN_IF(mWaiting)) {
// Don't touch mResponse, mResultCode or mState here! The
// RemoteLazyInputStream Thread may be accessing them at the same moment.
// Don't touch mResponse, mResultCode or mState here! The DOM File Thread
// may be accessing them at the same moment.
RefPtr<RequestHelper> self = this;

Просмотреть файл

@ -81,16 +81,16 @@
* like directory locking before sending a reply to a synchronous message, then
* we would have to block the thread or spin the event loop which is usually a
* bad idea, especially in the main process.
* Instead, we can use a special thread in the content process called
* RemoteLazyInputStream thread for communication with the main process using
* asynchronous messages and synchronously block the main thread until the DOM
* File thread is done (the main thread blocking is a bit more complicated, see
* the comment in RequestHelper::StartAndReturnResponse for more details).
* Anyway, the extra hop to the RemoteLazyInputStream thread brings another
* overhead and latency. The final solution is to use a combination of the
* special thread for complex stuff like datastore preparation and synchronous
* IPC messages sent directly from the main thread for database access when data
* is already loaded from disk into memory.
* Instead, we can use a special thread in the content process called DOM File
* thread for communication with the main process using asynchronous messages
* and synchronously block the main thread until the DOM File thread is done
* (the main thread blocking is a bit more complicated, see the comment in
* RequestHelper::StartAndReturnResponse for more details).
* Anyway, the extra hop to the DOM File thread brings another overhead and
* latency. The final solution is to use a combination of the special thread
* for complex stuff like datastore preparation and synchronous IPC messages
* sent directly from the main thread for database access when data is already
* loaded from disk into memory.
*
* Requests
* ~~~~~~~~
@ -116,13 +116,13 @@
* responses and do safe main thread blocking at the same time.
* It inherits from the "Runnable" class, so instances are ref counted and
* they are internally used on multiple threads (specifically on the main
* thread and on the RemoteLazyInputStream thread). Anyway, users should create
* and use instances of this class only on the main thread (apart from a special
* case when we need to cancel the request from an internal chromium IPC thread
* to prevent a dead lock involving CPOWs).
* thread and on the DOM File thread). Anyway, users should create and use
* instances of this class only on the main thread (apart from a special case
* when we need to cancel the request from an internal chromium IPC thread to
* prevent a dead lock involving CPOWs).
* The actual child actor is represented by the "LSRequestChild" class that
* implements the "PBackgroundLSRequestChild" interface. An "LSRequestChild"
* instance is not ref counted and lives on the RemoteLazyInputStream thread.
* instance is not ref counted and lives on the DOM File thread.
* Request responses are passed using the "LSRequestChildCallback" interface.
*
* Preparation of a datastore
@ -157,10 +157,9 @@
* In theory, the datastore preparation request could return a database actor
* directly (instead of returning an id intended for database linking to a
* datastore). However, as it was explained above, the preparation must be done
* on the RemoteLazyInputStream thread and database objects are used on the main
* thread. The returned actor would have to be migrated from the
* RemoteLazyInputStream thread to the main thread and that's something which
* our IPDL doesn't support yet.
* on the DOM File thread and database objects are used on the main thread. The
* returned actor would have to be migrated from the DOM File thread to the
* main thread and that's something which our IPDL doesn't support yet.
*
* Exposing local storage
* ~~~~~~~~~~~~~~~~~~~~~~

Просмотреть файл

@ -19,12 +19,12 @@ class AsyncRequestHelper final : public Runnable,
public LSRequestChildCallback {
enum class State {
/**
* The AsyncRequestHelper has been created and dispatched to the
* RemoteLazyInputStream Thread.
* The AsyncRequestHelper has been created and dispatched to the DOM File
* Thread.
*/
Initial,
/**
* Start() has been invoked on the RemoteLazyInputStream Thread and
* Start() has been invoked on the DOM File Thread and
* LocalStorageManager2::StartRequest has been invoked from there, sending
* an IPC message to PBackground to service the request. We stay in this
* state until a response is received.
@ -300,10 +300,9 @@ LocalStorageManager2::Preload(nsIPrincipal* aPrincipal, JSContext* aContext,
RefPtr<AsyncRequestHelper> helper =
new AsyncRequestHelper(this, promise, params);
// This will start and finish the async request on the RemoteLazyInputStream
// thread.
// This must be done on RemoteLazyInputStream Thread because it's very likely
// that a content process will issue a prepare datastore request for the same
// This will start and finish the async request on the DOM File thread.
// This must be done on DOM File Thread because it's very likely that a
// content process will issue a prepare datastore request for the same
// principal while blocking the content process on the main thread.
// There would be a potential for deadlock if the preloading was initialized
// from the main thread of the parent process and a11y issued a synchronous
@ -407,7 +406,7 @@ nsresult AsyncRequestHelper::Dispatch() {
AssertIsOnOwningThread();
nsCOMPtr<nsIEventTarget> domFileThread =
RemoteLazyInputStreamThread::GetOrCreate();
IPCBlobInputStreamThread::GetOrCreate();
if (NS_WARN_IF(!domFileThread)) {
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -93,8 +93,7 @@ child:
* Cancel() would be received by the parent after it had already sent
* __delete__. (Which may no longer be fatal thanks to improvements to the
* IPC layer, but it would still lead to warnings, etc. And we don't
* expect PBackground to be highly contended nor the RemoteLazyInputStream
* thread.)
* expect PBackground to be highly contended nor the DOM File thread.)
*/
async Ready();
};

Просмотреть файл

@ -5,8 +5,8 @@
include protocol PBackground;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include DOMTypes;
include ProtocolTypes;

Просмотреть файл

@ -19,10 +19,10 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/FetchEventOpParent.h"
#include "mozilla/dom/IPCBlobInputStreamStorage.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/RemoteLazyInputStreamUtils.h"
#include "mozilla/RemoteLazyInputStreamStorage.h"
namespace mozilla {
@ -47,8 +47,8 @@ nsresult MaybeDeserializeAndWrapForMainThread(
MOZ_TRY(nsContentUtils::GenerateUUIDInPlace(uuid));
RemoteLazyInputStreamStorage::Get()->AddStream(deserialized, uuid,
aBodyStreamSize, 0);
IPCBlobInputStreamStorage::Get()->AddStream(deserialized, uuid,
aBodyStreamSize, 0);
return NS_OK;
}
@ -80,7 +80,7 @@ nsresult MaybeDeserializeAndWrapForMainThread(
auto streamLength = copyRequest.bodySize();
const auto& uuid =
copyRequest.body().ref().get_ParentToParentStream().uuid();
RemoteLazyInputStreamStorage* storage = RemoteLazyInputStreamStorage::Get();
IPCBlobInputStreamStorage* storage = IPCBlobInputStreamStorage::Get();
storage->GetStream(uuid, 0, streamLength, getter_AddRefs(stream));
storage->ForgetStream(uuid);
@ -91,13 +91,10 @@ nsresult MaybeDeserializeAndWrapForMainThread(
MOZ_ASSERT(bgParent);
copyRequest.body() = Some(ParentToChildStream());
RemoteLazyStream ipdlStream;
MOZ_ALWAYS_SUCCEEDS(RemoteLazyInputStreamUtils::SerializeInputStream(
stream, streamLength, ipdlStream, bgParent));
copyRequest.body().ref().get_ParentToChildStream().actorParent() =
ipdlStream;
MOZ_ALWAYS_SUCCEEDS(IPCBlobUtils::SerializeInputStream(
stream, streamLength,
copyRequest.body().ref().get_ParentToChildStream().actorParent(),
bgParent));
}
Unused << aManager->SendPFetchEventOpProxyConstructor(actor, copyArgs);

Просмотреть файл

@ -38,6 +38,7 @@
#include "mozilla/dom/ClientIPCTypes.h"
#include "mozilla/dom/DOMTypes.h"
#include "mozilla/dom/FetchEventOpChild.h"
#include "mozilla/dom/IPCBlobInputStreamStorage.h"
#include "mozilla/dom/InternalHeaders.h"
#include "mozilla/dom/InternalRequest.h"
#include "mozilla/dom/ReferrerInfo.h"
@ -46,7 +47,6 @@
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/net/CookieJarSettings.h"
#include "mozilla/RemoteLazyInputStreamStorage.h"
namespace mozilla {
@ -71,7 +71,7 @@ ServiceWorkerPrivateImpl::RAIIActorPtrHolder::~RAIIActorPtrHolder() {
}
RemoteWorkerControllerChild*
ServiceWorkerPrivateImpl::RAIIActorPtrHolder::operator->() const {
ServiceWorkerPrivateImpl::RAIIActorPtrHolder::operator->() const {
AssertIsOnMainThread();
return get();
@ -774,7 +774,7 @@ nsresult MaybeStoreStreamForBackgroundThread(nsIInterceptedChannel* aChannel,
MOZ_TRY(nsContentUtils::GenerateUUIDInPlace(
body->get_ParentToParentStream().uuid()));
RemoteLazyInputStreamStorage::Get()->AddStream(
IPCBlobInputStreamStorage::Get()->AddStream(
uploadStream, body->get_ParentToParentStream().uuid(), bodySize, 0);
}
}

Просмотреть файл

@ -14,8 +14,8 @@
// immediately available (eliminating memory-backed Blobs) and 2) return
// NS_BASE_STREAM_WOULD_BLOCK. Under e10s, any Blob/File sourced from the
// parent process (as loadChromeScript performs) will be backed by an
// RemoteLazyInputStream and will behave this way on first use (when it is in
// the eInit state). For ease of testing, we reuse script_createFile.js which
// IPCBlobInputStream and will behave this way on first use (when it is in the
// eInit state). For ease of testing, we reuse script_createFile.js which
// involves a file on disk, but a memory-backed Blob from the parent process
// would be equally fine. Under non-e10s, this File will not do the right
// thing because a synchronous nsFileInputStream will be made directly

Просмотреть файл

@ -33,6 +33,7 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/ContentProcessMessageManager.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/ResultExtensions.h"
@ -1294,8 +1295,9 @@ gfxFontEntry* gfxPlatformFontList::FindFontForFamily(
gfxFontEntry* gfxPlatformFontList::GetOrCreateFontEntry(
fontlist::Face* aFace, const fontlist::Family* aFamily) {
return mFontEntries.LookupForAdd(aFace).OrInsert(
[=]() { return CreateFontEntry(aFace, aFamily); });
return mFontEntries.LookupForAdd(aFace).OrInsert([=]() {
return CreateFontEntry(aFace, aFamily);
});
}
void gfxPlatformFontList::AddOtherFamilyName(

Просмотреть файл

@ -25,11 +25,13 @@
#include "mozilla/dom/PFileSystemRequestChild.h"
#include "mozilla/dom/EndpointForReportChild.h"
#include "mozilla/dom/FileSystemTaskBase.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
#include "mozilla/dom/PMediaTransportChild.h"
#include "mozilla/dom/TemporaryIPCBlobChild.h"
#include "mozilla/dom/cache/ActorUtils.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBFactoryChild.h"
#include "mozilla/dom/indexedDB/PBackgroundIndexedDBUtilsChild.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/quota/PQuotaChild.h"
#include "mozilla/dom/RemoteWorkerChild.h"
#include "mozilla/dom/RemoteWorkerControllerChild.h"
@ -54,7 +56,6 @@
#include "mozilla/dom/WebAuthnTransactionChild.h"
#include "mozilla/dom/MIDIPortChild.h"
#include "mozilla/dom/MIDIManagerChild.h"
#include "mozilla/RemoteLazyInputStreamChild.h"
#include "nsID.h"
#include "nsTraceRefcnt.h"
@ -382,11 +383,11 @@ bool BackgroundChildImpl::DeallocPFileCreatorChild(PFileCreatorChild* aActor) {
return true;
}
already_AddRefed<PRemoteLazyInputStreamChild>
BackgroundChildImpl::AllocPRemoteLazyInputStreamChild(const nsID& aID,
const uint64_t& aSize) {
RefPtr<RemoteLazyInputStreamChild> actor =
new RemoteLazyInputStreamChild(aID, aSize);
already_AddRefed<dom::PIPCBlobInputStreamChild>
BackgroundChildImpl::AllocPIPCBlobInputStreamChild(const nsID& aID,
const uint64_t& aSize) {
RefPtr<dom::IPCBlobInputStreamChild> actor =
new dom::IPCBlobInputStreamChild(aID, aSize);
return actor.forget();
}

Просмотреть файл

@ -112,9 +112,9 @@ class BackgroundChildImpl : public PBackgroundChild,
virtual bool DeallocPBackgroundStorageChild(
PBackgroundStorageChild* aActor) override;
virtual already_AddRefed<PRemoteLazyInputStreamChild>
AllocPRemoteLazyInputStreamChild(const nsID& aID,
const uint64_t& aSize) override;
virtual already_AddRefed<PIPCBlobInputStreamChild>
AllocPIPCBlobInputStreamChild(const nsID& aID,
const uint64_t& aSize) override;
virtual PTemporaryIPCBlobChild* AllocPTemporaryIPCBlobChild() override;

Просмотреть файл

@ -33,6 +33,8 @@
#include "mozilla/dom/TemporaryIPCBlobParent.h"
#include "mozilla/dom/cache/ActorUtils.h"
#include "mozilla/dom/indexedDB/ActorsParent.h"
#include "mozilla/dom/IPCBlobInputStreamParent.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/localstorage/ActorsParent.h"
#include "mozilla/dom/quota/ActorsParent.h"
#include "mozilla/dom/simpledb/ActorsParent.h"
@ -60,7 +62,6 @@
#include "mozilla/dom/WebAuthnTransactionParent.h"
#include "mozilla/Preferences.h"
#include "mozilla/psm/VerifySSLServerCertParent.h"
#include "mozilla/RemoteLazyInputStreamParent.h"
#include "mozilla/StaticPrefs_dom.h"
#include "nsNetUtil.h"
#include "nsProxyRelease.h"
@ -622,22 +623,22 @@ bool BackgroundParentImpl::DeallocPTemporaryIPCBlobParent(
return true;
}
already_AddRefed<PRemoteLazyInputStreamParent>
BackgroundParentImpl::AllocPRemoteLazyInputStreamParent(const nsID& aID,
const uint64_t& aSize) {
already_AddRefed<dom::PIPCBlobInputStreamParent>
BackgroundParentImpl::AllocPIPCBlobInputStreamParent(const nsID& aID,
const uint64_t& aSize) {
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
RefPtr<RemoteLazyInputStreamParent> actor =
RemoteLazyInputStreamParent::Create(aID, aSize, this);
RefPtr<dom::IPCBlobInputStreamParent> actor =
dom::IPCBlobInputStreamParent::Create(aID, aSize, this);
return actor.forget();
}
mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPRemoteLazyInputStreamConstructor(
PRemoteLazyInputStreamParent* aActor, const nsID& aID,
BackgroundParentImpl::RecvPIPCBlobInputStreamConstructor(
dom::PIPCBlobInputStreamParent* aActor, const nsID& aID,
const uint64_t& aSize) {
if (!static_cast<RemoteLazyInputStreamParent*>(aActor)->HasValidStream()) {
if (!static_cast<dom::IPCBlobInputStreamParent*>(aActor)->HasValidStream()) {
return IPC_FAIL_NO_REASON(this);
}

Просмотреть файл

@ -144,12 +144,12 @@ class BackgroundParentImpl : public PBackgroundParent,
virtual already_AddRefed<PIdleSchedulerParent> AllocPIdleSchedulerParent()
override;
virtual already_AddRefed<PRemoteLazyInputStreamParent>
AllocPRemoteLazyInputStreamParent(const nsID& aID,
const uint64_t& aSize) override;
virtual already_AddRefed<PIPCBlobInputStreamParent>
AllocPIPCBlobInputStreamParent(const nsID& aID,
const uint64_t& aSize) override;
virtual mozilla::ipc::IPCResult RecvPRemoteLazyInputStreamConstructor(
PRemoteLazyInputStreamParent* aActor, const nsID& aID,
virtual mozilla::ipc::IPCResult RecvPIPCBlobInputStreamConstructor(
PIPCBlobInputStreamParent* aActor, const nsID& aID,
const uint64_t& aSize) override;
virtual PTemporaryIPCBlobParent* AllocPTemporaryIPCBlobParent() override;

Просмотреть файл

@ -6,7 +6,7 @@ include ProtocolTypes;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
using struct mozilla::void_t
from "ipc/IPCMessageUtils.h";
@ -49,17 +49,17 @@ struct SlicedInputStreamParams
bool closed;
};
struct RemoteLazyInputStreamRef
struct IPCBlobInputStreamRef
{
nsID id;
uint64_t start;
uint64_t length;
};
union RemoteLazyInputStreamParams
union IPCBlobInputStreamParams
{
RemoteLazyInputStreamRef;
PRemoteLazyInputStream;
IPCBlobInputStreamRef;
PIPCBlobInputStream;
};
union IPCRemoteStreamType
@ -89,7 +89,7 @@ union InputStreamParams
MIMEInputStreamParams;
MultiplexInputStreamParams;
SlicedInputStreamParams;
RemoteLazyInputStreamParams;
IPCBlobInputStreamParams;
InputStreamLengthWrapperParams;
IPCRemoteStreamParams;
EncryptedFileInputStreamParams;

Просмотреть файл

@ -10,14 +10,14 @@
#include "mozilla/Assertions.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/IPCBlobInputStream.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
#include "mozilla/dom/IPCBlobInputStreamStorage.h"
#include "mozilla/dom/quota/DecryptingInputStream_impl.h"
#include "mozilla/dom/quota/IPCStreamCipherStrategy.h"
#include "mozilla/ipc/IPCStreamDestination.h"
#include "mozilla/ipc/IPCStreamSource.h"
#include "mozilla/InputStreamLengthHelper.h"
#include "mozilla/RemoteLazyInputStream.h"
#include "mozilla/RemoteLazyInputStreamChild.h"
#include "mozilla/RemoteLazyInputStreamStorage.h"
#include "mozilla/SlicedInputStream.h"
#include "mozilla/InputStreamLengthWrapper.h"
#include "nsBufferedStreams.h"
@ -248,7 +248,7 @@ void InputStreamHelper::PostSerializationActivation(InputStreamParams& aParams,
case InputStreamParams::TFileInputStreamParams:
break;
case InputStreamParams::TRemoteLazyInputStreamParams:
case InputStreamParams::TIPCBlobInputStreamParams:
break;
case InputStreamParams::TEncryptedFileInputStreamParams:
@ -273,31 +273,28 @@ void InputStreamHelper::PostSerializationActivation(
already_AddRefed<nsIInputStream> InputStreamHelper::DeserializeInputStream(
const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors) {
if (aParams.type() == InputStreamParams::TRemoteLazyInputStreamParams) {
const RemoteLazyInputStreamParams& params =
aParams.get_RemoteLazyInputStreamParams();
if (aParams.type() == InputStreamParams::TIPCBlobInputStreamParams) {
const IPCBlobInputStreamParams& params =
aParams.get_IPCBlobInputStreamParams();
// RemoteLazyInputStreamRefs are not deserializable on the parent side,
// because the parent is the only one that has a copy of the original stream
// in the RemoteLazyInputStreamStorage.
if (params.type() ==
RemoteLazyInputStreamParams::TRemoteLazyInputStreamRef) {
// IPCBlobInputStreamRefs are not deserializable on the parent side, because
// the parent is the only one that has a copy of the original stream in the
// IPCBlobInputStreamStorage.
if (params.type() == IPCBlobInputStreamParams::TIPCBlobInputStreamRef) {
MOZ_ASSERT(XRE_IsParentProcess());
const RemoteLazyInputStreamRef& ref =
params.get_RemoteLazyInputStreamRef();
const IPCBlobInputStreamRef& ref = params.get_IPCBlobInputStreamRef();
nsCOMPtr<nsIInputStream> stream;
RemoteLazyInputStreamStorage::Get()->GetStream(
IPCBlobInputStreamStorage::Get()->GetStream(
ref.id(), ref.start(), ref.length(), getter_AddRefs(stream));
return stream.forget();
}
// parent -> child serializations receive an RemoteLazyInputStream actor.
// parent -> child serializations receive an IPCBlobInputStream actor.
MOZ_ASSERT(params.type() ==
RemoteLazyInputStreamParams::TPRemoteLazyInputStreamChild);
RemoteLazyInputStreamChild* actor =
static_cast<RemoteLazyInputStreamChild*>(
params.get_PRemoteLazyInputStreamChild());
IPCBlobInputStreamParams::TPIPCBlobInputStreamChild);
IPCBlobInputStreamChild* actor = static_cast<IPCBlobInputStreamChild*>(
params.get_PIPCBlobInputStreamChild());
nsCOMPtr<nsIInputStream> stream = actor->CreateStream();
return stream.forget();
}

Просмотреть файл

@ -25,7 +25,7 @@ include protocol PGamepadEventChannel;
include protocol PGamepadTestChannel;
include protocol PHttpBackgroundChannel;
include protocol PIdleScheduler;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
include protocol PMediaTransport;
include protocol PRemoteWorker;
include protocol PRemoteWorkerController;
@ -96,7 +96,7 @@ sync protocol PBackground
manages PGamepadTestChannel;
manages PHttpBackgroundChannel;
manages PIdleScheduler;
manages PRemoteLazyInputStream;
manages PIPCBlobInputStream;
manages PMediaTransport;
manages PRemoteWorker;
manages PRemoteWorkerController;
@ -263,9 +263,9 @@ child:
async PRemoteWorker(RemoteWorkerData data);
both:
// PRemoteLazyInputStream is created on the parent side only if the child
// starts a migration.
async PRemoteLazyInputStream(nsID aID, uint64_t aSize);
// PIPCBlobInputStream is created on the parent side only if the child starts
// a migration.
async PIPCBlobInputStream(nsID aID, uint64_t aSize);
async PFileDescriptorSet(FileDescriptor fd);
};

Просмотреть файл

@ -109,6 +109,7 @@
#include "mozilla/StaticPresData.h"
#include "mozilla/dom/AbstractRange.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/IPCBlobInputStreamStorage.h"
#include "mozilla/dom/WebIDLGlobalNameHash.h"
#include "mozilla/dom/U2FTokenManager.h"
#ifdef OS_WIN
@ -122,7 +123,6 @@
#include "mozilla/dom/quota/ActorsParent.h"
#include "mozilla/dom/localstorage/ActorsParent.h"
#include "mozilla/net/UrlClassifierFeatureFactory.h"
#include "mozilla/RemoteLazyInputStreamStorage.h"
#include "nsThreadManager.h"
#include "mozilla/css/ImageLoader.h"
#include "gfxUserFontSet.h"
@ -262,7 +262,7 @@ nsresult nsLayoutStatics::Initialize() {
}
// This must be initialized on the main-thread.
mozilla::RemoteLazyInputStreamStorage::Initialize();
mozilla::dom::IPCBlobInputStreamStorage::Initialize();
mozilla::dom::U2FTokenManager::Initialize();

Просмотреть файл

@ -182,7 +182,7 @@ interface nsIFileStream : nsISupports
* interface before taking any action that might consume the underlying stream.
* For example, once Available(), Read(), or nsIAsyncInputStream::AsyncWait()
* are invoked, these methods may return NS_BASE_STREAM_CLOSED. This will
* happen when using RemoteLazyInputStream with an underlying file stream, for
* happen when using IPCBlobInputStream with an underlying file stream, for
* example.
*/
[scriptable, uuid(07f679e4-9601-4bd1-b510-cd3852edb881)]

Просмотреть файл

@ -19,7 +19,7 @@ include protocol PAltSvcTransaction;
include protocol PTRRService;
include protocol PProxyConfigLookup;
include protocol PNativeDNSResolverOverride;
include protocol PRemoteLazyInputStream;
include protocol PIPCBlobInputStream;
include MemoryReportTypes;
include NeckoChannelParams;
@ -74,7 +74,7 @@ sync protocol PSocketProcess
manages PTRRService;
manages PProxyConfigLookup;
manages PNativeDNSResolverOverride;
manages PRemoteLazyInputStream;
manages PIPCBlobInputStream;
parent:
async InitCrashReporter(NativeThreadId threadId);
@ -144,7 +144,7 @@ child:
async PNativeDNSResolverOverride();
async NotifyObserver(nsCString aTopic, nsString aData);
async PRemoteLazyInputStream(nsID aID, uint64_t aSize);
async PIPCBlobInputStream(nsID aID, uint64_t aSize);
both:
async PFileDescriptorSet(FileDescriptor fd);

Просмотреть файл

@ -11,6 +11,7 @@
#include "HttpTransactionChild.h"
#include "HttpConnectionMgrChild.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
#include "mozilla/dom/MemoryReportRequest.h"
#include "mozilla/ipc/CrashReporterClient.h"
#include "mozilla/ipc/BackgroundChild.h"
@ -27,7 +28,6 @@
#include "mozilla/ipc/PChildToParentStreamChild.h"
#include "mozilla/ipc/PParentToChildStreamChild.h"
#include "mozilla/Preferences.h"
#include "mozilla/RemoteLazyInputStreamChild.h"
#include "mozilla/Telemetry.h"
#include "nsDebugImpl.h"
#include "nsHttpConnectionInfo.h"
@ -464,11 +464,11 @@ mozilla::ipc::IPCResult SocketProcessChild::RecvNotifyObserver(
return IPC_OK();
}
already_AddRefed<PRemoteLazyInputStreamChild>
SocketProcessChild::AllocPRemoteLazyInputStreamChild(const nsID& aID,
const uint64_t& aSize) {
RefPtr<RemoteLazyInputStreamChild> actor =
new RemoteLazyInputStreamChild(aID, aSize);
already_AddRefed<dom::PIPCBlobInputStreamChild>
SocketProcessChild::AllocPIPCBlobInputStreamChild(const nsID& aID,
const uint64_t& aSize) {
RefPtr<dom::IPCBlobInputStreamChild> actor =
new dom::IPCBlobInputStreamChild(aID, aSize);
return actor.forget();
}

Просмотреть файл

@ -123,8 +123,8 @@ class SocketProcessChild final
mozilla::ipc::IPCResult RecvNotifyObserver(const nsCString& aTopic,
const nsString& aData);
virtual already_AddRefed<PRemoteLazyInputStreamChild>
AllocPRemoteLazyInputStreamChild(const nsID& aID, const uint64_t& aSize);
virtual already_AddRefed<PIPCBlobInputStreamChild>
AllocPIPCBlobInputStreamChild(const nsID& aID, const uint64_t& aSize);
protected:
friend class SocketProcessImpl;

Просмотреть файл

@ -10,6 +10,7 @@
#include "CachePushChecker.h"
#include "HttpTransactionParent.h"
#include "SocketProcessHost.h"
#include "mozilla/dom/IPCBlobInputStreamParent.h"
#include "mozilla/dom/MemoryReportRequest.h"
#include "mozilla/ipc/FileDescriptorSetParent.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
@ -17,7 +18,6 @@
#include "mozilla/ipc/PParentToChildStreamParent.h"
#include "mozilla/net/DNSRequestParent.h"
#include "mozilla/net/ProxyConfigLookupParent.h"
#include "mozilla/RemoteLazyInputStreamParent.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryIPC.h"
#include "nsIAppStartup.h"
@ -388,19 +388,18 @@ void SocketProcessParent::Destroy(UniquePtr<SocketProcessParent>&& aParent) {
new DeferredDeleteSocketProcessParent(std::move(aParent)));
}
already_AddRefed<PRemoteLazyInputStreamParent>
SocketProcessParent::AllocPRemoteLazyInputStreamParent(const nsID& aID,
const uint64_t& aSize) {
RefPtr<RemoteLazyInputStreamParent> actor =
RemoteLazyInputStreamParent::Create(aID, aSize, this);
already_AddRefed<dom::PIPCBlobInputStreamParent>
SocketProcessParent::AllocPIPCBlobInputStreamParent(const nsID& aID,
const uint64_t& aSize) {
RefPtr<dom::IPCBlobInputStreamParent> actor =
dom::IPCBlobInputStreamParent::Create(aID, aSize, this);
return actor.forget();
}
mozilla::ipc::IPCResult
SocketProcessParent::RecvPRemoteLazyInputStreamConstructor(
PRemoteLazyInputStreamParent* aActor, const nsID& aID,
mozilla::ipc::IPCResult SocketProcessParent::RecvPIPCBlobInputStreamConstructor(
dom::PIPCBlobInputStreamParent* aActor, const nsID& aID,
const uint64_t& aSize) {
if (!static_cast<RemoteLazyInputStreamParent*>(aActor)->HasValidStream()) {
if (!static_cast<dom::IPCBlobInputStreamParent*>(aActor)->HasValidStream()) {
return IPC_FAIL_NO_REASON(this);
}

Просмотреть файл

@ -113,11 +113,11 @@ class SocketProcessParent final
nsIURI* aPushedURL, OriginAttributes&& aOriginAttributes,
nsCString&& aRequestString, CachePushCheckResolver&& aResolver);
already_AddRefed<PRemoteLazyInputStreamParent>
AllocPRemoteLazyInputStreamParent(const nsID& aID, const uint64_t& aSize);
already_AddRefed<PIPCBlobInputStreamParent> AllocPIPCBlobInputStreamParent(
const nsID& aID, const uint64_t& aSize);
mozilla::ipc::IPCResult RecvPRemoteLazyInputStreamConstructor(
PRemoteLazyInputStreamParent* aActor, const nsID& aID,
mozilla::ipc::IPCResult RecvPIPCBlobInputStreamConstructor(
PIPCBlobInputStreamParent* aActor, const nsID& aID,
const uint64_t& aSize);
private:

Просмотреть файл

@ -81,8 +81,8 @@
#include "nsStreamUtils.h"
#include "nsThreadUtils.h"
#include "nsURLHelper.h"
#include "mozilla/RemoteLazyInputStreamChild.h"
#include "mozilla/RemoteLazyInputStreamUtils.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
namespace mozilla {
namespace net {
@ -3680,8 +3680,9 @@ HttpBaseChannel::ReplacementChannelConfig::ReplacementChannelConfig(
method = aInit.method();
referrerInfo = aInit.referrerInfo();
timedChannel = aInit.timedChannel();
if (RemoteLazyInputStreamChild* actor =
static_cast<RemoteLazyInputStreamChild*>(aInit.uploadStreamChild())) {
if (dom::IPCBlobInputStreamChild* actor =
static_cast<dom::IPCBlobInputStreamChild*>(
aInit.uploadStreamChild())) {
uploadStreamLength = actor->Size();
uploadStream = actor->CreateStream();
// actor can be deleted by CreateStream, so don't touch it
@ -3705,10 +3706,8 @@ HttpBaseChannel::ReplacementChannelConfig::Serialize(
config.referrerInfo() = referrerInfo;
config.timedChannel() = timedChannel;
if (uploadStream) {
RemoteLazyStream ipdlStream;
RemoteLazyInputStreamUtils::SerializeInputStream(
uploadStream, uploadStreamLength, ipdlStream, aParent);
config.uploadStreamParent() = ipdlStream;
dom::IPCBlobUtils::SerializeInputStream(
uploadStream, uploadStreamLength, config.uploadStreamParent(), aParent);
}
config.uploadStreamHasHeaders() = uploadStreamHasHeaders;
config.contentType() = contentType;

Просмотреть файл

@ -475,7 +475,7 @@ function* getRawDataChunked(
// the file, rather than its data.
if (
unbuffered instanceof Ci.nsIFileInputStream ||
unbuffered instanceof Ci.mozIRemoteLazyInputStream
unbuffered instanceof Ci.mozIIPCBlobInputStream
) {
// But this is not actually supported yet.
yield { file: "<file>" };

Просмотреть файл

@ -22,7 +22,7 @@ interface nsICloneableInputStream : nsISupports
};
// This interface implements cloneWithRange() because for some streams
// (RemoteLazyInputStream only, so far) are more efficient to produce a sub
// (IPCBlobInputStream only, so far) are more efficient to produce a sub
// stream with range than doing clone + SlicedInputStream().
[scriptable, builtinclass, uuid(ece853c3-aded-4cef-8f51-0d1493d60bd5)]
interface nsICloneableInputStreamWithRange : nsICloneableInputStream