Index: third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp |
diff --git a/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp b/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp |
index 5ff0d0d3861a31c60532f733a76016d704734229..7481d2255ab8756cbb55b1c9624d49ca21739646 100644 |
--- a/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp |
+++ b/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp |
@@ -211,6 +211,7 @@ static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re |
ResourceFetcher::ResourceFetcher(FetchContext* newContext) |
: m_context(newContext) |
+ , m_linkPreloadCounter(0) |
, m_archive(context().isMainFrame() ? nullptr : context().archive()) |
, m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTimerFired) |
, m_autoLoadImages(true) |
@@ -474,6 +475,10 @@ Resource* ResourceFetcher::requestResource(FetchRequest& request, const Resource |
initializeRevalidation(request.mutableResourceRequest(), resource); |
break; |
case Use: |
+ if (resource->isLinkPreload() && !request.isLinkPreload()) { |
+ resource->setLinkPreload(false); |
+ --m_linkPreloadCounter; |
+ } |
memoryCache()->updateForAccess(resource); |
break; |
} |
@@ -869,6 +874,8 @@ void ResourceFetcher::preloadStarted(Resource* resource) |
return; |
TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource->identifier(), "Preload"); |
resource->increasePreloadCount(); |
+ if (resource->isLinkPreload()) |
+ ++m_linkPreloadCounter; |
if (!m_preloads) |
m_preloads = new HeapListHashSet<Member<Resource>>; |
@@ -878,7 +885,7 @@ void ResourceFetcher::preloadStarted(Resource* resource) |
bool ResourceFetcher::isPreloaded(const KURL& url) const |
{ |
if (m_preloads) { |
- for (auto resource : *m_preloads) { |
+ for (const auto& resource : *m_preloads) { |
if (resource->url() == url) |
return true; |
} |
@@ -894,7 +901,7 @@ void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) |
logPreloadStats(); |
- for (auto resource : *m_preloads) { |
+ for (const auto& resource : *m_preloads) { |
if (policy == ClearAllPreloads || !resource->isLinkPreload()) { |
resource->decreasePreloadCount(); |
if (resource->getPreloadResult() == Resource::PreloadNotReferenced) |
@@ -906,6 +913,17 @@ void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) |
m_preloads.clear(); |
} |
+void ResourceFetcher::warnUnusedPreloads() |
+{ |
+ if (!m_preloads) |
+ return; |
+ for (const auto& resource : *m_preloads) { |
+ if (resource && resource->isLinkPreload() && resource->getPreloadResult() == Resource::PreloadNotReferenced) { |
+ context().addConsoleMessage("The resource " + resource->url().getString() + " was preloaded using `<link rel=preload>` but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.", FetchContext::LogWarningMessage); |
Charlie Harrison
2016/09/14 21:07:59
Hm... but what about Link preload headers?
|
+ } |
+ } |
+} |
+ |
ArchiveResource* ResourceFetcher::createArchive(Resource* resource) |
{ |
// Only the top-frame can load MHTML. |
@@ -1180,7 +1198,7 @@ void ResourceFetcher::logPreloadStats() |
unsigned importMisses = 0; |
unsigned raws = 0; |
unsigned rawMisses = 0; |
- for (auto resource : *m_preloads) { |
+ for (const auto& resource : *m_preloads) { |
int missCount = resource->getPreloadResult() == Resource::PreloadNotReferenced ? 1 : 0; |
switch (resource->getType()) { |
case Resource::Image: |