Bug 1532730 - Update engines on reload. r=mikedeboer a=pascalc
authorDale Harvey <dale@arandomurl.com>
Thu, 28 Mar 2019 16:32:41 +0000
changeset 525960 3dc7b1a572313386a459b174e7335847e3c1dbb2
parent 525959 864e16abd2f73a5a0d0ef7a887a3a90e0ee22a37
child 525961 985158cfb6950e416e0d4664e1aa9aad83c923ab
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer, pascalc
bugs1532730
milestone67.0
Bug 1532730 - Update engines on reload. r=mikedeboer a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D24192
toolkit/components/search/SearchService.jsm
--- a/toolkit/components/search/SearchService.jsm
+++ b/toolkit/components/search/SearchService.jsm
@@ -2746,17 +2746,17 @@ SearchService.prototype = {
   },
 
   /**
    * Loads engines asynchronously.
    *
    * @returns {Promise} A promise, resolved successfully if loading data
    * succeeds.
    */
-  async _loadEngines(cache) {
+  async _loadEngines(cache, isReload) {
     LOG("_loadEngines: start");
     Services.obs.notifyObservers(null, SEARCH_SERVICE_TOPIC, "find-jar-engines");
     let chromeURIs = await this._findJAREngines();
 
     // Get the non-empty distribution directories into distDirs...
     let distDirs = [];
     let locations;
     try {
@@ -2803,17 +2803,17 @@ SearchService.prototype = {
       LOG("_loadEngines: No valid engines found in cache. Loading engines from disk.");
     }
 
     LOG("_loadEngines: Absent or outdated cache. Loading engines from disk.");
     for (let loadDir of distDirs) {
       let enginesFromDir = await this._loadEnginesFromDir(loadDir);
       enginesFromDir.forEach(this._addEngineToStore, this);
     }
-    let enginesFromURLs = await this._loadFromChromeURLs(chromeURIs);
+    let enginesFromURLs = await this._loadFromChromeURLs(chromeURIs, isReload);
     enginesFromURLs.forEach(this._addEngineToStore, this);
 
     LOG("_loadEngines: loading user-installed engines from the obsolete cache");
     this._loadEnginesFromCache(cache, true);
 
     this._loadEnginesMetadataFromCache(cache);
 
     LOG("_loadEngines: done using rebuilt cache");
@@ -2837,17 +2837,17 @@ SearchService.prototype = {
       let task = this._batchTask;
       this._batchTask = null;
       await task.finalize();
     }
     // Capture the current engine state, in case we need to notify below.
     let prevCurrentEngine = this._currentEngine;
     this._currentEngine = null;
 
-    await this._loadEngines(await this._readCacheFile());
+    await this._loadEngines(await this._readCacheFile(), true);
     // Make sure the current list of engines is persisted.
     await this._buildCache();
 
     // If the defaultEngine has changed between the previous load and this one,
     // dispatch the appropriate notifications.
     if (prevCurrentEngine && this.defaultEngine !== prevCurrentEngine) {
       notifyAction(this._currentEngine, SEARCH_ENGINE_DEFAULT);
       notifyAction(this._currentEngine, SEARCH_ENGINE_CURRENT);
@@ -3142,28 +3142,35 @@ SearchService.prototype = {
     }
     return engines;
   },
 
   /**
    * Loads engines from Chrome URLs asynchronously.
    *
    * @param aURLs a list of URLs.
+   * @param isReload is being called from maybeReloadEngines.
    *
    * @returns {Promise} A promise, resolved successfully if loading data
    * succeeds.
    */
-  async _loadFromChromeURLs(aURLs) {
+  async _loadFromChromeURLs(aURLs, isReload = false) {
     let engines = [];
     for (let url of aURLs) {
       try {
         LOG("_loadFromChromeURLs: loading engine from chrome url: " + url);
         let uri = Services.io.newURI(url);
         let engine = new Engine(uri, true);
         await engine._initFromURI(uri);
+        // If there is an existing engine with the same name then update that engine.
+        // Only do this during reloads so it doesnt interfere with distribution
+        // engines
+        if (isReload && engine.name in this._engines) {
+          engine._engineToUpdate = this._engines[engine.name];
+        }
         engines.push(engine);
       } catch (ex) {
         LOG("_loadFromChromeURLs: failed to load engine: " + ex);
       }
     }
     return engines;
   },