Changeset 260063 in webkit


Ignore:
Timestamp:
Apr 14, 2020 2:30:15 AM (4 years ago)
Author:
youenn@apple.com
Message:

WebSocketChannel should remove itself from its manager map
https://bugs.webkit.org/show_bug.cgi?id=210424

Reviewed by Alex Christensen.

WebSocketChannelManager was never removing any entry from its map.
To fix this, the manager is now keeping a WeakPtr to each channel.
When the channel is destroyed, it will remove itself from its channel manager.

  • WebProcess/Network/WebSocketChannel.cpp:

(WebKit::WebSocketChannel::WebSocketChannel):
(WebKit::WebSocketChannel::~WebSocketChannel):

  • WebProcess/Network/WebSocketChannel.h:
  • WebProcess/Network/WebSocketChannelManager.cpp:

(WebKit::WebSocketChannelManager::addChannel):
(WebKit::WebSocketChannelManager::createWebSocketChannel): Deleted.

  • WebProcess/Network/WebSocketChannelManager.h:

(WebKit::WebSocketChannelManager::removeChannel):

  • WebProcess/Network/WebSocketProvider.cpp:

(WebKit::WebSocketProvider::createWebSocketChannel):

Location:
trunk/Source/WebKit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260061 r260063  
     12020-04-14  Youenn Fablet  <youenn@apple.com>
     2
     3        WebSocketChannel should remove itself from its manager map
     4        https://bugs.webkit.org/show_bug.cgi?id=210424
     5
     6        Reviewed by Alex Christensen.
     7
     8        WebSocketChannelManager was never removing any entry from its map.
     9        To fix this, the manager is now keeping a WeakPtr to each channel.
     10        When the channel is destroyed, it will remove itself from its channel manager.
     11
     12        * WebProcess/Network/WebSocketChannel.cpp:
     13        (WebKit::WebSocketChannel::WebSocketChannel):
     14        (WebKit::WebSocketChannel::~WebSocketChannel):
     15        * WebProcess/Network/WebSocketChannel.h:
     16        * WebProcess/Network/WebSocketChannelManager.cpp:
     17        (WebKit::WebSocketChannelManager::addChannel):
     18        (WebKit::WebSocketChannelManager::createWebSocketChannel): Deleted.
     19        * WebProcess/Network/WebSocketChannelManager.h:
     20        (WebKit::WebSocketChannelManager::removeChannel):
     21        * WebProcess/Network/WebSocketProvider.cpp:
     22        (WebKit::WebSocketProvider::createWebSocketChannel):
     23
    1242020-04-14  Youenn Fablet  <youenn@apple.com>
    225
  • trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.cpp

    r260054 r260063  
    7676    , m_inspector(document)
    7777{
     78    WebProcess::singleton().webSocketChannelManager().addChannel(*this);
    7879}
    7980
    8081WebSocketChannel::~WebSocketChannel()
    8182{
     83    WebProcess::singleton().webSocketChannelManager().removeChannel(*this);
    8284}
    8385
  • trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h

    r256890 r260063  
    4343namespace WebKit {
    4444
    45 class WebSocketChannel : public IPC::MessageSender, public IPC::MessageReceiver, public WebCore::ThreadableWebSocketChannel, public RefCounted<WebSocketChannel> {
     45class WebSocketChannel : public IPC::MessageSender, public IPC::MessageReceiver, public WebCore::ThreadableWebSocketChannel, public RefCounted<WebSocketChannel>, public CanMakeWeakPtr<WebSocketChannel> {
    4646public:
    4747    static Ref<WebSocketChannel> create(WebCore::Document&, WebCore::WebSocketChannelClient&);
  • trunk/Source/WebKit/WebProcess/Network/WebSocketChannelManager.cpp

    r256303 r260063  
    2929namespace WebKit {
    3030
    31 RefPtr<WebCore::ThreadableWebSocketChannel> WebSocketChannelManager::createWebSocketChannel(WebCore::Document& document, WebCore::WebSocketChannelClient& client)
     31void WebSocketChannelManager::addChannel(WebSocketChannel& channel)
    3232{
    33     auto channel = WebSocketChannel::create(document, client);
    34     m_channels.add(channel->identifier(), channel.copyRef());
    35     return channel;
     33    ASSERT(!m_channels.contains(channel.identifier()));
     34    m_channels.add(channel.identifier(), makeWeakPtr(channel));
    3635}
    3736
  • trunk/Source/WebKit/WebProcess/Network/WebSocketChannelManager.h

    r256303 r260063  
    4343public:
    4444    WebSocketChannelManager() = default;
    45     RefPtr<WebCore::ThreadableWebSocketChannel> createWebSocketChannel(WebCore::Document&, WebCore::WebSocketChannelClient&);
    4645
    4746    void networkProcessCrashed();
    4847    void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
    4948
     49    void addChannel(WebSocketChannel&);
     50    void removeChannel(WebSocketChannel& channel) { m_channels.remove(channel.identifier() ); }
     51
    5052private:
    51     HashMap<WebSocketIdentifier, Ref<WebSocketChannel>> m_channels;
     53    HashMap<WebSocketIdentifier, WeakPtr<WebSocketChannel>> m_channels;
    5254};
    5355
  • trunk/Source/WebKit/WebProcess/Network/WebSocketProvider.cpp

    r250079 r260063  
    3232#include "WebSocketProvider.h"
    3333
    34 #include "WebProcess.h"
    3534#include "WebSocketChannelManager.h"
    3635#include "WebSocketStream.h"
     
    4746RefPtr<ThreadableWebSocketChannel> WebSocketProvider::createWebSocketChannel(Document& document, WebSocketChannelClient& client)
    4847{
    49     return WebProcess::singleton().webSocketChannelManager().createWebSocketChannel(document, client);
     48    return WebSocketChannel::create(document, client);
    5049}
    5150
Note: See TracChangeset for help on using the changeset viewer.