Identity_getPassword: async + async/yield -> sync. Make onGetPassword take one cb to pass back the password.

This commit is contained in:
Edward Lee 2009-06-05 22:33:08 -07:00
Родитель 0fc24851c3
Коммит b2645b621a
2 изменённых файлов: 8 добавлений и 21 удалений

Просмотреть файл

@ -42,11 +42,9 @@ const Cr = Components.results;
const Cu = Components.utils; const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://weave/ext/Sync.js");
Cu.import("resource://weave/constants.js"); Cu.import("resource://weave/constants.js");
Cu.import("resource://weave/util.js"); Cu.import("resource://weave/util.js");
Cu.import("resource://weave/async.js");
Function.prototype.async = Async.sugar;
Utils.lazy(this, 'ID', IDManager); Utils.lazy(this, 'ID', IDManager);
@ -136,26 +134,15 @@ Identity.prototype = {
}, },
// we'll call this if set to call out to the ui to prompt the user // we'll call this if set to call out to the ui to prompt the user
// note:the ui is expected to set the password/setTempPassword // This function takes a callback function to pass back the password
// note2: callback must be an async.js style generator function
onGetPassword: null, onGetPassword: null,
// Attempts to get the password from the user if not set // Attempts to get the password from the user if not set
_getPassword: function Id__getPassword() { getPassword: function Identity_getPassword() {
let self = yield;
let pass;
if (this.password) if (this.password)
pass = this.password; return this.password;
else {
if (this.onGetPassword) { if (typeof this.onGetPassword == "function")
yield Async.run(this, this.onGetPassword, self.cb, this); return this.password = Sync(this.onGetPassword)();
pass = this.password; // retry after ui callback
}
}
self.done(pass);
},
getPassword: function Id_getPassword(onComplete) {
this._getPassword.async(this, onComplete);
} }
}; };

Просмотреть файл

@ -752,7 +752,7 @@ WeaveSvc.prototype = {
this._log.info("Server data wiped to ensure consistency due to missing keys"); this._log.info("Server data wiped to ensure consistency due to missing keys");
} }
let pass = yield ID.get('WeaveCryptoID').getPassword(self.cb); let pass = ID.get("WeaveCryptoID").getPassword();
if (pass) { if (pass) {
let keys = PubKeys.createKeypair(pass, PubKeys.defaultKeyUri, let keys = PubKeys.createKeypair(pass, PubKeys.defaultKeyUri,
PrivKeys.defaultKeyUri); PrivKeys.defaultKeyUri);