Commit e7501585 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Lower priority for JavaScript requests when defer intervention is enabled

Change-Id: I3ecf89469653e98afed23f4d6cf8185bde032be8
Bug: 978490
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1687483
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676141}
parent 334958fd
...@@ -1015,6 +1015,7 @@ if (!is_android) { ...@@ -1015,6 +1015,7 @@ if (!is_android) {
"../browser/prerender/prerender_test_utils.cc", "../browser/prerender/prerender_test_utils.cc",
"../browser/prerender/prerender_test_utils.h", "../browser/prerender/prerender_test_utils.h",
"../browser/previews/defer_all_script_browsertest.cc", "../browser/previews/defer_all_script_browsertest.cc",
"../browser/previews/defer_all_script_priority_browsertest.cc",
"../browser/previews/hints_fetcher_browsertest.cc", "../browser/previews/hints_fetcher_browsertest.cc",
"../browser/previews/lazyload_browsertest.cc", "../browser/previews/lazyload_browsertest.cc",
"../browser/previews/previews_browsertest.cc", "../browser/previews/previews_browsertest.cc",
......
...@@ -282,6 +282,10 @@ class CORE_EXPORT DocumentLoader ...@@ -282,6 +282,10 @@ class CORE_EXPORT DocumentLoader
void SetLoadingJavaScriptUrl() { loading_url_as_javascript_ = true; } void SetLoadingJavaScriptUrl() { loading_url_as_javascript_ = true; }
WebURLRequest::PreviewsState previews_state() const {
return previews_state_;
}
protected: protected:
bool had_transient_activation() const { return had_transient_activation_; } bool had_transient_activation() const { return had_transient_activation_; }
......
...@@ -323,6 +323,10 @@ FrameFetchContext::GetPreviewsResourceLoadingHints() const { ...@@ -323,6 +323,10 @@ FrameFetchContext::GetPreviewsResourceLoadingHints() const {
return document_loader->GetPreviewsResourceLoadingHints(); return document_loader->GetPreviewsResourceLoadingHints();
} }
WebURLRequest::PreviewsState FrameFetchContext::previews_state() const {
return GetLocalFrameClient()->GetPreviewsStateForFrame();
}
LocalFrame* FrameFetchContext::GetFrame() const { LocalFrame* FrameFetchContext::GetFrame() const {
return &frame_or_imported_document_->GetFrame(); return &frame_or_imported_document_->GetFrame();
} }
......
...@@ -130,6 +130,7 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext { ...@@ -130,6 +130,7 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
SubresourceFilter* GetSubresourceFilter() const override; SubresourceFilter* GetSubresourceFilter() const override;
PreviewsResourceLoadingHints* GetPreviewsResourceLoadingHints() PreviewsResourceLoadingHints* GetPreviewsResourceLoadingHints()
const override; const override;
WebURLRequest::PreviewsState previews_state() const override;
bool AllowScriptFromSource(const KURL&) const override; bool AllowScriptFromSource(const KURL&) const override;
bool ShouldBlockRequestByInspector(const KURL&) const override; bool ShouldBlockRequestByInspector(const KURL&) const override;
void DispatchDidBlockRequest(const ResourceRequest&, void DispatchDidBlockRequest(const ResourceRequest&,
......
...@@ -142,6 +142,10 @@ class PLATFORM_EXPORT FetchContext ...@@ -142,6 +142,10 @@ class PLATFORM_EXPORT FetchContext
return false; return false;
} }
virtual WebURLRequest::PreviewsState previews_state() const {
return WebURLRequest::kPreviewsUnspecified;
}
private: private:
DISALLOW_COPY_AND_ASSIGN(FetchContext); DISALLOW_COPY_AND_ASSIGN(FetchContext);
}; };
......
...@@ -243,6 +243,33 @@ ResourceLoadPriority AdjustPriorityWithPriorityHint( ...@@ -243,6 +243,33 @@ ResourceLoadPriority AdjustPriorityWithPriorityHint(
return new_priority; return new_priority;
} }
ResourceLoadPriority AdjustPriorityWithDeferScriptIntervention(
const FetchContext& fetch_context,
ResourceLoadPriority priority_so_far,
ResourceType type,
const ResourceRequest& resource_request,
FetchParameters::DeferOption defer_option,
bool is_link_preload) {
WebURLRequest::PreviewsState context_previews_state =
fetch_context.previews_state();
if (type != ResourceType::kScript)
return priority_so_far;
// If none of the JavaScript resources are render blocking (due to the
// DeferAllScript intervention), then lower their priority so they do not
// contend for network resources with higher priority resources that may be
// render blocking (e.g., html, css). ResourceLoadPriority::kMedium
// corresponds to a network priority of
// network::mojom::blink::RequestPriority::kLow which is considered delayable
// by the resource scheduler on the browser side.
if (RuntimeEnabledFeatures::ForceDeferScriptInterventionEnabled() ||
(context_previews_state & WebURLRequest::kDeferAllScriptOn)) {
return std::min(priority_so_far, ResourceLoadPriority::kMedium);
}
return priority_so_far;
}
std::unique_ptr<TracedValue> BeginResourceLoadData( std::unique_ptr<TracedValue> BeginResourceLoadData(
const blink::ResourceRequest& request) { const blink::ResourceRequest& request) {
auto value = std::make_unique<TracedValue>(); auto value = std::make_unique<TracedValue>();
...@@ -508,6 +535,10 @@ ResourceLoadPriority ResourceFetcher::ComputeLoadPriority( ...@@ -508,6 +535,10 @@ ResourceLoadPriority ResourceFetcher::ComputeLoadPriority(
priority = AdjustPriorityWithPriorityHint(priority, type, resource_request, priority = AdjustPriorityWithPriorityHint(priority, type, resource_request,
defer_option, is_link_preload); defer_option, is_link_preload);
priority = AdjustPriorityWithDeferScriptIntervention(
Context(), priority, type, resource_request, defer_option,
is_link_preload);
if (properties_->IsSubframeDeprioritizationEnabled()) { if (properties_->IsSubframeDeprioritizationEnabled()) {
if (properties_->IsMainFrame()) { if (properties_->IsMainFrame()) {
DEFINE_STATIC_LOCAL( DEFINE_STATIC_LOCAL(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment