[GTK] Use RunLoop::Timer instead of GMainLoopSource
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 12:12:09 +0000 (12:12 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 12:12:09 +0000 (12:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150592

Reviewed by Žan Doberšek.

Source/WebCore:

* platform/network/ResourceHandle.h:
* platform/network/ResourceHandleInternal.h:
(WebCore::ResourceHandleInternal::ResourceHandleInternal):
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::cleanupSoupRequestOperation):
(WebCore::ResourceHandle::timeoutFired):
(WebCore::ResourceHandle::sendPendingRequest):
(WebCore::ResourceHandle::platformSetDefersLoading):

Source/WebKit2:

* Shared/Downloads/soup/DownloadSoup.cpp:
(WebKit::DownloadClient::DownloadClient):
(WebKit::DownloadClient::didReceiveData):
(WebKit::DownloadClient::handleResponseLater):
* UIProcess/gtk/GestureController.cpp:
(WebKit::GestureController::DragGesture::begin):
(WebKit::GestureController::DragGesture::update):
(WebKit::GestureController::DragGesture::end):
(WebKit::GestureController::DragGesture::longPressFired):
(WebKit::GestureController::DragGesture::DragGesture):
(WebKit::GestureController::ZoomGesture::scaleChanged):
(WebKit::GestureController::ZoomGesture::ZoomGesture):
* UIProcess/gtk/GestureController.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191787 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/ResourceHandle.h
Source/WebCore/platform/network/ResourceHandleInternal.h
Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/Downloads/soup/DownloadSoup.cpp
Source/WebKit2/UIProcess/gtk/GestureController.cpp
Source/WebKit2/UIProcess/gtk/GestureController.h

index 62623aa93d091efc39ba6e85844ebcbaf7c8894e..83435936fbb2cee6465fb5d4fe380d24529f52db 100644 (file)
@@ -1,3 +1,19 @@
+2015-10-30  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use RunLoop::Timer instead of GMainLoopSource
+        https://bugs.webkit.org/show_bug.cgi?id=150592
+
+        Reviewed by Žan Doberšek.
+
+        * platform/network/ResourceHandle.h:
+        * platform/network/ResourceHandleInternal.h:
+        (WebCore::ResourceHandleInternal::ResourceHandleInternal):
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::cleanupSoupRequestOperation):
+        (WebCore::ResourceHandle::timeoutFired):
+        (WebCore::ResourceHandle::sendPendingRequest):
+        (WebCore::ResourceHandle::platformSetDefersLoading):
+
 2015-10-30  Hunseop Jeong  <hs85.jeong@samsung.com>
 
         REGRESSION(r191776): EFL build broken.
index a1f591e29c87eb28647c9012bb50ca64708d0768..52dd46a9a54fc74f776cc7a41f9f6d9d90bd6674 100644 (file)
@@ -289,6 +289,10 @@ private:
 static void getConnectionTimingData(NSDictionary *timingData, ResourceLoadTiming&);
 #endif
 
+#if USE(SOUP)
+    void timeoutFired();
+#endif
+
     friend class ResourceHandleInternal;
     std::unique_ptr<ResourceHandleInternal> d;
 
index cced8b243530e5fec8af8f757e02291b6dbfc426..6123f14aca2484be42a6df100af3aac319bd2d9f 100644 (file)
@@ -52,7 +52,7 @@
 #if USE(SOUP)
 #include "GUniquePtrSoup.h"
 #include <libsoup/soup.h>
-#include <wtf/glib/GMainLoopSource.h>
+#include <wtf/RunLoop.h>
 #include <wtf/glib/GRefPtr.h>
 #endif
 
@@ -91,6 +91,7 @@ namespace WebCore {
 #endif
 #if USE(SOUP)
             , m_cancelled(false)
+            , m_timeoutSource(RunLoop::main(), loader, &ResourceHandle::timeoutFired)
             , m_bodySize(0)
             , m_bodyDataSent(0)
             , m_redirectCount(0)
@@ -169,7 +170,7 @@ namespace WebCore {
         GRefPtr<SoupMultipartInputStream> m_multipartInputStream;
         GRefPtr<GCancellable> m_cancellable;
         GRefPtr<GAsyncResult> m_deferredResult;
-        GMainLoopSource m_timeoutSource;
+        RunLoop::Timer<ResourceHandle> m_timeoutSource;
         GUniquePtr<SoupBuffer> m_soupBuffer;
         unsigned long m_bodySize;
         unsigned long m_bodyDataSent;
index dc39242ce13478db169123de1f226d6dbcd94edc..956897b5c9dcfda3edd132f4f17e234def27d3db 100644 (file)
@@ -601,7 +601,7 @@ static void cleanupSoupRequestOperation(ResourceHandle* handle, bool isDestroyin
         d->m_soupMessage.clear();
     }
 
-    d->m_timeoutSource.cancel();
+    d->m_timeoutSource.stop();
 
     if (!isDestroying)
         handle->deref();
@@ -1049,19 +1049,20 @@ RefPtr<ResourceHandle> ResourceHandle::releaseForDownload(ResourceHandleClient*
     return newHandle;
 }
 
+void ResourceHandle::timeoutFired()
+{
+    client()->didFail(this, ResourceError::timeoutError(firstRequest().url().string()));
+    cancel();
+}
+
 void ResourceHandle::sendPendingRequest()
 {
 #if ENABLE(WEB_TIMING)
     m_requestTime = monotonicallyIncreasingTime();
 #endif
 
-    if (d->m_firstRequest.timeoutInterval() > 0) {
-        d->m_timeoutSource.scheduleAfterDelay("[WebKit] ResourceHandle request timeout", [this] {
-            client()->didFail(this, ResourceError::timeoutError(firstRequest().url().string()));
-            cancel();
-        }, std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(d->m_firstRequest.timeoutInterval())),
-        G_PRIORITY_DEFAULT, nullptr, g_main_context_get_thread_default());
-    }
+    if (d->m_firstRequest.timeoutInterval() > 0)
+        d->m_timeoutSource.startOneShot(d->m_firstRequest.timeoutInterval());
 
     // Balanced by a deref() in cleanupSoupRequestOperation, which should always run.
     ref();
@@ -1265,7 +1266,7 @@ void ResourceHandle::platformSetDefersLoading(bool defersLoading)
 
     // Except when canceling a possible timeout timer, we only need to take action here to UN-defer loading.
     if (defersLoading) {
-        d->m_timeoutSource.cancel();
+        d->m_timeoutSource.stop();
         return;
     }
 
index 2fed6825510988f471e42b27356b71ca8ac7597a..24fa00c36902eb5865007d9312c69897fcb27ac4 100644 (file)
@@ -1,3 +1,24 @@
+2015-10-30  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use RunLoop::Timer instead of GMainLoopSource
+        https://bugs.webkit.org/show_bug.cgi?id=150592
+
+        Reviewed by Žan Doberšek.
+
+        * Shared/Downloads/soup/DownloadSoup.cpp:
+        (WebKit::DownloadClient::DownloadClient):
+        (WebKit::DownloadClient::didReceiveData):
+        (WebKit::DownloadClient::handleResponseLater):
+        * UIProcess/gtk/GestureController.cpp:
+        (WebKit::GestureController::DragGesture::begin):
+        (WebKit::GestureController::DragGesture::update):
+        (WebKit::GestureController::DragGesture::end):
+        (WebKit::GestureController::DragGesture::longPressFired):
+        (WebKit::GestureController::DragGesture::DragGesture):
+        (WebKit::GestureController::ZoomGesture::scaleChanged):
+        (WebKit::GestureController::ZoomGesture::ZoomGesture):
+        * UIProcess/gtk/GestureController.h:
+
 2015-10-29  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Use a persistent main loop source in RunLoop glib implementation
index 74ff1a842b0d80c19a2f814a93728b6ccb214a12..5655dfc4bb6fee23309b30b4fddcd984be96ef83 100644 (file)
@@ -32,7 +32,7 @@
 #include <WebCore/NotImplemented.h>
 #include <WebCore/ResourceHandleInternal.h>
 #include <gio/gio.h>
-#include <wtf/glib/GMainLoopSource.h>
+#include <wtf/RunLoop.h>
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/GUniquePtr.h>
 #include <wtf/text/CString.h>
@@ -50,6 +50,7 @@ class DownloadClient : public ResourceHandleClient {
 public:
     DownloadClient(Download* download)
         : m_download(download)
+        , m_handleResponseLater(RunLoop::main(), this, &DownloadClient::handleResponse)
         , m_allowOverwrite(false)
     {
     }
@@ -131,8 +132,8 @@ public:
 
     void didReceiveData(ResourceHandle*, const char* data, unsigned length, int /*encodedDataLength*/)
     {
-        if (m_handleResponseLater.isScheduled()) {
-            m_handleResponseLater.cancel();
+        if (m_handleResponseLater.isActive()) {
+            m_handleResponseLater.stop();
             handleResponse();
         }
 
@@ -197,13 +198,13 @@ public:
     void handleResponseLater(const ResourceResponse& response)
     {
         ASSERT(m_response.isNull());
-        ASSERT(!m_handleResponseLater.isScheduled());
+        ASSERT(!m_handleResponseLater.isActive());
 
         m_delayedResponse = response;
 
         // Call didReceiveResponse in an idle to make sure the download is added
         // to the DownloadManager downloads map.
-        m_handleResponseLater.schedule("[WebKit] DownloadHandleResponseLater", std::function<void()>(std::bind(&DownloadClient::handleResponse, this)));
+        m_handleResponseLater.startOneShot(0);
     }
 
     Download* m_download;
@@ -212,7 +213,7 @@ public:
     GRefPtr<GFile> m_destinationFile;
     GRefPtr<GFile> m_intermediateFile;
     ResourceResponse m_delayedResponse;
-    GMainLoopSource m_handleResponseLater;
+    RunLoop::Timer<DownloadClient> m_handleResponseLater;
     bool m_allowOverwrite;
 };
 
index 987fb143215dbe49aa79d401c7d40332600c6ac2..7e1577cba8b15705264e5ba5475ffc5962dab889 100644 (file)
@@ -127,9 +127,7 @@ void GestureController::DragGesture::begin(DragGesture* dragGesture, double x, d
     GtkWidget* widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
     unsigned delay;
     g_object_get(gtk_widget_get_settings(widget), "gtk-long-press-time", &delay, nullptr);
-    dragGesture->m_longPressTimeout.scheduleAfterDelay("[WebKit] DragGesture long press timeout", [dragGesture]() {
-        dragGesture->m_inDrag = true;
-    }, std::chrono::milliseconds(delay));
+    dragGesture->m_longPressTimeout.startOneShot(delay / 1000.0);
 }
 
 void GestureController::DragGesture::update(DragGesture* dragGesture, double x, double y, GtkGesture* gesture)
@@ -140,7 +138,7 @@ void GestureController::DragGesture::update(DragGesture* dragGesture, double x,
     GtkWidget* widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
     if (!dragGesture->m_inDrag && gtk_drag_check_threshold(widget, dragGesture->m_start.x(), dragGesture->m_start.y(), dragGesture->m_start.x() + x, dragGesture->m_start.y() + y)) {
         dragGesture->m_inDrag = true;
-        dragGesture->m_longPressTimeout.cancel();
+        dragGesture->m_longPressTimeout.stop();
     }
 
     if (dragGesture->m_inDrag)
@@ -150,7 +148,7 @@ void GestureController::DragGesture::update(DragGesture* dragGesture, double x,
 
 void GestureController::DragGesture::end(DragGesture* dragGesture, GdkEventSequence* sequence, GtkGesture* gesture)
 {
-    dragGesture->m_longPressTimeout.cancel();
+    dragGesture->m_longPressTimeout.stop();
     if (!dragGesture->m_inDrag) {
         dragGesture->handleTap(gtk_gesture_get_last_event(gesture, sequence));
         gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED);
@@ -158,8 +156,14 @@ void GestureController::DragGesture::end(DragGesture* dragGesture, GdkEventSeque
         gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED);
 }
 
+void GestureController::DragGesture::longPressFired()
+{
+    m_inDrag = true;
+}
+
 GestureController::DragGesture::DragGesture(WebPageProxy& page)
     : Gesture(gtk_gesture_drag_new(page.viewWidget()), page)
+    , m_longPressTimeout(RunLoop::main(), this, &GestureController::DragGesture::longPressFired)
     , m_inDrag(false)
 {
     gtk_gesture_single_set_touch_only(GTK_GESTURE_SINGLE(m_gesture.get()), TRUE);
@@ -199,16 +203,17 @@ void GestureController::ZoomGesture::scaleChanged(ZoomGesture* zoomGesture, doub
 {
     zoomGesture->m_scale = zoomGesture->m_initialScale * scale;
     zoomGesture->m_viewPoint = zoomGesture->center();
-    if (zoomGesture->m_idle.isScheduled())
+    if (zoomGesture->m_idle.isActive())
         return;
 
-    zoomGesture->m_idle.schedule("[WebKit] Zoom Gesture Idle", std::bind(&GestureController::ZoomGesture::handleZoom, zoomGesture));
+    zoomGesture->m_idle.startOneShot(0);
 }
 
 GestureController::ZoomGesture::ZoomGesture(WebPageProxy& page)
     : Gesture(gtk_gesture_zoom_new(page.viewWidget()), page)
     , m_initialScale(0)
     , m_scale(0)
+    , m_idle(RunLoop::main(), this, &GestureController::ZoomGesture::handleZoom)
 {
     g_signal_connect_swapped(m_gesture.get(), "begin", G_CALLBACK(begin), this);
     g_signal_connect_swapped(m_gesture.get(), "scale-changed", G_CALLBACK(scaleChanged), this);
index 78fc2cb31cb06862ffcc3f3b8622e13606829aa9..86792df42cf4c34f89d8dfd7c0191199041674ca 100644 (file)
@@ -30,7 +30,7 @@
 
 #include <WebCore/FloatPoint.h>
 #include <wtf/Noncopyable.h>
-#include <wtf/glib/GMainLoopSource.h>
+#include <wtf/RunLoop.h>
 #include <wtf/glib/GRefPtr.h>
 
 typedef union _GdkEvent GdkEvent;
@@ -69,6 +69,7 @@ private:
     private:
         void handleDrag(const GdkEvent*, double x, double y);
         void handleTap(const GdkEvent*);
+        void longPressFired();
 
         static void begin(DragGesture*, double x, double y, GtkGesture*);
         static void update(DragGesture*, double x, double y, GtkGesture*);
@@ -76,7 +77,7 @@ private:
 
         WebCore::FloatPoint m_start;
         WebCore::FloatPoint m_offset;
-        GMainLoopSource m_longPressTimeout;
+        RunLoop::Timer<DragGesture> m_longPressTimeout;
         GRefPtr<GtkGesture> m_longPress;
         bool m_inDrag;
     };
@@ -96,7 +97,7 @@ private:
         gdouble m_scale;
         WebCore::IntPoint m_initialPoint;
         WebCore::IntPoint m_viewPoint;
-        GMainLoopSource m_idle;
+        RunLoop::Timer<ZoomGesture> m_idle;
     };
 
     DragGesture m_dragGesture;