Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/MainThreadTaskRunner.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/MainThreadTaskRunner.cpp b/third_party/WebKit/Source/core/dom/MainThreadTaskRunner.cpp |
| index 4baf2bb94f13f155fc51ff676c29b0b9de58b08c..8ede5dfa62327d647d38e5879684efd9f3ee6a1a 100644 |
| --- a/third_party/WebKit/Source/core/dom/MainThreadTaskRunner.cpp |
| +++ b/third_party/WebKit/Source/core/dom/MainThreadTaskRunner.cpp |
| @@ -39,6 +39,7 @@ MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context) |
| : m_context(context) |
| , m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired) |
| , m_suspended(false) |
| + , m_weakFactory(this) |
| { |
| } |
| @@ -46,16 +47,11 @@ MainThreadTaskRunner::~MainThreadTaskRunner() |
| { |
| } |
| -DEFINE_TRACE(MainThreadTaskRunner) |
| -{ |
| - visitor->trace(m_context); |
| -} |
| - |
| void MainThreadTaskRunner::postTaskInternal(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task, bool isInspectorTask) |
| { |
| Platform::current()->mainThread()->getWebTaskRunner()->postTask(location, threadSafeBind( |
| &MainThreadTaskRunner::perform, |
| - CrossThreadWeakPersistentThisPointer<MainThreadTaskRunner>(this), |
| + AllowCrossThreadAccess(m_weakFactory.createWeakPtr()), |
| passed(std::move(task)), |
| isInspectorTask)); |
| } |
| @@ -74,6 +70,11 @@ void MainThreadTaskRunner::postInspectorTask(const WebTraceLocation& location, P |
| void MainThreadTaskRunner::perform(PassOwnPtr<ExecutionContextTask> task, bool isInspectorTask) |
| { |
| + // If the owner m_context is about to be swept then it |
| + // is no longer safe to access. |
| + if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) |
|
haraken
2016/05/04 03:21:33
Why was this check not needed before this CL?
sof
2016/05/04 05:17:39
The closure is constructed using CrossThreadWeakPe
|
| + return; |
| + |
| if (!isInspectorTask && (m_context->tasksNeedSuspension() || !m_pendingTasks.isEmpty())) { |
| m_pendingTasks.append(std::move(task)); |
| return; |
| @@ -101,6 +102,11 @@ void MainThreadTaskRunner::resume() |
| void MainThreadTaskRunner::pendingTasksTimerFired(Timer<MainThreadTaskRunner>*) |
| { |
| + // If the owner m_context is about to be swept then it |
| + // is no longer safe to access. |
| + if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) |
| + return; |
| + |
| while (!m_pendingTasks.isEmpty()) { |
| OwnPtr<ExecutionContextTask> task = m_pendingTasks[0].release(); |
| m_pendingTasks.remove(0); |