Changeset 191881 in webkit


Ignore:
Timestamp:
Nov 2, 2015 1:33:28 AM (8 years ago)
Author:
Carlos Garcia Campos
Message:

[GLIB] Remove support for GSocket main loop sources from GMainLoopSource
https://bugs.webkit.org/show_bug.cgi?id=150772

Reviewed by Žan Doberšek.

Source/WebKit2:

Add GSocketMonitor class to be used by Connection to monitor the
availability of the socket file descriptor instead of using a
GMainLoopSource.

  • Platform/IPC/Connection.h:
  • Platform/IPC/glib/GSocketMonitor.cpp: Added.

(IPC::GSocketMonitor::~GSocketMonitor):
(IPC::GSocketMonitor::socketSourceCallback):
(IPC::GSocketMonitor::start):
(IPC::GSocketMonitor::stop):

  • Platform/IPC/glib/GSocketMonitor.h: Added.
  • Platform/IPC/unix/ConnectionUnix.cpp:

(IPC::Connection::platformInvalidate):
(IPC::Connection::open):

  • PlatformGTK.cmake:

Source/WTF:

It complicated the code just to make generic what is only used in
one place.

  • wtf/glib/GMainLoopSource.cpp:

(WTF::GMainLoopSource::cancel): Deleted.
(WTF::GMainLoopSource::schedule): Deleted.
(WTF::GMainLoopSource::scheduleTimeoutSource): Deleted.
(WTF::GMainLoopSource::scheduleAfterDelay): Deleted.
(WTF::GMainLoopSource::finishVoidCallback): Deleted.
(WTF::GMainLoopSource::voidCallback): Deleted.
(WTF::GMainLoopSource::prepareBoolCallback): Deleted.

  • wtf/glib/GMainLoopSource.h:

(WTF::GMainLoopSource::Context::operator=): Deleted.

Location:
trunk/Source
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r191880 r191881  
     12015-11-02  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GLIB] Remove support for GSocket main loop sources from GMainLoopSource
     4        https://bugs.webkit.org/show_bug.cgi?id=150772
     5
     6        Reviewed by Žan Doberšek.
     7
     8        It complicated the code just to make generic what is only used in
     9        one place.
     10
     11        * wtf/glib/GMainLoopSource.cpp:
     12        (WTF::GMainLoopSource::cancel): Deleted.
     13        (WTF::GMainLoopSource::schedule): Deleted.
     14        (WTF::GMainLoopSource::scheduleTimeoutSource): Deleted.
     15        (WTF::GMainLoopSource::scheduleAfterDelay): Deleted.
     16        (WTF::GMainLoopSource::finishVoidCallback): Deleted.
     17        (WTF::GMainLoopSource::voidCallback): Deleted.
     18        (WTF::GMainLoopSource::prepareBoolCallback): Deleted.
     19        * wtf/glib/GMainLoopSource.h:
     20        (WTF::GMainLoopSource::Context::operator=): Deleted.
     21
    1222015-11-02  Carlos Garcia Campos  <cgarcia@igalia.com>
    223
  • trunk/Source/WTF/wtf/glib/GMainLoopSource.cpp

    r191880 r191881  
    5555    m_status = Ready;
    5656
    57     g_cancellable_cancel(m_context.socketCancellable.get());
    58 
    5957    if (!m_context.source)
    6058        return;
     
    8583        adoptGRef(g_idle_source_new()),
    8684        nullptr, // cancellable
    87         nullptr, // socketCancellable
    8885        WTF::move(function),
    8986        nullptr, // boolCallback
    90         nullptr, // socketCallback
    9187        WTF::move(destroyFunction)
    9288    };
     
    10298        adoptGRef(g_idle_source_new()),
    10399        nullptr, // cancellable
    104         nullptr, // socketCancellable
    105100        nullptr, // voidCallback
    106101        WTF::move(function),
    107         nullptr, // socketCallback
    108102        WTF::move(destroyFunction)
    109103    };
    110104    scheduleIdleSource(name, reinterpret_cast<GSourceFunc>(boolSourceCallback), priority, context);
    111 }
    112 
    113 void GMainLoopSource::schedule(const char* name, std::function<bool (GIOCondition)>&& function, GSocket* socket, GIOCondition condition, std::function<void ()>&& destroyFunction, GMainContext* context)
    114 {
    115     cancel();
    116 
    117     ASSERT(!m_context.source);
    118     GCancellable* socketCancellable = g_cancellable_new();
    119     m_context = {
    120         adoptGRef(g_socket_create_source(socket, condition, socketCancellable)),
    121         nullptr, // cancellable
    122         adoptGRef(socketCancellable),
    123         nullptr, // voidCallback
    124         nullptr, // boolCallback
    125         WTF::move(function),
    126         WTF::move(destroyFunction)
    127     };
    128 
    129     ASSERT(m_status == Ready);
    130     m_status = Scheduled;
    131     g_source_set_name(m_context.source.get(), name);
    132     g_source_set_callback(m_context.source.get(), reinterpret_cast<GSourceFunc>(socketSourceCallback), this, nullptr);
    133     g_source_attach(m_context.source.get(), context);
    134105}
    135106
     
    154125        adoptGRef(g_timeout_source_new(delay.count())),
    155126        nullptr, // cancellable
    156         nullptr, // socketCancellable
    157127        WTF::move(function),
    158128        nullptr, // boolCallback
    159         nullptr, // socketCallback
    160129        WTF::move(destroyFunction)
    161130    };
     
    171140        adoptGRef(g_timeout_source_new(delay.count())),
    172141        nullptr, // cancellable
    173         nullptr, // socketCancellable
    174142        nullptr, // voidCallback
    175143        WTF::move(function),
    176         nullptr, // socketCallback
    177144        WTF::move(destroyFunction)
    178145    };
     
    188155        adoptGRef(g_timeout_source_new_seconds(delay.count())),
    189156        nullptr, // cancellable
    190         nullptr, // socketCancellable
    191157        WTF::move(function),
    192158        nullptr, // boolCallback
    193         nullptr, // socketCallback
    194159        WTF::move(destroyFunction)
    195160    };
     
    205170        adoptGRef(g_timeout_source_new_seconds(delay.count())),
    206171        nullptr, // cancellable
    207         nullptr, // socketCancellable
    208172        nullptr, // voidCallback
    209173        WTF::move(function),
    210         nullptr, // socketCallback
    211174        WTF::move(destroyFunction)
    212175    };
     
    251214        adoptGRef(createMicrosecondsTimeoutSource(delay.count())),
    252215        nullptr, // cancellable
    253         nullptr, // socketCancellable
    254216        WTF::move(function),
    255217        nullptr, // boolCallback
    256         nullptr, // socketCallback
    257218        WTF::move(destroyFunction)
    258219    };
     
    268229        adoptGRef(createMicrosecondsTimeoutSource(delay.count())),
    269230        nullptr, // cancellable
    270         nullptr, // socketCancellable
    271231        nullptr, // voidCallback
    272232        WTF::move(function),
    273         nullptr, // socketCallback
    274233        WTF::move(destroyFunction)
    275234    };
     
    352311}
    353312
    354 bool GMainLoopSource::socketCallback(GIOCondition condition)
    355 {
    356     if (!m_context.source)
    357         return Stop;
    358 
    359     Context context;
    360     context = WTF::move(m_context);
    361 
    362     ASSERT(context.socketCallback);
    363     ASSERT(m_status == Scheduled || m_status == Dispatching);
    364     m_status = Dispatching;
    365 
    366     if (g_cancellable_is_cancelled(context.socketCancellable.get())) {
    367         context.destroySource();
    368         return Stop;
    369     }
    370 
    371     bool retval = context.socketCallback(condition);
    372 
    373     if (m_status != Ready && !m_context.source) {
    374         // m_status should reflect whether the GMainLoopSource has been rescheduled during dispatch.
    375         ASSERT((!m_context.source && m_status == Dispatching) || m_status == Scheduled);
    376         if (retval && !m_context.source)
    377             m_context = WTF::move(context);
    378         else if (!retval)
    379             m_status = Ready;
    380     }
    381 
    382     if (context.source)
    383         context.destroySource();
    384 
    385     return retval;
    386 }
    387 
    388313gboolean GMainLoopSource::voidSourceCallback(GMainLoopSource* source)
    389314{
     
    395320{
    396321    return source->boolCallback() == Continue;
    397 }
    398 
    399 gboolean GMainLoopSource::socketSourceCallback(GSocket*, GIOCondition condition, GMainLoopSource* source)
    400 {
    401     return source->socketCallback(condition) == Continue;
    402322}
    403323
  • trunk/Source/WTF/wtf/glib/GMainLoopSource.h

    r191880 r191881  
    3434#include <wtf/glib/GRefPtr.h>
    3535
    36 typedef struct _GSocket GSocket;
    37 
    3836namespace WTF {
    3937
     
    6159    WTF_EXPORT_PRIVATE virtual void cancel();
    6260
    63     WTF_EXPORT_PRIVATE void schedule(const char* name, std::function<bool(GIOCondition)>&&, GSocket*, GIOCondition, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
    64 
    6561protected:
    6662    enum Status { Ready, Scheduled, Dispatching };
     
    7268            source = WTF::move(c.source);
    7369            cancellable = WTF::move(c.cancellable);
    74             socketCancellable = WTF::move(c.socketCancellable);
    7570            voidCallback = WTF::move(c.voidCallback);
    7671            boolCallback = WTF::move(c.boolCallback);
    77             socketCallback = WTF::move(c.socketCallback);
    7872            destroyCallback = WTF::move(c.destroyCallback);
    7973            return *this;
     
    8478        GRefPtr<GSource> source;
    8579        GRefPtr<GCancellable> cancellable;
    86         GRefPtr<GCancellable> socketCancellable;
    8780        std::function<void ()> voidCallback;
    8881        std::function<bool ()> boolCallback;
    89         std::function<bool (GIOCondition)> socketCallback;
    9082        std::function<void ()> destroyCallback;
    9183    };
     
    10294    void scheduleIdleSource(const char* name, GSourceFunc, int priority, GMainContext*);
    10395    void scheduleTimeoutSource(const char* name, GSourceFunc, int priority, GMainContext*);
    104     bool socketCallback(GIOCondition);
    10596
    10697    static gboolean voidSourceCallback(GMainLoopSource*);
    10798    static gboolean boolSourceCallback(GMainLoopSource*);
    108     static gboolean socketSourceCallback(GSocket*, GIOCondition, GMainLoopSource*);
    10999
    110100protected:
  • trunk/Source/WebKit2/ChangeLog

    r191878 r191881  
     12015-11-02  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GLIB] Remove support for GSocket main loop sources from GMainLoopSource
     4        https://bugs.webkit.org/show_bug.cgi?id=150772
     5
     6        Reviewed by Žan Doberšek.
     7
     8        Add GSocketMonitor class to be used by Connection to monitor the
     9        availability of the socket file descriptor instead of using a
     10        GMainLoopSource.
     11
     12        * Platform/IPC/Connection.h:
     13        * Platform/IPC/glib/GSocketMonitor.cpp: Added.
     14        (IPC::GSocketMonitor::~GSocketMonitor):
     15        (IPC::GSocketMonitor::socketSourceCallback):
     16        (IPC::GSocketMonitor::start):
     17        (IPC::GSocketMonitor::stop):
     18        * Platform/IPC/glib/GSocketMonitor.h: Added.
     19        * Platform/IPC/unix/ConnectionUnix.cpp:
     20        (IPC::Connection::platformInvalidate):
     21        (IPC::Connection::open):
     22        * PlatformGTK.cmake:
     23
    1242015-11-01  Carlos Garcia Campos  <cgarcia@igalia.com>
    225
  • trunk/Source/WebKit2/Platform/IPC/Connection.h

    r191856 r191881  
    5454
    5555#if PLATFORM(GTK)
    56 #include <wtf/glib/GMainLoopSource.h>
     56#include "GSocketMonitor.h"
    5757#endif
    5858
     
    338338    int m_socketDescriptor;
    339339#if PLATFORM(GTK)
    340     GMainLoopSource m_socketEventSource;
     340    GSocketMonitor m_socketMonitor;
    341341#endif
    342342#elif OS(DARWIN)
  • trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp

    r191878 r191881  
    149149
    150150#if PLATFORM(GTK)
    151     m_socketEventSource.cancel();
     151    m_socketMonitor.stop();
    152152#elif PLATFORM(EFL)
    153153    m_connectionQueue->unregisterSocketEventHandler(m_socketDescriptor);
     
    378378#if PLATFORM(GTK)
    379379    GRefPtr<GSocket> socket = adoptGRef(g_socket_new_from_fd(m_socketDescriptor, nullptr));
    380     m_socketEventSource.schedule("[WebKit] Connection::SocketEventHandler", [protectedThis] (GIOCondition condition) {
     380    m_socketMonitor.start(socket.get(), G_IO_IN, m_connectionQueue->runLoop(), [protectedThis] (GIOCondition condition) -> gboolean {
    381381        if (condition & G_IO_HUP || condition & G_IO_ERR || condition & G_IO_NVAL) {
    382382            protectedThis->connectionDidClose();
    383             return GMainLoopSource::Stop;
     383            return G_SOURCE_REMOVE;
    384384        }
    385385
    386386        if (condition & G_IO_IN) {
    387387            protectedThis->readyReadHandler();
    388             return GMainLoopSource::Continue;
     388            return G_SOURCE_CONTINUE;
    389389        }
    390390
    391391        ASSERT_NOT_REACHED();
    392         return GMainLoopSource::Stop;
    393     }, socket.get(), G_IO_IN, nullptr, m_connectionQueue->runLoop().mainContext());
     392        return G_SOURCE_REMOVE;
     393    });
    394394#elif PLATFORM(EFL)
    395395    m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
  • trunk/Source/WebKit2/PlatformGTK.cmake

    r191686 r191881  
    3636    NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
    3737
     38    Platform/IPC/glib/GSocketMonitor.cpp
    3839    Platform/IPC/unix/AttachmentUnix.cpp
    3940    Platform/IPC/unix/ConnectionUnix.cpp
     
    493494    "${WEBKIT2_DIR}/NetworkProcess/gtk"
    494495    "${WEBKIT2_DIR}/NetworkProcess/unix"
     496    "${WEBKIT2_DIR}/Platform/IPC/glib"
    495497    "${WEBKIT2_DIR}/Shared/API/c/gtk"
    496498    "${WEBKIT2_DIR}/Shared/Network/CustomProtocols/soup"
     
    711713        Platform/IPC/StringReference.cpp
    712714
     715        Platform/IPC/glib/GSocketMonitor.cpp
    713716        Platform/IPC/unix/AttachmentUnix.cpp
    714717        Platform/IPC/unix/ConnectionUnix.cpp
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r191453 r191881  
    6666#include <memory>
    6767#include <wtf/HashMap.h>
     68#include <wtf/glib/GMainLoopSource.h>
    6869#include <wtf/glib/GRefPtr.h>
    6970#include <wtf/text/CString.h>
Note: See TracChangeset for help on using the changeset viewer.