diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index fdcb37acc73e..690cb2bf51d4 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2681,9 +2681,7 @@ bool ContentParent::LaunchSubprocessResolve(bool aIsSync, sCreatedFirstContentProcess = true; } - base::ProcessId procId = - base::GetProcId(mSubprocess->GetChildProcessHandle()); - Open(mSubprocess->TakeInitialPort(), procId); + mSubprocess->TakeInitialEndpoint().Bind(this); ContentProcessManager* cpm = ContentProcessManager::GetSingleton(); if (!cpm) { diff --git a/dom/media/gmp/GMPParent.cpp b/dom/media/gmp/GMPParent.cpp index 41c077bc0a24..ad005d1fa606 100644 --- a/dom/media/gmp/GMPParent.cpp +++ b/dom/media/gmp/GMPParent.cpp @@ -326,8 +326,7 @@ nsresult GMPParent::LoadProcess() { mChildPid = base::GetProcId(mProcess->GetChildProcessHandle()); GMP_PARENT_LOG_DEBUG("%s: Launched new child process", __FUNCTION__); - bool opened = Open(mProcess->TakeInitialPort(), - base::GetProcId(mProcess->GetChildProcessHandle())); + bool opened = mProcess->TakeInitialEndpoint().Bind(this); if (!opened) { GMP_PARENT_LOG_DEBUG("%s: Failed to open channel to new child process", __FUNCTION__); diff --git a/dom/media/ipc/RDDProcessHost.cpp b/dom/media/ipc/RDDProcessHost.cpp index 8d8b8b99c268..d4620c3e3ac9 100644 --- a/dom/media/ipc/RDDProcessHost.cpp +++ b/dom/media/ipc/RDDProcessHost.cpp @@ -169,8 +169,7 @@ void RDDProcessHost::InitAfterConnect(bool aSucceeded) { } mProcessToken = ++sRDDProcessTokenCounter; mRDDChild = MakeUnique(this); - DebugOnly rv = mRDDChild->Open( - TakeInitialPort(), base::GetProcId(GetChildProcessHandle())); + DebugOnly rv = TakeInitialEndpoint().Bind(mRDDChild.get()); MOZ_ASSERT(rv); // Only clear mPrefSerializer in the success case to avoid a diff --git a/gfx/ipc/GPUProcessHost.cpp b/gfx/ipc/GPUProcessHost.cpp index d5141dad90b7..f40b1660398b 100644 --- a/gfx/ipc/GPUProcessHost.cpp +++ b/gfx/ipc/GPUProcessHost.cpp @@ -144,8 +144,7 @@ void GPUProcessHost::InitAfterConnect(bool aSucceeded) { if (aSucceeded) { mProcessToken = ++sProcessTokenCounter; mGPUChild = MakeUnique(this); - DebugOnly rv = mGPUChild->Open( - TakeInitialPort(), base::GetProcId(GetChildProcessHandle())); + DebugOnly rv = TakeInitialEndpoint().Bind(mGPUChild.get()); MOZ_ASSERT(rv); mGPUChild->Init(); diff --git a/gfx/vr/ipc/VRProcessParent.cpp b/gfx/vr/ipc/VRProcessParent.cpp index 8de06f7a3447..cdc50c7dd0fd 100644 --- a/gfx/vr/ipc/VRProcessParent.cpp +++ b/gfx/vr/ipc/VRProcessParent.cpp @@ -163,8 +163,7 @@ bool VRProcessParent::InitAfterConnect(bool aSucceeded) { mVRChild = MakeUnique(this); - DebugOnly rv = mVRChild->Open( - TakeInitialPort(), base::GetProcId(GetChildProcessHandle())); + DebugOnly rv = TakeInitialEndpoint().Bind(mVRChild.get()); MOZ_ASSERT(rv); mVRChild->Init(); diff --git a/ipc/docs/processes.rst b/ipc/docs/processes.rst index 29978eeea420..afa332dfd02f 100644 --- a/ipc/docs/processes.rst +++ b/ipc/docs/processes.rst @@ -560,7 +560,8 @@ behavior is fairly clear: return; } - new DemoParent(std::move(host)); + auto actor = MakeRefPtr(std::move(host)); + actor->Init(); }); } @@ -579,20 +580,21 @@ the new host, if successful. In this sample, the ``DemoParent`` is owned (in the reference-counting sense) by IPDL, which is why it doesn't get assigned to anything. This simplifies the -design dramatically. IPDL takes ownership when the actor calls ``Open`` in its -constructor: +design dramatically. IPDL takes ownership when the actor calls ``Bind`` from +the ``Init`` method: .. code-block:: c++ DemoParent::DemoParent(UniqueHost&& aHost) - : mHost(std::move(aHost)) { - Open(mHost->TakeInitialPort(), - base::GetProcId(mHost->GetChildProcessHandle())); + : mHost(std::move(aHost)) {} + + DemoParent::Init() { + mHost->TakeInitialEndpoint().Bind(this); // ... mHost->MakeBridgeAndResolve(); } -After the ``Open`` call, the actor is live and communication with the new +After the ``Bind`` call, the actor is live and communication with the new process can begin. The constructor concludes by initiating the process of connecting the ``PDemoHelpline`` actors; ``Host::MakeBridgeAndResolve`` will be covered in `Creating a New Top Level Actor`_. However, before we get into diff --git a/ipc/glue/GeckoChildProcessHost.h b/ipc/glue/GeckoChildProcessHost.h index a41dfa2871d6..5d19b480c795 100644 --- a/ipc/glue/GeckoChildProcessHost.h +++ b/ipc/glue/GeckoChildProcessHost.h @@ -14,6 +14,7 @@ #include "chrome/common/ipc_message.h" #include "mojo/core/ports/port_ref.h" +#include "mozilla/ipc/Endpoint.h" #include "mozilla/ipc/FileDescriptor.h" #include "mozilla/ipc/NodeChannel.h" #include "mozilla/ipc/ScopedPort.h" @@ -127,7 +128,11 @@ class GeckoChildProcessHost : public ChildProcessHost, IPC::Channel* GetChannel() { return channelp(); } ChannelId GetChannelId() { return channel_id(); } - ScopedPort TakeInitialPort() { return std::move(mInitialPort); } + UntypedEndpoint TakeInitialEndpoint() { + return UntypedEndpoint{PrivateIPDLInterface{}, std::move(mInitialPort), + base::GetCurrentProcId(), + base::GetProcId(mChildProcessHandle)}; + } // Returns a "borrowed" handle to the child process - the handle returned // by this function must not be closed by the caller. diff --git a/ipc/glue/UtilityProcessHost.cpp b/ipc/glue/UtilityProcessHost.cpp index 6b05008e92f7..82938583be27 100644 --- a/ipc/glue/UtilityProcessHost.cpp +++ b/ipc/glue/UtilityProcessHost.cpp @@ -182,8 +182,7 @@ void UtilityProcessHost::InitAfterConnect(bool aSucceeded) { } mUtilityProcessParent = MakeRefPtr(this); - DebugOnly rv = mUtilityProcessParent->Open( - TakeInitialPort(), base::GetProcId(GetChildProcessHandle())); + DebugOnly rv = TakeInitialEndpoint().Bind(mUtilityProcessParent.get()); MOZ_ASSERT(rv); // Only clear mPrefSerializer in the success case to avoid a diff --git a/ipc/ipdl/test/gtest/IPDLUnitTest.cpp b/ipc/ipdl/test/gtest/IPDLUnitTest.cpp index 9cb5f834ad15..6181919328fa 100644 --- a/ipc/ipdl/test/gtest/IPDLUnitTest.cpp +++ b/ipc/ipdl/test/gtest/IPDLUnitTest.cpp @@ -61,9 +61,7 @@ already_AddRefed IPDLUnitTestParent::CreateCrossProcess() { return nullptr; } - if (!parent->Open( - parent->mSubprocess->TakeInitialPort(), - base::GetProcId(parent->mSubprocess->GetChildProcessHandle()))) { + if (!parent->mSubprocess->TakeInitialEndpoint().Bind(parent.get())) { ADD_FAILURE() << "Opening the parent actor failed"; return nullptr; } diff --git a/netwerk/ipc/SocketProcessHost.cpp b/netwerk/ipc/SocketProcessHost.cpp index 2c42d8e38709..e4ff9231cd9e 100644 --- a/netwerk/ipc/SocketProcessHost.cpp +++ b/netwerk/ipc/SocketProcessHost.cpp @@ -166,8 +166,7 @@ void SocketProcessHost::InitAfterConnect(bool aSucceeded) { } mSocketProcessParent = MakeUnique(this); - DebugOnly rv = mSocketProcessParent->Open( - TakeInitialPort(), base::GetProcId(GetChildProcessHandle())); + DebugOnly rv = TakeInitialEndpoint().Bind(mSocketProcessParent.get()); MOZ_ASSERT(rv); SocketPorcessInitAttributes attributes; diff --git a/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerParent.cpp b/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerParent.cpp index faafc21a2ce7..f8f3c60918b9 100644 --- a/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerParent.cpp +++ b/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerParent.cpp @@ -27,7 +27,7 @@ RefPtr RemoteSandboxBrokerParent::Launch( // Note: we rely on the caller to keep this instance alive while we launch // the process, so that these closures point to valid memory. auto resolve = [this](base::ProcessHandle handle) { - mOpened = Open(mProcess->TakeInitialPort(), base::GetProcId(handle)); + mOpened = mProcess->TakeInitialEndpoint().Bind(this); if (!mOpened) { mProcess->Destroy(); mProcess = nullptr;