Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 case Resource::LinkPrefetch: | 128 case Resource::LinkPrefetch: |
| 129 return ResourceLoadPriorityVeryLow; | 129 return ResourceLoadPriorityVeryLow; |
| 130 } | 130 } |
| 131 | 131 |
| 132 ASSERT_NOT_REACHED(); | 132 ASSERT_NOT_REACHED(); |
| 133 return ResourceLoadPriorityUnresolved; | 133 return ResourceLoadPriorityUnresolved; |
| 134 } | 134 } |
| 135 | 135 |
| 136 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request, ResourcePriority::VisibilityStatus visibility) | 136 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request, ResourcePriority::VisibilityStatus visibility) |
| 137 { | 137 { |
| 138 // TODO(yoav): Change it here so that priority can be changed even after it was resolved. | |
| 139 if (request.priority() != ResourceLoadPriorityUnresolved) | |
| 140 return request.priority(); | |
| 141 | |
| 142 // Synchronous requests should always be max priority, lest they hang the re nderer. | |
| 143 if (request.options().synchronousPolicy == RequestSynchronously) | |
| 144 return ResourceLoadPriorityHighest; | |
| 145 | |
| 146 ResourceLoadPriority priority = typeToPriority(type); | 138 ResourceLoadPriority priority = typeToPriority(type); |
| 147 | 139 |
| 148 // Visible resources (images in practice) get a boost to High priority. | 140 // Visible resources (images in practice) get a boost to High priority. |
| 149 if (visibility == ResourcePriority::Visible) | 141 if (visibility == ResourcePriority::Visible) |
| 150 priority = ResourceLoadPriorityHigh; | 142 priority = ResourceLoadPriorityHigh; |
| 151 | 143 |
| 152 // Resources before the first image are considered "early" in the document | 144 // Resources before the first image are considered "early" in the document |
| 153 // and resources after the first image are "late" in the document. Importan t to | 145 // and resources after the first image are "late" in the document. Importan t to |
| 154 // note that this is based on when the preload scanner discovers a resource | 146 // note that this is based on when the preload scanner discovers a resource |
| 155 // for the most part so the main parser may not have reached the image eleme nt yet. | 147 // for the most part so the main parser may not have reached the image eleme nt yet. |
| 156 if (type == Resource::Image) | 148 if (type == Resource::Image) |
| 157 m_imageFetched = true; | 149 m_imageFetched = true; |
| 158 | 150 |
| 159 // Special handling for scripts. | 151 // Special handling for scripts. |
| 160 // Default/Parser-Blocking/Preload early in document: High (set in typeToPri ority) | 152 // Default/Parser-Blocking/Preload early in document: High (set in typeToPri ority) |
| 161 // Async/Defer: Low Priority (applies to both preload and parser-inserted) | 153 // Async/Defer: Low Priority (applies to both preload and parser-inserted) |
| 162 // Preload late in document: Medium | 154 // Preload late in document: Medium |
| 163 if (type == Resource::Script) { | 155 if (type == Resource::Script) { |
| 164 if (FetchRequest::LazyLoad == request.defer()) | 156 if (FetchRequest::LazyLoad == request.defer()) |
| 165 priority = ResourceLoadPriorityLow; | 157 priority = ResourceLoadPriorityLow; |
| 166 else if (request.forPreload() && m_imageFetched) | 158 else if (request.forPreload() && m_imageFetched) |
| 167 priority = ResourceLoadPriorityMedium; | 159 priority = ResourceLoadPriorityMedium; |
| 160 } else if (FetchRequest::LazyLoad == request.defer()) { | |
| 161 priority = ResourceLoadPriorityVeryLow; | |
| 168 } | 162 } |
| 169 | 163 |
| 170 return context().modifyPriorityForExperiments(priority); | 164 return std::max(context().modifyPriorityForExperiments(priority), request.re sourceRequest().priority()); |
|
kinuko
2016/06/17 05:40:47
Is the max here to cover synchronous load case?
Nate Chapin
2016/06/17 18:38:16
That's half of it. Also, it covers the case where
kinuko
2016/06/20 04:28:31
Ah I see, thanks. Would it make sense to add a bri
Nate Chapin
2016/06/20 19:44:31
Done.
| |
| 171 } | 165 } |
| 172 | 166 |
| 173 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource) | 167 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource) |
| 174 { | 168 { |
| 175 info->setInitialRequest(resource->resourceRequest()); | 169 info->setInitialRequest(resource->resourceRequest()); |
| 176 info->setFinalResponse(resource->response()); | 170 info->setFinalResponse(resource->response()); |
| 177 } | 171 } |
| 178 | 172 |
| 179 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re source::Type type) | 173 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re source::Type type) |
| 180 { | 174 { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 | 409 |
| 416 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace Event(request.url())); | 410 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace Event(request.url())); |
| 417 | 411 |
| 418 if (!request.url().isValid()) | 412 if (!request.url().isValid()) |
| 419 return nullptr; | 413 return nullptr; |
| 420 | 414 |
| 421 if (!context().canRequest(factory.type(), request.resourceRequest(), MemoryC ache::removeFragmentIdentifierIfNeeded(request.url()), request.options(), reques t.forPreload(), request.getOriginRestriction())) | 415 if (!context().canRequest(factory.type(), request.resourceRequest(), MemoryC ache::removeFragmentIdentifierIfNeeded(request.url()), request.options(), reques t.forPreload(), request.getOriginRestriction())) |
| 422 return nullptr; | 416 return nullptr; |
| 423 | 417 |
| 424 unsigned long identifier = createUniqueIdentifier(); | 418 unsigned long identifier = createUniqueIdentifier(); |
| 425 request.setPriority(loadPriority(factory.type(), request, ResourcePriority:: NotVisible)); | 419 request.mutableResourceRequest().setPriority(loadPriority(factory.type(), re quest, ResourcePriority::NotVisible)); |
| 426 request.mutableResourceRequest().setPriority(request.priority()); | |
| 427 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), request.defer()); | 420 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), request.defer()); |
| 428 context().willStartLoadingResource(identifier, request.mutableResourceReques t(), factory.type()); | 421 context().willStartLoadingResource(identifier, request.mutableResourceReques t(), factory.type()); |
| 429 if (!request.url().isValid()) | 422 if (!request.url().isValid()) |
| 430 return nullptr; | 423 return nullptr; |
| 431 | 424 |
| 432 if (!request.forPreload()) { | 425 if (!request.forPreload()) { |
| 433 V8DOMActivityLogger* activityLogger = nullptr; | 426 V8DOMActivityLogger* activityLogger = nullptr; |
| 434 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml httprequest) | 427 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml httprequest) |
| 435 activityLogger = V8DOMActivityLogger::currentActivityLogger(); | 428 activityLogger = V8DOMActivityLogger::currentActivityLogger(); |
| 436 else | 429 else |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 | 485 |
| 493 if (policy != Use) | 486 if (policy != Use) |
| 494 resource->setIdentifier(identifier); | 487 resource->setIdentifier(identifier); |
| 495 | 488 |
| 496 if (!request.forPreload() || policy != Use) { | 489 if (!request.forPreload() || policy != Use) { |
| 497 // When issuing another request for a resource that is already in-flight make | 490 // When issuing another request for a resource that is already in-flight make |
| 498 // sure to not demote the priority of the in-flight request. If the new request | 491 // sure to not demote the priority of the in-flight request. If the new request |
| 499 // isn't at the same priority as the in-flight request, only allow promo tions. | 492 // isn't at the same priority as the in-flight request, only allow promo tions. |
| 500 // This can happen when a visible image's priority is increased and then another | 493 // This can happen when a visible image's priority is increased and then another |
| 501 // reference to the image is parsed (which would be at a lower priority) . | 494 // reference to the image is parsed (which would be at a lower priority) . |
| 502 if (request.priority() > resource->resourceRequest().priority()) | 495 if (request.resourceRequest().priority() > resource->resourceRequest().p riority()) |
| 503 resource->didChangePriority(request.priority(), 0); | 496 resource->didChangePriority(request.resourceRequest().priority(), 0) ; |
| 504 } | 497 } |
| 505 | 498 |
| 506 // If only the fragment identifiers differ, it is the same resource. | 499 // If only the fragment identifiers differ, it is the same resource. |
| 507 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); | 500 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); |
| 508 requestLoadStarted(identifier, resource, request, policy == Use ? ResourceLo adingFromCache : ResourceLoadingFromNetwork, isStaticData); | 501 requestLoadStarted(identifier, resource, request, policy == Use ? ResourceLo adingFromCache : ResourceLoadingFromNetwork, isStaticData); |
| 509 m_documentResources.set(MemoryCache::removeFragmentIdentifierIfNeeded(reques t.url()), resource); | 502 m_documentResources.set(MemoryCache::removeFragmentIdentifierIfNeeded(reques t.url()), resource); |
| 510 | 503 |
| 511 // Returns with an existing resource if the resource does not need to start | 504 // Returns with an existing resource if the resource does not need to start |
| 512 // loading immediately. | 505 // loading immediately. |
| 513 // If revalidation policy was determined as |Revalidate|, the resource was | 506 // If revalidation policy was determined as |Revalidate|, the resource was |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1260 visitor->trace(m_context); | 1253 visitor->trace(m_context); |
| 1261 visitor->trace(m_archive); | 1254 visitor->trace(m_archive); |
| 1262 visitor->trace(m_loaders); | 1255 visitor->trace(m_loaders); |
| 1263 visitor->trace(m_nonBlockingLoaders); | 1256 visitor->trace(m_nonBlockingLoaders); |
| 1264 visitor->trace(m_documentResources); | 1257 visitor->trace(m_documentResources); |
| 1265 visitor->trace(m_preloads); | 1258 visitor->trace(m_preloads); |
| 1266 visitor->trace(m_resourceTimingInfoMap); | 1259 visitor->trace(m_resourceTimingInfoMap); |
| 1267 } | 1260 } |
| 1268 | 1261 |
| 1269 } // namespace blink | 1262 } // namespace blink |
| OLD | NEW |