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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 m_stream->didFinishLoading(); | 570 m_stream->didFinishLoading(); |
571 m_loadingFinished = true; | 571 m_loadingFinished = true; |
572 | 572 |
573 // Calling notifyFinishedToClient can result into the upper layers dropping | 573 // Calling notifyFinishedToClient can result into the upper layers dropping |
574 // references to ScriptStreamer. Keep it alive until this function ends. | 574 // references to ScriptStreamer. Keep it alive until this function ends. |
575 RefPtrWillBeRawPtr<ScriptStreamer> protect(this); | 575 RefPtrWillBeRawPtr<ScriptStreamer> protect(this); |
576 | 576 |
577 notifyFinishedToClient(); | 577 notifyFinishedToClient(); |
578 } | 578 } |
579 | 579 |
580 ScriptStreamer::ScriptStreamer(ScriptResource* resource, Type scriptType, Script
State* scriptState, v8::ScriptCompiler::CompileOptions compileOptions, WebTaskRu
nner* loadingTaskRunner) | 580 ScriptStreamer::ScriptStreamer(PendingScript* script, Type scriptType, ScriptSta
te* scriptState, v8::ScriptCompiler::CompileOptions compileOptions, WebTaskRunne
r* loadingTaskRunner) |
581 : m_resource(resource) | 581 : m_pendingScript(script) |
| 582 , m_resource(script->resource()) |
582 , m_detached(false) | 583 , m_detached(false) |
583 , m_stream(0) | 584 , m_stream(0) |
584 , m_client(0) | |
585 , m_loadingFinished(false) | 585 , m_loadingFinished(false) |
586 , m_parsingFinished(false) | 586 , m_parsingFinished(false) |
587 , m_haveEnoughDataForStreaming(false) | 587 , m_haveEnoughDataForStreaming(false) |
588 , m_streamingSuppressed(false) | 588 , m_streamingSuppressed(false) |
589 , m_compileOptions(compileOptions) | 589 , m_compileOptions(compileOptions) |
590 , m_scriptState(scriptState) | 590 , m_scriptState(scriptState) |
591 , m_scriptType(scriptType) | 591 , m_scriptType(scriptType) |
592 , 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. | 592 , 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. |
593 , m_loadingTaskRunner(adoptPtr(loadingTaskRunner->clone())) | 593 , m_loadingTaskRunner(adoptPtr(loadingTaskRunner->clone())) |
594 { | 594 { |
595 } | 595 } |
596 | 596 |
597 ScriptStreamer::~ScriptStreamer() | 597 ScriptStreamer::~ScriptStreamer() |
598 { | 598 { |
599 } | 599 } |
600 | 600 |
601 DEFINE_TRACE(ScriptStreamer) | 601 DEFINE_TRACE(ScriptStreamer) |
602 { | 602 { |
| 603 visitor->trace(m_pendingScript); |
603 visitor->trace(m_resource); | 604 visitor->trace(m_resource); |
604 } | 605 } |
605 | 606 |
606 void ScriptStreamer::streamingComplete() | 607 void ScriptStreamer::streamingComplete() |
607 { | 608 { |
608 // The background task is completed; do the necessary ramp-down in the main | 609 // The background task is completed; do the necessary ramp-down in the main |
609 // thread. | 610 // thread. |
610 ASSERT(isMainThread()); | 611 ASSERT(isMainThread()); |
611 | 612 |
612 // It's possible that the corresponding Resource was deleted before V8 | 613 // It's possible that the corresponding Resource was deleted before V8 |
(...skipping 22 matching lines...) Expand all Loading... |
635 // time to catch up. But the other way is possible too: if V8 detects a | 636 // time to catch up. But the other way is possible too: if V8 detects a |
636 // parse error, the V8 side can complete before loading has finished. Send | 637 // parse error, the V8 side can complete before loading has finished. Send |
637 // the notification after both loading and V8 side operations have | 638 // the notification after both loading and V8 side operations have |
638 // completed. Here we also check that we have a client: it can happen that a | 639 // completed. Here we also check that we have a client: it can happen that a |
639 // function calling notifyFinishedToClient was already scheduled in the task | 640 // function calling notifyFinishedToClient was already scheduled in the task |
640 // queue and the upper layer decided that it's not interested in the script | 641 // queue and the upper layer decided that it's not interested in the script |
641 // and called removeClient. | 642 // and called removeClient. |
642 if (!isFinished()) | 643 if (!isFinished()) |
643 return; | 644 return; |
644 | 645 |
645 if (m_client) | 646 m_pendingScript->streamingFinished(); |
646 m_client->notifyFinished(m_resource); | |
647 } | 647 } |
648 | 648 |
649 bool ScriptStreamer::startStreamingInternal(PendingScript* script, Type scriptTy
pe, Settings* settings, ScriptState* scriptState, WebTaskRunner* loadingTaskRunn
er) | 649 bool ScriptStreamer::startStreamingInternal(PendingScript* script, Type scriptTy
pe, Settings* settings, ScriptState* scriptState, WebTaskRunner* loadingTaskRunn
er) |
650 { | 650 { |
651 ASSERT(isMainThread()); | 651 ASSERT(isMainThread()); |
652 ASSERT(scriptState->contextIsValid()); | 652 ASSERT(scriptState->contextIsValid()); |
653 ScriptResource* resource = script->resource(); | 653 ScriptResource* resource = script->resource(); |
654 if (resource->isLoaded()) { | 654 if (resource->isLoaded()) { |
655 recordNotStreamingReasonHistogram(scriptType, AlreadyLoaded); | 655 recordNotStreamingReasonHistogram(scriptType, AlreadyLoaded); |
656 return false; | 656 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
672 | 672 |
673 // Decide what kind of cached data we should produce while streaming. Only | 673 // Decide what kind of cached data we should produce while streaming. Only |
674 // produce parser cache if the non-streaming compile takes advantage of it. | 674 // produce parser cache if the non-streaming compile takes advantage of it. |
675 v8::ScriptCompiler::CompileOptions compileOption = v8::ScriptCompiler::kNoCo
mpileOptions; | 675 v8::ScriptCompiler::CompileOptions compileOption = v8::ScriptCompiler::kNoCo
mpileOptions; |
676 if (settings->v8CacheOptions() == V8CacheOptionsParse) | 676 if (settings->v8CacheOptions() == V8CacheOptionsParse) |
677 compileOption = v8::ScriptCompiler::kProduceParserCache; | 677 compileOption = v8::ScriptCompiler::kProduceParserCache; |
678 | 678 |
679 // The Resource might go out of scope if the script is no longer | 679 // The Resource might go out of scope if the script is no longer |
680 // needed. This makes PendingScript notify the ScriptStreamer when it is | 680 // needed. This makes PendingScript notify the ScriptStreamer when it is |
681 // destroyed. | 681 // destroyed. |
682 script->setStreamer(ScriptStreamer::create(resource, scriptType, scriptState
, compileOption, loadingTaskRunner)); | 682 script->setStreamer(ScriptStreamer::create(script, scriptType, scriptState,
compileOption, loadingTaskRunner)); |
683 | 683 |
684 return true; | 684 return true; |
685 } | 685 } |
686 | 686 |
687 } // namespace blink | 687 } // namespace blink |
OLD | NEW |