Bug 1806847: Move WebTransport parent-side binding to SocketThread r=nika

Differential Revision: https://phabricator.services.mozilla.com/D165295
This commit is contained in:
Randell Jesup 2022-12-23 02:40:22 +00:00
Родитель 2f3624de57
Коммит 4fc2895ad1
3 изменённых файлов: 42 добавлений и 24 удалений

Просмотреть файл

@ -19,13 +19,14 @@ WebTransportParent::~WebTransportParent() {
LOG(("Destroying WebTransportParent %p", this));
}
bool WebTransportParent::Init(
// static
void WebTransportParent::Create(
const nsAString& aURL, const bool& aDedicated,
const bool& aRequireUnreliable, const uint32_t& aCongestionControl,
// Sequence<WebTransportHash>* aServerCertHashes,
Endpoint<PWebTransportParent>&& aParentEndpoint,
std::function<void(const nsresult&)>&& aResolver) {
LOG(("Created WebTransportParent %p %s %s %s congestion=%s", this,
LOG(("Created WebTransportParent %s %s %s congestion=%s",
NS_ConvertUTF16toUTF8(aURL).get(),
aDedicated ? "Dedicated" : "AllowPooling",
aRequireUnreliable ? "RequireUnreliable" : "",
@ -39,21 +40,42 @@ bool WebTransportParent::Init(
if (!StaticPrefs::network_webtransport_enabled()) {
aResolver(NS_ERROR_DOM_NOT_ALLOWED_ERR);
return false;
return;
}
if (!aParentEndpoint.IsValid()) {
aResolver(NS_ERROR_INVALID_ARG);
return false;
return;
}
if (!aParentEndpoint.Bind(this)) {
aResolver(NS_ERROR_FAILURE);
return false;
}
// XXX Send connection to the server
aResolver(NS_OK);
return true;
// Bind to SocketThread for IPC - connection creation/destruction must
// hit MainThread, but keep all other traffic on SocketThread. Note that
// we must call aResolver() on this (PBackground) thread.
nsresult rv;
nsCOMPtr<nsISerialEventTarget> sts =
do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
MOZ_ASSERT(NS_SUCCEEDED(rv));
InvokeAsync(sts, __func__,
[parentEndpoint = std::move(aParentEndpoint)]() mutable {
RefPtr<WebTransportParent> parent = new WebTransportParent();
LOG(("Binding parent endpoint"));
if (!parentEndpoint.Bind(parent)) {
return GenericNonExclusivePromise::CreateAndReject(
NS_ERROR_FAILURE, __func__);
}
// IPC now holds a ref to parent
// XXX Send connection to the server via MainThread
return GenericNonExclusivePromise::CreateAndResolve(true,
__func__);
})
->Then(
GetCurrentSerialEventTarget(), __func__,
[aResolver](
const GenericNonExclusivePromise::ResolveOrRejectValue& aValue) {
aResolver(aValue.IsResolve() ? NS_OK : aValue.RejectValue());
});
}
void WebTransportParent::ActorDestroy(ActorDestroyReason aWhy) {

Просмотреть файл

@ -19,14 +19,14 @@ class WebTransportParent : public PWebTransportParent {
public:
WebTransportParent() = default;
// XXX Threadsafe??
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebTransportParent, override)
bool Init(const nsAString& aURL, const bool& aDedicated,
const bool& aRequireUnreliable, const uint32_t& aCongestionControl,
// Sequence<WebTransportHash>* aServerCertHashes,
Endpoint<PWebTransportParent>&& aParentEndpoint,
std::function<void(const nsresult&)>&& aResolver);
static void Create(const nsAString& aURL, const bool& aDedicated,
const bool& aRequireUnreliable,
const uint32_t& aCongestionControl,
// Sequence<WebTransportHash>* aServerCertHashes,
Endpoint<PWebTransportParent>&& aParentEndpoint,
std::function<void(const nsresult&)>&& aResolver);
mozilla::ipc::IPCResult RecvClose(const uint32_t& aCode,
const nsACString& aReason);

Просмотреть файл

@ -512,13 +512,9 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateWebTransportParent(
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
RefPtr<mozilla::dom::WebTransportParent> webt =
new mozilla::dom::WebTransportParent();
if (!webt->Init(aURL, aDedicated, aRequireUnreliable, aCongestionControl,
/*aServerCertHashes, */ std::move(aParentEndpoint),
std::move(aResolver))) {
webt->Close();
}
mozilla::dom::WebTransportParent::Create(
aURL, aDedicated, aRequireUnreliable, aCongestionControl,
/*aServerCertHashes, */ std::move(aParentEndpoint), std::move(aResolver));
return IPC_OK();
}