Make every port implement MainThreadSharedTimer instead of using global functions
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 13:25:26 +0000 (13:25 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 13:25:26 +0000 (13:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150498

Reviewed by Darin Adler.

Move MainThreadSharedTimer to its own files and add the common
implementation there.

* CMakeLists.txt: Add MainThreadSharedTimer.cpp.
* PlatformEfl.cmake: Update filenames.
* PlatformGTK.cmake: Ditto.
* PlatformMac.cmake: Ditto.
* PlatformWin.cmake: Ditto.
* platform/MainThreadSharedTimer.cpp: Copied from Source/WebCore/platform/efl/SharedTimerEfl.cpp.
(WebCore::MainThreadSharedTimer::singleton):
(WebCore::MainThreadSharedTimer::MainThreadSharedTimer):
(WebCore::MainThreadSharedTimer::setFiredFunction):
(WebCore::MainThreadSharedTimer::fired):
* platform/MainThreadSharedTimer.h: Copied from Source/WebCore/platform/gtk/SharedTimerGtk.cpp.
* platform/SharedTimer.h: Remove MainThreadSharedTimer
implementation and reindent the code.
(WebCore::SharedTimer::SharedTimer):
(WebCore::SharedTimer::~SharedTimer):
(WebCore::SharedTimer::invalidate):
* platform/ThreadTimers.cpp:
(WebCore::ThreadTimers::ThreadTimers): Use MainThreadSharedTimer::singleton().
(WebCore::ThreadTimers::setSharedTimer): Use a lambda function
instead of a pointer to a static method.
(WebCore::ThreadTimers::sharedTimerFired): Deleted.
* platform/ThreadTimers.h: Removed unsused static method sharedTimerFired.
* platform/cf/MainThreadSharedTimerCF.cpp: Renamed from Source/WebCore/platform/cf/SharedTimerCF.cpp.
(WebCore::applicationDidBecomeActive):
(WebCore::setupPowerObserver):
(WebCore::timerFired):
(WebCore::restartSharedTimer):
(WebCore::MainThreadSharedTimer::invalidate):
(WebCore::MainThreadSharedTimer::setFireInterval):
(WebCore::MainThreadSharedTimer::stop):
* platform/efl/MainThreadSharedTimerEfl.cpp: Renamed from Source/WebCore/platform/efl/SharedTimerEfl.cpp.
(WebCore::timerEvent):
(WebCore::MainThreadSharedTimer::stop):
(WebCore::MainThreadSharedTimer::setFireInterval):
(WebCore::MainThreadSharedTimer::invalidate):
* platform/gtk/MainThreadSharedTimerGtk.cpp: Renamed from Source/WebCore/platform/gtk/SharedTimerGtk.cpp.
(WebCore::MainThreadSharedTimer::setFireInterval):
(WebCore::MainThreadSharedTimer::stop):
(WebCore::MainThreadSharedTimer::invalidate):
* platform/win/MainThreadSharedTimerWin.cpp: Renamed from Source/WebCore/platform/win/SharedTimerWin.cpp.
(WebCore::TimerWindowWndProc):
(WebCore::initializeOffScreenTimerWindow):
(WebCore::queueTimerProc):
(WebCore::MainThreadSharedTimer::setFireInterval):
(WebCore::MainThreadSharedTimer::stop):
(WebCore::MainThreadSharedTimer::invalidate):
* workers/WorkerRunLoop.cpp: Update WorkerSharedTimer
implementation to use std::function instead of a pointer. Also
mark the class as final and the virtual implementations as override.

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

17 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/PlatformEfl.cmake
Source/WebCore/PlatformGTK.cmake
Source/WebCore/PlatformMac.cmake
Source/WebCore/PlatformWin.cmake
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/MainThreadSharedTimer.cpp [new file with mode: 0644]
Source/WebCore/platform/MainThreadSharedTimer.h [new file with mode: 0644]
Source/WebCore/platform/SharedTimer.h
Source/WebCore/platform/ThreadTimers.cpp
Source/WebCore/platform/ThreadTimers.h
Source/WebCore/platform/cf/MainThreadSharedTimerCF.cpp [moved from Source/WebCore/platform/cf/SharedTimerCF.cpp with 89% similarity]
Source/WebCore/platform/efl/MainThreadSharedTimerEfl.cpp [moved from Source/WebCore/platform/efl/SharedTimerEfl.cpp with 74% similarity]
Source/WebCore/platform/gtk/MainThreadSharedTimerGtk.cpp [moved from Source/WebCore/platform/gtk/SharedTimerGtk.cpp with 82% similarity]
Source/WebCore/platform/win/MainThreadSharedTimerWin.cpp [moved from Source/WebCore/platform/win/SharedTimerWin.cpp with 93% similarity]
Source/WebCore/workers/WorkerRunLoop.cpp

index 700fbb7..6b9ae21 100644 (file)
@@ -2110,6 +2110,7 @@ set(WebCore_SOURCES
     platform/LinkHash.cpp
     platform/Logging.cpp
     platform/MIMETypeRegistry.cpp
+    platform/MainThreadSharedTimer.cpp
     platform/MemoryPressureHandler.cpp
     platform/NotImplemented.cpp
     platform/PlatformEvent.cpp
index 8343593..b194293 100644 (file)
@@ -1,5 +1,65 @@
 2015-10-30  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        Make every port implement MainThreadSharedTimer instead of using global functions
+        https://bugs.webkit.org/show_bug.cgi?id=150498
+
+        Reviewed by Darin Adler.
+
+        Move MainThreadSharedTimer to its own files and add the common
+        implementation there.
+
+        * CMakeLists.txt: Add MainThreadSharedTimer.cpp.
+        * PlatformEfl.cmake: Update filenames.
+        * PlatformGTK.cmake: Ditto.
+        * PlatformMac.cmake: Ditto.
+        * PlatformWin.cmake: Ditto.
+        * platform/MainThreadSharedTimer.cpp: Copied from Source/WebCore/platform/efl/SharedTimerEfl.cpp.
+        (WebCore::MainThreadSharedTimer::singleton):
+        (WebCore::MainThreadSharedTimer::MainThreadSharedTimer):
+        (WebCore::MainThreadSharedTimer::setFiredFunction):
+        (WebCore::MainThreadSharedTimer::fired):
+        * platform/MainThreadSharedTimer.h: Copied from Source/WebCore/platform/gtk/SharedTimerGtk.cpp.
+        * platform/SharedTimer.h: Remove MainThreadSharedTimer
+        implementation and reindent the code.
+        (WebCore::SharedTimer::SharedTimer):
+        (WebCore::SharedTimer::~SharedTimer):
+        (WebCore::SharedTimer::invalidate):
+        * platform/ThreadTimers.cpp:
+        (WebCore::ThreadTimers::ThreadTimers): Use MainThreadSharedTimer::singleton().
+        (WebCore::ThreadTimers::setSharedTimer): Use a lambda function
+        instead of a pointer to a static method.
+        (WebCore::ThreadTimers::sharedTimerFired): Deleted.
+        * platform/ThreadTimers.h: Removed unsused static method sharedTimerFired.
+        * platform/cf/MainThreadSharedTimerCF.cpp: Renamed from Source/WebCore/platform/cf/SharedTimerCF.cpp.
+        (WebCore::applicationDidBecomeActive):
+        (WebCore::setupPowerObserver):
+        (WebCore::timerFired):
+        (WebCore::restartSharedTimer):
+        (WebCore::MainThreadSharedTimer::invalidate):
+        (WebCore::MainThreadSharedTimer::setFireInterval):
+        (WebCore::MainThreadSharedTimer::stop):
+        * platform/efl/MainThreadSharedTimerEfl.cpp: Renamed from Source/WebCore/platform/efl/SharedTimerEfl.cpp.
+        (WebCore::timerEvent):
+        (WebCore::MainThreadSharedTimer::stop):
+        (WebCore::MainThreadSharedTimer::setFireInterval):
+        (WebCore::MainThreadSharedTimer::invalidate):
+        * platform/gtk/MainThreadSharedTimerGtk.cpp: Renamed from Source/WebCore/platform/gtk/SharedTimerGtk.cpp.
+        (WebCore::MainThreadSharedTimer::setFireInterval):
+        (WebCore::MainThreadSharedTimer::stop):
+        (WebCore::MainThreadSharedTimer::invalidate):
+        * platform/win/MainThreadSharedTimerWin.cpp: Renamed from Source/WebCore/platform/win/SharedTimerWin.cpp.
+        (WebCore::TimerWindowWndProc):
+        (WebCore::initializeOffScreenTimerWindow):
+        (WebCore::queueTimerProc):
+        (WebCore::MainThreadSharedTimer::setFireInterval):
+        (WebCore::MainThreadSharedTimer::stop):
+        (WebCore::MainThreadSharedTimer::invalidate):
+        * workers/WorkerRunLoop.cpp: Update WorkerSharedTimer
+        implementation to use std::function instead of a pointer. Also
+        mark the class as final and the virtual implementations as override.
+
+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
 
index a6f1c1e..e597d01 100644 (file)
@@ -114,13 +114,13 @@ list(APPEND WebCore_SOURCES
     platform/efl/LocalizedStringsEfl.cpp
     platform/efl/LoggingEfl.cpp
     platform/efl/MIMETypeRegistryEfl.cpp
+    platform/efl/MainThreadSharedTimerEfl.cpp
     platform/efl/PasteboardEfl.cpp
     platform/efl/PlatformKeyboardEventEfl.cpp
     platform/efl/PlatformMouseEventEfl.cpp
     platform/efl/PlatformScreenEfl.cpp
     platform/efl/PlatformWheelEventEfl.cpp
     platform/efl/ScrollbarThemeEfl.cpp
-    platform/efl/SharedTimerEfl.cpp
     platform/efl/SoundEfl.cpp
     platform/efl/TemporaryLinkStubs.cpp
     platform/efl/WidgetEfl.cpp
index 8bc1fda..a4d7d76 100644 (file)
@@ -162,8 +162,8 @@ list(APPEND WebCore_SOURCES
     platform/gtk/LanguageGtk.cpp
     platform/gtk/LoggingGtk.cpp
     platform/gtk/MIMETypeRegistryGtk.cpp
+    platform/gtk/MainThreadSharedTimerGtk.cpp
     platform/gtk/SharedBufferGtk.cpp
-    platform/gtk/SharedTimerGtk.cpp
     platform/gtk/TemporaryLinkStubs.cpp
     platform/gtk/UserAgentGtk.cpp
 
index e5a3c4f..ce5583f 100644 (file)
@@ -312,10 +312,10 @@ list(APPEND WebCore_SOURCES
     platform/cf/FileSystemCF.cpp
     platform/cf/KeyedDecoderCF.cpp
     platform/cf/KeyedEncoderCF.cpp
+    platform/cf/MainThreadSharedTimerCF.cpp
     platform/cf/MediaAccessibilitySoftLink.cpp
     platform/cf/RunLoopObserver.cpp
     platform/cf/SharedBufferCF.cpp
-    platform/cf/SharedTimerCF.cpp
     platform/cf/URLCF.cpp
 
     platform/cocoa/ContentFilterUnblockHandlerCocoa.mm
index 0211f68..4ef8a7b 100644 (file)
@@ -124,6 +124,7 @@ list(APPEND WebCore_SOURCES
     platform/win/LoggingWin.cpp
     platform/win/MemoryPressureHandlerWin.cpp
     platform/win/MIMETypeRegistryWin.cpp
+    platform/win/MainThreadSharedTimerWin.cpp
     platform/win/PasteboardWin.cpp
     platform/win/PathWalker.cpp
     platform/win/PlatformMouseEventWin.cpp
@@ -133,7 +134,6 @@ list(APPEND WebCore_SOURCES
     platform/win/ScrollbarThemeWin.cpp
     platform/win/SearchPopupMenuWin.cpp
     platform/win/SharedBufferWin.cpp
-    platform/win/SharedTimerWin.cpp
     platform/win/SoundWin.cpp
     platform/win/StructuredExceptionHandlerSuppressor.cpp
     platform/win/SystemInfo.cpp
index 51c6a22..5de6e56 100644 (file)
                46233EEE1BA0F187000EBEBB /* AttributeDOMTokenList.h in Headers */ = {isa = PBXBuildFile; fileRef = 46233EED1BA0F17A000EBEBB /* AttributeDOMTokenList.h */; };
                46233EEF1BA0F18B000EBEBB /* AttributeDOMTokenList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46233EEC1BA0F17A000EBEBB /* AttributeDOMTokenList.cpp */; };
                4634592C1AC2271000ECB71C /* PowerObserverMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */; };
-               4634592E1AC2273C00ECB71C /* SharedTimerCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4634592D1AC2273C00ECB71C /* SharedTimerCF.cpp */; };
                463EB6221B8789E00096ED51 /* TagCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 463EB6201B8789CB0096ED51 /* TagCollection.cpp */; };
                463EB6231B8789E00096ED51 /* TagCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 463EB6211B8789CB0096ED51 /* TagCollection.h */; };
                4669B2871B852A0B000F905F /* JSDOMNamedFlowCollectionCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46F2768E1B85297F005C2556 /* JSDOMNamedFlowCollectionCustom.cpp */; };
                7ADE722610CBBB9B006B3B3A /* ContextMenuProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7AE335F11ACB09E200E401EF /* WheelEventTestTrigger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AE335EF1ACB09E200E401EF /* WheelEventTestTrigger.cpp */; };
                7AE335F21ACB09E200E401EF /* WheelEventTestTrigger.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AE335F01ACB09E200E401EF /* WheelEventTestTrigger.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               7AE6C9381BE0C5C800E19E03 /* MainThreadSharedTimerCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AE6C9371BE0C5C800E19E03 /* MainThreadSharedTimerCF.cpp */; };
+               7AE6C93B1BE0C60100E19E03 /* MainThreadSharedTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AE6C9391BE0C60100E19E03 /* MainThreadSharedTimer.cpp */; };
+               7AE6C93C1BE0C60100E19E03 /* MainThreadSharedTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AE6C93A1BE0C60100E19E03 /* MainThreadSharedTimer.h */; };
                7AF9B20218CFB2DF00C64BEF /* VTTRegion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AF9B1FC18CFB2DF00C64BEF /* VTTRegion.cpp */; };
                7AF9B20318CFB2DF00C64BEF /* VTTRegion.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AF9B1FD18CFB2DF00C64BEF /* VTTRegion.h */; };
                7AF9B20518CFB2DF00C64BEF /* VTTRegionList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AF9B1FF18CFB2DF00C64BEF /* VTTRegionList.cpp */; };
                46233EEC1BA0F17A000EBEBB /* AttributeDOMTokenList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeDOMTokenList.cpp; path = ../AttributeDOMTokenList.cpp; sourceTree = "<group>"; };
                46233EED1BA0F17A000EBEBB /* AttributeDOMTokenList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AttributeDOMTokenList.h; path = ../AttributeDOMTokenList.h; sourceTree = "<group>"; };
                4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PowerObserverMac.cpp; sourceTree = "<group>"; };
-               4634592D1AC2273C00ECB71C /* SharedTimerCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedTimerCF.cpp; sourceTree = "<group>"; };
                463EB6201B8789CB0096ED51 /* TagCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TagCollection.cpp; sourceTree = "<group>"; };
                463EB6211B8789CB0096ED51 /* TagCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagCollection.h; sourceTree = "<group>"; };
                4689F1AE1267BAE100E8D380 /* FileMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileMetadata.h; sourceTree = "<group>"; };
                7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextMenuProvider.h; sourceTree = "<group>"; };
                7AE335EF1ACB09E200E401EF /* WheelEventTestTrigger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WheelEventTestTrigger.cpp; sourceTree = "<group>"; };
                7AE335F01ACB09E200E401EF /* WheelEventTestTrigger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WheelEventTestTrigger.h; sourceTree = "<group>"; };
+               7AE6C9371BE0C5C800E19E03 /* MainThreadSharedTimerCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MainThreadSharedTimerCF.cpp; sourceTree = "<group>"; };
+               7AE6C9391BE0C60100E19E03 /* MainThreadSharedTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MainThreadSharedTimer.cpp; sourceTree = "<group>"; };
+               7AE6C93A1BE0C60100E19E03 /* MainThreadSharedTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainThreadSharedTimer.h; sourceTree = "<group>"; };
                7AF9B1FC18CFB2DF00C64BEF /* VTTRegion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VTTRegion.cpp; sourceTree = "<group>"; };
                7AF9B1FD18CFB2DF00C64BEF /* VTTRegion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VTTRegion.h; sourceTree = "<group>"; };
                7AF9B1FE18CFB2DF00C64BEF /* VTTRegion.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = VTTRegion.idl; sourceTree = "<group>"; };
                1AE42F670AA4B8CB00C8612D /* cf */ = {
                        isa = PBXGroup;
                        children = (
+                               7AE6C9371BE0C5C800E19E03 /* MainThreadSharedTimerCF.cpp */,
                                E1A8E56417552B2A007488E7 /* CFURLExtras.cpp */,
                                E1A8E56517552B2A007488E7 /* CFURLExtras.h */,
                                443817FD1A91B2F8006E04F2 /* CoreMediaSoftLink.cpp */,
                                2D76BB8319456F8100CFD29A /* RunLoopObserver.cpp */,
                                2D76BB801945632400CFD29A /* RunLoopObserver.h */,
                                512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */,
-                               4634592D1AC2273C00ECB71C /* SharedTimerCF.cpp */,
                                1A98956A0AA78F80005EF5EF /* URLCF.cpp */,
                        );
                        path = cf;
                BCF1A5BA097832090061A123 /* platform */ = {
                        isa = PBXGroup;
                        children = (
+                               7AE6C9391BE0C60100E19E03 /* MainThreadSharedTimer.cpp */,
+                               7AE6C93A1BE0C60100E19E03 /* MainThreadSharedTimer.h */,
                                49E912A40EFAC8E6009D0CAF /* animation */,
                                FD31604012B026A300C1A359 /* audio */,
                                1AE42F670AA4B8CB00C8612D /* cf */,
                                AAA728F716D1D8BC00D3BBC6 /* WebAccessibilityObjectWrapperIOS.h in Headers */,
                                AA478A7F16CD70C3007D1BB4 /* WebAccessibilityObjectWrapperMac.h in Headers */,
                                2D3EF4481917915C00034184 /* WebActionDisablingCALayerDelegate.h in Headers */,
+                               7AE6C93C1BE0C60100E19E03 /* MainThreadSharedTimer.h in Headers */,
                                07D637401BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h in Headers */,
                                A5A7AA43132F0ECC00D3A3C2 /* WebAutocapitalize.h in Headers */,
                                A56C5B9B189F34570082D13C /* WebConsoleAgent.h in Headers */,
                                0779BF0D18453168000B6AE7 /* HTMLMediaElementMediaStream.cpp in Sources */,
                                A8EA79F80A1916DF00A8EF5F /* HTMLMenuElement.cpp in Sources */,
                                2BE8E2C912A58A0100FAD550 /* HTMLMetaCharsetParser.cpp in Sources */,
+                               7AE6C9381BE0C5C800E19E03 /* MainThreadSharedTimerCF.cpp in Sources */,
                                A871DC270A15205700B12A68 /* HTMLMetaElement.cpp in Sources */,
                                A454424A119B3661009BE912 /* HTMLMeterElement.cpp in Sources */,
                                A8CFF7A90A156978000A4234 /* HTMLModElement.cpp in Sources */,
                                512DD8E30D91E2B4000F89EE /* SharedBufferCF.cpp in Sources */,
                                97B1F02E13B025CA00F5103F /* SharedBufferChunkReader.cpp in Sources */,
                                1A4A95520B4EDCFF002D8C3C /* SharedBufferMac.mm in Sources */,
-                               4634592E1AC2273C00ECB71C /* SharedTimerCF.cpp in Sources */,
                                163E88F7118A39D200ED9231 /* SimpleFontDataCoreText.cpp in Sources */,
                                E48944A2180B57D800F165D8 /* SimpleLineLayout.cpp in Sources */,
                                585D6E031A1A792E00FA4F12 /* SimpleLineLayoutFlowContents.cpp in Sources */,
                                BC8243E80D0CFD7500460C8F /* WindowFeatures.cpp in Sources */,
                                7E99AF510B13846468FB01A5 /* WindowFocusAllowedIndicator.cpp in Sources */,
                                A14832BD187F64B400DA63A6 /* WKContentObservation.cpp in Sources */,
+                               7AE6C93B1BE0C60100E19E03 /* MainThreadSharedTimer.cpp in Sources */,
                                A14832C0187F656600DA63A6 /* WKGraphics.mm in Sources */,
                                A14832C2187F65C700DA63A6 /* WKUtilities.c in Sources */,
                                A14832C5187F668300DA63A6 /* WKView.mm in Sources */,
diff --git a/Source/WebCore/platform/MainThreadSharedTimer.cpp b/Source/WebCore/platform/MainThreadSharedTimer.cpp
new file mode 100644 (file)
index 0000000..67f17c6
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 INC. OR
+ * 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"
+#include "MainThreadSharedTimer.h"
+
+namespace WebCore {
+
+MainThreadSharedTimer& MainThreadSharedTimer::singleton()
+{
+    static NeverDestroyed<MainThreadSharedTimer> instance;
+    return instance;
+}
+
+MainThreadSharedTimer::MainThreadSharedTimer()
+{
+}
+
+void MainThreadSharedTimer::setFiredFunction(std::function<void()>&& firedFunction)
+{
+    RELEASE_ASSERT(!m_firedFunction || !firedFunction);
+    m_firedFunction = WTF::move(firedFunction);
+}
+
+void MainThreadSharedTimer::fired() const
+{
+    ASSERT(m_firedFunction);
+    m_firedFunction();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/MainThreadSharedTimer.h b/Source/WebCore/platform/MainThreadSharedTimer.h
new file mode 100644 (file)
index 0000000..73cfcbc
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ * Copyright (C) 2006 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 INC. OR
+ * 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.
+ */
+
+#ifndef MainThreadSharedTimer_h
+#define MainThreadSharedTimer_h
+
+#include "SharedTimer.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+class MainThreadSharedTimer final : public SharedTimer {
+    friend class WTF::NeverDestroyed<MainThreadSharedTimer>;
+public:
+    static MainThreadSharedTimer& singleton();
+
+    void setFiredFunction(std::function<void()>&&) override;
+    void setFireInterval(double) override;
+    void stop() override;
+    void invalidate() override;
+
+    // FIXME: This should be private, but CF and Windows implementations
+    // need to call this from non-member functions at the moment.
+    void fired() const;
+
+private:
+    MainThreadSharedTimer();
+
+    std::function<void()> m_firedFunction;
+};
+
+} // namespace WebCore
+
+#endif // MainThreadSharedTimer
index 299c499..be2410e 100644 (file)
 #ifndef SharedTimer_h
 #define SharedTimer_h
 
+#include <functional>
 #include <wtf/FastMalloc.h>
 #include <wtf/Noncopyable.h>
 
 namespace WebCore {
 
-    // Each thread has its own single instance of shared timer, which implements this interface.
-    // This instance is shared by all timers in the thread.
-    // Not intended to be used directly; use the Timer class instead.
-    class SharedTimer {
-        WTF_MAKE_NONCOPYABLE(SharedTimer); WTF_MAKE_FAST_ALLOCATED;
-    public:
-        SharedTimer() { }
-        virtual ~SharedTimer() {}
-        virtual void setFiredFunction(void (*)()) = 0;
-
-        // The fire interval is in seconds relative to the current monotonic clock time.
-        virtual void setFireInterval(double) = 0;
-        virtual void stop() = 0;
-
-        virtual void invalidate() { }
-    };
-
-
-    // Implemented by port (since it provides the run loop for the main thread).
-    // FIXME: make ports implement MainThreadSharedTimer directly instead.
-    void setSharedTimerFiredFunction(void (*)());
-    void setSharedTimerFireInterval(double);
-    void stopSharedTimer();
-    void invalidateSharedTimer();
-
-    // Implementation of SharedTimer for the main thread.
-    class MainThreadSharedTimer final : public SharedTimer {
-    public:
-        void setFiredFunction(void (*function)()) override
-        {
-            setSharedTimerFiredFunction(function);
-        }
-        
-        void setFireInterval(double interval) override
-        {
-            setSharedTimerFireInterval(interval);
-        }
-        
-        void stop() override
-        {
-            stopSharedTimer();
-        }
-
-        void invalidate() override
-        {
-            invalidateSharedTimer();
-        }
-    };
+// Each thread has its own single instance of shared timer, which implements this interface.
+// This instance is shared by all timers in the thread.
+// Not intended to be used directly; use the Timer class instead.
+class SharedTimer {
+    WTF_MAKE_NONCOPYABLE(SharedTimer); WTF_MAKE_FAST_ALLOCATED;
+public:
+    SharedTimer() = default;
+    virtual ~SharedTimer() { }
+    virtual void setFiredFunction(std::function<void()>&&) = 0;
+
+    // The fire interval is in seconds relative to the current monotonic clock time.
+    virtual void setFireInterval(double) = 0;
+    virtual void stop() = 0;
+
+    virtual void invalidate() { }
+};
 
 } // namespace WebCore
 
index 1231ca2..0228341 100644 (file)
@@ -27,6 +27,7 @@
 #include "config.h"
 #include "ThreadTimers.h"
 
+#include "MainThreadSharedTimer.h"
 #include "SharedTimer.h"
 #include "ThreadGlobalData.h"
 #include "Timer.h"
@@ -47,27 +48,21 @@ static const double maxDurationOfFiringTimers = 0.050;
 // Timers are created, started and fired on the same thread, and each thread has its own ThreadTimers
 // copy to keep the heap and a set of currently firing timers.
 
-static MainThreadSharedTimer* mainThreadSharedTimer()
-{
-    static MainThreadSharedTimer* timer = new MainThreadSharedTimer;
-    return timer;
-}
-
 ThreadTimers::ThreadTimers()
     : m_sharedTimer(0)
     , m_firingTimers(false)
     , m_pendingSharedTimerFireTime(0)
 {
     if (isUIThread())
-        setSharedTimer(mainThreadSharedTimer());
+        setSharedTimer(&MainThreadSharedTimer::singleton());
 }
 
 // A worker thread may initialize SharedTimer after some timers are created.
-// Also, SharedTimer can be replaced with 0 before all timers are destroyed.
+// Also, SharedTimer can be replaced with nullptr before all timers are destroyed.
 void ThreadTimers::setSharedTimer(SharedTimer* sharedTimer)
 {
     if (m_sharedTimer) {
-        m_sharedTimer->setFiredFunction(0);
+        m_sharedTimer->setFiredFunction(nullptr);
         m_sharedTimer->stop();
         m_pendingSharedTimerFireTime = 0;
     }
@@ -75,7 +70,7 @@ void ThreadTimers::setSharedTimer(SharedTimer* sharedTimer)
     m_sharedTimer = sharedTimer;
     
     if (sharedTimer) {
-        m_sharedTimer->setFiredFunction(ThreadTimers::sharedTimerFired);
+        m_sharedTimer->setFiredFunction([] { threadGlobalData().threadTimers().sharedTimerFiredInternal(); });
         updateSharedTimer();
     }
 }
@@ -101,12 +96,6 @@ void ThreadTimers::updateSharedTimer()
     }
 }
 
-void ThreadTimers::sharedTimerFired()
-{
-    // Redirect to non-static method.
-    threadGlobalData().threadTimers().sharedTimerFiredInternal();
-}
-
 void ThreadTimers::sharedTimerFiredInternal()
 {
     ASSERT(isMainThread() || (!isWebThread() && !isUIThread()));
index 15d9f37..e4f2623 100644 (file)
@@ -51,8 +51,6 @@ namespace WebCore {
         void fireTimersInNestedEventLoop();
 
     private:
-        static void sharedTimerFired();
-
         void sharedTimerFiredInternal();
         void fireTimersInNestedEventLoopInternal();
 
@@ -24,7 +24,7 @@
  */
 
 #import "config.h"
-#import "SharedTimer.h"
+#import "MainThreadSharedTimer.h"
 
 #include <wtf/AutodrainedPool.h>
 
@@ -38,7 +38,6 @@
 namespace WebCore {
 
 static CFRunLoopTimerRef sharedTimer;
-static void (*sharedTimerFiredFunction)();
 static void timerFired(CFRunLoopTimerRef, void*);
 static void restartSharedTimer();
 
@@ -69,17 +68,10 @@ static void setupPowerObserver()
 #endif
 }
 
-void setSharedTimerFiredFunction(void (*f)())
-{
-    ASSERT(!sharedTimerFiredFunction || sharedTimerFiredFunction == f);
-
-    sharedTimerFiredFunction = f;
-}
-
 static void timerFired(CFRunLoopTimerRef, void*)
 {
     AutodrainedPool pool;
-    sharedTimerFiredFunction();
+    MainThreadSharedTimer::singleton().fired();
 }
 
 static void restartSharedTimer()
@@ -87,11 +79,11 @@ static void restartSharedTimer()
     if (!sharedTimer)
         return;
 
-    stopSharedTimer();
+    MainThreadSharedTimer::singleton().stop();
     timerFired(0, 0);
 }
 
-void invalidateSharedTimer()
+void MainThreadSharedTimer::invalidate()
 {
     if (!sharedTimer)
         return;
@@ -101,9 +93,9 @@ void invalidateSharedTimer()
     sharedTimer = nullptr;
 }
 
-void setSharedTimerFireInterval(double interval)
+void MainThreadSharedTimer::setFireInterval(double interval)
 {
-    ASSERT(sharedTimerFiredFunction);
+    ASSERT(m_firedFunction);
 
     CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent() + interval;
     if (!sharedTimer) {
@@ -122,7 +114,7 @@ void setSharedTimerFireInterval(double interval)
     CFRunLoopTimerSetNextFireDate(sharedTimer, fireDate);
 }
 
-void stopSharedTimer()
+void MainThreadSharedTimer::stop()
 {
     if (!sharedTimer)
         return;
@@ -27,7 +27,7 @@
  */
 
 #include "config.h"
-#include "SharedTimer.h"
+#include "MainThreadSharedTimer.h"
 
 #include <Ecore.h>
 #include <wtf/Assertions.h>
 
 namespace WebCore {
 
-static Ecore_Timer *_sharedTimer = 0;
-
-static void (*_timerFunction)();
-
-void setSharedTimerFiredFunction(void (*func)())
-{
-    _timerFunction = func;
-}
+static Ecore_Timer* sharedTimer;
 
 static Eina_Bool timerEvent(void*)
 {
-    _sharedTimer = 0;
-    if (_timerFunction)
-        _timerFunction();
-
+    sharedTimer = nullptr;
+    MainThreadSharedTimer::singleton().fired();
     return ECORE_CALLBACK_CANCEL;
 }
 
-void stopSharedTimer()
+void MainThreadSharedTimer::stop()
 {
-    if (_sharedTimer) {
-        ecore_timer_del(_sharedTimer);
-        _sharedTimer = 0;
+    if (sharedTimer) {
+        ecore_timer_del(sharedTimer);
+        sharedTimer = nullptr;
     }
 }
 
-void addNewTimer(double interval)
-{
-    stopSharedTimer();
-
-    _sharedTimer = ecore_timer_loop_add(interval, timerEvent, 0);
-}
-
-void setSharedTimerFireInterval(double interval)
+void MainThreadSharedTimer::setFireInterval(double interval)
 {
-    addNewTimer(interval);
+    stop();
+    sharedTimer = ecore_timer_loop_add(interval, timerEvent, nullptr);
 }
 
-void invalidateSharedTimer()
+void MainThreadSharedTimer::invalidate()
 {
 }
 
  */
 
 #include "config.h"
-#include "SharedTimer.h"
+#include "MainThreadSharedTimer.h"
 
 #include <wtf/glib/GMainLoopSource.h>
 
 namespace WebCore {
 
 static GMainLoopSource gSharedTimer;
-static void (*sharedTimerFiredFunction)();
 
-void setSharedTimerFiredFunction(void (*f)())
+void MainThreadSharedTimer::setFireInterval(double interval)
 {
-    sharedTimerFiredFunction = f;
-    if (!sharedTimerFiredFunction)
-        gSharedTimer.cancel();
-}
-
-void setSharedTimerFireInterval(double interval)
-{
-    ASSERT(sharedTimerFiredFunction);
+    ASSERT(m_firedFunction);
 
     // This is GDK_PRIORITY_REDRAW, but we don't want to depend on GDK here just to use a constant.
     static const int priority = G_PRIORITY_HIGH_IDLE + 20;
-    gSharedTimer.scheduleAfterDelay("[WebKit] sharedTimerTimeoutCallback", std::function<void()>(sharedTimerFiredFunction),
+    gSharedTimer.scheduleAfterDelay("[WebKit] sharedTimerTimeoutCallback", [this] { fired(); },
         std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(interval)), priority);
 }
 
-void stopSharedTimer()
+void MainThreadSharedTimer::stop()
 {
     gSharedTimer.cancel();
 }
 
-void invalidateSharedTimer()
+void MainThreadSharedTimer::invalidate()
 {
 }
 
@@ -24,7 +24,7 @@
  */
 
 #include "config.h"
-#include "SharedTimer.h"
+#include "MainThreadSharedTimer.h"
 
 #include "Page.h"
 #include "Settings.h"
@@ -53,7 +53,6 @@
 namespace WebCore {
 
 static UINT timerID;
-static void (*sharedTimerFiredFunction)();
 
 static HANDLE timer;
 static HWND timerWindowHandle = 0;
@@ -79,9 +78,8 @@ LRESULT CALLBACK TimerWindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPAR
     if (message == WM_TIMER) {
         if (wParam == sharedTimerID) {
             KillTimer(timerWindowHandle, sharedTimerID);
-            sharedTimerFiredFunction();
-        }
-        else if (wParam == endHighResTimerID) {
+            MainThreadSharedTimer::singleton().fired();
+        } else if (wParam == endHighResTimerID) {
             KillTimer(timerWindowHandle, endHighResTimerID);
             highResTimerActive = false;
             timeEndPeriod(timerResolution);
@@ -89,7 +87,7 @@ LRESULT CALLBACK TimerWindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPAR
     } else if (message == timerFiredMessage) {
         InterlockedExchange(&pendingTimers, 0);
         processingCustomTimerMessage = true;
-        sharedTimerFiredFunction();
+        MainThreadSharedTimer::singleton().fired();
         processingCustomTimerMessage = false;
     } else
         return DefWindowProc(hWnd, message, wParam, lParam);
@@ -117,20 +115,15 @@ static void initializeOffScreenTimerWindow()
     timerFiredMessage = RegisterWindowMessage(L"com.apple.WebKit.TimerFired");
 }
 
-void setSharedTimerFiredFunction(void (*f)())
-{
-    sharedTimerFiredFunction = f;
-}
-
 static void NTAPI queueTimerProc(PVOID, BOOLEAN)
 {
     if (InterlockedIncrement(&pendingTimers) == 1)
         PostMessage(timerWindowHandle, timerFiredMessage, 0, 0);
 }
 
-void setSharedTimerFireInterval(double interval)
+void MainThreadSharedTimer::setFireInterval(double interval)
 {
-    ASSERT(sharedTimerFiredFunction);
+    ASSERT(m_firedFunction);
 
     unsigned intervalInMS;
     interval *= 1000;
@@ -185,7 +178,7 @@ void setSharedTimerFireInterval(double interval)
     }
 }
 
-void stopSharedTimer()
+void MainThreadSharedTimer::stop()
 {
     if (timerQueue && timer) {
         DeleteTimerQueueTimer(timerQueue, timer, 0);
@@ -198,7 +191,7 @@ void stopSharedTimer()
     }
 }
 
-void invalidateSharedTimer()
+void MainThreadSharedTimer::invalidate()
 {
 }
 
index e812308..bb8d081 100644 (file)
 
 namespace WebCore {
 
-class WorkerSharedTimer : public SharedTimer {
+class WorkerSharedTimer final : public SharedTimer {
 public:
-    WorkerSharedTimer()
-        : m_sharedTimerFunction(0)
-        , m_nextFireTime(0)
-    {
-    }
-
     // SharedTimer interface.
-    virtual void setFiredFunction(void (*function)()) { m_sharedTimerFunction = function; }
-    virtual void setFireInterval(double interval) { m_nextFireTime = interval + currentTime(); }
-    virtual void stop() { m_nextFireTime = 0; }
+    virtual void setFiredFunction(std::function<void()>&& function) override { m_sharedTimerFunction = WTF::move(function); }
+    virtual void setFireInterval(double interval) override { m_nextFireTime = interval + currentTime(); }
+    virtual void stop() override { m_nextFireTime = 0; }
 
     bool isActive() { return m_sharedTimerFunction && m_nextFireTime; }
     double fireTime() { return m_nextFireTime; }
     void fire() { m_sharedTimerFunction(); }
 
 private:
-    void (*m_sharedTimerFunction)();
-    double m_nextFireTime;
+    std::function<void()> m_sharedTimerFunction;
+    double m_nextFireTime { 0 };
 };
 
 class ModePredicate {