Bug 1481447 - Switch search logging to a lazy pref. r=florian
authorMichael Kaply <mozilla@kaply.com>
Wed, 15 Aug 2018 05:34:18 +0000
changeset 486682 5f016db599045a909accd50f942afb96e740790c
parent 486681 7f9ad37449b67138ff06a5ebe04076844c0011c8
child 486683 27bd852b023ea5ee93af47e434c90a9518fc3d87
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1481447
milestone63.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 1481447 - Switch search logging to a lazy pref. r=florian Differential Revision: https://phabricator.services.mozilla.com/D2892
browser/base/content/test/performance/browser_preferences_usage.js
toolkit/components/search/nsSearchService.js
--- a/browser/base/content/test/performance/browser_preferences_usage.js
+++ b/browser/base/content/test/performance/browser_preferences_usage.js
@@ -76,20 +76,16 @@ add_task(async function startup() {
     "browser.startup.record": {
       min: 200,
       max: 350,
     },
     "layout.css.prefixes.webkit": {
       min: 135,
       max: 170,
     },
-    "browser.search.log": {
-      min: 100,
-      max: 214,
-    },
     "layout.css.dpi": {
       min: 45,
       max: 75,
     },
     "network.loadinfo.skip_type_assertion": {
       max: 658,
     },
     "extensions.getAddons.cache.enabled": {
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -23,16 +23,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
 XPCOMUtils.defineLazyServiceGetters(this, {
   gEnvironment: ["@mozilla.org/process/environment;1", "nsIEnvironment"],
   gChromeReg: ["@mozilla.org/chrome/chrome-registry;1", "nsIChromeRegistry"],
 });
 
 const BROWSER_SEARCH_PREF = "browser.search.";
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "resetStatus", BROWSER_SEARCH_PREF + "reset.status", "");
+XPCOMUtils.defineLazyPreferenceGetter(this, "loggingEnabled", BROWSER_SEARCH_PREF + "log", false);
 XPCOMUtils.defineLazyGetter(this, "resetEnabled", () => {
   return Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF).getBoolPref("reset.enabled");
 });
 // Can't use defineLazyPreferenceGetter because we want the value
 // from the default branch
 XPCOMUtils.defineLazyGetter(this, "distroID", () => {
   return Services.prefs.getDefaultBranch("distribution.").getCharPref("id", "");
 });
@@ -190,35 +191,21 @@ const SEARCH_GEO_DEFAULT_UPDATE_INTERVAL
 /**
  * Prefixed to all search debug output.
  */
 const SEARCH_LOG_PREFIX = "*** Search: ";
 
 /**
  * Outputs aText to the JavaScript console as well as to stdout.
  */
-function DO_LOG(aText) {
-  dump(SEARCH_LOG_PREFIX + aText + "\n");
-  Services.console.logStringMessage(aText);
-}
-
-/**
- * In debug builds, use a live, pref-based (browser.search.log) LOG function
- * to allow enabling/disabling without a restart. Otherwise, don't log at all by
- * default. This can be overridden at startup by the pref, see SearchService's
- * _init method.
- */
-var LOG = function() {};
-
-if (AppConstants.DEBUG) {
-  LOG = function(aText) {
-    if (getBoolPref(BROWSER_SEARCH_PREF + "log", false)) {
-      DO_LOG(aText);
-    }
-  };
+function LOG(aText) {
+  if (loggingEnabled) {
+    dump(SEARCH_LOG_PREFIX + aText + "\n");
+    Services.console.logStringMessage(aText);
+  }
 }
 
 /**
  * Presents an assertion dialog in non-release builds and throws.
  * @param  message
  *         A message to display
  * @param  resultCode
  *         The NS_ERROR_* value to throw.
@@ -2573,20 +2560,16 @@ function checkForSyncCompletion(aPromise
                                  Cr.NS_ERROR_ALREADY_INITIALIZED);
     }
     return aValue;
   });
 }
 
 // nsIBrowserSearchService
 function SearchService() {
-  // Replace empty LOG function with the useful one if the log pref is set.
-  if (getBoolPref(BROWSER_SEARCH_PREF + "log", false))
-    LOG = DO_LOG;
-
   this._initObservers = PromiseUtils.defer();
 }
 
 SearchService.prototype = {
   classID: Components.ID("{7319788a-fe93-4db3-9f39-818cf08f4256}"),
 
   // The current status of initialization. Note that it does not determine if
   // initialization is complete, only if an error has been encountered so far.