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

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: Rebase Created 5 years, 10 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') | Source/platform/blink_platform.gypi » ('j') | 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 return currentTime() - m_startTime; 75 return currentTime() - m_startTime;
76 } 76 }
77 77
78 void SpeculationsPumpSession::addedElementTokens(size_t count) 78 void SpeculationsPumpSession::addedElementTokens(size_t count)
79 { 79 {
80 m_processedElementTokens += count; 80 m_processedElementTokens += count;
81 } 81 }
82 82
83 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser) 83 HTMLParserScheduler::HTMLParserScheduler(HTMLDocumentParser* parser)
84 : m_parser(parser) 84 : m_parser(parser)
85 , m_continueNextChunkTimer(this, &HTMLParserScheduler::continueNextChunkTime rFired) 85 , m_cancellableContinueParse(WTF::bind(&HTMLDocumentParser::resumeParsingAft erYield, m_parser))
86 , m_isSuspendedWithActiveTimer(false) 86 , m_isSuspendedWithActiveTimer(false)
87 { 87 {
88 } 88 }
89 89
90 HTMLParserScheduler::~HTMLParserScheduler() 90 HTMLParserScheduler::~HTMLParserScheduler()
91 { 91 {
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 } 92 }
100 93
101 void HTMLParserScheduler::scheduleForResume() 94 void HTMLParserScheduler::scheduleForResume()
102 { 95 {
103 ASSERT(!m_isSuspendedWithActiveTimer); 96 ASSERT(!m_isSuspendedWithActiveTimer);
104 m_continueNextChunkTimer.startOneShot(0, FROM_HERE); 97 Scheduler::shared()->postLoadingTask(FROM_HERE, m_cancellableContinueParse.t ask());
105 } 98 }
106 99
107 void HTMLParserScheduler::suspend() 100 void HTMLParserScheduler::suspend()
108 { 101 {
109 ASSERT(!m_isSuspendedWithActiveTimer); 102 ASSERT(!m_isSuspendedWithActiveTimer);
110 if (!m_continueNextChunkTimer.isActive()) 103 if (!m_cancellableContinueParse.isPending())
111 return; 104 return;
112 m_isSuspendedWithActiveTimer = true; 105 m_isSuspendedWithActiveTimer = true;
113 m_continueNextChunkTimer.stop(); 106 m_cancellableContinueParse.cancel();
114 } 107 }
115 108
116 void HTMLParserScheduler::resume() 109 void HTMLParserScheduler::resume()
117 { 110 {
118 ASSERT(!m_continueNextChunkTimer.isActive()); 111 ASSERT(!m_cancellableContinueParse.isPending());
119 if (!m_isSuspendedWithActiveTimer) 112 if (!m_isSuspendedWithActiveTimer)
120 return; 113 return;
121 m_isSuspendedWithActiveTimer = false; 114 m_isSuspendedWithActiveTimer = false;
122 m_continueNextChunkTimer.startOneShot(0, FROM_HERE); 115
116 Scheduler::shared()->postLoadingTask(FROM_HERE, m_cancellableContinueParse.t ask());
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_cancellableContinueParse.isPending());
162 m_isSuspendedWithActiveTimer = true; 156 m_isSuspendedWithActiveTimer = true;
163 } 157 }
164 158
165 } 159 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLParserScheduler.h ('k') | Source/platform/blink_platform.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698