Bug 1556424 - Dont await init() on init() installed engines. r=Standard8 a=jcristau
authorDale Harvey <dale@arandomurl.com>
Tue, 04 Jun 2019 16:44:29 +0000
changeset 536828 f2aa60a336fa6dfcec12da4e2e132c34d3973fb4
parent 536827 52554b40948e17eb3b72a8c742c907fb225a47d7
child 536829 e94a4d5cd811f4b766af8ba4970452bab29b3f4c
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, jcristau
bugs1556424
milestone68.0
Bug 1556424 - Dont await init() on init() installed engines. r=Standard8 a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D33577
toolkit/components/search/SearchService.jsm
--- a/toolkit/components/search/SearchService.jsm
+++ b/toolkit/components/search/SearchService.jsm
@@ -915,17 +915,17 @@ SearchService.prototype = {
       let engineList = this._enginesToLocales(engines);
       for (let [id, locales] of engineList) {
         await this.ensureBuiltinExtension(id, locales);
       }
 
       SearchUtils.log("_loadEngines: loading " +
         this._startupExtensions.size + " engines reported by AddonManager startup");
       for (let extension of this._startupExtensions) {
-        await this._installExtensionEngine(extension, [DEFAULT_TAG]);
+        await this._installExtensionEngine(extension, [DEFAULT_TAG], true);
       }
     }
 
     SearchUtils.log("_loadEngines: loading user-installed engines from the obsolete cache");
     this._loadEnginesFromCache(cache, true);
 
     this._loadEnginesMetadataFromCache(cache);
 
@@ -1108,16 +1108,17 @@ SearchService.prototype = {
     })();
   },
 
   /**
    * Reset SearchService data.
    */
   reset() {
     gInitialized = false;
+    this._initObservers = PromiseUtils.defer();
     this._initStarted = this.__sortedEngines =
       this._currentEngine = this._searchDefault = null;
     this._startupExtensions = new Set();
     this._engines = {};
     this._visibleDefaultEngines = [];
     this._searchOrder = [];
     this._metaData = {};
   },
@@ -1846,17 +1847,17 @@ SearchService.prototype = {
         extensionID,
       };
     }
 
     let isBuiltin = !!params.isBuiltin;
     // We install search extensions during the init phase, both built in
     // web extensions freshly installed (via addEnginesFromExtension) or
     // user installed extensions being reenabled calling this directly.
-    if (!gInitialized && !isBuiltin) {
+    if (!gInitialized && !isBuiltin && !params.initEngine) {
       await this.init(true);
     }
     if (!name)
       SearchUtils.fail("Invalid name passed to addEngineWithDetails!");
     if (!params.template)
       SearchUtils.fail("Invalid template passed to addEngineWithDetails!");
     let existingEngine = this._engines[name];
     if (existingEngine) {
@@ -1898,35 +1899,37 @@ SearchService.prototype = {
     // to install in SearchService.init().
     if (!gInitialized) {
       this._startupExtensions.add(extension);
       return [];
     }
     return this._installExtensionEngine(extension, [DEFAULT_TAG]);
   },
 
-  async _installExtensionEngine(extension, locales) {
+  async _installExtensionEngine(extension, locales, initEngine) {
     SearchUtils.log("installExtensionEngine: " + extension.id);
 
     let installLocale = async (locale) => {
       let manifest = (locale === DEFAULT_TAG) ? extension.manifest :
         (await extension.getLocalizedManifest(locale));
-      return this._addEngineForManifest(extension, manifest, locale);
+      return this._addEngineForManifest(extension, manifest, locale, initEngine);
     };
 
     let engines = [];
     for (let locale of locales) {
       SearchUtils.log("addEnginesFromExtension: installing locale: " +
         extension.id + ":" + locale);
       engines.push(await installLocale(locale));
     }
     return engines;
   },
 
-  async _addEngineForManifest(extension, manifest, locale = DEFAULT_TAG) {
+  async _addEngineForManifest(extension, manifest,
+                              locale = DEFAULT_TAG,
+                              initEngine = false) {
     let {IconDetails} = ExtensionParent;
 
     // General set of icons for an engine.
     let icons = extension.manifest.icons;
     let iconList = [];
     if (icons) {
       iconList = Object.entries(icons).map(icon => {
         return {width: icon[0], height: icon[0],
@@ -1966,16 +1969,17 @@ SearchService.prototype = {
       extensionID: extension.id,
       isBuiltin: extension.addonData.builtIn,
       // suggest_url doesn't currently get encoded.
       suggestURL: searchProvider.suggest_url,
       suggestPostParams: searchProvider.suggest_url_post_params,
       suggestGetParams: searchProvider.suggest_url_get_params,
       queryCharset: searchProvider.encoding || "UTF-8",
       mozParams: searchProvider.params,
+      initEngine,
     };
 
     return this.addEngineWithDetails(params.name, params);
   },
 
   async addEngine(engineURL, iconURL, confirm, extensionID) {
     SearchUtils.log("addEngine: Adding \"" + engineURL + "\".");
     await this.init(true);