Changeset 50919 in webkit


Ignore:
Timestamp:
Nov 12, 2009 5:12:20 PM (14 years ago)
Author:
dimich@chromium.org
Message:

Add postTaskToMainThread to ScriptExecutionContext.
Move the code to post task to the main thread into a new method on ScriptExecutionContext,
to use as a helper implementation of the virtual ScriptExecutionContext::postTask(Task) in
contexts that live on the main thread.
https://bugs.webkit.org/show_bug.cgi?id=31427

Reviewed by Alexey Proskuryakov.

No new tests - simply moving the code.

  • dom/Document.cpp:

(WebCore::Document::postTask):

  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContextTaskTimer::ScriptExecutionContextTaskTimer):
(WebCore::ScriptExecutionContextTaskTimer::fired):
(WebCore::PerformTaskData::PerformTaskData):
(WebCore::PerformTaskData::performTask):
(WebCore::ScriptExecutionContext::postTaskToMainThread):

  • dom/ScriptExecutionContext.h:
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r50918 r50919  
     12009-11-12  Dmitry Titov  <dimich@chromium.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Add postTaskToMainThread to ScriptExecutionContext.
     6        Move the code to post task to the main thread into a new method on ScriptExecutionContext,
     7        to use as a helper implementation of the virtual ScriptExecutionContext::postTask(Task) in
     8        contexts that live on the main thread.
     9        https://bugs.webkit.org/show_bug.cgi?id=31427
     10
     11        No new tests - simply moving the code.
     12
     13        * dom/Document.cpp:
     14        (WebCore::Document::postTask):
     15        * dom/ScriptExecutionContext.cpp:
     16        (WebCore::ScriptExecutionContextTaskTimer::ScriptExecutionContextTaskTimer):
     17        (WebCore::ScriptExecutionContextTaskTimer::fired):
     18        (WebCore::PerformTaskData::PerformTaskData):
     19        (WebCore::PerformTaskData::performTask):
     20        (WebCore::ScriptExecutionContext::postTaskToMainThread):
     21        * dom/ScriptExecutionContext.h:
     22
    1232009-11-12  Simon Fraser  <simon.fraser@apple.com>
    224
  • trunk/WebCore/dom/Document.cpp

    r50675 r50919  
    45374537}
    45384538
    4539 class ScriptExecutionContextTaskTimer : public TimerBase {
    4540 public:
    4541     ScriptExecutionContextTaskTimer(PassRefPtr<Document> context, PassOwnPtr<ScriptExecutionContext::Task> task)
    4542         : m_context(context)
    4543         , m_task(task)
    4544     {
    4545     }
    4546 
    4547 private:
    4548     virtual void fired()
    4549     {
    4550         m_task->performTask(m_context.get());
    4551         delete this;
    4552     }
    4553 
    4554     RefPtr<Document> m_context;
    4555     OwnPtr<ScriptExecutionContext::Task> m_task;
    4556 };
    4557 
    4558 struct PerformTaskContext : Noncopyable {
    4559     PerformTaskContext(ScriptExecutionContext* scriptExecutionContext, PassOwnPtr<ScriptExecutionContext::Task> task)
    4560         : scriptExecutionContext(scriptExecutionContext)
    4561         , task(task)
    4562     {
    4563     }
    4564 
    4565     ScriptExecutionContext* scriptExecutionContext; // The context should exist until task execution.
    4566     OwnPtr<ScriptExecutionContext::Task> task;
    4567 };
    4568 
    4569 static void performTask(void* ctx)
    4570 {
    4571     PerformTaskContext* ptctx = reinterpret_cast<PerformTaskContext*>(ctx);
    4572     ptctx->task->performTask(ptctx->scriptExecutionContext);
    4573     delete ptctx;
    4574 }
    4575 
    45764539void Document::postTask(PassOwnPtr<Task> task)
    45774540{
    4578     if (isMainThread()) {
    4579         ScriptExecutionContextTaskTimer* timer = new ScriptExecutionContextTaskTimer(static_cast<Document*>(this), task);
    4580         timer->startOneShot(0);
    4581     } else {
    4582         callOnMainThread(performTask, new PerformTaskContext(this, task));
    4583     }
     4541    postTaskToMainThread(task);
    45844542}
    45854543
  • trunk/WebCore/dom/ScriptExecutionContext.cpp

    r50427 r50919  
    216216#endif
    217217
     218class ScriptExecutionContextTaskTimer : public TimerBase {
     219public:
     220    ScriptExecutionContextTaskTimer(PassRefPtr<ScriptExecutionContext> context, PassOwnPtr<ScriptExecutionContext::Task> task)
     221        : m_context(context)
     222        , m_task(task)
     223    {
     224    }
     225
     226private:
     227    virtual void fired()
     228    {
     229        m_task->performTask(m_context.get());
     230        delete this;
     231    }
     232
     233    RefPtr<ScriptExecutionContext> m_context;
     234    OwnPtr<ScriptExecutionContext::Task> m_task;
     235};
     236
     237class PerformTaskData {
     238public:
     239    PerformTaskData(PassRefPtr<ScriptExecutionContext> context, PassOwnPtr<ScriptExecutionContext::Task> task)
     240        : m_context(context)
     241        , m_task(task)
     242    {
     243    }
     244
     245    static void performTask(void* data)
     246    {
     247        PerformTaskData* taskData = static_cast<PerformTaskData*>(data);
     248        taskData->m_task->performTask(taskData->m_context.get());
     249        delete taskData;
     250    }
     251
     252private:
     253    RefPtr<ScriptExecutionContext> m_context;
     254    OwnPtr<ScriptExecutionContext::Task> m_task;
     255};
     256
     257void ScriptExecutionContext::postTaskToMainThread(PassOwnPtr<Task> task)
     258{
     259    if (isMainThread()) {
     260        ScriptExecutionContextTaskTimer* timer = new ScriptExecutionContextTaskTimer(this, task);
     261        timer->startOneShot(0);
     262    } else {
     263        callOnMainThread(PerformTaskData::performTask, new PerformTaskData(this, task));
     264    }
     265}
     266
    218267} // namespace WebCore
  • trunk/WebCore/dom/ScriptExecutionContext.h

    r50427 r50919  
    115115        void setSecurityOrigin(PassRefPtr<SecurityOrigin>);
    116116
     117        // Helper for contexts that live on the main thread.
     118        void postTaskToMainThread(PassOwnPtr<Task>);
     119
    117120    private:
    118121        virtual const KURL& virtualURL() const = 0;
Note: See TracChangeset for help on using the changeset viewer.