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

Unified Diff: third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp

Issue 2343623002: Add a warning whenever link preloads are not used (Closed)
Patch Set: Removed the counter, since it was not accurate Created 4 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 side-by-side diff with in-line comments
Download patch
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 a61d582a7a65b49fe938cba6f06b2a72098347c0..8fa59f5241d70b9766247b6abccc0386d4ae9178 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp
+++ b/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp
@@ -905,7 +905,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)
@@ -917,6 +917,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 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);
+ }
+ }
+}
+
ArchiveResource* ResourceFetcher::createArchive(Resource* resource)
{
// Only the top-frame can load MHTML.
@@ -1192,7 +1203,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:

Powered by Google App Engine
This is Rietveld 408576698