Bug 382711 - on migration or db upgrade of a profile with livemarks, we start up the livemark service' update timer (r=sspitzer)
authordietrich@mozilla.com
Thu, 17 Jan 2008 22:58:52 -0800
changeset 10383 76ecf24571b217174c28cc42b2e6df129ab16d8c
parent 10382 6aa8ddaf532488a7d90108ec03bb43a507aed205
child 10384 8ead09b180285be698ae8a18c809f798e1a751d8
push idunknown
push userunknown
push dateunknown
reviewerssspitzer
bugs382711
milestone1.9b3pre
Bug 382711 - on migration or db upgrade of a profile with livemarks, we start up the livemark service' update timer (r=sspitzer)
browser/base/content/browser.js
toolkit/components/places/public/nsILivemarkService.idl
toolkit/components/places/src/nsLivemarkService.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1044,16 +1044,23 @@ function delayedStartup()
   gBookmarkAllTabsHandler = new BookmarkAllTabsHandler();
 
   // Attach a listener to watch for "command" events bubbling up from error
   // pages.  This lets us fix bugs like 401575 which require error page UI to
   // do privileged things, without letting error pages have any privilege
   // themselves.
   gBrowser.addEventListener("command", BrowserOnCommand, false);
 
+  // Delayed initialization of the livemarks update timer.
+  // Livemark updates don't need to start until after bookmark UI 
+  // such as the toolbar has initialized. Starting 5 seconds after
+  // delayedStartup in order to stagger this before the download
+  // manager starts (see below).
+  setTimeout(function() PlacesUtils.livemarks.start(), 5000);
+
   // Initialize the download manager some time after the app starts so that
   // auto-resume downloads begin (such as after crashing or quitting with
   // active downloads) and speeds up the first-load of the download manager UI.
   // If the user manually opens the download manager before the timeout, the
   // downloads will start right away, and getting the service again won't hurt.
   setTimeout(function() Cc["@mozilla.org/download-manager;1"].
                         getService(Ci.nsIDownloadManager), 10000);
 }
--- a/toolkit/components/places/public/nsILivemarkService.idl
+++ b/toolkit/components/places/public/nsILivemarkService.idl
@@ -37,20 +37,27 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 interface nsIURI;
 interface nsINavBookmarksService;
 
-[scriptable, uuid(602e3a71-2d10-4d8f-80c2-6db302b5c89d)]
+[scriptable, uuid(7879747e-8871-4a7b-9032-5c4fff1d6017)]
 interface nsILivemarkService : nsISupports
 {
   /**
+   * Starts the livemark refresh timer.
+   * Being able to manually control this allows activity such
+   * as bookmarks import to occur without kicking off HTTP traffic.
+   */
+  void start();
+
+  /**
    * Creates a new livemark
    * @param folder      The id of the parent folder
    * @param name        The name to show when displaying the livemark
    * @param siteURI     The URI of the site the livemark was created from
    * @param feedURI     The URI of the actual RSS feed
    * @param index       The index to insert at, or -1 to append
    * @returns the ID of the folder for the livemark
    */
--- a/toolkit/components/places/src/nsLivemarkService.js
+++ b/toolkit/components/places/src/nsLivemarkService.js
@@ -142,18 +142,16 @@ function LivemarkService() {
   this._livemarks = [];
 
   this._iconURI = gIoService.newURI(LIVEMARK_ICON_URI, null, null);
   this._loading = GetString("bookmarksLivemarkLoading") || DEFAULT_LOAD_MSG;
   this._observerServiceObserver =
     new G_ObserverServiceObserver('xpcom-shutdown',
                                   BindToObject(this._shutdown, this),
                                   true /*only once*/);
-  new G_Alarm(BindToObject(this._fireTimer, this), LIVEMARK_TIMEOUT,
-              true /* repeat */);
 
   if (IS_CONTRACTID in Cc)
     this._idleService = Cc[IS_CONTRACTID].getService(Ci.nsIIdleService);
 
   // this is giving a reentrant getService warning in XPCShell. bug 194568.
   this._ans = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService);
 
   var livemarks = this._ans.getItemsWithAnnotation(LMANNO_FEEDURI, {});
@@ -178,16 +176,24 @@ LivemarkService.prototype = {
   },
 
   get _history() {
     if (!this.__history)
       this.__history = Cc[NH_CONTRACTID].getService(Ci.nsINavHistoryService);
     return this.__history;
   },
 
+  _updateTimer: null,
+  start: function LS_start() {
+    if (this._updateTimer)
+      return;
+    this._updateTimer = new G_Alarm(BindToObject(this._fireTimer, this),
+                                    LIVEMARK_TIMEOUT, true /* repeat */);
+  },
+
   // returns new length of _livemarks
   _pushLivemark: function LS__pushLivemark(folderId, feedURI) {
     return this._livemarks.push({folderId: folderId, feedURI: feedURI});
   },
 
   _getLivemarkIndex: function LS__getLivemarkIndex(folderId) {
     for (var i=0; i < this._livemarks.length; ++i) {
       if (this._livemarks[i].folderId == folderId)
@@ -199,16 +205,22 @@ LivemarkService.prototype = {
   _shutdown: function LS__shutdown() {
     // remove bookmarks observer
     this._bms.removeObserver(this);
 
     for (var livemark in this._livemarks) {
       if (livemark.loadGroup)
         livemark.loadGroup.cancel(NS_BINDING_ABORTED);
     }
+
+    // kill timer
+    if (this._updateTimer) {
+      this._updateTimer.cancel();
+      this._updateTimer = null;
+    }
   },
 
   _fireTimer: function LS__fireTimer() {
     for (var i=0; i < this._livemarks.length; ++i) {
       this._updateLivemarkChildren(i, false);
     }
   },