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

Side by Side Diff: Source/core/html/parser/HTMLParserScheduler.cpp

Issue 876623002: Adds a CancellableTaskFactory and exposes postLoadingTasks to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Bundle in the HTML Parser changes too Created 5 years, 11 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
OLDNEW
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
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/html/parser/HTMLParserScheduler.h" 27 #include "core/html/parser/HTMLParserScheduler.h"
28 28
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/html/parser/HTMLDocumentParser.h" 30 #include "core/html/parser/HTMLDocumentParser.h"
31 #include "core/frame/FrameView.h" 31 #include "core/frame/FrameView.h"
32 #include "platform/scheduler/Scheduler.h" 32 #include "platform/scheduler/Scheduler.h"
33 #include "public/platform/Platform.h"
34 #include "public/platform/WebTraceLocation.h"
33 #include "wtf/CurrentTime.h" 35 #include "wtf/CurrentTime.h"
34 36
35 namespace blink { 37 namespace blink {
36 38
37 ActiveParserSession::ActiveParserSession(unsigned& nestingLevel, Document* docum ent) 39 ActiveParserSession::ActiveParserSession(unsigned& nestingLevel, Document* docum ent)
38 : NestingLevelIncrementer(nestingLevel) 40 : NestingLevelIncrementer(nestingLevel)
39 , m_document(document) 41 , m_document(document)
40 { 42 {
41 if (!m_document) 43 if (!m_document)
42 return; 44 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 return currentTime() - m_startTime; 77 return currentTime() - m_startTime;
76 } 78 }
77 79
78 void SpeculationsPumpSession::addedElementTokens(size_t count) 80 void SpeculationsPumpSession::addedElementTokens(size_t count)
79 { 81 {
80 m_processedElementTokens += count; 82 m_processedElementTokens += count;
81 } 83 }
82 84
83 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser) 85 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser)
84 : m_parser(parser) 86 : m_parser(parser)
85 , m_continueNextChunkTimer(this, &HTMLParserScheduler::continueNextChunkTime rFired) 87 , m_cancelableContinueParse(WTF::bind(&HTMLDocumentParser::resumeParsingAfte rYield, m_parser))
86 , m_isSuspendedWithActiveTimer(false) 88 , m_isSuspendedWithActiveTimer(false)
87 { 89 {
88 } 90 }
89 91
90 HTMLParserScheduler::~HTMLParserScheduler() 92 HTMLParserScheduler::~HTMLParserScheduler()
91 { 93 {
92 m_continueNextChunkTimer.stop();
93 }
94
95 void HTMLParserScheduler::continueNextChunkTimerFired(Timer<HTMLParserScheduler> * timer)
96 {
97 ASSERT_UNUSED(timer, timer == &m_continueNextChunkTimer);
98 m_parser->resumeParsingAfterYield();
99 } 94 }
100 95
101 void HTMLParserScheduler::scheduleForResume() 96 void HTMLParserScheduler::scheduleForResume()
102 { 97 {
103 ASSERT(!m_isSuspendedWithActiveTimer); 98 Platform::current()->scheduler()->postLoadingTask(WebTraceLocation(FROM_HERE ), m_cancelableContinueParse.task());
104 m_continueNextChunkTimer.startOneShot(0, FROM_HERE);
105 } 99 }
106 100
107 void HTMLParserScheduler::suspend() 101 void HTMLParserScheduler::suspend()
108 { 102 {
109 ASSERT(!m_isSuspendedWithActiveTimer); 103 ASSERT(!m_isSuspendedWithActiveTimer);
110 if (!m_continueNextChunkTimer.isActive()) 104 if (!m_cancelableContinueParse.isPending())
111 return; 105 return;
112 m_isSuspendedWithActiveTimer = true; 106 m_isSuspendedWithActiveTimer = true;
113 m_continueNextChunkTimer.stop(); 107 m_cancelableContinueParse.cancel();
114 } 108 }
115 109
116 void HTMLParserScheduler::resume() 110 void HTMLParserScheduler::resume()
117 { 111 {
118 ASSERT(!m_continueNextChunkTimer.isActive()); 112 ASSERT(!m_cancelableContinueParse.isPending());
119 if (!m_isSuspendedWithActiveTimer) 113 if (!m_isSuspendedWithActiveTimer)
120 return; 114 return;
121 m_isSuspendedWithActiveTimer = false; 115 m_isSuspendedWithActiveTimer = false;
122 m_continueNextChunkTimer.startOneShot(0, FROM_HERE); 116 Platform::current()->scheduler()->postLoadingTask(WebTraceLocation(FROM_HERE ), m_cancelableContinueParse.task());
Sami 2015/01/26 17:18:34 I think it's a little unfortunate that we need to
alex clarke (OOO till 29th) 2015/01/26 17:31:35 If we do that we'll have the following nested thin
123 } 117 }
124 118
125 inline bool HTMLParserScheduler::shouldYield(const SpeculationsPumpSession& sess ion, bool startingScript) const 119 inline bool HTMLParserScheduler::shouldYield(const SpeculationsPumpSession& sess ion, bool startingScript) const
126 { 120 {
127 if (Scheduler::shared()->shouldYieldForHighPriorityWork()) 121 if (Scheduler::shared()->shouldYieldForHighPriorityWork())
128 return true; 122 return true;
129 123
130 const double parserTimeLimit = 0.5; 124 const double parserTimeLimit = 0.5;
131 if (session.elapsedTime() > parserTimeLimit) 125 if (session.elapsedTime() > parserTimeLimit)
132 return true; 126 return true;
(...skipping 18 matching lines...) Expand all
151 if (shouldYield(session, startingScript)) { 145 if (shouldYield(session, startingScript)) {
152 scheduleForResume(); 146 scheduleForResume();
153 return true; 147 return true;
154 } 148 }
155 149
156 return false; 150 return false;
157 } 151 }
158 152
159 void HTMLParserScheduler::forceResumeAfterYield() 153 void HTMLParserScheduler::forceResumeAfterYield()
160 { 154 {
161 ASSERT(!m_continueNextChunkTimer.isActive()); 155 ASSERT(!m_cancelableContinueParse.isPending());
162 m_isSuspendedWithActiveTimer = true; 156 m_isSuspendedWithActiveTimer = true;
163 } 157 }
164 158
165 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698