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

Unified Diff: third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp

Issue 2683653004: Put the BackgroundHTMLParser on oilpan heap (Closed)
Patch Set: Make BackgroundHTMLParser on oilpan heap Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp b/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
index 5a8861007025afa7d2415ea3bb3b954e6edce6a5..a4fbac20ad5771f54b8d64bb43ac7e68d4570851 100644
--- a/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
+++ b/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
@@ -25,6 +25,7 @@
#include "core/html/parser/HTMLDocumentParser.h"
+#include <memory>
#include "bindings/core/v8/DocumentWriteEvaluator.h"
#include "core/HTMLNames.h"
#include "core/css/MediaValuesCached.h"
@@ -51,6 +52,7 @@
#include "platform/SharedBuffer.h"
#include "platform/WebFrameScheduler.h"
#include "platform/heap/Handle.h"
+#include "platform/heap/Persistent.h"
#include "platform/instrumentation/tracing/TraceEvent.h"
#include "platform/loader/fetch/ResourceFetcher.h"
#include "public/platform/Platform.h"
@@ -59,7 +61,6 @@
#include "public/platform/WebThread.h"
#include "wtf/AutoReset.h"
#include "wtf/PtrUtil.h"
-#include <memory>
namespace blink {
@@ -131,21 +132,19 @@ HTMLDocumentParser::HTMLDocumentParser(Document& document,
m_tokenizer(syncPolicy == ForceSynchronousParsing
? HTMLTokenizer::create(m_options)
: nullptr),
- m_loadingTaskRunner(
- TaskRunnerHelper::get(TaskType::Networking, &document)),
m_parserScheduler(
syncPolicy == AllowAsynchronousParsing
- ? HTMLParserScheduler::create(this, m_loadingTaskRunner.get())
+ ? HTMLParserScheduler::create(
+ this,
+ TaskRunnerHelper::get(TaskType::Networking, &document))
: nullptr),
m_xssAuditorDelegate(&document),
- m_weakFactory(this),
m_preloader(HTMLResourcePreloader::create(document)),
m_tokenizedChunkQueue(TokenizedChunkQueue::create()),
m_evaluator(DocumentWriteEvaluator::create(document)),
m_pendingCSPMetaToken(nullptr),
m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing),
m_endWasDelayed(false),
- m_haveBackgroundParser(false),
m_tasksWereSuspended(false),
m_pumpSessionNestingLevel(0),
m_pumpSpeculationsSessionNestingLevel(0),
@@ -153,25 +152,19 @@ HTMLDocumentParser::HTMLDocumentParser(Document& document,
m_triedLoadingLinkHeaders(false),
m_addedPendingStylesheetInBody(false),
m_isWaitingForStylesheets(false) {
- ASSERT(shouldUseThreading() || (m_token && m_tokenizer));
+ DCHECK(shouldUseThreading() || (m_token && m_tokenizer));
// Threading is not allowed in prefetch mode.
DCHECK(!document.isPrefetchOnly() || !shouldUseThreading());
}
HTMLDocumentParser::~HTMLDocumentParser() {}
-void HTMLDocumentParser::dispose() {
- // In Oilpan, HTMLDocumentParser can die together with Document, and detach()
- // is not called in this case.
- if (m_haveBackgroundParser)
- stopBackgroundParser();
-}
-
DEFINE_TRACE(HTMLDocumentParser) {
visitor->trace(m_treeBuilder);
visitor->trace(m_parserScheduler);
visitor->trace(m_xssAuditorDelegate);
visitor->trace(m_scriptRunner);
+ visitor->trace(m_backgroundParser);
visitor->trace(m_preloader);
ScriptableDocumentParser::trace(visitor);
HTMLParserScriptRunnerHost::trace(visitor);
@@ -190,8 +183,7 @@ void HTMLDocumentParser::detach() {
m_tokenizedChunkQueue->peakPendingTokenCount());
}
- if (m_haveBackgroundParser)
- stopBackgroundParser();
+ m_backgroundParser.clear();
DocumentParser::detach();
if (m_scriptRunner)
m_scriptRunner->detach();
@@ -218,8 +210,7 @@ void HTMLDocumentParser::stopParsing() {
m_parserScheduler->detach();
m_parserScheduler.clear();
}
- if (m_haveBackgroundParser)
- stopBackgroundParser();
+ m_backgroundParser.clear();
}
// This kicks off "Once the user agent stops parsing" as described by:
@@ -227,11 +218,11 @@ void HTMLDocumentParser::stopParsing() {
void HTMLDocumentParser::prepareToStopParsing() {
// FIXME: It may not be correct to disable this for the background parser.
// That means hasInsertionPoint() may not be correct in some cases.
- ASSERT(!hasInsertionPoint() || m_haveBackgroundParser);
+ DCHECK(!hasInsertionPoint() || m_backgroundParser);
// NOTE: This pump should only ever emit buffered character tokens.
if (m_tokenizer) {
- ASSERT(!m_haveBackgroundParser);
+ DCHECK(!m_backgroundParser);
pumpTokenizerIfPossible();
}
@@ -270,8 +261,8 @@ bool HTMLDocumentParser::isScheduledForResume() const {
// Used by HTMLParserScheduler
void HTMLDocumentParser::resumeParsingAfterYield() {
- ASSERT(shouldUseThreading());
- ASSERT(m_haveBackgroundParser);
+ DCHECK(shouldUseThreading());
+ DCHECK(m_backgroundParser);
checkIfBodyStlyesheetAdded();
if (isStopped() || isPaused())
@@ -281,7 +272,7 @@ void HTMLDocumentParser::resumeParsingAfterYield() {
}
void HTMLDocumentParser::runScriptsForPausedTreeBuilder() {
- ASSERT(scriptingContentIsAllowed(getParserContentPolicy()));
+ DCHECK(scriptingContentIsAllowed(getParserContentPolicy()));
TextPosition scriptStartPosition = TextPosition::belowRangePosition();
Element* scriptElement =
@@ -360,7 +351,7 @@ void HTMLDocumentParser::notifyPendingTokenizedChunks() {
}
for (auto& index : chunk->likelyDocumentWriteScriptIndices) {
const CompactHTMLToken& token = chunk->tokens->at(index);
- ASSERT(token.type() == HTMLToken::TokenType::Character);
+ DCHECK(token.type() == HTMLToken::TokenType::Character);
m_queuedDocumentWriteScripts.push_back(token.data());
}
}
@@ -369,8 +360,8 @@ void HTMLDocumentParser::notifyPendingTokenizedChunks() {
// We can safely assume that there are no queued preloads request after the
// document element is available, as we empty the queue immediately after
// the document element is created in documentElementAvailable().
- ASSERT(m_queuedPreloads.isEmpty());
- ASSERT(m_queuedDocumentWriteScripts.isEmpty());
+ DCHECK(m_queuedPreloads.isEmpty());
+ DCHECK(m_queuedDocumentWriteScripts.isEmpty());
// Loop through the chunks to generate preloads before any document.write
// script evaluation takes place. Preloading these scripts is valuable and
// comparably cheap, while evaluating JS can be expensive.
@@ -379,7 +370,7 @@ void HTMLDocumentParser::notifyPendingTokenizedChunks() {
for (auto& chunk : pendingChunks) {
for (auto& index : chunk->likelyDocumentWriteScriptIndices) {
const CompactHTMLToken& token = chunk->tokens->at(index);
- ASSERT(token.type() == HTMLToken::TokenType::Character);
+ DCHECK(token.type() == HTMLToken::TokenType::Character);
evaluateAndPreloadScriptForDocumentWrite(token.data());
}
}
@@ -398,12 +389,14 @@ void HTMLDocumentParser::notifyPendingTokenizedChunks() {
void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(
const DocumentEncodingData& data) {
+ if (!isParsing())
Charlie Harrison 2017/02/08 23:48:01 This is necessary because now the bg parser is a m
Yoav Weiss 2017/02/14 06:45:47 ok
+ return;
document()->setEncodingData(data);
}
void HTMLDocumentParser::validateSpeculations(
std::unique_ptr<TokenizedChunk> chunk) {
- ASSERT(chunk);
+ DCHECK(chunk);
// TODO(kouhei): We should simplify codepath here by disallowing
// validateSpeculations
// while isPaused, and m_lastChunkBeforePause can simply be
@@ -439,7 +432,7 @@ void HTMLDocumentParser::validateSpeculations(
m_input.current().isEmpty() &&
chunk->treeBuilderState ==
HTMLTreeBuilderSimulator::stateFor(m_treeBuilder.get())) {
- ASSERT(token->isUninitialized());
+ DCHECK(token->isUninitialized());
return;
}
@@ -451,8 +444,6 @@ void HTMLDocumentParser::discardSpeculationsAndResumeFrom(
std::unique_ptr<TokenizedChunk> lastChunkBeforeScript,
std::unique_ptr<HTMLToken> token,
std::unique_ptr<HTMLTokenizer> tokenizer) {
- m_weakFactory.revokeAll();
-
size_t discardedTokenCount = 0;
for (const auto& speculation : m_speculations) {
discardedTokenCount += speculation->tokens->size();
@@ -467,7 +458,6 @@ void HTMLDocumentParser::discardSpeculationsAndResumeFrom(
std::unique_ptr<BackgroundHTMLParser::Checkpoint> checkpoint =
WTF::wrapUnique(new BackgroundHTMLParser::Checkpoint);
- checkpoint->parser = m_weakFactory.createWeakPtr();
checkpoint->token = std::move(token);
checkpoint->tokenizer = std::move(tokenizer);
checkpoint->treeBuilderState =
@@ -479,11 +469,8 @@ void HTMLDocumentParser::discardSpeculationsAndResumeFrom(
// FIXME: This should be passed in instead of cleared.
m_input.current().clear();
- ASSERT(checkpoint->unparsedInput.isSafeToSendToAnotherThread());
- m_loadingTaskRunner->postTask(
- BLINK_FROM_HERE,
- WTF::bind(&BackgroundHTMLParser::resumeFrom, m_backgroundParser,
- WTF::passed(std::move(checkpoint))));
+ DCHECK(checkpoint->unparsedInput.isSafeToSendToAnotherThread());
+ m_backgroundParser->resumeFrom(std::move(checkpoint));
}
size_t HTMLDocumentParser::processTokenizedChunkFromBackgroundParser(
@@ -496,22 +483,19 @@ size_t HTMLDocumentParser::processTokenizedChunkFromBackgroundParser(
SECURITY_DCHECK(m_pumpSpeculationsSessionNestingLevel == 1);
SECURITY_DCHECK(!inPumpSession());
- ASSERT(!isParsingFragment());
+ DCHECK(!isParsingFragment());
DCHECK(!isPaused());
- ASSERT(!isStopped());
- ASSERT(shouldUseThreading());
- ASSERT(!m_tokenizer);
- ASSERT(!m_token);
+ DCHECK(!isStopped());
+ DCHECK(shouldUseThreading());
+ DCHECK(!m_tokenizer);
+ DCHECK(!m_token);
DCHECK(!m_lastChunkBeforePause);
std::unique_ptr<TokenizedChunk> chunk(std::move(popChunk));
std::unique_ptr<CompactHTMLTokenStream> tokens = std::move(chunk->tokens);
size_t elementTokenCount = 0;
- m_loadingTaskRunner->postTask(
- BLINK_FROM_HERE,
- WTF::bind(&BackgroundHTMLParser::startedChunkWithCheckpoint,
- m_backgroundParser, chunk->inputCheckpoint));
+ m_backgroundParser->startedChunkWithCheckpoint(chunk->inputCheckpoint);
for (const auto& xssInfo : chunk->xssInfos) {
m_textPosition = xssInfo->m_textPosition;
@@ -526,7 +510,7 @@ size_t HTMLDocumentParser::processTokenizedChunkFromBackgroundParser(
for (Vector<CompactHTMLToken>::const_iterator it = tokens->begin();
it != tokens->end(); ++it) {
- ASSERT(!isWaitingForScripts());
+ DCHECK(!isWaitingForScripts());
if (!chunk->startingScript &&
(it->type() == HTMLToken::StartTag || it->type() == HTMLToken::EndTag))
@@ -538,7 +522,7 @@ size_t HTMLDocumentParser::processTokenizedChunkFromBackgroundParser(
// locationChangePending on the EOF path) we peek to see if this chunk has
// an EOF and process it anyway.
if (tokens->back().type() == HTMLToken::EndOfFile) {
- ASSERT(
+ DCHECK(
m_speculations
.isEmpty()); // There should never be any chunks after the EOF.
prepareToStopParsing();
@@ -562,7 +546,7 @@ size_t HTMLDocumentParser::processTokenizedChunkFromBackgroundParser(
if (isPaused()) {
// The script or stylesheet should be the last token of this bunch.
- ASSERT(it + 1 == tokens->end());
+ DCHECK(it + 1 == tokens->end());
if (isWaitingForScripts())
runScriptsForPausedTreeBuilder();
validateSpeculations(std::move(chunk));
@@ -571,15 +555,15 @@ size_t HTMLDocumentParser::processTokenizedChunkFromBackgroundParser(
if (it->type() == HTMLToken::EndOfFile) {
// The EOF is assumed to be the last token of this bunch.
- ASSERT(it + 1 == tokens->end());
+ DCHECK(it + 1 == tokens->end());
// There should never be any chunks after the EOF.
- ASSERT(m_speculations.isEmpty());
+ DCHECK(m_speculations.isEmpty());
prepareToStopParsing();
break;
}
- ASSERT(!m_tokenizer);
- ASSERT(!m_token);
+ DCHECK(!m_tokenizer);
+ DCHECK(!m_token);
}
// Make sure all required pending text nodes are emitted before returning.
@@ -595,13 +579,13 @@ size_t HTMLDocumentParser::processTokenizedChunkFromBackgroundParser(
void HTMLDocumentParser::pumpPendingSpeculations() {
// If this assert fails, you need to call validateSpeculations to make sure
// m_tokenizer and m_token don't have state that invalidates m_speculations.
- ASSERT(!m_tokenizer);
- ASSERT(!m_token);
+ DCHECK(!m_tokenizer);
+ DCHECK(!m_token);
DCHECK(!m_lastChunkBeforePause);
DCHECK(!isPaused());
- ASSERT(!isStopped());
- ASSERT(!isScheduledForResume());
- ASSERT(!inPumpSession());
+ DCHECK(!isStopped());
+ DCHECK(!isScheduledForResume());
+ DCHECK(!inPumpSession());
// FIXME: Here should never be reached when there is a blocking script,
// but it happens in unknown scenarios. See https://crbug.com/440901
@@ -623,7 +607,7 @@ void HTMLDocumentParser::pumpPendingSpeculations() {
SpeculationsPumpSession session(m_pumpSpeculationsSessionNestingLevel);
while (!m_speculations.isEmpty()) {
- ASSERT(!isScheduledForResume());
+ DCHECK(!isScheduledForResume());
size_t elementTokenCount =
processTokenizedChunkFromBackgroundParser(m_speculations.takeFirst());
session.addedElementTokens(elementTokenCount);
@@ -654,7 +638,7 @@ void HTMLDocumentParser::forcePlaintextForTextDocument() {
if (shouldUseThreading()) {
// This method is called before any data is appended, so we have to start
// the background parser ourselves.
- if (!m_haveBackgroundParser)
+ if (!m_backgroundParser)
startBackgroundParser();
// This task should be synchronous, because otherwise synchronous
@@ -665,9 +649,9 @@ void HTMLDocumentParser::forcePlaintextForTextDocument() {
}
void HTMLDocumentParser::pumpTokenizer() {
- ASSERT(!isStopped());
- ASSERT(m_tokenizer);
- ASSERT(m_token);
+ DCHECK(!isStopped());
+ DCHECK(m_tokenizer);
+ DCHECK(m_token);
PumpSession session(m_pumpSessionNestingLevel);
@@ -708,7 +692,7 @@ void HTMLDocumentParser::pumpTokenizer() {
}
constructTreeFromHTMLToken();
- ASSERT(isStopped() || token().isUninitialized());
+ DCHECK(isStopped() || token().isUninitialized());
}
if (isStopped())
@@ -717,12 +701,12 @@ void HTMLDocumentParser::pumpTokenizer() {
// There should only be PendingText left since the tree-builder always flushes
// the task queue before returning. In case that ever changes, crash.
m_treeBuilder->flush(FlushAlways);
- RELEASE_ASSERT(!isStopped());
+ CHECK(!isStopped());
if (isPaused()) {
- ASSERT(m_tokenizer->getState() == HTMLTokenizer::DataState);
+ DCHECK(m_tokenizer->getState() == HTMLTokenizer::DataState);
- ASSERT(m_preloader);
+ DCHECK(m_preloader);
// TODO(kouhei): m_preloader should be always available for synchronous
// parsing case, adding paranoia if for speculative crash fix for
// crbug.com/465478
@@ -764,7 +748,7 @@ void HTMLDocumentParser::constructTreeFromHTMLToken() {
return;
if (!token().isUninitialized()) {
- ASSERT(token().type() == HTMLToken::Character);
+ DCHECK(token().type() == HTMLToken::Character);
token().clear();
}
}
@@ -793,8 +777,8 @@ void HTMLDocumentParser::insert(const SegmentedString& source) {
source.length());
if (!m_tokenizer) {
- ASSERT(!inPumpSession());
- ASSERT(m_haveBackgroundParser || wasCreatedByScript());
+ DCHECK(!inPumpSession());
+ DCHECK(m_backgroundParser || wasCreatedByScript());
m_token = WTF::wrapUnique(new HTMLToken);
m_tokenizer = HTMLTokenizer::create(m_options);
}
@@ -817,14 +801,12 @@ void HTMLDocumentParser::insert(const SegmentedString& source) {
}
void HTMLDocumentParser::startBackgroundParser() {
- ASSERT(!isStopped());
- ASSERT(shouldUseThreading());
- ASSERT(!m_haveBackgroundParser);
- ASSERT(document());
- m_haveBackgroundParser = true;
-
- // TODO(alexclarke): Remove WebFrameScheduler::setDocumentParsingInBackground
- // when background parser goes away.
+ DCHECK(!isStopped());
+ DCHECK(shouldUseThreading());
+ DCHECK(!m_backgroundParser);
+ DCHECK(document());
+
+ // TODO(csharrison): Remove WebFrameScheduler::setDocumentParsingInBackground.
if (document()->frame() && document()->frame()->frameScheduler())
document()->frame()->frameScheduler()->setDocumentParsingInBackground(true);
@@ -836,7 +818,6 @@ void HTMLDocumentParser::startBackgroundParser() {
std::unique_ptr<BackgroundHTMLParser::Configuration> config =
WTF::wrapUnique(new BackgroundHTMLParser::Configuration);
config->options = m_options;
- config->parser = m_weakFactory.createWeakPtr();
config->xssAuditor = WTF::wrapUnique(new XSSAuditor);
config->xssAuditor->init(document(), &m_xssAuditorDelegate);
@@ -857,34 +838,10 @@ void HTMLDocumentParser::startBackgroundParser() {
}
}
- ASSERT(config->xssAuditor->isSafeToSendToAnotherThread());
+ DCHECK(config->xssAuditor->isSafeToSendToAnotherThread());
- // The background parser is created on the main thread, but may otherwise
- // only be used from the parser thread.
m_backgroundParser =
- BackgroundHTMLParser::create(std::move(config), m_loadingTaskRunner);
- // TODO(csharrison): This is a hack to initialize MediaValuesCached on the
- // correct thread. We should get rid of it.
- m_backgroundParser->init(
- document()->url(), CachedDocumentParameters::create(document()),
- MediaValuesCached::MediaValuesCachedData(*document()));
-}
-
-void HTMLDocumentParser::stopBackgroundParser() {
- ASSERT(shouldUseThreading());
- ASSERT(m_haveBackgroundParser);
-
- if (m_haveBackgroundParser && document()->frame() &&
- document()->frame()->frameScheduler())
- document()->frame()->frameScheduler()->setDocumentParsingInBackground(
- false);
-
- m_haveBackgroundParser = false;
-
- // Make this sync, as lsan triggers on some unittests if the task runner is
- // used.
- m_backgroundParser->stop();
- m_weakFactory.revokeAll();
+ BackgroundHTMLParser::create(this, *document(), std::move(config));
}
void HTMLDocumentParser::append(const String& inputSource) {
@@ -893,7 +850,7 @@ void HTMLDocumentParser::append(const String& inputSource) {
// We should never reach this point if we're using a parser thread, as
// appendBytes() will directly ship the data to the thread.
- ASSERT(!shouldUseThreading());
+ DCHECK(!shouldUseThreading());
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"),
"HTMLDocumentParser::append", "size", inputSource.length());
@@ -938,11 +895,10 @@ void HTMLDocumentParser::append(const String& inputSource) {
}
void HTMLDocumentParser::end() {
- ASSERT(!isDetached());
- ASSERT(!isScheduledForResume());
+ DCHECK(!isDetached());
+ DCHECK(!isScheduledForResume());
- if (m_haveBackgroundParser)
- stopBackgroundParser();
+ m_backgroundParser.clear();
// Informs the the rest of WebCore that parsing is really finished (and
// deletes this).
@@ -952,10 +908,10 @@ void HTMLDocumentParser::end() {
}
void HTMLDocumentParser::attemptToRunDeferredScriptsAndEnd() {
- ASSERT(isStopping());
+ DCHECK(isStopping());
// FIXME: It may not be correct to disable this for the background parser.
// That means hasInsertionPoint() may not be correct in some cases.
- ASSERT(!hasInsertionPoint() || m_haveBackgroundParser);
+ DCHECK(!hasInsertionPoint() || m_backgroundParser);
if (m_scriptRunner && !m_scriptRunner->executeScriptsWaitingForParsing())
return;
end();
@@ -985,7 +941,7 @@ void HTMLDocumentParser::endIfDelayed() {
}
void HTMLDocumentParser::finish() {
- // FIXME: We should ASSERT(!m_parserStopped) here, since it does not makes
+ // FIXME: We should DCHECK(!m_parserStopped) here, since it does not makes
// sense to call any methods on DocumentParser once it's been stopped.
// However, FrameLoader::stop calls DocumentParser::finish unconditionally.
@@ -996,17 +952,15 @@ void HTMLDocumentParser::finish() {
// Empty documents never got an append() call, and thus have never started a
// background parser. In those cases, we ignore shouldUseThreading() and fall
// through to the non-threading case.
- if (m_haveBackgroundParser) {
+ if (m_backgroundParser) {
if (!m_input.haveSeenEndOfFile())
m_input.closeWithoutMarkingEndOfFile();
- m_loadingTaskRunner->postTask(
- BLINK_FROM_HERE,
- WTF::bind(&BackgroundHTMLParser::finish, m_backgroundParser));
+ m_backgroundParser->finish();
return;
}
if (!m_tokenizer) {
- ASSERT(!m_token);
+ DCHECK(!m_token);
// We're finishing before receiving any data. Rather than booting up the
// background parser just to spin it down, we finish parsing synchronously.
m_token = WTF::wrapUnique(new HTMLToken);
@@ -1034,14 +988,14 @@ bool HTMLDocumentParser::isParsingAtLineNumber() const {
}
OrdinalNumber HTMLDocumentParser::lineNumber() const {
- if (m_haveBackgroundParser)
+ if (m_backgroundParser)
return m_textPosition.m_line;
return m_input.current().currentLine();
}
TextPosition HTMLDocumentParser::textPosition() const {
- if (m_haveBackgroundParser)
+ if (m_backgroundParser)
return m_textPosition;
const SegmentedString& currentString = m_input.current();
@@ -1064,21 +1018,21 @@ bool HTMLDocumentParser::isWaitingForScripts() const {
// Since the parser is paused while a script runner has a blocking script, it
// should never be possible to end up with both objects holding a blocking
// script.
- ASSERT(!(treeBuilderHasBlockingScript && scriptRunnerHasBlockingScript));
+ DCHECK(!(treeBuilderHasBlockingScript && scriptRunnerHasBlockingScript));
// If either object has a blocking script, the parser should be paused.
return treeBuilderHasBlockingScript || scriptRunnerHasBlockingScript ||
m_reentryPermit->parserPauseFlag();
}
void HTMLDocumentParser::resumeParsingAfterPause() {
- ASSERT(!isExecutingScript());
+ DCHECK(!isExecutingScript());
DCHECK(!isPaused());
checkIfBodyStlyesheetAdded();
if (isPaused())
return;
- if (m_haveBackgroundParser) {
+ if (m_backgroundParser) {
if (m_lastChunkBeforePause) {
validateSpeculations(std::move(m_lastChunkBeforePause));
DCHECK(!m_lastChunkBeforePause);
@@ -1095,14 +1049,14 @@ void HTMLDocumentParser::resumeParsingAfterPause() {
}
void HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan() {
- ASSERT(m_preloadScanner);
+ DCHECK(m_preloadScanner);
m_preloadScanner->appendToEnd(m_input.current());
scanAndPreload(m_preloadScanner.get());
}
void HTMLDocumentParser::notifyScriptLoaded(PendingScript* pendingScript) {
- ASSERT(m_scriptRunner);
- ASSERT(!isExecutingScript());
+ DCHECK(m_scriptRunner);
+ DCHECK(!isExecutingScript());
if (isStopped()) {
return;
@@ -1172,14 +1126,14 @@ void HTMLDocumentParser::parseDocumentFragment(
}
void HTMLDocumentParser::suspendScheduledTasks() {
- ASSERT(!m_tasksWereSuspended);
+ DCHECK(!m_tasksWereSuspended);
m_tasksWereSuspended = true;
if (m_parserScheduler)
m_parserScheduler->suspend();
}
void HTMLDocumentParser::resumeScheduledTasks() {
- ASSERT(m_tasksWereSuspended);
+ DCHECK(m_tasksWereSuspended);
m_tasksWereSuspended = false;
if (m_parserScheduler)
m_parserScheduler->resume();
@@ -1191,7 +1145,7 @@ void HTMLDocumentParser::appendBytes(const char* data, size_t length) {
if (shouldUseThreading()) {
double bytesReceivedTime = monotonicallyIncreasingTimeMS();
- if (!m_haveBackgroundParser)
+ if (!m_backgroundParser)
startBackgroundParser();
std::unique_ptr<Vector<char>> buffer =
@@ -1200,11 +1154,8 @@ void HTMLDocumentParser::appendBytes(const char* data, size_t length) {
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"),
"HTMLDocumentParser::appendBytes", "size", (unsigned)length);
- m_loadingTaskRunner->postTask(
- BLINK_FROM_HERE,
- WTF::bind(&BackgroundHTMLParser::appendRawBytesFromMainThread,
- m_backgroundParser, WTF::passed(std::move(buffer)),
- bytesReceivedTime));
+ m_backgroundParser->appendRawBytesFromMainThread(std::move(buffer),
+ bytesReceivedTime);
return;
}
@@ -1219,17 +1170,14 @@ void HTMLDocumentParser::flush() {
if (shouldUseThreading()) {
// In some cases, flush() is called without any invocation of appendBytes.
// Fallback to synchronous parsing in that case.
- if (!m_haveBackgroundParser) {
+ if (!m_backgroundParser) {
m_shouldUseThreading = false;
m_token = WTF::wrapUnique(new HTMLToken);
m_tokenizer = HTMLTokenizer::create(m_options);
DecodedDataDocumentParser::flush();
return;
}
-
- m_loadingTaskRunner->postTask(
- BLINK_FROM_HERE,
- WTF::bind(&BackgroundHTMLParser::flush, m_backgroundParser));
+ m_backgroundParser->flush();
} else {
DecodedDataDocumentParser::flush();
}
@@ -1237,15 +1185,11 @@ void HTMLDocumentParser::flush() {
void HTMLDocumentParser::setDecoder(
std::unique_ptr<TextResourceDecoder> decoder) {
- ASSERT(decoder);
+ DCHECK(decoder);
DecodedDataDocumentParser::setDecoder(std::move(decoder));
- if (m_haveBackgroundParser) {
- m_loadingTaskRunner->postTask(
- BLINK_FROM_HERE,
- WTF::bind(&BackgroundHTMLParser::setDecoder, m_backgroundParser,
- WTF::passed(takeDecoder())));
- }
+ if (m_backgroundParser)
+ m_backgroundParser->setDecoder(takeDecoder());
}
void HTMLDocumentParser::documentElementAvailable() {
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698