From 3b7fbc734f14c3d9daf32b48f74231c4c6898340 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 10 Jul 2019 22:37:35 +0000 Subject: [PATCH] Bug 1562763 - Move some types around. r=jld Having to namespace these into GeckoChildProcessHost is annoying. The |using| declarations help to some extent, but it's easier to just put them in mozilla::ipc. Differential Revision: https://phabricator.services.mozilla.com/D36538 --HG-- extra : moz-landing-system : lando --- dom/ipc/ContentParent.cpp | 12 ++++++------ dom/ipc/ContentParent.h | 5 +++-- ipc/glue/GeckoChildProcessHost.cpp | 12 +++++++----- ipc/glue/GeckoChildProcessHost.h | 13 ++++++------- .../RemoteSandboxBrokerProcessParent.cpp | 7 ++++--- .../RemoteSandboxBrokerProcessParent.h | 7 +------ 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index bea199236c56..68dca720b8d3 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2052,8 +2052,8 @@ void ContentParent::LaunchSubprocessInternal( if (isSync) { *aRetval.as() = false; } else { - *aRetval.as*>() = LaunchPromise::CreateAndReject( - GeckoChildProcessHost::LaunchError(), __func__); + *aRetval.as*>() = + LaunchPromise::CreateAndReject(LaunchError(), __func__); } }; @@ -2119,7 +2119,7 @@ void ContentParent::LaunchSubprocessInternal( RefPtr self(this); - auto reject = [self, this](GeckoChildProcessHost::LaunchError err) { + auto reject = [self, this](LaunchError err) { NS_ERROR("failed to launch child in the parent"); MarkAsDead(); return LaunchPromise::CreateAndReject(err, __func__); @@ -2207,19 +2207,19 @@ void ContentParent::LaunchSubprocessInternal( if (ok) { Unused << resolve(mSubprocess->GetChildProcessHandle()); } else { - Unused << reject(GeckoChildProcessHost::LaunchError{}); + Unused << reject(LaunchError{}); } *aRetval.as() = ok; } else { auto* retptr = aRetval.as*>(); if (mSubprocess->AsyncLaunch(std::move(extraArgs))) { - RefPtr ready = + RefPtr ready = mSubprocess->WhenProcessHandleReady(); mLaunchYieldTS = TimeStamp::Now(); *retptr = ready->Then(GetCurrentThreadSerialEventTarget(), __func__, std::move(resolve), std::move(reject)); } else { - *retptr = reject(GeckoChildProcessHost::LaunchError{}); + *retptr = reject(LaunchError{}); } } } diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 64ec270f5da6..fc8a37fd60e1 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -22,6 +22,7 @@ #include "mozilla/HalTypes.h" #include "mozilla/LinkedList.h" #include "mozilla/MemoryReportingProcess.h" +#include "mozilla/MozPromise.h" #include "mozilla/StaticPtr.h" #include "mozilla/TimeStamp.h" #include "mozilla/Variant.h" @@ -148,9 +149,9 @@ class ContentParent final : public PContentParent, #endif public: - using LaunchError = GeckoChildProcessHost::LaunchError; + using LaunchError = mozilla::ipc::LaunchError; using LaunchPromise = - GeckoChildProcessHost::LaunchPromise>; + mozilla::MozPromise, LaunchError, false>; NS_DECLARE_STATIC_IID_ACCESSOR(NS_CONTENTPARENT_IID) diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp index 5aba0679d474..3640600cb6fd 100644 --- a/ipc/glue/GeckoChildProcessHost.cpp +++ b/ipc/glue/GeckoChildProcessHost.cpp @@ -84,6 +84,8 @@ using mozilla::MonitorAutoLock; using mozilla::Preferences; using mozilla::StaticMutexAutoLock; using mozilla::ipc::GeckoChildProcessHost; +using mozilla::ipc::LaunchError; +using mozilla::ipc::ProcessHandlePromise; namespace mozilla { MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedPRFileDesc, PRFileDesc, @@ -192,14 +194,14 @@ void GeckoChildProcessHost::Destroy() { MOZ_RELEASE_ASSERT(!mDestroying); // We can remove from the list before it's really destroyed RemoveFromProcessList(); - RefPtr whenReady = mHandlePromise; + RefPtr whenReady = mHandlePromise; if (!whenReady) { // AsyncLaunch not called yet, so dispatch immediately. - whenReady = HandlePromise::CreateAndReject(LaunchError{}, __func__); + whenReady = ProcessHandlePromise::CreateAndReject(LaunchError{}, __func__); } - using Value = HandlePromise::ResolveOrRejectValue; + using Value = ProcessHandlePromise::ResolveOrRejectValue; mDestroying = true; whenReady->Then(XRE_GetIOMessageLoop()->SerialEventTarget(), __func__, [this](const Value&) { delete this; }); @@ -401,7 +403,7 @@ bool GeckoChildProcessHost::AsyncLaunch(std::vector aExtraOpts) { MessageLoop* ioLoop = XRE_GetIOMessageLoop(); MOZ_ASSERT(mHandlePromise == nullptr); - mHandlePromise = new HandlePromise::Private(__func__); + mHandlePromise = new ProcessHandlePromise::Private(__func__); // Currently this can't fail (see the MOZ_ALWAYS_SUCCEEDS in // MessageLoop::PostTask_Helper), but in the future it possibly @@ -1363,7 +1365,7 @@ void GeckoChildProcessHost::OnChannelError() { // FIXME/bug 773925: save up this error for the next listener. } -RefPtr +RefPtr GeckoChildProcessHost::WhenProcessHandleReady() { MOZ_ASSERT(mHandlePromise != nullptr); return mHandlePromise; diff --git a/ipc/glue/GeckoChildProcessHost.h b/ipc/glue/GeckoChildProcessHost.h index b918657f8286..82ef90b73699 100644 --- a/ipc/glue/GeckoChildProcessHost.h +++ b/ipc/glue/GeckoChildProcessHost.h @@ -38,6 +38,10 @@ typedef _MacSandboxInfo MacSandboxInfo; namespace mozilla { namespace ipc { +struct LaunchError {}; +typedef mozilla::MozPromise + ProcessHandlePromise; + class GeckoChildProcessHost : public ChildProcessHost, public LinkedListElement { protected: @@ -94,14 +98,9 @@ class GeckoChildProcessHost : public ChildProcessHost, virtual void OnChannelError() override; virtual void GetQueuedMessages(std::queue& queue) override; - struct LaunchError {}; - template - using LaunchPromise = mozilla::MozPromise; - using HandlePromise = LaunchPromise; - // Resolves to the process handle when it's available (see // LaunchAndWaitForProcessHandle); use with AsyncLaunch. - RefPtr WhenProcessHandleReady(); + RefPtr WhenProcessHandleReady(); virtual void InitializeChannel(); @@ -211,7 +210,7 @@ class GeckoChildProcessHost : public ChildProcessHost, #if defined(OS_MACOSX) task_t mChildTask; #endif - RefPtr mHandlePromise; + RefPtr mHandlePromise; bool OpenPrivilegedHandle(base::ProcessId aPid); diff --git a/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerProcessParent.cpp b/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerProcessParent.cpp index 9442e9301e23..d58f561a161b 100644 --- a/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerProcessParent.cpp +++ b/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerProcessParent.cpp @@ -9,6 +9,8 @@ #include using mozilla::ipc::GeckoChildProcessHost; +using mozilla::ipc::LaunchError; +using mozilla::ipc::ProcessHandlePromise; namespace mozilla { @@ -21,11 +23,10 @@ RemoteSandboxBrokerProcessParent::~RemoteSandboxBrokerProcessParent() { MOZ_COUNT_DTOR(RemoteSandboxBrokerProcessParent); } -RefPtr +RefPtr RemoteSandboxBrokerProcessParent::AsyncLaunch() { if (!GeckoChildProcessHost::AsyncLaunch()) { - return HandlePromise::CreateAndReject(GeckoChildProcessHost::LaunchError{}, - __func__); + return ProcessHandlePromise::CreateAndReject(LaunchError{}, __func__); } return WhenProcessHandleReady(); } diff --git a/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerProcessParent.h b/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerProcessParent.h index cdba9ec2ed9a..6b298ee9c641 100644 --- a/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerProcessParent.h +++ b/security/sandbox/win/src/remotesandboxbroker/RemoteSandboxBrokerProcessParent.h @@ -21,14 +21,9 @@ namespace mozilla { class RemoteSandboxBrokerProcessParent final : public mozilla::ipc::GeckoChildProcessHost { public: - using LaunchError = GeckoChildProcessHost::LaunchError; - using LaunchPromise = GeckoChildProcessHost::LaunchPromise; - RemoteSandboxBrokerProcessParent(); - using GeckoChildProcessHost::HandlePromise; - - RefPtr AsyncLaunch(); + RefPtr AsyncLaunch(); bool CanShutdown() override { return true; }