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

Unified Diff: Source/core/html/parser/HTMLDocumentParser.cpp

Issue 690793003: Threaded data provider: Support main thread data notifications (Blink side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use a DocumentLifecycleObserver instead of a WeakPtr to the document Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/loader/DocumentLoader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLDocumentParser.cpp
diff --git a/Source/core/html/parser/HTMLDocumentParser.cpp b/Source/core/html/parser/HTMLDocumentParser.cpp
index 9f9c44dbbffa480ec5f94314793f8f0bfcdf0140..fb11d7563a12c65311dbae110b45fa86c9b56820 100644
--- a/Source/core/html/parser/HTMLDocumentParser.cpp
+++ b/Source/core/html/parser/HTMLDocumentParser.cpp
@@ -29,6 +29,7 @@
#include "core/HTMLNames.h"
#include "core/css/MediaValuesCached.h"
#include "core/dom/DocumentFragment.h"
+#include "core/dom/DocumentLifecycleNotifier.h"
#include "core/dom/Element.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLDocument.h"
@@ -76,11 +77,27 @@ static HTMLTokenizer::State tokenizerStateForContextElement(Element* contextElem
return HTMLTokenizer::DataState;
}
-class ParserDataReceiver : public blink::WebThreadedDataReceiver {
+class ParserDataReceiver : public WebThreadedDataReceiver, public DocumentLifecycleObserver {
public:
- explicit ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser)
- : m_backgroundParser(backgroundParser)
+ explicit ParserDataReceiver(WeakPtr<BackgroundHTMLParser> backgroundParser, Document* document)
+ : DocumentLifecycleObserver(document)
+ , m_backgroundParser(backgroundParser)
+ , m_document(document)
{
+ ASSERT(document);
+ document->lifecycleNotifier().addObserver(this);
haraken 2015/01/16 01:01:59 This won't be needed. DocumentLifecycleObserver's
oystein (OOO til 10th of July) 2015/01/16 04:31:49 Done.
+ }
+
+ virtual ~ParserDataReceiver()
+ {
+ if (m_document)
+ m_document->lifecycleNotifier().removeObserver(this);
haraken 2015/01/16 01:01:59 Ditto. DocumentLifecycleObserver's destructor will
oystein (OOO til 10th of July) 2015/01/16 04:31:49 Done.
+ }
+
+ // DocumentLifecycleObserver
+ virtual void documentWasDetached() override final
+ {
+ m_document = nullptr;
}
// WebThreadedDataReceiver
@@ -99,8 +116,17 @@ public:
return nullptr;
}
+ virtual bool needsMainthreadDataCopy() override final { return InspectorInstrumentation::hasFrontends(); }
+ virtual void acceptMainthreadDataNotification(const char* data, int dataLength, int encodedDataLength) override final
+ {
+ ASSERT(!data || needsMainthreadDataCopy());
+ if (m_document)
+ m_document->loader()->acceptDataFromThreadedReceiver(data, dataLength, encodedDataLength);
+ }
+
private:
WeakPtr<BackgroundHTMLParser> m_backgroundParser;
+ Document* m_document;
haraken 2015/01/16 01:01:59 Remove this. Instead you should use DocumentLifecy
oystein (OOO til 10th of July) 2015/01/16 04:31:49 Done.
};
HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors, ParserSynchronizationPolicy syncPolicy)
@@ -729,7 +755,7 @@ void HTMLDocumentParser::startBackgroundParser()
// TODO(oysteine): Disabled due to crbug.com/398076 until a full fix can be implemented.
if (RuntimeEnabledFeatures::threadedParserDataReceiverEnabled()) {
if (DocumentLoader* loader = document()->loader())
- loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m_backgroundParser)));
+ loader->attachThreadedDataReceiver(adoptPtr(new ParserDataReceiver(m_backgroundParser, document()->contextDocument().get())));
}
OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new BackgroundHTMLParser::Configuration);
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/loader/DocumentLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698