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

Unified Diff: Source/core/html/parser/HTMLParserScheduler.cpp

Issue 652813004: Move speculations pump scheduling logic to HTMLParserScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: explicit Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/parser/HTMLParserScheduler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+}
+
}
« no previous file with comments | « Source/core/html/parser/HTMLParserScheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698