Bug 1101478 - Remove the WindowsJumpLists.jsm depedency on hasHistoryEntries. r=jimm draft
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 18 Nov 2014 20:21:44 +0100
changeset 792174 3e20e205319e1f441785f9a8d75c5dab849ec0e1
parent 792167 5329ed861c6f46ed5534ab775f69ed4e3fe447be
child 792357 8f16311fb00e415258833ff313a9982bf5e32c4b
push id109025
push usermak77@bonardo.net
push dateMon, 07 May 2018 19:46:27 +0000
reviewersjimm
bugs1101478
milestone61.0a1
Bug 1101478 - Remove the WindowsJumpLists.jsm depedency on hasHistoryEntries. r=jimm MozReview-Commit-ID: 9olZfsQrLPc
browser/modules/WindowsJumpLists.jsm
--- a/browser/modules/WindowsJumpLists.jsm
+++ b/browser/modules/WindowsJumpLists.jsm
@@ -52,16 +52,26 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "@mozilla.org/windows-taskbar;1",
                                    "nsIWinTaskbar");
 
 ChromeUtils.defineModuleGetter(this, "PlacesUtils",
   "resource://gre/modules/PlacesUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
   "resource://gre/modules/PrivateBrowsingUtils.jsm");
 
+XPCOMUtils.defineLazyGetter(this, "gHistoryObserver", function() {
+  return Object.freeze({
+    onClearHistory() {
+      WinTaskbarJumpList.update();
+    },
+    QueryInterface: XPCOMUtils.generateQI(Ci.nsINavHistoryObserver),
+    __noSuchMethod__: () => {}, // Catch all of the other notifications.
+  });
+});
+
 /**
  * Global functions
  */
 
 function _getString(name) {
   return _stringBundle.GetStringFromName(name);
 }
 
@@ -154,24 +164,16 @@ var WinTaskbarJumpList =
       return;
 
     // do what we came here to do, update the taskbar jumplist
     this._buildList();
   },
 
   _shutdown: function WTBJL__shutdown() {
     this._shuttingDown = true;
-
-    // Correctly handle a clear history on shutdown.  If there are no
-    // entries be sure to empty all history lists.  Luckily Places caches
-    // this value, so it's a pretty fast call.
-    if (!PlacesUtils.history.hasHistoryEntries) {
-      this.update();
-    }
-
     this._free();
   },
 
   /**
    * List building
    *
    * @note Async builders must add their mozIStoragePendingStatement to
    *       _pendingStatements object, using a different LIST_TYPE entry for
@@ -264,21 +266,16 @@ var WinTaskbarJumpList =
   },
 
   _buildCustom: function WTBJL__buildCustom(title, items) {
     if (items.length > 0)
       this._builder.addListToBuild(this._builder.JUMPLIST_CATEGORY_CUSTOMLIST, items, title);
   },
 
   _buildFrequent: function WTBJL__buildFrequent() {
-    // If history is empty, just bail out.
-    if (!PlacesUtils.history.hasHistoryEntries) {
-      return;
-    }
-
     // Windows supports default frequent and recent lists,
     // but those depend on internal windows visit tracking
     // which we don't populate. So we build our own custom
     // frequent and recent lists using our nav history data.
 
     var items = Cc["@mozilla.org/array;1"].
                 createInstance(Ci.nsIMutableArray);
     // track frequent items so that we don't add them to
@@ -304,21 +301,16 @@ var WinTaskbarJumpList =
         items.appendElement(shortcut);
         this._frequentHashList.push(aResult.uri);
       },
       this
     );
   },
 
   _buildRecent: function WTBJL__buildRecent() {
-    // If history is empty, just bail out.
-    if (!PlacesUtils.history.hasHistoryEntries) {
-      return;
-    }
-
     var items = Cc["@mozilla.org/array;1"].
                 createInstance(Ci.nsIMutableArray);
     // Frequent items will be skipped, so we select a double amount of
     // entries and stop fetching results at _maxItemCount.
     var count = 0;
 
     this._pendingStatements[LIST_TYPE.RECENT] = this._getHistoryResults(
       Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING,
@@ -468,22 +460,24 @@ var WinTaskbarJumpList =
 
   _initObs: function WTBJL__initObs() {
     // If the browser is closed while in private browsing mode, the "exit"
     // notification is fired on quit-application-granted.
     // History cleanup can happen at profile-change-teardown.
     Services.obs.addObserver(this, "profile-before-change");
     Services.obs.addObserver(this, "browser:purge-session-history");
     _prefs.addObserver("", this);
+    PlacesUtils.history.addObserver(gHistoryObserver, false);
   },
 
   _freeObs: function WTBJL__freeObs() {
     Services.obs.removeObserver(this, "profile-before-change");
     Services.obs.removeObserver(this, "browser:purge-session-history");
     _prefs.removeObserver("", this);
+    PlacesUtils.history.removeObserver(gHistoryObserver);
   },
 
   _updateTimer: function WTBJL__updateTimer() {
     if (this._enabled && !this._shuttingDown && !this._timer) {
       this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
       this._timer.initWithCallback(this,
                                    _prefs.getIntPref(PREF_TASKBAR_REFRESH) * 1000,
                                    this._timer.TYPE_REPEATING_SLACK);