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

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

Issue 2444783002: Add trace event for complete network request (Closed)
Patch Set: Address review comments Created 4 years, 1 month 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
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 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
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
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
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());
511 515
512 if (!context().canRequest( 516 if (!context().canRequest(
513 factory.type(), request.resourceRequest(), 517 factory.type(), request.resourceRequest(),
514 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), 518 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()),
515 request.options(), request.forPreload(), 519 request.options(), request.forPreload(),
516 request.getOriginRestriction())) { 520 request.getOriginRestriction())) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 m_documentResources.set( 629 m_documentResources.set(
626 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); 630 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource);
627 631
628 // Returns with an existing resource if the resource does not need to start 632 // Returns with an existing resource if the resource does not need to start
629 // loading immediately. If revalidation policy was determined as |Revalidate|, 633 // loading immediately. If revalidation policy was determined as |Revalidate|,
630 // the resource was already initialized for the revalidation here, but won't 634 // the resource was already initialized for the revalidation here, but won't
631 // start loading. 635 // start loading.
632 if (!resourceNeedsLoad(resource, request, policy)) 636 if (!resourceNeedsLoad(resource, request, policy))
633 return resource; 637 return resource;
634 638
635 if (!startLoad(resource)) 639 if (startLoad(resource))
640 scopedResourceLoadTracker.doNotCloseSliceAtEndOfScope();
chiniforooshan 2016/11/03 15:50:36 Move this right after "if (!startLoad(resource)) r
dproy 2016/11/03 16:27:19 Done.
641 else
636 return nullptr; 642 return nullptr;
643
637 DCHECK(!resource->errorOccurred() || 644 DCHECK(!resource->errorOccurred() ||
638 request.options().synchronousPolicy == RequestSynchronously); 645 request.options().synchronousPolicy == RequestSynchronously);
639 return resource; 646 return resource;
640 } 647 }
641 648
642 void ResourceFetcher::resourceTimingReportTimerFired(TimerBase* timer) { 649 void ResourceFetcher::resourceTimingReportTimerFired(TimerBase* timer) {
643 DCHECK_EQ(timer, &m_resourceTimingReportTimer); 650 DCHECK_EQ(timer, &m_resourceTimingReportTimer);
644 Vector<std::unique_ptr<ResourceTimingInfo>> timingReports; 651 Vector<std::unique_ptr<ResourceTimingInfo>> timingReports;
645 timingReports.swap(m_scheduledResourceTimingReports); 652 timingReports.swap(m_scheduledResourceTimingReports);
646 for (const auto& timingInfo : timingReports) 653 for (const auto& timingInfo : timingReports)
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 return m_loaders.size(); 1044 return m_loaders.size();
1038 } 1045 }
1039 1046
1040 bool ResourceFetcher::hasPendingRequest() const { 1047 bool ResourceFetcher::hasPendingRequest() const {
1041 return m_loaders.size() > 0 || m_nonBlockingLoaders.size() > 0; 1048 return m_loaders.size() > 0 || m_nonBlockingLoaders.size() > 0;
1042 } 1049 }
1043 1050
1044 void ResourceFetcher::preloadStarted(Resource* resource) { 1051 void ResourceFetcher::preloadStarted(Resource* resource) {
1045 if (m_preloads && m_preloads->contains(resource)) 1052 if (m_preloads && m_preloads->contains(resource))
1046 return; 1053 return;
1054 // TODO(dproy): Remove this. http://crbug.com/659666
1047 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource->identifier(), 1055 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource->identifier(),
1048 "Preload"); 1056 "Preload");
1049 resource->increasePreloadCount(); 1057 resource->increasePreloadCount();
1050 1058
1051 if (!m_preloads) 1059 if (!m_preloads)
1052 m_preloads = new HeapListHashSet<Member<Resource>>; 1060 m_preloads = new HeapListHashSet<Member<Resource>>;
1053 m_preloads->add(resource); 1061 m_preloads->add(resource);
1054 1062
1055 if (m_preloadedURLsForTest) 1063 if (m_preloadedURLsForTest)
1056 m_preloadedURLsForTest->add(resource->url().getString()); 1064 m_preloadedURLsForTest->add(resource->url().getString());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 if (!context().isMainFrame()) 1119 if (!context().isMainFrame())
1112 return nullptr; 1120 return nullptr;
1113 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()); 1121 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer());
1114 return m_archive ? m_archive->mainResource() : nullptr; 1122 return m_archive ? m_archive->mainResource() : nullptr;
1115 } 1123 }
1116 1124
1117 void ResourceFetcher::didFinishLoading(Resource* resource, 1125 void ResourceFetcher::didFinishLoading(Resource* resource,
1118 double finishTime, 1126 double finishTime,
1119 int64_t encodedDataLength, 1127 int64_t encodedDataLength,
1120 DidFinishLoadingReason finishReason) { 1128 DidFinishLoadingReason finishReason) {
1129 // TODO(dproy): Remove this. http://crbug.com/659666
1121 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); 1130 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier());
1131 network_instrumentation::endResourceLoad(
1132 resource->identifier(), network_instrumentation::RequestOutcome::Success);
1122 DCHECK(resource); 1133 DCHECK(resource);
1123 1134
1124 // When loading a multipart resource, make the loader non-block when finishing 1135 // When loading a multipart resource, make the loader non-block when finishing
1125 // loading the first part. 1136 // loading the first part.
1126 if (finishReason == DidFinishFirstPartInMultipart) 1137 if (finishReason == DidFinishFirstPartInMultipart)
1127 moveResourceLoaderToNonBlocking(resource->loader()); 1138 moveResourceLoaderToNonBlocking(resource->loader());
1128 else 1139 else
1129 removeResourceLoader(resource->loader()); 1140 removeResourceLoader(resource->loader());
1130 DCHECK(!m_loaders.contains(resource->loader())); 1141 DCHECK(!m_loaders.contains(resource->loader()));
1131 DCHECK(finishReason == DidFinishFirstPartInMultipart || 1142 DCHECK(finishReason == DidFinishFirstPartInMultipart ||
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 context().didLoadResource(resource); 1177 context().didLoadResource(resource);
1167 1178
1168 if (resource->isImage() && 1179 if (resource->isImage() &&
1169 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { 1180 toImageResource(resource)->shouldReloadBrokenPlaceholder()) {
1170 toImageResource(resource)->reloadIfLoFiOrPlaceholder(this); 1181 toImageResource(resource)->reloadIfLoFiOrPlaceholder(this);
1171 } 1182 }
1172 } 1183 }
1173 1184
1174 void ResourceFetcher::didFailLoading(Resource* resource, 1185 void ResourceFetcher::didFailLoading(Resource* resource,
1175 const ResourceError& error) { 1186 const ResourceError& error) {
1187 // TODO(dproy): Remove this. http://crbug.com/659666
1176 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); 1188 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier());
1189 network_instrumentation::endResourceLoad(
1190 resource->identifier(), network_instrumentation::RequestOutcome::Fail);
1177 removeResourceLoader(resource->loader()); 1191 removeResourceLoader(resource->loader());
1178 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); 1192 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource));
1179 bool isInternalRequest = resource->options().initiatorInfo.name == 1193 bool isInternalRequest = resource->options().initiatorInfo.name ==
1180 FetchInitiatorTypeNames::internal; 1194 FetchInitiatorTypeNames::internal;
1181 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); 1195 context().dispatchDidFail(resource->identifier(), error, isInternalRequest);
1182 resource->error(error); 1196 resource->error(error);
1183 context().didLoadResource(resource); 1197 context().didLoadResource(resource);
1184 1198
1185 if (resource->isImage() && 1199 if (resource->isImage() &&
1186 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { 1200 toImageResource(resource)->shouldReloadBrokenPlaceholder()) {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 ResourcePriority resourcePriority = resource->priorityFromObservers(); 1426 ResourcePriority resourcePriority = resource->priorityFromObservers();
1413 ResourceLoadPriority resourceLoadPriority = computeLoadPriority( 1427 ResourceLoadPriority resourceLoadPriority = computeLoadPriority(
1414 Resource::Image, 1428 Resource::Image,
1415 FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), 1429 FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()),
1416 resourcePriority.visibility); 1430 resourcePriority.visibility);
1417 if (resourceLoadPriority == resource->resourceRequest().priority()) 1431 if (resourceLoadPriority == resource->resourceRequest().priority())
1418 continue; 1432 continue;
1419 1433
1420 resource->didChangePriority(resourceLoadPriority, 1434 resource->didChangePriority(resourceLoadPriority,
1421 resourcePriority.intraPriorityValue); 1435 resourcePriority.intraPriorityValue);
1436 // TODO(dproy): Remove this. http://crbug.com/659666
1422 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", 1437 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource",
1423 resource->identifier(), "ChangePriority", 1438 resource->identifier(), "ChangePriority",
1424 "priority", resourceLoadPriority); 1439 "priority", resourceLoadPriority);
1425 context().dispatchDidChangeResourcePriority( 1440 context().dispatchDidChangeResourcePriority(
1426 resource->identifier(), resourceLoadPriority, 1441 resource->identifier(), resourceLoadPriority,
1427 resourcePriority.intraPriorityValue); 1442 resourcePriority.intraPriorityValue);
1428 } 1443 }
1429 } 1444 }
1430 1445
1431 void ResourceFetcher::reloadLoFiImages() { 1446 void ResourceFetcher::reloadLoFiImages() {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 visitor->trace(m_context); 1637 visitor->trace(m_context);
1623 visitor->trace(m_archive); 1638 visitor->trace(m_archive);
1624 visitor->trace(m_loaders); 1639 visitor->trace(m_loaders);
1625 visitor->trace(m_nonBlockingLoaders); 1640 visitor->trace(m_nonBlockingLoaders);
1626 visitor->trace(m_documentResources); 1641 visitor->trace(m_documentResources);
1627 visitor->trace(m_preloads); 1642 visitor->trace(m_preloads);
1628 visitor->trace(m_resourceTimingInfoMap); 1643 visitor->trace(m_resourceTimingInfoMap);
1629 } 1644 }
1630 1645
1631 } // namespace blink 1646 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698