engines now get the pbe identity directly from the identity manager; engines now know their 'enabled' status (pref); main service syncs *all* registered (enabled) engines

This commit is contained in:
Dan Mills 2008-04-15 17:21:34 -07:00
Родитель 1fa3e135bc
Коммит 9a24767ab7
3 изменённых файлов: 53 добавлений и 35 удалений

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

@ -102,6 +102,10 @@ Engine.prototype = {
get snapshotFile() { return this.serverPrefix + "snapshot.json"; },
get deltasFile() { return this.serverPrefix + "deltas.json"; },
get enabled() {
return Utils.prefs.getBoolPref("engine." + this.name);
},
__os: null,
get _os() {
if (!this.__os)
@ -143,10 +147,18 @@ Engine.prototype = {
this.__snapshot = value;
},
_init: function Engine__init(davCollection, pbeId) {
this._pbeId = pbeId;
this._engineId = new Identity(pbeId.realm + " - " + this.logName,
pbeId.username);
get _pbeId() {
let id = ID.get('Engine:PBE:' + this.name);
if (!id)
id = ID.get('Engine:PBE:default');
if (!id)
throw "No identity found for engine PBE!";
return id;
},
_init: function Engine__init() {
this._engineId = new Identity(this._pbeId.realm + " - " + this.logName,
this._pbeId.username);
this._log = Log4Moz.Service.getLogger("Service." + this.logName);
this._log.level =
Log4Moz.Level[Utils.prefs.getCharPref("log.logger.service.engine")];
@ -818,8 +830,8 @@ Engine.prototype = {
}
};
function BookmarksEngine(davCollection, pbeId) {
this._init(davCollection, pbeId);
function BookmarksEngine(pbeId) {
this._init(pbeId);
}
BookmarksEngine.prototype = {
get name() { return "bookmarks"; },
@ -929,8 +941,8 @@ BookmarksEngine.prototype = {
};
BookmarksEngine.prototype.__proto__ = new Engine();
function HistoryEngine(davCollection, pbeId) {
this._init(davCollection, pbeId);
function HistoryEngine(pbeId) {
this._init(pbeId);
}
HistoryEngine.prototype = {
get name() { return "history"; },
@ -953,8 +965,8 @@ HistoryEngine.prototype = {
};
HistoryEngine.prototype.__proto__ = new Engine();
function CookieEngine(davCollection, pbeId) {
this._init(davCollection, pbeId);
function CookieEngine(pbeId) {
this._init(pbeId);
}
CookieEngine.prototype = {
get name() { return "cookies"; },

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

@ -77,17 +77,21 @@ function WeaveSvc() {
this._initLogs();
this._log.info("Weave Sync Service Initializing");
// Create Weave identities (for logging in, and for encryption)
ID.set('WeaveID', new Identity('Mozilla Services Password', this.username));
ID.setAlias('WeaveID', 'DAV:default');
ID.set('WeaveCryptoID',
new Identity('Mozilla Services Encryption Passphrase', this.username));
//ID.setAlias('WeaveCryptoID', '...');
Engines.register(new BookmarksEngine(DAV, ID.get('WeaveCryptoID')));
Engines.register(new HistoryEngine(DAV, ID.get('WeaveCryptoID')));
Engines.register(new CookieEngine(DAV, ID.get('WeaveCryptoID')));
// Set up aliases for other modules to use our IDs
ID.setAlias('WeaveID', 'DAV:default');
ID.setAlias('WeaveCryptoID', 'Engine:PBE:default');
// Register built-in engines
Engines.register(new BookmarksEngine());
Engines.register(new HistoryEngine());
Engines.register(new CookieEngine());
// Other misc startup
Utils.prefs.addObserver("", this, false);
if (!this.enabled) {
@ -484,22 +488,18 @@ WeaveSvc.prototype = {
this._keyCheck.async(this, self.cb);
yield;
if (Utils.prefs.getBoolPref("bookmarks")) {
this._notify(Engines.get("bookmarks").name + "-engine:sync",
this._syncEngine, Engines.get("bookmarks")).async(this, self.cb);
yield;
Engines.get("bookmarks").syncMounts(self.cb); // FIXME
yield;
}
if (Utils.prefs.getBoolPref("history")) {
this._notify(Engines.get("history").name + "-engine:sync",
this._syncEngine, Engines.get("history")).async(this, self.cb);
yield;
}
if (Utils.prefs.getBoolPref("cookies")) {
this._notify(Engines.get("cookies").name + "-engine:sync",
this._syncEngine, Engines.get("cookies")).async(this, self.cb);
yield;
let engines = Engines.getAll();
for (let i = 0; i < engines.length; i++) {
if (engines[i].enabled) {
this._notify(engines[i].name + "-engine:sync",
this._syncEngine, engines[i]).async(this, self.cb);
engines[i].resetServer(self.cb);
yield;
if (engines[i].name == "bookmarks") { // FIXME
Engines.get("bookmarks").syncMounts(self.cb);
yield;
}
}
}
},
_syncEngine: function WeaveSvc__syncEngine(engine) {
@ -520,6 +520,8 @@ WeaveSvc.prototype = {
let engines = Engines.getAll();
for (let i = 0; i < engines.length; i++) {
if (!engines[i].enabled)
continue;
engines[i].resetServer(self.cb);
yield;
}
@ -533,6 +535,8 @@ WeaveSvc.prototype = {
let self = yield;
let engines = Engines.getAll();
for (let i = 0; i < engines.length; i++) {
if (!engines[i].enabled)
continue;
engines[i].resetClient(self.cb);
yield;
}
@ -545,6 +549,8 @@ WeaveSvc.prototype = {
},
_shareBookmarks: function WeaveSync__shareBookmarks(username) {
let self = yield;
if (Engines.get("bookmarks").enabled)
return;
Engines.get("bookmarks").share(self.cb, username);
let ret = yield;
self.done(ret);

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

@ -11,10 +11,10 @@ pref("extensions.weave.ui.sharebookmarks", false);
pref("extensions.weave.rememberpassword", true);
pref("extensions.weave.autoconnect", true);
pref("extensions.weave.enabled", true);
pref("extensions.weave.bookmarks", true);
pref("extensions.weave.history", true);
pref("extensions.weave.cookies", false );
pref("extensions.weave.schedule", 1);
pref("extensions.weave.engine.bookmarks", true);
pref("extensions.weave.engine.history", true);
pref("extensions.weave.engine.cookies", false );
pref("extensions.weave.log.appender.console", "Warn");
pref("extensions.weave.log.appender.dump", "Error");