Changeset 50919 in webkit
- Timestamp:
- Nov 12, 2009 5:12:20 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r50918 r50919 1 2009-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 1 23 2009-11-12 Simon Fraser <simon.fraser@apple.com> 2 24 -
trunk/WebCore/dom/Document.cpp
r50675 r50919 4537 4537 } 4538 4538 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 4576 4539 void Document::postTask(PassOwnPtr<Task> task) 4577 4540 { 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); 4584 4542 } 4585 4543 -
trunk/WebCore/dom/ScriptExecutionContext.cpp
r50427 r50919 216 216 #endif 217 217 218 class ScriptExecutionContextTaskTimer : public TimerBase { 219 public: 220 ScriptExecutionContextTaskTimer(PassRefPtr<ScriptExecutionContext> context, PassOwnPtr<ScriptExecutionContext::Task> task) 221 : m_context(context) 222 , m_task(task) 223 { 224 } 225 226 private: 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 237 class PerformTaskData { 238 public: 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 252 private: 253 RefPtr<ScriptExecutionContext> m_context; 254 OwnPtr<ScriptExecutionContext::Task> m_task; 255 }; 256 257 void 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 218 267 } // namespace WebCore -
trunk/WebCore/dom/ScriptExecutionContext.h
r50427 r50919 115 115 void setSecurityOrigin(PassRefPtr<SecurityOrigin>); 116 116 117 // Helper for contexts that live on the main thread. 118 void postTaskToMainThread(PassOwnPtr<Task>); 119 117 120 private: 118 121 virtual const KURL& virtualURL() const = 0;
Note: See TracChangeset
for help on using the changeset viewer.