Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / ipc / SocketProcessBridgeParent.cpp
blobb16be05b4db8bc0962190449a0a49eb0b4996aa3
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "SocketProcessBridgeParent.h"
7 #include "SocketProcessLogging.h"
9 #ifdef MOZ_WEBRTC
10 # include "mozilla/dom/MediaTransportParent.h"
11 #endif
12 #include "mozilla/ipc/BackgroundParent.h"
13 #include "mozilla/ipc/Endpoint.h"
14 #include "SocketProcessChild.h"
15 #include "mozilla/net/BackgroundDataBridgeParent.h"
16 #include "nsThreadUtils.h"
18 namespace mozilla {
19 namespace net {
21 SocketProcessBridgeParent::SocketProcessBridgeParent(ProcessId aId) : mId(aId) {
22 LOG(
23 ("CONSTRUCT SocketProcessBridgeParent::SocketProcessBridgeParent "
24 "mId=%" PRIPID "\n",
25 mId));
28 SocketProcessBridgeParent::~SocketProcessBridgeParent() {
29 LOG(("DESTRUCT SocketProcessBridgeParent::SocketProcessBridgeParent\n"));
32 mozilla::ipc::IPCResult SocketProcessBridgeParent::RecvInitBackgroundDataBridge(
33 mozilla::ipc::Endpoint<PBackgroundDataBridgeParent>&& aEndpoint,
34 uint64_t aChannelID) {
35 LOG(("SocketProcessBridgeParent::RecvInitBackgroundDataBridge\n"));
37 nsCOMPtr<nsISerialEventTarget> transportQueue;
38 if (NS_FAILED(NS_CreateBackgroundTaskQueue("BackgroundDataBridge",
39 getter_AddRefs(transportQueue)))) {
40 return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
43 if (!aEndpoint.IsValid()) {
44 return IPC_FAIL(this, "Invalid endpoint");
47 transportQueue->Dispatch(NS_NewRunnableFunction(
48 "BackgroundDataBridgeParent::Bind",
49 [endpoint = std::move(aEndpoint), aChannelID]() mutable {
50 RefPtr<net::BackgroundDataBridgeParent> actor =
51 new net::BackgroundDataBridgeParent(aChannelID);
52 endpoint.Bind(actor);
53 }));
54 return IPC_OK();
57 #ifdef MOZ_WEBRTC
58 mozilla::ipc::IPCResult SocketProcessBridgeParent::RecvInitMediaTransport(
59 mozilla::ipc::Endpoint<mozilla::dom::PMediaTransportParent>&& aEndpoint) {
60 LOG(("SocketProcessBridgeParent::RecvInitMediaTransport\n"));
62 if (!aEndpoint.IsValid()) {
63 return IPC_FAIL(this, "Invalid endpoint");
66 if (!mMediaTransportTaskQueue) {
67 nsCOMPtr<nsISerialEventTarget> transportQueue;
68 if (NS_FAILED(NS_CreateBackgroundTaskQueue(
69 "MediaTransport", getter_AddRefs(transportQueue)))) {
70 return IPC_FAIL(this, "NS_CreateBackgroundTaskQueue failed");
73 mMediaTransportTaskQueue = std::move(transportQueue);
76 mMediaTransportTaskQueue->Dispatch(NS_NewRunnableFunction(
77 "BackgroundDataBridgeParent::Bind",
78 [endpoint = std::move(aEndpoint)]() mutable {
79 RefPtr<MediaTransportParent> actor = new MediaTransportParent();
80 endpoint.Bind(actor);
81 }));
82 return IPC_OK();
84 #endif
86 void SocketProcessBridgeParent::ActorDestroy(ActorDestroyReason aReason) {
87 // See bug 1846478. We might be able to remove this dispatch.
88 GetCurrentSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
89 "SocketProcessBridgeParent::ActorDestroy", [id = mId] {
90 if (SocketProcessChild* child = SocketProcessChild::GetSingleton()) {
91 child->DestroySocketProcessBridgeParent(id);
93 }));
96 } // namespace net
97 } // namespace mozilla