2012-06-12 14:23:32 -07:00
|
|
|
var _CSvc;
|
|
|
|
function get_cache_service() {
|
|
|
|
if (_CSvc)
|
|
|
|
return _CSvc;
|
|
|
|
|
|
|
|
return _CSvc = Components.classes["@mozilla.org/network/cache-service;1"]
|
|
|
|
.getService(Components.interfaces.nsICacheService);
|
|
|
|
}
|
|
|
|
|
|
|
|
function evict_cache_entries(where)
|
|
|
|
{
|
|
|
|
if (where == null)
|
|
|
|
where = Components.interfaces.nsICache.STORE_ANYWHERE;
|
|
|
|
|
|
|
|
get_cache_service().evictEntries(where);
|
|
|
|
}
|
|
|
|
|
|
|
|
function asyncOpenCacheEntry(key, sessionName, storagePolicy, access, callback)
|
|
|
|
{
|
|
|
|
function CacheListener() { }
|
|
|
|
CacheListener.prototype = {
|
|
|
|
QueryInterface: function (iid) {
|
|
|
|
if (iid.equals(Components.interfaces.nsICacheListener) ||
|
|
|
|
iid.equals(Components.interfaces.nsISupports))
|
|
|
|
return this;
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
onCacheEntryAvailable: function (entry, access, status) {
|
|
|
|
callback(status, entry);
|
|
|
|
},
|
|
|
|
|
|
|
|
run: function () {
|
|
|
|
var cache = get_cache_service();
|
|
|
|
var session = cache.createSession(
|
|
|
|
sessionName,
|
|
|
|
storagePolicy,
|
|
|
|
Components.interfaces.nsICache.STREAM_BASED);
|
2012-07-11 02:18:00 -07:00
|
|
|
session.asyncOpenCacheEntry(key, access, this);
|
2012-06-12 14:23:32 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
(new CacheListener()).run();
|
|
|
|
}
|
|
|
|
|
2012-08-01 14:22:28 -07:00
|
|
|
function syncWithCacheIOThread(callback)
|
|
|
|
{
|
|
|
|
asyncOpenCacheEntry(
|
|
|
|
"nonexistententry",
|
|
|
|
"HTTP",
|
|
|
|
Components.interfaces.nsICache.STORE_ANYWHERE,
|
|
|
|
Components.interfaces.nsICache.ACCESS_READ,
|
|
|
|
function(status, entry) {
|
|
|
|
do_check_eq(status, Components.results.NS_ERROR_CACHE_KEY_NOT_FOUND);
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
2012-09-04 17:37:45 -07:00
|
|
|
|
|
|
|
function get_device_entry_count(device) {
|
|
|
|
var cs = get_cache_service();
|
|
|
|
var entry_count = -1;
|
|
|
|
|
|
|
|
var visitor = {
|
|
|
|
visitDevice: function (deviceID, deviceInfo) {
|
|
|
|
if (device == deviceID)
|
|
|
|
entry_count = deviceInfo.entryCount;
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
visitEntry: function (deviceID, entryInfo) {
|
|
|
|
do_throw("nsICacheVisitor.visitEntry should not be called " +
|
|
|
|
"when checking the availability of devices");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// get the device entry count
|
|
|
|
cs.visitEntries(visitor);
|
|
|
|
|
|
|
|
return entry_count;
|
|
|
|
}
|