Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 25b5f25

Browse files
committed
Bug 1703578 - Part 4: Record setAsDefaultUserChoice() result telemetry. r=bytesized
Depends on D113428 Differential Revision: https://phabricator.services.mozilla.com/D113429
1 parent 00133ca commit 25b5f25

2 files changed

Lines changed: 66 additions & 25 deletions

File tree

browser/components/shell/ShellService.jsm

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,36 +145,65 @@ let ShellServiceInternal = {
145145
// quarrantine any program that writes UserChoice, though this has not
146146
// occurred during extensive testing.
147147

148-
if (!ShellService.checkAllProgIDsExist()) {
149-
throw new Error("checkAllProgIDsExist() failed");
150-
}
151-
152-
if (!ShellService.checkBrowserUserChoiceHashes()) {
153-
throw new Error("checkBrowserUserChoiceHashes() failed");
154-
}
148+
let telemetryResult = "ErrOther";
155149

156-
const wdba = Services.dirsvc.get("XREExeF", Ci.nsIFile);
157-
wdba.leafName = "default-browser-agent.exe";
158-
const aumi = XreDirProvider.getInstallHash();
150+
try {
151+
if (!ShellService.checkAllProgIDsExist()) {
152+
telemetryResult = "ErrProgID";
153+
throw new Error("checkAllProgIDsExist() failed");
154+
}
159155

160-
const exeProcess = await Subprocess.call({
161-
command: wdba.path,
162-
arguments: ["set-default-browser-user-choice", aumi],
163-
});
156+
if (!ShellService.checkBrowserUserChoiceHashes()) {
157+
telemetryResult = "ErrHash";
158+
throw new Error("checkBrowserUserChoiceHashes() failed");
159+
}
164160

165-
// exit codes
166-
const S_OK = 0;
167-
const STILL_ACTIVE = 0x103;
161+
const wdba = Services.dirsvc.get("XREExeF", Ci.nsIFile);
162+
wdba.leafName = "default-browser-agent.exe";
163+
const aumi = XreDirProvider.getInstallHash();
168164

169-
const exeWaitTimeoutMs = 2000; // 2 seconds
170-
const exeWaitPromise = exeProcess.wait();
171-
const timeoutPromise = new Promise(function(resolve, reject) {
172-
setTimeout(() => resolve({ exitCode: STILL_ACTIVE }), exeWaitTimeoutMs);
173-
});
174-
const { exitCode } = await Promise.race([exeWaitPromise, timeoutPromise]);
165+
telemetryResult = "ErrLaunchExe";
166+
const exeProcess = await Subprocess.call({
167+
command: wdba.path,
168+
arguments: ["set-default-browser-user-choice", aumi],
169+
});
170+
telemetryResult = "ErrOther";
171+
172+
// Exit codes, see toolkit/mozapps/defaultagent/SetDefaultBrowser.h
173+
const S_OK = 0;
174+
const STILL_ACTIVE = 0x103;
175+
const MOZ_E_NO_PROGID = 0xa0000001;
176+
const MOZ_E_HASH_CHECK = 0xa0000002;
177+
const MOZ_E_REJECTED = 0xa0000003;
178+
179+
const exeWaitTimeoutMs = 2000; // 2 seconds
180+
const exeWaitPromise = exeProcess.wait();
181+
const timeoutPromise = new Promise(function(resolve, reject) {
182+
setTimeout(() => resolve({ exitCode: STILL_ACTIVE }), exeWaitTimeoutMs);
183+
});
184+
const { exitCode } = await Promise.race([exeWaitPromise, timeoutPromise]);
185+
186+
if (exitCode != S_OK) {
187+
telemetryResult =
188+
new Map([
189+
[STILL_ACTIVE, "ErrExeTimeout"],
190+
[MOZ_E_NO_PROGID, "ErrExeProgID"],
191+
[MOZ_E_HASH_CHECK, "ErrExeHash"],
192+
[MOZ_E_REJECTED, "ErrExeRejected"],
193+
]).get(exitCode) ?? "ErrExeOther";
194+
throw new Error(
195+
`WDBA nonzero exit code ${exitCode}: ${telemetryResult}`
196+
);
197+
}
175198

176-
if (exitCode != S_OK) {
177-
throw new Error(`WDBA nonzero exit code ${exitCode}`);
199+
telemetryResult = "Success";
200+
} finally {
201+
try {
202+
const histogram = Services.telemetry.getHistogramById(
203+
"BROWSER_SET_DEFAULT_USER_CHOICE_RESULT"
204+
);
205+
histogram.add(telemetryResult);
206+
} catch (ex) {}
178207
}
179208
},
180209

toolkit/components/telemetry/Histograms.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11826,6 +11826,18 @@
1182611826
"releaseChannelCollection": "opt-out",
1182711827
"description": "True if the browser was unable to set Firefox as the default browser"
1182811828
},
11829+
"BROWSER_SET_DEFAULT_USER_CHOICE_RESULT": {
11830+
"record_in_processes": ["main"],
11831+
"products": ["firefox"],
11832+
"operating_systems": ["windows"],
11833+
"expires_in_version": "96",
11834+
"kind": "categorical",
11835+
"labels": ["Success", "ErrProgID", "ErrHash", "ErrLaunchExe", "ErrExeTimeout", "ErrExeProgID", "ErrExeHash", "ErrExeRejected", "ErrExeOther", "ErrOther"],
11836+
"releaseChannelCollection": "opt-out",
11837+
"bug_numbers": [1703578],
11838+
"alert_emails": ["application-update-telemetry-alerts@mozilla.com", "agashlin@mozilla.com"],
11839+
"description": "Result of each attempt to set the default browser with SetDefaultBrowserUserChoice()"
11840+
},
1182911841
"BROWSER_IS_ASSIST_DEFAULT": {
1183011842
"record_in_processes": ["main"],
1183111843
"products": ["firefox", "fennec"],

0 commit comments

Comments
 (0)