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

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

Issue 2181943002: Rename ParsedChunk to TokenizedChunk in core/html/parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 , m_treeBuilderSimulator(config->options) 103 , m_treeBuilderSimulator(config->options)
104 , m_options(config->options) 104 , m_options(config->options)
105 , m_outstandingTokenLimit(config->outstandingTokenLimit) 105 , m_outstandingTokenLimit(config->outstandingTokenLimit)
106 , m_parser(config->parser) 106 , m_parser(config->parser)
107 , m_pendingTokens(wrapUnique(new CompactHTMLTokenStream)) 107 , m_pendingTokens(wrapUnique(new CompactHTMLTokenStream))
108 , m_pendingTokenLimit(config->pendingTokenLimit) 108 , m_pendingTokenLimit(config->pendingTokenLimit)
109 , m_xssAuditor(std::move(config->xssAuditor)) 109 , m_xssAuditor(std::move(config->xssAuditor))
110 , m_preloadScanner(wrapUnique(new TokenPreloadScanner(documentURL, std::move (cachedDocumentParameters), mediaValuesCachedData))) 110 , m_preloadScanner(wrapUnique(new TokenPreloadScanner(documentURL, std::move (cachedDocumentParameters), mediaValuesCachedData)))
111 , m_decoder(std::move(config->decoder)) 111 , m_decoder(std::move(config->decoder))
112 , m_loadingTaskRunner(std::move(loadingTaskRunner)) 112 , m_loadingTaskRunner(std::move(loadingTaskRunner))
113 , m_parsedChunkQueue(config->parsedChunkQueue.release()) 113 , m_tokenizedChunkQueue(config->tokenizedChunkQueue.release())
114 , m_startingScript(false) 114 , m_startingScript(false)
115 , m_lastBytesReceivedTime(0.0) 115 , m_lastBytesReceivedTime(0.0)
116 { 116 {
117 ASSERT(m_outstandingTokenLimit > 0); 117 ASSERT(m_outstandingTokenLimit > 0);
118 ASSERT(m_pendingTokenLimit > 0); 118 ASSERT(m_pendingTokenLimit > 0);
119 ASSERT(m_outstandingTokenLimit >= m_pendingTokenLimit); 119 ASSERT(m_outstandingTokenLimit >= m_pendingTokenLimit);
120 } 120 }
121 121
122 BackgroundHTMLParser::~BackgroundHTMLParser() 122 BackgroundHTMLParser::~BackgroundHTMLParser()
123 { 123 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 void BackgroundHTMLParser::resumeFrom(std::unique_ptr<Checkpoint> checkpoint) 171 void BackgroundHTMLParser::resumeFrom(std::unique_ptr<Checkpoint> checkpoint)
172 { 172 {
173 m_parser = checkpoint->parser; 173 m_parser = checkpoint->parser;
174 m_token = std::move(checkpoint->token); 174 m_token = std::move(checkpoint->token);
175 m_tokenizer = std::move(checkpoint->tokenizer); 175 m_tokenizer = std::move(checkpoint->tokenizer);
176 m_treeBuilderSimulator.setState(checkpoint->treeBuilderState); 176 m_treeBuilderSimulator.setState(checkpoint->treeBuilderState);
177 m_input.rewindTo(checkpoint->inputCheckpoint, checkpoint->unparsedInput); 177 m_input.rewindTo(checkpoint->inputCheckpoint, checkpoint->unparsedInput);
178 m_preloadScanner->rewindTo(checkpoint->preloadScannerCheckpoint); 178 m_preloadScanner->rewindTo(checkpoint->preloadScannerCheckpoint);
179 m_startingScript = false; 179 m_startingScript = false;
180 m_parsedChunkQueue->clear(); 180 m_tokenizedChunkQueue->clear();
181 m_lastBytesReceivedTime = monotonicallyIncreasingTimeMS(); 181 m_lastBytesReceivedTime = monotonicallyIncreasingTimeMS();
182 pumpTokenizer(); 182 pumpTokenizer();
183 } 183 }
184 184
185 void BackgroundHTMLParser::startedChunkWithCheckpoint(HTMLInputCheckpoint inputC heckpoint) 185 void BackgroundHTMLParser::startedChunkWithCheckpoint(HTMLInputCheckpoint inputC heckpoint)
186 { 186 {
187 // Note, we should not have to worry about the index being invalid 187 // Note, we should not have to worry about the index being invalid
188 // as messages from the main thread will be processed in FIFO order. 188 // as messages from the main thread will be processed in FIFO order.
189 m_input.invalidateCheckpointsBefore(inputCheckpoint); 189 m_input.invalidateCheckpointsBefore(inputCheckpoint);
190 pumpTokenizer(); 190 pumpTokenizer();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 if (m_pendingTokens->isEmpty()) 282 if (m_pendingTokens->isEmpty())
283 return; 283 return;
284 284
285 #if ENABLE(ASSERT) 285 #if ENABLE(ASSERT)
286 checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get()); 286 checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get());
287 checkThatPreloadsAreSafeToSendToAnotherThread(m_pendingPreloads); 287 checkThatPreloadsAreSafeToSendToAnotherThread(m_pendingPreloads);
288 checkThatXSSInfosAreSafeToSendToAnotherThread(m_pendingXSSInfos); 288 checkThatXSSInfosAreSafeToSendToAnotherThread(m_pendingXSSInfos);
289 #endif 289 #endif
290 290
291 double chunkStartTime = monotonicallyIncreasingTimeMS(); 291 double chunkStartTime = monotonicallyIncreasingTimeMS();
292 std::unique_ptr<HTMLDocumentParser::ParsedChunk> chunk = wrapUnique(new HTML DocumentParser::ParsedChunk); 292 std::unique_ptr<HTMLDocumentParser::TokenizedChunk> chunk = wrapUnique(new H TMLDocumentParser::TokenizedChunk);
293 TRACE_EVENT_WITH_FLOW0("blink,loading", "BackgroundHTMLParser::sendTokensToM ainThread", chunk.get(), TRACE_EVENT_FLAG_FLOW_OUT); 293 TRACE_EVENT_WITH_FLOW0("blink,loading", "BackgroundHTMLParser::sendTokensToM ainThread", chunk.get(), TRACE_EVENT_FLAG_FLOW_OUT);
294 294
295 if (!m_pendingPreloads.isEmpty()) { 295 if (!m_pendingPreloads.isEmpty()) {
296 double delay = monotonicallyIncreasingTimeMS() - m_lastBytesReceivedTime ; 296 double delay = monotonicallyIncreasingTimeMS() - m_lastBytesReceivedTime ;
297 DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadTokenizeDelay, ("Parser .PreloadTokenizeDelay", 1, 10000, 50)); 297 DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadTokenizeDelay, ("Parser .PreloadTokenizeDelay", 1, 10000, 50));
298 preloadTokenizeDelay.count(delay); 298 preloadTokenizeDelay.count(delay);
299 } 299 }
300 300
301 chunk->preloads.swap(m_pendingPreloads); 301 chunk->preloads.swap(m_pendingPreloads);
302 if (m_viewportDescription.set) 302 if (m_viewportDescription.set)
303 chunk->viewport = m_viewportDescription; 303 chunk->viewport = m_viewportDescription;
304 chunk->xssInfos.swap(m_pendingXSSInfos); 304 chunk->xssInfos.swap(m_pendingXSSInfos);
305 chunk->tokenizerState = m_tokenizer->getState(); 305 chunk->tokenizerState = m_tokenizer->getState();
306 chunk->treeBuilderState = m_treeBuilderSimulator.state(); 306 chunk->treeBuilderState = m_treeBuilderSimulator.state();
307 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); 307 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size());
308 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); 308 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint();
309 chunk->tokens = std::move(m_pendingTokens); 309 chunk->tokens = std::move(m_pendingTokens);
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_tokenizedChunkQueue->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(&HTMLDocumentParser::notifyPendingParsedChunks, m_parser ); 320 runOnMainThread(&HTMLDocumentParser::notifyPendingTokenizedChunks, m_par ser);
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 template <typename FunctionType, typename... Ps> 331 template <typename FunctionType, typename... Ps>
332 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame ters) 332 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame ters)
333 { 333 {
334 if (isMainThread()) { 334 if (isMainThread()) {
335 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); 335 (*WTF::bind(function, std::forward<Ps>(parameters)...))();
336 } else { 336 } else {
337 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(function, std::forward<Ps>(parameters)...)); 337 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(function, std::forward<Ps>(parameters)...));
338 } 338 }
339 } 339 }
340 340
341 } // namespace blink 341 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698