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"
10 # include "mozilla/dom/MediaTransportParent.h"
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"
21 SocketProcessBridgeParent::SocketProcessBridgeParent(ProcessId aId
) : mId(aId
) {
23 ("CONSTRUCT SocketProcessBridgeParent::SocketProcessBridgeParent "
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
);
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();
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
);
97 } // namespace mozilla