Title: [101335] trunk/Source
Revision
101335
Author
dgro...@chromium.org
Date
2011-11-28 23:59:22 -0800 (Mon, 28 Nov 2011)

Log Message

WebWorkerRunLoop wrapper around WorkerRunLoop
https://bugs.webkit.org/show_bug.cgi?id=71757

Source/WebCore:

Reviewed by Darin Fisher.

No new tests - IndexedDB tests forthcoming.

* platform/chromium/PlatformSupport.h: Add two methods that allow
WebCore to notify chromium when workers start and stop.
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::workerThread): Call into PlatformSupport when
the worker's runloop is started and stopped.

Source/WebKit/chromium:

This allows the embedder to post tasks to webcore-created worker
threads.  WebWorkerRunLoop is a thin wrapper that just holds a
WorkerRunLoop*.  As such, it is not heap allocated and can be copied.

Reviewed by Darin Fisher.

* WebKit.gyp: Added WebWorkerRunLoop.{cpp,h}

* public/WebWorkerRunLoop.h: Added. Interface the embedder will use to
post Tasks to worker threads created in WebCore.
(WebKit::WebWorkerRunLoop::Task::~Task):
(WebKit::operator==): These are the operators necessary to allow
WebWorkerRunLoop to be used as a key in a std::map using the value of
the underlying WebCore::WorkerRunLoop* for the meaningful comparisons.
(WebKit::operator<):

* public/platform/WebKitPlatformSupport.h: Stubs for the embedder to
implement.
(WebKit::WebKitPlatformSupport::didStartWorkerRunLoop):
(WebKit::WebKitPlatformSupport::didStopWorkerRunLoop):

* src/PlatformSupport.cpp: Wrap incoming WorkerRunLoop objects in
WebWorkerRunLoopImpl objects, forward them to WebKitPlatformSupport.
(WebCore::PlatformSupport::didStartWorkerRunLoop):
(WebCore::PlatformSupport::didStopWorkerRunLoop):

* src/WebWorkerRunLoop.cpp: Added.
(WebKit::WebWorkerRunLoop::WebWorkerRunLoop): Store incoming
WorkerRunLoop pointer.
(WebKit::WebWorkerRunLoop::postTask): Wrap incoming Task in
ScriptExecutionContext::Task, post to stored WorkerRunLoop.
(WebKit::WebWorkerRunLoop::equals): Support for the operators mentioned
above.
(WebKit::WebWorkerRunLoop::lessThan): Ditto.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101334 => 101335)


--- trunk/Source/WebCore/ChangeLog	2011-11-29 07:57:23 UTC (rev 101334)
+++ trunk/Source/WebCore/ChangeLog	2011-11-29 07:59:22 UTC (rev 101335)
@@ -1,3 +1,18 @@
+2011-11-28  David Grogan  <dgro...@chromium.org>
+
+        WebWorkerRunLoop wrapper around WorkerRunLoop
+        https://bugs.webkit.org/show_bug.cgi?id=71757
+
+        Reviewed by Darin Fisher.
+
+        No new tests - IndexedDB tests forthcoming.
+
+        * platform/chromium/PlatformSupport.h: Add two methods that allow
+        WebCore to notify chromium when workers start and stop.
+        * workers/WorkerThread.cpp:
+        (WebCore::WorkerThread::workerThread): Call into PlatformSupport when
+        the worker's runloop is started and stopped.
+
 2011-11-29  Alexandru Chiculita  <ach...@adobe.com>
 
         [CSS Filters] Filters do not render correctly when the layer has a transform

Modified: trunk/Source/WebCore/platform/chromium/PlatformSupport.h (101334 => 101335)


--- trunk/Source/WebCore/platform/chromium/PlatformSupport.h	2011-11-29 07:57:23 UTC (rev 101334)
+++ trunk/Source/WebCore/platform/chromium/PlatformSupport.h	2011-11-29 07:59:22 UTC (rev 101335)
@@ -82,6 +82,7 @@
 class KURL;
 class SerializedScriptValue;
 class Widget;
+class WorkerRunLoop;
 
 struct Cookie;
 struct FontRenderStyle;
@@ -420,6 +421,9 @@
     static LinkHash visitedLinkHash(const UChar* url, unsigned length);
     static LinkHash visitedLinkHash(const KURL& base, const AtomicString& attributeURL);
     static bool isLinkVisited(LinkHash);
+
+    static void didStartWorkerRunLoop(WorkerRunLoop*);
+    static void didStopWorkerRunLoop(WorkerRunLoop*);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/WorkerThread.cpp (101334 => 101335)


--- trunk/Source/WebCore/workers/WorkerThread.cpp	2011-11-29 07:57:23 UTC (rev 101334)
+++ trunk/Source/WebCore/workers/WorkerThread.cpp	2011-11-29 07:59:22 UTC (rev 101335)
@@ -136,6 +136,9 @@
            m_workerContext->script()->forbidExecution();
         }
     }
+#if PLATFORM(CHROMIUM)
+    PlatformSupport::didStartWorkerRunLoop(&m_runLoop);
+#endif
 
     WorkerScriptController* script = m_workerContext->script();
 #if ENABLE(INSPECTOR)
@@ -149,6 +152,10 @@
 
     runEventLoop();
 
+#if PLATFORM(CHROMIUM)
+    PlatformSupport::didStopWorkerRunLoop(&m_runLoop);
+#endif
+
     ThreadIdentifier threadID = m_threadID;
 
     ASSERT(m_workerContext->hasOneRef());

Modified: trunk/Source/WebKit/chromium/ChangeLog (101334 => 101335)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-11-29 07:57:23 UTC (rev 101334)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-11-29 07:59:22 UTC (rev 101335)
@@ -1,3 +1,43 @@
+2011-11-28  David Grogan  <dgro...@chromium.org>
+
+        WebWorkerRunLoop wrapper around WorkerRunLoop
+        https://bugs.webkit.org/show_bug.cgi?id=71757
+
+        This allows the embedder to post tasks to webcore-created worker
+        threads.  WebWorkerRunLoop is a thin wrapper that just holds a
+        WorkerRunLoop*.  As such, it is not heap allocated and can be copied.
+
+        Reviewed by Darin Fisher.
+
+        * WebKit.gyp: Added WebWorkerRunLoop.{cpp,h}
+
+        * public/WebWorkerRunLoop.h: Added. Interface the embedder will use to
+        post Tasks to worker threads created in WebCore.
+        (WebKit::WebWorkerRunLoop::Task::~Task):
+        (WebKit::operator==): These are the operators necessary to allow
+        WebWorkerRunLoop to be used as a key in a std::map using the value of
+        the underlying WebCore::WorkerRunLoop* for the meaningful comparisons.
+        (WebKit::operator<):
+
+        * public/platform/WebKitPlatformSupport.h: Stubs for the embedder to
+        implement.
+        (WebKit::WebKitPlatformSupport::didStartWorkerRunLoop):
+        (WebKit::WebKitPlatformSupport::didStopWorkerRunLoop):
+
+        * src/PlatformSupport.cpp: Wrap incoming WorkerRunLoop objects in
+        WebWorkerRunLoopImpl objects, forward them to WebKitPlatformSupport.
+        (WebCore::PlatformSupport::didStartWorkerRunLoop):
+        (WebCore::PlatformSupport::didStopWorkerRunLoop):
+
+        * src/WebWorkerRunLoop.cpp: Added.
+        (WebKit::WebWorkerRunLoop::WebWorkerRunLoop): Store incoming
+        WorkerRunLoop pointer.
+        (WebKit::WebWorkerRunLoop::postTask): Wrap incoming Task in
+        ScriptExecutionContext::Task, post to stored WorkerRunLoop.
+        (WebKit::WebWorkerRunLoop::equals): Support for the operators mentioned
+        above.
+        (WebKit::WebWorkerRunLoop::lessThan): Ditto.
+
 2011-11-29  Roland Steiner  <rolandstei...@chromium.org>
 
         <style scoped>: add ENABLE(STYLE_SCOPED) flag to WebKit

Modified: trunk/Source/WebKit/chromium/WebKit.gyp (101334 => 101335)


--- trunk/Source/WebKit/chromium/WebKit.gyp	2011-11-29 07:57:23 UTC (rev 101334)
+++ trunk/Source/WebKit/chromium/WebKit.gyp	2011-11-29 07:59:22 UTC (rev 101335)
@@ -336,6 +336,7 @@
                 'public/WebWidgetClient.h',
                 'public/WebWorker.h',
                 'public/WebWorkerClient.h',
+                'public/WebWorkerRunLoop.h',
                 'public/win/WebInputEventFactory.h',
                 'public/win/WebSandboxSupport.h',
                 'public/win/WebScreenInfoFactory.h',
@@ -648,6 +649,7 @@
                 'src/WebWorkerClientImpl.h',
                 'src/WebWorkerImpl.cpp',
                 'src/WebWorkerImpl.h',
+                'src/WebWorkerRunLoop.cpp',
                 'src/WorkerAsyncFileSystemChromium.cpp',
                 'src/WorkerAsyncFileSystemChromium.h',
                 'src/WorkerAsyncFileWriterChromium.cpp',

Added: trunk/Source/WebKit/chromium/public/WebWorkerRunLoop.h (0 => 101335)


--- trunk/Source/WebKit/chromium/public/WebWorkerRunLoop.h	                        (rev 0)
+++ trunk/Source/WebKit/chromium/public/WebWorkerRunLoop.h	2011-11-29 07:59:22 UTC (rev 101335)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011 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:
+ * 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. 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 INC. 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.
+ */
+
+#ifndef WebWorkerRunLoop_h
+#define WebWorkerRunLoop_h
+
+#include "WebCommon.h"
+
+namespace WebCore {
+class WorkerRunLoop;
+}
+
+namespace WebKit {
+
+class WebWorkerRunLoop {
+public:
+    class Task {
+    public:
+        virtual ~Task() { }
+        virtual void Run() = 0;
+    };
+    WEBKIT_EXPORT void postTask(Task*);
+    WEBKIT_EXPORT bool equals(const WebWorkerRunLoop&) const;
+    WEBKIT_EXPORT bool lessThan(const WebWorkerRunLoop&) const;
+
+#if WEBKIT_IMPLEMENTATION
+    WebWorkerRunLoop(WebCore::WorkerRunLoop*);
+#endif
+
+private:
+    WebCore::WorkerRunLoop* m_workerRunLoop;
+};
+
+inline bool operator==(const WebWorkerRunLoop& a, const WebWorkerRunLoop& b)
+{
+    return a.equals(b);
+}
+
+inline bool operator<(const WebWorkerRunLoop& a, const WebWorkerRunLoop& b)
+{
+    return a.lessThan(b);
+}
+
+}
+
+#endif

Modified: trunk/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h (101334 => 101335)


--- trunk/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h	2011-11-29 07:57:23 UTC (rev 101334)
+++ trunk/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h	2011-11-29 07:59:22 UTC (rev 101335)
@@ -72,6 +72,7 @@
 class WebThemeEngine;
 class WebThread;
 class WebURLLoader;
+class WebWorkerRunLoop;
 
 class WebKitPlatformSupport {
 public:
@@ -334,6 +335,9 @@
     // May return null if WebRTC functionality is not avaliable or out of resources.
     virtual WebPeerConnectionHandler* createPeerConnectionHandler(WebPeerConnectionHandlerClient*) { return 0; }
 
+    virtual void didStartWorkerRunLoop(const WebWorkerRunLoop&) { }
+    virtual void didStopWorkerRunLoop(const WebWorkerRunLoop&) { }
+
 protected:
     ~WebKitPlatformSupport() { }
 };

Modified: trunk/Source/WebKit/chromium/src/PlatformSupport.cpp (101334 => 101335)


--- trunk/Source/WebKit/chromium/src/PlatformSupport.cpp	2011-11-29 07:57:23 UTC (rev 101334)
+++ trunk/Source/WebKit/chromium/src/PlatformSupport.cpp	2011-11-29 07:59:22 UTC (rev 101335)
@@ -61,6 +61,7 @@
 #include "WebViewClient.h"
 #include "WebViewImpl.h"
 #include "WebWorkerClientImpl.h"
+#include "WebWorkerRunLoop.h"
 
 #if USE(CG)
 #include <CoreGraphics/CGContext.h>
@@ -1099,6 +1100,16 @@
     return false;
 }
 
+void PlatformSupport::didStartWorkerRunLoop(WorkerRunLoop* loop)
+{
+    webKitPlatformSupport()->didStartWorkerRunLoop(WebWorkerRunLoop(loop));
+}
+
+void PlatformSupport::didStopWorkerRunLoop(WorkerRunLoop* loop)
+{
+    webKitPlatformSupport()->didStopWorkerRunLoop(WebWorkerRunLoop(loop));
+}
+
 #if ENABLE(WORKERS)
 WorkerContextProxy* WorkerContextProxy::create(Worker* worker)
 {

Added: trunk/Source/WebKit/chromium/src/WebWorkerRunLoop.cpp (0 => 101335)


--- trunk/Source/WebKit/chromium/src/WebWorkerRunLoop.cpp	                        (rev 0)
+++ trunk/Source/WebKit/chromium/src/WebWorkerRunLoop.cpp	2011-11-29 07:59:22 UTC (rev 101335)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2011 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:
+ * 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. 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 INC. 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"
+#include "WebWorkerRunLoop.h"
+
+#include "WorkerRunLoop.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+namespace {
+
+class TaskForwarder : public ScriptExecutionContext::Task {
+public:
+    static PassOwnPtr<TaskForwarder> create(PassOwnPtr<WebWorkerRunLoop::Task> task)
+    {
+        return adoptPtr(new TaskForwarder(task));
+    }
+
+    virtual void performTask(ScriptExecutionContext*)
+    {
+        m_task->Run();
+    }
+
+private:
+    TaskForwarder(PassOwnPtr<WebWorkerRunLoop::Task> task)
+        : m_task(task)
+    {
+    }
+
+    OwnPtr<WebWorkerRunLoop::Task> m_task;
+};
+
+}
+
+WebWorkerRunLoop::WebWorkerRunLoop(WorkerRunLoop* workerRunLoop)
+    : m_workerRunLoop(workerRunLoop)
+{
+}
+
+void WebWorkerRunLoop::postTask(Task* task)
+{
+    m_workerRunLoop->postTask(TaskForwarder::create(adoptPtr(task)));
+}
+
+bool WebWorkerRunLoop::equals(const WebWorkerRunLoop& o) const
+{
+    return m_workerRunLoop == o.m_workerRunLoop;
+}
+
+bool WebWorkerRunLoop::lessThan(const WebWorkerRunLoop& o) const
+{
+    return m_workerRunLoop < o.m_workerRunLoop;
+}
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to