diff --git a/dom/datastore/DataStore.jsm b/dom/datastore/DataStore.jsm index 8f74a1d2b92..e0ed0992916 100644 --- a/dom/datastore/DataStore.jsm +++ b/dom/datastore/DataStore.jsm @@ -8,26 +8,13 @@ var EXPORTED_SYMBOLS = ["DataStore"]; -function debug(s) { - // dump('DEBUG DataStore: ' + s + '\n'); -} - -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; - -Cu.import("resource://gre/modules/DataStoreDB.jsm"); -Cu.import("resource://gre/modules/ObjectWrapper.jsm"); -Cu.import('resource://gre/modules/Services.jsm'); - /* DataStore object */ -function DataStore(aAppId, aName, aOwner, aReadOnly, aGlobalScope) { +function DataStore(aAppId, aName, aOwner, aReadOnly) { this.appId = aAppId; this.name = aName; this.owner = aOwner; this.readOnly = aReadOnly; - - this.db = new DataStoreDB(); - this.db.init(aOwner, aName, aGlobalScope); } DataStore.prototype = { @@ -36,113 +23,9 @@ DataStore.prototype = { owner: null, readOnly: null, - newDBPromise: function(aWindow, aTxnType, aFunction) { - let db = this.db; - return new aWindow.Promise(function(aResolve, aReject) { - debug("DBPromise started"); - db.txn( - aTxnType, - function(aTxn, aStore) { - debug("DBPromise success"); - aFunction(aResolve, aReject, aTxn, aStore); - }, - function() { - debug("DBPromise error"); - aReject(new aWindow.DOMError("InvalidStateError")); - } - ); - }); - }, - - getInternal: function(aWindow, aResolve, aReject, aStore, aId) { - debug("GetInternal " + aId); - - let request = aStore.get(aId); - request.onsuccess = function(aEvent) { - debug("GetInternal success. Record: " + aEvent.target.result); - aResolve(ObjectWrapper.wrap(aEvent.target.result, aWindow)); - }; - - request.onerror = function(aEvent) { - debug("GetInternal error"); - aReject(new aWindow.DOMError(aEvent.target.error.name)); - }; - }, - - updateInternal: function(aWindow, aResolve, aReject, aStore, aId, aObj) { - debug("UpdateInternal " + aId); - - let request = aStore.put(aObj, aId); - request.onsuccess = function(aEvent) { - debug("UpdateInternal success"); - // No wrap here because the result is always a int. - aResolve(aEvent.target.result); - }; - request.onerror = function(aEvent) { - debug("UpdateInternal error"); - aReject(new aWindow.DOMError(aEvent.target.error.name)); - }; - }, - - addInternal: function(aWindow, aResolve, aReject, aStore, aObj) { - debug("AddInternal"); - - let request = aStore.put(aObj); - request.onsuccess = function(aEvent) { - debug("Request successful. Id: " + aEvent.target.result); - // No wrap here because the result is always a int. - aResolve(aEvent.target.result); - }; - request.onerror = function(aEvent) { - debug("AddInternal error"); - aReject(new aWindow.DOMError(aEvent.target.error.name)); - }; - }, - - removeInternal: function(aResolve, aReject, aStore, aId) { - debug("RemoveInternal"); - - let request = aStore.delete(aId); - request.onsuccess = function() { - debug("RemoveInternal success"); - aResolve(); - }; - request.onerror = function(aEvent) { - debug("RemoveInternal error"); - aReject(new aWindow.DOMError(aEvent.target.error.name)); - }; - }, - - clearInternal: function(aResolve, aReject, aStore) { - debug("ClearInternal"); - - let request = aStore.clear(); - request.onsuccess = function() { - debug("ClearInternal success"); - aResolve(); - }; - request.onerror = function(aEvent) { - debug("ClearInternal error"); - aReject(new aWindow.DOMError(aEvent.target.error.name)); - }; - }, - - throwInvalidArg: function(aWindow) { - return aWindow.Promise.reject( - new aWindow.DOMError("SyntaxError", "Non-numeric or invalid id")); - }, - - throwReadOnly: function(aWindow) { - return aWindow.Promise.reject( - new aWindow.DOMError("ReadOnlyError", "DataStore in readonly mode")); - }, - exposeObject: function(aWindow) { let self = this; - let object = { - - // Public interface : - + let chromeObject = { get name() { return self.name; }, @@ -155,83 +38,13 @@ DataStore.prototype = { return self.readOnly; }, - get: function DS_get(aId) { - aId = parseInt(aId); - if (isNaN(aId) || aId <= 0) { - return self.throwInvalidArg(aWindow); - } - - // Promise - return self.newDBPromise(aWindow, "readonly", - function(aResolve, aReject, aTxn, aStore) { - self.getInternal(aWindow, aResolve, aReject, aStore, aId); - } - ); - }, - - update: function DS_update(aId, aObj) { - aId = parseInt(aId); - if (isNaN(aId) || aId <= 0) { - return self.throwInvalidArg(aWindow); - } - - if (self.readOnly) { - return self.throwReadOnly(aWindow); - } - - // Promise - return self.newDBPromise(aWindow, "readwrite", - function(aResolve, aReject, aTxn, aStore) { - self.updateInternal(aWindow, aResolve, aReject, aStore, aId, aObj); - } - ); - }, - - add: function DS_add(aObj) { - if (self.readOnly) { - return self.throwReadOnly(aWindow); - } - - // Promise - return self.newDBPromise(aWindow, "readwrite", - function(aResolve, aReject, aTxn, aStore) { - self.addInternal(aWindow, aResolve, aReject, aStore, aObj); - } - ); - }, - - remove: function DS_remove(aId) { - aId = parseInt(aId); - if (isNaN(aId) || aId <= 0) { - return self.throwInvalidArg(aWindow); - } - - if (self.readOnly) { - return self.throwReadOnly(aWindow); - } - - // Promise - return self.newDBPromise(aWindow, "readwrite", - function(aResolve, aReject, aTxn, aStore) { - self.removeInternal(aResolve, aReject, aStore, aId); - } - ); - }, - - clear: function DS_clear() { - if (self.readOnly) { - return self.throwReadOnly(aWindow); - } - - // Promise - return self.newDBPromise(aWindow, "readwrite", - function(aResolve, aReject, aTxn, aStore) { - self.clearInternal(aResolve, aReject, aStore); - } - ); - }, - /* TODO: + Promise get(unsigned long id); + Promise update(unsigned long id, any obj); + Promise add(any obj) + Promise remove(unsigned long id) + Promise clear(); + readonly attribute DOMString revisionId attribute EventHandler onchange; Promise getChanges(DOMString revisionId) @@ -241,19 +54,10 @@ DataStore.prototype = { __exposedProps__: { name: 'r', owner: 'r', - readOnly: 'r', - get: 'r', - update: 'r', - add: 'r', - remove: 'r', - clear: 'r' + readOnly: 'r' } }; - return object; - }, - - delete: function() { - this.db.delete(); + return chromeObject; } }; diff --git a/dom/datastore/DataStoreDB.jsm b/dom/datastore/DataStoreDB.jsm deleted file mode 100644 index 926d63fbfc9..00000000000 --- a/dom/datastore/DataStoreDB.jsm +++ /dev/null @@ -1,54 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -'use strict'; - -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; - -this.EXPORTED_SYMBOLS = ['DataStoreDB']; - -function debug(s) { - // dump('DEBUG DataStoreDB: ' + s + '\n'); -} - -const DATASTOREDB_VERSION = 1; -const DATASTOREDB_OBJECTSTORE_NAME = 'DataStoreDB'; - -Cu.import('resource://gre/modules/IndexedDBHelper.jsm'); - -this.DataStoreDB = function DataStoreDB() {} - -DataStoreDB.prototype = { - - __proto__: IndexedDBHelper.prototype, - - upgradeSchema: function(aTransaction, aDb, aOldVersion, aNewVersion) { - debug('updateSchema'); - aDb.createObjectStore(DATASTOREDB_OBJECTSTORE_NAME, { autoIncrement: true }); - }, - - init: function(aOrigin, aName) { - let dbName = aOrigin + '_' + aName; - this.initDBHelper(dbName, DATASTOREDB_VERSION, - [DATASTOREDB_OBJECTSTORE_NAME]); - }, - - txn: function(aType, aCallback, aErrorCb) { - debug('Transaction request'); - this.newTxn( - aType, - DATASTOREDB_OBJECTSTORE_NAME, - aCallback, - function() {}, - aErrorCb - ); - }, - - delete: function() { - debug('delete'); - this.close(); - indexedDB.deleteDatabase(this.dbName); - debug('database deleted'); - } -} diff --git a/dom/datastore/DataStoreService.js b/dom/datastore/DataStoreService.js index ac0a082c753..dda3714951f 100644 --- a/dom/datastore/DataStoreService.js +++ b/dom/datastore/DataStoreService.js @@ -8,9 +8,12 @@ /* static functions */ -function debug(s) { - // dump('DEBUG DataStoreService: ' + s + '\n'); -} +let DEBUG = 0; +let debug; +if (DEBUG) + debug = function (s) { dump('DEBUG DataStore: ' + s + '\n'); } +else + debug = function (s) {} const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; @@ -39,9 +42,8 @@ DataStoreService.prototype = { stores: {}, installDataStore: function(aAppId, aName, aOwner, aReadOnly) { - debug('installDataStore - appId: ' + aAppId + ', aName: ' + - aName + ', aOwner:' + aOwner + ', aReadOnly: ' + - aReadOnly); + debug('installDataStore - appId: ' + aAppId + ', aName: ' + aName + + ', aOwner:' + aOwner + ', aReadOnly: ' + aReadOnly); if (aName in this.stores && aAppId in this.stores[aName]) { debug('This should not happen'); @@ -90,7 +92,6 @@ DataStoreService.prototype = { for (let key in this.stores) { if (params.appId in this.stores[key]) { - this.stores[key][params.appId].delete(); delete this.stores[key][params.appId]; } diff --git a/dom/datastore/moz.build b/dom/datastore/moz.build index 8957fd0dc8b..a21ed6fd18e 100644 --- a/dom/datastore/moz.build +++ b/dom/datastore/moz.build @@ -21,5 +21,4 @@ EXTRA_COMPONENTS += [ EXTRA_JS_MODULES += [ 'DataStore.jsm', - 'DataStoreDB.jsm', ] diff --git a/dom/datastore/tests/Makefile.in b/dom/datastore/tests/Makefile.in index abb6d137515..37ca6add520 100644 --- a/dom/datastore/tests/Makefile.in +++ b/dom/datastore/tests/Makefile.in @@ -13,8 +13,6 @@ include $(DEPTH)/config/autoconf.mk MOCHITEST_FILES = \ test_app_install.html \ - test_readonly.html \ - test_basic.html \ file_app.sjs \ file_app.template.webapp \ $(NULL) diff --git a/dom/datastore/tests/test_app_install.html b/dom/datastore/tests/test_app_install.html index b8f914af204..08cb9cc0a9a 100644 --- a/dom/datastore/tests/test_app_install.html +++ b/dom/datastore/tests/test_app_install.html @@ -5,9 +5,6 @@ Test for DataStore - install/uninstall apps - - -
+ + +

+ +
+
+
diff --git a/dom/datastore/tests/test_basic.html b/dom/datastore/tests/test_basic.html deleted file mode 100644 index 94c5038a946..00000000000 --- a/dom/datastore/tests/test_basic.html +++ /dev/null @@ -1,229 +0,0 @@ - - - - - Test for DataStore - basic operation on a readonly db - - - - -
- - - diff --git a/dom/datastore/tests/test_readonly.html b/dom/datastore/tests/test_readonly.html deleted file mode 100644 index 5b323412bc0..00000000000 --- a/dom/datastore/tests/test_readonly.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - - Test for DataStore - basic operation on a readonly db - - - - -
- - -