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

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

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

Powered by Google App Engine
This is Rietveld 408576698