| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/ScriptedIdleTaskController.h" | 5 #include "core/dom/ScriptedIdleTaskController.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/dom/IdleRequestCallback.h" | 8 #include "core/dom/IdleRequestCallback.h" |
| 9 #include "core/dom/IdleRequestOptions.h" | 9 #include "core/dom/IdleRequestOptions.h" |
| 10 #include "core/inspector/InspectorTraceEvents.h" | 10 #include "core/inspector/InspectorTraceEvents.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 118 } |
| 119 // Just drop callbacks called while suspended, these will be reposted on
the idle task queue when we are resumed. | 119 // Just drop callbacks called while suspended, these will be reposted on
the idle task queue when we are resumed. |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 runCallback(id, deadlineSeconds, callbackType); | 123 runCallback(id, deadlineSeconds, callbackType); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ScriptedIdleTaskController::runCallback(CallbackId id, double deadlineSecon
ds, IdleDeadline::CallbackType callbackType) | 126 void ScriptedIdleTaskController::runCallback(CallbackId id, double deadlineSecon
ds, IdleDeadline::CallbackType callbackType) |
| 127 { | 127 { |
| 128 ASSERT(!m_suspended); | 128 DCHECK(!m_suspended); |
| 129 auto callback = m_callbacks.take(id); | 129 auto callback = m_callbacks.take(id); |
| 130 if (!callback) | 130 if (!callback) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 double allottedTimeMillis = std::max((deadlineSeconds - monotonicallyIncreas
ingTime()) * 1000, 0.0); | 133 double allottedTimeMillis = std::max((deadlineSeconds - monotonicallyIncreas
ingTime()) * 1000, 0.0); |
| 134 | 134 |
| 135 DEFINE_STATIC_LOCAL(CustomCountHistogram, idleCallbackDeadlineHistogram, ("W
ebCore.ScriptedIdleTaskController.IdleCallbackDeadline", 0, 50, 50)); | 135 DEFINE_STATIC_LOCAL(CustomCountHistogram, idleCallbackDeadlineHistogram, ("W
ebCore.ScriptedIdleTaskController.IdleCallbackDeadline", 0, 50, 50)); |
| 136 idleCallbackDeadlineHistogram.count(allottedTimeMillis); | 136 idleCallbackDeadlineHistogram.count(allottedTimeMillis); |
| 137 | 137 |
| 138 TRACE_EVENT1("devtools.timeline", "FireIdleCallback", | 138 TRACE_EVENT1("devtools.timeline", "FireIdleCallback", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 150 m_callbacks.clear(); | 150 m_callbacks.clear(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void ScriptedIdleTaskController::suspend() | 153 void ScriptedIdleTaskController::suspend() |
| 154 { | 154 { |
| 155 m_suspended = true; | 155 m_suspended = true; |
| 156 } | 156 } |
| 157 | 157 |
| 158 void ScriptedIdleTaskController::resume() | 158 void ScriptedIdleTaskController::resume() |
| 159 { | 159 { |
| 160 ASSERT(m_suspended); | 160 DCHECK(m_suspended); |
| 161 m_suspended = false; | 161 m_suspended = false; |
| 162 | 162 |
| 163 // Run any pending timeouts. | 163 // Run any pending timeouts. |
| 164 Vector<CallbackId> pendingTimeouts; | 164 Vector<CallbackId> pendingTimeouts; |
| 165 m_pendingTimeouts.swap(pendingTimeouts); | 165 m_pendingTimeouts.swap(pendingTimeouts); |
| 166 for (auto& id : pendingTimeouts) | 166 for (auto& id : pendingTimeouts) |
| 167 runCallback(id, monotonicallyIncreasingTime(), IdleDeadline::CallbackTyp
e::CalledByTimeout); | 167 runCallback(id, monotonicallyIncreasingTime(), IdleDeadline::CallbackTyp
e::CalledByTimeout); |
| 168 | 168 |
| 169 // Repost idle tasks for any remaining callbacks. | 169 // Repost idle tasks for any remaining callbacks. |
| 170 for (auto& callback : m_callbacks) { | 170 for (auto& callback : m_callbacks) { |
| 171 RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper = internal:
:IdleRequestCallbackWrapper::create(callback.key, this); | 171 RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper = internal:
:IdleRequestCallbackWrapper::create(callback.key, this); |
| 172 m_scheduler->postIdleTask(BLINK_FROM_HERE, WTF::bind<double>(&internal::
IdleRequestCallbackWrapper::idleTaskFired, callbackWrapper)); | 172 m_scheduler->postIdleTask(BLINK_FROM_HERE, WTF::bind<double>(&internal::
IdleRequestCallbackWrapper::idleTaskFired, callbackWrapper)); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |