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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptStreamerImpl.cpp

Issue 2653923008: Reland of Split PendingScript into PendingScript and ClassicPendingScript (Closed)
Patch Set: Crash fix by adding Dispose() as ClassicPendingScript prefinalizer Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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/ScriptStreamerImpl.h" 5 #include "bindings/core/v8/ScriptStreamerImpl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "bindings/core/v8/ScriptStreamerThread.h" 8 #include "bindings/core/v8/ScriptStreamerThread.h"
9 #include "bindings/core/v8/V8ScriptRunner.h" 9 #include "bindings/core/v8/V8ScriptRunner.h"
10 #include "core/dom/ClassicPendingScript.h"
10 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
11 #include "core/dom/Element.h" 12 #include "core/dom/Element.h"
12 #include "core/dom/PendingScript.h"
13 #include "core/frame/Settings.h" 13 #include "core/frame/Settings.h"
14 #include "core/html/parser/TextResourceDecoder.h" 14 #include "core/html/parser/TextResourceDecoder.h"
15 #include "core/loader/resource/ScriptResource.h" 15 #include "core/loader/resource/ScriptResource.h"
16 #include "platform/CrossThreadFunctional.h" 16 #include "platform/CrossThreadFunctional.h"
17 #include "platform/Histogram.h" 17 #include "platform/Histogram.h"
18 #include "platform/SharedBuffer.h" 18 #include "platform/SharedBuffer.h"
19 #include "platform/instrumentation/tracing/TraceEvent.h" 19 #include "platform/instrumentation/tracing/TraceEvent.h"
20 #include "platform/loader/fetch/CachedMetadata.h" 20 #include "platform/loader/fetch/CachedMetadata.h"
21 #include "platform/wtf/Deque.h" 21 #include "platform/wtf/Deque.h"
22 #include "platform/wtf/PtrUtil.h" 22 #include "platform/wtf/PtrUtil.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 SourceStreamDataQueue data_queue_; // Thread safe. 321 SourceStreamDataQueue data_queue_; // Thread safe.
322 size_t queue_lead_position_; // Only used by v8 thread. 322 size_t queue_lead_position_; // Only used by v8 thread.
323 size_t queue_tail_position_; // Used by both threads; guarded by m_mutex. 323 size_t queue_tail_position_; // Used by both threads; guarded by m_mutex.
324 324
325 RefPtr<WebTaskRunner> loading_task_runner_; 325 RefPtr<WebTaskRunner> loading_task_runner_;
326 }; 326 };
327 327
328 size_t ScriptStreamerImpl::small_script_threshold_ = 30 * 1024; 328 size_t ScriptStreamerImpl::small_script_threshold_ = 30 * 1024;
329 329
330 void ScriptStreamerImpl::StartStreaming( 330 void ScriptStreamerImpl::StartStreaming(
331 PendingScript* script, 331 ClassicPendingScript* script,
332 Type script_type, 332 Type script_type,
333 Settings* settings, 333 Settings* settings,
334 ScriptState* script_state, 334 ScriptState* script_state,
335 RefPtr<WebTaskRunner> loading_task_runner) { 335 RefPtr<WebTaskRunner> loading_task_runner) {
336 // We don't yet know whether the script will really be streamed. E.g., 336 // We don't yet know whether the script will really be streamed. E.g.,
337 // suppressing streaming for short scripts is done later. Record only the 337 // suppressing streaming for short scripts is done later. Record only the
338 // sure negative cases here. 338 // sure negative cases here.
339 bool started_streaming = 339 bool started_streaming =
340 StartStreamingInternal(script, script_type, settings, script_state, 340 StartStreamingInternal(script, script_type, settings, script_state,
341 std::move(loading_task_runner)); 341 std::move(loading_task_runner));
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 SuppressStreaming(); 511 SuppressStreaming();
512 } 512 }
513 if (stream_) 513 if (stream_)
514 stream_->DidFinishLoading(); 514 stream_->DidFinishLoading();
515 loading_finished_ = true; 515 loading_finished_ = true;
516 516
517 NotifyFinishedToClient(); 517 NotifyFinishedToClient();
518 } 518 }
519 519
520 ScriptStreamerImpl::ScriptStreamerImpl( 520 ScriptStreamerImpl::ScriptStreamerImpl(
521 PendingScript* script, 521 ClassicPendingScript* script,
522 Type script_type, 522 Type script_type,
523 ScriptState* script_state, 523 ScriptState* script_state,
524 v8::ScriptCompiler::CompileOptions compile_options, 524 v8::ScriptCompiler::CompileOptions compile_options,
525 RefPtr<WebTaskRunner> loading_task_runner) 525 RefPtr<WebTaskRunner> loading_task_runner)
526 : pending_script_(script), 526 : pending_script_(script),
527 resource_(script->GetResource()), 527 resource_(script->GetResource()),
528 detached_(false), 528 detached_(false),
529 stream_(0), 529 stream_(0),
530 loading_finished_(false), 530 loading_finished_(false),
531 parsing_finished_(false), 531 parsing_finished_(false),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 // parse error, the V8 side can complete before loading has finished. Send 576 // parse error, the V8 side can complete before loading has finished. Send
577 // the notification after both loading and V8 side operations have 577 // the notification after both loading and V8 side operations have
578 // completed. 578 // completed.
579 if (!IsFinished()) 579 if (!IsFinished())
580 return; 580 return;
581 581
582 pending_script_->StreamingFinished(); 582 pending_script_->StreamingFinished();
583 } 583 }
584 584
585 bool ScriptStreamerImpl::StartStreamingInternal( 585 bool ScriptStreamerImpl::StartStreamingInternal(
586 PendingScript* script, 586 ClassicPendingScript* script,
587 Type script_type, 587 Type script_type,
588 Settings* settings, 588 Settings* settings,
589 ScriptState* script_state, 589 ScriptState* script_state,
590 RefPtr<WebTaskRunner> loading_task_runner) { 590 RefPtr<WebTaskRunner> loading_task_runner) {
591 DCHECK(IsMainThread()); 591 DCHECK(IsMainThread());
592 DCHECK(script_state->ContextIsValid()); 592 DCHECK(script_state->ContextIsValid());
593 ScriptResource* resource = script->GetResource(); 593 ScriptResource* resource = script->GetResource();
594 if (resource->IsLoaded()) { 594 if (resource->IsLoaded()) {
595 RecordNotStreamingReasonHistogram(script_type, kAlreadyLoaded); 595 RecordNotStreamingReasonHistogram(script_type, kAlreadyLoaded);
596 return false; 596 return false;
597 } 597 }
598 if (!resource->Url().ProtocolIsInHTTPFamily()) { 598 if (!resource->Url().ProtocolIsInHTTPFamily()) {
599 RecordNotStreamingReasonHistogram(script_type, kNotHTTP); 599 RecordNotStreamingReasonHistogram(script_type, kNotHTTP);
600 return false; 600 return false;
601 } 601 }
602 if (resource->IsCacheValidator()) { 602 if (resource->IsCacheValidator()) {
603 RecordNotStreamingReasonHistogram(script_type, kReload); 603 RecordNotStreamingReasonHistogram(script_type, kReload);
604 // This happens e.g., during reloads. We're actually not going to load 604 // This happens e.g., during reloads. We're actually not going to load
605 // the current Resource of the PendingScript but switch to another 605 // the current Resource of the ClassicPendingScript but switch to another
606 // Resource -> don't stream. 606 // Resource -> don't stream.
607 return false; 607 return false;
608 } 608 }
609 // We cannot filter out short scripts, even if we wait for the HTTP headers 609 // We cannot filter out short scripts, even if we wait for the HTTP headers
610 // to arrive: the Content-Length HTTP header is not sent for chunked 610 // to arrive: the Content-Length HTTP header is not sent for chunked
611 // downloads. 611 // downloads.
612 612
613 // Decide what kind of cached data we should produce while streaming. Only 613 // Decide what kind of cached data we should produce while streaming. Only
614 // produce parser cache if the non-streaming compile takes advantage of it. 614 // produce parser cache if the non-streaming compile takes advantage of it.
615 v8::ScriptCompiler::CompileOptions compile_option = 615 v8::ScriptCompiler::CompileOptions compile_option =
616 v8::ScriptCompiler::kNoCompileOptions; 616 v8::ScriptCompiler::kNoCompileOptions;
617 if (settings->GetV8CacheOptions() == kV8CacheOptionsParse) 617 if (settings->GetV8CacheOptions() == kV8CacheOptionsParse)
618 compile_option = v8::ScriptCompiler::kProduceParserCache; 618 compile_option = v8::ScriptCompiler::kProduceParserCache;
619 619
620 // The Resource might go out of scope if the script is no longer needed. 620 // The Resource might go out of scope if the script is no longer needed.
621 // This makes PendingScript notify the ScriptStreamerImpl when it is 621 // This makes ClassicPendingScript notify the ScriptStreamerImpl when it is
622 // destroyed. 622 // destroyed.
623 script->SetStreamer(ScriptStreamerImpl::Create( 623 script->SetStreamer(ScriptStreamerImpl::Create(
624 script, script_type, script_state, compile_option, 624 script, script_type, script_state, compile_option,
625 std::move(loading_task_runner))); 625 std::move(loading_task_runner)));
626 626
627 return true; 627 return true;
628 } 628 }
629 629
630 } // namespace blink 630 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698