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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.cpp

Issue 2134323002: Remove threading primitives from ParseHTMLOnMainThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on 405128 Created 4 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2013 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 void BackgroundHTMLParser::updateDocument(const String& decodedData) 154 void BackgroundHTMLParser::updateDocument(const String& decodedData)
155 { 155 {
156 DocumentEncodingData encodingData(*m_decoder.get()); 156 DocumentEncodingData encodingData(*m_decoder.get());
157 157
158 if (encodingData != m_lastSeenEncodingData) { 158 if (encodingData != m_lastSeenEncodingData) {
159 m_lastSeenEncodingData = encodingData; 159 m_lastSeenEncodingData = encodingData;
160 160
161 m_xssAuditor->setEncoding(encodingData.encoding()); 161 m_xssAuditor->setEncoding(encodingData.encoding());
162 runOnMainThread(crossThreadBind(&HTMLDocumentParser::didReceiveEncodingD ataFromBackgroundParser, m_parser, encodingData)); 162 runOnMainThread(&HTMLDocumentParser::didReceiveEncodingDataFromBackgroun dParser, m_parser, encodingData);
163 } 163 }
164 164
165 if (decodedData.isEmpty()) 165 if (decodedData.isEmpty())
166 return; 166 return;
167 167
168 appendDecodedBytes(decodedData); 168 appendDecodedBytes(decodedData);
169 } 169 }
170 170
171 void BackgroundHTMLParser::resumeFrom(std::unique_ptr<Checkpoint> checkpoint) 171 void BackgroundHTMLParser::resumeFrom(std::unique_ptr<Checkpoint> checkpoint)
172 { 172 {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 chunk->startingScript = m_startingScript; 310 chunk->startingScript = m_startingScript;
311 chunk->likelyDocumentWriteScriptIndices.swap(m_likelyDocumentWriteScriptIndi ces); 311 chunk->likelyDocumentWriteScriptIndices.swap(m_likelyDocumentWriteScriptIndi ces);
312 m_startingScript = false; 312 m_startingScript = false;
313 313
314 bool isEmpty = m_parsedChunkQueue->enqueue(std::move(chunk)); 314 bool isEmpty = m_parsedChunkQueue->enqueue(std::move(chunk));
315 315
316 DEFINE_STATIC_LOCAL(CustomCountHistogram, chunkEnqueueTime, ("Parser.ChunkEn queueTime", 1, 10000, 50)); 316 DEFINE_STATIC_LOCAL(CustomCountHistogram, chunkEnqueueTime, ("Parser.ChunkEn queueTime", 1, 10000, 50));
317 chunkEnqueueTime.count(monotonicallyIncreasingTimeMS() - chunkStartTime); 317 chunkEnqueueTime.count(monotonicallyIncreasingTimeMS() - chunkStartTime);
318 318
319 if (isEmpty) { 319 if (isEmpty) {
320 runOnMainThread(crossThreadBind(&HTMLDocumentParser::notifyPendingParsed Chunks, m_parser)); 320 runOnMainThread(&HTMLDocumentParser::notifyPendingParsedChunks, m_parser );
321 } 321 }
322 322
323 m_pendingTokens = wrapUnique(new CompactHTMLTokenStream); 323 m_pendingTokens = wrapUnique(new CompactHTMLTokenStream);
324 } 324 }
325 325
326 // If the background parser is already running on the main thread, then it is 326 // If the background parser is already running on the main thread, then it is
327 // not necessary to post a task to the main thread to run asynchronously. The 327 // not necessary to post a task to the main thread to run asynchronously. The
328 // main parser deals with chunking up its own work. 328 // main parser deals with chunking up its own work.
329 // TODO(csharrison): This is a pretty big hack because we don't actually need a 329 // TODO(csharrison): This is a pretty big hack because we don't actually need a
330 // CrossThreadClosure in these cases. This is just experimental. 330 // CrossThreadClosure in these cases. This is just experimental.
331 void BackgroundHTMLParser::runOnMainThread(std::unique_ptr<CrossThreadClosure> c losure) 331 template <typename FunctionType, typename... Ps>
332 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame ters)
332 { 333 {
333 if (isMainThread()) 334 if (isMainThread()) {
334 (*closure)(); 335 (*WTF::bind(function, std::forward<Ps>(parameters)...))();
335 else 336 } else {
336 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, std::move(closure)); 337 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(function, std::forward<Ps>(parameters)...));
338 }
337 } 339 }
338 340
339 } // namespace blink 341 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698