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;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://weave/ext/Sync.js");
Cu.import("resource://weave/constants.js");
Cu.import("resource://weave/util.js");
Cu.import("resource://weave/async.js");
Function.prototype.async = Async.sugar;
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
// note:the ui is expected to set the password/setTempPassword
// note2: callback must be an async.js style generator function
// This function takes a callback function to pass back the password
onGetPassword: null,
// Attempts to get the password from the user if not set
_getPassword: function Id__getPassword() {
let self = yield;
let pass;
getPassword: function Identity_getPassword() {
if (this.password)
pass = this.password;
else {
if (this.onGetPassword) {
yield Async.run(this, this.onGetPassword, self.cb, this);
pass = this.password; // retry after ui callback
}
}
self.done(pass);
},
getPassword: function Id_getPassword(onComplete) {
this._getPassword.async(this, onComplete);
return this.password;
if (typeof this.onGetPassword == "function")
return this.password = Sync(this.onGetPassword)();
}
};

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

@ -752,7 +752,7 @@ WeaveSvc.prototype = {
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) {
let keys = PubKeys.createKeypair(pass, PubKeys.defaultKeyUri,
PrivKeys.defaultKeyUri);