From 2b65729455a8b2490f39c0f1f53419b98537e287 Mon Sep 17 00:00:00 2001 From: Felipe Gomes Date: Wed, 9 Aug 2017 15:06:30 -0300 Subject: [PATCH] Bug 1388145 - Move the default browser check to an idle callback. r=florian Note that the DefaultBrowserCheck.prompt() was scheduled with an idle callback before and it was removed here, because it's no longer necessary (as the entire function is now running from an idle callback) MozReview-Commit-ID: GQQbAlBn2UI --HG-- extra : rebase_source : e317326c3dc4a47f87ba86b29dc3dbdec2657f33 --- browser/components/nsBrowserGlue.js | 156 +++++++++++++++------------- 1 file changed, 81 insertions(+), 75 deletions(-) diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 2f6066099b99..9a2cece83b99 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -1104,81 +1104,6 @@ BrowserGlue.prototype = { this._notifyDisabledNonMpc(); } - // Perform default browser checking. - if (ShellService) { - let shouldCheck = AppConstants.DEBUG ? false : - ShellService.shouldCheckDefaultBrowser; - - const skipDefaultBrowserCheck = - Services.prefs.getBoolPref("browser.shell.skipDefaultBrowserCheckOnFirstRun") && - !Services.prefs.getBoolPref("browser.shell.didSkipDefaultBrowserCheckOnFirstRun"); - - const usePromptLimit = !AppConstants.RELEASE_OR_BETA; - let promptCount = - usePromptLimit ? Services.prefs.getIntPref("browser.shell.defaultBrowserCheckCount") : 0; - - let willRecoverSession = false; - try { - let ss = Cc["@mozilla.org/browser/sessionstartup;1"]. - getService(Ci.nsISessionStartup); - willRecoverSession = - (ss.sessionType == Ci.nsISessionStartup.RECOVER_SESSION); - } catch (ex) { /* never mind; suppose SessionStore is broken */ } - - // startup check, check all assoc - let isDefault = false; - let isDefaultError = false; - try { - isDefault = ShellService.isDefaultBrowser(true, false); - } catch (ex) { - isDefaultError = true; - } - - if (isDefault) { - let now = (Math.floor(Date.now() / 1000)).toString(); - Services.prefs.setCharPref("browser.shell.mostRecentDateSetAsDefault", now); - } - - let willPrompt = shouldCheck && !isDefault && !willRecoverSession; - - // Skip the "Set Default Browser" check during first-run or after the - // browser has been run a few times. - if (willPrompt) { - if (skipDefaultBrowserCheck) { - Services.prefs.setBoolPref("browser.shell.didSkipDefaultBrowserCheckOnFirstRun", true); - willPrompt = false; - } else { - promptCount++; - } - if (usePromptLimit && promptCount > 3) { - willPrompt = false; - } - } - - if (usePromptLimit && willPrompt) { - Services.prefs.setIntPref("browser.shell.defaultBrowserCheckCount", promptCount); - } - - try { - // Report default browser status on startup to telemetry - // so we can track whether we are the default. - Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT") - .add(isDefault); - Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT_ERROR") - .add(isDefaultError); - Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_ALWAYS_CHECK") - .add(shouldCheck); - Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_DIALOG_PROMPT_RAWCOUNT") - .add(promptCount); - } catch (ex) { /* Don't break the default prompt if telemetry is broken. */ } - - if (willPrompt) { - Services.tm.dispatchToMainThread(function() { - DefaultBrowserCheck.prompt(RecentWindow.getMostRecentBrowserWindow()); - }); - } - } - if (AppConstants.MOZ_CRASHREPORTER) { UnsubmittedCrashHandler.init(); Services.tm.idleDispatchToMainThread(function() { @@ -1233,6 +1158,10 @@ BrowserGlue.prototype = { Services.tm.idleDispatchToMainThread(() => { SafeBrowsing.init(); }, 5000); + + Services.tm.idleDispatchToMainThread(() => { + this._checkForDefaultBrowser(); + }); }, /** @@ -2163,6 +2092,83 @@ BrowserGlue.prototype = { Services.prefs.setIntPref("browser.migration.version", UI_VERSION); }, + _checkForDefaultBrowser() { + // Perform default browser checking. + if (!ShellService) { + return; + } + + let shouldCheck = AppConstants.DEBUG ? false : + ShellService.shouldCheckDefaultBrowser; + + const skipDefaultBrowserCheck = + Services.prefs.getBoolPref("browser.shell.skipDefaultBrowserCheckOnFirstRun") && + !Services.prefs.getBoolPref("browser.shell.didSkipDefaultBrowserCheckOnFirstRun"); + + const usePromptLimit = !AppConstants.RELEASE_OR_BETA; + let promptCount = + usePromptLimit ? Services.prefs.getIntPref("browser.shell.defaultBrowserCheckCount") : 0; + + let willRecoverSession = false; + try { + let ss = Cc["@mozilla.org/browser/sessionstartup;1"]. + getService(Ci.nsISessionStartup); + willRecoverSession = + (ss.sessionType == Ci.nsISessionStartup.RECOVER_SESSION); + } catch (ex) { /* never mind; suppose SessionStore is broken */ } + + // startup check, check all assoc + let isDefault = false; + let isDefaultError = false; + try { + isDefault = ShellService.isDefaultBrowser(true, false); + } catch (ex) { + isDefaultError = true; + } + + if (isDefault) { + let now = (Math.floor(Date.now() / 1000)).toString(); + Services.prefs.setCharPref("browser.shell.mostRecentDateSetAsDefault", now); + } + + let willPrompt = shouldCheck && !isDefault && !willRecoverSession; + + // Skip the "Set Default Browser" check during first-run or after the + // browser has been run a few times. + if (willPrompt) { + if (skipDefaultBrowserCheck) { + Services.prefs.setBoolPref("browser.shell.didSkipDefaultBrowserCheckOnFirstRun", true); + willPrompt = false; + } else { + promptCount++; + } + if (usePromptLimit && promptCount > 3) { + willPrompt = false; + } + } + + if (usePromptLimit && willPrompt) { + Services.prefs.setIntPref("browser.shell.defaultBrowserCheckCount", promptCount); + } + + try { + // Report default browser status on startup to telemetry + // so we can track whether we are the default. + Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT") + .add(isDefault); + Services.telemetry.getHistogramById("BROWSER_IS_USER_DEFAULT_ERROR") + .add(isDefaultError); + Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_ALWAYS_CHECK") + .add(shouldCheck); + Services.telemetry.getHistogramById("BROWSER_SET_DEFAULT_DIALOG_PROMPT_RAWCOUNT") + .add(promptCount); + } catch (ex) { /* Don't break the default prompt if telemetry is broken. */ } + + if (willPrompt) { + DefaultBrowserCheck.prompt(RecentWindow.getMostRecentBrowserWindow()); + } + }, + // ------------------------------ // public nsIBrowserGlue members // ------------------------------