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 "config.h" | 5 #include "config.h" |
6 #include "core/dom/ScriptedIdleTaskController.h" | 6 #include "core/dom/ScriptedIdleTaskController.h" |
7 | 7 |
8 #include "core/dom/ExecutionContext.h" | 8 #include "core/dom/ExecutionContext.h" |
9 #include "core/dom/IdleRequestCallback.h" | 9 #include "core/dom/IdleRequestCallback.h" |
10 #include "core/dom/IdleRequestOptions.h" | 10 #include "core/dom/IdleRequestOptions.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 ActiveDOMObject::trace(visitor); | 77 ActiveDOMObject::trace(visitor); |
78 } | 78 } |
79 | 79 |
80 ScriptedIdleTaskController::CallbackId ScriptedIdleTaskController::registerCallb
ack(IdleRequestCallback* callback, const IdleRequestOptions& options) | 80 ScriptedIdleTaskController::CallbackId ScriptedIdleTaskController::registerCallb
ack(IdleRequestCallback* callback, const IdleRequestOptions& options) |
81 { | 81 { |
82 CallbackId id = ++m_nextCallbackId; | 82 CallbackId id = ++m_nextCallbackId; |
83 m_callbacks.set(id, callback); | 83 m_callbacks.set(id, callback); |
84 long long timeoutMillis = options.timeout(); | 84 long long timeoutMillis = options.timeout(); |
85 | 85 |
86 RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper = internal::Idl
eRequestCallbackWrapper::create(id, this); | 86 RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper = internal::Idl
eRequestCallbackWrapper::create(id, this); |
87 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&internal::IdleReques
tCallbackWrapper::idleTaskFired, callbackWrapper)); | 87 m_scheduler->postIdleTask(BLINK_FROM_HERE, WTF::bind<double>(&internal::Idle
RequestCallbackWrapper::idleTaskFired, callbackWrapper)); |
88 if (timeoutMillis > 0) | 88 if (timeoutMillis > 0) |
89 m_scheduler->timerTaskRunner()->postDelayedTask(FROM_HERE, WTF::bind(&in
ternal::IdleRequestCallbackWrapper::timeoutFired, callbackWrapper), timeoutMilli
s); | 89 m_scheduler->timerTaskRunner()->postDelayedTask(BLINK_FROM_HERE, WTF::bi
nd(&internal::IdleRequestCallbackWrapper::timeoutFired, callbackWrapper), timeou
tMillis); |
90 TRACE_EVENT_INSTANT1("devtools.timeline", "RequestIdleCallback", TRACE_EVENT
_SCOPE_THREAD, "data", InspectorIdleCallbackRequestEvent::data(executionContext(
), id, timeoutMillis)); | 90 TRACE_EVENT_INSTANT1("devtools.timeline", "RequestIdleCallback", TRACE_EVENT
_SCOPE_THREAD, "data", InspectorIdleCallbackRequestEvent::data(executionContext(
), id, timeoutMillis)); |
91 return id; | 91 return id; |
92 } | 92 } |
93 | 93 |
94 void ScriptedIdleTaskController::cancelCallback(CallbackId id) | 94 void ScriptedIdleTaskController::cancelCallback(CallbackId id) |
95 { | 95 { |
96 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelIdleCallback", TRACE_EVENT_
SCOPE_THREAD, "data", InspectorIdleCallbackCancelEvent::data(executionContext(),
id)); | 96 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelIdleCallback", TRACE_EVENT_
SCOPE_THREAD, "data", InspectorIdleCallbackCancelEvent::data(executionContext(),
id)); |
97 m_callbacks.remove(id); | 97 m_callbacks.remove(id); |
98 } | 98 } |
99 | 99 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 // Run any pending timeouts. | 150 // Run any pending timeouts. |
151 Vector<CallbackId> pendingTimeouts; | 151 Vector<CallbackId> pendingTimeouts; |
152 m_pendingTimeouts.swap(pendingTimeouts); | 152 m_pendingTimeouts.swap(pendingTimeouts); |
153 for (auto& id : pendingTimeouts) | 153 for (auto& id : pendingTimeouts) |
154 runCallback(id, monotonicallyIncreasingTime(), IdleDeadline::CallbackTyp
e::CalledByTimeout); | 154 runCallback(id, monotonicallyIncreasingTime(), IdleDeadline::CallbackTyp
e::CalledByTimeout); |
155 | 155 |
156 // Repost idle tasks for any remaining callbacks. | 156 // Repost idle tasks for any remaining callbacks. |
157 for (auto& callback : m_callbacks) { | 157 for (auto& callback : m_callbacks) { |
158 RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper = internal:
:IdleRequestCallbackWrapper::create(callback.key, this); | 158 RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper = internal:
:IdleRequestCallbackWrapper::create(callback.key, this); |
159 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&internal::IdleRe
questCallbackWrapper::idleTaskFired, callbackWrapper)); | 159 m_scheduler->postIdleTask(BLINK_FROM_HERE, WTF::bind<double>(&internal::
IdleRequestCallbackWrapper::idleTaskFired, callbackWrapper)); |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 bool ScriptedIdleTaskController::hasPendingActivity() const | 163 bool ScriptedIdleTaskController::hasPendingActivity() const |
164 { | 164 { |
165 return !m_callbacks.isEmpty(); | 165 return !m_callbacks.isEmpty(); |
166 } | 166 } |
167 | 167 |
168 } // namespace blink | 168 } // namespace blink |
OLD | NEW |