OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 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 12 matching lines...) Expand all Loading... |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/dom/ScriptRunner.h" | 27 #include "core/dom/ScriptRunner.h" |
28 | 28 |
29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
30 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
31 #include "core/dom/ScriptLoader.h" | 31 #include "core/dom/ScriptLoader.h" |
32 #include "platform/heap/Handle.h" | 32 #include "platform/heap/Handle.h" |
| 33 #include "platform/scheduler/CancellableTaskFactory.h" |
33 #include "public/platform/Platform.h" | 34 #include "public/platform/Platform.h" |
34 #include "public/platform/WebScheduler.h" | 35 #include "public/platform/WebScheduler.h" |
35 #include "public/platform/WebThread.h" | 36 #include "public/platform/WebThread.h" |
36 #include "wtf/Functional.h" | |
37 | |
38 // This bit of magic is needed by oilpan to prevent the ScriptRunner from leakin
g. | |
39 namespace WTF { | |
40 template<> | |
41 struct ParamStorageTraits<blink::ScriptRunner*> : public PointerParamStorageTrai
ts<blink::ScriptRunner*, false> { | |
42 }; | |
43 } | |
44 | 37 |
45 namespace blink { | 38 namespace blink { |
46 | 39 |
47 | 40 |
48 ScriptRunner::ScriptRunner(Document* document) | 41 ScriptRunner::ScriptRunner(Document* document) |
49 : m_document(document) | 42 : m_document(document) |
50 , m_executeScriptsTaskFactory(WTF::bind(&ScriptRunner::executeScripts, this)
) | 43 , m_executeScriptsTaskFactory(CancellableTaskFactory::create(this, &ScriptRu
nner::executeScripts)) |
51 { | 44 { |
52 ASSERT(document); | 45 ASSERT(document); |
53 #if ENABLE(LAZY_SWEEPING) && defined(ADDRESS_SANITIZER) | |
54 m_executeScriptsTaskFactory.setUnpoisonBeforeUpdate(); | |
55 #endif | |
56 } | 46 } |
57 | 47 |
58 ScriptRunner::~ScriptRunner() | 48 ScriptRunner::~ScriptRunner() |
59 { | 49 { |
60 #if !ENABLE(OILPAN) | 50 #if !ENABLE(OILPAN) |
61 // Make sure that ScriptLoaders don't keep their PendingScripts alive. | 51 // Make sure that ScriptLoaders don't keep their PendingScripts alive. |
62 for (ScriptLoader* scriptLoader : m_scriptsToExecuteInOrder) | 52 for (ScriptLoader* scriptLoader : m_scriptsToExecuteInOrder) |
63 scriptLoader->detach(); | 53 scriptLoader->detach(); |
64 for (ScriptLoader* scriptLoader : m_scriptsToExecuteSoon) | 54 for (ScriptLoader* scriptLoader : m_scriptsToExecuteSoon) |
65 scriptLoader->detach(); | 55 scriptLoader->detach(); |
(...skipping 19 matching lines...) Expand all Loading... |
85 | 75 |
86 case IN_ORDER_EXECUTION: | 76 case IN_ORDER_EXECUTION: |
87 m_document->incrementLoadEventDelayCount(); | 77 m_document->incrementLoadEventDelayCount(); |
88 m_scriptsToExecuteInOrder.append(scriptLoader); | 78 m_scriptsToExecuteInOrder.append(scriptLoader); |
89 break; | 79 break; |
90 } | 80 } |
91 } | 81 } |
92 | 82 |
93 void ScriptRunner::suspend() | 83 void ScriptRunner::suspend() |
94 { | 84 { |
95 m_executeScriptsTaskFactory.cancel(); | 85 m_executeScriptsTaskFactory->cancel(); |
96 } | 86 } |
97 | 87 |
98 void ScriptRunner::resume() | 88 void ScriptRunner::resume() |
99 { | 89 { |
100 if (hasPendingScripts()) | 90 if (hasPendingScripts()) |
101 postTaskIfOneIsNotAlreadyInFlight(); | 91 postTaskIfOneIsNotAlreadyInFlight(); |
102 } | 92 } |
103 | 93 |
104 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
xecutionType) | 94 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
xecutionType) |
105 { | 95 { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 { | 207 { |
218 if (!Platform::current()->currentThread()->scheduler()->shouldYieldForHighPr
iorityWork()) | 208 if (!Platform::current()->currentThread()->scheduler()->shouldYieldForHighPr
iorityWork()) |
219 return false; | 209 return false; |
220 | 210 |
221 postTaskIfOneIsNotAlreadyInFlight(); | 211 postTaskIfOneIsNotAlreadyInFlight(); |
222 return true; | 212 return true; |
223 } | 213 } |
224 | 214 |
225 void ScriptRunner::postTaskIfOneIsNotAlreadyInFlight() | 215 void ScriptRunner::postTaskIfOneIsNotAlreadyInFlight() |
226 { | 216 { |
227 if (m_executeScriptsTaskFactory.isPending()) | 217 if (m_executeScriptsTaskFactory->isPending()) |
228 return; | 218 return; |
229 | 219 |
230 Platform::current()->currentThread()->scheduler()->loadingTaskRunner()->post
Task(FROM_HERE, m_executeScriptsTaskFactory.cancelAndCreate()); | 220 Platform::current()->currentThread()->scheduler()->loadingTaskRunner()->post
Task(FROM_HERE, m_executeScriptsTaskFactory->cancelAndCreate()); |
231 } | 221 } |
232 | 222 |
233 DEFINE_TRACE(ScriptRunner) | 223 DEFINE_TRACE(ScriptRunner) |
234 { | 224 { |
235 #if ENABLE(OILPAN) | 225 #if ENABLE(OILPAN) |
236 visitor->trace(m_document); | 226 visitor->trace(m_document); |
237 visitor->trace(m_scriptsToExecuteInOrder); | 227 visitor->trace(m_scriptsToExecuteInOrder); |
238 visitor->trace(m_scriptsToExecuteSoon); | 228 visitor->trace(m_scriptsToExecuteSoon); |
239 visitor->trace(m_pendingAsyncScripts); | 229 visitor->trace(m_pendingAsyncScripts); |
240 #endif | 230 #endif |
241 } | 231 } |
242 | 232 |
243 } | 233 } // namespace blink |
OLD | NEW |