[or-cvs] r11726: A cache appears! It seems to cache things. Hurray for locali (in torbutton/trunk/src: chrome/content components)
mikeperry at seul.org
mikeperry at seul.org
Mon Oct 1 07:00:16 UTC 2007
Author: mikeperry
Date: 2007-10-01 03:00:16 -0400 (Mon, 01 Oct 2007)
New Revision: 11726
Modified:
torbutton/trunk/src/chrome/content/torbutton.js
torbutton/trunk/src/components/window-mapper.js
Log:
A cache appears! It seems to cache things. Hurray for
locality!
Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js 2007-10-01 06:57:46 UTC (rev 11725)
+++ torbutton/trunk/src/chrome/content/torbutton.js 2007-10-01 07:00:16 UTC (rev 11726)
@@ -1062,6 +1062,8 @@
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
+ wm.expireOldCache();
+
var browser = wm.getBrowserForContentWindow(win);
if(!browser) win.alert("No window found!");
torbutton_log(2, "Got browser "+browser.contentDocument.location+" for: "
Modified: torbutton/trunk/src/components/window-mapper.js
===================================================================
--- torbutton/trunk/src/components/window-mapper.js 2007-10-01 06:57:46 UTC (rev 11725)
+++ torbutton/trunk/src/components/window-mapper.js 2007-10-01 07:00:16 UTC (rev 11726)
@@ -16,19 +16,42 @@
const Cr = Components.results;
const Cc = Components.classes;
const Ci = Components.interfaces;
+const EXPIRATION_TIME = 60000; // 60 seconds
function ContentWindowMapper() {
+ this.cache = new Object();
+ this.cache["bah"] = 0;
- var checkCache = function(topContentWindow) {
+ this.checkCache = function(topContentWindow) {
+ if(typeof(this.cache[topContentWindow]) != "undefined") {
+ dump("Found cached element\n");
+ return this.cache[topContentWindow].browser;
+ }
+
return null;
};
- var addCache = function(topContentWindow, browser) {
- return null;
+ this.addCache = function(topContentWindow, browser) {
+ var insertion = new Object();
+ insertion.browser = browser;
+ insertion.time = Date.now();
+ this.cache[topContentWindow] = insertion;
+ dump("Cached element\n");
};
+ this.expireOldCache = function() {
+ var now = Date.now();
+
+ for(var elem in this.cache) {
+ if((now - this.cache[elem].time) > EXPIRATION_TIME) {
+ dump("Deleting expired entry\n");
+ delete this.cache[elem];
+ }
+ }
+ };
+
this.getBrowserForContentWindow = function(topContentWindow) {
- var cached = checkCache(topContentWindow);
+ var cached = this.checkCache(topContentWindow);
if(cached != null) return cached;
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
@@ -40,7 +63,7 @@
for (var i = 0; i < browser.browsers.length; ++i) {
var b = browser.browsers[i];
if (b && b.contentWindow == topContentWindow) {
- addCache(topContentWindow, browser);
+ this.addCache(topContentWindow, browser);
return browser;
}
}
@@ -98,6 +121,7 @@
}
+var ContentWindowMapperInstance = null;
var ContentWindowMapperFactory = new Object();
ContentWindowMapperFactory.createInstance = function (outer, iid)
@@ -111,7 +135,10 @@
Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
return null;
}
- return new ContentWindowMapper();
+ if(ContentWindowMapperInstance == null)
+ ContentWindowMapperInstance = new ContentWindowMapper();
+
+ return ContentWindowMapperInstance;
}
var ContentWindowMapperModule = new Object();
More information about the tor-commits
mailing list