diff options
author | tonyg@chromium.org <tonyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 17:48:14 +0000 |
---|---|---|
committer | tonyg@chromium.org <tonyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 17:48:14 +0000 |
commit | 0a8efffe56a55dd191da6b9d65829a23791af4e4 (patch) | |
tree | 1d378c5f4735d93c2c8a86faeef1a985a4a0155c /chrome/browser/renderer_host | |
parent | ecde2747b368a859e01614c7894fca25f670f1e5 (diff) | |
download | chromium_src-0a8efffe56a55dd191da6b9d65829a23791af4e4.zip chromium_src-0a8efffe56a55dd191da6b9d65829a23791af4e4.tar.gz chromium_src-0a8efffe56a55dd191da6b9d65829a23791af4e4.tar.bz2 |
Upgrade fonts to receive MEDIUM request priority like scripts and
stylesheets. A detailed discussion can be found here:
http://www.stevesouders.com/blog/2009/10/13/font-face-and-performance/
http://paulirish.com/2009/fighting-the-font-face-fout/
Also, factor out resource priorities and ensure that all types are
considered.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1572013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43498 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 68 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.h | 4 |
2 files changed, 53 insertions, 19 deletions
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 7576926..a1aa5e4 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -59,6 +59,7 @@ #include "net/base/load_flags.h" #include "net/base/mime_util.h" #include "net/base/net_errors.h" +#include "net/base/request_priority.h" #include "net/base/ssl_cert_request_info.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" @@ -394,25 +395,7 @@ void ResourceDispatcherHost::BeginRequest( load_flags |= net::LOAD_VERIFY_EV_CERT; request->set_load_flags(load_flags); request->set_context(context); - - // If the request is for the top level page or a frame/iframe, then we - // should prioritize it higher than other resource types. Currently, we - // just use priorities 1 and 0. - if (ResourceType::IsFrame(request_data.resource_type)) { - request->set_priority(net::HIGHEST); - } else { - switch (request_data.resource_type) { - case ResourceType::STYLESHEET: - case ResourceType::SCRIPT: - request->set_priority(net::MEDIUM); - break; - case ResourceType::IMAGE: - request->set_priority(net::LOWEST); - break; - default: - request->set_priority(net::LOW); - } - } + request->set_priority(DetermineRequestPriority(request_data.resource_type)); // Set upload data. uint64 upload_size = 0; @@ -1766,3 +1749,50 @@ void ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( request_info->set_filter_policy(FilterPolicy::FILTER_EXTENSION_MESSAGES); } } + +// static +net::RequestPriority ResourceDispatcherHost::DetermineRequestPriority( + ResourceType::Type type) { + // Determine request priority based on how critical this resource typically + // is to user-perceived page load performance. Important considerations are: + // * Can this resource block the download of other resources. + // * Can this resource block the rendering of the page. + // * How useful is the page to the user if this resource is not loaded yet. + switch (type) { + // Main frames are the highest priority because they can block nearly every + // type of other resource and there is no useful display without them. + // Sub frames are a close second, however it is a common pattern to wrap + // ads in an iframe or even in multiple nested iframes. It is worth + // investigating if there is a better priority for them. + case ResourceType::MAIN_FRAME: + case ResourceType::SUB_FRAME: + return net::HIGHEST; + + // Stylesheets and scripts can block rendering and loading of other + // resources. Fonts can block text from rendering. + case ResourceType::STYLESHEET: + case ResourceType::SCRIPT: + case ResourceType::FONT_RESOURCE: + return net::MEDIUM; + + // Sub resources, objects and media are lower priority than potentially + // blocking stylesheets, scripts and fonts, but are higher priority than + // images because if they exist they are probably more central to the page + // focus than images on the page. + case ResourceType::SUB_RESOURCE: + case ResourceType::OBJECT: + case ResourceType::MEDIA: + return net::LOW; + + // Images are the lowest priority because they typically do not block + // downloads or rendering and most pages have some useful content without + // them. + case ResourceType::IMAGE: + return net::LOWEST; + + default: + // When new resource types are added, their priority must be considered. + NOTREACHED(); + return net::LOW; + } +} diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index e6d5d24..b9b7930 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -417,6 +417,10 @@ class ResourceDispatcherHost : public URLRequest::Delegate { const ResourceType::Type& resource_type, ResourceDispatcherHostRequestInfo* request_info); + // Determine request priority based on how critical this resource typically + // is to user-perceived page load performance. + static net::RequestPriority DetermineRequestPriority(ResourceType::Type type); + PendingRequestList pending_requests_; // A timer that periodically calls UpdateLoadStates while pending_requests_ |