OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "bindings/core/v8/ScriptStreamer.h" | 5 #include "bindings/core/v8/ScriptStreamer.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptStreamerThread.h" | 7 #include "bindings/core/v8/ScriptStreamerThread.h" |
8 #include "bindings/core/v8/V8ScriptRunner.h" | 8 #include "bindings/core/v8/V8ScriptRunner.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 m_stream->didFinishLoading(); | 560 m_stream->didFinishLoading(); |
561 m_loadingFinished = true; | 561 m_loadingFinished = true; |
562 | 562 |
563 // Calling notifyFinishedToClient can result into the upper layers dropping | 563 // Calling notifyFinishedToClient can result into the upper layers dropping |
564 // references to ScriptStreamer. Keep it alive until this function ends. | 564 // references to ScriptStreamer. Keep it alive until this function ends. |
565 RefPtrWillBeRawPtr<ScriptStreamer> protect(this); | 565 RefPtrWillBeRawPtr<ScriptStreamer> protect(this); |
566 | 566 |
567 notifyFinishedToClient(); | 567 notifyFinishedToClient(); |
568 } | 568 } |
569 | 569 |
570 ScriptStreamer::ScriptStreamer(ScriptResource* resource, Type scriptType, Script
State* scriptState, v8::ScriptCompiler::CompileOptions compileOptions, WebTaskRu
nner* loadingTaskRunner) | 570 ScriptStreamer::ScriptStreamer(PendingScript* script, Type scriptType, ScriptSta
te* scriptState, v8::ScriptCompiler::CompileOptions compileOptions, WebTaskRunne
r* loadingTaskRunner) |
571 : m_resource(resource) | 571 : m_pendingScript(script) |
| 572 , m_resource(script->resource()) |
572 , m_detached(false) | 573 , m_detached(false) |
573 , m_stream(0) | 574 , m_stream(0) |
574 , m_client(0) | |
575 , m_loadingFinished(false) | 575 , m_loadingFinished(false) |
576 , m_parsingFinished(false) | 576 , m_parsingFinished(false) |
577 , m_haveEnoughDataForStreaming(false) | 577 , m_haveEnoughDataForStreaming(false) |
578 , m_streamingSuppressed(false) | 578 , m_streamingSuppressed(false) |
579 , m_compileOptions(compileOptions) | 579 , m_compileOptions(compileOptions) |
580 , m_scriptState(scriptState) | 580 , m_scriptState(scriptState) |
581 , m_scriptType(scriptType) | 581 , m_scriptType(scriptType) |
582 , m_encoding(v8::ScriptCompiler::StreamedSource::TWO_BYTE) // Unfortunately
there's no dummy encoding value in the enum; let's use one we don't stream. | 582 , m_encoding(v8::ScriptCompiler::StreamedSource::TWO_BYTE) // Unfortunately
there's no dummy encoding value in the enum; let's use one we don't stream. |
583 , m_loadingTaskRunner(adoptPtr(loadingTaskRunner->clone())) | 583 , m_loadingTaskRunner(adoptPtr(loadingTaskRunner->clone())) |
584 { | 584 { |
585 } | 585 } |
586 | 586 |
587 ScriptStreamer::~ScriptStreamer() | 587 ScriptStreamer::~ScriptStreamer() |
588 { | 588 { |
589 } | 589 } |
590 | 590 |
591 DEFINE_TRACE(ScriptStreamer) | 591 DEFINE_TRACE(ScriptStreamer) |
592 { | 592 { |
| 593 visitor->trace(m_pendingScript); |
593 visitor->trace(m_resource); | 594 visitor->trace(m_resource); |
594 } | 595 } |
595 | 596 |
596 void ScriptStreamer::streamingComplete() | 597 void ScriptStreamer::streamingComplete() |
597 { | 598 { |
598 // The background task is completed; do the necessary ramp-down in the main | 599 // The background task is completed; do the necessary ramp-down in the main |
599 // thread. | 600 // thread. |
600 ASSERT(isMainThread()); | 601 ASSERT(isMainThread()); |
601 | 602 |
602 // It's possible that the corresponding Resource was deleted before V8 | 603 // It's possible that the corresponding Resource was deleted before V8 |
(...skipping 22 matching lines...) Expand all Loading... |
625 // time to catch up. But the other way is possible too: if V8 detects a | 626 // time to catch up. But the other way is possible too: if V8 detects a |
626 // parse error, the V8 side can complete before loading has finished. Send | 627 // parse error, the V8 side can complete before loading has finished. Send |
627 // the notification after both loading and V8 side operations have | 628 // the notification after both loading and V8 side operations have |
628 // completed. Here we also check that we have a client: it can happen that a | 629 // completed. Here we also check that we have a client: it can happen that a |
629 // function calling notifyFinishedToClient was already scheduled in the task | 630 // function calling notifyFinishedToClient was already scheduled in the task |
630 // queue and the upper layer decided that it's not interested in the script | 631 // queue and the upper layer decided that it's not interested in the script |
631 // and called removeClient. | 632 // and called removeClient. |
632 if (!isFinished()) | 633 if (!isFinished()) |
633 return; | 634 return; |
634 | 635 |
635 if (m_client) | 636 m_pendingScript->streamingFinished(); |
636 m_client->notifyFinished(m_resource); | |
637 } | 637 } |
638 | 638 |
639 bool ScriptStreamer::startStreamingInternal(PendingScript* script, Type scriptTy
pe, Settings* settings, ScriptState* scriptState, WebTaskRunner* loadingTaskRunn
er) | 639 bool ScriptStreamer::startStreamingInternal(PendingScript* script, Type scriptTy
pe, Settings* settings, ScriptState* scriptState, WebTaskRunner* loadingTaskRunn
er) |
640 { | 640 { |
641 ASSERT(isMainThread()); | 641 ASSERT(isMainThread()); |
642 ASSERT(scriptState->contextIsValid()); | 642 ASSERT(scriptState->contextIsValid()); |
643 ScriptResource* resource = script->resource(); | 643 ScriptResource* resource = script->resource(); |
644 if (resource->isLoaded()) { | 644 if (resource->isLoaded()) { |
645 Platform::current()->histogramEnumeration(notStreamingReasonHistogramNam
e(scriptType), AlreadyLoaded, NotStreamingReasonEnd); | 645 Platform::current()->histogramEnumeration(notStreamingReasonHistogramNam
e(scriptType), AlreadyLoaded, NotStreamingReasonEnd); |
646 return false; | 646 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
662 | 662 |
663 // Decide what kind of cached data we should produce while streaming. Only | 663 // Decide what kind of cached data we should produce while streaming. Only |
664 // produce parser cache if the non-streaming compile takes advantage of it. | 664 // produce parser cache if the non-streaming compile takes advantage of it. |
665 v8::ScriptCompiler::CompileOptions compileOption = v8::ScriptCompiler::kNoCo
mpileOptions; | 665 v8::ScriptCompiler::CompileOptions compileOption = v8::ScriptCompiler::kNoCo
mpileOptions; |
666 if (settings->v8CacheOptions() == V8CacheOptionsParse) | 666 if (settings->v8CacheOptions() == V8CacheOptionsParse) |
667 compileOption = v8::ScriptCompiler::kProduceParserCache; | 667 compileOption = v8::ScriptCompiler::kProduceParserCache; |
668 | 668 |
669 // The Resource might go out of scope if the script is no longer | 669 // The Resource might go out of scope if the script is no longer |
670 // needed. This makes PendingScript notify the ScriptStreamer when it is | 670 // needed. This makes PendingScript notify the ScriptStreamer when it is |
671 // destroyed. | 671 // destroyed. |
672 script->setStreamer(ScriptStreamer::create(resource, scriptType, scriptState
, compileOption, loadingTaskRunner)); | 672 script->setStreamer(ScriptStreamer::create(script, scriptType, scriptState,
compileOption, loadingTaskRunner)); |
673 | 673 |
674 return true; | 674 return true; |
675 } | 675 } |
676 | 676 |
677 } // namespace blink | 677 } // namespace blink |
OLD | NEW |