2014-06-23 17:09:02 +00:00
|
|
|
var Filer = require("../..");
|
|
|
|
|
|
|
|
var indexedDB = global.indexedDB ||
|
|
|
|
global.mozIndexedDB ||
|
|
|
|
global.webkitIndexedDB ||
|
|
|
|
global.msIndexedDB;
|
|
|
|
|
|
|
|
var needsCleanup = [];
|
|
|
|
if(global.addEventListener) {
|
|
|
|
global.addEventListener('beforeunload', function() {
|
|
|
|
needsCleanup.forEach(function(f) { f(); });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function IndexedDBTestProvider(name) {
|
|
|
|
var _done = false;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
function cleanup(callback) {
|
2014-12-17 07:54:29 +00:00
|
|
|
callback = callback || function(){};
|
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
if(!that.provider || _done) {
|
2014-08-16 20:22:41 +00:00
|
|
|
return callback();
|
2014-06-23 17:09:02 +00:00
|
|
|
}
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
// We have to force any other connections to close
|
|
|
|
// before we can delete a db.
|
|
|
|
if(that.provider.db) {
|
|
|
|
that.provider.db.close();
|
2014-01-21 21:25:09 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
var request = indexedDB.deleteDatabase(name);
|
|
|
|
function finished() {
|
|
|
|
that.provider = null;
|
|
|
|
_done = true;
|
|
|
|
callback();
|
2014-01-21 21:25:09 +00:00
|
|
|
}
|
2014-06-23 17:09:02 +00:00
|
|
|
request.onsuccess = finished;
|
|
|
|
request.onerror = finished;
|
|
|
|
}
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
function init() {
|
|
|
|
if(that.provider) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
that.provider = new Filer.FileSystem.providers.IndexedDB(name);
|
|
|
|
needsCleanup.push(cleanup);
|
2014-01-21 21:25:09 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
this.init = init;
|
|
|
|
this.cleanup = cleanup;
|
|
|
|
}
|
2014-08-16 20:22:41 +00:00
|
|
|
IndexedDBTestProvider.isSupported = function() {
|
|
|
|
return Filer.FileSystem.providers.IndexedDB.isSupported();
|
|
|
|
};
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
module.exports = IndexedDBTestProvider;
|