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

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

Issue 2353013002: [test] Resources served from MemoryCache - early exit (Closed)
Patch Set: use the right issue :P Created 4 years, 2 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
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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 481 }
482 482
483 Resource* ResourceFetcher::requestResource( 483 Resource* ResourceFetcher::requestResource(
484 FetchRequest& request, 484 FetchRequest& request,
485 const ResourceFactory& factory, 485 const ResourceFactory& factory,
486 const SubstituteData& substituteData) { 486 const SubstituteData& substituteData) {
487 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); 487 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime");
488 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || 488 DCHECK(request.options().synchronousPolicy == RequestAsynchronously ||
489 factory.type() == Resource::Raw || 489 factory.type() == Resource::Raw ||
490 factory.type() == Resource::XSLStyleSheet); 490 factory.type() == Resource::XSLStyleSheet);
491 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url",
492 urlForTraceEvent(request.url()));
491 493
492 context().populateRequestData(request.mutableResourceRequest()); 494 context().populateRequestData(request.mutableResourceRequest());
493 if (request.resourceRequest().httpHeaderField("Upgrade-Insecure-Requests") != 495 if (request.resourceRequest().httpHeaderField("Upgrade-Insecure-Requests") !=
494 AtomicString("1")) { 496 AtomicString("1")) {
495 context().modifyRequestForCSP(request.mutableResourceRequest()); 497 context().modifyRequestForCSP(request.mutableResourceRequest());
496 } 498 }
497 context().addClientHintsIfNecessary(request); 499 context().addClientHintsIfNecessary(request);
498 context().addCSPHeaderIfNecessary(factory.type(), request); 500 context().addCSPHeaderIfNecessary(factory.type(), request);
499 501
500 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url",
501 urlForTraceEvent(request.url()));
502
503 if (!request.url().isValid()) 502 if (!request.url().isValid())
504 return nullptr; 503 return nullptr;
505 504
506 unsigned long identifier = createUniqueIdentifier(); 505 unsigned long identifier = createUniqueIdentifier();
506
507 // Potentially early return if this request matches a preload. We need to be
508 // careful to ensure that the preload request matches the various security
509 // properties of the load.
510 Resource* originalResource(nullptr);
511 originalResource =
512 memoryCache()->resourceForURL(request.url(), getCacheIdentifier());
513 if (originalResource) {
514 const RevalidationPolicy policy = determineRevalidationPolicy(
515 factory.type(), request, originalResource, false);
516 if (policy == Use) {
517 if (originalResource->isLinkPreload() && !request.isLinkPreload())
518 originalResource->setLinkPreload(false);
519 moveCachedNonBlockingResourceToBlocking(originalResource, request);
520 requestLoadStarted(identifier, originalResource, request,
521 ResourceLoadingFromCache, false);
522 return originalResource;
523 }
524 }
525
507 request.mutableResourceRequest().setPriority(computeLoadPriority( 526 request.mutableResourceRequest().setPriority(computeLoadPriority(
508 factory.type(), request, ResourcePriority::NotVisible)); 527 factory.type(), request, ResourcePriority::NotVisible));
509 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), 528 initializeResourceRequest(request.mutableResourceRequest(), factory.type(),
510 request.defer()); 529 request.defer());
511 530
512 if (!context().canRequest( 531 if (!context().canRequest(
513 factory.type(), request.resourceRequest(), 532 factory.type(), request.resourceRequest(),
514 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), 533 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()),
515 request.options(), request.forPreload(), 534 request.options(), request.forPreload(),
516 request.getOriginRestriction())) { 535 request.getOriginRestriction())) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 Resource* resource(nullptr); 567 Resource* resource(nullptr);
549 if (isStaticData) { 568 if (isStaticData) {
550 resource = resourceForStaticData(request, factory, substituteData); 569 resource = resourceForStaticData(request, factory, substituteData);
551 // Abort the request if the archive doesn't contain the resource, except in 570 // Abort the request if the archive doesn't contain the resource, except in
552 // the case of data URLs which might have resources such as fonts that need 571 // the case of data URLs which might have resources such as fonts that need
553 // to be decoded only on demand. These data URLs are allowed to be 572 // to be decoded only on demand. These data URLs are allowed to be
554 // processed using the normal ResourceFetcher machinery. 573 // processed using the normal ResourceFetcher machinery.
555 if (!resource && !isDataUrl && m_archive) 574 if (!resource && !isDataUrl && m_archive)
556 return nullptr; 575 return nullptr;
557 } 576 }
577
578 // Only retrieve the Resource from MemoryCache if the url has been changed
579 // by the embedder.
558 if (!resource) { 580 if (!resource) {
559 resource = 581 if (!originalResource || request.url() != originalResource->url()) {
560 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); 582 resource =
583 memoryCache()->resourceForURL(request.url(), getCacheIdentifier());
584 } else {
585 resource = originalResource;
586 }
561 } 587 }
562 588
563 // See if we can use an existing resource from the cache. If so, we need to 589 // See if we can use an existing resource from the cache. If so, we need to
564 // move it to be load blocking. 590 // move it to be load blocking.
565 moveCachedNonBlockingResourceToBlocking(resource, request); 591 moveCachedNonBlockingResourceToBlocking(resource, request);
566 592
567 const RevalidationPolicy policy = determineRevalidationPolicy( 593 const RevalidationPolicy policy = determineRevalidationPolicy(
568 factory.type(), request, resource, isStaticData); 594 factory.type(), request, resource, isStaticData);
569 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy", 595 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy",
570 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy); 596 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 RecordSriResourceIntegrityMismatchEvent(CheckingForIntegrityMismatch); 827 RecordSriResourceIntegrityMismatchEvent(CheckingForIntegrityMismatch);
802 if (existingResource->mustRefetchDueToIntegrityMetadata(fetchRequest)) { 828 if (existingResource->mustRefetchDueToIntegrityMetadata(fetchRequest)) {
803 RecordSriResourceIntegrityMismatchEvent(RefetchDueToIntegrityMismatch); 829 RecordSriResourceIntegrityMismatchEvent(RefetchDueToIntegrityMismatch);
804 return Reload; 830 return Reload;
805 } 831 }
806 832
807 // Service Worker's CORS fallback message must not be cached. 833 // Service Worker's CORS fallback message must not be cached.
808 if (existingResource->response().wasFallbackRequiredByServiceWorker()) 834 if (existingResource->response().wasFallbackRequiredByServiceWorker())
809 return Reload; 835 return Reload;
810 836
811 // We already have a preload going for this URL.
812 if (fetchRequest.forPreload() && existingResource->isPreloaded())
813 return Use;
814
815 // If the same URL has been loaded as a different type, we need to reload. 837 // If the same URL has been loaded as a different type, we need to reload.
816 if (existingResource->getType() != type) { 838 if (existingResource->getType() != type) {
817 // FIXME: If existingResource is a Preload and the new type is LinkPrefetch 839 // FIXME: If existingResource is a Preload and the new type is LinkPrefetch
818 // We really should discard the new prefetch since the preload has more 840 // We really should discard the new prefetch since the preload has more
819 // specific type information! crbug.com/379893 841 // specific type information! crbug.com/379893
820 // fast/dom/HTMLLinkElement/link-and-subresource-test hits this case. 842 // fast/dom/HTMLLinkElement/link-and-subresource-test hits this case.
821 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPolicy " 843 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPolicy "
822 "reloading due to type mismatch."; 844 "reloading due to type mismatch.";
823 return Reload; 845 return Reload;
824 } 846 }
825 847
848 // We already have a preload going for this URL.
849 if (fetchRequest.forPreload() && existingResource->isPreloaded())
850 return Use;
851
826 // Do not load from cache if images are not enabled. There are two general 852 // Do not load from cache if images are not enabled. There are two general
827 // cases: 853 // cases:
828 // 854 //
829 // 1. Images are disabled. Don't ever load images, even if the image is cached 855 // 1. Images are disabled. Don't ever load images, even if the image is cached
830 // or it is a data: url. In this case, we "Reload" the image, then defer it 856 // or it is a data: url. In this case, we "Reload" the image, then defer it
831 // with resourceNeedsLoad() so that it never actually goes to the network. 857 // with resourceNeedsLoad() so that it never actually goes to the network.
832 // 858 //
833 // 2. Images are enabled, but not loaded automatically. In this case, we will 859 // 2. Images are enabled, but not loaded automatically. In this case, we will
834 // Use cached resources or data: urls, but will similarly fall back to a 860 // Use cached resources or data: urls, but will similarly fall back to a
835 // deferred network load if we don't have the data available without a network 861 // deferred network load if we don't have the data available without a network
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 visitor->trace(m_context); 1638 visitor->trace(m_context);
1613 visitor->trace(m_archive); 1639 visitor->trace(m_archive);
1614 visitor->trace(m_loaders); 1640 visitor->trace(m_loaders);
1615 visitor->trace(m_nonBlockingLoaders); 1641 visitor->trace(m_nonBlockingLoaders);
1616 visitor->trace(m_documentResources); 1642 visitor->trace(m_documentResources);
1617 visitor->trace(m_preloads); 1643 visitor->trace(m_preloads);
1618 visitor->trace(m_resourceTimingInfoMap); 1644 visitor->trace(m_resourceTimingInfoMap);
1619 } 1645 }
1620 1646
1621 } // namespace blink 1647 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698