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

Side by Side Diff: Source/core/fetch/ResourceFetcher.cpp

Issue 1319153004: Cleanup ResourceLoadPriority setting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More test cleanup Created 5 years, 3 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 | Annotate | Revision Log
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 rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "public/platform/WebURLRequest.h" 50 #include "public/platform/WebURLRequest.h"
51 #include "wtf/text/CString.h" 51 #include "wtf/text/CString.h"
52 #include "wtf/text/WTFString.h" 52 #include "wtf/text/WTFString.h"
53 53
54 #define PRELOAD_DEBUG 0 54 #define PRELOAD_DEBUG 0
55 55
56 using blink::WebURLRequest; 56 using blink::WebURLRequest;
57 57
58 namespace blink { 58 namespace blink {
59 59
60 static ResourceLoadPriority typeToPriority(Resource::Type type)
61 {
62 switch (type) {
63 case Resource::MainResource:
64 return ResourceLoadPriorityVeryHigh;
65 case Resource::XSLStyleSheet:
66 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
67 case Resource::CSSStyleSheet:
68 return ResourceLoadPriorityHigh;
69 case Resource::Raw:
70 case Resource::Script:
71 case Resource::Font:
72 case Resource::ImportResource:
73 return ResourceLoadPriorityMedium;
74 case Resource::LinkSubresource:
75 case Resource::TextTrack:
76 case Resource::Media:
77 case Resource::SVGDocument:
78 return ResourceLoadPriorityLow;
79 case Resource::Image:
80 case Resource::LinkPrefetch:
81 case Resource::LinkPreload:
82 return ResourceLoadPriorityVeryLow;
83 }
84
85 ASSERT_NOT_REACHED();
86 return ResourceLoadPriorityUnresolved;
87 }
88
60 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request) 89 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request)
61 { 90 {
62 // TODO(yoav): Change it here so that priority can be changed even after it was resolved. 91 // TODO(yoav): Change it here so that priority can be changed even after it was resolved.
63 if (request.priority() != ResourceLoadPriorityUnresolved) 92 if (request.priority() != ResourceLoadPriorityUnresolved)
64 return request.priority(); 93 return request.priority();
65 94
66 // An image fetch is used to distinguish between "early" and "late" scripts in a document 95 // Synchronous requests should always be max priority, lest they hang the re nderer.
67 if (type == Resource::Image) 96 if (request.options().synchronousPolicy == RequestSynchronously)
68 m_imageFetched = true; 97 return ResourceLoadPriorityHighest;
69 98
70 // Runtime experiment that change how we prioritize resources. 99 return context().modifyPriorityForExperiments(typeToPriority(type), type, re quest);
71 // The toggles do not depend on each other and can be flipped individually
72 // though the cumulative result will depend on the interaction between them.
73 // Background doc: https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0g pwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing
74 bool deferLateScripts = context().fetchDeferLateScripts();
75 bool increaseFontPriority = context().fetchIncreaseFontPriority();
76 bool increaseAsyncScriptPriority = context().fetchIncreaseAsyncScriptPriorit y();
77 // Increases the priorities for CSS, Scripts, Fonts and Images all by one le vel
78 // and parser-blocking scripts and visible images by 2.
79 // This is used in conjunction with logic on the Chrome side to raise the th reshold
80 // of "layout-blocking" resources and provide a boost to resources that are needed
81 // as soon as possible for something currently on the screen.
82 bool increasePriorities = context().fetchIncreasePriorities();
83
84 switch (type) {
85 case Resource::MainResource:
86 return context().isLowPriorityIframe() ? ResourceLoadPriorityVeryLow : R esourceLoadPriorityVeryHigh;
87 case Resource::CSSStyleSheet:
88 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceLoadP riorityHigh;
89 case Resource::Raw:
90 return request.options().synchronousPolicy == RequestSynchronously ? Res ourceLoadPriorityVeryHigh : ResourceLoadPriorityMedium;
91 case Resource::Script:
92 // Async/Defer scripts.
93 if (FetchRequest::LazyLoad == request.defer())
94 return increaseAsyncScriptPriority ? ResourceLoadPriorityMedium : Re sourceLoadPriorityLow;
95 // Reduce the priority of late-body scripts.
96 if (deferLateScripts && request.forPreload() && m_imageFetched)
97 return increasePriorities ? ResourceLoadPriorityMedium : ResourceLoa dPriorityLow;
98 // Parser-blocking scripts.
99 if (!request.forPreload())
100 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceL oadPriorityMedium;
101 // Non-async/defer scripts discovered by the preload scanner (only early scripts if deferLateScripts is active).
102 return increasePriorities ? ResourceLoadPriorityHigh : ResourceLoadPrior ityMedium;
103 case Resource::Font:
104 if (increaseFontPriority)
105 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceL oadPriorityHigh;
106 return increasePriorities ? ResourceLoadPriorityHigh : ResourceLoadPrior ityMedium;
107 case Resource::ImportResource:
108 return ResourceLoadPriorityMedium;
109 case Resource::Image:
110 // Default images to VeryLow, and promote when they become visible.
111 return increasePriorities ? ResourceLoadPriorityLow : ResourceLoadPriori tyVeryLow;
112 case Resource::Media:
113 return ResourceLoadPriorityLow;
114 case Resource::XSLStyleSheet:
115 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
116 return ResourceLoadPriorityHigh;
117 case Resource::SVGDocument:
118 return ResourceLoadPriorityLow;
119 case Resource::LinkPrefetch:
120 case Resource::LinkPreload:
121 return ResourceLoadPriorityVeryLow;
122 case Resource::LinkSubresource:
123 return ResourceLoadPriorityLow;
124 case Resource::TextTrack:
125 return ResourceLoadPriorityLow;
126 }
127
128 ASSERT_NOT_REACHED();
129 return ResourceLoadPriorityUnresolved;
130 } 100 }
131 101
132 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource, bool clearLoadTimings) 102 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource, bool clearLoadTimings)
133 { 103 {
134 info->setInitialRequest(resource->resourceRequest()); 104 info->setInitialRequest(resource->resourceRequest());
135 info->setFinalResponse(resource->response()); 105 info->setFinalResponse(resource->response());
136 if (clearLoadTimings) { 106 if (clearLoadTimings) {
137 info->clearLoadTimings(); 107 info->clearLoadTimings();
138 info->setLoadFinishTime(info->initialTime()); 108 info->setLoadFinishTime(info->initialTime());
139 } else { 109 } else {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return WebURLRequest::RequestContextSubresource; 152 return WebURLRequest::RequestContextSubresource;
183 } 153 }
184 154
185 ResourceFetcher::ResourceFetcher(FetchContext* context) 155 ResourceFetcher::ResourceFetcher(FetchContext* context)
186 : m_context(context) 156 : m_context(context)
187 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl ectDocumentResourcesTimerFired) 157 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl ectDocumentResourcesTimerFired)
188 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi merFired) 158 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi merFired)
189 , m_autoLoadImages(true) 159 , m_autoLoadImages(true)
190 , m_imagesEnabled(true) 160 , m_imagesEnabled(true)
191 , m_allowStaleResources(false) 161 , m_allowStaleResources(false)
192 , m_imageFetched(false)
193 { 162 {
194 #if ENABLE(OILPAN) 163 #if ENABLE(OILPAN)
195 ThreadState::current()->registerPreFinalizer(this); 164 ThreadState::current()->registerPreFinalizer(this);
196 #endif 165 #endif
197 } 166 }
198 167
199 ResourceFetcher::~ResourceFetcher() 168 ResourceFetcher::~ResourceFetcher()
200 { 169 {
201 #if !ENABLE(OILPAN) 170 #if !ENABLE(OILPAN)
202 clearPreloads(); 171 clearPreloads();
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 visitor->trace(m_archiveResourceCollection); 1101 visitor->trace(m_archiveResourceCollection);
1133 visitor->trace(m_loaders); 1102 visitor->trace(m_loaders);
1134 visitor->trace(m_nonBlockingLoaders); 1103 visitor->trace(m_nonBlockingLoaders);
1135 #if ENABLE(OILPAN) 1104 #if ENABLE(OILPAN)
1136 visitor->trace(m_preloads); 1105 visitor->trace(m_preloads);
1137 visitor->trace(m_resourceTimingInfoMap); 1106 visitor->trace(m_resourceTimingInfoMap);
1138 #endif 1107 #endif
1139 } 1108 }
1140 1109
1141 } 1110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698