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 | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
| 6 rights reserved. | 6 rights reserved. |
| 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
| 8 | 8 |
| 9 This library is free software; you can redistribute it and/or | 9 This library is free software; you can redistribute it and/or |
| 10 modify it under the terms of the GNU Library General Public | 10 modify it under the terms of the GNU Library General Public |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 #include "core/fetch/FetchInitiatorTypeNames.h" | 33 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 34 #include "core/fetch/ImageResource.h" | 34 #include "core/fetch/ImageResource.h" |
| 35 #include "core/fetch/MemoryCache.h" | 35 #include "core/fetch/MemoryCache.h" |
| 36 #include "core/fetch/ResourceLoader.h" | 36 #include "core/fetch/ResourceLoader.h" |
| 37 #include "core/fetch/ResourceLoadingLog.h" | 37 #include "core/fetch/ResourceLoadingLog.h" |
| 38 #include "core/fetch/UniqueIdentifier.h" | 38 #include "core/fetch/UniqueIdentifier.h" |
| 39 #include "platform/Histogram.h" | 39 #include "platform/Histogram.h" |
| 40 #include "platform/RuntimeEnabledFeatures.h" | 40 #include "platform/RuntimeEnabledFeatures.h" |
| 41 #include "platform/mhtml/ArchiveResource.h" | 41 #include "platform/mhtml/ArchiveResource.h" |
| 42 #include "platform/mhtml/MHTMLArchive.h" | 42 #include "platform/mhtml/MHTMLArchive.h" |
| 43 #include "platform/network/NetworkInstrumentation.h" | |
| 43 #include "platform/network/NetworkUtils.h" | 44 #include "platform/network/NetworkUtils.h" |
| 44 #include "platform/network/ResourceTimingInfo.h" | 45 #include "platform/network/ResourceTimingInfo.h" |
| 45 #include "platform/tracing/TraceEvent.h" | 46 #include "platform/tracing/TraceEvent.h" |
| 46 #include "platform/tracing/TracedValue.h" | 47 #include "platform/tracing/TracedValue.h" |
| 47 #include "platform/weborigin/KnownPorts.h" | 48 #include "platform/weborigin/KnownPorts.h" |
| 48 #include "platform/weborigin/SecurityOrigin.h" | 49 #include "platform/weborigin/SecurityOrigin.h" |
| 49 #include "platform/weborigin/SecurityPolicy.h" | 50 #include "platform/weborigin/SecurityPolicy.h" |
| 50 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
| 51 #include "public/platform/WebCachePolicy.h" | 52 #include "public/platform/WebCachePolicy.h" |
| 52 #include "public/platform/WebURL.h" | 53 #include "public/platform/WebURL.h" |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 if (resource && !resource->isAlive() && | 478 if (resource && !resource->isAlive() && |
| 478 (!m_preloads || !m_preloads->contains(resource))) { | 479 (!m_preloads || !m_preloads->contains(resource))) { |
| 479 DEFINE_RESOURCE_HISTOGRAM("Dead."); | 480 DEFINE_RESOURCE_HISTOGRAM("Dead."); |
| 480 } | 481 } |
| 481 } | 482 } |
| 482 | 483 |
| 483 Resource* ResourceFetcher::requestResource( | 484 Resource* ResourceFetcher::requestResource( |
| 484 FetchRequest& request, | 485 FetchRequest& request, |
| 485 const ResourceFactory& factory, | 486 const ResourceFactory& factory, |
| 486 const SubstituteData& substituteData) { | 487 const SubstituteData& substituteData) { |
| 488 unsigned long identifier = createUniqueIdentifier(); | |
| 489 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker( | |
| 490 identifier, request.resourceRequest()); | |
| 487 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); | 491 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); |
| 488 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || | 492 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || |
| 489 factory.type() == Resource::Raw || | 493 factory.type() == Resource::Raw || |
| 490 factory.type() == Resource::XSLStyleSheet); | 494 factory.type() == Resource::XSLStyleSheet); |
| 491 | 495 |
| 492 context().populateRequestData(request.mutableResourceRequest()); | 496 context().populateRequestData(request.mutableResourceRequest()); |
| 493 if (request.resourceRequest().httpHeaderField("Upgrade-Insecure-Requests") != | 497 if (request.resourceRequest().httpHeaderField("Upgrade-Insecure-Requests") != |
| 494 AtomicString("1")) { | 498 AtomicString("1")) { |
| 495 context().modifyRequestForCSP(request.mutableResourceRequest()); | 499 context().modifyRequestForCSP(request.mutableResourceRequest()); |
| 496 } | 500 } |
| 497 context().addClientHintsIfNecessary(request); | 501 context().addClientHintsIfNecessary(request); |
| 498 context().addCSPHeaderIfNecessary(factory.type(), request); | 502 context().addCSPHeaderIfNecessary(factory.type(), request); |
| 499 | 503 |
| 504 // TODO(dproy): Remove this. http://crbug.com/659666 | |
|
Charlie Harrison
2016/11/08 15:20:18
drive-by: This trace is important for tracking CPU
dproy
2016/11/08 16:31:50
Do you mean just this single trace in particular?
Charlie Harrison
2016/11/08 16:34:26
Yep this single method does a lot of work, includi
dproy
2016/11/08 16:45:35
Ah I see. This CL is about tracking the entire net
Charlie Harrison
2016/11/08 17:34:04
That plan sounds great to me. Just to clarify, wil
| |
| 500 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", | 505 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", |
| 501 urlForTraceEvent(request.url())); | 506 urlForTraceEvent(request.url())); |
| 502 | 507 |
| 503 if (!request.url().isValid()) | 508 if (!request.url().isValid()) |
| 504 return nullptr; | 509 return nullptr; |
| 505 | 510 |
| 506 unsigned long identifier = createUniqueIdentifier(); | |
| 507 request.mutableResourceRequest().setPriority(computeLoadPriority( | 511 request.mutableResourceRequest().setPriority(computeLoadPriority( |
| 508 factory.type(), request, ResourcePriority::NotVisible)); | 512 factory.type(), request, ResourcePriority::NotVisible)); |
| 509 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), | 513 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), |
| 510 request.defer()); | 514 request.defer()); |
| 515 network_instrumentation::initialResourcePrioritySet( | |
|
caseq
2016/11/08 18:24:32
let's unify this with resourcePriorityChanged, I'd
dproy
2016/11/09 20:44:00
Done.
| |
| 516 identifier, request.resourceRequest().priority()); | |
| 511 | 517 |
| 512 if (!context().canRequest( | 518 if (!context().canRequest( |
| 513 factory.type(), request.resourceRequest(), | 519 factory.type(), request.resourceRequest(), |
| 514 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), | 520 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), |
| 515 request.options(), request.forPreload(), | 521 request.options(), request.forPreload(), |
| 516 request.getOriginRestriction())) { | 522 request.getOriginRestriction())) { |
| 517 DCHECK(!substituteData.forceSynchronousLoad()); | 523 DCHECK(!substituteData.forceSynchronousLoad()); |
| 518 return resourceForBlockedRequest(request, factory); | 524 return resourceForBlockedRequest(request, factory); |
| 519 } | 525 } |
| 520 | 526 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 | 633 |
| 628 // Returns with an existing resource if the resource does not need to start | 634 // Returns with an existing resource if the resource does not need to start |
| 629 // loading immediately. If revalidation policy was determined as |Revalidate|, | 635 // loading immediately. If revalidation policy was determined as |Revalidate|, |
| 630 // the resource was already initialized for the revalidation here, but won't | 636 // the resource was already initialized for the revalidation here, but won't |
| 631 // start loading. | 637 // start loading. |
| 632 if (!resourceNeedsLoad(resource, request, policy)) | 638 if (!resourceNeedsLoad(resource, request, policy)) |
| 633 return resource; | 639 return resource; |
| 634 | 640 |
| 635 if (!startLoad(resource)) | 641 if (!startLoad(resource)) |
| 636 return nullptr; | 642 return nullptr; |
| 643 | |
| 644 scopedResourceLoadTracker.doNotCloseSliceAtEndOfScope(); | |
| 645 | |
| 637 DCHECK(!resource->errorOccurred() || | 646 DCHECK(!resource->errorOccurred() || |
| 638 request.options().synchronousPolicy == RequestSynchronously); | 647 request.options().synchronousPolicy == RequestSynchronously); |
| 639 return resource; | 648 return resource; |
| 640 } | 649 } |
| 641 | 650 |
| 642 void ResourceFetcher::resourceTimingReportTimerFired(TimerBase* timer) { | 651 void ResourceFetcher::resourceTimingReportTimerFired(TimerBase* timer) { |
| 643 DCHECK_EQ(timer, &m_resourceTimingReportTimer); | 652 DCHECK_EQ(timer, &m_resourceTimingReportTimer); |
| 644 Vector<std::unique_ptr<ResourceTimingInfo>> timingReports; | 653 Vector<std::unique_ptr<ResourceTimingInfo>> timingReports; |
| 645 timingReports.swap(m_scheduledResourceTimingReports); | 654 timingReports.swap(m_scheduledResourceTimingReports); |
| 646 for (const auto& timingInfo : timingReports) | 655 for (const auto& timingInfo : timingReports) |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 return m_loaders.size(); | 1046 return m_loaders.size(); |
| 1038 } | 1047 } |
| 1039 | 1048 |
| 1040 bool ResourceFetcher::hasPendingRequest() const { | 1049 bool ResourceFetcher::hasPendingRequest() const { |
| 1041 return m_loaders.size() > 0 || m_nonBlockingLoaders.size() > 0; | 1050 return m_loaders.size() > 0 || m_nonBlockingLoaders.size() > 0; |
| 1042 } | 1051 } |
| 1043 | 1052 |
| 1044 void ResourceFetcher::preloadStarted(Resource* resource) { | 1053 void ResourceFetcher::preloadStarted(Resource* resource) { |
| 1045 if (m_preloads && m_preloads->contains(resource)) | 1054 if (m_preloads && m_preloads->contains(resource)) |
| 1046 return; | 1055 return; |
| 1047 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource->identifier(), | |
| 1048 "Preload"); | |
| 1049 resource->increasePreloadCount(); | 1056 resource->increasePreloadCount(); |
| 1050 | 1057 |
| 1051 if (!m_preloads) | 1058 if (!m_preloads) |
| 1052 m_preloads = new HeapListHashSet<Member<Resource>>; | 1059 m_preloads = new HeapListHashSet<Member<Resource>>; |
| 1053 m_preloads->add(resource); | 1060 m_preloads->add(resource); |
| 1054 | 1061 |
| 1055 if (m_preloadedURLsForTest) | 1062 if (m_preloadedURLsForTest) |
| 1056 m_preloadedURLsForTest->add(resource->url().getString()); | 1063 m_preloadedURLsForTest->add(resource->url().getString()); |
| 1057 } | 1064 } |
| 1058 | 1065 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 if (!context().isMainFrame()) | 1118 if (!context().isMainFrame()) |
| 1112 return nullptr; | 1119 return nullptr; |
| 1113 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()); | 1120 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()); |
| 1114 return m_archive ? m_archive->mainResource() : nullptr; | 1121 return m_archive ? m_archive->mainResource() : nullptr; |
| 1115 } | 1122 } |
| 1116 | 1123 |
| 1117 void ResourceFetcher::didFinishLoading(Resource* resource, | 1124 void ResourceFetcher::didFinishLoading(Resource* resource, |
| 1118 double finishTime, | 1125 double finishTime, |
| 1119 int64_t encodedDataLength, | 1126 int64_t encodedDataLength, |
| 1120 DidFinishLoadingReason finishReason) { | 1127 DidFinishLoadingReason finishReason) { |
| 1121 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); | 1128 network_instrumentation::endResourceLoad( |
| 1129 resource->identifier(), network_instrumentation::RequestOutcome::Success); | |
| 1122 DCHECK(resource); | 1130 DCHECK(resource); |
| 1123 | 1131 |
| 1124 // When loading a multipart resource, make the loader non-block when finishing | 1132 // When loading a multipart resource, make the loader non-block when finishing |
| 1125 // loading the first part. | 1133 // loading the first part. |
| 1126 if (finishReason == DidFinishFirstPartInMultipart) | 1134 if (finishReason == DidFinishFirstPartInMultipart) |
| 1127 moveResourceLoaderToNonBlocking(resource->loader()); | 1135 moveResourceLoaderToNonBlocking(resource->loader()); |
| 1128 else | 1136 else |
| 1129 removeResourceLoader(resource->loader()); | 1137 removeResourceLoader(resource->loader()); |
| 1130 DCHECK(!m_loaders.contains(resource->loader())); | 1138 DCHECK(!m_loaders.contains(resource->loader())); |
| 1131 DCHECK(finishReason == DidFinishFirstPartInMultipart || | 1139 DCHECK(finishReason == DidFinishFirstPartInMultipart || |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 context().didLoadResource(resource); | 1174 context().didLoadResource(resource); |
| 1167 | 1175 |
| 1168 if (resource->isImage() && | 1176 if (resource->isImage() && |
| 1169 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { | 1177 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { |
| 1170 toImageResource(resource)->reloadIfLoFiOrPlaceholder(this); | 1178 toImageResource(resource)->reloadIfLoFiOrPlaceholder(this); |
| 1171 } | 1179 } |
| 1172 } | 1180 } |
| 1173 | 1181 |
| 1174 void ResourceFetcher::didFailLoading(Resource* resource, | 1182 void ResourceFetcher::didFailLoading(Resource* resource, |
| 1175 const ResourceError& error) { | 1183 const ResourceError& error) { |
| 1176 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); | 1184 network_instrumentation::endResourceLoad( |
| 1185 resource->identifier(), network_instrumentation::RequestOutcome::Fail); | |
| 1177 removeResourceLoader(resource->loader()); | 1186 removeResourceLoader(resource->loader()); |
| 1178 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); | 1187 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); |
| 1179 bool isInternalRequest = resource->options().initiatorInfo.name == | 1188 bool isInternalRequest = resource->options().initiatorInfo.name == |
| 1180 FetchInitiatorTypeNames::internal; | 1189 FetchInitiatorTypeNames::internal; |
| 1181 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); | 1190 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); |
| 1182 resource->error(error); | 1191 resource->error(error); |
| 1183 context().didLoadResource(resource); | 1192 context().didLoadResource(resource); |
| 1184 | 1193 |
| 1185 if (resource->isImage() && | 1194 if (resource->isImage() && |
| 1186 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { | 1195 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1412 ResourcePriority resourcePriority = resource->priorityFromObservers(); | 1421 ResourcePriority resourcePriority = resource->priorityFromObservers(); |
| 1413 ResourceLoadPriority resourceLoadPriority = computeLoadPriority( | 1422 ResourceLoadPriority resourceLoadPriority = computeLoadPriority( |
| 1414 Resource::Image, | 1423 Resource::Image, |
| 1415 FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), | 1424 FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), |
| 1416 resourcePriority.visibility); | 1425 resourcePriority.visibility); |
| 1417 if (resourceLoadPriority == resource->resourceRequest().priority()) | 1426 if (resourceLoadPriority == resource->resourceRequest().priority()) |
| 1418 continue; | 1427 continue; |
| 1419 | 1428 |
| 1420 resource->didChangePriority(resourceLoadPriority, | 1429 resource->didChangePriority(resourceLoadPriority, |
| 1421 resourcePriority.intraPriorityValue); | 1430 resourcePriority.intraPriorityValue); |
| 1422 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", | 1431 network_instrumentation::resourcePriorityChanged(resource->identifier(), |
| 1423 resource->identifier(), "ChangePriority", | 1432 resourceLoadPriority); |
| 1424 "priority", resourceLoadPriority); | |
| 1425 context().dispatchDidChangeResourcePriority( | 1433 context().dispatchDidChangeResourcePriority( |
| 1426 resource->identifier(), resourceLoadPriority, | 1434 resource->identifier(), resourceLoadPriority, |
| 1427 resourcePriority.intraPriorityValue); | 1435 resourcePriority.intraPriorityValue); |
| 1428 } | 1436 } |
| 1429 } | 1437 } |
| 1430 | 1438 |
| 1431 void ResourceFetcher::reloadLoFiImages() { | 1439 void ResourceFetcher::reloadLoFiImages() { |
| 1432 for (const auto& documentResource : m_documentResources) { | 1440 for (const auto& documentResource : m_documentResources) { |
| 1433 Resource* resource = documentResource.value.get(); | 1441 Resource* resource = documentResource.value.get(); |
| 1434 if (resource && resource->isImage()) { | 1442 if (resource && resource->isImage()) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1622 visitor->trace(m_context); | 1630 visitor->trace(m_context); |
| 1623 visitor->trace(m_archive); | 1631 visitor->trace(m_archive); |
| 1624 visitor->trace(m_loaders); | 1632 visitor->trace(m_loaders); |
| 1625 visitor->trace(m_nonBlockingLoaders); | 1633 visitor->trace(m_nonBlockingLoaders); |
| 1626 visitor->trace(m_documentResources); | 1634 visitor->trace(m_documentResources); |
| 1627 visitor->trace(m_preloads); | 1635 visitor->trace(m_preloads); |
| 1628 visitor->trace(m_resourceTimingInfoMap); | 1636 visitor->trace(m_resourceTimingInfoMap); |
| 1629 } | 1637 } |
| 1630 | 1638 |
| 1631 } // namespace blink | 1639 } // namespace blink |
| OLD | NEW |