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

Side by Side Diff: Source/core/html/parser/HTMLDocumentParser.cpp

Issue 74513003: Moved text decoding to the parser thread (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@parserthread_step25
Patch Set: Created 7 years, 1 month 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) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 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 24 matching lines...) Expand all
35 #include "core/html/parser/CompactHTMLToken.h" 35 #include "core/html/parser/CompactHTMLToken.h"
36 #include "core/html/parser/HTMLIdentifier.h" 36 #include "core/html/parser/HTMLIdentifier.h"
37 #include "core/html/parser/HTMLParserScheduler.h" 37 #include "core/html/parser/HTMLParserScheduler.h"
38 #include "core/html/parser/HTMLParserThread.h" 38 #include "core/html/parser/HTMLParserThread.h"
39 #include "core/html/parser/HTMLPreloadScanner.h" 39 #include "core/html/parser/HTMLPreloadScanner.h"
40 #include "core/html/parser/HTMLScriptRunner.h" 40 #include "core/html/parser/HTMLScriptRunner.h"
41 #include "core/html/parser/HTMLTokenizer.h" 41 #include "core/html/parser/HTMLTokenizer.h"
42 #include "core/html/parser/HTMLTreeBuilder.h" 42 #include "core/html/parser/HTMLTreeBuilder.h"
43 #include "core/inspector/InspectorInstrumentation.h" 43 #include "core/inspector/InspectorInstrumentation.h"
44 #include "core/frame/Frame.h" 44 #include "core/frame/Frame.h"
45 #include "platform/SharedBuffer.h"
45 #include "platform/TraceEvent.h" 46 #include "platform/TraceEvent.h"
46 #include "wtf/Functional.h" 47 #include "wtf/Functional.h"
47 48
48 namespace WebCore { 49 namespace WebCore {
49 50
50 using namespace HTMLNames; 51 using namespace HTMLNames;
51 52
52 // This is a direct transcription of step 4 from: 53 // This is a direct transcription of step 4 from:
53 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#frag ment-case 54 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#frag ment-case
54 static HTMLTokenizer::State tokenizerStateForContextElement(Element* contextElem ent, bool reportErrors, const HTMLParserOptions& options) 55 static HTMLTokenizer::State tokenizerStateForContextElement(Element* contextElem ent, bool reportErrors, const HTMLParserOptions& options)
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 313
313 // processParsedChunkFromBackgroundParser can cause this parser to be detach ed from the Document, 314 // processParsedChunkFromBackgroundParser can cause this parser to be detach ed from the Document,
314 // but we need to ensure it isn't deleted yet. 315 // but we need to ensure it isn't deleted yet.
315 RefPtr<HTMLDocumentParser> protect(this); 316 RefPtr<HTMLDocumentParser> protect(this);
316 317
317 ASSERT(m_speculations.isEmpty()); 318 ASSERT(m_speculations.isEmpty());
318 chunk->preloads.clear(); // We don't need to preload because we're going to parse immediately. 319 chunk->preloads.clear(); // We don't need to preload because we're going to parse immediately.
319 m_speculations.append(chunk); 320 m_speculations.append(chunk);
320 pumpPendingSpeculations(); 321 pumpPendingSpeculations();
321 } 322 }
323 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume ntEncodingData& data)
abarth-chromium 2013/11/18 06:57:10 Missing a blank line above this line.
oystein (OOO til 10th of July) 2013/11/18 22:18:42 Done.
324 {
325 document()->setEncodingData(data);
326 }
322 327
323 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) 328 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk)
324 { 329 {
325 ASSERT(chunk); 330 ASSERT(chunk);
326 if (isWaitingForScripts()) { 331 if (isWaitingForScripts()) {
327 // We're waiting on a network script, just save the chunk, we'll get 332 // We're waiting on a network script, just save the chunk, we'll get
328 // a second validateSpeculations call after the script completes. 333 // a second validateSpeculations call after the script completes.
329 // This call should have been made immediately after runScriptsForPaused TreeBuilder 334 // This call should have been made immediately after runScriptsForPaused TreeBuilder
330 // which may have started a network load and left us waiting. 335 // which may have started a network load and left us waiting.
331 ASSERT(!m_lastChunkBeforeScript); 336 ASSERT(!m_lastChunkBeforeScript);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 673
669 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration); 674 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background HTMLParser::Configuration);
670 config->options = m_options; 675 config->options = m_options;
671 config->parser = m_weakFactory.createWeakPtr(); 676 config->parser = m_weakFactory.createWeakPtr();
672 config->xssAuditor = adoptPtr(new XSSAuditor); 677 config->xssAuditor = adoptPtr(new XSSAuditor);
673 config->xssAuditor->init(document(), &m_xssAuditorDelegate); 678 config->xssAuditor->init(document(), &m_xssAuditorDelegate);
674 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), document()->devicePixelRatio())); 679 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url(). copy(), document()->devicePixelRatio()));
675 680
676 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); 681 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread());
677 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); 682 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread());
678 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::create, ref erence.release(), config.release())); 683 OwnPtr<TextResourceDecoder> decoder = adoptDecoder();
684 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::create, ref erence.release(), config.release(), decoder.release()));
679 } 685 }
680 686
681 void HTMLDocumentParser::stopBackgroundParser() 687 void HTMLDocumentParser::stopBackgroundParser()
682 { 688 {
683 ASSERT(shouldUseThreading()); 689 ASSERT(shouldUseThreading());
684 ASSERT(m_haveBackgroundParser); 690 ASSERT(m_haveBackgroundParser);
685 m_haveBackgroundParser = false; 691 m_haveBackgroundParser = false;
686 692
687 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::stop, m_bac kgroundParser)); 693 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::stop, m_bac kgroundParser));
688 m_weakFactory.revokeAll(); 694 m_weakFactory.revokeAll();
689 } 695 }
690 696
691 void HTMLDocumentParser::append(PassRefPtr<StringImpl> inputSource) 697 void HTMLDocumentParser::append(PassRefPtr<StringImpl> inputSource)
692 { 698 {
693 if (isStopped()) 699 if (isStopped())
694 return; 700 return;
695 701
696 if (shouldUseThreading()) { 702 // We should never reach this point if we're using a parser thread,
697 if (!m_haveBackgroundParser) 703 // as appendBytes() will directly ship the data to the thread.
698 startBackgroundParser(); 704 ASSERT(!shouldUseThreading());
699
700 ASSERT(inputSource->hasOneRef());
701 TRACE_EVENT1("net", "HTMLDocumentParser::append", "size", inputSource->l ength());
eseidel 2013/11/18 20:07:40 We've lost this trace event now. I'm not sure tha
oystein (OOO til 10th of July) 2013/11/18 22:18:42 Added to appendBytes() now, just in case.
702 // NOTE: Important that the String temporary is destroyed before we post the task
703 // otherwise the String could call deref() on a StringImpl now owned by the background parser.
704 // We would like to ASSERT(closure.arg3()->hasOneRef()) but sadly the ar gs are private.
705 Closure closure = bind(&BackgroundHTMLParser::append, m_backgroundParser , String(inputSource));
706 HTMLParserThread::shared()->postTask(closure);
707 return;
708 }
709 705
710 // pumpTokenizer can cause this parser to be detached from the Document, 706 // pumpTokenizer can cause this parser to be detached from the Document,
711 // but we need to ensure it isn't deleted yet. 707 // but we need to ensure it isn't deleted yet.
712 RefPtr<HTMLDocumentParser> protect(this); 708 RefPtr<HTMLDocumentParser> protect(this);
713 TRACE_EVENT1("net", "HTMLDocumentParser::append", "size", inputSource->lengt h()); 709 TRACE_EVENT1("net", "HTMLDocumentParser::append", "size", inputSource->lengt h());
714 String source(inputSource); 710 String source(inputSource);
715 711
716 if (m_preloadScanner) { 712 if (m_preloadScanner) {
717 if (m_input.current().isEmpty() && !isWaitingForScripts()) { 713 if (m_input.current().isEmpty() && !isWaitingForScripts()) {
718 // We have parsed until the end of the current input and so are now moving ahead of the preload scanner. 714 // We have parsed until the end of the current input and so are now moving ahead of the preload scanner.
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 if (m_parserScheduler) 960 if (m_parserScheduler)
965 m_parserScheduler->suspend(); 961 m_parserScheduler->suspend();
966 } 962 }
967 963
968 void HTMLDocumentParser::resumeScheduledTasks() 964 void HTMLDocumentParser::resumeScheduledTasks()
969 { 965 {
970 if (m_parserScheduler) 966 if (m_parserScheduler)
971 m_parserScheduler->resume(); 967 m_parserScheduler->resume();
972 } 968 }
973 969
970 void HTMLDocumentParser::appendBytes(const char* data, size_t length)
971 {
972 if (!length || isDetached())
973 return;
974
975 if (shouldUseThreading()) {
976 if (!m_haveBackgroundParser)
977 startBackgroundParser();
978
979 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::appendB ytes, m_backgroundParser, SharedBuffer::create(data, length)));
abarth-chromium 2013/11/18 06:57:10 Why a SharedBuffer and not just a Vector? It's to
oystein (OOO til 10th of July) 2013/11/18 22:18:42 I didn't see any other buffer classes when I looke
980 return;
981 }
982
983 DecodedDataDocumentParser::appendBytes(data, length);
974 } 984 }
985
986 void HTMLDocumentParser::flush()
987 {
988 // If we've got no decoder, we never received any data.
989 if (isDetached() || needsDecoder())
990 return;
991
992 if (m_haveBackgroundParser)
993 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::flush, m_backgroundParser));
994 else
995 DecodedDataDocumentParser::flush();
996 }
997
998 }
OLDNEW
« Source/core/html/parser/HTMLDocumentParser.h ('K') | « Source/core/html/parser/HTMLDocumentParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698