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

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

Issue 1304063016: Refactor the API for setting dynamic resource load priorities (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
« no previous file with comments | « Source/core/fetch/ResourceFetcher.h ('k') | Source/core/fetch/ResourceLoadPriorityOptimizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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); 382 resource->mutableResourceRequest().setPriority(priority);
383 resource->didChangePriority(priority, 0); 383 resource->didChangePriority(priority, 0);
384 } 384 }
385 } 385 }
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 m_resourceTimingInfoMap.remove(it); 849 m_resourceTimingInfoMap.remove(it);
850 populateResourceTiming(info.get(), resource, false); 850 populateResourceTiming(info.get(), resource, false);
851 if (resource->options().requestInitiatorContext == DocumentContext) 851 if (resource->options().requestInitiatorContext == DocumentContext)
852 context().addResourceTiming(*info); 852 context().addResourceTiming(*info);
853 resource->reportResourceTimingToClients(*info); 853 resource->reportResourceTimingToClients(*info);
854 } 854 }
855 } 855 }
856 context().dispatchDidFinishLoading(resource->identifier(), finishTime, encod edDataLength); 856 context().dispatchDidFinishLoading(resource->identifier(), finishTime, encod edDataLength);
857 } 857 }
858 858
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) 859 void ResourceFetcher::didFailLoading(const Resource* resource, const ResourceErr or& error)
866 { 860 {
867 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); 861 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource);
868 willTerminateResourceLoader(resource->loader()); 862 willTerminateResourceLoader(resource->loader());
869 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit iatorTypeNames::internal; 863 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit iatorTypeNames::internal;
870 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); 864 context().dispatchDidFail(resource->identifier(), error, isInternalRequest);
871 } 865 }
872 866
873 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& in itiatorInfo) 867 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& in itiatorInfo)
874 { 868 {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 resource->setCORSFailed(); 986 resource->setCORSFailed();
993 context().addConsoleMessage(errorMessage); 987 context().addConsoleMessage(errorMessage);
994 return false; 988 return false;
995 } 989 }
996 } 990 }
997 if (resource->type() == Resource::Image && shouldDeferImageLoad(newRequest.u rl())) 991 if (resource->type() == Resource::Image && shouldDeferImageLoad(newRequest.u rl()))
998 return false; 992 return false;
999 return true; 993 return true;
1000 } 994 }
1001 995
996 void ResourceFetcher::updateAllImageResourcePriorities()
997 {
998 if (!m_loaders)
999 return;
1000
1001 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource Priorities");
1002 for (const auto& loader : m_loaders->hashSet()) {
1003 Resource* resource = loader->cachedResource();
1004 if (!resource->isImage())
1005 continue;
1006
1007 ResourcePriority resourcePriority = resource->priorityFromClients();
1008 ResourceLoadPriority resourceLoadPriority = loadPriority(Resource::Image , FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resourcePrior ity.visibility);
1009 if (resourceLoadPriority == resource->resourceRequest().priority())
1010 continue;
1011
1012 resource->mutableResourceRequest().setPriority(resourceLoadPriority, res ourcePriority.intraPriorityValue);
1013 resource->didChangePriority(resourceLoadPriority, resourcePriority.intra PriorityValue);
1014 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource, "ChangeP riority", "priority", resourceLoadPriority);
1015 context().dispatchDidChangeResourcePriority(resource->identifier(), reso urceLoadPriority, resourcePriority.intraPriorityValue);
1016 }
1017 }
1018
1002 #if PRELOAD_DEBUG 1019 #if PRELOAD_DEBUG
1003 void ResourceFetcher::printPreloadStats() 1020 void ResourceFetcher::printPreloadStats()
1004 { 1021 {
1005 if (!m_preloads) 1022 if (!m_preloads)
1006 return; 1023 return;
1007 1024
1008 unsigned scripts = 0; 1025 unsigned scripts = 0;
1009 unsigned scriptMisses = 0; 1026 unsigned scriptMisses = 0;
1010 unsigned stylesheets = 0; 1027 unsigned stylesheets = 0;
1011 unsigned stylesheetMisses = 0; 1028 unsigned stylesheetMisses = 0;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 visitor->trace(m_archiveResourceCollection); 1118 visitor->trace(m_archiveResourceCollection);
1102 visitor->trace(m_loaders); 1119 visitor->trace(m_loaders);
1103 visitor->trace(m_nonBlockingLoaders); 1120 visitor->trace(m_nonBlockingLoaders);
1104 #if ENABLE(OILPAN) 1121 #if ENABLE(OILPAN)
1105 visitor->trace(m_preloads); 1122 visitor->trace(m_preloads);
1106 visitor->trace(m_resourceTimingInfoMap); 1123 visitor->trace(m_resourceTimingInfoMap);
1107 #endif 1124 #endif
1108 } 1125 }
1109 1126
1110 } 1127 }
OLDNEW
« no previous file with comments | « Source/core/fetch/ResourceFetcher.h ('k') | Source/core/fetch/ResourceLoadPriorityOptimizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698