| 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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // streaming case). | 370 // streaming case). |
| 371 // We store this separately, to avoid having to guard all | 371 // We store this separately, to avoid having to guard all |
| 372 // m_queueLeadPosition references with a mutex. | 372 // m_queueLeadPosition references with a mutex. |
| 373 unsigned m_lengthOfBOM; // Used by both threads; guarded by m_mutex. | 373 unsigned m_lengthOfBOM; // Used by both threads; guarded by m_mutex. |
| 374 | 374 |
| 375 OwnPtr<WebTaskRunner> m_loadingTaskRunner; | 375 OwnPtr<WebTaskRunner> m_loadingTaskRunner; |
| 376 }; | 376 }; |
| 377 | 377 |
| 378 size_t ScriptStreamer::kSmallScriptThreshold = 30 * 1024; | 378 size_t ScriptStreamer::kSmallScriptThreshold = 30 * 1024; |
| 379 | 379 |
| 380 void ScriptStreamer::startStreaming(PendingScript& script, PendingScript::Type s
criptType, Settings* settings, ScriptState* scriptState, WebTaskRunner* loadingT
askRunner) | 380 void ScriptStreamer::startStreaming(PendingScript* script, PendingScript::Type s
criptType, Settings* settings, ScriptState* scriptState, WebTaskRunner* loadingT
askRunner) |
| 381 { | 381 { |
| 382 // We don't yet know whether the script will really be streamed. E.g., | 382 // We don't yet know whether the script will really be streamed. E.g., |
| 383 // suppressing streaming for short scripts is done later. Record only the | 383 // suppressing streaming for short scripts is done later. Record only the |
| 384 // sure negative cases here. | 384 // sure negative cases here. |
| 385 bool startedStreaming = startStreamingInternal(script, scriptType, settings,
scriptState, loadingTaskRunner); | 385 bool startedStreaming = startStreamingInternal(script, scriptType, settings,
scriptState, loadingTaskRunner); |
| 386 if (!startedStreaming) | 386 if (!startedStreaming) |
| 387 Platform::current()->histogramEnumeration(startedStreamingHistogramName(
scriptType), 0, 2); | 387 Platform::current()->histogramEnumeration(startedStreamingHistogramName(
scriptType), 0, 2); |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool ScriptStreamer::convertEncoding(const char* encodingName, v8::ScriptCompile
r::StreamedSource::Encoding* encoding) | 390 bool ScriptStreamer::convertEncoding(const char* encodingName, v8::ScriptCompile
r::StreamedSource::Encoding* encoding) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 // function calling notifyFinishedToClient was already scheduled in the task | 629 // function calling notifyFinishedToClient was already scheduled in the task |
| 630 // queue and the upper layer decided that it's not interested in the script | 630 // queue and the upper layer decided that it's not interested in the script |
| 631 // and called removeClient. | 631 // and called removeClient. |
| 632 if (!isFinished()) | 632 if (!isFinished()) |
| 633 return; | 633 return; |
| 634 | 634 |
| 635 if (m_client) | 635 if (m_client) |
| 636 m_client->notifyFinished(m_resource); | 636 m_client->notifyFinished(m_resource); |
| 637 } | 637 } |
| 638 | 638 |
| 639 bool ScriptStreamer::startStreamingInternal(PendingScript& script, PendingScript
::Type scriptType, Settings* settings, ScriptState* scriptState, WebTaskRunner*
loadingTaskRunner) | 639 bool ScriptStreamer::startStreamingInternal(PendingScript* script, PendingScript
::Type scriptType, Settings* settings, ScriptState* scriptState, WebTaskRunner*
loadingTaskRunner) |
| 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; |
| 647 } | 647 } |
| 648 if (!resource->url().protocolIsInHTTPFamily()) { | 648 if (!resource->url().protocolIsInHTTPFamily()) { |
| 649 Platform::current()->histogramEnumeration(notStreamingReasonHistogramNam
e(scriptType), NotHTTP, NotStreamingReasonEnd); | 649 Platform::current()->histogramEnumeration(notStreamingReasonHistogramNam
e(scriptType), NotHTTP, NotStreamingReasonEnd); |
| 650 return false; | 650 return false; |
| 651 } | 651 } |
| 652 if (resource->isCacheValidator()) { | 652 if (resource->isCacheValidator()) { |
| 653 Platform::current()->histogramEnumeration(notStreamingReasonHistogramNam
e(scriptType), Reload, NotStreamingReasonEnd); | 653 Platform::current()->histogramEnumeration(notStreamingReasonHistogramNam
e(scriptType), Reload, NotStreamingReasonEnd); |
| 654 // This happens e.g., during reloads. We're actually not going to load | 654 // This happens e.g., during reloads. We're actually not going to load |
| 655 // the current Resource of the PendingScript but switch to another | 655 // the current Resource of the PendingScript but switch to another |
| 656 // Resource -> don't stream. | 656 // Resource -> don't stream. |
| 657 return false; | 657 return false; |
| 658 } | 658 } |
| 659 // We cannot filter out short scripts, even if we wait for the HTTP headers | 659 // We cannot filter out short scripts, even if we wait for the HTTP headers |
| 660 // to arrive: the Content-Length HTTP header is not sent for chunked | 660 // to arrive: the Content-Length HTTP header is not sent for chunked |
| 661 // downloads. | 661 // downloads. |
| 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(resource, scriptType, scriptState
, compileOption, loadingTaskRunner)); |
| 673 | 673 |
| 674 return true; | 674 return true; |
| 675 } | 675 } |
| 676 | 676 |
| 677 } // namespace blink | 677 } // namespace blink |
| OLD | NEW |