diff --git a/blink/renderer/core/loader/resource_load_observer_for_frame.cc b/blink/renderer/core/loader/resource_load_observer_for_frame.cc index 6b503716a9d..3fb68eaf91c 100644 --- a/blink/renderer/core/loader/resource_load_observer_for_frame.cc +++ b/blink/renderer/core/loader/resource_load_observer_for_frame.cc @@ -4,6 +4,7 @@ #include "third_party/blink/renderer/core/loader/resource_load_observer_for_frame.h" +#include "base/metrics/histogram_macros.h" #include "base/stl_util.h" #include "components/power_scheduler/power_mode_arbiter.h" #include "services/network/public/cpp/cors/cors_error_status.h" @@ -12,6 +13,7 @@ #include "third_party/blink/public/common/security/address_space_feature.h" #include "third_party/blink/public/mojom/frame/frame.mojom-blink.h" #include "third_party/blink/renderer/core/core_probes_inl.h" +#include "third_party/blink/renderer/core/dom/events/event_target.h" #include "third_party/blink/renderer/core/frame/attribution_src_loader.h" #include "third_party/blink/renderer/core/frame/deprecation/deprecation.h" #include "third_party/blink/renderer/core/frame/frame_console.h" @@ -173,6 +175,50 @@ void ResourceLoadObserverForFrame::DidChangePriority( identifier, priority); } +namespace { + +// These values are persisted to logs. Entries should not be renumbered and +// numeric values should never be reused. +// +// Must remain in sync with LinkPrefetchMimeType in +// tools/metrics/histograms/enums.xml. +enum class LinkPrefetchMimeType { + kUnknown = 0, + kHtml = 1, + kScript = 2, + kStyle = 3, + kFont = 4, + kImage = 5, + kMedia = 6, + kMaxValue = kMedia, +}; + +void LogLinkPrefetchMimeTypeHistogram(const AtomicString& mime) { + // Loosely based on https://mimesniff.spec.whatwg.org/#mime-type-groups. + // This could be done properly if needed, but this is just to gather + // approximate data. + LinkPrefetchMimeType type = LinkPrefetchMimeType::kUnknown; + if (mime == "text/html" || mime == "application/xhtml+xml") { + type = LinkPrefetchMimeType::kHtml; + } else if (mime == "application/javascript" || mime == "text/javascript") { + type = LinkPrefetchMimeType::kScript; + } else if (mime == "text/css") { + type = LinkPrefetchMimeType::kStyle; + } else if (mime.StartsWith("font/") || mime.StartsWith("application/font-") || + mime == "application/vnd.ms-fontobject" || + mime == "application/vnd.ms-opentype") { + type = LinkPrefetchMimeType::kFont; + } else if (mime.StartsWith("image/")) { + type = LinkPrefetchMimeType::kImage; + } else if (mime.StartsWith("audio/") || mime.StartsWith("video/") || + mime == "application/ogg") { + type = LinkPrefetchMimeType::kMedia; + } + UMA_HISTOGRAM_ENUMERATION("Blink.Prefetch.LinkPrefetchMimeType", type); +} + +} // namespace + void ResourceLoadObserverForFrame::DidReceiveResponse( uint64_t identifier, const ResourceRequest& request, @@ -230,6 +276,9 @@ void ResourceLoadObserverForFrame::DidReceiveResponse( } } + if (resource->GetType() == ResourceType::kLinkPrefetch) + LogLinkPrefetchMimeTypeHistogram(response.MimeType()); + PreloadHelper::CanLoadResources resource_loading_policy = response_source == ResponseSource::kFromMemoryCache ? PreloadHelper::kDoNotLoadResources