Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: Source/core/dom/ScriptedIdleTaskController.cpp

Issue 1340263003: Rename IdleCallbackDeadline to IdleDeadline to be in sync with spec. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/ScriptedIdleTaskController.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "platform/Logging.h" 10 #include "platform/Logging.h"
(...skipping 14 matching lines...) Expand all
25 { 25 {
26 return adoptRef(new IdleRequestCallbackWrapper(id, controller)); 26 return adoptRef(new IdleRequestCallbackWrapper(id, controller));
27 } 27 }
28 virtual ~IdleRequestCallbackWrapper() 28 virtual ~IdleRequestCallbackWrapper()
29 { 29 {
30 } 30 }
31 31
32 static void idleTaskFired(PassRefPtr<IdleRequestCallbackWrapper> callbackWra pper, double deadlineSeconds) 32 static void idleTaskFired(PassRefPtr<IdleRequestCallbackWrapper> callbackWra pper, double deadlineSeconds)
33 { 33 {
34 // TODO(rmcilroy): Implement clamping of deadline in some form. 34 // TODO(rmcilroy): Implement clamping of deadline in some form.
35 callbackWrapper->controller()->callbackFired(callbackWrapper->id(), dead lineSeconds, IdleCallbackDeadline::CallbackType::CalledWhenIdle); 35 callbackWrapper->controller()->callbackFired(callbackWrapper->id(), dead lineSeconds, IdleDeadline::CallbackType::CalledWhenIdle);
36 } 36 }
37 37
38 static void timeoutFired(PassRefPtr<IdleRequestCallbackWrapper> callbackWrap per) 38 static void timeoutFired(PassRefPtr<IdleRequestCallbackWrapper> callbackWrap per)
39 { 39 {
40 callbackWrapper->controller()->callbackFired(callbackWrapper->id(), mono tonicallyIncreasingTime(), IdleCallbackDeadline::CallbackType::CalledByTimeout); 40 callbackWrapper->controller()->callbackFired(callbackWrapper->id(), mono tonicallyIncreasingTime(), IdleDeadline::CallbackType::CalledByTimeout);
41 } 41 }
42 42
43 ScriptedIdleTaskController::CallbackId id() const { return m_id; } 43 ScriptedIdleTaskController::CallbackId id() const { return m_id; }
44 PassRefPtrWillBeRawPtr<ScriptedIdleTaskController> controller() const { retu rn m_controller; } 44 PassRefPtrWillBeRawPtr<ScriptedIdleTaskController> controller() const { retu rn m_controller; }
45 45
46 private: 46 private:
47 IdleRequestCallbackWrapper(ScriptedIdleTaskController::CallbackId id, PassRe fPtrWillBeRawPtr<ScriptedIdleTaskController> controller) 47 IdleRequestCallbackWrapper(ScriptedIdleTaskController::CallbackId id, PassRe fPtrWillBeRawPtr<ScriptedIdleTaskController> controller)
48 : m_id(id) 48 : m_id(id)
49 , m_controller(controller) 49 , m_controller(controller)
50 { 50 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // TODO(rmcilroy): Add devtools tracing. 88 // TODO(rmcilroy): Add devtools tracing.
89 return id; 89 return id;
90 } 90 }
91 91
92 void ScriptedIdleTaskController::cancelCallback(CallbackId id) 92 void ScriptedIdleTaskController::cancelCallback(CallbackId id)
93 { 93 {
94 // TODO(rmcilroy): Add devtools tracing. 94 // TODO(rmcilroy): Add devtools tracing.
95 m_callbacks.remove(id); 95 m_callbacks.remove(id);
96 } 96 }
97 97
98 void ScriptedIdleTaskController::callbackFired(CallbackId id, double deadlineSec onds, IdleCallbackDeadline::CallbackType callbackType) 98 void ScriptedIdleTaskController::callbackFired(CallbackId id, double deadlineSec onds, IdleDeadline::CallbackType callbackType)
99 { 99 {
100 if (!m_callbacks.contains(id)) 100 if (!m_callbacks.contains(id))
101 return; 101 return;
102 102
103 if (m_suspended) { 103 if (m_suspended) {
104 if (callbackType == IdleCallbackDeadline::CallbackType::CalledByTimeout) { 104 if (callbackType == IdleDeadline::CallbackType::CalledByTimeout) {
105 // Queue for execution when we are resumed. 105 // Queue for execution when we are resumed.
106 m_pendingTimeouts.append(id); 106 m_pendingTimeouts.append(id);
107 } 107 }
108 // Just drop callbacks called while suspended, these will be reposted on the idle task queue when we are resumed. 108 // Just drop callbacks called while suspended, these will be reposted on the idle task queue when we are resumed.
109 return; 109 return;
110 } 110 }
111 111
112 runCallback(id, deadlineSeconds, callbackType); 112 runCallback(id, deadlineSeconds, callbackType);
113 } 113 }
114 114
115 void ScriptedIdleTaskController::runCallback(CallbackId id, double deadlineSecon ds, IdleCallbackDeadline::CallbackType callbackType) 115 void ScriptedIdleTaskController::runCallback(CallbackId id, double deadlineSecon ds, IdleDeadline::CallbackType callbackType)
116 { 116 {
117 ASSERT(!m_suspended); 117 ASSERT(!m_suspended);
118 auto callback = m_callbacks.take(id); 118 auto callback = m_callbacks.take(id);
119 if (!callback) 119 if (!callback)
120 return; 120 return;
121 121
122 // TODO(rmcilroy): Add devtools tracing. 122 // TODO(rmcilroy): Add devtools tracing.
123 callback->handleEvent(IdleCallbackDeadline::create(deadlineSeconds, callback Type)); 123 callback->handleEvent(IdleDeadline::create(deadlineSeconds, callbackType));
124 } 124 }
125 125
126 void ScriptedIdleTaskController::stop() 126 void ScriptedIdleTaskController::stop()
127 { 127 {
128 m_callbacks.clear(); 128 m_callbacks.clear();
129 } 129 }
130 130
131 void ScriptedIdleTaskController::suspend() 131 void ScriptedIdleTaskController::suspend()
132 { 132 {
133 m_suspended = true; 133 m_suspended = true;
134 } 134 }
135 135
136 void ScriptedIdleTaskController::resume() 136 void ScriptedIdleTaskController::resume()
137 { 137 {
138 ASSERT(m_suspended); 138 ASSERT(m_suspended);
139 m_suspended = false; 139 m_suspended = false;
140 140
141 // Run any pending timeouts. 141 // Run any pending timeouts.
142 Vector<CallbackId> pendingTimeouts; 142 Vector<CallbackId> pendingTimeouts;
143 m_pendingTimeouts.swap(pendingTimeouts); 143 m_pendingTimeouts.swap(pendingTimeouts);
144 for (auto& id : pendingTimeouts) 144 for (auto& id : pendingTimeouts)
145 runCallback(id, monotonicallyIncreasingTime(), IdleCallbackDeadline::Cal lbackType::CalledByTimeout); 145 runCallback(id, monotonicallyIncreasingTime(), IdleDeadline::CallbackTyp e::CalledByTimeout);
146 146
147 // Repost idle tasks for any remaining callbacks. 147 // Repost idle tasks for any remaining callbacks.
148 for (auto& callback : m_callbacks) { 148 for (auto& callback : m_callbacks) {
149 RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper = internal: :IdleRequestCallbackWrapper::create(callback.key, this); 149 RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper = internal: :IdleRequestCallbackWrapper::create(callback.key, this);
150 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&internal::IdleRe questCallbackWrapper::idleTaskFired, callbackWrapper)); 150 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&internal::IdleRe questCallbackWrapper::idleTaskFired, callbackWrapper));
151 } 151 }
152 } 152 }
153 153
154 bool ScriptedIdleTaskController::hasPendingActivity() const 154 bool ScriptedIdleTaskController::hasPendingActivity() const
155 { 155 {
156 return !m_callbacks.isEmpty(); 156 return !m_callbacks.isEmpty();
157 } 157 }
158 158
159 } // namespace blink 159 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/ScriptedIdleTaskController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698