Title: [264586] trunk/Source
Revision
264586
Author
[email protected]
Date
2020-07-19 18:21:57 -0700 (Sun, 19 Jul 2020)

Log Message

There should be only one RunLoop Timer class
https://bugs.webkit.org/show_bug.cgi?id=214340

Reviewed by Darin Adler.

RunLoop::Timer wins. RunLoopTimer loses.

Source/WebCore:

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::DocumentLoader):
(WebCore::DocumentLoader::tryLoadingSubstituteData):
(WebCore::DocumentLoader::cancelMainResourceLoad):
(WebCore::DocumentLoader::startDataLoadTimer): Deleted. Use
RunLoop::dispatch instead of a timer because we have no need to control
the time period or to fire more than once. Use an explicit token so that
we can still cancel.

* loader/DocumentLoader.h:
(WebCore::DocumentLoader::DataLoadToken::clear): Added an explicit token
class to we can cancel a data load.

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::loadDataURL): page->scheduledRunLoopPairs()
is never null; and if it were null, data loads would always fail.

* platform/network/DataURLDecoder.cpp:
(WebCore::DataURLDecoder::decode):
(WebCore::DataURLDecoder::DecodingResultDispatcher::dispatch): Deleted.
(WebCore::DataURLDecoder::DecodingResultDispatcher::DecodingResultDispatcher): Deleted.
(WebCore::DataURLDecoder::DecodingResultDispatcher::startTimer): Deleted.
(WebCore::DataURLDecoder::DecodingResultDispatcher::timerFired): Deleted.
No need for two code paths, now that we can just call RunLoop::dispatch.

* platform/network/DataURLDecoder.h:

Source/WTF:

* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/PlatformHave.h:
* wtf/PlatformMac.cmake: Remove RunLoopTimer.

* wtf/RunLoop.cpp:
(WTF::RunLoop::dispatchAfter): While we're here. let's make dispatchAfter
available on all platforms. We had cross-platform code, but it was
factored to be needlessly platform-specific.

* wtf/RunLoop.h: Added a version of dispatch() that accepts a
SchedulePairHashSet for Cocoa. Removed some indirection from timer
stuff, since it was confusing me. Consistently named all time intervals
"interval".

* wtf/RunLoopTimer.h: Removed.

* wtf/cf/RunLoopCF.cpp:
(WTF::createTimer): Factored out a helper function for dispatch() to use.
(WTF::RunLoop::dispatch): This function is the meat of the patch. It's
the only unique functionality that RunLoopTimer used to provide.
(WTF::RunLoop::TimerBase::start): Adopted helper function.
(WTF::RunLoop::runForDuration): Deleted.
(WTF::RunLoop::TimerBase::timerFired): Deleted.

* wtf/cf/RunLoopTimerCF.cpp: Removed.

* wtf/generic/RunLoopGeneric.cpp:
(WTF::RunLoop::dispatchAfter): Deleted. Now cross-platform.

* wtf/glib/RunLoopGLib.cpp:
(WTF::RunLoop::TimerBase::updateReadyTime):
(WTF::RunLoop::TimerBase::start):
(WTF::RunLoop::TimerBase::stop):
(WTF::DispatchAfterContext::DispatchAfterContext): Deleted.
(WTF::DispatchAfterContext::dispatch): Deleted.
(WTF::RunLoop::dispatchAfter): Deleted. Now cross-platform.

* wtf/win/RunLoopWin.cpp:
(WTF::RunLoop::TimerBase::start):
(WTF::RunLoop::dispatchAfter): Deleted. Now cross-platform.

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (264585 => 264586)


--- trunk/Source/WTF/ChangeLog	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/ChangeLog	2020-07-20 01:21:57 UTC (rev 264586)
@@ -1,3 +1,54 @@
+2020-07-19  Geoffrey Garen  <[email protected]>
+
+        There should be only one RunLoop Timer class
+        https://bugs.webkit.org/show_bug.cgi?id=214340
+
+        Reviewed by Darin Adler.
+
+        RunLoop::Timer wins. RunLoopTimer loses.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        * wtf/PlatformHave.h:
+        * wtf/PlatformMac.cmake: Remove RunLoopTimer.
+
+        * wtf/RunLoop.cpp:
+        (WTF::RunLoop::dispatchAfter): While we're here. let's make dispatchAfter
+        available on all platforms. We had cross-platform code, but it was
+        factored to be needlessly platform-specific.
+
+        * wtf/RunLoop.h: Added a version of dispatch() that accepts a
+        SchedulePairHashSet for Cocoa. Removed some indirection from timer
+        stuff, since it was confusing me. Consistently named all time intervals
+        "interval".
+
+        * wtf/RunLoopTimer.h: Removed.
+
+        * wtf/cf/RunLoopCF.cpp:
+        (WTF::createTimer): Factored out a helper function for dispatch() to use.
+        (WTF::RunLoop::dispatch): This function is the meat of the patch. It's
+        the only unique functionality that RunLoopTimer used to provide.
+        (WTF::RunLoop::TimerBase::start): Adopted helper function.
+        (WTF::RunLoop::runForDuration): Deleted.
+        (WTF::RunLoop::TimerBase::timerFired): Deleted.
+
+        * wtf/cf/RunLoopTimerCF.cpp: Removed.
+
+        * wtf/generic/RunLoopGeneric.cpp:
+        (WTF::RunLoop::dispatchAfter): Deleted. Now cross-platform.
+
+        * wtf/glib/RunLoopGLib.cpp:
+        (WTF::RunLoop::TimerBase::updateReadyTime):
+        (WTF::RunLoop::TimerBase::start):
+        (WTF::RunLoop::TimerBase::stop):
+        (WTF::DispatchAfterContext::DispatchAfterContext): Deleted.
+        (WTF::DispatchAfterContext::dispatch): Deleted.
+        (WTF::RunLoop::dispatchAfter): Deleted. Now cross-platform.
+
+        * wtf/win/RunLoopWin.cpp:
+        (WTF::RunLoop::TimerBase::start):
+        (WTF::RunLoop::dispatchAfter): Deleted. Now cross-platform.
+
 2020-07-17  Sam Weinig  <[email protected]>
 
         Remove final vestigates of SimpleColor

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (264585 => 264586)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2020-07-20 01:21:57 UTC (rev 264586)
@@ -111,7 +111,6 @@
 		A3E4DD931F3A803400DED0B4 /* TextStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3E4DD911F3A803400DED0B4 /* TextStream.cpp */; };
 		A3EE5C3A21FFAC5F00FABD61 /* OSAllocatorPOSIX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3EE5C3921FFAC5E00FABD61 /* OSAllocatorPOSIX.cpp */; };
 		A3EE5C3D21FFAC7D00FABD61 /* SchedulePairCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3EE5C3B21FFAC7C00FABD61 /* SchedulePairCF.cpp */; };
-		A3EE5C3E21FFAC7D00FABD61 /* RunLoopTimerCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3EE5C3C21FFAC7D00FABD61 /* RunLoopTimerCF.cpp */; };
 		A3EE5C4021FFACA200FABD61 /* SchedulePairMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A3EE5C3F21FFACA200FABD61 /* SchedulePairMac.mm */; };
 		A5BA15F3182433A900A82E69 /* StringCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5BA15F2182433A900A82E69 /* StringCocoa.mm */; };
 		A5BA15F51824348000A82E69 /* StringImplCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5BA15F41824348000A82E69 /* StringImplCocoa.mm */; };
@@ -313,7 +312,6 @@
 		143F611E1565F0F900DB514A /* RAMSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAMSize.h; sourceTree = "<group>"; };
 		1447AEC518FCE57700B3D7FF /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
 		1447AECA18FCE5B900B3D7FF /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = /usr/lib/libicucore.dylib; sourceTree = "<absolute>"; };
-		1469419016EAAF6D0024E146 /* RunLoopTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RunLoopTimer.h; sourceTree = "<group>"; };
 		1469419416EAAFF80024E146 /* SchedulePair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SchedulePair.h; sourceTree = "<group>"; };
 		1469419A16EAB10A0024E146 /* AutodrainedPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutodrainedPool.h; sourceTree = "<group>"; };
 		1469419B16EAB10A0024E146 /* AutodrainedPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutodrainedPool.cpp; sourceTree = "<group>"; };
@@ -517,7 +515,6 @@
 		A3E4DD921F3A803400DED0B4 /* TextStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextStream.h; sourceTree = "<group>"; };
 		A3EE5C3921FFAC5E00FABD61 /* OSAllocatorPOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OSAllocatorPOSIX.cpp; sourceTree = "<group>"; };
 		A3EE5C3B21FFAC7C00FABD61 /* SchedulePairCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SchedulePairCF.cpp; sourceTree = "<group>"; };
-		A3EE5C3C21FFAC7D00FABD61 /* RunLoopTimerCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoopTimerCF.cpp; sourceTree = "<group>"; };
 		A3EE5C3F21FFACA200FABD61 /* SchedulePairMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SchedulePairMac.mm; sourceTree = "<group>"; };
 		A5098AFF1C169E0700087797 /* SandboxSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SandboxSPI.h; sourceTree = "<group>"; };
 		A5098B011C16A4F900087797 /* SecuritySPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecuritySPI.h; sourceTree = "<group>"; };
@@ -819,7 +816,6 @@
 				A331D95C21F249E4009F02AA /* FileSystemCF.cpp */,
 				C2BCFC411F61D61600C9222C /* LanguageCF.cpp */,
 				2CDED0EE18115C38004DBA70 /* RunLoopCF.cpp */,
-				A3EE5C3C21FFAC7D00FABD61 /* RunLoopTimerCF.cpp */,
 				A3EE5C3B21FFAC7C00FABD61 /* SchedulePairCF.cpp */,
 				1AFDE647195201C300C48FFA /* TypeCastsCF.h */,
 				5C1F0594216437B30039302C /* URLCF.cpp */,
@@ -1205,7 +1201,6 @@
 				A8A47305151A825B004123FF /* RetainPtr.h */,
 				2CDED0F118115C85004DBA70 /* RunLoop.cpp */,
 				2CDED0F218115C85004DBA70 /* RunLoop.h */,
-				1469419016EAAF6D0024E146 /* RunLoopTimer.h */,
 				14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */,
 				1469419416EAAFF80024E146 /* SchedulePair.h */,
 				1A3524AA1D63A2FF0031729B /* Scope.h */,
@@ -1724,7 +1719,6 @@
 				E392FA2722E92BFF00ECDC73 /* ResourceUsageCocoa.cpp in Sources */,
 				2CDED0F318115C85004DBA70 /* RunLoop.cpp in Sources */,
 				2CDED0EF18115C38004DBA70 /* RunLoopCF.cpp in Sources */,
-				A3EE5C3E21FFAC7D00FABD61 /* RunLoopTimerCF.cpp in Sources */,
 				1CA85CA9241B0B260071C2F5 /* RuntimeApplicationChecksCocoa.cpp in Sources */,
 				A3EE5C3D21FFAC7D00FABD61 /* SchedulePairCF.cpp in Sources */,
 				A3EE5C4021FFACA200FABD61 /* SchedulePairMac.mm in Sources */,

Modified: trunk/Source/WTF/wtf/CMakeLists.txt (264585 => 264586)


--- trunk/Source/WTF/wtf/CMakeLists.txt	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/CMakeLists.txt	2020-07-20 01:21:57 UTC (rev 264586)
@@ -213,7 +213,6 @@
     ResourceUsage.h
     RetainPtr.h
     RunLoop.h
-    RunLoopTimer.h
     SHA1.h
     SaturatedArithmetic.h
     SchedulePair.h

Modified: trunk/Source/WTF/wtf/PlatformHave.h (264585 => 264586)


--- trunk/Source/WTF/wtf/PlatformHave.h	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2020-07-20 01:21:57 UTC (rev 264586)
@@ -61,10 +61,6 @@
 #endif
 
 #if PLATFORM(MAC)
-#define HAVE_RUNLOOP_TIMER 1
-#endif
-
-#if PLATFORM(MAC)
 #define HAVE_SEC_KEYCHAIN 1
 #endif
 

Modified: trunk/Source/WTF/wtf/PlatformMac.cmake (264585 => 264586)


--- trunk/Source/WTF/wtf/PlatformMac.cmake	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/PlatformMac.cmake	2020-07-20 01:21:57 UTC (rev 264586)
@@ -51,7 +51,6 @@
     cf/FileSystemCF.cpp
     cf/LanguageCF.cpp
     cf/RunLoopCF.cpp
-    cf/RunLoopTimerCF.cpp
     cf/SchedulePairCF.cpp
     cf/URLCF.cpp
 

Modified: trunk/Source/WTF/wtf/RunLoop.cpp (264585 => 264586)


--- trunk/Source/WTF/wtf/RunLoop.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/RunLoop.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -141,6 +141,16 @@
         wakeUp();
 }
 
+void RunLoop::dispatchAfter(Seconds delay, Function<void()>&& function)
+{
+    auto timer = new DispatchTimer(*this);
+    timer->setFunction([timer, function = WTFMove(function)] {
+        function();
+        delete timer;
+    });
+    timer->startOneShot(delay);
+}
+
 void RunLoop::suspendFunctionDispatchForCurrentCycle()
 {
     // Don't suspend if there are already suspended functions to avoid unexecuted function pile-up.

Modified: trunk/Source/WTF/wtf/RunLoop.h (264585 => 264586)


--- trunk/Source/WTF/wtf/RunLoop.h	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/RunLoop.h	2020-07-20 01:21:57 UTC (rev 264586)
@@ -47,6 +47,12 @@
 
 namespace WTF {
 
+#if USE(COCOA_EVENT_LOOP)
+class SchedulePair;
+struct SchedulePairHash;
+using SchedulePairHashSet = HashSet<RefPtr<SchedulePair>, SchedulePairHash>;
+#endif
+
 #if USE(CF)
 using RunLoopMode = CFStringRef;
 #define DefaultRunLoopMode kCFRunLoopDefaultMode
@@ -73,7 +79,11 @@
     WTF_EXPORT_PRIVATE static bool isMain();
     ~RunLoop() final;
 
-    WTF_EXPORT_PRIVATE void dispatch(Function<void()>&&) final;
+    WTF_EXPORT_PRIVATE void dispatch(Function<void()>&&);
+    WTF_EXPORT_PRIVATE void dispatchAfter(Seconds, Function<void()>&&);
+#if USE(COCOA_EVENT_LOOP)
+    WTF_EXPORT_PRIVATE static void dispatch(const SchedulePairHashSet&, Function<void()>&&);
+#endif
 
     WTF_EXPORT_PRIVATE static void run();
     WTF_EXPORT_PRIVATE void stop();
@@ -84,10 +94,6 @@
     enum class CycleResult { Continue, Stop };
     WTF_EXPORT_PRIVATE CycleResult static cycle(RunLoopMode = DefaultRunLoopMode);
 
-#if USE(COCOA_EVENT_LOOP)
-    WTF_EXPORT_PRIVATE void runForDuration(Seconds duration);
-#endif
-
 #if USE(GLIB_EVENT_LOOP)
     WTF_EXPORT_PRIVATE GMainContext* mainContext() const { return m_mainContext.get(); }
 #endif
@@ -102,10 +108,6 @@
     static void registerRunLoopMessageWindowClass();
 #endif
 
-#if !USE(COCOA_EVENT_LOOP)
-    WTF_EXPORT_PRIVATE void dispatchAfter(Seconds, Function<void()>&&);
-#endif
-
     class TimerBase {
         WTF_MAKE_FAST_ALLOCATED;
         friend class RunLoop;
@@ -113,8 +115,8 @@
         WTF_EXPORT_PRIVATE explicit TimerBase(RunLoop&);
         WTF_EXPORT_PRIVATE virtual ~TimerBase();
 
-        void startRepeating(Seconds repeatInterval) { startInternal(repeatInterval, true); }
-        void startOneShot(Seconds interval) { startInternal(interval, false); }
+        void startRepeating(Seconds interval) { start(std::max(interval, 0_s), true); }
+        void startOneShot(Seconds interval) { start(std::max(interval, 0_s), false); }
 
         WTF_EXPORT_PRIVATE void stop();
         WTF_EXPORT_PRIVATE bool isActive() const;
@@ -128,13 +130,8 @@
 #endif
 
     private:
-        void startInternal(Seconds nextFireInterval, bool repeat)
-        {
-            start(std::max(nextFireInterval, 0_s), repeat);
-        }
+        WTF_EXPORT_PRIVATE void start(Seconds interval, bool repeat);
 
-        WTF_EXPORT_PRIVATE void start(Seconds nextFireInterval, bool repeat);
-
         Ref<RunLoop> m_runLoop;
 
 #if USE(WINDOWS_EVENT_LOOP)
@@ -145,13 +142,12 @@
         bool m_isRepeating { false };
         bool m_isActive { false };
 #elif USE(COCOA_EVENT_LOOP)
-        static void timerFired(CFRunLoopTimerRef, void*);
         RetainPtr<CFRunLoopTimerRef> m_timer;
 #elif USE(GLIB_EVENT_LOOP)
         void updateReadyTime();
         GRefPtr<GSource> m_source;
         bool m_isRepeating { false };
-        Seconds m_fireInterval { 0 };
+        Seconds m_interval { 0 };
 #elif USE(GENERIC_EVENT_LOOP)
         bool isActive(const AbstractLocker&) const;
         void stop(const AbstractLocker&);
@@ -182,7 +178,9 @@
         TimerFiredClass* m_object;
     };
 
-#if USE(WINDOWS_EVENT_LOOP)
+private:
+    class Holder;
+
     class DispatchTimer final : public TimerBase {
     public:
         DispatchTimer(RunLoop& runLoop)
@@ -199,11 +197,7 @@
 
         Function<void()> m_function;
     };
-#endif
 
-    class Holder;
-
-private:
     RunLoop();
 
     void performWork();

Deleted: trunk/Source/WTF/wtf/RunLoopTimer.h (264585 => 264586)


--- trunk/Source/WTF/wtf/RunLoopTimer.h	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/RunLoopTimer.h	2020-07-20 01:21:57 UTC (rev 264586)
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <wtf/SchedulePair.h>
-#include <wtf/Seconds.h>
-
-#if USE(CF)
-#include <wtf/RetainPtr.h>
-#endif
-
-namespace WTF {
-
-// Time intervals are all in seconds.
-
-class RunLoopTimerBase {
-    WTF_MAKE_NONCOPYABLE(RunLoopTimerBase);
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    WTF_EXPORT_PRIVATE RunLoopTimerBase();
-    WTF_EXPORT_PRIVATE virtual ~RunLoopTimerBase();
-
-    WTF_EXPORT_PRIVATE void schedule(const SchedulePair*);
-    WTF_EXPORT_PRIVATE void schedule(const SchedulePairHashSet&);
-
-    WTF_EXPORT_PRIVATE void start(Seconds nextFireInterval, Seconds repeatInterval);
-
-    void startRepeating(Seconds repeatInterval) { start(repeatInterval, repeatInterval); }
-    void startOneShot(Seconds interval) { start(interval, 0_s); }
-
-    WTF_EXPORT_PRIVATE void stop();
-    bool isActive() const;
-
-    virtual void fired() = 0;
-
-private:
-#if USE(CF)
-    RetainPtr<CFRunLoopTimerRef> m_timer;
-#endif
-};
-
-// FIXME: This doesn't have to be a class template.
-template <typename TimerFiredClass> class RunLoopTimer : public RunLoopTimerBase {
-public:
-    typedef void (TimerFiredClass::*TimerFiredFunction)();
-
-    RunLoopTimer(TimerFiredClass& o, TimerFiredFunction f)
-        : m_object(&o), m_function(f) { }
-
-    virtual void fired() { (m_object->*m_function)(); }
-
-private:
-    TimerFiredClass* m_object;
-    TimerFiredFunction m_function;
-};
-
-} // namespace WTF
-
-using WTF::RunLoopTimer;

Modified: trunk/Source/WTF/wtf/cf/RunLoopCF.cpp (264585 => 264586)


--- trunk/Source/WTF/wtf/cf/RunLoopCF.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/cf/RunLoopCF.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -29,9 +29,17 @@
 #include <CoreFoundation/CoreFoundation.h>
 #include <dispatch/dispatch.h>
 #include <wtf/AutodrainedPool.h>
+#include <wtf/SchedulePair.h>
 
 namespace WTF {
 
+static RetainPtr<CFRunLoopTimerRef> createTimer(Seconds interval, bool repeat, void(*timerFired)(CFRunLoopTimerRef, void*), void* info)
+{
+    CFRunLoopTimerContext context = { 0, info, 0, 0, 0 };
+    Seconds repeatInterval = repeat ? interval : 0_s;
+    return adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + interval.seconds(), repeatInterval.seconds(), 0, 0, timerFired, &context));
+}
+
 void RunLoop::performWork(void* context)
 {
     AutodrainedPool pool;
@@ -51,11 +59,6 @@
     CFRunLoopSourceInvalidate(m_runLoopSource.get());
 }
 
-void RunLoop::runForDuration(Seconds duration)
-{
-    CFRunLoopRunInMode(kCFRunLoopDefaultMode, duration.seconds(), true);
-}
-
 void RunLoop::wakeUp()
 {
     CFRunLoopSourceSignal(m_runLoopSource.get());
@@ -81,20 +84,23 @@
     CFRunLoopStop(m_runLoop.get());
 }
 
-// RunLoop::Timer
-
-void RunLoop::TimerBase::timerFired(CFRunLoopTimerRef cfTimer, void* context)
+void RunLoop::dispatch(const SchedulePairHashSet& schedulePairs, Function<void()>&& function)
 {
-    TimerBase* timer = static_cast<TimerBase*>(context);
+    auto timer = createTimer(0_s, false, [] (CFRunLoopTimerRef timer, void* context) {
+        AutodrainedPool pool;
 
-    AutodrainedPool pool;
+        CFRunLoopTimerInvalidate(timer);
 
-    if (!CFRunLoopTimerDoesRepeat(cfTimer))
-        timer->stop();
+        Function<void()> function(static_cast<Function<void()>::Impl*>(context));
+        function();
+    }, function.leakImpl());
 
-    timer->fired();
+    for (auto& schedulePair : schedulePairs)
+        CFRunLoopAddTimer(schedulePair->runLoop(), timer.get(), schedulePair->mode());
 }
 
+// RunLoop::Timer
+
 RunLoop::TimerBase::TimerBase(RunLoop& runLoop)
     : m_runLoop(runLoop)
 {
@@ -105,14 +111,20 @@
     stop();
 }
 
-void RunLoop::TimerBase::start(Seconds nextFireInterval, bool repeat)
+void RunLoop::TimerBase::start(Seconds interval, bool repeat)
 {
     if (m_timer)
         stop();
-    
-    CFRunLoopTimerContext context = { 0, this, 0, 0, 0 };
-    Seconds repeatInterval = repeat ? nextFireInterval : 0_s;
-    m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + nextFireInterval.seconds(), repeatInterval.seconds(), 0, 0, timerFired, &context));
+
+    m_timer = createTimer(interval, repeat, [] (CFRunLoopTimerRef cfTimer, void* context) {
+        AutodrainedPool pool;
+
+        auto timer = static_cast<TimerBase*>(context);
+        if (!CFRunLoopTimerDoesRepeat(cfTimer))
+            timer->stop();
+
+        timer->fired();
+    }, this);
     CFRunLoopAddTimer(m_runLoop->m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
 }
 

Deleted: trunk/Source/WTF/wtf/cf/RunLoopTimerCF.cpp (264585 => 264586)


--- trunk/Source/WTF/wtf/cf/RunLoopTimerCF.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/cf/RunLoopTimerCF.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if PLATFORM(COCOA) && HAVE(RUNLOOP_TIMER)
-
-#include <wtf/RunLoopTimer.h>
-
-#include <wtf/AutodrainedPool.h>
-
-namespace WTF {
-
-RunLoopTimerBase::RunLoopTimerBase() = default;
-
-RunLoopTimerBase::~RunLoopTimerBase()
-{
-    stop();
-}
-
-static void timerFired(CFRunLoopTimerRef, void* context)
-{
-    // CFRunLoopTimer does not create an NSAutoreleasePool, like NSTimer does. This can lead to
-    // autoreleased objects being pushed into NSAutoreleasePools underneath the run loop, which
-    // are very infrequently drained. Create a new autorelease pool here to give autoreleased objects
-    // a place to collect.
-    AutodrainedPool pool;
-    RunLoopTimerBase* timer = static_cast<RunLoopTimerBase*>(context);
-    timer->fired();
-}
-
-void RunLoopTimerBase::start(Seconds nextFireInterval, Seconds repeatInterval)
-{
-    if (m_timer)
-        CFRunLoopTimerInvalidate(m_timer.get());
-    CFRunLoopTimerContext context = { 0, this, 0, 0, 0 };
-    m_timer = adoptCF(CFRunLoopTimerCreate(0, CFAbsoluteTimeGetCurrent() + nextFireInterval.seconds(), repeatInterval.seconds(), 0, 0, timerFired, &context));
-}
-
-void RunLoopTimerBase::schedule(const SchedulePair* schedulePair)
-{
-    ASSERT_ARG(schedulePair, schedulePair);
-    ASSERT_WITH_MESSAGE(m_timer, "Timer must have one of the start functions called before calling schedule().");
-    CFRunLoopAddTimer(schedulePair->runLoop(), m_timer.get(), schedulePair->mode());
-}
-
-void RunLoopTimerBase::schedule(const SchedulePairHashSet& schedulePairs)
-{
-    SchedulePairHashSet::const_iterator end = schedulePairs.end();
-    for (SchedulePairHashSet::const_iterator it = schedulePairs.begin(); it != end; ++it)
-        schedule((*it).get());
-}
-
-void RunLoopTimerBase::stop()
-{
-    if (!m_timer)
-        return;
-    CFRunLoopTimerInvalidate(m_timer.get());
-    m_timer = 0;
-}
-
-bool RunLoopTimerBase::isActive() const
-{
-    return m_timer && CFRunLoopTimerIsValid(m_timer.get());
-}
-
-} // namespace WTF
-
-#endif // PLATFORM(COCOA) && HAVE(RUNLOOP_TIMER)

Modified: trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp (264585 => 264586)


--- trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -250,14 +250,6 @@
     wakeUp(locker);
 }
 
-void RunLoop::dispatchAfter(Seconds delay, Function<void()>&& function)
-{
-    LockHolder locker(m_loopLock);
-    bool repeating = false;
-    schedule(locker, TimerBase::ScheduledTask::create(WTFMove(function), delay, repeating));
-    wakeUp(locker);
-}
-
 // Since RunLoop does not own the registered TimerBase,
 // TimerBase and its owner should manage these lifetime.
 RunLoop::TimerBase::TimerBase(RunLoop& runLoop)

Modified: trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp (264585 => 264586)


--- trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -129,39 +129,6 @@
     return CycleResult::Continue;
 }
 
-class DispatchAfterContext {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    DispatchAfterContext(Function<void()>&& function)
-        : m_function(WTFMove(function))
-    {
-    }
-
-    void dispatch()
-    {
-        m_function();
-    }
-
-private:
-    Function<void()> m_function;
-};
-
-void RunLoop::dispatchAfter(Seconds duration, Function<void()>&& function)
-{
-    GRefPtr<GSource> source = adoptGRef(g_source_new(&runLoopSourceFunctions, sizeof(GSource)));
-    g_source_set_priority(source.get(), RunLoopSourcePriority::RunLoopTimer);
-    g_source_set_name(source.get(), "[WebKit] RunLoop dispatchAfter");
-    g_source_set_ready_time(source.get(), g_get_monotonic_time() + duration.microsecondsAs<gint64>());
-
-    std::unique_ptr<DispatchAfterContext> context = makeUnique<DispatchAfterContext>(WTFMove(function));
-    g_source_set_callback(source.get(), [](gpointer userData) -> gboolean {
-        std::unique_ptr<DispatchAfterContext> context(static_cast<DispatchAfterContext*>(userData));
-        context->dispatch();
-        return G_SOURCE_REMOVE;
-    }, context.release(), nullptr);
-    g_source_attach(source.get(), m_mainContext.get());
-}
-
 RunLoop::TimerBase::TimerBase(RunLoop& runLoop)
     : m_runLoop(runLoop)
     , m_source(adoptGRef(g_source_new(&runLoopSourceFunctions, sizeof(GSource))))
@@ -201,20 +168,20 @@
 
 void RunLoop::TimerBase::updateReadyTime()
 {
-    if (!m_fireInterval) {
+    if (!m_interval) {
         g_source_set_ready_time(m_source.get(), 0);
         return;
     }
 
     gint64 currentTime = g_get_monotonic_time();
-    gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, m_fireInterval.microsecondsAs<gint64>());
+    gint64 targetTime = currentTime + std::min<gint64>(G_MAXINT64 - currentTime, m_interval.microsecondsAs<gint64>());
     ASSERT(targetTime >= currentTime);
     g_source_set_ready_time(m_source.get(), targetTime);
 }
 
-void RunLoop::TimerBase::start(Seconds fireInterval, bool repeat)
+void RunLoop::TimerBase::start(Seconds interval, bool repeat)
 {
-    m_fireInterval = fireInterval;
+    m_interval = interval;
     m_isRepeating = repeat;
     updateReadyTime();
 }
@@ -222,7 +189,7 @@
 void RunLoop::TimerBase::stop()
 {
     g_source_set_ready_time(m_source.get(), -1);
-    m_fireInterval = { };
+    m_interval = { };
     m_isRepeating = false;
 }
 

Modified: trunk/Source/WTF/wtf/win/RunLoopWin.cpp (264585 => 264586)


--- trunk/Source/WTF/wtf/win/RunLoopWin.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WTF/wtf/win/RunLoopWin.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -140,16 +140,6 @@
     return CycleResult::Continue;
 }
 
-void RunLoop::dispatchAfter(Seconds delay, Function<void()>&& function)
-{
-    auto timer = new DispatchTimer(*this);
-    timer->setFunction([timer, function = WTFMove(function)] {
-        function();
-        delete timer;
-    });
-    timer->startOneShot(delay);
-}
-
 // RunLoop::Timer
 
 void RunLoop::TimerBase::timerFired()
@@ -180,14 +170,14 @@
     stop();
 }
 
-void RunLoop::TimerBase::start(Seconds nextFireInterval, bool repeat)
+void RunLoop::TimerBase::start(Seconds interval, bool repeat)
 {
     LockHolder locker(m_runLoop->m_loopLock);
     m_isRepeating = repeat;
     m_isActive = true;
-    m_interval = nextFireInterval;
+    m_interval = interval;
     m_nextFireDate = MonotonicTime::now() + m_interval;
-    ::SetTimer(m_runLoop->m_runLoopMessageWindow, bitwise_cast<uintptr_t>(this), nextFireInterval.millisecondsAs<UINT>(), nullptr);
+    ::SetTimer(m_runLoop->m_runLoopMessageWindow, bitwise_cast<uintptr_t>(this), interval.millisecondsAs<UINT>(), nullptr);
 }
 
 void RunLoop::TimerBase::stop()

Modified: trunk/Source/WebCore/ChangeLog (264585 => 264586)


--- trunk/Source/WebCore/ChangeLog	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WebCore/ChangeLog	2020-07-20 01:21:57 UTC (rev 264586)
@@ -1,3 +1,39 @@
+2020-07-19  Geoffrey Garen  <[email protected]>
+
+        There should be only one RunLoop Timer class
+        https://bugs.webkit.org/show_bug.cgi?id=214340
+
+        Reviewed by Darin Adler.
+
+        RunLoop::Timer wins. RunLoopTimer loses.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::DocumentLoader):
+        (WebCore::DocumentLoader::tryLoadingSubstituteData):
+        (WebCore::DocumentLoader::cancelMainResourceLoad):
+        (WebCore::DocumentLoader::startDataLoadTimer): Deleted. Use
+        RunLoop::dispatch instead of a timer because we have no need to control
+        the time period or to fire more than once. Use an explicit token so that
+        we can still cancel.
+
+        * loader/DocumentLoader.h:
+        (WebCore::DocumentLoader::DataLoadToken::clear): Added an explicit token
+        class to we can cancel a data load.
+
+        * loader/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::loadDataURL): page->scheduledRunLoopPairs()
+        is never null; and if it were null, data loads would always fail.
+
+        * platform/network/DataURLDecoder.cpp:
+        (WebCore::DataURLDecoder::decode):
+        (WebCore::DataURLDecoder::DecodingResultDispatcher::dispatch): Deleted.
+        (WebCore::DataURLDecoder::DecodingResultDispatcher::DecodingResultDispatcher): Deleted.
+        (WebCore::DataURLDecoder::DecodingResultDispatcher::startTimer): Deleted.
+        (WebCore::DataURLDecoder::DecodingResultDispatcher::timerFired): Deleted.
+        No need for two code paths, now that we can just call RunLoop::dispatch.
+
+        * platform/network/DataURLDecoder.h:
+
 2020-07-19  Sam Weinig  <[email protected]>
 
         Rename Color::transparent to Color::transparentBlack to more clearly state what it is

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (264585 => 264586)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -153,7 +153,6 @@
     , m_request(request)
     , m_originalSubstituteDataWasValid(substituteData.isValid())
     , m_substituteResourceDeliveryTimer(*this, &DocumentLoader::substituteResourceDeliveryTimerFired)
-    , m_dataLoadTimer(*this, &DocumentLoader::handleSubstituteDataLoadNow)
     , m_applicationCacheHost(makeUnique<ApplicationCacheHost>(*this))
 {
 }
@@ -492,16 +491,6 @@
     responseReceived(response, nullptr);
 }
 
-void DocumentLoader::startDataLoadTimer()
-{
-    m_dataLoadTimer.startOneShot(0_s);
-
-#if HAVE(RUNLOOP_TIMER)
-    if (SchedulePairHashSet* scheduledPairs = m_frame->page()->scheduledRunLoopPairs())
-        m_dataLoadTimer.schedule(*scheduledPairs);
-#endif
-}
-
 #if ENABLE(SERVICE_WORKER)
 bool DocumentLoader::setControllingServiceWorkerRegistration(ServiceWorkerRegistrationData&& data)
 {
@@ -711,9 +700,21 @@
 
     if (!m_deferMainResourceDataLoad || frameLoader()->loadsSynchronously())
         handleSubstituteDataLoadNow();
-    else
-        startDataLoadTimer();
+    else {
+        auto loadData = [this, weakDataLoadToken = makeWeakPtr(m_dataLoadToken)] {
+            if (!weakDataLoadToken)
+                return;
+            m_dataLoadToken.clear();
+            handleSubstituteDataLoadNow();
+        };
 
+#if USE(COCOA_EVENT_LOOP)
+        RunLoop::dispatch(*m_frame->page()->scheduledRunLoopPairs(), WTFMove(loadData));
+#else
+        RunLoop::current().dispatch(WTFMove(loadData));
+#endif
+    }
+
     return true;
 }
 
@@ -2005,7 +2006,7 @@
 
     RELEASE_LOG_IF_ALLOWED("cancelMainResourceLoad: (type = %d, code = %d)", static_cast<int>(error.type()), error.errorCode());
 
-    m_dataLoadTimer.stop();
+    m_dataLoadToken.clear();
 
     cancelPolicyCheckIfNeeded();
 

Modified: trunk/Source/WebCore/loader/DocumentLoader.h (264585 => 264586)


--- trunk/Source/WebCore/loader/DocumentLoader.h	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WebCore/loader/DocumentLoader.h	2020-07-20 01:21:57 UTC (rev 264586)
@@ -59,10 +59,6 @@
 #include "ApplicationManifest.h"
 #endif
 
-#if HAVE(RUNLOOP_TIMER)
-#include <wtf/RunLoopTimer.h>
-#endif
-
 #if PLATFORM(COCOA)
 #include <wtf/SchedulePair.h>
 #endif
@@ -429,6 +425,11 @@
     bool m_deferMainResourceDataLoad { true };
 
 private:
+    class DataLoadToken : public CanMakeWeakPtr<DataLoadToken> {
+    public:
+        void clear() { weakPtrFactory().revokeAll(); }
+    };
+
     Document* document() const;
 
 #if ENABLE(SERVICE_WORKER)
@@ -489,13 +490,7 @@
     void stopLoadingForPolicyChange();
     ResourceError interruptedForPolicyChangeError() const;
 
-#if HAVE(RUNLOOP_TIMER)
-    typedef RunLoopTimer<DocumentLoader> DocumentLoaderTimer;
-#else
-    typedef Timer DocumentLoaderTimer;
-#endif
     void handleSubstituteDataLoadNow();
-    void startDataLoadTimer();
 
     void deliverSubstituteResourcesAfterDelay();
     void substituteResourceDeliveryTimerFired();
@@ -600,7 +595,7 @@
     MonotonicTime m_timeOfLastDataReceived;
     unsigned long m_identifierForLoadWithoutResourceLoader { 0 };
 
-    DocumentLoaderTimer m_dataLoadTimer;
+    DataLoadToken m_dataLoadToken;
     bool m_waitingForContentPolicy { false };
     bool m_waitingForNavigationPolicy { false };
 

Modified: trunk/Source/WebCore/loader/ResourceLoader.cpp (264585 => 264586)


--- trunk/Source/WebCore/loader/ResourceLoader.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WebCore/loader/ResourceLoader.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -266,11 +266,9 @@
     ASSERT(url.protocolIsData());
 
     DataURLDecoder::ScheduleContext scheduleContext;
-#if HAVE(RUNLOOP_TIMER)
-    if (auto page = m_frame->page()) {
-        if (auto scheduledPairs = page->scheduledRunLoopPairs())
-            scheduleContext.scheduledPairs = *scheduledPairs;
-    }
+#if USE(COCOA_EVENT_LOOP)
+    if (auto page = m_frame->page())
+        scheduleContext.scheduledPairs = *page->scheduledRunLoopPairs();
 #endif
     auto mode = DataURLDecoder::Mode::Legacy;
     if (m_request.requester() == ResourceRequest::Requester::Fetch)

Modified: trunk/Source/WebCore/platform/network/DataURLDecoder.cpp (264585 => 264586)


--- trunk/Source/WebCore/platform/network/DataURLDecoder.cpp	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WebCore/platform/network/DataURLDecoder.cpp	2020-07-20 01:21:57 UTC (rev 264586)
@@ -97,52 +97,6 @@
     Result result;
 };
 
-#if HAVE(RUNLOOP_TIMER)
-
-class DecodingResultDispatcher : public ThreadSafeRefCounted<DecodingResultDispatcher> {
-public:
-    static void dispatch(std::unique_ptr<DecodeTask> decodeTask)
-    {
-        Ref<DecodingResultDispatcher> dispatcher = adoptRef(*new DecodingResultDispatcher(WTFMove(decodeTask)));
-        dispatcher->startTimer();
-    }
-
-private:
-    DecodingResultDispatcher(std::unique_ptr<DecodeTask> decodeTask)
-        : m_timer(*this, &DecodingResultDispatcher::timerFired)
-        , m_decodeTask(WTFMove(decodeTask))
-    {
-    }
-
-    void startTimer()
-    {
-        // Keep alive until the timer has fired.
-        ref();
-
-        auto scheduledPairs = m_decodeTask->scheduleContext.scheduledPairs;
-        m_timer.startOneShot(0_s);
-        m_timer.schedule(scheduledPairs);
-    }
-
-    void timerFired()
-    {
-        if (m_decodeTask->result.data)
-            m_decodeTask->completionHandler(WTFMove(m_decodeTask->result));
-        else
-            m_decodeTask->completionHandler({ });
-
-        // Ensure DecodeTask gets deleted in the main thread.
-        m_decodeTask = nullptr;
-
-        deref();
-    }
-
-    RunLoopTimer<DecodingResultDispatcher> m_timer;
-    std::unique_ptr<DecodeTask> m_decodeTask;
-};
-
-#endif // HAVE(RUNLOOP_TIMER)
-
 static std::unique_ptr<DecodeTask> createDecodeTask(const URL& url, const ScheduleContext& scheduleContext, DecodeCompletionHandler&& completionHandler)
 {
     return makeUnique<DecodeTask>(
@@ -194,16 +148,22 @@
                 decodeEscaped(*decodeTask);
         }
 
-#if HAVE(RUNLOOP_TIMER)
-        DecodingResultDispatcher::dispatch(WTFMove(decodeTask));
-#else
-        callOnMainThread([decodeTask = WTFMove(decodeTask)] {
+#if USE(COCOA_EVENT_LOOP)
+        auto scheduledPairs = decodeTask->scheduleContext.scheduledPairs;
+#endif
+
+        auto callCompletionHandler = [decodeTask = WTFMove(decodeTask)] {
             if (!decodeTask->result.data) {
                 decodeTask->completionHandler({ });
                 return;
             }
             decodeTask->completionHandler(WTFMove(decodeTask->result));
-        });
+        };
+
+#if USE(COCOA_EVENT_LOOP)
+        RunLoop::dispatch(scheduledPairs, WTFMove(callCompletionHandler));
+#else
+        RunLoop::main().dispatch(WTFMove(callCompletionHandler));
 #endif
     });
 }

Modified: trunk/Source/WebCore/platform/network/DataURLDecoder.h (264585 => 264586)


--- trunk/Source/WebCore/platform/network/DataURLDecoder.h	2020-07-19 22:39:50 UTC (rev 264585)
+++ trunk/Source/WebCore/platform/network/DataURLDecoder.h	2020-07-20 01:21:57 UTC (rev 264586)
@@ -27,8 +27,8 @@
 
 #include <wtf/text/WTFString.h>
 
-#if HAVE(RUNLOOP_TIMER)
-#include <wtf/RunLoopTimer.h>
+#if USE(COCOA_EVENT_LOOP)
+#include <wtf/SchedulePair.h>
 #endif
 
 namespace WebCore {
@@ -46,7 +46,7 @@
 
 using DecodeCompletionHandler = WTF::Function<void (Optional<Result>)>;
 struct ScheduleContext {
-#if HAVE(RUNLOOP_TIMER)
+#if USE(COCOA_EVENT_LOOP)
     SchedulePairHashSet scheduledPairs;
 #endif
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to