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

Unified Diff: Source/core/dom/PendingScript.cpp

Issue 368283002: Stream scripts to V8 as they load - Blink side. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: cleanup Created 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/PendingScript.cpp
diff --git a/Source/core/dom/PendingScript.cpp b/Source/core/dom/PendingScript.cpp
index 58b27c2ce913bfdbdfbb7deaea6564e817a692be..c2fb4afbcac358565bb14619660c338336b5e55f 100644
--- a/Source/core/dom/PendingScript.cpp
+++ b/Source/core/dom/PendingScript.cpp
@@ -26,6 +26,7 @@
#include "config.h"
#include "core/dom/PendingScript.h"
+#include "bindings/core/v8/ScriptStreamer.h"
#include "core/dom/Element.h"
#include "core/fetch/ScriptResource.h"
@@ -35,23 +36,33 @@ PendingScript::~PendingScript()
{
}
-void PendingScript::watchForLoad(ResourceClient* client)
+void PendingScript::watchForLoad(ScriptResourceClient* client)
{
ASSERT(!m_watchingForLoad);
ASSERT(!resource()->isLoaded());
- // addClient() will call notifyFinished() if the load is complete. Callers
- // do not expect to be re-entered from this call, so they should not become
- // a client of an already-loaded Resource.
- resource()->addClient(client);
+ if (m_streamer) {
+ m_streamer->addClient(client);
+ } else {
+ // addClient() will call notifyFinished() if the load is
+ // complete. Callers do not expect to be re-entered from this call, so
+ // they should not become a client of an already-loaded Resource.
+ resource()->addClient(client);
+ }
m_watchingForLoad = true;
}
-void PendingScript::stopWatchingForLoad(ResourceClient* client)
+void PendingScript::stopWatchingForLoad(ScriptResourceClient* client)
{
- if (resource() && m_watchingForLoad) {
+ if (!m_watchingForLoad) {
+ return;
+ }
+ if (m_streamer) {
+ m_streamer->cancel();
+ m_streamer->removeClient(client);
+ } else if (resource()) {
haraken 2014/09/10 05:57:52 How is it possible that resource() returns 0 here?
marja 2014/09/11 09:15:37 This code was originally in HTMLScriptRunner like
resource()->removeClient(client);
- m_watchingForLoad = false;
}
+ m_watchingForLoad = false;
}
PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear()
@@ -65,10 +76,25 @@ PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear()
void PendingScript::setScriptResource(ScriptResource* resource)
{
setResource(resource);
+ // This function is only called 1) during construction (we're not yet
+ // streaming) 2) after loading has completed (and streaming too, if we were
+ // streaming).
+ ASSERT(!m_streamer || !m_streamer->streamingInProgress());
haraken 2014/09/10 05:57:52 ASSERT(!isStreaming());
haraken 2014/09/10 05:57:52 Add ASSERT(!m_watchingForLoad);
marja 2014/09/11 09:15:37 Done.
marja 2014/09/11 09:15:37 Done.
marja 2014/09/16 11:20:38 Actually, this is not true in the current code (in
+ m_streamer.release();
}
void PendingScript::notifyFinished(Resource*)
{
+ if (m_streamer) {
+ m_streamer->notifyFinished();
+ }
+}
+
+void PendingScript::notifyAppendData(ScriptResource*)
+{
+ if (m_streamer) {
+ m_streamer->notifyAppendData();
+ }
}
void PendingScript::trace(Visitor* visitor)
@@ -81,10 +107,18 @@ ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc
if (resource()) {
errorOccurred = resource()->errorOccurred();
ASSERT(resource()->isLoaded());
+ if (m_streamer && !m_streamer->streamingSuppressed()) {
haraken 2014/09/10 05:57:51 Help me understand: Why do we need this branch? Ca
marja 2014/09/11 09:15:37 We need to somehow take the results of streaming i
+ return ScriptSourceCode(m_streamer, resource());
+ }
return ScriptSourceCode(resource());
}
errorOccurred = false;
return ScriptSourceCode(m_element->textContent(), documentURL, startingPosition());
}
+bool PendingScript::isStreaming() const
+{
+ return m_streamer && m_streamer->streamingInProgress();
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698