@@ -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
0 commit comments