| Index: Source/core/html/parser/HTMLParserScheduler.cpp
|
| diff --git a/Source/core/html/parser/HTMLParserScheduler.cpp b/Source/core/html/parser/HTMLParserScheduler.cpp
|
| index b234f684a237e3898d85e1e5fac40d770bea4795..6efa7521cbc94e6f4ce0a99ef717fb463908a44f 100644
|
| --- a/Source/core/html/parser/HTMLParserScheduler.cpp
|
| +++ b/Source/core/html/parser/HTMLParserScheduler.cpp
|
| @@ -29,6 +29,8 @@
|
| #include "core/dom/Document.h"
|
| #include "core/html/parser/HTMLDocumentParser.h"
|
| #include "core/frame/FrameView.h"
|
| +#include "platform/scheduler/Scheduler.h"
|
| +#include "wtf/CurrentTime.h"
|
|
|
| namespace blink {
|
|
|
| @@ -57,6 +59,21 @@ PumpSession::~PumpSession()
|
| {
|
| }
|
|
|
| +SpeculationsPumpSession::SpeculationsPumpSession(Document* document)
|
| + : ActiveParserSession(document)
|
| + , m_startTime(currentTime())
|
| +{
|
| +}
|
| +
|
| +SpeculationsPumpSession::~SpeculationsPumpSession()
|
| +{
|
| +}
|
| +
|
| +inline double SpeculationsPumpSession::elapsedTime() const
|
| +{
|
| + return currentTime() - m_startTime;
|
| +}
|
| +
|
| HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser)
|
| : m_parser(parser)
|
| , m_continueNextChunkTimer(this, &HTMLParserScheduler::continueNextChunkTimerFired)
|
| @@ -98,4 +115,26 @@ void HTMLParserScheduler::resume()
|
| m_continueNextChunkTimer.startOneShot(0, FROM_HERE);
|
| }
|
|
|
| +inline bool HTMLParserScheduler::shouldYield(const SpeculationsPumpSession& session) const
|
| +{
|
| + if (Scheduler::shared()->shouldYieldForHighPriorityWork())
|
| + return true;
|
| +
|
| + const double parserTimeLimit = 0.5;
|
| + if (session.elapsedTime() > parserTimeLimit)
|
| + return true;
|
| +
|
| + return false;
|
| +}
|
| +
|
| +bool HTMLParserScheduler::yieldIfNeeded(const SpeculationsPumpSession& session)
|
| +{
|
| + if (shouldYield(session)) {
|
| + scheduleForResume();
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| }
|
|
|