All pastes #68209 Raw Edit

Someone

public text v1 · immutable
#68209 ·published 2006-06-21 06:28 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:27:28 -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";
@@ -133,16 +129,25 @@ MicrosummaryService.prototype = {
   // Observer Service
   __obs: null,
   get _obs() {
     if (!this.__obs)
       this.__obs = Cc["@mozilla.org/observer-service;1"].
                    getService(Ci.nsIObserverService);
     return this.__obs;
   },
+  
+  // Preference Service
+  __ps: null,
+  get _ps() {
+    if (!this.__ps)
+      this.__ps = Cc["@mozilla.org/preferences-service;1"].
+                  getService(Ci.nsIPrefBranch);
+    return this.__ps;
+  },
 
   /**
    * Make a URI from a spec.
    * @param   spec
    *          The string spec of the URI.
    * @returns An nsIURI object.
    */
   _uri: function MSS__uri(spec) {
@@ -175,16 +180,34 @@ 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. Note that the pref.
+  // takes a time in minutes, though.
+  get _updateInterval() {
+    var mins;
+    try {
+      mins = 
+        this._pb.getIntPref("browser.bookmarks.microsummary.updateInterval");
+      // We're not going to update any more than once a minute. 
+      if (mins < 1)
+        mins = 1;
+    } 
+    catch (ex) {
+      // Default to 30 minutes.
+      mins = 30;
+    }
+    return mins * 60 * 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 +289,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 +772,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();