Changeset 261277 in webkit


Ignore:
Timestamp:
May 7, 2020 2:23:43 AM (4 years ago)
Author:
youenn@apple.com
Message:

Sending WebRTC network packets should not go through the main thread
https://bugs.webkit.org/show_bug.cgi?id=211291

Reviewed by Eric Carlson.

Source/WebCore:

Covered by existing tests.

  • Modules/mediastream/PeerConnectionBackend.cpp:

(WebCore::PeerConnectionBackend::filterSDP const):
Fix a case where the SDP would be badly formatted if we do not have yet a MDNS name for the corresponding IP address.
Small refactoring to use early returns.

  • platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:

(WebCore::LibWebRTCProvider::getStaticFactoryAndThreads):

  • platform/mediastream/libwebrtc/LibWebRTCProvider.h:

Add the ability for WebKit LibWebRTCProvider to do some processing on creation of the RTC threads.

Source/WebKit:

Following on receiving RTC packets from a background thread, we also send RTC packets from a background thread.
Creation of the sockets also happens in a background thread.
LibWebRTCNetwork is getting the connection whenever a new connection to network process is created.
It will then hop to the RTC network thread to set the IPC connection to the libwebrtc socket factory.

At creation of the socket, we get the IPC connection to the network process and keep a ref in the RTC socket.
In case network process crashed and the IPC connection of the RTC network is null, we hop to the main thread to create a new IPC connection.
This will fail the creation of the socket (as well as new ones as well) as long as the IPC connection to network process is not valid again.

Covered by existing tests.

  • WebProcess/Network/webrtc/LibWebRTCNetwork.cpp:

(WebKit::LibWebRTCNetwork::setAsActive):
(WebKit::LibWebRTCNetwork::setConnection):
(WebKit::LibWebRTCNetwork::dispatchToThread):

  • WebProcess/Network/webrtc/LibWebRTCNetwork.h:

(WebKit::LibWebRTCNetwork::connection):
(WebKit::LibWebRTCNetwork::isActive const):

  • WebProcess/Network/webrtc/LibWebRTCProvider.cpp:

(WebKit::LibWebRTCProvider::startedNetworkThread):

  • WebProcess/Network/webrtc/LibWebRTCProvider.h:
  • WebProcess/Network/webrtc/LibWebRTCSocket.cpp:

(WebKit::LibWebRTCSocket::SendTo):
(WebKit::LibWebRTCSocket::Close):
(WebKit::LibWebRTCSocket::SetOption):
(WebKit::LibWebRTCSocket::suspend):

  • WebProcess/Network/webrtc/LibWebRTCSocket.h:
  • WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp:

(WebKit::LibWebRTCSocketFactory::setConnection):
(WebKit::LibWebRTCSocketFactory::connection):
(WebKit::LibWebRTCSocketFactory::createServerTcpSocket):
(WebKit::LibWebRTCSocketFactory::createUdpSocket):
(WebKit::LibWebRTCSocketFactory::createClientTcpSocket):
(WebKit::LibWebRTCSocketFactory::createNewConnectionSocket):
(WebKit::LibWebRTCSocketFactory::addSocket):
(WebKit::LibWebRTCSocketFactory::removeSocket):
(WebKit::LibWebRTCSocketFactory::forSocketInGroup):

  • WebProcess/Network/webrtc/LibWebRTCSocketFactory.h:
Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r261273 r261277  
     12020-05-07  Youenn Fablet  <youenn@apple.com>
     2
     3        Sending WebRTC network packets should not go through the main thread
     4        https://bugs.webkit.org/show_bug.cgi?id=211291
     5
     6        Reviewed by Eric Carlson.
     7
     8        Covered by existing tests.
     9
     10        * Modules/mediastream/PeerConnectionBackend.cpp:
     11        (WebCore::PeerConnectionBackend::filterSDP const):
     12        Fix a case where the SDP would be badly formatted if we do not have yet a MDNS name for the corresponding IP address.
     13        Small refactoring to use early returns.
     14        * platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
     15        (WebCore::LibWebRTCProvider::getStaticFactoryAndThreads):
     16        * platform/mediastream/libwebrtc/LibWebRTCProvider.h:
     17        Add the ability for WebKit LibWebRTCProvider to do some processing on creation of the RTC threads.
     18
    1192020-05-06  Sergio Villar Senin  <svillar@igalia.com>
    220
  • trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp

    r259290 r261277  
    440440    StringBuilder filteredSDP;
    441441    sdp.split('\n', [this, &filteredSDP](StringView line) {
    442         if (line.startsWith("c=IN IP4"))
    443             filteredSDP.append("c=IN IP4 0.0.0.0\r");
    444         else if (line.startsWith("c=IN IP6"))
    445             filteredSDP.append("c=IN IP6 ::\r");
    446         else if (!line.startsWith("a=candidate"))
     442        if (line.startsWith("c=IN IP4")) {
     443            filteredSDP.append("c=IN IP4 0.0.0.0\r\n");
     444            return;
     445        }
     446        if (line.startsWith("c=IN IP6")) {
     447            filteredSDP.append("c=IN IP6 ::\r\n");
     448            return;
     449        }
     450        if (!line.startsWith("a=candidate")) {
    447451            filteredSDP.append(line);
    448         else if (line.find(" host ", 11) == notFound)
     452            filteredSDP.append('\n');
     453            return;
     454        }
     455        if (line.find(" host ", 11) == notFound) {
    449456            filteredSDP.append(filterICECandidate(line.toString()));
    450         else {
    451             auto ipAddress = extractIPAddress(line);
    452             auto mdnsName = m_ipAddressToMDNSNameMap.get(ipAddress);
    453             if (!mdnsName.isEmpty()) {
    454                 auto sdp = line.toString();
    455                 sdp.replace(ipAddress, mdnsName);
    456                 filteredSDP.append(sdp);
    457             }
    458         }
     457            filteredSDP.append('\n');
     458            return;
     459        }
     460
     461        auto ipAddress = extractIPAddress(line);
     462        auto mdnsName = m_ipAddressToMDNSNameMap.get(ipAddress);
     463        if (mdnsName.isEmpty())
     464            return;
     465        auto sdp = line.toString();
     466        sdp.replace(ipAddress, mdnsName);
     467        filteredSDP.append(sdp);
    459468        filteredSDP.append('\n');
    460469    });
  • trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp

    r258547 r261277  
    192192}
    193193
    194 static inline PeerConnectionFactoryAndThreads& getStaticFactoryAndThreads(bool useNetworkThreadWithSocketServer)
     194PeerConnectionFactoryAndThreads& LibWebRTCProvider::getStaticFactoryAndThreads(bool useNetworkThreadWithSocketServer)
    195195{
    196196    auto& factoryAndThreads = staticFactoryAndThreads();
     
    201201        factoryAndThreads.networkThreadWithSocketServer = useNetworkThreadWithSocketServer;
    202202        initializePeerConnectionFactoryAndThreads(factoryAndThreads);
     203        startedNetworkThread();
    203204    }
    204205    return factoryAndThreads;
  • trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h

    r259452 r261277  
    6060
    6161class LibWebRTCAudioModule;
     62struct PeerConnectionFactoryAndThreads;
    6263struct RTCRtpCapabilities;
    6364
     
    135136    virtual std::unique_ptr<webrtc::VideoEncoderFactory> createEncoderFactory();
    136137
     138    virtual void startedNetworkThread() { };
     139
     140    PeerConnectionFactoryAndThreads& getStaticFactoryAndThreads(bool useNetworkThreadWithSocketServer);
     141
    137142    bool m_enableEnumeratingAllNetworkInterfaces { false };
    138143    // FIXME: Remove m_useNetworkThreadWithSocketServer member variable and make it a global.
  • trunk/Source/WebKit/ChangeLog

    r261276 r261277  
     12020-05-07  Youenn Fablet  <youenn@apple.com>
     2
     3        Sending WebRTC network packets should not go through the main thread
     4        https://bugs.webkit.org/show_bug.cgi?id=211291
     5
     6        Reviewed by Eric Carlson.
     7
     8        Following on receiving RTC packets from a background thread, we also send RTC packets from a background thread.
     9        Creation of the sockets also happens in a background thread.
     10        LibWebRTCNetwork is getting the connection whenever a new connection to network process is created.
     11        It will then hop to the RTC network thread to set the IPC connection to the libwebrtc socket factory.
     12
     13        At creation of the socket, we get the IPC connection to the network process and keep a ref in the RTC socket.
     14        In case network process crashed and the IPC connection of the RTC network is null, we hop to the main thread to create a new IPC connection.
     15        This will fail the creation of the socket (as well as new ones as well) as long as the IPC connection to network process is not valid again.
     16
     17        Covered by existing tests.
     18
     19        * WebProcess/Network/webrtc/LibWebRTCNetwork.cpp:
     20        (WebKit::LibWebRTCNetwork::setAsActive):
     21        (WebKit::LibWebRTCNetwork::setConnection):
     22        (WebKit::LibWebRTCNetwork::dispatchToThread):
     23        * WebProcess/Network/webrtc/LibWebRTCNetwork.h:
     24        (WebKit::LibWebRTCNetwork::connection):
     25        (WebKit::LibWebRTCNetwork::isActive const):
     26        * WebProcess/Network/webrtc/LibWebRTCProvider.cpp:
     27        (WebKit::LibWebRTCProvider::startedNetworkThread):
     28        * WebProcess/Network/webrtc/LibWebRTCProvider.h:
     29        * WebProcess/Network/webrtc/LibWebRTCSocket.cpp:
     30        (WebKit::LibWebRTCSocket::SendTo):
     31        (WebKit::LibWebRTCSocket::Close):
     32        (WebKit::LibWebRTCSocket::SetOption):
     33        (WebKit::LibWebRTCSocket::suspend):
     34        * WebProcess/Network/webrtc/LibWebRTCSocket.h:
     35        * WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp:
     36        (WebKit::LibWebRTCSocketFactory::setConnection):
     37        (WebKit::LibWebRTCSocketFactory::connection):
     38        (WebKit::LibWebRTCSocketFactory::createServerTcpSocket):
     39        (WebKit::LibWebRTCSocketFactory::createUdpSocket):
     40        (WebKit::LibWebRTCSocketFactory::createClientTcpSocket):
     41        (WebKit::LibWebRTCSocketFactory::createNewConnectionSocket):
     42        (WebKit::LibWebRTCSocketFactory::addSocket):
     43        (WebKit::LibWebRTCSocketFactory::removeSocket):
     44        (WebKit::LibWebRTCSocketFactory::forSocketInGroup):
     45        * WebProcess/Network/webrtc/LibWebRTCSocketFactory.h:
     46
    1472020-05-07  Adrian Perez de Castro  <aperez@igalia.com>
    248
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCNetwork.cpp

    r261163 r261277  
    4040}
    4141
     42void LibWebRTCNetwork::setAsActive()
     43{
     44    ASSERT(!m_isActive);
     45    m_isActive = true;
     46#if USE(LIBWEBRTC)
     47    if (m_connection) {
     48        WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([this, connection = m_connection]() mutable {
     49            m_socketFactory.setConnection(WTFMove(connection));
     50        });
     51    }
     52#endif
     53}
     54
    4255void LibWebRTCNetwork::networkProcessCrashed()
    4356{
     
    5467    if (m_connection)
    5568        m_connection->removeThreadMessageReceiver(Messages::LibWebRTCNetwork::messageReceiverName());
     69    if (m_isActive) {
     70        WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([this, connection]() mutable {
     71            m_socketFactory.setConnection(WTFMove(connection));
     72        });
     73    }
    5674#endif
    5775    m_connection = WTFMove(connection);
     
    6280}
    6381
    64 bool LibWebRTCNetwork::isActive() const
    65 {
    66 #if USE(LIBWEBRTC)
    67     return WebCore::LibWebRTCProvider::hasWebRTCThreads();
    68 #else
    69     return false;
    70 #endif
    71 }
    72 
    7382void LibWebRTCNetwork::dispatchToThread(Function<void()>&& callback)
    7483{
    75     if (!isActive()) {
     84    if (!m_isActive) {
    7685        RELEASE_LOG_ERROR(WebRTC, "Received WebRTCSocket message while libWebRTCNetwork is not active");
    7786        return;
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCNetwork.h

    r261163 r261277  
    4242    ~LibWebRTCNetwork();
    4343
     44    IPC::Connection* connection() { return m_connection.get(); }
    4445    void setConnection(RefPtr<IPC::Connection>&&);
     46
    4547    void networkProcessCrashed();
    4648
    47     bool isActive() const;
     49    bool isActive() const { return m_isActive; }
    4850
    4951#if USE(LIBWEBRTC)
     
    6163    WebMDNSRegister& mdnsRegister() { return m_mdnsRegister; }
    6264#endif
     65
     66    void setAsActive();
    6367
    6468private:
     
    8286    WebMDNSRegister m_mdnsRegister;
    8387#endif
     88    bool m_isActive { false };
    8489    RefPtr<IPC::Connection> m_connection;
    8590};
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp

    r261133 r261277  
    132132}
    133133
     134void LibWebRTCProvider::startedNetworkThread()
     135{
     136    WebProcess::singleton().libWebRTCNetwork().setAsActive();
     137}
     138
    134139std::unique_ptr<LibWebRTCProvider::SuspendableSocketFactory> LibWebRTCProvider::createSocketFactory(String&& userAgent)
    135140{
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.h

    r256838 r261277  
    5858    void registerMDNSName(WebCore::DocumentIdentifier, const String& ipAddress, CompletionHandler<void(MDNSNameOrError&&)>&&) final;
    5959    void disableNonLocalhostConnections() final;
     60    void startedNetworkThread() final;
    6061
    6162#if PLATFORM(COCOA)
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocket.cpp

    r261163 r261277  
    5858}
    5959
    60 void LibWebRTCSocket::sendOnMainThread(Function<void(IPC::Connection&)>&& callback)
    61 {
    62     callOnMainThread([callback = WTFMove(callback)]() {
    63         callback(WebProcess::singleton().ensureNetworkProcessConnection().connection());
    64     });
    65 }
    66 
    6760rtc::SocketAddress LibWebRTCSocket::GetLocalAddress() const
    6861{
     
    136129int LibWebRTCSocket::SendTo(const void *value, size_t size, const rtc::SocketAddress& address, const rtc::PacketOptions& options)
    137130{
    138     if (!willSend(size))
     131    auto* connection = m_factory.connection();
     132    if (!connection || !willSend(size))
    139133        return -1;
    140134
     
    142136        return size;
    143137
    144     auto buffer = WebCore::SharedBuffer::create(static_cast<const uint8_t*>(value), size);
    145     auto identifier = this->identifier();
    146 
    147     sendOnMainThread([identifier, buffer = WTFMove(buffer), address, options](auto& connection) {
    148         IPC::DataReference data(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
    149         connection.send(Messages::NetworkRTCSocket::SendTo { data, RTCNetwork::SocketAddress { address }, RTCPacketOptions { options } }, identifier);
    150     });
     138    IPC::DataReference data(static_cast<const uint8_t*>(value), size);
     139    connection->send(Messages::NetworkRTCSocket::SendTo { data, RTCNetwork::SocketAddress { address }, RTCPacketOptions { options } }, m_identifier);
     140
    151141    return size;
    152142}
     
    154144int LibWebRTCSocket::Close()
    155145{
    156     if (m_state == STATE_CLOSED)
     146    auto* connection = m_factory.connection();
     147    if (!connection || m_state == STATE_CLOSED)
    157148        return 0;
    158149
    159150    m_state = STATE_CLOSED;
    160151
    161     sendOnMainThread([identifier = identifier()](auto& connection) {
    162         connection.send(Messages::NetworkRTCSocket::Close(), identifier);
    163     });
     152    connection->send(Messages::NetworkRTCSocket::Close(), m_identifier);
     153
    164154    return 0;
    165155}
     
    181171    m_options[option] = value;
    182172
    183     sendOnMainThread([identifier = identifier(), option, value](auto& connection) {
    184         connection.send(Messages::NetworkRTCSocket::SetOption(option, value), identifier);
    185     });
     173    if (auto* connection = m_factory.connection())
     174        connection->send(Messages::NetworkRTCSocket::SetOption(option, value), m_identifier);
     175
    186176    return 0;
    187177}
     
    208198
    209199    // On suspend, we close TCP sockets as we cannot make sure packets are delivered reliably.
    210     if (m_type != Type::UDP) {
    211         sendOnMainThread([identifier = identifier()](auto& connection) {
    212             connection.send(Messages::NetworkRTCSocket::Close { }, identifier);
    213         });
    214     }
     200    if (m_type == Type::UDP)
     201        return;
     202
     203    if (auto* connection = m_factory.connection())
     204        connection->send(Messages::NetworkRTCSocket::Close { }, m_identifier);
    215205}
    216206
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocket.h

    r261163 r261277  
    8686    int SetOption(rtc::Socket::Option, int) final;
    8787
    88     static void sendOnMainThread(Function<void(IPC::Connection&)>&&);
    89 
    9088    LibWebRTCSocketFactory& m_factory;
    9189    WebCore::LibWebRTCSocketIdentifier m_identifier;
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp

    r261163 r261277  
    2929#if USE(LIBWEBRTC)
    3030
     31#include "LibWebRTCNetwork.h"
     32#include "Logging.h"
    3133#include "NetworkProcessConnection.h"
    3234#include "NetworkRTCMonitorMessages.h"
     
    4648}
    4749
     50void LibWebRTCSocketFactory::setConnection(RefPtr<IPC::Connection>&& connection)
     51{
     52    ASSERT(!WTF::isMainRunLoop());
     53    m_connection = WTFMove(connection);
     54}
     55
     56IPC::Connection* LibWebRTCSocketFactory::connection()
     57{
     58    ASSERT(!WTF::isMainRunLoop());
     59    return m_connection.get();
     60}
     61
    4862rtc::AsyncPacketSocket* LibWebRTCSocketFactory::createServerTcpSocket(const void* socketGroup, const rtc::SocketAddress& address, uint16_t minPort, uint16_t maxPort, int options)
    4963{
     64    ASSERT(!WTF::isMainRunLoop());
     65    if (!m_connection) {
     66        RELEASE_LOG(WebRTC, "No connection to create server TCP socket");
     67        callOnMainThread([] {
     68            WebProcess::singleton().ensureNetworkProcessConnection();
     69        });
     70        return nullptr;
     71    }
     72
    5073    auto socket = makeUnique<LibWebRTCSocket>(*this, socketGroup, LibWebRTCSocket::Type::ServerTCP, address, rtc::SocketAddress());
    5174
    52     callOnMainThread([identifier = socket->identifier(), address = prepareSocketAddress(address, m_disableNonLocalhostConnections), minPort, maxPort, options]() {
    53         if (!WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkRTCProvider::CreateServerTCPSocket(identifier, RTCNetwork::SocketAddress(address), minPort, maxPort, options), 0)) {
    54             // FIXME: Set error back to socket
    55             return;
    56         }
     75    m_connection->send(Messages::NetworkRTCProvider::CreateServerTCPSocket(socket->identifier(), RTCNetwork::SocketAddress(address), minPort, maxPort, options), 0);
    5776
    58     });
    5977    return socket.release();
    6078}
     
    6280rtc::AsyncPacketSocket* LibWebRTCSocketFactory::createUdpSocket(const void* socketGroup, const rtc::SocketAddress& address, uint16_t minPort, uint16_t maxPort)
    6381{
     82    ASSERT(!WTF::isMainRunLoop());
     83    if (!m_connection) {
     84        RELEASE_LOG(WebRTC, "No connection to create UDP socket");
     85        callOnMainThread([] {
     86            WebProcess::singleton().ensureNetworkProcessConnection();
     87        });
     88        return nullptr;
     89    }
     90
    6491    auto socket = makeUnique<LibWebRTCSocket>(*this, socketGroup, LibWebRTCSocket::Type::UDP, address, rtc::SocketAddress());
    6592
    66     callOnMainThread([identifier = socket->identifier(), address = prepareSocketAddress(address, m_disableNonLocalhostConnections), minPort, maxPort]() {
    67         if (!WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkRTCProvider::CreateUDPSocket(identifier, RTCNetwork::SocketAddress(address), minPort, maxPort), 0)) {
    68             // FIXME: Set error back to socket
    69             return;
    70         }
    71     });
     93    m_connection->send(Messages::NetworkRTCProvider::CreateUDPSocket(socket->identifier(), RTCNetwork::SocketAddress(address), minPort, maxPort), 0);
     94
    7295    return socket.release();
    7396}
     
    7598rtc::AsyncPacketSocket* LibWebRTCSocketFactory::createClientTcpSocket(const void* socketGroup, const rtc::SocketAddress& localAddress, const rtc::SocketAddress& remoteAddress, String&& userAgent, const rtc::PacketSocketTcpOptions& options)
    7699{
     100    ASSERT(!WTF::isMainRunLoop());
     101    if (!m_connection) {
     102        RELEASE_LOG(WebRTC, "No connection to create client TCP socket");
     103        callOnMainThread([] {
     104            WebProcess::singleton().ensureNetworkProcessConnection();
     105        });
     106        return nullptr;
     107    }
     108
    77109    auto socket = makeUnique<LibWebRTCSocket>(*this, socketGroup, LibWebRTCSocket::Type::ClientTCP, localAddress, remoteAddress);
    78110    socket->setState(LibWebRTCSocket::STATE_CONNECTING);
    79111
    80112    // FIXME: We only transfer options.opts but should also handle other members.
    81     callOnMainThread([identifier = socket->identifier(), localAddress = prepareSocketAddress(localAddress, m_disableNonLocalhostConnections), remoteAddress = prepareSocketAddress(remoteAddress, m_disableNonLocalhostConnections), userAgent = WTFMove(userAgent).isolatedCopy(), options = options.opts]() {
    82         if (!WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkRTCProvider::CreateClientTCPSocket(identifier, RTCNetwork::SocketAddress(localAddress), RTCNetwork::SocketAddress(remoteAddress), userAgent, options), 0)) {
    83             // FIXME: Set error back to socket
    84             return;
    85         }
    86     });
     113    m_connection->send(Messages::NetworkRTCProvider::CreateClientTCPSocket(socket->identifier(), RTCNetwork::SocketAddress(prepareSocketAddress(localAddress, m_disableNonLocalhostConnections)), RTCNetwork::SocketAddress(prepareSocketAddress(remoteAddress, m_disableNonLocalhostConnections)), userAgent, options.opts), 0);
     114
    87115    return socket.release();
    88116}
     
    90118rtc::AsyncPacketSocket* LibWebRTCSocketFactory::createNewConnectionSocket(LibWebRTCSocket& serverSocket, LibWebRTCSocketIdentifier newConnectionSocketIdentifier, const rtc::SocketAddress& remoteAddress)
    91119{
     120    ASSERT(!WTF::isMainRunLoop());
     121    if (!m_connection) {
     122        RELEASE_LOG(WebRTC, "No connection to create incoming TCP socket");
     123        callOnMainThread([] {
     124            WebProcess::singleton().ensureNetworkProcessConnection();
     125        });
     126        return nullptr;
     127    }
     128
    92129    auto socket = makeUnique<LibWebRTCSocket>(*this, serverSocket.socketGroup(), LibWebRTCSocket::Type::ServerConnectionTCP, serverSocket.localAddress(), remoteAddress);
    93130    socket->setState(LibWebRTCSocket::STATE_CONNECTED);
    94131
    95     callOnMainThread([identifier = socket->identifier(), newConnectionSocketIdentifier]() {
    96         if (!WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkRTCProvider::WrapNewTCPConnection(identifier, newConnectionSocketIdentifier), 0)) {
    97             // FIXME: Set error back to socket
    98             return;
    99         }
    100     });
     132    m_connection->send(Messages::NetworkRTCProvider::WrapNewTCPConnection(socket->identifier(), newConnectionSocketIdentifier), 0);
     133
    101134    return socket.release();
    102135}
     
    104137void LibWebRTCSocketFactory::addSocket(LibWebRTCSocket& socket)
    105138{
     139    ASSERT(!WTF::isMainRunLoop());
    106140    ASSERT(!m_sockets.contains(socket.identifier()));
    107141    m_sockets.add(socket.identifier(), &socket);
     
    110144void LibWebRTCSocketFactory::removeSocket(LibWebRTCSocket& socket)
    111145{
     146    ASSERT(!WTF::isMainRunLoop());
    112147    ASSERT(m_sockets.contains(socket.identifier()));
    113148    m_sockets.remove(socket.identifier());
     
    116151void LibWebRTCSocketFactory::forSocketInGroup(const void* socketGroup, const Function<void(LibWebRTCSocket&)>& callback)
    117152{
     153    ASSERT(!WTF::isMainRunLoop());
    118154    for (auto* socket : m_sockets.values()) {
    119155        if (socket->socketGroup() == socketGroup)
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h

    r259345 r261277  
    3838namespace WebKit {
    3939
     40class LibWebRTCNetwork;
    4041class LibWebRTCSocket;
    4142
    4243class LibWebRTCSocketFactory {
    4344public:
    44     LibWebRTCSocketFactory() { }
     45    LibWebRTCSocketFactory() = default;
    4546
    4647    void addSocket(LibWebRTCSocket&);
     
    6061    void disableNonLocalhostConnections() { m_disableNonLocalhostConnections = true; }
    6162
     63    void setConnection(RefPtr<IPC::Connection>&&);
     64    IPC::Connection* connection();
     65
    6266private:
    6367    // We cannot own sockets, clients of the factory are responsible to free them.
     
    6771    HashMap<LibWebRTCResolverIdentifier, std::unique_ptr<LibWebRTCResolver>> m_resolvers;
    6872    bool m_disableNonLocalhostConnections { false };
     73
     74    RefPtr<IPC::Connection> m_connection;
    6975};
    7076
Note: See TracChangeset for help on using the changeset viewer.