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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.cpp

Issue 2753053004: Improve preload related priorities (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
6 rights reserved. 6 rights reserved.
7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return ResourceLoadPriorityUnresolved; 150 return ResourceLoadPriorityUnresolved;
151 } 151 }
152 152
153 } // namespace 153 } // namespace
154 154
155 ResourceLoadPriority ResourceFetcher::computeLoadPriority( 155 ResourceLoadPriority ResourceFetcher::computeLoadPriority(
156 Resource::Type type, 156 Resource::Type type,
157 const ResourceRequest& resourceRequest, 157 const ResourceRequest& resourceRequest,
158 ResourcePriority::VisibilityStatus visibility, 158 ResourcePriority::VisibilityStatus visibility,
159 FetchRequest::DeferOption deferOption, 159 FetchRequest::DeferOption deferOption,
160 bool speculativePreload) { 160 bool isSpeculativePreload,
161 bool isLinkPreload) {
161 ResourceLoadPriority priority = typeToPriority(type); 162 ResourceLoadPriority priority = typeToPriority(type);
162 163
163 // Visible resources (images in practice) get a boost to High priority. 164 // Visible resources (images in practice) get a boost to High priority.
164 if (visibility == ResourcePriority::Visible) 165 if (visibility == ResourcePriority::Visible)
165 priority = ResourceLoadPriorityHigh; 166 priority = ResourceLoadPriorityHigh;
166 167
167 // Resources before the first image are considered "early" in the document and 168 // Resources before the first image are considered "early" in the document and
168 // resources after the first image are "late" in the document. Important to 169 // resources after the first image are "late" in the document. Important to
169 // note that this is based on when the preload scanner discovers a resource 170 // note that this is based on when the preload scanner discovers a resource
170 // for the most part so the main parser may not have reached the image element 171 // for the most part so the main parser may not have reached the image element
171 // yet. 172 // yet.
172 if (type == Resource::Image) 173 if (type == Resource::Image && !isLinkPreload)
173 m_imageFetched = true; 174 m_imageFetched = true;
174 175
176 // A preloaded font should not take precedence over critical CSS or
177 // parser-blocking scripts.
178 if (type == Resource::Font && isLinkPreload)
179 priority = ResourceLoadPriorityHigh;
180
175 if (FetchRequest::IdleLoad == deferOption) { 181 if (FetchRequest::IdleLoad == deferOption) {
176 priority = ResourceLoadPriorityVeryLow; 182 priority = ResourceLoadPriorityVeryLow;
177 } else if (type == Resource::Script) { 183 } else if (type == Resource::Script) {
178 // Special handling for scripts. 184 // Special handling for scripts.
179 // Default/Parser-Blocking/Preload early in document: High (set in 185 // Default/Parser-Blocking/Preload early in document: High (set in
180 // typeToPriority) 186 // typeToPriority)
181 // Async/Defer: Low Priority (applies to both preload and parser-inserted) 187 // Async/Defer: Low Priority (applies to both preload and parser-inserted)
182 // Preload late in document: Medium 188 // Preload late in document: Medium
183 if (FetchRequest::LazyLoad == deferOption) { 189 if (FetchRequest::LazyLoad == deferOption) {
184 priority = ResourceLoadPriorityLow; 190 priority = ResourceLoadPriorityLow;
185 } else if (speculativePreload && m_imageFetched) { 191 } else if (isSpeculativePreload && m_imageFetched) {
186 // Speculative preload is used as a signal for scripts at the bottom of 192 // Speculative preload is used as a signal for scripts at the bottom of
187 // the document. 193 // the document.
188 priority = ResourceLoadPriorityMedium; 194 priority = ResourceLoadPriorityMedium;
189 } 195 }
190 } else if (FetchRequest::LazyLoad == deferOption) { 196 } else if (FetchRequest::LazyLoad == deferOption) {
191 priority = ResourceLoadPriorityVeryLow; 197 priority = ResourceLoadPriorityVeryLow;
192 } 198 }
193 199
194 // A manually set priority acts as a floor. This is used to ensure that 200 // A manually set priority acts as a floor. This is used to ensure that
195 // synchronous requests are always given the highest possible priority, as 201 // synchronous requests are always given the highest possible priority, as
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 479
474 context().populateResourceRequest( 480 context().populateResourceRequest(
475 factory.type(), request.clientHintsPreferences(), 481 factory.type(), request.clientHintsPreferences(),
476 request.getResourceWidth(), resourceRequest); 482 request.getResourceWidth(), resourceRequest);
477 483
478 if (!request.url().isValid()) 484 if (!request.url().isValid())
479 return Abort; 485 return Abort;
480 486
481 resourceRequest.setPriority(computeLoadPriority( 487 resourceRequest.setPriority(computeLoadPriority(
482 factory.type(), request.resourceRequest(), ResourcePriority::NotVisible, 488 factory.type(), request.resourceRequest(), ResourcePriority::NotVisible,
483 request.defer(), request.isSpeculativePreload())); 489 request.defer(), request.isSpeculativePreload(),
490 request.isLinkPreload()));
484 initializeResourceRequest(resourceRequest, factory.type(), request.defer()); 491 initializeResourceRequest(resourceRequest, factory.type(), request.defer());
485 network_instrumentation::resourcePrioritySet(identifier, 492 network_instrumentation::resourcePrioritySet(identifier,
486 resourceRequest.priority()); 493 resourceRequest.priority());
487 494
488 blockedReason = context().canRequest( 495 blockedReason = context().canRequest(
489 factory.type(), resourceRequest, 496 factory.type(), resourceRequest,
490 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), 497 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()),
491 request.options(), 498 request.options(),
492 /* Don't send security violation reports for speculative preloads */ 499 /* Don't send security violation reports for speculative preloads */
493 request.isSpeculativePreload() 500 request.isSpeculativePreload()
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 visitor->trace(m_context); 1553 visitor->trace(m_context);
1547 visitor->trace(m_archive); 1554 visitor->trace(m_archive);
1548 visitor->trace(m_loaders); 1555 visitor->trace(m_loaders);
1549 visitor->trace(m_nonBlockingLoaders); 1556 visitor->trace(m_nonBlockingLoaders);
1550 visitor->trace(m_documentResources); 1557 visitor->trace(m_documentResources);
1551 visitor->trace(m_preloads); 1558 visitor->trace(m_preloads);
1552 visitor->trace(m_resourceTimingInfoMap); 1559 visitor->trace(m_resourceTimingInfoMap);
1553 } 1560 }
1554 1561
1555 } // namespace blink 1562 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698