diff --git a/media/mtransport/nr_socket_prsock.cpp b/media/mtransport/nr_socket_prsock.cpp index 966108f1b947..116614aecef0 100644 --- a/media/mtransport/nr_socket_prsock.cpp +++ b/media/mtransport/nr_socket_prsock.cpp @@ -693,57 +693,9 @@ abort: return(_status); } -NS_IMPL_ISUPPORTS(NrSocketIpcProxy, nsIUDPSocketInternal) - -nsresult -NrSocketIpcProxy::Init(const nsRefPtr& socket) -{ - nsresult rv; - sts_thread_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) { - MOZ_ASSERT(false, "Failed to get STS thread"); - return rv; - } - - socket_ = socket; - return NS_OK; -} - -NrSocketIpcProxy::~NrSocketIpcProxy() -{ - // Send our ref to STS to be released - RUN_ON_THREAD(sts_thread_, - mozilla::WrapRelease(socket_.forget()), - NS_DISPATCH_NORMAL); -} - -// IUDPSocketInternal interfaces -// callback while error happened in UDP socket operation -NS_IMETHODIMP NrSocketIpcProxy::CallListenerError(const nsACString &message, - const nsACString &filename, - uint32_t line_number) { - return socket_->CallListenerError(message, filename, line_number); -} - -// callback while receiving UDP packet -NS_IMETHODIMP NrSocketIpcProxy::CallListenerReceivedData(const nsACString &host, - uint16_t port, - const uint8_t *data, - uint32_t data_length) { - return socket_->CallListenerReceivedData(host, port, data, data_length); -} - -// callback while UDP socket is opened -NS_IMETHODIMP NrSocketIpcProxy::CallListenerOpened() { - return socket_->CallListenerOpened(); -} - -// callback while UDP socket is closed -NS_IMETHODIMP NrSocketIpcProxy::CallListenerClosed() { - return socket_->CallListenerClosed(); -} - // NrSocketIpc Implementation +NS_IMPL_ISUPPORTS(NrSocketIpc, nsIUDPSocketInternal) + NrSocketIpc::NrSocketIpc(const nsCOMPtr &main_thread) : err_(false), state_(NR_INIT), @@ -1070,15 +1022,7 @@ void NrSocketIpc::create_m(const nsACString &host, const uint16_t port) { socket_child_ = new nsMainThreadPtrHolder(socketChild); socket_child_->SetFilterName(nsCString("stun")); - nsRefPtr proxy(new NrSocketIpcProxy); - rv = proxy->Init(this); - if (NS_FAILED(rv)) { - err_ = true; - mon.NotifyAll(); - return; - } - - if (NS_FAILED(socket_child_->Bind(proxy, host, port, + if (NS_FAILED(socket_child_->Bind(this, host, port, /* reuse = */ false, /* loopback = */ false))) { err_ = true; @@ -1163,7 +1107,7 @@ static nr_socket_vtbl nr_socket_local_vtbl={ }; int nr_socket_local_create(nr_transport_addr *addr, nr_socket **sockp) { - RefPtr sock; + NrSocketBase *sock = nullptr; // create IPC bridge for content process if (XRE_GetProcessType() == GeckoProcessType_Default) { @@ -1185,12 +1129,15 @@ int nr_socket_local_create(nr_transport_addr *addr, nr_socket **sockp) { if (r) ABORT(r); + // Add a reference so that we can delete it in destroy() + sock->AddRef(); + _status = 0; - // We will release this reference in destroy(), not exactly the normal - // ownership model, but it is what it is. - sock.forget().drop(); abort: + if (_status) { + delete sock; + } return _status; } diff --git a/media/mtransport/nr_socket_prsock.h b/media/mtransport/nr_socket_prsock.h index 476a36587ada..0da801435980 100644 --- a/media/mtransport/nr_socket_prsock.h +++ b/media/mtransport/nr_socket_prsock.h @@ -188,7 +188,8 @@ private: DISALLOW_COPY_ASSIGN(nr_udp_message); }; -class NrSocketIpc : public NrSocketBase { +class NrSocketIpc : public NrSocketBase, + public nsIUDPSocketInternal { public: enum NrSocketIpcState { @@ -199,17 +200,8 @@ public: NR_CLOSED, }; - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrSocketIpc) - - NS_IMETHODIMP CallListenerError(const nsACString &message, - const nsACString &filename, - uint32_t line_number); - NS_IMETHODIMP CallListenerReceivedData(const nsACString &host, - uint16_t port, - const uint8_t *data, - uint32_t data_length); - NS_IMETHODIMP CallListenerOpened(); - NS_IMETHODIMP CallListenerClosed(); + NS_DECL_THREADSAFE_ISUPPORTS + NS_DECL_NSIUDPSOCKETINTERNAL explicit NrSocketIpc(const nsCOMPtr &main_thread); @@ -248,22 +240,6 @@ private: ReentrantMonitor monitor_; }; -// The socket child holds onto one of these, which just passes callbacks -// through and makes sure the ref to the NrSocketIpc is released on STS. -class NrSocketIpcProxy : public nsIUDPSocketInternal { -public: - NS_DECL_THREADSAFE_ISUPPORTS - NS_DECL_NSIUDPSOCKETINTERNAL - - nsresult Init(const nsRefPtr& socket); - -private: - virtual ~NrSocketIpcProxy(); - - nsRefPtr socket_; - nsCOMPtr sts_thread_; -}; - int nr_netaddr_to_transport_addr(const net::NetAddr *netaddr, nr_transport_addr *addr, int protocol); diff --git a/media/mtransport/runnable_utils.h b/media/mtransport/runnable_utils.h index ed9d3513a625..52fefdab0598 100644 --- a/media/mtransport/runnable_utils.h +++ b/media/mtransport/runnable_utils.h @@ -96,25 +96,6 @@ RUN_ON_THREAD(nsIEventTarget *thread, detail::runnable_args_base -class DispatchedRelease : public detail::runnable_args_base { -public: - explicit DispatchedRelease(already_AddRefed& ref) : ref_(ref) {} - - NS_IMETHOD Run() { - ref_ = nullptr; - return NS_OK; - } -private: - nsRefPtr ref_; -}; - -template -DispatchedRelease* WrapRelease(already_AddRefed&& ref) -{ - return new DispatchedRelease(ref); -} - } /* namespace mozilla */ #endif