[GTK] Remove the remaining uses of GMainLoopSource
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Nov 2015 16:54:45 +0000 (16:54 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Nov 2015 16:54:45 +0000 (16:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151632

Reviewed by Žan Doberšek.

Source/WebKit2:

* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(_WebKitWebViewBasePrivate::_WebKitWebViewBasePrivate):
(_WebKitWebViewBasePrivate::clearRedirectedWindowSoonTimerFired):
(webkitWebViewBaseClearRedirectedWindowSoon):
(webkitWebViewBaseEnterAcceleratedCompositingMode):

Tools:

* TestWebKitAPI/Tests/WebKit2Gtk/TestResources.cpp:
(testWebViewSyncRequestOnMaxConns):
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::TestRunner):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:
(WTR::TestRunner::invalidateWaitToDumpWatchdogTimer):
(WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
* WebKitTestRunner/gtk/TestControllerGtk.cpp:
(WTR::timeoutSource):
(WTR::TestController::notifyDone):
(WTR::TestController::platformRunUntil):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestResources.cpp
Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp
Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp

index e2486db..f963547 100644 (file)
@@ -1,3 +1,16 @@
+2015-11-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Remove the remaining uses of GMainLoopSource
+        https://bugs.webkit.org/show_bug.cgi?id=151632
+
+        Reviewed by Žan Doberšek.
+
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (_WebKitWebViewBasePrivate::_WebKitWebViewBasePrivate):
+        (_WebKitWebViewBasePrivate::clearRedirectedWindowSoonTimerFired):
+        (webkitWebViewBaseClearRedirectedWindowSoon):
+        (webkitWebViewBaseEnterAcceleratedCompositingMode):
+
 2015-11-23  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Use the network process unconditionally
index 0c89920..939879e 100644 (file)
@@ -65,7 +65,6 @@
 #include <glib/gi18n-lib.h>
 #include <memory>
 #include <wtf/HashMap.h>
-#include <wtf/glib/GMainLoopSource.h>
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/text/CString.h>
 
@@ -149,6 +148,19 @@ typedef HashMap<GtkWidget*, IntRect> WebKitWebViewChildrenMap;
 typedef HashMap<uint32_t, GUniquePtr<GdkEvent>> TouchEventsMap;
 
 struct _WebKitWebViewBasePrivate {
+#if USE(REDIRECTED_XCOMPOSITE_WINDOW)
+    _WebKitWebViewBasePrivate()
+        : clearRedirectedWindowSoonTimer(RunLoop::main(), this, &_WebKitWebViewBasePrivate::clearRedirectedWindowSoonTimerFired)
+    {
+    }
+
+    void clearRedirectedWindowSoonTimerFired()
+    {
+        if (redirectedWindow)
+            redirectedWindow->resize(IntSize());
+    }
+#endif
+
     WebKitWebViewChildrenMap children;
     std::unique_ptr<PageClientImpl> pageClient;
     RefPtr<WebPageProxy> pageProxy;
@@ -190,7 +202,7 @@ struct _WebKitWebViewBasePrivate {
 
 #if USE(REDIRECTED_XCOMPOSITE_WINDOW)
     std::unique_ptr<RedirectedXCompositeWindow> redirectedWindow;
-    GMainLoopSource clearRedirectedWindowSoon;
+    RunLoop::Timer<WebKitWebViewBasePrivate> clearRedirectedWindowSoonTimer;
 #endif
 
 #if ENABLE(DRAG_SUPPORT)
@@ -1358,12 +1370,8 @@ void webkitWebViewBaseResetClickCounter(WebKitWebViewBase* webkitWebViewBase)
 #if USE(REDIRECTED_XCOMPOSITE_WINDOW)
 static void webkitWebViewBaseClearRedirectedWindowSoon(WebKitWebViewBase* webkitWebViewBase)
 {
-    WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv;
-    static const std::chrono::seconds clearRedirectedWindowSoonDelay = 2_s;
-    priv->clearRedirectedWindowSoon.scheduleAfterDelay("[WebKit] Clear RedirectedWindow soon", [priv]() {
-        if (priv->redirectedWindow)
-            priv->redirectedWindow->resize(IntSize());
-    }, clearRedirectedWindowSoonDelay);
+    static const double clearRedirectedWindowSoonDelay = 2;
+    webkitWebViewBase->priv->clearRedirectedWindowSoonTimer.startOneShot(clearRedirectedWindowSoonDelay);
 }
 #endif
 
@@ -1390,7 +1398,7 @@ void webkitWebViewBaseWillEnterAcceleratedCompositingMode(WebKitWebViewBase* web
 void webkitWebViewBaseEnterAcceleratedCompositingMode(WebKitWebViewBase* webkitWebViewBase)
 {
 #if USE(REDIRECTED_XCOMPOSITE_WINDOW)
-    webkitWebViewBase->priv->clearRedirectedWindowSoon.cancel();
+    webkitWebViewBase->priv->clearRedirectedWindowSoonTimer.stop();
 #else
     UNUSED_PARAM(webkitWebViewBase);
 #endif
index b037c21..79138e6 100644 (file)
@@ -1,3 +1,24 @@
+2015-11-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Remove the remaining uses of GMainLoopSource
+        https://bugs.webkit.org/show_bug.cgi?id=151632
+
+        Reviewed by Žan Doberšek.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestResources.cpp:
+        (testWebViewSyncRequestOnMaxConns):
+        * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::TestRunner):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/InjectedBundle/gtk/TestRunnerGtk.cpp:
+        (WTR::TestRunner::invalidateWaitToDumpWatchdogTimer):
+        (WTR::TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded):
+        * WebKitTestRunner/gtk/TestControllerGtk.cpp:
+        (WTR::timeoutSource):
+        (WTR::TestController::notifyDone):
+        (WTR::TestController::platformRunUntil):
+
 2015-11-27  Csaba Osztrogonác  <ossy@webkit.org>
 
         [cmake] Add testb3 to the build system
index 9f97b5f..705ad5b 100644 (file)
@@ -22,7 +22,6 @@
 #include "WebKitTestServer.h"
 #include "WebViewTest.h"
 #include <wtf/Vector.h>
-#include <wtf/glib/GMainLoopSource.h>
 #include <wtf/glib/GMutexLocker.h>
 #include <wtf/glib/GRefPtr.h>
 
@@ -706,12 +705,27 @@ static void testWebViewSyncRequestOnMaxConns(SyncRequestOnMaxConnsTest* test, gc
     }
 
     // By default sync XHRs have a 10 seconds timeout, we don't want to wait all that so use our own timeout.
-    GMainLoopSource timeoutSource;
-    timeoutSource.scheduleAfterDelay("Timeout", [] { g_assert_not_reached(); }, std::chrono::seconds(1));
-
-    GMainLoopSource unlockServerSource;
-    unlockServerSource.schedule("Unlock Server Idle", [&lock] { lock.unlock(); });
+    guint timeoutSourceID = g_timeout_add(1000, [] (gpointer) -> gboolean {
+        g_assert_not_reached();
+        return G_SOURCE_REMOVE;
+    }, nullptr);
+
+    struct UnlockServerSourceContext {
+        WTF::GMutexLocker<GMutex>& lock;
+        guint unlockServerSourceID;
+    } context = {
+        lock,
+        g_idle_add_full(G_PRIORITY_DEFAULT, [](gpointer userData) -> gboolean {
+            auto& context = *static_cast<UnlockServerSourceContext*>(userData);
+            context.unlockServerSourceID = 0;
+            context.lock.unlock();
+            return G_SOURCE_REMOVE;
+        }, &context, nullptr)
+    };
     test->waitUntilResourcesLoaded(s_maxConnectionsPerHost + 3); // s_maxConnectionsPerHost resource + main resource + 2 XHR.
+    g_source_remove(timeoutSourceID);
+    if (context.unlockServerSourceID)
+        g_source_remove(context.unlockServerSourceID);
 }
 
 static void addCacheHTTPHeadersToResponse(SoupMessage* message)
index 69e2ce7..7b34830 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <JavaScriptCore/JSRetainPtr.h>
 #include <WebCore/GUniquePtrGtk.h>
-#include <wtf/glib/GMainLoopSource.h>
 
 WebViewTest::WebViewTest(WebKitUserContentManager* userContentManager)
     : m_webView(WEBKIT_WEB_VIEW(g_object_ref_sink(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", m_webContext.get(), "user-content-manager", userContentManager, nullptr))))
index c80f88e..8ebadd7 100644 (file)
@@ -96,6 +96,9 @@ TestRunner::TestRunner()
     , m_databaseMaxQuota(-1)
     , m_userStyleSheetEnabled(false)
     , m_userStyleSheetLocation(adoptWK(WKStringCreateWithUTF8CString("")))
+#if PLATFORM(GTK)
+    , m_waitToDumpWatchdogTimer(RunLoop::main(), this, &TestRunner::waitToDumpWatchdogTimerFired)
+#endif
 {
     platformInitialize();
 }
index d904736..e5a9642 100644 (file)
 #include <CoreFoundation/CFRunLoop.h>
 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
 #elif PLATFORM(GTK)
-#include <wtf/glib/GMainLoopSource.h>
-typedef GMainLoopSource PlatformTimerRef;
+#include <wtf/RunLoop.h>
+namespace WTR {
+class TestRunner;
+typedef RunLoop::Timer<TestRunner> PlatformTimerRef;
+}
 #elif PLATFORM(EFL)
 typedef Ecore_Timer* PlatformTimerRef;
 #endif
index daade34..a9f7f40 100644 (file)
@@ -40,16 +40,15 @@ void TestRunner::platformInitialize()
 
 void TestRunner::invalidateWaitToDumpWatchdogTimer()
 {
-    m_waitToDumpWatchdogTimer.cancel();
+    m_waitToDumpWatchdogTimer.stop();
 }
 
 void TestRunner::initializeWaitToDumpWatchdogTimerIfNeeded()
 {
-    if (m_waitToDumpWatchdogTimer.isScheduled())
+    if (m_waitToDumpWatchdogTimer.isActive())
         return;
 
-    m_waitToDumpWatchdogTimer.scheduleAfterDelay("[WTR] waitToDumpWatchdogTimerCallback", [this] { waitToDumpWatchdogTimerFired(); },
-        std::chrono::milliseconds(m_timeout));
+    m_waitToDumpWatchdogTimer.startOneShot(m_timeout / 1000.0);
 }
 
 JSRetainPtr<JSStringRef> TestRunner::pathToLocalResource(JSStringRef url)
index 20cfdbc..df5da65 100644 (file)
 #include <gtk/gtk.h>
 #include <wtf/Platform.h>
 #include <wtf/RunLoop.h>
-#include <wtf/glib/GMainLoopSource.h>
+#include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/GUniquePtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace WTR {
 
-static GMainLoopSource timeoutSource;
+static GSource* timeoutSource()
+{
+    static GRefPtr<GSource> source = nullptr;
+    if (!source) {
+        source = adoptGRef(g_timeout_source_new(0));
+        g_source_set_ready_time(source.get(), -1);
+        g_source_set_name(source.get(), "[WTR] Test timeout source");
+        g_source_set_callback(source.get(), [](gpointer userData) -> gboolean {
+            g_source_set_ready_time(static_cast<GSource*>(userData), -1);
+            fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
+            RunLoop::main().stop();
+            return G_SOURCE_CONTINUE;
+        }, source.get(), nullptr);
+        g_source_attach(source.get(), nullptr);
+    }
+    return source.get();
+}
 
 void TestController::notifyDone()
 {
-    timeoutSource.cancel();
+    g_source_set_ready_time(timeoutSource(), -1);
     RunLoop::main().stop();
 }
 
@@ -61,12 +77,17 @@ void TestController::platformDestroy()
 void TestController::platformRunUntil(bool&, double timeout)
 {
     if (timeout > 0) {
-        timeoutSource.scheduleAfterDelay("[WTR] Test timeout source", [] {
-            fprintf(stderr, "FAIL: TestControllerRunLoop timed out.\n");
-            RunLoop::main().stop();
-        }, std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(timeout)));
+        // FIXME: This conversion is now repeated in several places, it should be moved to a common place in WTF and used everywhere.
+        auto timeoutDuration = std::chrono::duration<double>(timeout);
+        auto safeDuration = std::chrono::microseconds::max();
+        if (timeoutDuration < safeDuration)
+            safeDuration = std::chrono::duration_cast<std::chrono::microseconds>(timeoutDuration);
+        gint64 currentTime = g_get_monotonic_time();
+        gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, safeDuration.count());
+        ASSERT(targetTime >= currentTime);
+        g_source_set_ready_time(timeoutSource(), targetTime);
     } else
-        timeoutSource.cancel();
+        g_source_set_ready_time(timeoutSource(), -1);
     RunLoop::main().run();
 }