Bug 1706355 - Move recording new download to telemetry from DownloadsCommon to DownloadsList for more accurate download count r=Gijs,mak

Differential Revision: https://phabricator.services.mozilla.com/D115806
This commit is contained in:
Ava Katushka 2021-05-27 10:53:35 +00:00
parent d9f27f416f
commit 96ac53de7f
3 changed files with 152 additions and 150 deletions

View File

@ -80,140 +80,12 @@ const kMaxHistoryResultsForLimitedView = 42;
const kPrefBranch = Services.prefs.getBranch("browser.download.");
const kFileExtensions = [
"aac",
"adt",
"adts",
"accdb",
"accde",
"accdr",
"accdt",
"aif",
"aifc",
"aiff",
"apng",
"aspx",
"avi",
"avif",
"bat",
"bin",
"bmp",
"cab",
"cda",
"csv",
"dif",
"dll",
"doc",
"docm",
"docx",
"dot",
"dotx",
"eml",
"eps",
"exe",
"flac",
"flv",
"gif",
"htm",
"html",
"ico",
"ini",
"iso",
"jar",
"jfif",
"jpg",
"jpeg",
"json",
"m4a",
"mdb",
"mid",
"midi",
"mov",
"mp3",
"mp4",
"mpeg",
"mpg",
"msi",
"mui",
"oga",
"ogg",
"ogv",
"opus",
"pdf",
"pjpeg",
"pjp",
"png",
"pot",
"potm",
"potx",
"ppam",
"pps",
"ppsm",
"ppsx",
"ppt",
"pptm",
"pptx",
"psd",
"pst",
"pub",
"rar",
"rdf",
"rtf",
"shtml",
"sldm",
"sldx",
"svg",
"swf",
"sys",
"tif",
"tiff",
"tmp",
"txt",
"vob",
"vsd",
"vsdm",
"vsdx",
"vss",
"vssm",
"vst",
"vstm",
"vstx",
"wav",
"wbk",
"webm",
"webp",
"wks",
"wma",
"wmd",
"wmv",
"wmz",
"wms",
"wpd",
"wp5",
"xht",
"xhtml",
"xla",
"xlam",
"xll",
"xlm",
"xls",
"xlsm",
"xlsx",
"xlt",
"xltm",
"xltx",
"xml",
"zip",
];
const kGenericContentTypes = [
"application/octet-stream",
"binary/octet-stream",
"application/unknown",
];
const TELEMETRY_EVENT_CATEGORY = "downloads";
var PrefObserver = {
QueryInterface: ChromeUtils.generateQI([
"nsIObserver",
@ -953,26 +825,6 @@ DownloadsDataCtor.prototype = {
// Integration with the asynchronous Downloads back-end
onDownloadAdded(download) {
let extension = download.target.path.split(".").pop();
if (!kFileExtensions.includes(extension)) {
extension = "other";
}
try {
Services.telemetry.recordEvent(
TELEMETRY_EVENT_CATEGORY,
"added",
"fileExtension",
extension,
{}
);
} catch (ex) {
Cu.reportError(
"DownloadsCommon: error recording telemetry event. " + ex.message
);
}
// Download objects do not store the end time of downloads, as the Downloads
// API does not need to persist this information for all platforms. Once a
// download terminates on a Desktop browser, it becomes a history download,

View File

@ -14,6 +14,136 @@ var EXPORTED_SYMBOLS = [
"DownloadSummary",
];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const kFileExtensions = [
"aac",
"adt",
"adts",
"accdb",
"accde",
"accdr",
"accdt",
"aif",
"aifc",
"aiff",
"apng",
"aspx",
"avi",
"avif",
"bat",
"bin",
"bmp",
"cab",
"cda",
"csv",
"dif",
"dll",
"doc",
"docm",
"docx",
"dot",
"dotx",
"eml",
"eps",
"exe",
"flac",
"flv",
"gif",
"htm",
"html",
"ico",
"ini",
"iso",
"jar",
"jfif",
"jpg",
"jpeg",
"json",
"m4a",
"mdb",
"mid",
"midi",
"mov",
"mp3",
"mp4",
"mpeg",
"mpg",
"msi",
"mui",
"oga",
"ogg",
"ogv",
"opus",
"pdf",
"pjpeg",
"pjp",
"png",
"pot",
"potm",
"potx",
"ppam",
"pps",
"ppsm",
"ppsx",
"ppt",
"pptm",
"pptx",
"psd",
"pst",
"pub",
"rar",
"rdf",
"rtf",
"shtml",
"sldm",
"sldx",
"svg",
"swf",
"sys",
"tif",
"tiff",
"tmp",
"txt",
"vob",
"vsd",
"vsdm",
"vsdx",
"vss",
"vssm",
"vst",
"vstm",
"vstx",
"wav",
"wbk",
"webm",
"webp",
"wks",
"wma",
"wmd",
"wmv",
"wmz",
"wms",
"wpd",
"wp5",
"xht",
"xhtml",
"xla",
"xlam",
"xll",
"xlm",
"xls",
"xlsm",
"xlsx",
"xlt",
"xltm",
"xltx",
"xml",
"zip",
];
const TELEMETRY_EVENT_CATEGORY = "downloads";
/**
* Represents a collection of Download objects that can be viewed and managed by
* the user interface, and persisted across sessions.
@ -294,6 +424,26 @@ DownloadCombinedList.prototype = {
* @rejects JavaScript exception.
*/
add(aDownload) {
let extension = aDownload.target.path.split(".").pop();
if (!kFileExtensions.includes(extension)) {
extension = "other";
}
try {
Services.telemetry.recordEvent(
TELEMETRY_EVENT_CATEGORY,
"added",
"fileExtension",
extension,
{}
);
} catch (ex) {
Cu.reportError(
"DownloadsCommon: error recording telemetry event. " + ex.message
);
}
if (aDownload.source.isPrivate) {
return this._privateList.add(aDownload);
}

View File

@ -427,10 +427,10 @@ blocklist:
downloads:
added:
description: >
Sent when downloading a new file. Possible values are in contained in DownloadsCommon::kFileExtensions.
Sent when downloading a new file. Possible values are in contained in DownloadList::kFileExtensions.
All other downloads not in the listare marked as other.
objects: ["fileExtension"]
bug_numbers: [1627676]
bug_numbers: [1627676, 1706355]
notification_emails: ["rtestard@mozilla.com", "emalysz@mozilla.com"]
products:
- "firefox"