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

Unified Diff: Source/core/fetch/FontResource.cpp

Issue 324003002: Add a UMA histogram for type of web font usage (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase, and make PackageFormatUnknown the first bucket Created 6 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fetch/FontResource.cpp
diff --git a/Source/core/fetch/FontResource.cpp b/Source/core/fetch/FontResource.cpp
index 92a91170215ecd6a09b885352faff14ea4129620..a915a14d53409cfde2f61bece82fa4b12dcf8d71 100644
--- a/Source/core/fetch/FontResource.cpp
+++ b/Source/core/fetch/FontResource.cpp
@@ -46,6 +46,33 @@ namespace WebCore {
static const double fontLoadWaitLimitSec = 3.0;
+enum FontPackageFormat {
+ PackageFormatUnknown,
+ PackageFormatSFNT,
+ PackageFormatWOFF,
+ PackageFormatWOFF2,
+ PackageFormatSVG,
+ PackageFormatEnumMax
+};
+
+static FontPackageFormat packageFormatOf(SharedBuffer* buffer)
+{
+ if (buffer->size() < 4)
+ return PackageFormatUnknown;
+
+ const char* data = buffer->data();
+ if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F')
+ return PackageFormatWOFF;
+ if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == '2')
+ return PackageFormatWOFF2;
+ return PackageFormatSFNT;
+}
+
+static void recordPackageFormatHistogram(FontPackageFormat format)
+{
+ blink::Platform::current()->histogramEnumeration("WebFont.PackageFormat", format, PackageFormatEnumMax);
+}
+
FontResource::FontResource(const ResourceRequest& resourceRequest)
: Resource(resourceRequest, Font)
, m_loadInitiated(false)
@@ -91,8 +118,13 @@ bool FontResource::ensureCustomFontData()
if (!m_fontData && !errorOccurred() && !isLoading()) {
if (m_data)
m_fontData = FontCustomPlatformData::create(m_data.get());
- if (!m_fontData)
+
+ if (m_fontData) {
+ recordPackageFormatHistogram(packageFormatOf(m_data.get()));
+ } else {
setStatus(DecodeError);
+ recordPackageFormatHistogram(PackageFormatUnknown);
+ }
}
return m_fontData;
}
@@ -123,8 +155,12 @@ bool FontResource::ensureSVGFontData()
if (decoder->sawError())
m_externalSVGDocument = nullptr;
}
- if (!m_externalSVGDocument)
+ if (m_externalSVGDocument) {
+ recordPackageFormatHistogram(PackageFormatSVG);
+ } else {
setStatus(DecodeError);
+ recordPackageFormatHistogram(PackageFormatUnknown);
+ }
}
return m_externalSVGDocument;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698