Bug 1544799 - Make PSocketProcess manage PWebrtcProxyChannel r=dragana
authorKershaw Chang <kershaw@mozilla.com>
Tue, 23 Apr 2019 13:10:56 +0000
changeset 470482 56f46d0eafe230c410e139ad51b2c596e18d14d5
parent 470481 c126bc2983801e7e8b77e57e5c6c2d5998ce7d59
child 470483 1d1277b80e5c0a6accef9e80a111619036c13888
push id35906
push useraciure@mozilla.com
push dateTue, 23 Apr 2019 22:14:56 +0000
treeherdermozilla-central@0ce3633f8b80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1544799
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1544799 - Make PSocketProcess manage PWebrtcProxyChannel r=dragana Differential Revision: https://phabricator.services.mozilla.com/D28038
media/mtransport/ipc/PWebrtcProxyChannel.ipdl
netwerk/ipc/PSocketProcess.ipdl
netwerk/ipc/SocketProcessChild.cpp
netwerk/ipc/SocketProcessChild.h
netwerk/ipc/SocketProcessParent.cpp
netwerk/ipc/SocketProcessParent.h
--- a/media/mtransport/ipc/PWebrtcProxyChannel.ipdl
+++ b/media/mtransport/ipc/PWebrtcProxyChannel.ipdl
@@ -1,25 +1,26 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et tw=80 ft=cpp : */
 
 /* 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 PNecko;
+include protocol PSocketProcess;
 
 include NeckoChannelParams;
 
 namespace mozilla {
 namespace net {
 
 async protocol PWebrtcProxyChannel
 {
-  manager PNecko;
+  manager PNecko or PSocketProcess;
 
 parent:
   async AsyncOpen(nsCString aHost,
                   int32_t aPort,
                   LoadInfoArgs? aLoadInfoArgs,
                   nsCString aAlpn);
   async Write(uint8_t[] aWriteData);
   async Close();
--- a/netwerk/ipc/PSocketProcess.ipdl
+++ b/netwerk/ipc/PSocketProcess.ipdl
@@ -1,44 +1,51 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 MemoryReportTypes;
 include protocol PSocketProcessBridge;
 include protocol PProfiler;
+include protocol PWebrtcProxyChannel;
+
+include MemoryReportTypes;
+include PBrowserOrId;
 include PrefsTypes;
 
 using mozilla::dom::NativeThreadId from "mozilla/dom/TabMessageUtils.h";
 using mozilla::Telemetry::HistogramAccumulation from "mozilla/TelemetryComms.h";
 using mozilla::Telemetry::KeyedHistogramAccumulation from "mozilla/TelemetryComms.h";
 using mozilla::Telemetry::ScalarAction from "mozilla/TelemetryComms.h";
 using mozilla::Telemetry::KeyedScalarAction from "mozilla/TelemetryComms.h";
 using mozilla::Telemetry::ChildEventData from "mozilla/TelemetryComms.h";
 using mozilla::Telemetry::DiscardedData from "mozilla/TelemetryComms.h";
 using base::ProcessId from "base/process.h";
 
 namespace mozilla {
 namespace net {
 
 protocol PSocketProcess
 {
+  manages PWebrtcProxyChannel;
+
 parent:
   async InitCrashReporter(Shmem shmem, NativeThreadId threadId);
   async AddMemoryReport(MemoryReport aReport);
   async FinishMemoryReport(uint32_t aGeneration);
   // Messages for sending telemetry to parent process.
   async AccumulateChildHistograms(HistogramAccumulation[] accumulations);
   async AccumulateChildKeyedHistograms(KeyedHistogramAccumulation[] accumulations);
   async UpdateChildScalars(ScalarAction[] actions);
   async UpdateChildKeyedScalars(KeyedScalarAction[] actions);
   async RecordChildEvents(ChildEventData[] events);
   async RecordDiscardedData(DiscardedData data);
 
+  async PWebrtcProxyChannel(PBrowserOrId browser);
+
 child:
   async PreferenceUpdate(Pref pref);
   async RequestMemoryReport(uint32_t generation,
                             bool anonymize,
                             bool minimizeMemoryUsage,
                             FileDescriptor? DMDFile);
   async SetOffline(bool offline);
   async InitSocketProcessBridgeParent(ProcessId processId, Endpoint<PSocketProcessBridgeParent> endpoint);
--- a/netwerk/ipc/SocketProcessChild.cpp
+++ b/netwerk/ipc/SocketProcessChild.cpp
@@ -16,16 +16,20 @@
 #include "nsThreadManager.h"
 #include "ProcessUtils.h"
 #include "SocketProcessBridgeParent.h"
 
 #ifdef MOZ_GECKO_PROFILER
 #  include "ChildProfilerController.h"
 #endif
 
+#ifdef MOZ_WEBRTC
+#  include "mozilla/net/WebrtcProxyChannelChild.h"
+#endif
+
 namespace mozilla {
 namespace net {
 
 using namespace ipc;
 
 static SocketProcessChild* sSocketProcessChild;
 
 SocketProcessChild::SocketProcessChild() {
@@ -165,10 +169,30 @@ mozilla::ipc::IPCResult SocketProcessChi
 }
 
 void SocketProcessChild::DestroySocketProcessBridgeParent(ProcessId aId) {
   MOZ_ASSERT(NS_IsMainThread());
 
   mSocketProcessBridgeParentMap.Remove(aId);
 }
 
+PWebrtcProxyChannelChild* SocketProcessChild::AllocPWebrtcProxyChannelChild(
+    const PBrowserOrId& browser) {
+  // We don't allocate here: instead we always use IPDL constructor that takes
+  // an existing object
+  MOZ_ASSERT_UNREACHABLE(
+      "AllocPWebrtcProxyChannelChild should not be called on"
+      " socket child");
+  return nullptr;
+}
+
+bool SocketProcessChild::DeallocPWebrtcProxyChannelChild(
+    PWebrtcProxyChannelChild* aActor) {
+#ifdef MOZ_WEBRTC
+  WebrtcProxyChannelChild* child =
+      static_cast<WebrtcProxyChannelChild*>(aActor);
+  child->ReleaseIPDLReference();
+#endif
+  return true;
+}
+
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/ipc/SocketProcessChild.h
+++ b/netwerk/ipc/SocketProcessChild.h
@@ -40,16 +40,20 @@ class SocketProcessChild final : public 
   mozilla::ipc::IPCResult RecvSetOffline(const bool& aOffline);
   mozilla::ipc::IPCResult RecvInitSocketProcessBridgeParent(
       const ProcessId& aContentProcessId,
       Endpoint<mozilla::net::PSocketProcessBridgeParent>&& aEndpoint);
   mozilla::ipc::IPCResult RecvInitProfiler(
       Endpoint<mozilla::PProfilerChild>&& aEndpoint);
   mozilla::ipc::IPCResult RecvSocketProcessTelemetryPing();
 
+  PWebrtcProxyChannelChild* AllocPWebrtcProxyChannelChild(
+      const PBrowserOrId& browser);
+  bool DeallocPWebrtcProxyChannelChild(PWebrtcProxyChannelChild* aActor);
+
   void CleanUp();
   void DestroySocketProcessBridgeParent(ProcessId aId);
 
  private:
   // Mapping of content process id and the SocketProcessBridgeParent.
   // This table keeps SocketProcessBridgeParent alive in socket process.
   nsRefPtrHashtable<nsUint32HashKey, SocketProcessBridgeParent>
       mSocketProcessBridgeParentMap;
--- a/netwerk/ipc/SocketProcessParent.cpp
+++ b/netwerk/ipc/SocketProcessParent.cpp
@@ -4,16 +4,21 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SocketProcessParent.h"
 
 #include "SocketProcessHost.h"
 #include "mozilla/ipc/CrashReporterHost.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TelemetryIPC.h"
+#ifdef MOZ_WEBRTC
+#  include "mozilla/dom/ContentProcessManager.h"
+#  include "mozilla/dom/TabParent.h"
+#  include "mozilla/net/WebrtcProxyChannelParent.h"
+#endif
 
 namespace mozilla {
 namespace net {
 
 static SocketProcessParent* sSocketProcessParent;
 
 SocketProcessParent::SocketProcessParent(SocketProcessHost* aHost)
     : mHost(aHost) {
@@ -122,16 +127,51 @@ mozilla::ipc::IPCResult SocketProcessPar
 
 mozilla::ipc::IPCResult SocketProcessParent::RecvRecordDiscardedData(
     const mozilla::Telemetry::DiscardedData& aDiscardedData) {
   TelemetryIPC::RecordDiscardedData(Telemetry::ProcessID::Socket,
                                     aDiscardedData);
   return IPC_OK();
 }
 
+PWebrtcProxyChannelParent* SocketProcessParent::AllocPWebrtcProxyChannelParent(
+    const PBrowserOrId& aBrowser) {
+#ifdef MOZ_WEBRTC
+  if (aBrowser.type() != PBrowserOrId::TTabId) {
+    MOZ_ASSERT(false, "We only allow TabId here.");
+    return nullptr;
+  }
+
+  dom::ContentProcessManager* cpm = dom::ContentProcessManager::GetSingleton();
+  dom::TabId tabId = aBrowser.get_TabId();
+  dom::ContentParentId cpId = cpm->GetTabProcessId(tabId);
+  RefPtr<dom::TabParent> tab = cpm->GetTabParentByProcessAndTabId(cpId, tabId);
+  if (!tab) {
+    MOZ_ASSERT(false, "Cannot find the TabParent!");
+    return nullptr;
+  }
+
+  WebrtcProxyChannelParent* parent = new WebrtcProxyChannelParent(tab);
+  parent->AddRef();
+  return parent;
+#else
+  return nullptr;
+#endif
+}
+
+bool SocketProcessParent::DeallocPWebrtcProxyChannelParent(
+    PWebrtcProxyChannelParent* aActor) {
+#ifdef MOZ_WEBRTC
+  WebrtcProxyChannelParent* parent =
+      static_cast<WebrtcProxyChannelParent*>(aActor);
+  parent->Release();
+#endif
+  return true;
+}
+
 // To ensure that IPDL is finished before SocketParent gets deleted.
 class DeferredDeleteSocketProcessParent : public Runnable {
  public:
   explicit DeferredDeleteSocketProcessParent(
       UniquePtr<SocketProcessParent>&& aParent)
       : Runnable("net::DeferredDeleteSocketProcessParent"),
         mParent(std::move(aParent)) {}
 
--- a/netwerk/ipc/SocketProcessParent.h
+++ b/netwerk/ipc/SocketProcessParent.h
@@ -47,16 +47,20 @@ class SocketProcessParent final : public
       InfallibleTArray<ScalarAction>&& aScalarActions);
   mozilla::ipc::IPCResult RecvUpdateChildKeyedScalars(
       InfallibleTArray<KeyedScalarAction>&& aScalarActions);
   mozilla::ipc::IPCResult RecvRecordChildEvents(
       nsTArray<ChildEventData>&& events);
   mozilla::ipc::IPCResult RecvRecordDiscardedData(
       const DiscardedData& aDiscardedData);
 
+  PWebrtcProxyChannelParent* AllocPWebrtcProxyChannelParent(
+      const PBrowserOrId& aBrowser);
+  bool DeallocPWebrtcProxyChannelParent(PWebrtcProxyChannelParent* aActor);
+
   void ActorDestroy(ActorDestroyReason aWhy) override;
   bool SendRequestMemoryReport(const uint32_t& aGeneration,
                                const bool& aAnonymize,
                                const bool& aMinimizeMemoryUsage,
                                const Maybe<ipc::FileDescriptor>& aDMDFile);
 
  private:
   SocketProcessHost* mHost;