Bug 1703578 - Part 4: Record setAsDefaultUserChoice() result telemetry. r=bytesized
authorAdam Gashlin <agashlin@mozilla.com>
Thu, 17 Jun 2021 18:06:35 +0000
changeset 583758 fe2b9abdb53bf6d24ea184ebcb77350f38ea8405
parent 583757 91f7b8dc86708e694233f5ddbd2c4213febf90fb
child 583759 8bcf35827a03386d64e4b89b5b3136bb848b77fe
push id145231
push useragashlin@mozilla.com
push dateThu, 17 Jun 2021 20:30:21 +0000
treeherderautoland@fe2b9abdb53b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbytesized
bugs1703578
milestone91.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1703578 - Part 4: Record setAsDefaultUserChoice() result telemetry. r=bytesized Depends on D113428 Differential Revision: https://phabricator.services.mozilla.com/D113429
browser/components/shell/ShellService.jsm
toolkit/components/telemetry/Histograms.json
--- a/browser/components/shell/ShellService.jsm
+++ b/browser/components/shell/ShellService.jsm
@@ -140,46 +140,75 @@ let ShellServiceInternal = {
 
     // We launch the WDBA to handle the registry writes, see
     // SetDefaultBrowserUserChoice() in
     // toolkit/mozapps/defaultagent/SetDefaultBrowser.cpp.
     // This is external in case an overzealous antimalware product decides to
     // quarrantine any program that writes UserChoice, though this has not
     // occurred during extensive testing.
 
-    if (!ShellService.checkAllProgIDsExist()) {
-      throw new Error("checkAllProgIDsExist() failed");
-    }
+    let telemetryResult = "ErrOther";
+
+    try {
+      if (!ShellService.checkAllProgIDsExist()) {
+        telemetryResult = "ErrProgID";
+        throw new Error("checkAllProgIDsExist() failed");
+      }
 
-    if (!ShellService.checkBrowserUserChoiceHashes()) {
-      throw new Error("checkBrowserUserChoiceHashes() failed");
-    }
+      if (!ShellService.checkBrowserUserChoiceHashes()) {
+        telemetryResult = "ErrHash";
+        throw new Error("checkBrowserUserChoiceHashes() failed");
+      }
 
-    const wdba = Services.dirsvc.get("XREExeF", Ci.nsIFile);
-    wdba.leafName = "default-browser-agent.exe";
-    const aumi = XreDirProvider.getInstallHash();
+      const wdba = Services.dirsvc.get("XREExeF", Ci.nsIFile);
+      wdba.leafName = "default-browser-agent.exe";
+      const aumi = XreDirProvider.getInstallHash();
+
+      telemetryResult = "ErrLaunchExe";
+      const exeProcess = await Subprocess.call({
+        command: wdba.path,
+        arguments: ["set-default-browser-user-choice", aumi],
+      });
+      telemetryResult = "ErrOther";
 
-    const exeProcess = await Subprocess.call({
-      command: wdba.path,
-      arguments: ["set-default-browser-user-choice", aumi],
-    });
+      // Exit codes, see toolkit/mozapps/defaultagent/SetDefaultBrowser.h
+      const S_OK = 0;
+      const STILL_ACTIVE = 0x103;
+      const MOZ_E_NO_PROGID = 0xa0000001;
+      const MOZ_E_HASH_CHECK = 0xa0000002;
+      const MOZ_E_REJECTED = 0xa0000003;
 
-    // exit codes
-    const S_OK = 0;
-    const STILL_ACTIVE = 0x103;
+      const exeWaitTimeoutMs = 2000; // 2 seconds
+      const exeWaitPromise = exeProcess.wait();
+      const timeoutPromise = new Promise(function(resolve, reject) {
+        setTimeout(() => resolve({ exitCode: STILL_ACTIVE }), exeWaitTimeoutMs);
+      });
+      const { exitCode } = await Promise.race([exeWaitPromise, timeoutPromise]);
 
-    const exeWaitTimeoutMs = 2000; // 2 seconds
-    const exeWaitPromise = exeProcess.wait();
-    const timeoutPromise = new Promise(function(resolve, reject) {
-      setTimeout(() => resolve({ exitCode: STILL_ACTIVE }), exeWaitTimeoutMs);
-    });
-    const { exitCode } = await Promise.race([exeWaitPromise, timeoutPromise]);
+      if (exitCode != S_OK) {
+        telemetryResult =
+          new Map([
+            [STILL_ACTIVE, "ErrExeTimeout"],
+            [MOZ_E_NO_PROGID, "ErrExeProgID"],
+            [MOZ_E_HASH_CHECK, "ErrExeHash"],
+            [MOZ_E_REJECTED, "ErrExeRejected"],
+          ]).get(exitCode) ?? "ErrExeOther";
+        throw new Error(
+          `WDBA nonzero exit code ${exitCode}: ${telemetryResult}`
+        );
+      }
 
-    if (exitCode != S_OK) {
-      throw new Error(`WDBA nonzero exit code ${exitCode}`);
+      telemetryResult = "Success";
+    } finally {
+      try {
+        const histogram = Services.telemetry.getHistogramById(
+          "BROWSER_SET_DEFAULT_USER_CHOICE_RESULT"
+        );
+        histogram.add(telemetryResult);
+      } catch (ex) {}
     }
   },
 
   // override nsIShellService.setDefaultBrowser() on the ShellService proxy.
   setDefaultBrowser(claimAllTypes, forAllUsers) {
     // On Windows 10, our best chance is to set UserChoice, so try that first.
     if (
       AppConstants.isPlatformAndVersionAtLeast("win", "10") &&
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -11821,16 +11821,28 @@
   "BROWSER_SET_DEFAULT_ERROR": {
     "record_in_processes": ["main"],
     "products": ["firefox", "fennec"],
     "expires_in_version": "never",
     "kind": "boolean",
     "releaseChannelCollection": "opt-out",
     "description": "True if the browser was unable to set Firefox as the default browser"
   },
+  "BROWSER_SET_DEFAULT_USER_CHOICE_RESULT": {
+    "record_in_processes": ["main"],
+    "products": ["firefox"],
+    "operating_systems": ["windows"],
+    "expires_in_version": "96",
+    "kind": "categorical",
+    "labels": ["Success", "ErrProgID", "ErrHash", "ErrLaunchExe", "ErrExeTimeout", "ErrExeProgID", "ErrExeHash", "ErrExeRejected", "ErrExeOther", "ErrOther"],
+    "releaseChannelCollection": "opt-out",
+    "bug_numbers": [1703578],
+    "alert_emails": ["application-update-telemetry-alerts@mozilla.com", "agashlin@mozilla.com"],
+    "description": "Result of each attempt to set the default browser with SetDefaultBrowserUserChoice()"
+  },
   "BROWSER_IS_ASSIST_DEFAULT": {
     "record_in_processes": ["main"],
     "products": ["firefox", "fennec"],
     "expires_in_version": "never",
     "kind": "boolean",
     "description": "The result of the default browser check for assist intent."
   },
   "BROWSER_ATTRIBUTION_ERRORS": {