| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2013 Google Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 , m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired) | 40 , m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired) |
| 41 , m_suspended(false) | 41 , m_suspended(false) |
| 42 , m_weakFactory(this) | 42 , m_weakFactory(this) |
| 43 { | 43 { |
| 44 } | 44 } |
| 45 | 45 |
| 46 MainThreadTaskRunner::~MainThreadTaskRunner() | 46 MainThreadTaskRunner::~MainThreadTaskRunner() |
| 47 { | 47 { |
| 48 } | 48 } |
| 49 | 49 |
| 50 void MainThreadTaskRunner::postTaskInternal(const WebTraceLocation& location, st
d::unique_ptr<ExecutionContextTask> task, bool isInspectorTask) | 50 void MainThreadTaskRunner::postTaskInternal(const WebTraceLocation& location, st
d::unique_ptr<ExecutionContextTask> task, bool isInspectorTask, bool instrumenti
ng) |
| 51 { | 51 { |
| 52 Platform::current()->mainThread()->getWebTaskRunner()->postTask(location, th
readSafeBind( | 52 Platform::current()->mainThread()->getWebTaskRunner()->postTask(location, th
readSafeBind( |
| 53 &MainThreadTaskRunner::perform, | 53 &MainThreadTaskRunner::perform, |
| 54 m_weakFactory.createWeakPtr(), | 54 m_weakFactory.createWeakPtr(), |
| 55 passed(std::move(task)), | 55 passed(std::move(task)), |
| 56 isInspectorTask)); | 56 isInspectorTask, |
| 57 instrumenting)); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, std::uniqu
e_ptr<ExecutionContextTask> task) | 60 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, std::uniqu
e_ptr<ExecutionContextTask> task, const String& taskNameForInstrumentation) |
| 60 { | 61 { |
| 61 if (!task->taskNameForInstrumentation().isEmpty()) | 62 if (!taskNameForInstrumentation.isEmpty()) |
| 62 InspectorInstrumentation::asyncTaskScheduled(m_context, task->taskNameFo
rInstrumentation(), task.get()); | 63 InspectorInstrumentation::asyncTaskScheduled(m_context, taskNameForInstr
umentation, task.get()); |
| 63 postTaskInternal(location, std::move(task), false); | 64 const bool instrumenting = !taskNameForInstrumentation.isEmpty(); |
| 65 postTaskInternal(location, std::move(task), false, instrumenting); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void MainThreadTaskRunner::postInspectorTask(const WebTraceLocation& location, s
td::unique_ptr<ExecutionContextTask> task) | 68 void MainThreadTaskRunner::postInspectorTask(const WebTraceLocation& location, s
td::unique_ptr<ExecutionContextTask> task) |
| 67 { | 69 { |
| 68 postTaskInternal(location, std::move(task), true); | 70 postTaskInternal(location, std::move(task), true, false); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void MainThreadTaskRunner::perform(std::unique_ptr<ExecutionContextTask> task, b
ool isInspectorTask) | 73 void MainThreadTaskRunner::perform(std::unique_ptr<ExecutionContextTask> task, b
ool isInspectorTask, bool instrumenting) |
| 72 { | 74 { |
| 73 // If the owner m_context is about to be swept then it | 75 // If the owner m_context is about to be swept then it |
| 74 // is no longer safe to access. | 76 // is no longer safe to access. |
| 75 if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) | 77 if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) |
| 76 return; | 78 return; |
| 77 | 79 |
| 78 if (!isInspectorTask && (m_context->tasksNeedSuspension() || !m_pendingTasks
.isEmpty())) { | 80 if (!isInspectorTask && (m_context->tasksNeedSuspension() || !m_pendingTasks
.isEmpty())) { |
| 79 m_pendingTasks.append(std::move(task)); | 81 m_pendingTasks.append(make_pair(std::move(task), instrumenting)); |
| 80 return; | 82 return; |
| 81 } | 83 } |
| 82 | 84 |
| 83 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), !isInsp
ectorTask); | 85 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), !isInsp
ectorTask); |
| 84 task->performTask(m_context); | 86 task->performTask(m_context); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void MainThreadTaskRunner::suspend() | 89 void MainThreadTaskRunner::suspend() |
| 88 { | 90 { |
| 89 DCHECK(!m_suspended); | 91 DCHECK(!m_suspended); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 101 } | 103 } |
| 102 | 104 |
| 103 void MainThreadTaskRunner::pendingTasksTimerFired(Timer<MainThreadTaskRunner>*) | 105 void MainThreadTaskRunner::pendingTasksTimerFired(Timer<MainThreadTaskRunner>*) |
| 104 { | 106 { |
| 105 // If the owner m_context is about to be swept then it | 107 // If the owner m_context is about to be swept then it |
| 106 // is no longer safe to access. | 108 // is no longer safe to access. |
| 107 if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) | 109 if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) |
| 108 return; | 110 return; |
| 109 | 111 |
| 110 while (!m_pendingTasks.isEmpty()) { | 112 while (!m_pendingTasks.isEmpty()) { |
| 111 std::unique_ptr<ExecutionContextTask> task = std::move(m_pendingTasks[0]
); | 113 std::unique_ptr<ExecutionContextTask> task = std::move(m_pendingTasks[0]
.first); |
| 114 const bool instrumenting = m_pendingTasks[0].second; |
| 112 m_pendingTasks.remove(0); | 115 m_pendingTasks.remove(0); |
| 113 const bool instrumenting = !task->taskNameForInstrumentation().isEmpty()
; | |
| 114 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), ins
trumenting); | 116 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), ins
trumenting); |
| 115 task->performTask(m_context); | 117 task->performTask(m_context); |
| 116 } | 118 } |
| 117 } | 119 } |
| 118 | 120 |
| 119 } // namespace blink | 121 } // namespace blink |
| OLD | NEW |