| OLD | NEW |
| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 BackgroundHTMLParser::Configuration::Configuration() | 105 BackgroundHTMLParser::Configuration::Configuration() |
| 106 : outstandingTokenLimit(defaultOutstandingTokenLimit), | 106 : outstandingTokenLimit(defaultOutstandingTokenLimit), |
| 107 pendingTokenLimit(defaultPendingTokenLimit), | 107 pendingTokenLimit(defaultPendingTokenLimit), |
| 108 shouldCoalesceChunks(false) {} | 108 shouldCoalesceChunks(false) {} |
| 109 | 109 |
| 110 BackgroundHTMLParser::BackgroundHTMLParser( | 110 BackgroundHTMLParser::BackgroundHTMLParser( |
| 111 std::unique_ptr<Configuration> config, | 111 std::unique_ptr<Configuration> config, |
| 112 std::unique_ptr<WebTaskRunner> loadingTaskRunner) | 112 std::unique_ptr<WebTaskRunner> loadingTaskRunner) |
| 113 : m_weakFactory(this), | 113 : m_weakFactory(this), |
| 114 m_token(wrapUnique(new HTMLToken)), | 114 m_token(WTF::wrapUnique(new HTMLToken)), |
| 115 m_tokenizer(HTMLTokenizer::create(config->options)), | 115 m_tokenizer(HTMLTokenizer::create(config->options)), |
| 116 m_treeBuilderSimulator(config->options), | 116 m_treeBuilderSimulator(config->options), |
| 117 m_options(config->options), | 117 m_options(config->options), |
| 118 m_outstandingTokenLimit(config->outstandingTokenLimit), | 118 m_outstandingTokenLimit(config->outstandingTokenLimit), |
| 119 m_parser(config->parser), | 119 m_parser(config->parser), |
| 120 m_pendingTokens(wrapUnique(new CompactHTMLTokenStream)), | 120 m_pendingTokens(WTF::wrapUnique(new CompactHTMLTokenStream)), |
| 121 m_pendingTokenLimit(config->pendingTokenLimit), | 121 m_pendingTokenLimit(config->pendingTokenLimit), |
| 122 m_xssAuditor(std::move(config->xssAuditor)), | 122 m_xssAuditor(std::move(config->xssAuditor)), |
| 123 m_decoder(std::move(config->decoder)), | 123 m_decoder(std::move(config->decoder)), |
| 124 m_loadingTaskRunner(std::move(loadingTaskRunner)), | 124 m_loadingTaskRunner(std::move(loadingTaskRunner)), |
| 125 m_tokenizedChunkQueue(config->tokenizedChunkQueue.release()), | 125 m_tokenizedChunkQueue(config->tokenizedChunkQueue.release()), |
| 126 m_pendingCSPMetaTokenIndex( | 126 m_pendingCSPMetaTokenIndex( |
| 127 HTMLDocumentParser::TokenizedChunk::noPendingToken), | 127 HTMLDocumentParser::TokenizedChunk::noPendingToken), |
| 128 m_startingScript(false), | 128 m_startingScript(false), |
| 129 m_lastBytesReceivedTime(0.0), | 129 m_lastBytesReceivedTime(0.0), |
| 130 m_shouldCoalesceChunks(config->shouldCoalesceChunks) { | 130 m_shouldCoalesceChunks(config->shouldCoalesceChunks) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 return false; | 319 return false; |
| 320 | 320 |
| 321 #if ENABLE(ASSERT) | 321 #if ENABLE(ASSERT) |
| 322 checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get()); | 322 checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get()); |
| 323 checkThatPreloadsAreSafeToSendToAnotherThread(m_pendingPreloads); | 323 checkThatPreloadsAreSafeToSendToAnotherThread(m_pendingPreloads); |
| 324 checkThatXSSInfosAreSafeToSendToAnotherThread(m_pendingXSSInfos); | 324 checkThatXSSInfosAreSafeToSendToAnotherThread(m_pendingXSSInfos); |
| 325 #endif | 325 #endif |
| 326 | 326 |
| 327 double chunkStartTime = monotonicallyIncreasingTimeMS(); | 327 double chunkStartTime = monotonicallyIncreasingTimeMS(); |
| 328 std::unique_ptr<HTMLDocumentParser::TokenizedChunk> chunk = | 328 std::unique_ptr<HTMLDocumentParser::TokenizedChunk> chunk = |
| 329 wrapUnique(new HTMLDocumentParser::TokenizedChunk); | 329 WTF::wrapUnique(new HTMLDocumentParser::TokenizedChunk); |
| 330 TRACE_EVENT_WITH_FLOW0("blink,loading", | 330 TRACE_EVENT_WITH_FLOW0("blink,loading", |
| 331 "BackgroundHTMLParser::sendTokensToMainThread", | 331 "BackgroundHTMLParser::sendTokensToMainThread", |
| 332 chunk.get(), TRACE_EVENT_FLAG_FLOW_OUT); | 332 chunk.get(), TRACE_EVENT_FLAG_FLOW_OUT); |
| 333 | 333 |
| 334 if (!m_pendingPreloads.isEmpty()) { | 334 if (!m_pendingPreloads.isEmpty()) { |
| 335 double delay = monotonicallyIncreasingTimeMS() - m_lastBytesReceivedTime; | 335 double delay = monotonicallyIncreasingTimeMS() - m_lastBytesReceivedTime; |
| 336 DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadTokenizeDelay, | 336 DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadTokenizeDelay, |
| 337 ("Parser.PreloadTokenizeDelay", 1, 10000, 50)); | 337 ("Parser.PreloadTokenizeDelay", 1, 10000, 50)); |
| 338 preloadTokenizeDelay.count(delay); | 338 preloadTokenizeDelay.count(delay); |
| 339 } | 339 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 354 m_startingScript = false; | 354 m_startingScript = false; |
| 355 m_pendingCSPMetaTokenIndex = | 355 m_pendingCSPMetaTokenIndex = |
| 356 HTMLDocumentParser::TokenizedChunk::noPendingToken; | 356 HTMLDocumentParser::TokenizedChunk::noPendingToken; |
| 357 | 357 |
| 358 bool isEmpty = m_tokenizedChunkQueue->enqueue(std::move(chunk)); | 358 bool isEmpty = m_tokenizedChunkQueue->enqueue(std::move(chunk)); |
| 359 | 359 |
| 360 DEFINE_STATIC_LOCAL(CustomCountHistogram, chunkEnqueueTime, | 360 DEFINE_STATIC_LOCAL(CustomCountHistogram, chunkEnqueueTime, |
| 361 ("Parser.ChunkEnqueueTime", 1, 10000, 50)); | 361 ("Parser.ChunkEnqueueTime", 1, 10000, 50)); |
| 362 chunkEnqueueTime.count(monotonicallyIncreasingTimeMS() - chunkStartTime); | 362 chunkEnqueueTime.count(monotonicallyIncreasingTimeMS() - chunkStartTime); |
| 363 | 363 |
| 364 m_pendingTokens = wrapUnique(new CompactHTMLTokenStream); | 364 m_pendingTokens = WTF::wrapUnique(new CompactHTMLTokenStream); |
| 365 return isEmpty; | 365 return isEmpty; |
| 366 } | 366 } |
| 367 | 367 |
| 368 // If the background parser is already running on the main thread, then it is | 368 // If the background parser is already running on the main thread, then it is |
| 369 // not necessary to post a task to the main thread to run asynchronously. The | 369 // not necessary to post a task to the main thread to run asynchronously. The |
| 370 // main parser deals with chunking up its own work. | 370 // main parser deals with chunking up its own work. |
| 371 // TODO(csharrison): This is a pretty big hack because we don't actually need a | 371 // TODO(csharrison): This is a pretty big hack because we don't actually need a |
| 372 // CrossThreadClosure in these cases. This is just experimental. | 372 // CrossThreadClosure in these cases. This is just experimental. |
| 373 template <typename FunctionType, typename... Ps> | 373 template <typename FunctionType, typename... Ps> |
| 374 void BackgroundHTMLParser::runOnMainThread(FunctionType function, | 374 void BackgroundHTMLParser::runOnMainThread(FunctionType function, |
| 375 Ps&&... parameters) { | 375 Ps&&... parameters) { |
| 376 if (isMainThread()) { | 376 if (isMainThread()) { |
| 377 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); | 377 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); |
| 378 } else { | 378 } else { |
| 379 m_loadingTaskRunner->postTask( | 379 m_loadingTaskRunner->postTask( |
| 380 BLINK_FROM_HERE, | 380 BLINK_FROM_HERE, |
| 381 crossThreadBind(function, std::forward<Ps>(parameters)...)); | 381 crossThreadBind(function, std::forward<Ps>(parameters)...)); |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace blink | 385 } // namespace blink |
| OLD | NEW |