2014-06-23 17:09:02 +00:00
|
|
|
var Filer = require('../..');
|
|
|
|
|
|
|
|
var needsCleanup = [];
|
|
|
|
if(global.addEventListener) {
|
2014-07-15 15:36:53 +00:00
|
|
|
global.addEventListener('beforeunload', function() {
|
2014-06-23 17:09:02 +00:00
|
|
|
needsCleanup.forEach(function(f) { f(); });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function WebSQLTestProvider(name) {
|
|
|
|
var _done = false;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
function cleanup(callback) {
|
|
|
|
if(!that.provider || _done) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Provider is there, but db was never touched
|
|
|
|
if(!that.provider.db) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
var context = that.provider.getReadWriteContext();
|
|
|
|
context.clear(function() {
|
|
|
|
that.provider = null;
|
|
|
|
_done = true;
|
|
|
|
callback();
|
2014-05-17 19:17:09 +00:00
|
|
|
});
|
|
|
|
}
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
function init() {
|
|
|
|
if(that.provider) {
|
|
|
|
return;
|
2014-01-21 21:25:09 +00:00
|
|
|
}
|
2014-06-23 17:09:02 +00:00
|
|
|
that.provider = new Filer.FileSystem.providers.WebSQL(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-01-21 21:25:09 +00:00
|
|
|
|
2014-06-23 17:09:02 +00:00
|
|
|
module.exports = WebSQLTestProvider;
|