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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/core/html/parser/HTMLParserScheduler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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"
33 #include "wtf/CurrentTime.h"
32 34
33 namespace blink { 35 namespace blink {
34 36
35 ActiveParserSession::ActiveParserSession(Document* document) 37 ActiveParserSession::ActiveParserSession(Document* document)
36 : m_document(document) 38 : m_document(document)
37 { 39 {
38 if (!m_document) 40 if (!m_document)
39 return; 41 return;
40 m_document->incrementActiveParserCount(); 42 m_document->incrementActiveParserCount();
41 } 43 }
42 44
43 ActiveParserSession::~ActiveParserSession() 45 ActiveParserSession::~ActiveParserSession()
44 { 46 {
45 if (!m_document) 47 if (!m_document)
46 return; 48 return;
47 m_document->decrementActiveParserCount(); 49 m_document->decrementActiveParserCount();
48 } 50 }
49 51
50 PumpSession::PumpSession(unsigned& nestingLevel, Document* document) 52 PumpSession::PumpSession(unsigned& nestingLevel, Document* document)
51 : NestingLevelIncrementer(nestingLevel) 53 : NestingLevelIncrementer(nestingLevel)
52 , ActiveParserSession(document) 54 , ActiveParserSession(document)
53 { 55 {
54 } 56 }
55 57
56 PumpSession::~PumpSession() 58 PumpSession::~PumpSession()
57 { 59 {
58 } 60 }
59 61
62 SpeculationsPumpSession::SpeculationsPumpSession(Document* document)
63 : ActiveParserSession(document)
64 , m_startTime(currentTime())
65 {
66 }
67
68 SpeculationsPumpSession::~SpeculationsPumpSession()
69 {
70 }
71
72 inline double SpeculationsPumpSession::elapsedTime() const
73 {
74 return currentTime() - m_startTime;
75 }
76
60 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser) 77 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser)
61 : m_parser(parser) 78 : m_parser(parser)
62 , m_continueNextChunkTimer(this, &HTMLParserScheduler::continueNextChunkTime rFired) 79 , m_continueNextChunkTimer(this, &HTMLParserScheduler::continueNextChunkTime rFired)
63 , m_isSuspendedWithActiveTimer(false) 80 , m_isSuspendedWithActiveTimer(false)
64 { 81 {
65 } 82 }
66 83
67 HTMLParserScheduler::~HTMLParserScheduler() 84 HTMLParserScheduler::~HTMLParserScheduler()
68 { 85 {
69 m_continueNextChunkTimer.stop(); 86 m_continueNextChunkTimer.stop();
(...skipping 21 matching lines...) Expand all
91 108
92 void HTMLParserScheduler::resume() 109 void HTMLParserScheduler::resume()
93 { 110 {
94 ASSERT(!m_continueNextChunkTimer.isActive()); 111 ASSERT(!m_continueNextChunkTimer.isActive());
95 if (!m_isSuspendedWithActiveTimer) 112 if (!m_isSuspendedWithActiveTimer)
96 return; 113 return;
97 m_isSuspendedWithActiveTimer = false; 114 m_isSuspendedWithActiveTimer = false;
98 m_continueNextChunkTimer.startOneShot(0, FROM_HERE); 115 m_continueNextChunkTimer.startOneShot(0, FROM_HERE);
99 } 116 }
100 117
118 inline bool HTMLParserScheduler::shouldYield(const SpeculationsPumpSession& sess ion) const
119 {
120 if (Scheduler::shared()->shouldYieldForHighPriorityWork())
121 return true;
122
123 const double parserTimeLimit = 0.5;
124 if (session.elapsedTime() > parserTimeLimit)
125 return true;
126
127 return false;
101 } 128 }
129
130 bool HTMLParserScheduler::yieldIfNeeded(const SpeculationsPumpSession& session)
131 {
132 if (shouldYield(session)) {
133 scheduleForResume();
134 return true;
135 }
136
137 return false;
138 }
139
140 }
OLDNEW
« 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