[GLIB] Remove delete on destroy GMainLoopSources
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Nov 2015 09:15:39 +0000 (09:15 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Nov 2015 09:15:39 +0000 (09:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150771

Reviewed by Žan Doberšek.

Source/WTF:

Delete on destroy sources made the GMainLoopSource implementation
more complex and they are currently unused.

* wtf/glib/GMainLoopSource.cpp:
(WTF::GMainLoopSource::boolCallback):
(WTF::GMainLoopSource::create): Deleted.
(WTF::GMainLoopSource::GMainLoopSource): Deleted.
(WTF::GMainLoopSource::cancel): Deleted.
(WTF::GMainLoopSource::scheduleAndDeleteOnDestroy): Deleted.
(WTF::GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy): Deleted.
(WTF::GMainLoopSource::voidCallback): Deleted.
* wtf/glib/GMainLoopSource.h:

Tools:

* TestWebKitAPI/Tests/WTF/glib/GMainLoopSource.cpp:
(TestWebKitAPI::TEST): Remove DeleteOnDestroy unit tests.
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
(WebViewTest::wait): Use g_timeout_add instead of GMainLoopSource.

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

Source/WTF/ChangeLog
Source/WTF/wtf/glib/GMainLoopSource.cpp
Source/WTF/wtf/glib/GMainLoopSource.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/glib/GMainLoopSource.cpp
Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp

index 967c32f8af24199d488b74220cfcd4d550bda5ad..c8645d3db28c75937fbfe323c2dc6ce664862b47 100644 (file)
@@ -1,3 +1,23 @@
+2015-11-02  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GLIB] Remove delete on destroy GMainLoopSources
+        https://bugs.webkit.org/show_bug.cgi?id=150771
+
+        Reviewed by Žan Doberšek.
+
+        Delete on destroy sources made the GMainLoopSource implementation
+        more complex and they are currently unused.
+
+        * wtf/glib/GMainLoopSource.cpp:
+        (WTF::GMainLoopSource::boolCallback):
+        (WTF::GMainLoopSource::create): Deleted.
+        (WTF::GMainLoopSource::GMainLoopSource): Deleted.
+        (WTF::GMainLoopSource::cancel): Deleted.
+        (WTF::GMainLoopSource::scheduleAndDeleteOnDestroy): Deleted.
+        (WTF::GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy): Deleted.
+        (WTF::GMainLoopSource::voidCallback): Deleted.
+        * wtf/glib/GMainLoopSource.h:
+
 2015-11-01  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Use RunLoop in WorkQueue implementation
index 814c75506eab8dd6ac30b0ff8b9adfce1e42837a..50608b794a06a3ba685e09367aea626c6719a405 100644 (file)
 
 namespace WTF {
 
-GMainLoopSource& GMainLoopSource::create()
-{
-    return *new GMainLoopSource(DeleteOnDestroy);
-}
-
-GMainLoopSource::GMainLoopSource()
-    : m_deleteOnDestroy(DoNotDeleteOnDestroy)
-    , m_status(Ready)
-{
-}
-
-GMainLoopSource::GMainLoopSource(DeleteOnDestroyType deleteOnDestroy)
-    : m_deleteOnDestroy(deleteOnDestroy)
-    , m_status(Ready)
-{
-}
-
 GMainLoopSource::~GMainLoopSource()
 {
     cancel();
@@ -66,10 +49,6 @@ bool GMainLoopSource::isActive() const
 
 void GMainLoopSource::cancel()
 {
-    // Delete-on-destroy GMainLoopSource objects can't be cancelled.
-    if (m_deleteOnDestroy == DeleteOnDestroy)
-        return;
-
     // A valid context should only be present if GMainLoopSource is in the Scheduled or Dispatching state.
     ASSERT(!m_context.source || m_status == Scheduled || m_status == Dispatching);
 
@@ -297,46 +276,6 @@ void GMainLoopSource::scheduleAfterDelay(const char* name, std::function<bool ()
     scheduleTimeoutSource(name, reinterpret_cast<GSourceFunc>(boolSourceCallback), priority, context);
 }
 
-void GMainLoopSource::scheduleAndDeleteOnDestroy(const char* name, std::function<void()>&& function, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
-    create().schedule(name, WTF::move(function), priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAndDeleteOnDestroy(const char* name, std::function<bool()>&& function, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
-    create().schedule(name, WTF::move(function), priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&& function, std::chrono::milliseconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
-    create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&& function, std::chrono::milliseconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
-    create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&& function, std::chrono::seconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
-    create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&& function, std::chrono::seconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
-    create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&& function, std::chrono::microseconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
-    create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&& function, std::chrono::microseconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
-    create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
 bool GMainLoopSource::prepareVoidCallback(Context& context)
 {
     if (!m_context.source)
@@ -369,8 +308,6 @@ void GMainLoopSource::voidCallback()
     }
 
     context.destroySource();
-    if (m_deleteOnDestroy == DeleteOnDestroy)
-        delete this;
 }
 
 bool GMainLoopSource::prepareBoolCallback(Context& context)
@@ -408,11 +345,8 @@ bool GMainLoopSource::boolCallback()
         finishBoolCallback(retval, context);
     }
 
-    if (context.source) {
+    if (context.source)
         context.destroySource();
-        if (m_deleteOnDestroy == DeleteOnDestroy)
-            delete this;
-    }
 
     return retval;
 }
index da91908b86aa6e7312f15132565734f2ef852471..99642ee88939050b8a58d9b61a67a9b6b79c4fec 100644 (file)
@@ -41,7 +41,7 @@ class GMainLoopSource {
     WTF_MAKE_NONCOPYABLE(GMainLoopSource);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    WTF_EXPORT_PRIVATE GMainLoopSource();
+    WTF_EXPORT_PRIVATE GMainLoopSource() = default;
     WTF_EXPORT_PRIVATE virtual ~GMainLoopSource();
 
     static const bool Stop = false;
@@ -62,15 +62,6 @@ public:
 
     WTF_EXPORT_PRIVATE void schedule(const char* name, std::function<bool(GIOCondition)>&&, GSocket*, GIOCondition, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
 
-    static void scheduleAndDeleteOnDestroy(const char* name, std::function<void()>&&, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-    static void scheduleAndDeleteOnDestroy(const char* name, std::function<bool()>&&, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-    static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&&, std::chrono::milliseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-    static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&&, std::chrono::milliseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-    static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&&, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-    static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&&, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-    static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&&, std::chrono::microseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-    static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&&, std::chrono::microseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-
 protected:
     enum Status { Ready, Scheduled, Dispatching };
 
@@ -108,11 +99,6 @@ protected:
     virtual void finishBoolCallback(bool retval, Context&);
 
 private:
-    static GMainLoopSource& create();
-
-    enum DeleteOnDestroyType { DeleteOnDestroy, DoNotDeleteOnDestroy };
-    GMainLoopSource(DeleteOnDestroyType);
-
     void scheduleIdleSource(const char* name, GSourceFunc, int priority, GMainContext*);
     void scheduleTimeoutSource(const char* name, GSourceFunc, int priority, GMainContext*);
     bool socketCallback(GIOCondition);
@@ -121,11 +107,9 @@ private:
     static gboolean boolSourceCallback(GMainLoopSource*);
     static gboolean socketSourceCallback(GSocket*, GIOCondition, GMainLoopSource*);
 
-    DeleteOnDestroyType m_deleteOnDestroy;
-
 protected:
     Context m_context;
-    Status m_status;
+    Status m_status { Ready };
 };
 
 } // namespace WTF
index c4b853a6fcee4f05295a072ac60f44124293a54e..a71db77fa6e06c7460162790ab16cb2c177072bd 100644 (file)
@@ -1,3 +1,15 @@
+2015-11-02  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GLIB] Remove delete on destroy GMainLoopSources
+        https://bugs.webkit.org/show_bug.cgi?id=150771
+
+        Reviewed by Žan Doberšek.
+
+        * TestWebKitAPI/Tests/WTF/glib/GMainLoopSource.cpp:
+        (TestWebKitAPI::TEST): Remove DeleteOnDestroy unit tests.
+        * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
+        (WebViewTest::wait): Use g_timeout_add instead of GMainLoopSource.
+
 2015-11-01  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         [ES6] Support Generator Syntax
index 54991eeeb63904fa796e78b7dc5ddc107f31f388..276683c620644ad680dcc339473e6ec380c9cd42 100644 (file)
@@ -494,54 +494,4 @@ TEST(WTF_GMainLoopSource, DestroyCallbacksAfterReschedulingDuringDispatch)
     destroyCallbacksAfterReschedulingDuringDispatch<ThreadSafeTestingContext>();
 }
 
-TEST(WTF_GMainLoopSource, DeleteOnDestroySources)
-{
-    // Testing the delete-on-destroy sources is very limited. There's no good way
-    // of testing that the GMainLoopSource objects are deleted when their GSource
-    // is destroyed.
-
-    struct TestingContext {
-        GMainLoopSourceTest<GMainLoopSource> test;
-        unsigned callbackCallCount = 0;
-        bool destroyCallbackCalled = false;
-    } context;
-
-    {
-        TestingContext context;
-
-        GMainLoopSource::scheduleAndDeleteOnDestroy("[Test] DeleteOnDestroy",
-            [&] {
-                context.callbackCallCount++;
-            }, G_PRIORITY_DEFAULT,
-            [&] {
-                EXPECT_FALSE(context.destroyCallbackCalled);
-                context.destroyCallbackCalled = true;
-            });
-
-        context.test.delayedFinish();
-        context.test.runLoop();
-        EXPECT_EQ(1, context.callbackCallCount);
-        EXPECT_TRUE(context.destroyCallbackCalled);
-    }
-
-    {
-        TestingContext context;
-
-        GMainLoopSource::scheduleAndDeleteOnDestroy("[Test] DeleteOnDestroy",
-            std::function<bool ()>([&] {
-                context.callbackCallCount++;
-                return context.callbackCallCount != 3;
-            }), G_PRIORITY_DEFAULT,
-            [&] {
-                EXPECT_FALSE(context.destroyCallbackCalled);
-                context.destroyCallbackCalled = true;
-            });
-
-        context.test.delayedFinish();
-        context.test.runLoop();
-        EXPECT_EQ(3, context.callbackCallCount);
-        EXPECT_TRUE(context.destroyCallbackCalled);
-    }
-}
-
 } // namespace TestWebKitAPI
index 14f2c1466650e7684a6edc2bb4fe37cdf1b50f23..69e2ce704ef7d0c872edd0581ede7054346e32b1 100644 (file)
@@ -182,8 +182,10 @@ void WebViewTest::quitMainLoopAfterProcessingPendingEvents()
 
 void WebViewTest::wait(double seconds)
 {
-    GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy("WebViewTest wait", [this] { quitMainLoop(); },
-        std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>(seconds)));
+    g_timeout_add(seconds * 1000, [](gpointer userData) -> gboolean {
+        static_cast<WebViewTest*>(userData)->quitMainLoop();
+        return G_SOURCE_REMOVE;
+    }, this);
     g_main_loop_run(m_mainLoop);
 }