Bug 1550364 part 4. Move various methods from nsIUDPSocketChild to dom::UDPSocketChild, and simplify their signatures where possible. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 09 May 2019 06:55:06 +0000
changeset 535175 dfbb67a692f4c1a257edd0b441a84b8c01a8e9c7
parent 535174 2e9edc96c3d22f6aab3cc9bb69125b134a381b82
child 535176 1456c2b5efb899d210fb91f2ebedfcad7c094bea
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1550364
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 1550364 part 4. Move various methods from nsIUDPSocketChild to dom::UDPSocketChild, and simplify their signatures where possible. r=baku Differential Revision: https://phabricator.services.mozilla.com/D30447
dom/network/UDPSocket.cpp
dom/network/UDPSocketChild.cpp
dom/network/UDPSocketChild.h
dom/network/interfaces/nsIUDPSocketChild.idl
media/mtransport/nr_socket_prsock.cpp
--- a/dom/network/UDPSocket.cpp
+++ b/dom/network/UDPSocket.cpp
@@ -222,18 +222,17 @@ void UDPSocket::JoinMulticastGroup(const
     aRv = mSocket->JoinMulticast(address, EmptyCString());
     NS_WARNING_ASSERTION(!aRv.Failed(), "JoinMulticast failed");
 
     return;
   }
 
   MOZ_ASSERT(mSocketChild);
 
-  aRv = mSocketChild->JoinMulticast(address, EmptyCString());
-  NS_WARNING_ASSERTION(!aRv.Failed(), "JoinMulticast failed");
+  mSocketChild->JoinMulticast(address, EmptyCString());
 }
 
 void UDPSocket::LeaveMulticastGroup(const nsAString& aMulticastGroupAddress,
                                     ErrorResult& aRv) {
   if (mReadyState == SocketReadyState::Closed) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
@@ -253,18 +252,17 @@ void UDPSocket::LeaveMulticastGroup(cons
 
     aRv = mSocket->LeaveMulticast(address, EmptyCString());
     NS_WARNING_ASSERTION(!aRv.Failed(), "mSocket->LeaveMulticast failed");
     return;
   }
 
   MOZ_ASSERT(mSocketChild);
 
-  aRv = mSocketChild->LeaveMulticast(address, EmptyCString());
-  NS_WARNING_ASSERTION(!aRv.Failed(), "mSocketChild->LeaveMulticast failed");
+  mSocketChild->LeaveMulticast(address, EmptyCString());
 }
 
 nsresult UDPSocket::DoPendingMcastCommand() {
   MOZ_ASSERT(mReadyState == SocketReadyState::Open,
              "Multicast command can only be executed after socket opened");
 
   for (uint32_t i = 0; i < mPendingMcastCommands.Length(); ++i) {
     MulticastCommand& command = mPendingMcastCommands[i];
@@ -687,23 +685,19 @@ NS_IMETHODIMP
 UDPSocket::CallListenerOpened() {
   if (mReadyState != SocketReadyState::Opening) {
     return NS_OK;
   }
 
   MOZ_ASSERT(mSocketChild);
 
   // Get real local address and local port
-  nsCString localAddress;
-  mSocketChild->GetLocalAddress(localAddress);
-  mLocalAddress = NS_ConvertUTF8toUTF16(localAddress);
+  mLocalAddress = NS_ConvertUTF8toUTF16(mSocketChild->LocalAddress());
 
-  uint16_t localPort;
-  mSocketChild->GetLocalPort(&localPort);
-  mLocalPort.SetValue(localPort);
+  mLocalPort.SetValue(mSocketChild->LocalPort());
 
   mReadyState = SocketReadyState::Open;
   nsresult rv = DoPendingMcastCommand();
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
     CloseWithReason(rv);
     return NS_OK;
   }
--- a/dom/network/UDPSocketChild.cpp
+++ b/dom/network/UDPSocketChild.cpp
@@ -47,36 +47,33 @@ NS_IMETHODIMP_(MozExternalRefCountType) 
   }
   return refcnt;
 }
 
 UDPSocketChild::UDPSocketChild() : mBackgroundManager(nullptr), mLocalPort(0) {}
 
 UDPSocketChild::~UDPSocketChild() {}
 
-// nsIUDPSocketChild Methods
-
-NS_IMETHODIMP
-UDPSocketChild::SetBackgroundSpinsEvents() {
+nsresult UDPSocketChild::SetBackgroundSpinsEvents() {
   using mozilla::ipc::BackgroundChild;
 
   mBackgroundManager = BackgroundChild::GetOrCreateForCurrentThread();
   if (NS_WARN_IF(!mBackgroundManager)) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-UDPSocketChild::Bind(nsIUDPSocketInternal* aSocket, nsIPrincipal* aPrincipal,
-                     const nsACString& aHost, uint16_t aPort,
-                     bool aAddressReuse, bool aLoopback,
-                     uint32_t recvBufferSize, uint32_t sendBufferSize,
-                     nsIEventTarget* aMainThreadEventTarget) {
+nsresult UDPSocketChild::Bind(nsIUDPSocketInternal* aSocket,
+                              nsIPrincipal* aPrincipal, const nsACString& aHost,
+                              uint16_t aPort, bool aAddressReuse,
+                              bool aLoopback, uint32_t recvBufferSize,
+                              uint32_t sendBufferSize,
+                              nsIEventTarget* aMainThreadEventTarget) {
   UDPSOCKET_LOG(
       ("%s: %s:%u", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort));
 
   NS_ENSURE_ARG(aSocket);
 
   if (NS_IsMainThread()) {
     if (aMainThreadEventTarget) {
       gNeckoChild->SetEventTargetForActor(this, aMainThreadEventTarget);
@@ -102,38 +99,31 @@ UDPSocketChild::Bind(nsIUDPSocketInterna
   mSocket = aSocket;
   AddIPDLReference();
 
   SendBind(UDPAddressInfo(nsCString(aHost), aPort), aAddressReuse, aLoopback,
            recvBufferSize, sendBufferSize);
   return NS_OK;
 }
 
-NS_IMETHODIMP
-UDPSocketChild::Connect(nsIUDPSocketInternal* aSocket, const nsACString& aHost,
-                        uint16_t aPort) {
+void UDPSocketChild::Connect(nsIUDPSocketInternal* aSocket,
+                             const nsACString& aHost, uint16_t aPort) {
   UDPSOCKET_LOG(
       ("%s: %s:%u", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort));
 
   mSocket = aSocket;
 
   SendConnect(UDPAddressInfo(nsCString(aHost), aPort));
-
-  return NS_OK;
 }
 
-NS_IMETHODIMP
-UDPSocketChild::Close() {
-  SendClose();
-  return NS_OK;
-}
+void UDPSocketChild::Close() { SendClose(); }
 
-NS_IMETHODIMP
-UDPSocketChild::SendWithAddress(const NetAddr* aAddr, const uint8_t* aData,
-                                uint32_t aByteLength) {
+nsresult UDPSocketChild::SendWithAddress(const NetAddr* aAddr,
+                                         const uint8_t* aData,
+                                         uint32_t aByteLength) {
   NS_ENSURE_ARG(aAddr);
   NS_ENSURE_ARG(aData);
 
   UDPSOCKET_LOG(("%s: %u bytes", __FUNCTION__, aByteLength));
   return SendDataInternal(UDPSocketAddr(*aAddr), aData, aByteLength);
 }
 
 nsresult UDPSocketChild::SendDataInternal(const UDPSocketAddr& aAddr,
@@ -149,77 +139,52 @@ nsresult UDPSocketChild::SendDataInterna
   InfallibleTArray<uint8_t> array;
   array.SwapElements(fallibleArray);
 
   SendOutgoingData(array, aAddr);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-UDPSocketChild::SendBinaryStream(const nsACString& aHost, uint16_t aPort,
-                                 nsIInputStream* aStream) {
+nsresult UDPSocketChild::SendBinaryStream(const nsACString& aHost,
+                                          uint16_t aPort,
+                                          nsIInputStream* aStream) {
   NS_ENSURE_ARG(aStream);
 
   mozilla::ipc::AutoIPCStream autoStream;
   autoStream.Serialize(aStream, static_cast<mozilla::dom::ContentChild*>(
                                     gNeckoChild->Manager()));
 
   UDPSOCKET_LOG(
       ("%s: %s:%u", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort));
   SendOutgoingData(UDPData(autoStream.TakeValue()),
                    UDPSocketAddr(UDPAddressInfo(nsCString(aHost), aPort)));
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-UDPSocketChild::JoinMulticast(const nsACString& aMulticastAddress,
-                              const nsACString& aInterface) {
+void UDPSocketChild::JoinMulticast(const nsACString& aMulticastAddress,
+                                   const nsACString& aInterface) {
   SendJoinMulticast(nsCString(aMulticastAddress), nsCString(aInterface));
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-UDPSocketChild::LeaveMulticast(const nsACString& aMulticastAddress,
-                               const nsACString& aInterface) {
-  SendLeaveMulticast(nsCString(aMulticastAddress), nsCString(aInterface));
-  return NS_OK;
 }
 
-NS_IMETHODIMP
-UDPSocketChild::GetLocalPort(uint16_t* aLocalPort) {
-  NS_ENSURE_ARG_POINTER(aLocalPort);
-
-  *aLocalPort = mLocalPort;
-  return NS_OK;
+void UDPSocketChild::LeaveMulticast(const nsACString& aMulticastAddress,
+                                    const nsACString& aInterface) {
+  SendLeaveMulticast(nsCString(aMulticastAddress), nsCString(aInterface));
 }
 
-NS_IMETHODIMP
-UDPSocketChild::GetLocalAddress(nsACString& aLocalAddress) {
-  aLocalAddress = mLocalAddress;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-UDPSocketChild::SetFilterName(const nsACString& aFilterName) {
+nsresult UDPSocketChild::SetFilterName(const nsACString& aFilterName) {
   if (!mFilterName.IsEmpty()) {
     // filter name can only be set once.
     return NS_ERROR_FAILURE;
   }
   mFilterName = aFilterName;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-UDPSocketChild::GetFilterName(nsACString& aFilterName) {
-  aFilterName = mFilterName;
-  return NS_OK;
-}
-
 // PUDPSocketChild Methods
 mozilla::ipc::IPCResult UDPSocketChild::RecvCallbackOpened(
     const UDPAddressInfo& aAddressInfo) {
   mLocalAddress = aAddressInfo.addr();
   mLocalPort = aAddressInfo.port();
 
   UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, mLocalAddress.get(), mLocalPort));
   nsresult rv = mSocket->CallListenerOpened();
--- a/dom/network/UDPSocketChild.h
+++ b/dom/network/UDPSocketChild.h
@@ -40,16 +40,54 @@ class UDPSocketChild : public mozilla::n
                        public UDPSocketChildBase {
  public:
   NS_DECL_NSIUDPSOCKETCHILD
   NS_IMETHOD_(MozExternalRefCountType) Release() override;
 
   UDPSocketChild();
   virtual ~UDPSocketChild();
 
+  uint16_t LocalPort() const { return mLocalPort; }
+  // Local address as UTF-8.
+  const nsACString& LocalAddress() const { return mLocalAddress; }
+
+  nsresult SetFilterName(const nsACString& aFilterName);
+
+  // Allow hosting this over PBackground instead of PNecko
+  nsresult SetBackgroundSpinsEvents();
+
+  // Tell the chrome process to bind the UDP socket to a given local host and
+  // port
+  nsresult Bind(nsIUDPSocketInternal* aSocket, nsIPrincipal* aPrincipal,
+                const nsACString& aHost, uint16_t aPort, bool aAddressReuse,
+                bool aLoopback, uint32_t recvBufferSize,
+                uint32_t sendBufferSize,
+                nsIEventTarget* aMainThreadEventTarget);
+
+  // Tell the chrome process to connect the UDP socket to a given remote host
+  // and port
+  void Connect(nsIUDPSocketInternal* aSocket, const nsACString& aHost,
+               uint16_t aPort);
+
+  // Send the given data to the given address.
+  nsresult SendWithAddress(const NetAddr* aAddr, const uint8_t* aData,
+                           uint32_t aByteLength);
+
+  // Send input stream. This must be a buffered stream implementation.
+  nsresult SendBinaryStream(const nsACString& aHost, uint16_t aPort,
+                            nsIInputStream* aStream);
+
+  void Close();
+
+  // Address and interface are both UTF-8.
+  void JoinMulticast(const nsACString& aMulticastAddress,
+                     const nsACString& aInterface);
+  void LeaveMulticast(const nsACString& aMulticastAddress,
+                      const nsACString& aInterface);
+
   mozilla::ipc::IPCResult RecvCallbackOpened(
       const UDPAddressInfo& aAddressInfo);
   mozilla::ipc::IPCResult RecvCallbackConnected(
       const UDPAddressInfo& aAddressInfo);
   mozilla::ipc::IPCResult RecvCallbackClosed();
   mozilla::ipc::IPCResult RecvCallbackReceivedData(
       const UDPAddressInfo& aAddressInfo, InfallibleTArray<uint8_t>&& aData);
   mozilla::ipc::IPCResult RecvCallbackError(const nsCString& aMessage,
--- a/dom/network/interfaces/nsIUDPSocketChild.idl
+++ b/dom/network/interfaces/nsIUDPSocketChild.idl
@@ -5,56 +5,19 @@
 #include "nsISupports.idl"
 #include "nsINetAddr.idl"
 
 interface nsIUDPSocketInternal;
 interface nsIInputStream;
 interface nsIPrincipal;
 interface nsIEventTarget;
 
-%{ C++
-namespace mozilla {
-namespace net {
-union NetAddr;
-}
-}
-%}
-native NetAddr(mozilla::net::NetAddr);
-[ptr] native NetAddrPtr(mozilla::net::NetAddr);
-
 [uuid(1e6ad73b-6c05-4d78-9a88-2d357b88f58b)]
 interface nsIUDPSocketChild : nsISupports
 {
-  readonly attribute unsigned short localPort;
-  readonly attribute AUTF8String localAddress;
-  attribute AUTF8String filterName;
-
-  // Allow hosting this over PBackground instead of PNecko
-  [noscript] void setBackgroundSpinsEvents();
-
-  // Tell the chrome process to bind the UDP socket to a given local host and port
-  void bind(in nsIUDPSocketInternal socket, in nsIPrincipal principal,
-            in AUTF8String host, in unsigned short port,
-            in bool addressReuse, in bool loopback, in uint32_t recvBufferSize,
-            in uint32_t sendBufferSize,
-            [optional] in nsIEventTarget mainThreadTarget);
-
-  // Tell the chrome process to connect the UDP socket to a given remote host and port
-  void connect(in nsIUDPSocketInternal socket, in AUTF8String host, in unsigned short port);
-
-  // Send the given data to the given address.
-  [noscript] void sendWithAddress([const] in NetAddrPtr addr,
-                                  [const, array, size_is(byteLength)] in uint8_t bytes,
-                                  in unsigned long byteLength);
-  // Send input stream. This must be a buffered stream implementation.
-  void sendBinaryStream(in AUTF8String host, in unsigned short port, in nsIInputStream stream);
-
-  void close();
-  void joinMulticast(in AUTF8String multicastAddress, in AUTF8String iface);
-  void leaveMulticast(in AUTF8String multicastAddress, in AUTF8String iface);
 };
 
 /*
  * Internal interface for callback from chrome process
  */
 [scriptable, uuid(613dd3ad-598b-4da9-ad63-bbda50c20098)]
 interface nsIUDPSocketInternal : nsISupports
 {
--- a/media/mtransport/nr_socket_prsock.cpp
+++ b/media/mtransport/nr_socket_prsock.cpp
@@ -1153,29 +1153,19 @@ NS_IMETHODIMP NrUdpSocketIpc::CallListen
   RUN_ON_THREAD(sts_thread_,
                 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
                                       &NrUdpSocketIpc::recv_callback_s, msg),
                 NS_DISPATCH_NORMAL);
   return NS_OK;
 }
 
 nsresult NrUdpSocketIpc::SetAddress() {
-  uint16_t port;
-  if (NS_FAILED(socket_child_->GetLocalPort(&port))) {
-    err_ = true;
-    MOZ_ASSERT(false, "Failed to get local port");
-    return NS_OK;
-  }
+  uint16_t port = socket_child_->LocalPort();
 
-  nsAutoCString address;
-  if (NS_FAILED(socket_child_->GetLocalAddress(address))) {
-    err_ = true;
-    MOZ_ASSERT(false, "Failed to get local address");
-    return NS_OK;
-  }
+  nsAutoCString address(socket_child_->LocalAddress());
 
   PRNetAddr praddr;
   if (PR_SUCCESS != PR_InitializeNetAddr(PR_IpAddrAny, port, &praddr)) {
     err_ = true;
     MOZ_ASSERT(false, "Failed to set port in PRNetAddr");
     return NS_OK;
   }
 
@@ -1537,22 +1527,17 @@ void NrUdpSocketIpc::connect_i(const nsA
   RefPtr<NrUdpSocketIpcProxy> proxy(new NrUdpSocketIpcProxy);
   rv = proxy->Init(this);
   if (NS_FAILED(rv)) {
     err_ = true;
     mon.NotifyAll();
     return;
   }
 
-  if (NS_FAILED(socket_child_->Connect(proxy, host, port))) {
-    err_ = true;
-    MOZ_ASSERT(false, "Failed to connect UDP socket");
-    mon.NotifyAll();
-    return;
-  }
+  socket_child_->Connect(proxy, host, port);
 }
 
 void NrUdpSocketIpc::sendto_i(const net::NetAddr& addr,
                               nsAutoPtr<MediaPacket> buf) {
   ASSERT_ON_THREAD(io_thread_);
 
   ReentrantMonitorAutoEnter mon(monitor_);