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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 case Resource::Image: | 79 case Resource::Image: |
| 80 case Resource::LinkPrefetch: | 80 case Resource::LinkPrefetch: |
| 81 case Resource::LinkPreload: | 81 case Resource::LinkPreload: |
| 82 return ResourceLoadPriorityVeryLow; | 82 return ResourceLoadPriorityVeryLow; |
| 83 } | 83 } |
| 84 | 84 |
| 85 ASSERT_NOT_REACHED(); | 85 ASSERT_NOT_REACHED(); |
| 86 return ResourceLoadPriorityUnresolved; | 86 return ResourceLoadPriorityUnresolved; |
| 87 } | 87 } |
| 88 | 88 |
| 89 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request) | 89 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request, ResourcePriority::VisibilityStatus visibility) |
| 90 { | 90 { |
| 91 // 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. |
| 92 if (request.priority() != ResourceLoadPriorityUnresolved) | 92 if (request.priority() != ResourceLoadPriorityUnresolved) |
| 93 return request.priority(); | 93 return request.priority(); |
| 94 | 94 |
| 95 // Synchronous requests should always be max priority, lest they hang the re nderer. | 95 // Synchronous requests should always be max priority, lest they hang the re nderer. |
| 96 if (request.options().synchronousPolicy == RequestSynchronously) | 96 if (request.options().synchronousPolicy == RequestSynchronously) |
| 97 return ResourceLoadPriorityHighest; | 97 return ResourceLoadPriorityHighest; |
| 98 | 98 |
| 99 return context().modifyPriorityForExperiments(typeToPriority(type), type, re quest); | 99 return context().modifyPriorityForExperiments(typeToPriority(type), type, re quest, visibility); |
| 100 } | 100 } |
| 101 | 101 |
| 102 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource, bool clearLoadTimings) | 102 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource, bool clearLoadTimings) |
| 103 { | 103 { |
| 104 info->setInitialRequest(resource->resourceRequest()); | 104 info->setInitialRequest(resource->resourceRequest()); |
| 105 info->setFinalResponse(resource->response()); | 105 info->setFinalResponse(resource->response()); |
| 106 if (clearLoadTimings) { | 106 if (clearLoadTimings) { |
| 107 info->clearLoadTimings(); | 107 info->clearLoadTimings(); |
| 108 info->setLoadFinishTime(info->initialTime()); | 108 info->setLoadFinishTime(info->initialTime()); |
| 109 } else { | 109 } else { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 return nullptr; | 365 return nullptr; |
| 366 } | 366 } |
| 367 | 367 |
| 368 if (!resource->hasClients()) | 368 if (!resource->hasClients()) |
| 369 m_deadStatsRecorder.update(policy); | 369 m_deadStatsRecorder.update(policy); |
| 370 | 370 |
| 371 if (policy != Use) | 371 if (policy != Use) |
| 372 resource->setIdentifier(createUniqueIdentifier()); | 372 resource->setIdentifier(createUniqueIdentifier()); |
| 373 | 373 |
| 374 if (!request.forPreload() || policy != Use) { | 374 if (!request.forPreload() || policy != Use) { |
| 375 ResourceLoadPriority priority = loadPriority(factory.type(), request); | 375 ResourceLoadPriority priority = loadPriority(factory.type(), request, Re sourcePriority::NotVisible); |
| 376 // When issuing another request for a resource that is already in-flight make | 376 // When issuing another request for a resource that is already in-flight make |
| 377 // sure to not demote the priority of the in-flight request. If the new request | 377 // sure to not demote the priority of the in-flight request. If the new request |
| 378 // isn't at the same priority as the in-flight request, only allow promo tions. | 378 // isn't at the same priority as the in-flight request, only allow promo tions. |
| 379 // This can happen when a visible image's priority is increased and then another | 379 // This can happen when a visible image's priority is increased and then another |
| 380 // reference to the image is parsed (which would be at a lower priority) . | 380 // reference to the image is parsed (which would be at a lower priority) . |
| 381 if (priority > resource->resourceRequest().priority()) { | 381 if (priority > resource->resourceRequest().priority()) |
| 382 resource->mutableResourceRequest().setPriority(priority); | |
| 383 resource->didChangePriority(priority, 0); | 382 resource->didChangePriority(priority, 0); |
| 384 } | |
| 385 } | 383 } |
| 386 | 384 |
| 387 if (resourceNeedsLoad(resource.get(), request, policy)) { | 385 if (resourceNeedsLoad(resource.get(), request, policy)) { |
| 388 if (!context().shouldLoadNewResource(factory.type())) { | 386 if (!context().shouldLoadNewResource(factory.type())) { |
| 389 if (memoryCache()->contains(resource.get())) | 387 if (memoryCache()->contains(resource.get())) |
| 390 memoryCache()->remove(resource.get()); | 388 memoryCache()->remove(resource.get()); |
| 391 return nullptr; | 389 return nullptr; |
| 392 } | 390 } |
| 393 | 391 |
| 394 if (!scheduleArchiveLoad(resource.get(), request.resourceRequest())) | 392 if (!scheduleArchiveLoad(resource.get(), request.resourceRequest())) |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 m_resourceTimingInfoMap.remove(it); | 847 m_resourceTimingInfoMap.remove(it); |
| 850 populateResourceTiming(info.get(), resource, false); | 848 populateResourceTiming(info.get(), resource, false); |
| 851 if (resource->options().requestInitiatorContext == DocumentContext) | 849 if (resource->options().requestInitiatorContext == DocumentContext) |
| 852 context().addResourceTiming(*info); | 850 context().addResourceTiming(*info); |
| 853 resource->reportResourceTimingToClients(*info); | 851 resource->reportResourceTimingToClients(*info); |
| 854 } | 852 } |
| 855 } | 853 } |
| 856 context().dispatchDidFinishLoading(resource->identifier(), finishTime, encod edDataLength); | 854 context().dispatchDidFinishLoading(resource->identifier(), finishTime, encod edDataLength); |
| 857 } | 855 } |
| 858 | 856 |
| 859 void ResourceFetcher::didChangeLoadingPriority(const Resource* resource, Resourc eLoadPriority loadPriority, int intraPriorityValue) | |
| 860 { | |
| 861 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource, "ChangePrior ity", "priority", loadPriority); | |
| 862 context().dispatchDidChangeResourcePriority(resource->identifier(), loadPrio rity, intraPriorityValue); | |
| 863 } | |
| 864 | |
| 865 void ResourceFetcher::didFailLoading(const Resource* resource, const ResourceErr or& error) | 857 void ResourceFetcher::didFailLoading(const Resource* resource, const ResourceErr or& error) |
| 866 { | 858 { |
| 867 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); | 859 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); |
| 868 willTerminateResourceLoader(resource->loader()); | 860 willTerminateResourceLoader(resource->loader()); |
| 869 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit iatorTypeNames::internal; | 861 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit iatorTypeNames::internal; |
| 870 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); | 862 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); |
| 871 } | 863 } |
| 872 | 864 |
| 873 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& in itiatorInfo) | 865 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& in itiatorInfo) |
| 874 { | 866 { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 992 resource->setCORSFailed(); | 984 resource->setCORSFailed(); |
| 993 context().addConsoleMessage(errorMessage); | 985 context().addConsoleMessage(errorMessage); |
| 994 return false; | 986 return false; |
| 995 } | 987 } |
| 996 } | 988 } |
| 997 if (resource->type() == Resource::Image && shouldDeferImageLoad(newRequest.u rl())) | 989 if (resource->type() == Resource::Image && shouldDeferImageLoad(newRequest.u rl())) |
| 998 return false; | 990 return false; |
| 999 return true; | 991 return true; |
| 1000 } | 992 } |
| 1001 | 993 |
| 994 void ResourceFetcher::updateAllImageResourcePriorities() | |
| 995 { | |
| 996 if (!m_loaders) | |
| 997 return; | |
| 998 | |
| 999 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource Priorities"); | |
| 1000 for (const auto& loader : m_loaders->hashSet()) { | |
|
Nate Chapin
2015/10/07 19:40:40
This feels a little hacky, but it's the cleanest w
| |
| 1001 Resource* resource = loader->cachedResource(); | |
| 1002 if (!resource->isImage()) | |
| 1003 continue; | |
| 1004 | |
| 1005 ResourcePriority resourcePriority = resource->priorityFromClients(); | |
| 1006 ResourceLoadPriority resourceLoadPriority = loadPriority(Resource::Image , FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resourcePrior ity.visibility); | |
| 1007 if (resourceLoadPriority == resource->resourceRequest().priority()) | |
| 1008 continue; | |
| 1009 | |
| 1010 resource->didChangePriority(resourceLoadPriority, resourcePriority.intra PriorityValue); | |
| 1011 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource, "ChangeP riority", "priority", resourceLoadPriority); | |
| 1012 context().dispatchDidChangeResourcePriority(resource->identifier(), reso urceLoadPriority, resourcePriority.intraPriorityValue); | |
| 1013 } | |
| 1014 } | |
| 1015 | |
| 1002 #if PRELOAD_DEBUG | 1016 #if PRELOAD_DEBUG |
| 1003 void ResourceFetcher::printPreloadStats() | 1017 void ResourceFetcher::printPreloadStats() |
| 1004 { | 1018 { |
| 1005 if (!m_preloads) | 1019 if (!m_preloads) |
| 1006 return; | 1020 return; |
| 1007 | 1021 |
| 1008 unsigned scripts = 0; | 1022 unsigned scripts = 0; |
| 1009 unsigned scriptMisses = 0; | 1023 unsigned scriptMisses = 0; |
| 1010 unsigned stylesheets = 0; | 1024 unsigned stylesheets = 0; |
| 1011 unsigned stylesheetMisses = 0; | 1025 unsigned stylesheetMisses = 0; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1101 visitor->trace(m_archiveResourceCollection); | 1115 visitor->trace(m_archiveResourceCollection); |
| 1102 visitor->trace(m_loaders); | 1116 visitor->trace(m_loaders); |
| 1103 visitor->trace(m_nonBlockingLoaders); | 1117 visitor->trace(m_nonBlockingLoaders); |
| 1104 #if ENABLE(OILPAN) | 1118 #if ENABLE(OILPAN) |
| 1105 visitor->trace(m_preloads); | 1119 visitor->trace(m_preloads); |
| 1106 visitor->trace(m_resourceTimingInfoMap); | 1120 visitor->trace(m_resourceTimingInfoMap); |
| 1107 #endif | 1121 #endif |
| 1108 } | 1122 } |
| 1109 | 1123 |
| 1110 } | 1124 } |
| OLD | NEW |