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

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

Issue 2329243002: Implement WTF::WeakPtr in terms of base::WeakPtr (Closed)
Patch Set: Thread-safety fix with comment Created 4 years, 3 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 17 matching lines...) Expand all
28 #include "core/HTMLNames.h" 28 #include "core/HTMLNames.h"
29 #include "core/html/parser/HTMLDocumentParser.h" 29 #include "core/html/parser/HTMLDocumentParser.h"
30 #include "core/html/parser/TextResourceDecoder.h" 30 #include "core/html/parser/TextResourceDecoder.h"
31 #include "core/html/parser/XSSAuditor.h" 31 #include "core/html/parser/XSSAuditor.h"
32 #include "platform/CrossThreadFunctional.h" 32 #include "platform/CrossThreadFunctional.h"
33 #include "platform/Histogram.h" 33 #include "platform/Histogram.h"
34 #include "platform/TraceEvent.h" 34 #include "platform/TraceEvent.h"
35 #include "public/platform/Platform.h" 35 #include "public/platform/Platform.h"
36 #include "public/platform/WebTaskRunner.h" 36 #include "public/platform/WebTaskRunner.h"
37 #include "wtf/CurrentTime.h" 37 #include "wtf/CurrentTime.h"
38 #include "wtf/Functional.h"
38 #include "wtf/PtrUtil.h" 39 #include "wtf/PtrUtil.h"
39 #include "wtf/text/TextPosition.h" 40 #include "wtf/text/TextPosition.h"
40 #include <memory> 41 #include <memory>
41 42
42 namespace blink { 43 namespace blink {
43 44
44 // On a network with high latency and high bandwidth, using a device 45 // On a network with high latency and high bandwidth, using a device
45 // with a fast CPU, we could end up speculatively tokenizing 46 // with a fast CPU, we could end up speculatively tokenizing
46 // the whole document, well ahead of when the main-thread actually needs it. 47 // the whole document, well ahead of when the main-thread actually needs it.
47 // This is a waste of memory (and potentially time if the speculation fails). 48 // This is a waste of memory (and potentially time if the speculation fails).
(...skipping 29 matching lines...) Expand all
77 } 78 }
78 79
79 static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& i nfos) 80 static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& i nfos)
80 { 81 {
81 for (size_t i = 0; i < infos.size(); ++i) 82 for (size_t i = 0; i < infos.size(); ++i)
82 ASSERT(infos[i]->isSafeToSendToAnotherThread()); 83 ASSERT(infos[i]->isSafeToSendToAnotherThread());
83 } 84 }
84 85
85 #endif 86 #endif
86 87
87 void BackgroundHTMLParser::start(PassRefPtr<WeakReference<BackgroundHTMLParser>> reference, std::unique_ptr<Configuration> config, const KURL& documentURL, std: :unique_ptr<CachedDocumentParameters> cachedDocumentParameters, const MediaValue sCached::MediaValuesCachedData& mediaValuesCachedData, std::unique_ptr<WebTaskRu nner> loadingTaskRunner) 88 WeakPtr<BackgroundHTMLParser> BackgroundHTMLParser::create(std::unique_ptr<Confi guration> config, std::unique_ptr<WebTaskRunner> loadingTaskRunner)
88 { 89 {
89 new BackgroundHTMLParser(reference, std::move(config), documentURL, std::mov e(cachedDocumentParameters), mediaValuesCachedData, std::move(loadingTaskRunner) ); 90 auto* backgroundParser = new BackgroundHTMLParser(std::move(config), std::mo ve(loadingTaskRunner));
90 // Caller must free by calling stop(). 91 return backgroundParser->m_weakFactory.createWeakPtr();
91 } 92 }
92 93
94 void BackgroundHTMLParser::init(const KURL& documentURL, std::unique_ptr<CachedD ocumentParameters> cachedDocumentParameters, const MediaValuesCached::MediaValue sCachedData& mediaValuesCachedData)
95 {
96 m_preloadScanner.reset(new TokenPreloadScanner(documentURL, std::move(cached DocumentParameters), mediaValuesCachedData));
97 }
98
99
93 BackgroundHTMLParser::Configuration::Configuration() 100 BackgroundHTMLParser::Configuration::Configuration()
94 : outstandingTokenLimit(defaultOutstandingTokenLimit) 101 : outstandingTokenLimit(defaultOutstandingTokenLimit)
95 , pendingTokenLimit(defaultPendingTokenLimit) 102 , pendingTokenLimit(defaultPendingTokenLimit)
96 , shouldCoalesceChunks(false) 103 , shouldCoalesceChunks(false)
97 { 104 {
98 } 105 }
99 106
100 BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHT MLParser>> reference, std::unique_ptr<Configuration> config, const KURL& documen tURL, std::unique_ptr<CachedDocumentParameters> cachedDocumentParameters, const MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData, std::unique_ptr <WebTaskRunner> loadingTaskRunner) 107 BackgroundHTMLParser::BackgroundHTMLParser(std::unique_ptr<Configuration> config , std::unique_ptr<WebTaskRunner> loadingTaskRunner)
101 : m_weakFactory(reference, this) 108 : m_weakFactory(this)
102 , m_token(wrapUnique(new HTMLToken)) 109 , m_token(wrapUnique(new HTMLToken))
103 , m_tokenizer(HTMLTokenizer::create(config->options)) 110 , m_tokenizer(HTMLTokenizer::create(config->options))
104 , m_treeBuilderSimulator(config->options) 111 , m_treeBuilderSimulator(config->options)
105 , m_options(config->options) 112 , m_options(config->options)
106 , m_outstandingTokenLimit(config->outstandingTokenLimit) 113 , m_outstandingTokenLimit(config->outstandingTokenLimit)
107 , m_parser(config->parser) 114 , m_parser(config->parser)
108 , m_pendingTokens(wrapUnique(new CompactHTMLTokenStream)) 115 , m_pendingTokens(wrapUnique(new CompactHTMLTokenStream))
109 , m_pendingTokenLimit(config->pendingTokenLimit) 116 , m_pendingTokenLimit(config->pendingTokenLimit)
110 , m_xssAuditor(std::move(config->xssAuditor)) 117 , m_xssAuditor(std::move(config->xssAuditor))
111 , m_preloadScanner(wrapUnique(new TokenPreloadScanner(documentURL, std::move (cachedDocumentParameters), mediaValuesCachedData)))
112 , m_decoder(std::move(config->decoder)) 118 , m_decoder(std::move(config->decoder))
113 , m_loadingTaskRunner(std::move(loadingTaskRunner)) 119 , m_loadingTaskRunner(std::move(loadingTaskRunner))
114 , m_tokenizedChunkQueue(config->tokenizedChunkQueue.release()) 120 , m_tokenizedChunkQueue(config->tokenizedChunkQueue.release())
115 , m_pendingCSPMetaTokenIndex(HTMLDocumentParser::TokenizedChunk::noPendingTo ken) 121 , m_pendingCSPMetaTokenIndex(HTMLDocumentParser::TokenizedChunk::noPendingTo ken)
116 , m_startingScript(false) 122 , m_startingScript(false)
117 , m_lastBytesReceivedTime(0.0) 123 , m_lastBytesReceivedTime(0.0)
118 , m_shouldCoalesceChunks(config->shouldCoalesceChunks) 124 , m_shouldCoalesceChunks(config->shouldCoalesceChunks)
119 { 125 {
120 ASSERT(m_outstandingTokenLimit > 0); 126 ASSERT(m_outstandingTokenLimit > 0);
121 ASSERT(m_pendingTokenLimit > 0); 127 ASSERT(m_pendingTokenLimit > 0);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame ters) 358 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame ters)
353 { 359 {
354 if (isMainThread()) { 360 if (isMainThread()) {
355 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); 361 (*WTF::bind(function, std::forward<Ps>(parameters)...))();
356 } else { 362 } else {
357 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(function, std::forward<Ps>(parameters)...)); 363 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(function, std::forward<Ps>(parameters)...));
358 } 364 }
359 } 365 }
360 366
361 } // namespace blink 367 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698