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

Unified Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 1820813004: Add UMA to HTMLCanvasElement to track image formats usage of toDataURL/toBlob (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding comment based on feedback Created 4 years, 9 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 | « third_party/WebKit/Source/core/html/HTMLCanvasElement.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
index 80d196bcc1ba02d4519451fad4f66b009db6d91f..fc7e8c34c1f960c14315417cfa1c495d90a59d9d 100644
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
@@ -492,14 +492,55 @@ void HTMLCanvasElement::setSurfaceSize(const IntSize& size)
}
}
-String HTMLCanvasElement::toEncodingMimeType(const String& mimeType)
+// This enum is used in a UMA histogram; the values should not be changed.
+enum RequestedImageMimeType {
+ RequestedImageMimeTypePng = 0,
+ RequestedImageMimeTypeJpeg = 1,
+ RequestedImageMimeTypeWebp = 2,
+ RequestedImageMimeTypeGif = 3,
+ RequestedImageMimeTypeBmp = 4,
+ RequestedImageMimeTypeIco = 5,
+ RequestedImageMimeTypeTiff = 6,
+ RequestedImageMimeTypeUnknown = 7,
+ NumberOfRequestedImageMimeTypes
+};
+
+String HTMLCanvasElement::toEncodingMimeType(const String& mimeType, const EncodeReason encodeReason)
{
String lowercaseMimeType = mimeType.lower();
+ if (mimeType.isNull())
+ lowercaseMimeType = DefaultMimeType;
+
+ RequestedImageMimeType imageFormat;
+ if (lowercaseMimeType == "image/png") {
+ imageFormat = RequestedImageMimeTypePng;
+ } else if (lowercaseMimeType == "image/jpeg") {
+ imageFormat = RequestedImageMimeTypeJpeg;
+ } else if (lowercaseMimeType == "image/webp") {
+ imageFormat = RequestedImageMimeTypeWebp;
+ } else if (lowercaseMimeType == "image/gif") {
+ imageFormat = RequestedImageMimeTypeGif;
+ } else if (lowercaseMimeType == "image/bmp" || lowercaseMimeType == "image/x-windows-bmp") {
+ imageFormat = RequestedImageMimeTypeBmp;
+ } else if (lowercaseMimeType == "image/x-icon") {
+ imageFormat = RequestedImageMimeTypeIco;
+ } else if (lowercaseMimeType == "image/tiff" || lowercaseMimeType == "image/x-tiff") {
+ imageFormat = RequestedImageMimeTypeTiff;
+ } else {
+ imageFormat = RequestedImageMimeTypeUnknown;
+ }
+
+ if (encodeReason == EncodeReasonToDataURL) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toDataURLImageFormatHistogram, new EnumerationHistogram("Canvas.RequestedImageMimeTypes_toDataURL", NumberOfRequestedImageMimeTypes));
+ toDataURLImageFormatHistogram.count(imageFormat);
+ } else if (encodeReason == EncodeReasonToBlobCallback) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toBlobCallbackImageFormatHistogram, new EnumerationHistogram("Canvas.RequestedImageMimeTypes_toBlobCallback", NumberOfRequestedImageMimeTypes));
+ toBlobCallbackImageFormatHistogram.count(imageFormat);
+ }
// FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread).
- if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(lowercaseMimeType))
+ if (!MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(lowercaseMimeType))
lowercaseMimeType = DefaultMimeType;
-
return lowercaseMimeType;
}
@@ -554,7 +595,7 @@ String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
if (!isPaintable())
return String("data:,");
- String encodingMimeType = toEncodingMimeType(mimeType);
+ String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToDataURL);
ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL);
ScopedDisposal<ImageData> disposer(imageData);
@@ -599,7 +640,7 @@ void HTMLCanvasElement::toBlob(BlobCallback* callback, const String& mimeType, c
}
}
- String encodingMimeType = toEncodingMimeType(mimeType);
+ String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToBlobCallback);
ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob);
// imageData unref its data, which we still keep alive for the async toBlob thread
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLCanvasElement.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698