Introduce HTMLParserThread to be able to parse on a background thread
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Jan 2013 02:05:33 +0000 (02:05 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Jan 2013 02:05:33 +0000 (02:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=107071

Reviewed by Tony Gentilcore.

This patch introduces a simple thread class that we can use to parse
HTML. This patch is unlikely to be the final design because we'll
likely want to use libdispatch or some other platform-specific thread
pool. However, this implementation is enough to let us work on the
parser-specific aspects of this feature.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* html/parser/HTMLParserThread.cpp: Added.
(WebCore):
(WebCore::HTMLParserThread::HTMLParserThread):
(WebCore::HTMLParserThread::~HTMLParserThread):
(WebCore::HTMLParserThread::start):
(WebCore::HTMLParserThread::stop):
(WebCore::HTMLParserThread::shared):
(WebCore::HTMLParserThread::postTask):
(WebCore::HTMLParserThread::threadStart):
(WebCore::HTMLParserThread::runLoop):
* html/parser/HTMLParserThread.h: Added.
(WebCore):
(HTMLParserThread):
(WebCore::HTMLParserThread::create):
(WebCore::HTMLParserThread::threadId):

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

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/parser/HTMLParserThread.cpp [new file with mode: 0644]
Source/WebCore/html/parser/HTMLParserThread.h [new file with mode: 0644]

index 2ee51c9..5238cce 100644 (file)
@@ -1535,6 +1535,7 @@ set(WebCore_SOURCES
     html/parser/HTMLParserIdioms.cpp
     html/parser/HTMLParserOptions.cpp
     html/parser/HTMLParserScheduler.cpp
+    html/parser/HTMLParserThread.cpp
     html/parser/HTMLFormattingElementList.cpp
     html/parser/HTMLMetaCharsetParser.cpp
     html/parser/HTMLPreloadScanner.cpp
index dd92f93..c755238 100644 (file)
@@ -1,3 +1,38 @@
+2013-01-16  Adam Barth  <abarth@webkit.org>
+
+        Introduce HTMLParserThread to be able to parse on a background thread
+        https://bugs.webkit.org/show_bug.cgi?id=107071
+
+        Reviewed by Tony Gentilcore.
+
+        This patch introduces a simple thread class that we can use to parse
+        HTML. This patch is unlikely to be the final design because we'll
+        likely want to use libdispatch or some other platform-specific thread
+        pool. However, this implementation is enough to let us work on the
+        parser-specific aspects of this feature.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/parser/HTMLParserThread.cpp: Added.
+        (WebCore):
+        (WebCore::HTMLParserThread::HTMLParserThread):
+        (WebCore::HTMLParserThread::~HTMLParserThread):
+        (WebCore::HTMLParserThread::start):
+        (WebCore::HTMLParserThread::stop):
+        (WebCore::HTMLParserThread::shared):
+        (WebCore::HTMLParserThread::postTask):
+        (WebCore::HTMLParserThread::threadStart):
+        (WebCore::HTMLParserThread::runLoop):
+        * html/parser/HTMLParserThread.h: Added.
+        (WebCore):
+        (HTMLParserThread):
+        (WebCore::HTMLParserThread::create):
+        (WebCore::HTMLParserThread::threadId):
+
 2013-01-16  MORITA Hajime  <morrita@google.com>
 
         WebCore::ScriptRunner::timerFired() is reported to crash.
index b77f009..f2ebd20 100644 (file)
@@ -3554,6 +3554,8 @@ webcore_sources += \
        Source/WebCore/html/parser/HTMLParserOptions.h \
        Source/WebCore/html/parser/HTMLParserScheduler.cpp \
        Source/WebCore/html/parser/HTMLParserScheduler.h \
+       Source/WebCore/html/parser/HTMLParserThread.cpp \
+       Source/WebCore/html/parser/HTMLParserThread.h \
        Source/WebCore/html/parser/HTMLPreloadScanner.cpp \
        Source/WebCore/html/parser/HTMLPreloadScanner.h \
        Source/WebCore/html/parser/HTMLScriptRunner.cpp \
index 4557c4e..48e0c2d 100644 (file)
@@ -718,6 +718,7 @@ SOURCES += \
     html/parser/HTMLParserIdioms.cpp \
     html/parser/HTMLParserOptions.cpp \
     html/parser/HTMLParserScheduler.cpp \
+    html/parser/HTMLParserThread.cpp \
     html/parser/HTMLPreloadScanner.cpp \
     html/parser/HTMLScriptRunner.cpp \
     html/parser/HTMLSourceTracker.cpp \
index a1c3f99..665debc 100644 (file)
             'html/parser/HTMLParserOptions.h',
             'html/parser/HTMLParserScheduler.cpp',
             'html/parser/HTMLParserScheduler.h',
+            'html/parser/HTMLParserThread.cpp',
+            'html/parser/HTMLParserThread.h',
             'html/parser/HTMLPreloadScanner.cpp',
             'html/parser/HTMLPreloadScanner.h',
             'html/parser/HTMLScriptRunner.cpp',
index f7994cc..fd475ae 100755 (executable)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\html\parser\HTMLParserThread.cpp"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\html\parser\HTMLParserThread.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\html\parser\HTMLPreloadScanner.cpp"
                                        >
                                </File>
index 77ed7b7..6ce242c 100644 (file)
                973E325710883B7C005BC493 /* ResourceLoadNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 973E325510883B7C005BC493 /* ResourceLoadNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
                973F418A169B95FF0006BF60 /* HTMLParserOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 973F4188169B95EF0006BF60 /* HTMLParserOptions.h */; };
                973F418B169B96030006BF60 /* HTMLParserOptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 973F4187169B95EF0006BF60 /* HTMLParserOptions.cpp */; };
+               974187D316A7932700FA77A7 /* HTMLParserThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 974187D016A7932200FA77A7 /* HTMLParserThread.cpp */; };
+               974187D416A7932900FA77A7 /* HTMLParserThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 974187D116A7932200FA77A7 /* HTMLParserThread.h */; };
                9746AF2314F4DDE6003E7A70 /* Geolocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9746AF1314F4DDE6003E7A70 /* Geolocation.cpp */; };
                9746AF2414F4DDE6003E7A70 /* Geolocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 9746AF1414F4DDE6003E7A70 /* Geolocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9746AF2614F4DDE6003E7A70 /* GeolocationController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9746AF1614F4DDE6003E7A70 /* GeolocationController.cpp */; };
                973E325510883B7C005BC493 /* ResourceLoadNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadNotifier.h; sourceTree = "<group>"; };
                973F4187169B95EF0006BF60 /* HTMLParserOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HTMLParserOptions.cpp; path = parser/HTMLParserOptions.cpp; sourceTree = "<group>"; };
                973F4188169B95EF0006BF60 /* HTMLParserOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLParserOptions.h; path = parser/HTMLParserOptions.h; sourceTree = "<group>"; };
+               974187D016A7932200FA77A7 /* HTMLParserThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HTMLParserThread.cpp; path = parser/HTMLParserThread.cpp; sourceTree = "<group>"; };
+               974187D116A7932200FA77A7 /* HTMLParserThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLParserThread.h; path = parser/HTMLParserThread.h; sourceTree = "<group>"; };
                9746AF1314F4DDE6003E7A70 /* Geolocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Geolocation.cpp; path = Modules/geolocation/Geolocation.cpp; sourceTree = "<group>"; };
                9746AF1414F4DDE6003E7A70 /* Geolocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Geolocation.h; path = Modules/geolocation/Geolocation.h; sourceTree = "<group>"; };
                9746AF1514F4DDE6003E7A70 /* Geolocation.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Geolocation.idl; path = Modules/geolocation/Geolocation.idl; sourceTree = "<group>"; };
                                A9D247F90D757E4100FDF959 /* Plugins */,
                                89F60B17157F6A020075E157 /* Quota */,
                                BC9854460CD3DA5F00069BC1 /* Ranges */,
+                               AA7FEE9B16A491A1004C0C33 /* Speech */,
                                A83B79150CCB0078000B0825 /* Storage */,
                                A83B790A0CCAFF47000B0825 /* SVG */,
                                417DA71213735D90007C57FB /* Testing */,
                                E1C8BE4B0E8BD0D10064CB7D /* Threads */,
                                BC9854530CD3DA8F00069BC1 /* Traversal */,
-                               AA7FEE9B16A491A1004C0C33 /* Speech */,
                                FDA15E7B12B03E04003A583A /* WebAudio */,
                                5DA5E0F9102B950400088CF9 /* WebSockets */,
                                BC9854430CD3D9D000069BC1 /* Window */,
                                BCE1C41A0D982980003B02F2 /* Location.cpp */,
                                BCE1C4190D982980003B02F2 /* Location.h */,
                                BCE1C4220D9829F2003B02F2 /* Location.idl */,
+                               BC59DEFA169DEDD80016AC34 /* make_settings.pl */,
                                931BCC601124DFCB00BE70DD /* MediaCanStartListener.h */,
                                9FFE3E7811B59C5D0037874E /* MemoryInfo.cpp */,
                                9FFE3E7911B59C5D0037874E /* MemoryInfo.h */,
                                14C9A5E90B3D105F005A0232 /* Settings.cpp */,
                                F587863A02DE3A1401EA4122 /* Settings.h */,
                                BC59DEF8169DEDC30016AC34 /* Settings.in */,
-                               BC59DEFA169DEDD80016AC34 /* make_settings.pl */,
                                626CDE0C1140424C001E5A68 /* SpatialNavigation.cpp */,
                                626CDE0D1140424C001E5A68 /* SpatialNavigation.h */,
                                7578F90811DDF26900D933C5 /* SpeechInput.cpp */,
                                973F4188169B95EF0006BF60 /* HTMLParserOptions.h */,
                                977B3857122883E900B81FF8 /* HTMLParserScheduler.cpp */,
                                977B3858122883E900B81FF8 /* HTMLParserScheduler.h */,
+                               974187D016A7932200FA77A7 /* HTMLParserThread.cpp */,
+                               974187D116A7932200FA77A7 /* HTMLParserThread.h */,
                                977B3859122883E900B81FF8 /* HTMLPreloadScanner.cpp */,
                                977B385A122883E900B81FF8 /* HTMLPreloadScanner.h */,
                                977B385B122883E900B81FF8 /* HTMLScriptRunner.cpp */,
                                977E2DCC12F0E28300C13379 /* HTMLSourceTracker.h */,
                                97C1F552122855CB00EDE615 /* HTMLStackItem.h */,
                                97C1F552122855CB00EDE616 /* HTMLToken.h */,
-                               97C1F552122855CB00EDE617 /* HTMLTokenTypes.h */,
                                977B385E122883E900B81FF8 /* HTMLTokenizer.cpp */,
                                977B385F122883E900B81FF8 /* HTMLTokenizer.h */,
+                               97C1F552122855CB00EDE617 /* HTMLTokenTypes.h */,
                                977B37211228721700B81FF8 /* HTMLTreeBuilder.cpp */,
                                977B37221228721700B81FF8 /* HTMLTreeBuilder.h */,
                                977B3860122883E900B81FF8 /* HTMLViewSourceParser.cpp */,
                                BC53C6910DA591140021EB5D /* CSSGradientValue.h */,
                                FCEBCD711623A7910029965E /* CSSGrammar.y.in */,
                                FCEBCD721623A7910029965E /* CSSGrammar.y.includes */,
-                               FB3056C1169E5DAC0096A232 /* CSSGroupingRule.h */,
                                FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */,
+                               FB3056C1169E5DAC0096A232 /* CSSGroupingRule.h */,
                                BC772B360C4EA91E0083285F /* CSSHelper.h */,
                                BC23E76B0DAE88A9009FDC91 /* CSSImageGeneratorValue.cpp */,
                                BC23EE910DAED2BC009FDC91 /* CSSImageGeneratorValue.h */,
                                9712A5AE15004EDA0048AF10 /* DOMWindowIndexedDatabase.h in Headers */,
                                97B38E27151C4271004622E9 /* DOMWindowNotifications.h in Headers */,
                                97D2AD0414B823A60093DF32 /* DOMWindowProperty.h in Headers */,
-                               AA2A5AD616A4861600975A25 /* DOMWindowSpeechSynthesis.h in Headers */,
                                89F60B11157F686E0075E157 /* DOMWindowQuota.h in Headers */,
+                               AA2A5AD616A4861600975A25 /* DOMWindowSpeechSynthesis.h in Headers */,
                                A8CCBB49151F831600AB7CE9 /* DOMWindowWebDatabase.h in Headers */,
                                BC53DA2E1143121E000D817E /* DOMWrapperWorld.h in Headers */,
                                1A1D13800A5325520064BF5F /* DOMXPath.h in Headers */,
                                973F418A169B95FF0006BF60 /* HTMLParserOptions.h in Headers */,
                                449B19F50FA72ECE0015CA4A /* HTMLParserQuirks.h in Headers */,
                                977B3871122883E900B81FF8 /* HTMLParserScheduler.h in Headers */,
+                               974187D416A7932900FA77A7 /* HTMLParserThread.h in Headers */,
                                A871D4560A127CBC00B12A68 /* HTMLPlugInElement.h in Headers */,
                                4415292E0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h in Headers */,
                                A8EA7CB00A192B9C00A8EF5F /* HTMLPreElement.h in Headers */,
                                514C76790CE923A1007EF3CD /* ResourceHandle.h in Headers */,
                                514C767A0CE923A1007EF3CD /* ResourceHandleClient.h in Headers */,
                                514C767B0CE923A1007EF3CD /* ResourceHandleInternal.h in Headers */,
+                               51E4143416A6596300C633C7 /* ResourceHandleTypes.h in Headers */,
                                656D373F0ADBA5DE00A4554D /* ResourceLoader.h in Headers */,
                                D0A3A7311405A39800FB8ED3 /* ResourceLoaderOptions.h in Headers */,
                                492863991253B8FC00F792D6 /* ResourceLoadInfo.h in Headers */,
                                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
                                977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
-                               51E4143416A6596300C633C7 /* ResourceHandleTypes.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                BC02A6460E09AAE9004B6D2B /* CSSFunctionValue.cpp in Sources */,
                                BC23E4E10DAACE0F009FDC91 /* CSSGradientValue.cpp in Sources */,
                                650F53DD09D15DDF00C9B0C8 /* CSSGrammar.cpp in Sources */,
+                               FBF89045169E9F1F0052D86E /* CSSGroupingRule.cpp in Sources */,
                                BC23E76C0DAE88A9009FDC91 /* CSSImageGeneratorValue.cpp in Sources */,
                                9393E5FF151A99F200066F06 /* CSSImageSetValue.cpp in Sources */,
                                A80E6CFE0A1989CA007FB8C5 /* CSSImageValue.cpp in Sources */,
                                93E2A306123E9DC0009FE12A /* HTMLParserIdioms.cpp in Sources */,
                                973F418B169B96030006BF60 /* HTMLParserOptions.cpp in Sources */,
                                977B3870122883E900B81FF8 /* HTMLParserScheduler.cpp in Sources */,
+                               974187D316A7932700FA77A7 /* HTMLParserThread.cpp in Sources */,
                                A871D4570A127CBC00B12A68 /* HTMLPlugInElement.cpp in Sources */,
                                4415292F0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.cpp in Sources */,
                                A8EA7CAD0A192B9C00A8EF5F /* HTMLPreElement.cpp in Sources */,
                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
-                               FBF89045169E9F1F0052D86E /* CSSGroupingRule.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Source/WebCore/html/parser/HTMLParserThread.cpp b/Source/WebCore/html/parser/HTMLParserThread.cpp
new file mode 100644 (file)
index 0000000..8e156ae
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2013 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER 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"
+
+#if ENABLE(THREADED_HTML_PARSER)
+
+#include "HTMLParserThread.h"
+
+namespace WebCore {
+
+HTMLParserThread::HTMLParserThread()
+    : m_threadID(0)
+{
+}
+
+HTMLParserThread::~HTMLParserThread()
+{
+    ASSERT(m_queue.killed());
+}
+
+bool HTMLParserThread::start()
+{
+    MutexLocker lock(m_threadCreationMutex);
+    if (m_threadID)
+        return true;
+    m_threadID = createThread(HTMLParserThread::threadStart, this, "WebCore: HTMLParser");
+    return m_threadID;
+}
+
+void HTMLParserThread::stop()
+{
+    m_queue.kill();
+    waitForThreadCompletion(m_threadID);
+}
+
+HTMLParserThread* HTMLParserThread::shared()
+{
+    static HTMLParserThread* thread;
+    if (!thread) {
+        thread = HTMLParserThread::create().leakPtr();
+        thread->start();
+    }
+    return thread;
+}
+
+void HTMLParserThread::postTask(const Closure& function)
+{
+    m_queue.append(adoptPtr(new Closure(function)));
+}
+
+void HTMLParserThread::threadStart(void* arg)
+{
+    HTMLParserThread* thread = static_cast<HTMLParserThread*>(arg);
+    thread->runLoop();
+}
+
+void HTMLParserThread::runLoop()
+{
+    {
+        // Wait for HTMLParserThread::start() to complete to have m_threadID
+        // established before starting the main loop.
+        MutexLocker lock(m_threadCreationMutex);
+    }
+    while (OwnPtr<Closure> function = m_queue.waitForMessage())
+        (*function)();
+
+    // stop() will wait to join the thread, so we do not detach here.
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(THREADED_HTML_PARSER)
diff --git a/Source/WebCore/html/parser/HTMLParserThread.h b/Source/WebCore/html/parser/HTMLParserThread.h
new file mode 100644 (file)
index 0000000..f301c1d
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER 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 HTMLParserThread_h
+#define HTMLParserThread_h
+
+#if ENABLE(THREADED_HTML_PARSER)
+
+#include <wtf/Functional.h>
+#include <wtf/MessageQueue.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/Threading.h>
+
+namespace WebCore {
+
+// FIXME:: Closure is the Chromium-name for Function<void()>, but we may want something else for WebCore.
+typedef Function<void()> Closure;
+
+class HTMLParserThread {
+public:
+    static PassOwnPtr<HTMLParserThread> create()
+    {
+        return adoptPtr(new HTMLParserThread());
+    }
+    ~HTMLParserThread();
+
+    static HTMLParserThread* shared();
+
+    bool start();
+    void stop();
+
+    void postTask(const Closure&);
+
+    ThreadIdentifier threadId() const { return m_threadID; }
+
+private:
+    HTMLParserThread();
+
+    static void threadStart(void*);
+    void runLoop();
+
+    Mutex m_threadCreationMutex;
+    MessageQueue<Closure> m_queue;
+    ThreadIdentifier m_threadID;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(THREADED_HTML_PARSER)
+
+#endif // HTMLParserThread_h