|
1 var DEBUG = true; |
|
2 |
|
3 var clientID = "javascript"; |
|
4 var nsICache = Components.interfaces.nsICache; |
|
5 |
|
6 function getCacheService() |
|
7 { |
|
8 var nsCacheService = Components.classes["@mozilla.org/network/cache-service;1"]; |
|
9 var service = nsCacheService.getService(Components.interfaces.nsICacheService); |
|
10 return service; |
|
11 } |
|
12 |
|
13 function CacheVisitor() |
|
14 { |
|
15 } |
|
16 |
|
17 CacheVisitor.prototype = { |
|
18 QueryInterface : function(iid) |
|
19 { |
|
20 if (iid.equals(Components.interfaces.nsICacheVisitor)) |
|
21 return this; |
|
22 throw Components.results.NS_NOINTERFACE; |
|
23 }, |
|
24 |
|
25 visitDevice : function(deviceID, deviceInfo) |
|
26 { |
|
27 print("[visiting device (deviceID = " + deviceID + ", description = " + deviceInfo.description + ")]"); |
|
28 return true; |
|
29 }, |
|
30 |
|
31 visitEntry : function(deviceID, entryInfo) |
|
32 { |
|
33 print("[visiting entry (clientID = " + entryInfo.clientID + ", key = " + entryInfo.key + ")]"); |
|
34 return true; |
|
35 } |
|
36 }; |
|
37 |
|
38 function test() |
|
39 { |
|
40 var cacheService = getCacheService(); |
|
41 var visitor = new CacheVisitor(); |
|
42 cacheService.visitEntries(visitor); |
|
43 } |
|
44 |
|
45 // load the cache service before doing anything with Java... |
|
46 getCacheService(); |
|
47 |
|
48 if (DEBUG) { |
|
49 print("cache service loaded."); |
|
50 } else { |
|
51 print("running cache visitor test."); |
|
52 test(); |
|
53 print("cache visitor test complete."); |
|
54 } |