Bug 1754004 - Part 1: Switch IPCStream to use DataPipe instead of P{ChildToParent,ParentToChild}Stream, r=asuth,necko-reviewers,kershaw

This gives us various positive benefits, such as using a shared memory ring
buffer for faster communication, not having data streaming being bound to the
thread which transferred the nsIInputStream (which is often the main thread),
and the ability for some backpressure to be applied to data streaming.

After this change, the "delayed start" parameter for IPCStream serialization is
less relevant, as backpressure will serve a similar purpose. It will still be
used to determine whether or not to use RemoteLazyInputStream when serializing
from the parent process.

Differential Revision: https://phabricator.services.mozilla.com/D141038
This commit is contained in:
Nika Layzell 2022-05-02 20:44:22 +00:00
parent fd60df03b9
commit ac6a0491c8
63 changed files with 32 additions and 1916 deletions

View File

@ -3,9 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include DOMTypes;

View File

@ -32,7 +32,6 @@ enum CleanupAction { Forget, Delete };
void CleanupChild(CacheReadStream& aReadStream, CleanupAction aAction) {
// fds cleaned up by mStreamCleanupList
// PChildToParentStream actors cleaned up by mStreamCleanupList
}
void CleanupChild(Maybe<CacheReadStream>& aMaybeReadStream,

View File

@ -212,8 +212,8 @@ already_AddRefed<nsIInputStream> CacheOpParent::DeserializeCacheStream(
}
// Option 2: A stream was serialized using normal methods or passed
// as a PChildToParentStream actor. Use the standard method for
// extracting the resulting stream.
// as a DataPipe. Use the standard method for extracting the
// resulting stream.
return DeserializeIPCStream(readStream.stream());
}

View File

@ -4,7 +4,6 @@
include protocol PCache;
include protocol PCacheStreamControl;
include protocol PChildToParentStream;
include IPCStream;
include IPCChannelInfo;
include PBackgroundSharedTypes;

View File

@ -6,8 +6,6 @@ include protocol PBackground;
include protocol PCacheOp;
include protocol PCacheStreamControl;
include protocol PFileDescriptorSet;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include CacheTypes;

View File

@ -6,8 +6,6 @@ include protocol PCache;
include protocol PCacheStorage;
include protocol PCacheStreamControl;
include protocol PFileDescriptorSet;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include CacheTypes;

View File

@ -7,8 +7,6 @@ include protocol PCache;
include protocol PCacheOp;
include protocol PCacheStreamControl;
include protocol PFileDescriptorSet;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include CacheTypes;

View File

@ -4,8 +4,6 @@
include protocol PBackground;
include protocol PFileDescriptorSet;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include IPCStream;
using struct nsID from "nsID.h";

View File

@ -222,12 +222,9 @@ void ReadStream::Inner::Serialize(
mControl->SerializeStream(aReadStreamOut, mStream, aStreamCleanupList);
}
MOZ_DIAGNOSTIC_ASSERT(
aReadStreamOut->stream().isNothing() ||
(aReadStreamOut->stream().ref().stream().type() !=
mozilla::ipc::InputStreamParams::TIPCRemoteStreamParams &&
aReadStreamOut->stream().ref().stream().type() !=
mozilla::ipc::InputStreamParams::T__None));
MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut->stream().isNothing() ||
aReadStreamOut->stream().ref().stream().type() !=
mozilla::ipc::InputStreamParams::T__None);
// We're passing ownership across the IPC barrier with the control, so
// do not signal that the stream is closed here.
@ -515,12 +512,9 @@ already_AddRefed<ReadStream> ReadStream::Create(
return nullptr;
}
MOZ_DIAGNOSTIC_ASSERT(
aReadStream.stream().isNothing() ||
(aReadStream.stream().ref().stream().type() !=
mozilla::ipc::InputStreamParams::TIPCRemoteStreamParams &&
aReadStream.stream().ref().stream().type() !=
mozilla::ipc::InputStreamParams::T__None));
MOZ_DIAGNOSTIC_ASSERT(aReadStream.stream().isNothing() ||
aReadStream.stream().ref().stream().type() !=
mozilla::ipc::InputStreamParams::T__None);
// Control is guaranteed to survive this method as ActorDestroy() cannot
// run on this thread until we complete.

View File

@ -4,8 +4,6 @@
include protocol PClientManager;
include protocol PClientHandleOp;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include ClientIPCTypes;

View File

@ -7,8 +7,6 @@ include protocol PClientHandle;
include protocol PClientManagerOp;
include protocol PClientNavigateOp;
include protocol PClientSource;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include ClientIPCTypes;

View File

@ -4,8 +4,6 @@
include protocol PClientManager;
include protocol PClientSourceOp;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include ClientIPCTypes;

View File

@ -2,8 +2,6 @@
* 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 protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PRemoteLazyInputStream;
include IPCStream;

View File

@ -66,7 +66,7 @@
* and its size is lower than 1Mb, we are able to recreate the stream completely
* on the parent side. This happens, basically with any kind of child-to-parent
* stream except for huge memory streams. In this case we end up using
* PChildToParentStream. See more information in IPCStreamUtils.h.
* DataPipe. See more information in IPCStreamUtils.h.
*
* In order to populate IPCStream correctly, we use AutoIPCStream as documented
* in IPCStreamUtils.h. Note that we use the 'delayed start' feature because,

View File

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

View File

@ -3,10 +3,8 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include protocol PChildToParentStream;
include protocol PContent;
include protocol PFileDescriptorSet;
include protocol PParentToChildStream;
include protocol PSocketProcess;
include IPCStream;

View File

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

View File

@ -4,9 +4,7 @@
include protocol PBackgroundFileRequest;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include IPCBlob;

View File

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

View File

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

View File

@ -8,9 +8,7 @@ include protocol PBackgroundIDBFactory;
include protocol PBackgroundIDBTransaction;
include protocol PBackgroundIDBVersionChangeTransaction;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include IPCBlob;

View File

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

View File

@ -4,9 +4,7 @@
include protocol PBackgroundIDBDatabaseFile;
include protocol PBackgroundMutableFile;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include DOMTypes;

View File

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

View File

@ -101,8 +101,6 @@
#include "mozilla/ipc/FileDescriptorSetChild.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/ipc/PChildToParentStreamChild.h"
#include "mozilla/ipc/PParentToChildStreamChild.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/ipc/TestShellChild.h"
#include "mozilla/layers/APZChild.h"
@ -250,9 +248,6 @@
#include "mozilla/dom/File.h"
#include "mozilla/dom/MediaControllerBinding.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
#include "mozilla/ipc/IPCStreamDestination.h"
#include "mozilla/ipc/IPCStreamSource.h"
#ifdef MOZ_WEBSPEECH
# include "mozilla/dom/PSpeechSynthesisChild.h"
@ -2028,37 +2023,6 @@ PRemotePrintJobChild* ContentChild::AllocPRemotePrintJobChild() {
#endif
}
PChildToParentStreamChild* ContentChild::SendPChildToParentStreamConstructor(
PChildToParentStreamChild* aActor) {
MOZ_ASSERT(NS_IsMainThread());
if (IsShuttingDown()) {
return nullptr;
}
return PContentChild::SendPChildToParentStreamConstructor(aActor);
}
PChildToParentStreamChild* ContentChild::AllocPChildToParentStreamChild() {
MOZ_CRASH("PChildToParentStreamChild actors should be manually constructed!");
}
bool ContentChild::DeallocPChildToParentStreamChild(
PChildToParentStreamChild* aActor) {
delete aActor;
return true;
}
PParentToChildStreamChild* ContentChild::AllocPParentToChildStreamChild() {
return mozilla::ipc::AllocPParentToChildStreamChild();
}
bool ContentChild::DeallocPParentToChildStreamChild(
PParentToChildStreamChild* aActor) {
delete aActor;
return true;
}
media::PMediaChild* ContentChild::AllocPMediaChild() {
return media::AllocPMediaChild();
}

View File

@ -46,7 +46,6 @@ class ChildProfilerController;
class BenchmarkStorageChild;
namespace ipc {
class PChildToParentStreamChild;
class PFileDescriptorSetChild;
} // namespace ipc
@ -232,12 +231,6 @@ class ContentChild final : public PContentChild,
PRemotePrintJobChild* AllocPRemotePrintJobChild();
PChildToParentStreamChild* AllocPChildToParentStreamChild();
bool DeallocPChildToParentStreamChild(PChildToParentStreamChild*);
PParentToChildStreamChild* AllocPParentToChildStreamChild();
bool DeallocPParentToChildStreamChild(PParentToChildStreamChild*);
PMediaChild* AllocPMediaChild();
bool DeallocPMediaChild(PMediaChild* aActor);
@ -654,8 +647,6 @@ class ContentChild final : public PContentChild,
Endpoint<PSandboxTestingChild>&& aEndpoint);
#endif
PChildToParentStreamChild* SendPChildToParentStreamConstructor(
PChildToParentStreamChild* aActor) override;
PFileDescriptorSetChild* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) override;

View File

@ -149,11 +149,7 @@
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/FileDescriptorSetParent.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
#include "mozilla/ipc/IPCStreamDestination.h"
#include "mozilla/ipc/IPCStreamSource.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/ipc/PChildToParentStreamParent.h"
#include "mozilla/ipc/TestShellParent.h"
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/ImageBridgeParent.h"
@ -4333,27 +4329,6 @@ mozilla::ipc::IPCResult ContentParent::RecvInitStreamFilter(
return IPC_OK();
}
PChildToParentStreamParent* ContentParent::AllocPChildToParentStreamParent() {
return mozilla::ipc::AllocPChildToParentStreamParent();
}
bool ContentParent::DeallocPChildToParentStreamParent(
PChildToParentStreamParent* aActor) {
delete aActor;
return true;
}
PParentToChildStreamParent* ContentParent::AllocPParentToChildStreamParent() {
MOZ_CRASH(
"PParentToChildStreamParent actors should be manually constructed!");
}
bool ContentParent::DeallocPParentToChildStreamParent(
PParentToChildStreamParent* aActor) {
delete aActor;
return true;
}
mozilla::ipc::IPCResult ContentParent::RecvAddSecurityState(
const MaybeDiscarded<WindowContext>& aContext, uint32_t aStateFlags) {
if (aContext.IsNullOrDiscarded()) {
@ -7265,12 +7240,6 @@ mozilla::ipc::IPCResult ContentParent::RecvCommitBrowsingContextTransaction(
return aTransaction.CommitFromIPC(aContext, this);
}
PParentToChildStreamParent* ContentParent::SendPParentToChildStreamConstructor(
PParentToChildStreamParent* aActor) {
MOZ_ASSERT(NS_IsMainThread());
return PContentParent::SendPParentToChildStreamConstructor(aActor);
}
PFileDescriptorSetParent* ContentParent::SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) {
MOZ_ASSERT(NS_IsMainThread());

View File

@ -20,8 +20,6 @@
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/ipc/PParentToChildStreamParent.h"
#include "mozilla/ipc/PChildToParentStreamParent.h"
#include "mozilla/Attributes.h"
#include "mozilla/DataMutex.h"
#include "mozilla/FileUtils.h"
@ -450,12 +448,6 @@ class ContentParent final
const uint64_t& aChannelId, const nsString& aAddonId,
InitStreamFilterResolver&& aResolver);
PChildToParentStreamParent* AllocPChildToParentStreamParent();
bool DeallocPChildToParentStreamParent(PChildToParentStreamParent* aActor);
PParentToChildStreamParent* AllocPParentToChildStreamParent();
bool DeallocPParentToChildStreamParent(PParentToChildStreamParent* aActor);
PHalParent* AllocPHalParent();
virtual mozilla::ipc::IPCResult RecvPHalConstructor(
@ -683,8 +675,6 @@ class ContentParent final
FORWARD_SHMEM_ALLOCATOR_TO(PContentParent)
PParentToChildStreamParent* SendPParentToChildStreamConstructor(
PParentToChildStreamParent* aActor) override;
PFileDescriptorSetParent* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) override;

View File

@ -12,8 +12,6 @@ include protocol PDocAccessible;
#endif
include protocol PFilePicker;
include protocol PRemotePrintJob;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PFileDescriptorSet;
include protocol PRemoteLazyInputStream;
include protocol PPaymentRequest;

View File

@ -27,8 +27,6 @@ include protocol PStreamFilter;
include protocol PGMPContent;
include protocol PGMPService;
include protocol PGMP;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
#ifdef MOZ_WEBSPEECH
include protocol PSpeechSynthesis;
#endif
@ -471,8 +469,6 @@ sync protocol PContent
manages PRemotePrintJob;
manages PMedia;
manages PNecko;
manages PChildToParentStream;
manages PParentToChildStream;
#ifdef MOZ_WEBSPEECH
manages PSpeechSynthesis;
#endif
@ -863,8 +859,6 @@ child:
async GMPsChanged(GMPCapabilityData[] capabilities);
async PParentToChildStream();
async ProvideAnonymousTemporaryFile(uint64_t aID, FileDescOrError aFD);
async SetPermissionsWithKey(nsCString aPermissionKey, Permission[] aPermissions);
@ -1090,8 +1084,6 @@ parent:
async PNecko();
async PChildToParentStream();
#ifdef MOZ_WEBSPEECH
async PSpeechSynthesis();
#endif

View File

@ -5,9 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBrowser;
include protocol PChildToParentStream;
include protocol PFileDescriptorSet;
include protocol PParentToChildStream;
include protocol PRemoteLazyInputStream;
include IPCBlob;

View File

@ -3,9 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBackground;
include protocol PChildToParentStream; // FIXME: bug 792908
include protocol PFileDescriptorSet; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include protocol PRemoteLazyInputStream; // FIXME: bug 792908
include DOMTypes;

View File

@ -8,8 +8,6 @@
include protocol PNecko;
include protocol PBackground;
include protocol PFileDescriptorSet; // FIXME: bug #792908
include protocol PChildToParentStream; //FIXME: bug #792908
include protocol PParentToChildStream; //FIXME: bug #792908
include IPCStream;

View File

@ -7,8 +7,6 @@ include protocol PContent;
include protocol PWebBrowserPersistResources;
include protocol PWebBrowserPersistSerialize;
include protocol PFileDescriptorSet;
include protocol PChildToParentStream; //FIXME: bug #792908
include protocol PParentToChildStream; //FIXME: bug #792908
include PBackgroundSharedTypes;
include IPCStream;

View File

@ -46,10 +46,7 @@
#include "mozilla/dom/ServiceWorkerContainerChild.h"
#include "mozilla/dom/ServiceWorkerManagerChild.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
#include "mozilla/ipc/PBackgroundTestChild.h"
#include "mozilla/ipc/PChildToParentStreamChild.h"
#include "mozilla/ipc/PParentToChildStreamChild.h"
#include "mozilla/net/HttpBackgroundChannelChild.h"
#include "mozilla/net/PUDPSocketChild.h"
#include "mozilla/dom/network/UDPSocketChild.h"
@ -525,28 +522,6 @@ bool BackgroundChildImpl::DeallocPMessagePortChild(PMessagePortChild* aActor) {
return true;
}
PChildToParentStreamChild*
BackgroundChildImpl::AllocPChildToParentStreamChild() {
MOZ_CRASH("PChildToParentStreamChild actors should be manually constructed!");
}
bool BackgroundChildImpl::DeallocPChildToParentStreamChild(
PChildToParentStreamChild* aActor) {
delete aActor;
return true;
}
PParentToChildStreamChild*
BackgroundChildImpl::AllocPParentToChildStreamChild() {
return mozilla::ipc::AllocPParentToChildStreamChild();
}
bool BackgroundChildImpl::DeallocPParentToChildStreamChild(
PParentToChildStreamChild* aActor) {
delete aActor;
return true;
}
BackgroundChildImpl::PQuotaChild* BackgroundChildImpl::AllocPQuotaChild() {
MOZ_CRASH("PQuotaChild actor should be manually constructed!");
}
@ -671,12 +646,6 @@ bool BackgroundChildImpl::DeallocPMediaTransportChild(
return true;
}
PChildToParentStreamChild*
BackgroundChildImpl::SendPChildToParentStreamConstructor(
PChildToParentStreamChild* aActor) {
return PBackgroundChild::SendPChildToParentStreamConstructor(aActor);
}
PFileDescriptorSetChild* BackgroundChildImpl::SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) {
return PBackgroundChild::SendPFileDescriptorSetConstructor(aFD);

View File

@ -41,8 +41,6 @@ class BackgroundChildImpl : public PBackgroundChild,
// This functions is implemented in BackgroundImpl.cpp.
static ThreadLocal* GetThreadLocalForCurrentThread();
PChildToParentStreamChild* SendPChildToParentStreamConstructor(
PChildToParentStreamChild* aActor) override;
PFileDescriptorSetChild* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) override;
@ -206,16 +204,6 @@ class BackgroundChildImpl : public PBackgroundChild,
virtual bool DeallocPMessagePortChild(PMessagePortChild* aActor) override;
virtual PChildToParentStreamChild* AllocPChildToParentStreamChild() override;
virtual bool DeallocPChildToParentStreamChild(
PChildToParentStreamChild* aActor) override;
virtual PParentToChildStreamChild* AllocPParentToChildStreamChild() override;
virtual bool DeallocPParentToChildStreamChild(
PParentToChildStreamChild* aActor) override;
virtual PQuotaChild* AllocPQuotaChild() override;
virtual bool DeallocPQuotaChild(PQuotaChild* aActor) override;

View File

@ -62,12 +62,9 @@
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
#include "mozilla/ipc/IdleSchedulerParent.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/ipc/PBackgroundTestParent.h"
#include "mozilla/ipc/PChildToParentStreamParent.h"
#include "mozilla/ipc/PParentToChildStreamParent.h"
#include "mozilla/media/MediaParent.h"
#include "mozilla/net/BackgroundDataBridgeParent.h"
#include "mozilla/net/HttpBackgroundChannelParent.h"
@ -690,29 +687,6 @@ bool BackgroundParentImpl::DeallocPFileDescriptorSetParent(
return true;
}
PChildToParentStreamParent*
BackgroundParentImpl::AllocPChildToParentStreamParent() {
return mozilla::ipc::AllocPChildToParentStreamParent();
}
bool BackgroundParentImpl::DeallocPChildToParentStreamParent(
PChildToParentStreamParent* aActor) {
delete aActor;
return true;
}
PParentToChildStreamParent*
BackgroundParentImpl::AllocPParentToChildStreamParent() {
MOZ_CRASH(
"PParentToChildStreamParent actors should be manually constructed!");
}
bool BackgroundParentImpl::DeallocPParentToChildStreamParent(
PParentToChildStreamParent* aActor) {
delete aActor;
return true;
}
already_AddRefed<BackgroundParentImpl::PVsyncParent>
BackgroundParentImpl::AllocPVsyncParent() {
AssertIsInMainOrSocketProcess();
@ -1495,12 +1469,6 @@ BackgroundParentImpl::AllocPLockManagerParent(
aClientId);
}
PParentToChildStreamParent*
BackgroundParentImpl::SendPParentToChildStreamConstructor(
PParentToChildStreamParent* aActor) {
return PBackgroundParent::SendPParentToChildStreamConstructor(aActor);
}
PFileDescriptorSetParent*
BackgroundParentImpl::SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) {

View File

@ -18,8 +18,6 @@ namespace mozilla::ipc {
class BackgroundParentImpl : public PBackgroundParent,
public ParentToChildStreamActorManager {
public:
PParentToChildStreamParent* SendPParentToChildStreamConstructor(
PParentToChildStreamParent* aActor) override;
PFileDescriptorSetParent* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) override;
@ -241,16 +239,6 @@ class BackgroundParentImpl : public PBackgroundParent,
bool DeallocPBroadcastChannelParent(PBroadcastChannelParent* aActor) override;
PChildToParentStreamParent* AllocPChildToParentStreamParent() override;
bool DeallocPChildToParentStreamParent(
PChildToParentStreamParent* aActor) override;
PParentToChildStreamParent* AllocPParentToChildStreamParent() override;
bool DeallocPParentToChildStreamParent(
PParentToChildStreamParent* aActor) override;
PServiceWorkerManagerParent* AllocPServiceWorkerManagerParent() override;
bool DeallocPServiceWorkerManagerParent(

View File

@ -2,9 +2,6 @@
* 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 protocol PChildToParentStream;
include protocol PParentToChildStream;
include BlobTypes;
include InputStreamParams;
include ProtocolTypes;

View File

@ -1,23 +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_ipc_IPCStreamAlloc_h
#define mozilla_ipc_IPCStreamAlloc_h
namespace mozilla {
namespace ipc {
class PChildToParentStreamParent;
class PParentToChildStreamChild;
PChildToParentStreamParent* AllocPChildToParentStreamParent();
PParentToChildStreamChild* AllocPParentToChildStreamChild();
} // namespace ipc
} // namespace mozilla
#endif // mozilla_ipc_IPCStreamAlloc_h

View File

@ -1,158 +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 "IPCStreamDestination.h"
#include "IPCStreamSource.h"
#include "mozilla/Unused.h"
#include "mozilla/ipc/PChildToParentStreamChild.h"
#include "mozilla/ipc/PParentToChildStreamChild.h"
#include "mozilla/ipc/InputStreamUtils.h"
namespace mozilla {
namespace ipc {
// Child to Parent implementation
// ----------------------------------------------------------------------------
namespace {
class IPCStreamSourceChild final : public PChildToParentStreamChild,
public IPCStreamSource {
public:
static IPCStreamSourceChild* Create(nsIAsyncInputStream* aInputStream) {
MOZ_ASSERT(aInputStream);
IPCStreamSourceChild* source = new IPCStreamSourceChild(aInputStream);
if (!source->Initialize()) {
delete source;
return nullptr;
}
return source;
}
// PChildToParentStreamChild methods
void ActorDestroy(ActorDestroyReason aReason) override { ActorDestroyed(); }
IPCResult RecvStartReading() override {
Start();
return IPC_OK();
}
IPCResult RecvRequestClose(const nsresult& aRv) override {
OnEnd(aRv);
return IPC_OK();
}
void Close(nsresult aRv) override {
MOZ_ASSERT(IPCStreamSource::mState == IPCStreamSource::eClosed);
Unused << SendClose(aRv);
}
void SendData(const wr::ByteBuffer& aBuffer) override {
Unused << SendBuffer(aBuffer);
}
private:
explicit IPCStreamSourceChild(nsIAsyncInputStream* aInputStream)
: IPCStreamSource(aInputStream) {}
};
} // anonymous namespace
/* static */
PChildToParentStreamChild* IPCStreamSource::Create(
nsIAsyncInputStream* aInputStream,
ChildToParentStreamActorManager* aManager) {
MOZ_ASSERT(aInputStream);
MOZ_ASSERT(aManager);
IPCStreamSourceChild* source = IPCStreamSourceChild::Create(aInputStream);
if (!source) {
return nullptr;
}
if (!aManager->SendPChildToParentStreamConstructor(source)) {
return nullptr;
}
source->ActorConstructed();
return source;
}
/* static */
IPCStreamSource* IPCStreamSource::Cast(PChildToParentStreamChild* aActor) {
MOZ_ASSERT(aActor);
return static_cast<IPCStreamSourceChild*>(aActor);
}
// Parent to Child implementation
// ----------------------------------------------------------------------------
namespace {
class IPCStreamDestinationChild final : public PParentToChildStreamChild,
public IPCStreamDestination {
public:
nsresult Initialize() { return IPCStreamDestination::Initialize(); }
~IPCStreamDestinationChild() = default;
private:
// PParentToChildStreamChild methods
void ActorDestroy(ActorDestroyReason aReason) override { ActorDestroyed(); }
IPCResult RecvBuffer(const wr::ByteBuffer& aBuffer) override {
BufferReceived(aBuffer);
return IPC_OK();
}
IPCResult RecvClose(const nsresult& aRv) override {
CloseReceived(aRv);
return IPC_OK();
}
// IPCStreamDestination methods
void StartReading() override {
MOZ_ASSERT(HasDelayedStart());
Unused << SendStartReading();
}
void RequestClose(nsresult aRv) override { Unused << SendRequestClose(aRv); }
void TerminateDestination() override { Unused << Send__delete__(this); }
};
} // anonymous namespace
PParentToChildStreamChild* AllocPParentToChildStreamChild() {
IPCStreamDestinationChild* actor = new IPCStreamDestinationChild();
if (NS_WARN_IF(NS_FAILED(actor->Initialize()))) {
delete actor;
actor = nullptr;
}
return actor;
}
void DeallocPParentToChildStreamChild(PParentToChildStreamChild* aActor) {
delete aActor;
}
/* static */
IPCStreamDestination* IPCStreamDestination::Cast(
PParentToChildStreamChild* aActor) {
MOZ_ASSERT(aActor);
return static_cast<IPCStreamDestinationChild*>(aActor);
}
} // namespace ipc
} // namespace mozilla

View File

@ -1,404 +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 "IPCStreamDestination.h"
#include "mozilla/InputStreamLengthWrapper.h"
#include "mozilla/Mutex.h"
#include "nsIAsyncInputStream.h"
#include "nsIAsyncOutputStream.h"
#include "nsIBufferedStreams.h"
#include "nsICloneableInputStream.h"
#include "nsIPipe.h"
#include "nsThreadUtils.h"
#include "mozilla/webrender/WebRenderTypes.h"
namespace mozilla {
namespace ipc {
// ----------------------------------------------------------------------------
// IPCStreamDestination::DelayedStartInputStream
//
// When AutoIPCStream is used with delayedStart, we need to ask for data at the
// first real use of the nsIInputStream. In order to do so, we wrap the
// nsIInputStream, created by the nsIPipe, with this wrapper.
class IPCStreamDestination::DelayedStartInputStream final
: public nsIAsyncInputStream,
public nsIInputStreamCallback,
public nsISearchableInputStream,
public nsICloneableInputStream,
public nsIBufferedInputStream {
public:
NS_DECL_THREADSAFE_ISUPPORTS
DelayedStartInputStream(IPCStreamDestination* aDestination,
nsCOMPtr<nsIAsyncInputStream>&& aStream)
: mDestination(aDestination),
mStream(std::move(aStream)),
mMutex("IPCStreamDestination::DelayedStartInputStream::mMutex") {
MOZ_ASSERT(mDestination);
MOZ_ASSERT(mStream);
}
void DestinationShutdown() {
MutexAutoLock lock(mMutex);
mDestination = nullptr;
}
// nsIInputStream interface
NS_IMETHOD
Close() override {
MaybeCloseDestination();
return mStream->Close();
}
NS_IMETHOD
Available(uint64_t* aLength) override {
MaybeStartReading();
return mStream->Available(aLength);
}
NS_IMETHOD
Read(char* aBuffer, uint32_t aCount, uint32_t* aReadCount) override {
MaybeStartReading();
return mStream->Read(aBuffer, aCount, aReadCount);
}
NS_IMETHOD
ReadSegments(nsWriteSegmentFun aWriter, void* aClosure, uint32_t aCount,
uint32_t* aResult) override {
MaybeStartReading();
return mStream->ReadSegments(aWriter, aClosure, aCount, aResult);
}
NS_IMETHOD
IsNonBlocking(bool* aNonBlocking) override {
MaybeStartReading();
return mStream->IsNonBlocking(aNonBlocking);
}
// nsIAsyncInputStream interface
NS_IMETHOD
CloseWithStatus(nsresult aReason) override {
MaybeCloseDestination();
return mStream->CloseWithStatus(aReason);
}
NS_IMETHOD
AsyncWait(nsIInputStreamCallback* aCallback, uint32_t aFlags,
uint32_t aRequestedCount, nsIEventTarget* aTarget) override {
{
MutexAutoLock lock(mMutex);
if (mAsyncWaitCallback && aCallback) {
return NS_ERROR_FAILURE;
}
mAsyncWaitCallback = aCallback;
MaybeStartReading(lock);
}
nsCOMPtr<nsIInputStreamCallback> callback = aCallback ? this : nullptr;
return mStream->AsyncWait(callback, aFlags, aRequestedCount, aTarget);
}
NS_IMETHOD
Search(const char* aForString, bool aIgnoreCase, bool* aFound,
uint32_t* aOffsetSearchedTo) override {
MaybeStartReading();
nsCOMPtr<nsISearchableInputStream> searchable = do_QueryInterface(mStream);
MOZ_ASSERT(searchable);
return searchable->Search(aForString, aIgnoreCase, aFound,
aOffsetSearchedTo);
}
// nsICloneableInputStream interface
NS_IMETHOD
GetCloneable(bool* aCloneable) override {
MaybeStartReading();
nsCOMPtr<nsICloneableInputStream> cloneable = do_QueryInterface(mStream);
MOZ_ASSERT(cloneable);
return cloneable->GetCloneable(aCloneable);
}
NS_IMETHOD
Clone(nsIInputStream** aResult) override {
MaybeStartReading();
nsCOMPtr<nsICloneableInputStream> cloneable = do_QueryInterface(mStream);
MOZ_ASSERT(cloneable);
return cloneable->Clone(aResult);
}
// nsIBufferedInputStream
NS_IMETHOD
Init(nsIInputStream* aStream, uint32_t aBufferSize) override {
MaybeStartReading();
nsCOMPtr<nsIBufferedInputStream> stream = do_QueryInterface(mStream);
MOZ_ASSERT(stream);
return stream->Init(aStream, aBufferSize);
}
NS_IMETHODIMP
GetData(nsIInputStream** aResult) override {
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsIInputStreamCallback
NS_IMETHOD
OnInputStreamReady(nsIAsyncInputStream* aStream) override {
nsCOMPtr<nsIInputStreamCallback> callback;
{
MutexAutoLock lock(mMutex);
// We have been canceled in the meanwhile.
if (!mAsyncWaitCallback) {
return NS_OK;
}
callback.swap(mAsyncWaitCallback);
}
callback->OnInputStreamReady(this);
return NS_OK;
}
void MaybeStartReading();
void MaybeStartReading(const MutexAutoLock& aProofOfLook);
void MaybeCloseDestination();
private:
~DelayedStartInputStream() = default;
IPCStreamDestination* mDestination;
nsCOMPtr<nsIAsyncInputStream> mStream;
nsCOMPtr<nsIInputStreamCallback> mAsyncWaitCallback;
// This protects mDestination: any method can be called by any thread.
Mutex mMutex MOZ_UNANNOTATED;
class HelperRunnable;
};
class IPCStreamDestination::DelayedStartInputStream::HelperRunnable final
: public Runnable {
public:
enum Op {
eStartReading,
eCloseDestination,
};
HelperRunnable(
IPCStreamDestination::DelayedStartInputStream* aDelayedStartInputStream,
Op aOp)
: Runnable(
"ipc::IPCStreamDestination::DelayedStartInputStream::"
"HelperRunnable"),
mDelayedStartInputStream(aDelayedStartInputStream),
mOp(aOp) {
MOZ_ASSERT(aDelayedStartInputStream);
}
NS_IMETHOD
Run() override {
switch (mOp) {
case eStartReading:
mDelayedStartInputStream->MaybeStartReading();
break;
case eCloseDestination:
mDelayedStartInputStream->MaybeCloseDestination();
break;
}
return NS_OK;
}
private:
RefPtr<IPCStreamDestination::DelayedStartInputStream>
mDelayedStartInputStream;
Op mOp;
};
void IPCStreamDestination::DelayedStartInputStream::MaybeStartReading() {
MutexAutoLock lock(mMutex);
MaybeStartReading(lock);
}
void IPCStreamDestination::DelayedStartInputStream::MaybeStartReading(
const MutexAutoLock& aProofOfLook) {
if (!mDestination) {
return;
}
if (mDestination->IsOnOwningThread()) {
mDestination->StartReading();
mDestination = nullptr;
return;
}
RefPtr<Runnable> runnable =
new HelperRunnable(this, HelperRunnable::eStartReading);
mDestination->DispatchRunnable(runnable.forget());
}
void IPCStreamDestination::DelayedStartInputStream::MaybeCloseDestination() {
MutexAutoLock lock(mMutex);
if (!mDestination) {
return;
}
if (mDestination->IsOnOwningThread()) {
mDestination->RequestClose(NS_ERROR_ABORT);
mDestination = nullptr;
return;
}
RefPtr<Runnable> runnable =
new HelperRunnable(this, HelperRunnable::eCloseDestination);
mDestination->DispatchRunnable(runnable.forget());
}
NS_IMPL_ADDREF(IPCStreamDestination::DelayedStartInputStream);
NS_IMPL_RELEASE(IPCStreamDestination::DelayedStartInputStream);
NS_INTERFACE_MAP_BEGIN(IPCStreamDestination::DelayedStartInputStream)
NS_INTERFACE_MAP_ENTRY(nsIAsyncInputStream)
NS_INTERFACE_MAP_ENTRY(nsIInputStreamCallback)
NS_INTERFACE_MAP_ENTRY(nsISearchableInputStream)
NS_INTERFACE_MAP_ENTRY(nsICloneableInputStream)
NS_INTERFACE_MAP_ENTRY(nsIBufferedInputStream)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIInputStream, nsIAsyncInputStream)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAsyncInputStream)
NS_INTERFACE_MAP_END
// ----------------------------------------------------------------------------
// IPCStreamDestination
IPCStreamDestination::IPCStreamDestination()
: mOwningThread(NS_GetCurrentThread()),
mDelayedStart(false)
#ifdef MOZ_DEBUG
,
mLengthSet(false)
#endif
{
}
IPCStreamDestination::~IPCStreamDestination() = default;
nsresult IPCStreamDestination::Initialize() {
MOZ_ASSERT(!mReader);
MOZ_ASSERT(!mWriter);
// use async versions for both reader and writer even though we are
// opening the writer as an infinite stream. We want to be able to
// use CloseWithStatus() to communicate errors through the pipe.
// Use an "infinite" pipe because we cannot apply back-pressure through
// the async IPC layer at the moment. Blocking the IPC worker thread
// is not desirable, either.
nsresult rv = NS_NewPipe2(getter_AddRefs(mReader), getter_AddRefs(mWriter),
true, true, // non-blocking
0, // segment size
UINT32_MAX); // "infinite" pipe
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
void IPCStreamDestination::SetDelayedStart(bool aDelayedStart) {
mDelayedStart = aDelayedStart;
}
void IPCStreamDestination::SetLength(int64_t aLength) {
MOZ_ASSERT(mReader);
MOZ_ASSERT(!mLengthSet);
#ifdef DEBUG
mLengthSet = true;
#endif
mLength = aLength;
}
already_AddRefed<nsIInputStream> IPCStreamDestination::TakeReader() {
MOZ_ASSERT(mReader);
MOZ_ASSERT(!mDelayedStartInputStream);
nsCOMPtr<nsIAsyncInputStream> reader{mReader.forget()};
if (mDelayedStart) {
mDelayedStartInputStream =
new DelayedStartInputStream(this, std::move(reader));
reader = mDelayedStartInputStream;
MOZ_ASSERT(reader);
}
if (mLength != -1) {
MOZ_ASSERT(mLengthSet);
nsCOMPtr<nsIInputStream> finalStream =
new InputStreamLengthWrapper(reader.forget(), mLength);
reader = do_QueryInterface(finalStream);
MOZ_ASSERT(reader);
}
return reader.forget();
}
bool IPCStreamDestination::IsOnOwningThread() const {
return mOwningThread == NS_GetCurrentThread();
}
void IPCStreamDestination::DispatchRunnable(
already_AddRefed<nsIRunnable>&& aRunnable) {
nsCOMPtr<nsIRunnable> runnable = aRunnable;
mOwningThread->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
}
void IPCStreamDestination::ActorDestroyed() {
MOZ_ASSERT(mWriter);
// If we were gracefully closed we should have gotten RecvClose(). In
// that case, the writer will already be closed and this will have no
// effect. This just aborts the writer in the case where the child process
// crashes.
mWriter->CloseWithStatus(NS_ERROR_ABORT);
if (mDelayedStartInputStream) {
mDelayedStartInputStream->DestinationShutdown();
mDelayedStartInputStream = nullptr;
}
}
void IPCStreamDestination::BufferReceived(const wr::ByteBuffer& aBuffer) {
MOZ_ASSERT(mWriter);
uint32_t numWritten = 0;
// This should only fail if we hit an OOM condition.
nsresult rv = mWriter->Write(reinterpret_cast<char*>(aBuffer.mData),
aBuffer.mLength, &numWritten);
if (NS_WARN_IF(NS_FAILED(rv))) {
RequestClose(rv);
}
}
void IPCStreamDestination::CloseReceived(nsresult aRv) {
MOZ_ASSERT(mWriter);
mWriter->CloseWithStatus(aRv);
TerminateDestination();
}
} // namespace ipc
} // namespace mozilla

View File

@ -1,96 +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_ipc_IPCStreamDestination_h
#define mozilla_ipc_IPCStreamDestination_h
#include "mozilla/AlreadyAddRefed.h"
#include "nsIRunnable.h"
#include "nsIThread.h"
class nsIInputStream;
class nsIAsyncInputStream;
class nsIAsyncOutputStream;
namespace mozilla {
namespace wr {
struct ByteBuffer;
} // namespace wr
namespace ipc {
class PChildToParentStreamParent;
class PParentToChildStreamChild;
// On the destination side, you must simply call TakeReader() upon receiving a
// reference to the IPCStream{Child,Parent} actor. You do not need to maintain
// a reference to the actor itself.
class IPCStreamDestination {
public:
static IPCStreamDestination* Cast(PChildToParentStreamParent* aActor);
static IPCStreamDestination* Cast(PParentToChildStreamChild* aActor);
void SetDelayedStart(bool aDelayedStart);
void SetLength(int64_t aLength);
already_AddRefed<nsIInputStream> TakeReader();
bool IsOnOwningThread() const;
void DispatchRunnable(already_AddRefed<nsIRunnable>&& aRunnable);
protected:
IPCStreamDestination();
virtual ~IPCStreamDestination();
nsresult Initialize();
// The implementation of the actor should call these methods.
void ActorDestroyed();
void BufferReceived(const wr::ByteBuffer& aBuffer);
void CloseReceived(nsresult aRv);
#ifdef DEBUG
bool HasDelayedStart() const { return mDelayedStart; }
#endif
// These methods will be implemented by the actor.
virtual void StartReading() = 0;
virtual void RequestClose(nsresult aRv) = 0;
virtual void TerminateDestination() = 0;
private:
nsCOMPtr<nsIAsyncInputStream> mReader;
nsCOMPtr<nsIAsyncOutputStream> mWriter;
// This is created by TakeReader() if we need to delay the reading of data.
// We keep a reference to the stream in order to inform it when the actor goes
// away. If that happens, the reading of data will not be possible anymore.
class DelayedStartInputStream;
RefPtr<DelayedStartInputStream> mDelayedStartInputStream;
int64_t mLength = -1;
nsCOMPtr<nsIThread> mOwningThread;
bool mDelayedStart;
#ifdef MOZ_DEBUG
bool mLengthSet;
#endif
};
} // namespace ipc
} // namespace mozilla
#endif // mozilla_ipc_IPCStreamDestination_h

View File

@ -1,158 +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 "IPCStreamDestination.h"
#include "mozilla/ipc/IPCStreamSource.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/ipc/PChildToParentStreamParent.h"
#include "mozilla/ipc/PParentToChildStreamParent.h"
#include "mozilla/Unused.h"
namespace mozilla {
namespace ipc {
// Child to Parent implementation
// ----------------------------------------------------------------------------
namespace {
class IPCStreamSourceParent final : public PParentToChildStreamParent,
public IPCStreamSource {
public:
static IPCStreamSourceParent* Create(nsIAsyncInputStream* aInputStream) {
MOZ_ASSERT(aInputStream);
IPCStreamSourceParent* source = new IPCStreamSourceParent(aInputStream);
if (!source->Initialize()) {
delete source;
return nullptr;
}
return source;
}
// PParentToChildStreamParent methods
void ActorDestroy(ActorDestroyReason aReason) override { ActorDestroyed(); }
IPCResult RecvStartReading() override {
Start();
return IPC_OK();
}
IPCResult RecvRequestClose(const nsresult& aRv) override {
OnEnd(aRv);
return IPC_OK();
}
void Close(nsresult aRv) override {
MOZ_ASSERT(IPCStreamSource::mState == IPCStreamSource::eClosed);
Unused << SendClose(aRv);
}
void SendData(const wr::ByteBuffer& aBuffer) override {
Unused << SendBuffer(aBuffer);
}
private:
explicit IPCStreamSourceParent(nsIAsyncInputStream* aInputStream)
: IPCStreamSource(aInputStream) {}
};
} // anonymous namespace
/* static */
PParentToChildStreamParent* IPCStreamSource::Create(
nsIAsyncInputStream* aInputStream,
ParentToChildStreamActorManager* aManager) {
MOZ_ASSERT(aInputStream);
MOZ_ASSERT(aManager);
IPCStreamSourceParent* source = IPCStreamSourceParent::Create(aInputStream);
if (!source) {
return nullptr;
}
if (!aManager->SendPParentToChildStreamConstructor(source)) {
// no delete here, the manager will delete the actor for us.
return nullptr;
}
source->ActorConstructed();
return source;
}
/* static */
IPCStreamSource* IPCStreamSource::Cast(PParentToChildStreamParent* aActor) {
MOZ_ASSERT(aActor);
return static_cast<IPCStreamSourceParent*>(aActor);
}
// Child to Parent implementation
// ----------------------------------------------------------------------------
namespace {
class IPCStreamDestinationParent final : public PChildToParentStreamParent,
public IPCStreamDestination {
public:
nsresult Initialize() { return IPCStreamDestination::Initialize(); }
~IPCStreamDestinationParent() = default;
private:
// PChildToParentStreamParent methods
void ActorDestroy(ActorDestroyReason aReason) override { ActorDestroyed(); }
IPCResult RecvBuffer(const wr::ByteBuffer& aBuffer) override {
BufferReceived(aBuffer);
return IPC_OK();
}
IPCResult RecvClose(const nsresult& aRv) override {
CloseReceived(aRv);
return IPC_OK();
}
// IPCStreamDestination methods
void StartReading() override {
MOZ_ASSERT(HasDelayedStart());
Unused << SendStartReading();
}
void RequestClose(nsresult aRv) override { Unused << SendRequestClose(aRv); }
void TerminateDestination() override { Unused << Send__delete__(this); }
};
} // anonymous namespace
PChildToParentStreamParent* AllocPChildToParentStreamParent() {
IPCStreamDestinationParent* actor = new IPCStreamDestinationParent();
if (NS_WARN_IF(NS_FAILED(actor->Initialize()))) {
delete actor;
actor = nullptr;
}
return actor;
}
void DeallocPChildToParentStreamParent(PChildToParentStreamParent* aActor) {
delete aActor;
}
/* static */
IPCStreamDestination* IPCStreamDestination::Cast(
PChildToParentStreamParent* aActor) {
MOZ_ASSERT(aActor);
return static_cast<IPCStreamDestinationParent*>(aActor);
}
} // namespace ipc
} // namespace mozilla

View File

@ -1,278 +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 "IPCStreamSource.h"
#include "BackgroundParent.h" // for AssertIsOnBackgroundThread
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/RemoteWorkerService.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/webrender/WebRenderTypes.h"
#include "nsIAsyncInputStream.h"
#include "nsICancelableRunnable.h"
#include "nsIRunnable.h"
#include "nsISerialEventTarget.h"
#include "nsStreamUtils.h"
#include "nsThreadUtils.h"
#include "nsIThread.h"
using mozilla::wr::ByteBuffer;
namespace mozilla {
namespace ipc {
class IPCStreamSource::Callback final : public DiscardableRunnable,
public nsIInputStreamCallback {
public:
explicit Callback(IPCStreamSource* aSource)
: DiscardableRunnable("IPCStreamSource::Callback"),
mSource(aSource),
mOwningEventTarget(GetCurrentSerialEventTarget()) {
MOZ_ASSERT(mSource);
}
NS_IMETHOD
OnInputStreamReady(nsIAsyncInputStream* aStream) override {
// any thread
if (mOwningEventTarget->IsOnCurrentThread()) {
return Run();
}
// If this fails, then it means the owning thread is a Worker that has
// been shutdown. Its ok to lose the event in this case because the
// IPCStreamChild listens for this event through the WorkerRef.
nsresult rv =
mOwningEventTarget->Dispatch(this, nsIThread::DISPATCH_NORMAL);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to dispatch stream readable event to owning thread");
}
return NS_OK;
}
NS_IMETHOD
Run() override {
MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
if (mSource) {
mSource->OnStreamReady(this);
}
return NS_OK;
}
// OnDiscard() gets called when the Worker thread is being shutdown. We have
// nothing to do here because IPCStreamChild handles this case via
// the WorkerRef.
void ClearSource() {
MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
MOZ_ASSERT(mSource);
mSource = nullptr;
}
private:
~Callback() {
// called on any thread
// ClearSource() should be called before the Callback is destroyed
MOZ_ASSERT(!mSource);
}
// This is a raw pointer because the source keeps alive the callback and,
// before beeing destroyed, it nullifies this pointer (this happens when
// ActorDestroyed() is called).
IPCStreamSource* mSource;
nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
NS_DECL_ISUPPORTS_INHERITED
};
NS_IMPL_ISUPPORTS_INHERITED(IPCStreamSource::Callback, DiscardableRunnable,
nsIInputStreamCallback);
IPCStreamSource::IPCStreamSource(nsIAsyncInputStream* aInputStream)
: mStream(aInputStream), mState(ePending) {
MOZ_ASSERT(aInputStream);
}
IPCStreamSource::~IPCStreamSource() {
NS_ASSERT_OWNINGTHREAD(IPCStreamSource);
MOZ_ASSERT(mState == eClosed);
MOZ_ASSERT(!mCallback);
MOZ_ASSERT(!mWorkerRef);
}
bool IPCStreamSource::Initialize() {
bool nonBlocking = false;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(mStream->IsNonBlocking(&nonBlocking)));
// IPCStreamChild reads in the current thread, so it is only supported on
// non-blocking, async channels
if (!nonBlocking) {
return false;
}
// A source can be used on any thread, but we only support IPCStream on
// main thread, Workers, Worker Launcher, and PBackground thread right now.
// This is due to the requirement that the thread be guaranteed to live long
// enough to receive messages. We can enforce this guarantee with a
// StrongWorkerRef on worker threads, but not other threads. Main-thread,
// PBackground, and Worker Launcher threads do not need anything special in
// order to be kept alive.
if (!NS_IsMainThread()) {
if (const auto workerPrivate = dom::GetCurrentThreadWorkerPrivate()) {
RefPtr<dom::StrongWorkerRef> workerRef =
dom::StrongWorkerRef::CreateForcibly(workerPrivate,
"IPCStreamSource");
if (NS_WARN_IF(!workerRef)) {
return false;
}
mWorkerRef = std::move(workerRef);
} else {
MOZ_DIAGNOSTIC_ASSERT(
IsOnBackgroundThread() ||
dom::RemoteWorkerService::Thread()->IsOnCurrentThread());
}
}
return true;
}
void IPCStreamSource::ActorConstructed() {
MOZ_ASSERT(mState == ePending);
mState = eActorConstructed;
}
void IPCStreamSource::ActorDestroyed() {
NS_ASSERT_OWNINGTHREAD(IPCStreamSource);
mState = eClosed;
if (mCallback) {
mCallback->ClearSource();
mCallback = nullptr;
}
mWorkerRef = nullptr;
}
void IPCStreamSource::Start() {
NS_ASSERT_OWNINGTHREAD(IPCStreamSource);
DoRead();
}
void IPCStreamSource::StartDestroy() {
NS_ASSERT_OWNINGTHREAD(IPCStreamSource);
OnEnd(NS_ERROR_ABORT);
}
void IPCStreamSource::DoRead() {
NS_ASSERT_OWNINGTHREAD(IPCStreamSource);
MOZ_ASSERT(mState == eActorConstructed);
MOZ_ASSERT(!mCallback);
// The input stream (likely a pipe) probably uses a segment size of
// 4kb. If there is data already buffered it would be nice to aggregate
// multiple segments into a single IPC call. Conversely, don't send too
// too large of a buffer in a single call to avoid spiking memory.
static const uint64_t kMaxBytesPerMessage = 32 * 1024;
static_assert(kMaxBytesPerMessage <= static_cast<uint64_t>(UINT32_MAX),
"kMaxBytesPerMessage must cleanly cast to uint32_t");
UniquePtr<char[]> buffer(new char[kMaxBytesPerMessage]);
while (true) {
// It should not be possible to transition to closed state without
// this loop terminating via a return.
MOZ_ASSERT(mState == eActorConstructed);
// See if the stream is closed by checking the return of Available.
uint64_t dummy;
nsresult rv = mStream->Available(&dummy);
if (NS_FAILED(rv)) {
OnEnd(rv);
return;
}
uint32_t bytesRead = 0;
rv = mStream->Read(buffer.get(), kMaxBytesPerMessage, &bytesRead);
if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
MOZ_ASSERT(bytesRead == 0);
Wait();
return;
}
if (NS_FAILED(rv)) {
MOZ_ASSERT(bytesRead == 0);
OnEnd(rv);
return;
}
// Zero-byte read indicates end-of-stream.
if (bytesRead == 0) {
OnEnd(NS_BASE_STREAM_CLOSED);
return;
}
// We read some data from the stream, send it across.
SendData(ByteBuffer(bytesRead, reinterpret_cast<uint8_t*>(buffer.get())));
}
}
void IPCStreamSource::Wait() {
NS_ASSERT_OWNINGTHREAD(IPCStreamSource);
MOZ_ASSERT(mState == eActorConstructed);
MOZ_ASSERT(!mCallback);
// Set mCallback immediately instead of waiting for success. Its possible
// AsyncWait() will callback synchronously.
mCallback = new Callback(this);
nsresult rv = mStream->AsyncWait(mCallback, 0, 0, nullptr);
if (NS_FAILED(rv)) {
OnEnd(rv);
return;
}
}
void IPCStreamSource::OnStreamReady(Callback* aCallback) {
NS_ASSERT_OWNINGTHREAD(IPCStreamSource);
MOZ_ASSERT(mCallback);
MOZ_ASSERT(aCallback == mCallback);
mCallback->ClearSource();
mCallback = nullptr;
// Possibly closed if this callback is (indirectly) called by
// IPCStreamSourceParent::RecvRequestClose().
if (mState == eClosed) {
return;
}
DoRead();
}
void IPCStreamSource::OnEnd(nsresult aRv) {
NS_ASSERT_OWNINGTHREAD(IPCStreamSource);
MOZ_ASSERT(aRv != NS_BASE_STREAM_WOULD_BLOCK);
if (mState == eClosed) {
return;
}
mState = eClosed;
mStream->CloseWithStatus(aRv);
if (aRv == NS_BASE_STREAM_CLOSED) {
aRv = NS_OK;
}
// This will trigger an ActorDestroy() from the other side
Close(aRv);
}
} // namespace ipc
} // namespace mozilla

View File

@ -1,125 +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_ipc_IPCStreamSource_h
#define mozilla_ipc_IPCStreamSource_h
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/dom/WorkerRef.h"
#include "nsCOMPtr.h"
class nsIAsyncInputStream;
namespace mozilla {
namespace wr {
struct ByteBuffer;
} // namespace wr
namespace ipc {
class ParentToChildStreamActorManager;
class ChildToParentStreamActorManager;
class PChildToParentStreamChild;
class PParentToChildStreamParent;
// The IPCStream IPC actor is designed to push an nsIInputStream from child to
// parent or parent to child incrementally. This is mainly needed for streams
// such as nsPipe that may not yet have all their data available when the
// stream must be sent across an IPC boundary. While many streams are handled
// by SerializeInputStream(), these streams cannot be serialized and must be
// sent using this actor.
//
// The IPCStream actor only support async, non-blocking streams because they
// must be read inline on the main thread and Worker threads.
//
// In general, the creation and handling of the IPCStream actor cannot be
// abstracted away behind SerializeInputStream() because the actor must be
// carefully managed. Specifically:
//
// 1) The data flow must be explicitly initiated by calling
// IPCStreamSource{Child,Parent}::Start() after the actor has been sent to
// the other-side actor.
// 2) If the actor is never sent to the other-side, then this code must
// call IPCStreamSource{Child,Parent}::StartDestroy() to avoid memory leaks.
// 3) The IPCStreamSource actor can only be used on threads that can be
// guaranteed to stay alive as long as the actor is alive. Right now
// this limits IPCStream to the main thread and Worker threads.
//
// In general you should probably use the AutoIPCStreamSource RAII class
// defined in InputStreamUtils.h instead of using IPCStreamSource directly.
class IPCStreamSource {
public:
// Create a IPCStreamSource using a ChildToParentStreamActorManager manager.
// This can return nullptr if the provided stream is blocking.
static PChildToParentStreamChild* Create(
nsIAsyncInputStream* aInputStream,
ChildToParentStreamActorManager* aManager);
// Create a IPCStreamSource using a ParentToChildStreamActorManager manager.
// This can return nullptr if the provided stream is blocking.
static PParentToChildStreamParent* Create(
nsIAsyncInputStream* aInputStream,
ParentToChildStreamActorManager* aManager);
static IPCStreamSource* Cast(PChildToParentStreamChild* aActor);
static IPCStreamSource* Cast(PParentToChildStreamParent* aActor);
// Start reading data from the nsIAsyncInputStream used to create the actor.
// This must be called after the actor is passed to the parent. If you
// use AutoIPCStream this is handled automatically.
void Start();
// Start cleaning up the actor. This must be called if the actor is never
// sent to the other side. If you use AutoIPCStream this is handled
// automatically.
void StartDestroy();
protected:
IPCStreamSource(nsIAsyncInputStream* aInputStream);
virtual ~IPCStreamSource();
bool Initialize();
void ActorDestroyed();
void OnEnd(nsresult aRv);
virtual void Close(nsresult aRv) = 0;
virtual void SendData(const wr::ByteBuffer& aBuffer) = 0;
void ActorConstructed();
private:
class Callback;
void DoRead();
void Wait();
void OnStreamReady(Callback* aCallback);
nsCOMPtr<nsIAsyncInputStream> mStream;
RefPtr<Callback> mCallback;
RefPtr<dom::StrongWorkerRef> mWorkerRef;
#ifdef DEBUG
protected:
#endif
enum { ePending, eActorConstructed, eClosed } mState;
private:
NS_DECL_OWNINGTHREAD
};
} // namespace ipc
} // namespace mozilla
#endif // mozilla_ipc_IPCStreamSource_h

View File

@ -289,10 +289,6 @@ void ActivateAndCleanupIPCStream(IPCStream& aValue, bool aConsumedByIPC,
Unused << FileDescriptorSetParent::Send__delete__(fdSetActor);
}
}
// Activate IPCRemoteStreamParams.
InputStreamHelper::PostSerializationActivation(aValue.stream(),
aConsumedByIPC, aDelayedStart);
}
void ActivateAndCleanupIPCStream(Maybe<IPCStream>& aValue, bool aConsumedByIPC,
@ -325,10 +321,6 @@ bool NormalizeOptionalValue(nsIInputStream* aStream, IPCStream* aValue,
} // anonymous namespace
already_AddRefed<nsIInputStream> DeserializeIPCStream(const IPCStream& aValue) {
// Note, we explicitly do not support deserializing the PChildToParentStream
// actor on the child side nor the PParentToChildStream actor on the parent
// side.
AutoTArray<FileDescriptor, 4> fds;
if (aValue.optionalFds().type() ==
OptionalFileDescriptorSet::TPFileDescriptorSetParent) {

View File

@ -36,8 +36,7 @@ already_AddRefed<nsIInputStream> DeserializeIPCStream(
const Maybe<IPCStream>& aValue);
// RAII helper class that serializes an nsIInputStream into an IPCStream struct.
// Any file descriptor or PChildToParentStream actors are automatically managed
// correctly.
// Any file descriptor actors are automatically managed correctly.
//
// Here is a simple example:
//
@ -64,8 +63,7 @@ already_AddRefed<nsIInputStream> DeserializeIPCStream(
// nsCOMPtr<nsIInputStream> stream = DeserializeIPCStream(aIPCStream);
// // Do something with stream...
//
// // You can also serialize streams from parent-to-child as long as
// // they don't require PChildToParentStream actor support.
// // You can also serialize streams from parent-to-child.
// AutoIPCStream anotherStream;
// anotherStream.Serialize(mFileStream, Manager());
// SendStuffDone(anotherStream.TakeValue());
@ -114,9 +112,7 @@ already_AddRefed<nsIInputStream> DeserializeIPCStream(
// TakeOptionalValue() instead.
//
// The AutoIPCStream class can also be used to serialize nsIInputStream objects
// on the parent side to send to the child. Currently, however, this only
// works for directly serializable stream types. The PChildToParentStream actor
// mechanism is not supported in this direction yet.
// on the parent side to send to the child.
//
// Like SerializeInputStream(), the AutoIPCStream will crash if
// serialization cannot be completed.

View File

@ -4,8 +4,6 @@
include ProtocolTypes;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PRemoteLazyInputStream;
using struct mozilla::void_t from "mozilla/ipc/IPCCore.h";
@ -62,25 +60,6 @@ union RemoteLazyInputStreamParams
PRemoteLazyInputStream;
};
union IPCRemoteStreamType
{
PChildToParentStream;
PParentToChildStream;
};
struct IPCRemoteStreamParams
{
// If this is true, the stream will send data only when the first operation
// is done on the destination side. The benefit of this is that we do not
// send data if not needed. On the other hand, it could have a performance
// issue.
bool delayedStart;
IPCRemoteStreamType stream;
int64_t length;
};
struct DataPipeReceiverStreamParams
{
DataPipeReceiver pipe;
@ -96,7 +75,6 @@ union InputStreamParams
SlicedInputStreamParams;
RemoteLazyInputStreamParams;
InputStreamLengthWrapperParams;
IPCRemoteStreamParams;
EncryptedFileInputStreamParams;
DataPipeReceiverStreamParams;
};

View File

@ -13,8 +13,6 @@
#include "mozilla/dom/quota/DecryptingInputStream_impl.h"
#include "mozilla/dom/quota/IPCStreamCipherStrategy.h"
#include "mozilla/ipc/DataPipe.h"
#include "mozilla/ipc/IPCStreamDestination.h"
#include "mozilla/ipc/IPCStreamSource.h"
#include "mozilla/InputStreamLengthHelper.h"
#include "mozilla/RemoteLazyInputStream.h"
#include "mozilla/RemoteLazyInputStreamChild.h"
@ -84,42 +82,28 @@ void SerializeInputStreamAsPipeInternal(nsIInputStream* aInputStream,
length = -1;
}
nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(aInputStream);
// As a fallback, attempt to stream the data across using a IPCStream
// actor. For blocking streams, create a nonblocking pipe instead,
bool nonBlocking = false;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(aInputStream->IsNonBlocking(&nonBlocking)));
if (!nonBlocking || !asyncStream) {
const uint32_t kBufferSize = 32768; // matches IPCStream buffer size.
nsCOMPtr<nsIAsyncOutputStream> sink;
nsresult rv = NS_NewPipe2(getter_AddRefs(asyncStream), getter_AddRefs(sink),
true, false, kBufferSize, UINT32_MAX);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
nsCOMPtr<nsIEventTarget> target =
do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
// Since the source stream could be used by others, let's not close it when
// the copy is done.
rv = NS_AsyncCopy(aInputStream, sink, target, NS_ASYNCCOPY_VIA_READSEGMENTS,
kBufferSize, nullptr, nullptr, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
}
MOZ_DIAGNOSTIC_ASSERT(asyncStream);
auto* streamSource = IPCStreamSource::Create(asyncStream, aManager);
if (NS_WARN_IF(!streamSource)) {
// Failed to create IPCStreamSource, which would cause a failure should we
// attempt to serialize it later. So abort now.
RefPtr<DataPipeSender> sender;
RefPtr<DataPipeReceiver> receiver;
nsresult rv = NewDataPipe(kDefaultDataPipeCapacity, getter_AddRefs(sender),
getter_AddRefs(receiver));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
aParams = IPCRemoteStreamParams(aDelayedStart, streamSource, length);
nsCOMPtr<nsIEventTarget> target =
do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
rv =
NS_AsyncCopy(aInputStream, sender, target, NS_ASYNCCOPY_VIA_WRITESEGMENTS,
kDefaultDataPipeCapacity, nullptr, nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
aParams = DataPipeReceiverStreamParams(receiver);
if (length != -1) {
aParams = InputStreamLengthWrapperParams(aParams, length, false);
}
}
} // namespace
@ -173,116 +157,6 @@ void InputStreamHelper::SerializeInputStreamAsPipe(
aManager);
}
void InputStreamHelper::PostSerializationActivation(InputStreamParams& aParams,
bool aConsumedByIPC,
bool aDelayedStart) {
switch (aParams.type()) {
case InputStreamParams::TBufferedInputStreamParams: {
BufferedInputStreamParams& params =
aParams.get_BufferedInputStreamParams();
InputStreamHelper::PostSerializationActivation(
params.optionalStream(), aConsumedByIPC, aDelayedStart);
return;
}
case InputStreamParams::TMIMEInputStreamParams: {
MIMEInputStreamParams& params = aParams.get_MIMEInputStreamParams();
InputStreamHelper::PostSerializationActivation(
params.optionalStream(), aConsumedByIPC, aDelayedStart);
return;
}
case InputStreamParams::TMultiplexInputStreamParams: {
MultiplexInputStreamParams& params =
aParams.get_MultiplexInputStreamParams();
for (InputStreamParams& subParams : params.streams()) {
InputStreamHelper::PostSerializationActivation(
subParams, aConsumedByIPC, aDelayedStart);
}
return;
}
case InputStreamParams::TSlicedInputStreamParams: {
SlicedInputStreamParams& params = aParams.get_SlicedInputStreamParams();
InputStreamHelper::PostSerializationActivation(
params.stream(), aConsumedByIPC, aDelayedStart);
return;
}
case InputStreamParams::TInputStreamLengthWrapperParams: {
InputStreamLengthWrapperParams& params =
aParams.get_InputStreamLengthWrapperParams();
InputStreamHelper::PostSerializationActivation(
params.stream(), aConsumedByIPC, aDelayedStart);
return;
}
case InputStreamParams::TIPCRemoteStreamParams: {
IPCRemoteStreamType& remoteInputStream =
aParams.get_IPCRemoteStreamParams().stream();
IPCStreamSource* source = nullptr;
if (remoteInputStream.type() ==
IPCRemoteStreamType::TPChildToParentStreamChild) {
source = IPCStreamSource::Cast(
remoteInputStream.get_PChildToParentStreamChild());
} else {
MOZ_ASSERT(remoteInputStream.type() ==
IPCRemoteStreamType::TPParentToChildStreamParent);
source = IPCStreamSource::Cast(
remoteInputStream.get_PParentToChildStreamParent());
}
MOZ_ASSERT(source);
// If the source stream has not been taken to be sent to the other side,
// we can destroy it.
if (!aConsumedByIPC) {
source->StartDestroy();
return;
}
if (!aDelayedStart) {
// If we don't need to do a delayedStart, we start it now. Otherwise,
// the Start() will be called at the first use by the
// IPCStreamDestination::DelayedStartInputStream.
source->Start();
}
return;
}
case InputStreamParams::TDataPipeReceiverStreamParams:
break;
case InputStreamParams::TStringInputStreamParams:
break;
case InputStreamParams::TFileInputStreamParams:
break;
case InputStreamParams::TRemoteLazyInputStreamParams:
break;
case InputStreamParams::TEncryptedFileInputStreamParams:
break;
default:
MOZ_CRASH(
"A new stream? Should decide if it must be processed recursively or "
"not.");
}
}
void InputStreamHelper::PostSerializationActivation(
Maybe<InputStreamParams>& aParams, bool aConsumedByIPC,
bool aDelayedStart) {
if (aParams.isSome()) {
InputStreamHelper::PostSerializationActivation(
aParams.ref(), aConsumedByIPC, aDelayedStart);
}
}
already_AddRefed<nsIInputStream> InputStreamHelper::DeserializeInputStream(
const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors) {
@ -317,28 +191,6 @@ already_AddRefed<nsIInputStream> InputStreamHelper::DeserializeInputStream(
return stream.forget();
}
if (aParams.type() == InputStreamParams::TIPCRemoteStreamParams) {
const IPCRemoteStreamParams& remoteStream =
aParams.get_IPCRemoteStreamParams();
const IPCRemoteStreamType& remoteStreamType = remoteStream.stream();
IPCStreamDestination* destinationStream;
if (remoteStreamType.type() ==
IPCRemoteStreamType::TPChildToParentStreamParent) {
destinationStream = IPCStreamDestination::Cast(
remoteStreamType.get_PChildToParentStreamParent());
} else {
MOZ_ASSERT(remoteStreamType.type() ==
IPCRemoteStreamType::TPParentToChildStreamChild);
destinationStream = IPCStreamDestination::Cast(
remoteStreamType.get_PParentToChildStreamChild());
}
destinationStream->SetDelayedStart(remoteStream.delayedStart());
destinationStream->SetLength(remoteStream.length());
return destinationStream->TakeReader();
}
if (aParams.type() == InputStreamParams::TDataPipeReceiverStreamParams) {
const DataPipeReceiverStreamParams& pipeParams =
aParams.get_DataPipeReceiverStreamParams();

View File

@ -18,23 +18,16 @@ namespace ipc {
class FileDescriptor;
class PFileDescriptorSetChild;
class PFileDescriptorSetParent;
class PChildToParentStreamChild;
class PParentToChildStreamParent;
// Provide two interfaces for sending PParentToChildStream and
// PFileDescriptorSet constructor messages.
// Provide two interfaces for sending PFileDescriptorSet constructor messages.
class ParentToChildStreamActorManager {
public:
virtual PParentToChildStreamParent* SendPParentToChildStreamConstructor(
PParentToChildStreamParent* aActor) = 0;
virtual PFileDescriptorSetParent* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) = 0;
};
class ChildToParentStreamActorManager {
public:
virtual PChildToParentStreamChild* SendPChildToParentStreamConstructor(
PChildToParentStreamChild* aActor) = 0;
virtual PFileDescriptorSetChild* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) = 0;
};
@ -79,17 +72,6 @@ class InputStreamHelper {
nsIInputStream* aInputStream, InputStreamParams& aParams,
bool aDelayedStart, ChildToParentStreamActorManager* aManager);
// After the sending of the inputStream into the IPC pipe, some of the
// InputStreamParams data struct needs to be activated (IPCRemoteStream).
// These 2 methods do that.
static void PostSerializationActivation(InputStreamParams& aParams,
bool aConsumedByIPC,
bool aDelayedStart);
static void PostSerializationActivation(Maybe<InputStreamParams>& aParams,
bool aConsumedByIPC,
bool aDelayedStart);
static already_AddRefed<nsIInputStream> DeserializeInputStream(
const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors);

View File

@ -42,8 +42,6 @@ include protocol PLockManager;
include protocol PMIDIManager;
include protocol PMIDIPort;
include protocol PQuota;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PServiceWorker;
include protocol PServiceWorkerContainer;
include protocol PServiceWorkerManager;
@ -124,8 +122,6 @@ sync protocol PBackground
manages PMIDIManager;
manages PMIDIPort;
manages PQuota;
manages PChildToParentStream;
manages PParentToChildStream;
manages PServiceWorker;
manages PServiceWorkerContainer;
manages PServiceWorkerManager;
@ -207,8 +203,6 @@ parent:
async PMessagePort(nsID uuid, nsID destinationUuid, uint32_t sequenceId);
async PChildToParentStream();
async MessagePortForceClose(nsID uuid, nsID destinationUuid, uint32_t sequenceId);
async PQuota();
@ -301,8 +295,6 @@ child:
async PCache();
async PCacheStreamControl();
async PParentToChildStream();
async PRemoteWorker(RemoteWorkerData data);
both:

View File

@ -1,48 +0,0 @@
/* 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 protocol PBackground;
include protocol PContent;
include protocol PSocketProcess;
include "mozilla/layers/WebRenderMessageUtils.h";
using mozilla::wr::ByteBuffer from "mozilla/webrender/WebRenderTypes.h";
namespace mozilla {
namespace ipc {
// This is protocol is the opposite of PParentToChildStream. Please keep these
// protocols in sync.
[ManualDealloc, ChildImpl=virtual, ParentImpl=virtual]
protocol PChildToParentStream
{
manager PBackground or PContent or PSocketProcess;
parent:
async Buffer(ByteBuffer aBuffer);
async Close(nsresult aRv);
child:
// The remote stream can be used in 2 ways: it can start receiving data
// immediately after the creation of the child actor, or it can wait until
// the child stream is actually used. This second configuration is enabled by
// passing 'true' to delayedStart in AutoIPCStream CTOR.
// If we are delaying the reading, at the first use of the remote stream, we
// must activate the sending of data. This happens by calling this method.
async StartReading();
// The parent side has hit an error condition and has requested the child
// actor issue a Close() message. The close must be initiated by the child
// to avoid racing with an in-flight Buffer() message.
async RequestClose(nsresult aRv);
// Stream is always destroyed from the parent side. This occurs if the
// parent encounters an error while writing to its pipe or if the child
// signals the stream should close by SendClose().
async __delete__();
};
} // namespace ipc
} // namespace mozilla

View File

@ -1,48 +0,0 @@
/* 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 protocol PBackground;
include protocol PContent;
include protocol PSocketProcess;
include "mozilla/layers/WebRenderMessageUtils.h";
using mozilla::wr::ByteBuffer from "mozilla/webrender/WebRenderTypes.h";
namespace mozilla {
namespace ipc {
// This is protocol is the opposite of PChildToParentStream. Please keep these
// protocols in sync.
[ManualDealloc, ChildImpl=virtual, ParentImpl=virtual]
protocol PParentToChildStream
{
manager PBackground or PContent or PSocketProcess;
child:
async Buffer(ByteBuffer aBuffer);
async Close(nsresult aRv);
parent:
// The remote stream can be used in 2 ways: it can start receiving data
// immediately after the creation of the child actor, or it can wait until
// the child stream is actually used. This second configuration is enabled by
// passing 'true' to delayedStart in AutoIPCStream CTOR.
// If we are delaying the reading, at the first use of the remote stream, we
// must activate the sending of data. This happens by calling this method.
async StartReading();
// The parent side has hit an error condition and has requested the child
// actor issue a Close() message. The close must be initiated by the child
// to avoid racing with an in-flight Buffer() message.
async RequestClose(nsresult aRv);
// Stream is always destroyed from the parent side. This occurs if the
// parent encounters an error while writing to its pipe or if the child
// signals the stream should close by SendClose().
async __delete__();
};
} // namespace ipc
} // namespace mozilla

View File

@ -37,9 +37,6 @@ EXPORTS.mozilla.ipc += [
"InputStreamUtils.h",
"IOThreadChild.h",
"IPCCore.h",
"IPCStreamAlloc.h",
"IPCStreamDestination.h",
"IPCStreamSource.h",
"IPCStreamUtils.h",
"IPCTypes.h",
"IPDLParamTraits.h",
@ -171,10 +168,6 @@ UNIFIED_SOURCES += [
"InputStreamUtils.cpp",
"IPCMessageUtils.cpp",
"IPCMessageUtilsSpecializations.cpp",
"IPCStreamChild.cpp",
"IPCStreamDestination.cpp",
"IPCStreamParent.cpp",
"IPCStreamSource.cpp",
"IPCStreamUtils.cpp",
"LibrarySandboxPreload.cpp",
"MessageChannel.cpp",
@ -241,10 +234,8 @@ IPDL_SOURCES = [
"PBackgroundSharedTypes.ipdlh",
"PBackgroundStarter.ipdl",
"PBackgroundTest.ipdl",
"PChildToParentStream.ipdl",
"PFileDescriptorSet.ipdl",
"PIdleScheduler.ipdl",
"PParentToChildStream.ipdl",
"ProtocolTypes.ipdlh",
"PUtilityAudioDecoder.ipdl",
"URIParams.ipdlh",

View File

@ -6,7 +6,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PHttpChannel;
include protocol PChildToParentStream;
include BlobTypes;
include ClientIPCTypes;
include URIParams;

View File

@ -22,8 +22,6 @@ include protocol PFileDescriptorSet;
include protocol PDataChannel;
include protocol PSimpleChannel;
include protocol PTransportProvider;
include protocol PChildToParentStream; //FIXME: bug #792908
include protocol PParentToChildStream; //FIXME: bug #792908
include protocol PStunAddrsRequest;
include protocol PFileChannel;
include protocol PClassifierDummyChannel;

View File

@ -10,8 +10,6 @@ include protocol PWebrtcTCPSocket;
include protocol PHttpTransaction;
include protocol PHttpConnectionMgr;
include protocol PFileDescriptorSet;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PInputChannelThrottleQueue;
include protocol PBackgroundStarter;
include protocol PAltService;
@ -99,8 +97,6 @@ sync protocol PSocketProcess
manages PFileDescriptorSet;
manages PHttpTransaction;
manages PHttpConnectionMgr;
manages PChildToParentStream;
manages PParentToChildStream;
manages PInputChannelThrottleQueue;
manages PAltService;
manages PAltSvcTransaction;
@ -122,7 +118,6 @@ parent:
/* tabId is only required for web-proxy support, which isn't always needed */
async PWebrtcTCPSocket(TabId? tabId);
async PChildToParentStream();
async ObserveHttpActivity(HttpActivityArgs aActivityArgs,
uint32_t aActivityType,
uint32_t aActivitySubtype,
@ -181,7 +176,6 @@ child:
async SocketProcessTelemetryPing();
async PHttpTransaction();
async PParentToChildStream();
async PHttpConnectionMgr(HttpHandlerInitArgs aArgs);
async UpdateDeviceModelId(nsCString aModelId);

View File

@ -21,7 +21,6 @@
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/FileDescriptorSetChild.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/net/AltSvcTransactionChild.h"
#include "mozilla/net/BackgroundDataBridgeParent.h"
@ -30,8 +29,6 @@
#include "mozilla/net/NativeDNSResolverOverrideChild.h"
#include "mozilla/net/ProxyAutoConfigChild.h"
#include "mozilla/net/TRRServiceChild.h"
#include "mozilla/ipc/PChildToParentStreamChild.h"
#include "mozilla/ipc/PParentToChildStreamChild.h"
#include "mozilla/ipc/ProcessUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/RemoteLazyInputStreamChild.h"
@ -367,35 +364,6 @@ bool SocketProcessChild::DeallocPFileDescriptorSetChild(
return true;
}
PChildToParentStreamChild*
SocketProcessChild::AllocPChildToParentStreamChild() {
MOZ_CRASH("PChildToParentStreamChild actors should be manually constructed!");
}
bool SocketProcessChild::DeallocPChildToParentStreamChild(
PChildToParentStreamChild* aActor) {
delete aActor;
return true;
}
PParentToChildStreamChild*
SocketProcessChild::AllocPParentToChildStreamChild() {
return mozilla::ipc::AllocPParentToChildStreamChild();
}
bool SocketProcessChild::DeallocPParentToChildStreamChild(
PParentToChildStreamChild* aActor) {
delete aActor;
return true;
}
PChildToParentStreamChild*
SocketProcessChild::SendPChildToParentStreamConstructor(
PChildToParentStreamChild* aActor) {
MOZ_ASSERT(NS_IsMainThread());
return PSocketProcessChild::SendPChildToParentStreamConstructor(aActor);
}
PFileDescriptorSetChild* SocketProcessChild::SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) {
MOZ_ASSERT(NS_IsMainThread());

View File

@ -72,16 +72,9 @@ class SocketProcessChild final
const FileDescriptor& fd);
bool DeallocPFileDescriptorSetChild(PFileDescriptorSetChild* aActor);
PChildToParentStreamChild* AllocPChildToParentStreamChild();
bool DeallocPChildToParentStreamChild(PChildToParentStreamChild* aActor);
PParentToChildStreamChild* AllocPParentToChildStreamChild();
bool DeallocPParentToChildStreamChild(PParentToChildStreamChild* aActor);
void CleanUp();
void DestroySocketProcessBridgeParent(ProcessId aId);
PChildToParentStreamChild* SendPChildToParentStreamConstructor(
PChildToParentStreamChild* aActor) override;
PFileDescriptorSetChild* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) override;
already_AddRefed<PHttpConnectionMgrChild> AllocPHttpConnectionMgrChild(

View File

@ -14,9 +14,6 @@
#include "mozilla/dom/MemoryReportRequest.h"
#include "mozilla/FOGIPC.h"
#include "mozilla/ipc/FileDescriptorSetParent.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
#include "mozilla/ipc/PChildToParentStreamParent.h"
#include "mozilla/ipc/PParentToChildStreamParent.h"
#include "mozilla/net/DNSRequestParent.h"
#include "mozilla/net/ProxyConfigLookupParent.h"
#include "mozilla/RemoteLazyInputStreamParent.h"
@ -246,35 +243,6 @@ bool SocketProcessParent::DeallocPFileDescriptorSetParent(
return true;
}
mozilla::ipc::PChildToParentStreamParent*
SocketProcessParent::AllocPChildToParentStreamParent() {
return mozilla::ipc::AllocPChildToParentStreamParent();
}
bool SocketProcessParent::DeallocPChildToParentStreamParent(
PChildToParentStreamParent* aActor) {
delete aActor;
return true;
}
mozilla::ipc::PParentToChildStreamParent*
SocketProcessParent::AllocPParentToChildStreamParent() {
MOZ_CRASH("PParentToChildStreamChild actors should be manually constructed!");
}
bool SocketProcessParent::DeallocPParentToChildStreamParent(
PParentToChildStreamParent* aActor) {
delete aActor;
return true;
}
mozilla::ipc::PParentToChildStreamParent*
SocketProcessParent::SendPParentToChildStreamConstructor(
PParentToChildStreamParent* aActor) {
MOZ_ASSERT(NS_IsMainThread());
return PSocketProcessParent::SendPParentToChildStreamConstructor(aActor);
}
mozilla::ipc::PFileDescriptorSetParent*
SocketProcessParent::SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) {

View File

@ -74,13 +74,6 @@ class SocketProcessParent final
const FileDescriptor& fd);
bool DeallocPFileDescriptorSetParent(PFileDescriptorSetParent* aActor);
PChildToParentStreamParent* AllocPChildToParentStreamParent();
bool DeallocPChildToParentStreamParent(PChildToParentStreamParent* aActor);
PParentToChildStreamParent* AllocPParentToChildStreamParent();
bool DeallocPParentToChildStreamParent(PParentToChildStreamParent* aActor);
PParentToChildStreamParent* SendPParentToChildStreamConstructor(
PParentToChildStreamParent* aActor) override;
PFileDescriptorSetParent* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) override;

View File

@ -12,8 +12,6 @@ include IPCStream;
include NeckoChannelParams;
include protocol PFileDescriptorSet; //FIXME: bug #792908
include protocol PChildToParentStream; //FIXME: bug #792908
include protocol PParentToChildStream; //FIXME: bug #792908
include "mozilla/net/WebSocketChannelParent.h";
include "mozilla/net/WebSocketChannelChild.h";