All pastes #68199 Raw Edit

Stuff

public text v1 · immutable
#68199 ·published 2006-06-21 06:02 UTC
rendered paste body
Index: browser/components/microsummaries/src/nsMicrosummaryService.js.in
===================================================================
RCS file: /cvsroot/mozilla/browser/components/microsummaries/src/nsMicrosummaryService.js.in,v
retrieving revision 1.1.2.12
diff -u -8 -p -r1.1.2.12 nsMicrosummaryService.js.in
--- browser/components/microsummaries/src/nsMicrosummaryService.js.in	19 Jun 2006 23:16:10 -0000	1.1.2.12
+++ browser/components/microsummaries/src/nsMicrosummaryService.js.in	21 Jun 2006 06:02:07 -0000
@@ -39,20 +39,16 @@ const Ci = Components.interfaces;
 
 const PERMS_FILE    = 0644;
 const MODE_WRONLY   = 0x02;
 const MODE_TRUNCATE = 0x20;
 
 const NS_ERROR_MODULE_DOM = 2152923136;
 const NS_ERROR_DOM_BAD_URI = NS_ERROR_MODULE_DOM + 1012;
 
-// How often to update microsummaries, in milliseconds.
-// XXX Make this a hidden pref so power users can modify it.
-const UPDATE_INTERVAL = 30 * 60 * 1000; // 30 minutes
-
 // How often to check for microsummaries that need updating, in milliseconds.
 const CHECK_INTERVAL = 15 * 1000; // 15 seconds
 
 const MICSUM_NS = new Namespace("http://www.mozilla.org/microsummaries/0.1");
 const XSLT_NS = new Namespace("http://www.w3.org/1999/XSL/Transform");
 
 #ifdef MOZ_PLACES
 const FIELD_MICSUM_GEN_URI    = "microsummary/generatorURI";
@@ -175,16 +171,37 @@ MicrosummaryService.prototype = {
   __dirs: null,
   get _dirs() {
     if (!this.__dirs)
       this.__dirs = Cc["@mozilla.org/file/directory_service;1"].
                    getService(Ci.nsIProperties);
     return this.__dirs;
   },
 
+  // How often to update microsummaries, in milliseconds. 
+  __updateInterval: null,
+  get _updateInterval() {
+    if (!this.__updateInterval) {
+      var pb = Cc["@mozilla.org/preferences-service;1"].
+               getService(Ci.nsIPrefBranch);
+      var seconds;
+      try {
+        seconds = 
+          pb.getIntPref("browser.bookmarks.microsummary.refresh_seconds");
+        // We're not going to update any more than once a minute. 
+        if (seconds < 60)
+          seconds = 60;
+      } catch (ex) {
+        // Default to 30 minutes.
+        seconds = 30 * 60;
+      }
+      return seconds * 1000;
+    }
+  },
+
   // A cache of local microsummary generators.  This gets built on startup
   // by the _cacheLocalGenerators() method.
   _localGenerators: {},
 
   // The timer that periodically checks for microsummaries needing updating.
   _timer: null,
 
   // Interfaces this component implements.
@@ -266,17 +283,17 @@ MicrosummaryService.prototype = {
       this.refreshMicrosummary(bookmarkID);
     }
   },
   
   _updateMicrosummary: function MSS__updateMicrosummary(bookmarkID, microsummary) {
     this._setField(bookmarkID, FIELD_GENERATED_TITLE, microsummary.content);
 
     var now = new Date().getTime();
-    this._setField(bookmarkID, FIELD_MICSUM_EXPIRATION, now + UPDATE_INTERVAL);
+    this._setField(bookmarkID, FIELD_MICSUM_EXPIRATION, now + this._updateInterval);
 
     LOG("updated microsummary for page " + microsummary.pageURI.spec +
         " to " + microsummary.content);
   },
 
   /**
    * Load local generators into the cache.
    * 
@@ -749,17 +766,17 @@ MicrosummaryService.prototype = {
     this._setField(bookmarkID, FIELD_MICSUM_GEN_URI, microsummary.generatorURI.spec);
 
     // If the microsummary content has already been generated,
     // set the URI's generated title to the microsummary content
     // and expire the microsummary after the normal interval.
     if (microsummary.content) {
       var now = new Date().getTime();
       this._setField(bookmarkID, FIELD_GENERATED_TITLE, microsummary.content);
-      this._setField(bookmarkID, FIELD_MICSUM_EXPIRATION, now + UPDATE_INTERVAL);
+      this._setField(bookmarkID, FIELD_MICSUM_EXPIRATION, now + this._updateInterval);
     }
 
     // Otherwise, expire the microsummary and update it immediately.
     else {
       if (this._hasField(bookmarkID, FIELD_MICSUM_EXPIRATION))
         this._clearField(bookmarkID, FIELD_MICSUM_EXPIRATION);
       microsummary.addObserver(this);
       microsummary.update();