Chromium Code Reviews| 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..31ab010bc14a7a15d2abbde520216a20bd5f4393 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) |
| +{ |
| + if (Scheduler::shared()->shouldYieldForHighPriorityWork()) |
| + return true; |
| + |
| + const double parserTimeLimit = 0.500; |
|
Sami
2014/10/16 12:46:25
nit: no need for the trailing zeros.
kouhei (in TOK)
2014/10/16 12:54:19
Done.
|
| + if (session.elapsedTime() > parserTimeLimit) |
| + return true; |
| + |
| + return false; |
| +} |
| + |
| +bool HTMLParserScheduler::yieldIfNeeded(const SpeculationsPumpSession& session) |
| +{ |
| + if (shouldYield(session)) { |
| + scheduleForResume(); |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| } |