Chromium Code Reviews| 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 61170c3f92f950b69419e723d5824542fba9798a..84a1b7f011b5a67d57a2ced5a9a179e3fb78ae6c 100644 |
| --- a/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp |
| +++ b/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp |
| @@ -403,7 +403,7 @@ void HTMLDocumentParser::discardSpeculationsAndResumeFrom(std::unique_ptr<Parsed |
| m_input.current().clear(); // FIXME: This should be passed in instead of cleared. |
| ASSERT(checkpoint->unparsedInput.isSafeToSendToAnotherThread()); |
| - postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::resumeFrom, m_backgroundParser, passed(std::move(checkpoint)))); |
| + postTaskToLookaheadParser(Asynchronous, &BackgroundHTMLParser::resumeFrom, m_backgroundParser, passed(std::move(checkpoint))); |
| } |
| size_t HTMLDocumentParser::processParsedChunkFromBackgroundParser(std::unique_ptr<ParsedChunk> popChunk) |
| @@ -425,7 +425,7 @@ size_t HTMLDocumentParser::processParsedChunkFromBackgroundParser(std::unique_pt |
| std::unique_ptr<CompactHTMLTokenStream> tokens = std::move(chunk->tokens); |
| size_t elementTokenCount = 0; |
| - postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::startedChunkWithCheckpoint, m_backgroundParser, chunk->inputCheckpoint)); |
| + postTaskToLookaheadParser(Asynchronous, &BackgroundHTMLParser::startedChunkWithCheckpoint, m_backgroundParser, chunk->inputCheckpoint); |
| for (const auto& xssInfo : chunk->xssInfos) { |
| m_textPosition = xssInfo->m_textPosition; |
| @@ -556,7 +556,7 @@ void HTMLDocumentParser::forcePlaintextForTextDocument() |
| if (!m_haveBackgroundParser) |
| startBackgroundParser(); |
| - postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::forcePlaintextForTextDocument, m_backgroundParser)); |
| + postTaskToLookaheadParser(Asynchronous, &BackgroundHTMLParser::forcePlaintextForTextDocument, m_backgroundParser); |
| } else |
| m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); |
| } |
| @@ -732,14 +732,15 @@ void HTMLDocumentParser::startBackgroundParser() |
| } |
| ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); |
| - postTaskToLookaheadParser(crossThreadBind( |
| + postTaskToLookaheadParser( |
| + Synchronous, |
| &BackgroundHTMLParser::start, |
| reference.release(), |
| passed(std::move(config)), |
| document()->url(), |
| passed(CachedDocumentParameters::create(document())), |
| MediaValuesCached::MediaValuesCachedData(*document()), |
| - passed(wrapUnique(m_loadingTaskRunner->clone()))), Synchronous); |
| + passed(wrapUnique(m_loadingTaskRunner->clone()))); |
| } |
| void HTMLDocumentParser::stopBackgroundParser() |
| @@ -751,7 +752,7 @@ void HTMLDocumentParser::stopBackgroundParser() |
| // Make this sync, as lsan triggers on some unittests if the task runner is |
| // used. Note that these lifetimes will be much more concrete if |
| // ParseHTMLOnMainThread lands (the lookahead parser will be a member). |
| - postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::stop, m_backgroundParser), Synchronous); |
| + postTaskToLookaheadParser(Synchronous, &BackgroundHTMLParser::stop, m_backgroundParser); |
| m_weakFactory.revokeAll(); |
| } |
| @@ -859,7 +860,7 @@ void HTMLDocumentParser::finish() |
| if (m_haveBackgroundParser) { |
| if (!m_input.haveSeenEndOfFile()) |
| m_input.closeWithoutMarkingEndOfFile(); |
| - postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::finish, m_backgroundParser)); |
| + postTaskToLookaheadParser(Asynchronous, &BackgroundHTMLParser::finish, m_backgroundParser); |
| return; |
| } |
| @@ -1025,7 +1026,7 @@ void HTMLDocumentParser::appendBytes(const char* data, size_t length) |
| memcpy(buffer->data(), data, length); |
| TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), "HTMLDocumentParser::appendBytes", "size", (unsigned)length); |
| - postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::appendRawBytesFromMainThread, m_backgroundParser, passed(std::move(buffer)), bytesReceivedTime)); |
| + postTaskToLookaheadParser(Asynchronous, &BackgroundHTMLParser::appendRawBytesFromMainThread, m_backgroundParser, passed(std::move(buffer)), bytesReceivedTime); |
| return; |
| } |
| @@ -1049,7 +1050,7 @@ void HTMLDocumentParser::flush() |
| return; |
| } |
| - postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::flush, m_backgroundParser)); |
| + postTaskToLookaheadParser(Asynchronous, &BackgroundHTMLParser::flush, m_backgroundParser); |
| } else { |
| DecodedDataDocumentParser::flush(); |
| } |
| @@ -1061,7 +1062,7 @@ void HTMLDocumentParser::setDecoder(std::unique_ptr<TextResourceDecoder> decoder |
| DecodedDataDocumentParser::setDecoder(std::move(decoder)); |
| if (m_haveBackgroundParser) |
| - postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::setDecoder, m_backgroundParser, passed(takeDecoder()))); |
| + postTaskToLookaheadParser(Asynchronous, &BackgroundHTMLParser::setDecoder, m_backgroundParser, passed(takeDecoder())); |
| } |
| void HTMLDocumentParser::documentElementAvailable() |
| @@ -1125,10 +1126,11 @@ void HTMLDocumentParser::evaluateAndPreloadScriptForDocumentWrite(const String& |
| } |
| } |
| -void HTMLDocumentParser::postTaskToLookaheadParser(std::unique_ptr<CrossThreadClosure> closure, LookaheadParserTaskSynchrony synchronyPolicy) |
| +template <typename FunctionType, typename... Ps> |
| +void HTMLDocumentParser::postTaskToLookaheadParser(LookaheadParserTaskSynchrony synchronyPolicy, FunctionType function, Ps&&... parameters) |
| { |
| if (!RuntimeEnabledFeatures::parseHTMLOnMainThreadEnabled()) { |
| - HTMLParserThread::shared()->postTask(std::move(closure)); |
| + HTMLParserThread::shared()->postTask(crossThreadBind(function, std::forward<Ps>(parameters)...)); |
| return; |
| } |
| @@ -1136,10 +1138,10 @@ void HTMLDocumentParser::postTaskToLookaheadParser(std::unique_ptr<CrossThreadCl |
| // just post to the loading task runner. |
| switch (synchronyPolicy) { |
| case Synchronous: |
| - (*closure)(); |
| + (*WTF::bind(function, std::forward<Ps>(parameters)...))(); |
|
hiroshige
2016/07/12 05:33:12
Is this statement covered by tests?
Charlie Harrison
2016/07/12 12:18:36
Yes, ditto.
|
| return; |
| case Asynchronous: |
| - m_loadingTaskRunner->postTask(BLINK_FROM_HERE, std::move(closure)); |
| + m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std::forward<Ps>(parameters)...)); |
| return; |
| } |
| NOTREACHED(); |