зеркало из https://github.com/mozilla/gecko-dev.git
Backout 79296b6a6026 (bug 980549) for test failures, CLOSED TREE.
This commit is contained in:
Родитель
c43d89e3a3
Коммит
de86ad842a
|
@ -19,11 +19,9 @@ const Ci = Components.interfaces;
|
|||
this.EXPORTED_SYMBOLS = ["IndexedDBHelper"];
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.importGlobalProperties(["indexedDB"]);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, 'Services',
|
||||
'resource://gre/modules/Services.jsm');
|
||||
|
||||
this.IndexedDBHelper = function IndexedDBHelper() {}
|
||||
|
||||
IndexedDBHelper.prototype = {
|
||||
|
@ -90,10 +88,7 @@ IndexedDBHelper.prototype = {
|
|||
ensureDB: function ensureDB(aSuccessCb, aFailureCb) {
|
||||
if (this._db) {
|
||||
if (DEBUG) debug("ensureDB: already have a database, returning early.");
|
||||
if (aSuccessCb) {
|
||||
Services.tm.currentThread.dispatch(aSuccessCb,
|
||||
Ci.nsIThread.DISPATCH_NORMAL);
|
||||
}
|
||||
aSuccessCb && aSuccessCb();
|
||||
return;
|
||||
}
|
||||
this.open(aSuccessCb, aFailureCb);
|
||||
|
|
|
@ -32,13 +32,6 @@ function SettingsLock(aSettingsManager) {
|
|||
this._requests = new Queue();
|
||||
this._settingsManager = aSettingsManager;
|
||||
this._transaction = null;
|
||||
|
||||
let closeHelper = function() {
|
||||
if (DEBUG) debug("closing lock");
|
||||
this._open = false;
|
||||
}.bind(this);
|
||||
|
||||
Services.tm.currentThread.dispatch(closeHelper, Ci.nsIThread.DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
SettingsLock.prototype = {
|
||||
|
@ -72,13 +65,11 @@ SettingsLock.prototype = {
|
|||
break;
|
||||
case "set":
|
||||
let keys = Object.getOwnPropertyNames(info.settings);
|
||||
if (keys.length) {
|
||||
lock._isBusy = true;
|
||||
}
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
let last = i === keys.length - 1;
|
||||
if (DEBUG) debug("key: " + key + ", val: " + JSON.stringify(info.settings[key]) + ", type: " + typeof(info.settings[key]));
|
||||
lock._isBusy = true;
|
||||
let checkKeyRequest = store.get(key);
|
||||
|
||||
checkKeyRequest.onsuccess = function (event) {
|
||||
|
@ -96,11 +87,15 @@ SettingsLock.prototype = {
|
|||
let setReq = store.put(obj);
|
||||
|
||||
setReq.onsuccess = function() {
|
||||
lock._isBusy = false;
|
||||
cpmm.sendAsyncMessage("Settings:Changed", { key: key, value: userValue });
|
||||
if (last && !request.error) {
|
||||
lock._open = true;
|
||||
Services.DOMRequest.fireSuccess(request, 0);
|
||||
lock._open = false;
|
||||
if (!lock._requests.isEmpty()) {
|
||||
lock.process();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -109,13 +104,6 @@ SettingsLock.prototype = {
|
|||
Services.DOMRequest.fireError(request, setReq.error.name)
|
||||
}
|
||||
};
|
||||
|
||||
if (last) {
|
||||
lock._isBusy = false;
|
||||
if (!lock._requests.isEmpty()) {
|
||||
lock.process();
|
||||
}
|
||||
}
|
||||
};
|
||||
checkKeyRequest.onerror = function(event) {
|
||||
if (!request.error) {
|
||||
|
@ -123,9 +111,7 @@ SettingsLock.prototype = {
|
|||
}
|
||||
};
|
||||
}
|
||||
// Don't break here, instead return. Once the previous requests have
|
||||
// finished this loop will start again.
|
||||
return;
|
||||
break;
|
||||
case "get":
|
||||
let getReq = (info.name === "*") ? store.mozGetAll()
|
||||
: store.mozGetAll(info.name);
|
||||
|
@ -162,20 +148,22 @@ SettingsLock.prototype = {
|
|||
},
|
||||
|
||||
createTransactionAndProcess: function() {
|
||||
if (DEBUG) debug("database opened, creating transaction");
|
||||
|
||||
let manager = this._settingsManager;
|
||||
let transactionType = manager.hasWritePrivileges ? "readwrite" : "readonly";
|
||||
|
||||
this._transaction =
|
||||
manager._settingsDB._db.transaction(SETTINGSSTORE_NAME, transactionType);
|
||||
|
||||
this.process();
|
||||
},
|
||||
|
||||
maybeProcess: function() {
|
||||
if (this._transaction && !this._isBusy) {
|
||||
this.process();
|
||||
if (this._settingsManager._settingsDB._db) {
|
||||
var lock;
|
||||
while (lock = this._settingsManager._locks.dequeue()) {
|
||||
if (!lock._transaction) {
|
||||
let transactionType = this._settingsManager.hasWritePrivileges ? "readwrite" : "readonly";
|
||||
lock._transaction = lock._settingsManager._settingsDB._db.transaction(SETTINGSSTORE_NAME, transactionType);
|
||||
}
|
||||
if (!lock._isBusy) {
|
||||
lock.process();
|
||||
} else {
|
||||
this._settingsManager._locks.enqueue(lock);
|
||||
}
|
||||
}
|
||||
if (!this._requests.isEmpty() && !this._isBusy) {
|
||||
this.process();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -188,7 +176,7 @@ SettingsLock.prototype = {
|
|||
if (this._settingsManager.hasReadPrivileges) {
|
||||
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
||||
this._requests.enqueue({ request: req, intent:"get", name: aName });
|
||||
this.maybeProcess();
|
||||
this.createTransactionAndProcess();
|
||||
return req;
|
||||
} else {
|
||||
if (DEBUG) debug("get not allowed");
|
||||
|
@ -233,7 +221,7 @@ SettingsLock.prototype = {
|
|||
if (DEBUG) debug("send: " + JSON.stringify(aSettings));
|
||||
let settings = this._serializePreservingBinaries(aSettings);
|
||||
this._requests.enqueue({request: req, intent: "set", settings: settings});
|
||||
this.maybeProcess();
|
||||
this.createTransactionAndProcess();
|
||||
return req;
|
||||
} else {
|
||||
if (DEBUG) debug("set not allowed");
|
||||
|
@ -249,7 +237,7 @@ SettingsLock.prototype = {
|
|||
if (this._settingsManager.hasWritePrivileges) {
|
||||
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
||||
this._requests.enqueue({ request: req, intent: "clear"});
|
||||
this.maybeProcess();
|
||||
this.createTransactionAndProcess();
|
||||
return req;
|
||||
} else {
|
||||
if (DEBUG) debug("clear not allowed");
|
||||
|
@ -263,6 +251,7 @@ SettingsLock.prototype = {
|
|||
};
|
||||
|
||||
function SettingsManager() {
|
||||
this._locks = new Queue();
|
||||
this._settingsDB = new SettingsDB();
|
||||
this._settingsDB.init();
|
||||
}
|
||||
|
@ -274,6 +263,13 @@ SettingsManager.prototype = {
|
|||
return Cu.cloneInto(obj, this._window);
|
||||
},
|
||||
|
||||
nextTick: function nextTick(aCallback, thisObj) {
|
||||
if (thisObj)
|
||||
aCallback = aCallback.bind(thisObj);
|
||||
|
||||
Services.tm.currentThread.dispatch(aCallback, Ci.nsIThread.DISPATCH_NORMAL);
|
||||
},
|
||||
|
||||
set onsettingchange(aHandler) {
|
||||
this.__DOM_IMPL__.setEventHandler("onsettingchange", aHandler);
|
||||
},
|
||||
|
@ -285,10 +281,12 @@ SettingsManager.prototype = {
|
|||
createLock: function() {
|
||||
if (DEBUG) debug("get lock!");
|
||||
var lock = new SettingsLock(this);
|
||||
this._locks.enqueue(lock);
|
||||
this._settingsDB.ensureDB(
|
||||
function() { lock.createTransactionAndProcess(); },
|
||||
function() { dump("Cannot open Settings DB. Trying to open an old version?\n"); }
|
||||
);
|
||||
this.nextTick(function() { this._open = false; }, lock);
|
||||
return lock;
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче