| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 return nullptr; | 373 return nullptr; |
| 374 } | 374 } |
| 375 | 375 |
| 376 if (!resource->hasClients()) | 376 if (!resource->hasClients()) |
| 377 m_deadStatsRecorder.update(policy); | 377 m_deadStatsRecorder.update(policy); |
| 378 | 378 |
| 379 if (policy != Use) | 379 if (policy != Use) |
| 380 resource->setIdentifier(createUniqueIdentifier()); | 380 resource->setIdentifier(createUniqueIdentifier()); |
| 381 | 381 |
| 382 if (!request.forPreload() || policy != Use) { | 382 if (!request.forPreload() || policy != Use) { |
| 383 ResourceLoadPriority priority = loadPriority(factory.type(), request); | 383 ResourceLoadPriority priority = loadPriority(factory.type(), request, Re
sourcePriority::NotVisible); |
| 384 // When issuing another request for a resource that is already in-flight
make | 384 // When issuing another request for a resource that is already in-flight
make |
| 385 // sure to not demote the priority of the in-flight request. If the new
request | 385 // sure to not demote the priority of the in-flight request. If the new
request |
| 386 // isn't at the same priority as the in-flight request, only allow promo
tions. | 386 // isn't at the same priority as the in-flight request, only allow promo
tions. |
| 387 // This can happen when a visible image's priority is increased and then
another | 387 // This can happen when a visible image's priority is increased and then
another |
| 388 // reference to the image is parsed (which would be at a lower priority)
. | 388 // reference to the image is parsed (which would be at a lower priority)
. |
| 389 if (priority > resource->resourceRequest().priority()) { | 389 if (priority > resource->resourceRequest().priority()) |
| 390 resource->mutableResourceRequest().setPriority(priority); | |
| 391 resource->didChangePriority(priority, 0); | 390 resource->didChangePriority(priority, 0); |
| 392 } | |
| 393 } | 391 } |
| 394 | 392 |
| 395 if (resourceNeedsLoad(resource.get(), request, policy)) { | 393 if (resourceNeedsLoad(resource.get(), request, policy)) { |
| 396 if (!context().shouldLoadNewResource(factory.type())) { | 394 if (!context().shouldLoadNewResource(factory.type())) { |
| 397 if (memoryCache()->contains(resource.get())) | 395 if (memoryCache()->contains(resource.get())) |
| 398 memoryCache()->remove(resource.get()); | 396 memoryCache()->remove(resource.get()); |
| 399 return nullptr; | 397 return nullptr; |
| 400 } | 398 } |
| 401 | 399 |
| 402 if (!scheduleArchiveLoad(resource.get(), request.resourceRequest())) | 400 if (!scheduleArchiveLoad(resource.get(), request.resourceRequest())) |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 m_resourceTimingInfoMap.remove(it); | 859 m_resourceTimingInfoMap.remove(it); |
| 862 populateResourceTiming(info.get(), resource, false); | 860 populateResourceTiming(info.get(), resource, false); |
| 863 if (resource->options().requestInitiatorContext == DocumentContext) | 861 if (resource->options().requestInitiatorContext == DocumentContext) |
| 864 context().addResourceTiming(*info); | 862 context().addResourceTiming(*info); |
| 865 resource->reportResourceTimingToClients(*info); | 863 resource->reportResourceTimingToClients(*info); |
| 866 } | 864 } |
| 867 } | 865 } |
| 868 context().dispatchDidFinishLoading(resource->identifier(), finishTime, encod
edDataLength); | 866 context().dispatchDidFinishLoading(resource->identifier(), finishTime, encod
edDataLength); |
| 869 } | 867 } |
| 870 | 868 |
| 871 void ResourceFetcher::didChangeLoadingPriority(const Resource* resource, Resourc
eLoadPriority loadPriority, int intraPriorityValue) | |
| 872 { | |
| 873 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource, "ChangePrior
ity", "priority", loadPriority); | |
| 874 context().dispatchDidChangeResourcePriority(resource->identifier(), loadPrio
rity, intraPriorityValue); | |
| 875 } | |
| 876 | |
| 877 void ResourceFetcher::didFailLoading(const Resource* resource, const ResourceErr
or& error) | 869 void ResourceFetcher::didFailLoading(const Resource* resource, const ResourceErr
or& error) |
| 878 { | 870 { |
| 879 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); | 871 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); |
| 880 willTerminateResourceLoader(resource->loader()); | 872 willTerminateResourceLoader(resource->loader()); |
| 881 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit
iatorTypeNames::internal; | 873 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit
iatorTypeNames::internal; |
| 882 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); | 874 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); |
| 883 } | 875 } |
| 884 | 876 |
| 885 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest&
request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& in
itiatorInfo) | 877 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest&
request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& in
itiatorInfo) |
| 886 { | 878 { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 resource->setCORSFailed(); | 996 resource->setCORSFailed(); |
| 1005 context().addConsoleMessage(errorMessage); | 997 context().addConsoleMessage(errorMessage); |
| 1006 return false; | 998 return false; |
| 1007 } | 999 } |
| 1008 } | 1000 } |
| 1009 if (resource->type() == Resource::Image && shouldDeferImageLoad(newRequest.u
rl())) | 1001 if (resource->type() == Resource::Image && shouldDeferImageLoad(newRequest.u
rl())) |
| 1010 return false; | 1002 return false; |
| 1011 return true; | 1003 return true; |
| 1012 } | 1004 } |
| 1013 | 1005 |
| 1006 void ResourceFetcher::updateAllImageResourcePriorities() |
| 1007 { |
| 1008 if (!m_loaders) |
| 1009 return; |
| 1010 |
| 1011 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource
Priorities"); |
| 1012 for (const auto& loader : m_loaders->hashSet()) { |
| 1013 Resource* resource = loader->cachedResource(); |
| 1014 if (!resource->isImage()) |
| 1015 continue; |
| 1016 |
| 1017 ResourcePriority resourcePriority = resource->priorityFromClients(); |
| 1018 ResourceLoadPriority resourceLoadPriority = loadPriority(Resource::Image
, FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resourcePrior
ity.visibility); |
| 1019 if (resourceLoadPriority == resource->resourceRequest().priority()) |
| 1020 continue; |
| 1021 |
| 1022 resource->didChangePriority(resourceLoadPriority, resourcePriority.intra
PriorityValue); |
| 1023 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource, "ChangeP
riority", "priority", resourceLoadPriority); |
| 1024 context().dispatchDidChangeResourcePriority(resource->identifier(), reso
urceLoadPriority, resourcePriority.intraPriorityValue); |
| 1025 } |
| 1026 } |
| 1027 |
| 1014 #if PRELOAD_DEBUG | 1028 #if PRELOAD_DEBUG |
| 1015 void ResourceFetcher::printPreloadStats() | 1029 void ResourceFetcher::printPreloadStats() |
| 1016 { | 1030 { |
| 1017 if (!m_preloads) | 1031 if (!m_preloads) |
| 1018 return; | 1032 return; |
| 1019 | 1033 |
| 1020 unsigned scripts = 0; | 1034 unsigned scripts = 0; |
| 1021 unsigned scriptMisses = 0; | 1035 unsigned scriptMisses = 0; |
| 1022 unsigned stylesheets = 0; | 1036 unsigned stylesheets = 0; |
| 1023 unsigned stylesheetMisses = 0; | 1037 unsigned stylesheetMisses = 0; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 visitor->trace(m_archiveResourceCollection); | 1127 visitor->trace(m_archiveResourceCollection); |
| 1114 visitor->trace(m_loaders); | 1128 visitor->trace(m_loaders); |
| 1115 visitor->trace(m_nonBlockingLoaders); | 1129 visitor->trace(m_nonBlockingLoaders); |
| 1116 #if ENABLE(OILPAN) | 1130 #if ENABLE(OILPAN) |
| 1117 visitor->trace(m_preloads); | 1131 visitor->trace(m_preloads); |
| 1118 visitor->trace(m_resourceTimingInfoMap); | 1132 visitor->trace(m_resourceTimingInfoMap); |
| 1119 #endif | 1133 #endif |
| 1120 } | 1134 } |
| 1121 | 1135 |
| 1122 } | 1136 } |
| OLD | NEW |