mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 09:15:35 +00:00
Wrap.notify now takes the topic prefix as an argument, instead of requiring this._osPrefix to be set; use Observers.js in several places (sync.js, status.js, etc); some event topics have changed, beware; fix up status window, now prints some useful status as sync progresses
This commit is contained in:
parent
9754fd15ca
commit
34b3a01ca1
@ -9,7 +9,9 @@ status.closing = Closing...
|
||||
status.locked = Server Busy
|
||||
status.tryagain = Please try again in a few minutes.
|
||||
|
||||
status.engine_start = Starting Sync
|
||||
status.engine.start = Starting Sync
|
||||
status.engine.process-incoming = Processing Incoming Items
|
||||
status.engine.upload-outgoing = Uploading Outgoing Items
|
||||
|
||||
status.downloading-status = Downloading Status from Server
|
||||
status.uploading-status = Updating Status on Server
|
||||
|
@ -43,6 +43,7 @@ const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://weave/ext/Observers.js");
|
||||
Cu.import("resource://weave/log4moz.js");
|
||||
Cu.import("resource://weave/constants.js");
|
||||
Cu.import("resource://weave/util.js");
|
||||
@ -99,8 +100,6 @@ EngineManagerSvc.prototype = {
|
||||
|
||||
function Engine() { this._init(); }
|
||||
Engine.prototype = {
|
||||
_notify: Wrap.notify,
|
||||
|
||||
name: "engine",
|
||||
displayName: "Boring Engine",
|
||||
logName: "Engine",
|
||||
@ -138,9 +137,9 @@ Engine.prototype = {
|
||||
try { level = Utils.prefs.getCharPref(levelPref); }
|
||||
catch (e) { /* ignore unset prefs */ }
|
||||
|
||||
this._notify = Wrap.notify("weave:engine:");
|
||||
this._log = Log4Moz.repository.getLogger("Engine." + this.logName);
|
||||
this._log.level = Log4Moz.Level[level];
|
||||
this._osPrefix = "weave:" + this.name + "-engine:";
|
||||
|
||||
this._tracker; // initialize tracker to load previously changed IDs
|
||||
this._log.debug("Engine initialized");
|
||||
@ -149,13 +148,13 @@ Engine.prototype = {
|
||||
sync: function Engine_sync(onComplete) {
|
||||
if (!this._sync)
|
||||
throw "engine does not implement _sync method";
|
||||
this._notify("sync", "", this._sync).async(this, onComplete);
|
||||
this._notify("sync", this.name, this._sync).async(this, onComplete);
|
||||
},
|
||||
|
||||
wipeServer: function Engimne_wipeServer(onComplete) {
|
||||
if (!this._wipeServer)
|
||||
throw "engine does not implement _wipeServer method";
|
||||
this._notify("wipe-server", "", this._wipeServer).async(this, onComplete);
|
||||
this._notify("wipe-server", this.name, this._wipeServer).async(this, onComplete);
|
||||
},
|
||||
|
||||
_wipeClient: function Engine__wipeClient() {
|
||||
@ -164,7 +163,7 @@ Engine.prototype = {
|
||||
this._store.wipe();
|
||||
},
|
||||
wipeClient: function Engine_wipeClient(onComplete) {
|
||||
this._notify("wipe-client", "", this._wipeClient).async(this, onComplete);
|
||||
this._notify("wipe-client", this.name, this._wipeClient).async(this, onComplete);
|
||||
}
|
||||
};
|
||||
|
||||
@ -470,7 +469,9 @@ SyncEngine.prototype = {
|
||||
|
||||
try {
|
||||
yield this._syncStartup.async(this, self.cb);
|
||||
Observers.notify("weave:engine:sync:status", "process-incoming");
|
||||
yield this._processIncoming.async(this, self.cb);
|
||||
Observers.notify("weave:engine:sync:status", "upload-outgoing");
|
||||
yield this._uploadOutgoing.async(this, self.cb);
|
||||
yield this._syncFinish.async(this, self.cb);
|
||||
}
|
||||
|
@ -338,14 +338,12 @@ JsonFilter.prototype = {
|
||||
beforePUT: function JsonFilter_beforePUT(data) {
|
||||
let self = yield;
|
||||
this._log.trace("Encoding data as JSON");
|
||||
Observers.notify("weave:service:sync:status", null, "stats.encoding-json");
|
||||
self.done(this._json.encode(data));
|
||||
},
|
||||
|
||||
afterGET: function JsonFilter_afterGET(data) {
|
||||
let self = yield;
|
||||
this._log.trace("Decoding JSON data");
|
||||
Observers.notify("weave:service:sync:status", null, "stats.decoding-json");
|
||||
self.done(this._json.decode(data));
|
||||
}
|
||||
};
|
||||
|
@ -107,13 +107,13 @@ Utils.lazy(Weave, 'Service', WeaveSvc);
|
||||
* Main entry point into Weave's sync framework
|
||||
*/
|
||||
|
||||
function WeaveSvc() {}
|
||||
function WeaveSvc() {
|
||||
this._notify = Wrap.notify("weave:service:");
|
||||
}
|
||||
WeaveSvc.prototype = {
|
||||
|
||||
_notify: Wrap.notify,
|
||||
_localLock: Wrap.localLock,
|
||||
_catchAll: Wrap.catchAll,
|
||||
_osPrefix: "weave:service:",
|
||||
_isQuitting: false,
|
||||
_loggedIn: false,
|
||||
_syncInProgress: false,
|
||||
@ -550,7 +550,7 @@ WeaveSvc.prototype = {
|
||||
this._keyPair = {};
|
||||
ID.get('WeaveID').setTempPassword(null); // clear cached password
|
||||
ID.get('WeaveCryptoID').setTempPassword(null); // and passphrase
|
||||
this._os.notifyObservers(null, "weave:service:logout:success", "");
|
||||
this._os.notifyObservers(null, "weave:service:logout:finish", "");
|
||||
},
|
||||
|
||||
serverWipe: function WeaveSvc_serverWipe(onComplete) {
|
||||
|
@ -42,6 +42,7 @@ const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://weave/ext/Observers.js");
|
||||
Cu.import("resource://weave/log4moz.js");
|
||||
Cu.import("resource://weave/async.js");
|
||||
Cu.import("resource://weave/util.js");
|
||||
@ -59,54 +60,50 @@ Function.prototype.async = Async.sugar;
|
||||
|
||||
let Wrap = {
|
||||
|
||||
// NOTE: requires _osPrefix string property in your object
|
||||
// NOTE2: copy this function over to your objects, use like this:
|
||||
// NOTE: copy this function over to your objects, use like this:
|
||||
//
|
||||
// function MyObj() {
|
||||
// this._notify = Wrap.notify("some:prefix:");
|
||||
// }
|
||||
// MyObj.prototype = {
|
||||
// _notify: Wrap.notify,
|
||||
// ...
|
||||
// method: function MyMethod() {
|
||||
// let self = yield;
|
||||
// ...
|
||||
// // doFoo is assumed to be an asynchronous method
|
||||
// this._notify("foo", this._doFoo, arg1, arg2).async(this, self.cb);
|
||||
// this._notify("foo", "", this._doFoo, arg1, arg2).async(this, self.cb);
|
||||
// let ret = yield;
|
||||
// ...
|
||||
// }
|
||||
// };
|
||||
notify: function Weave_notify(name, payload, method /* , arg1, arg2, ..., argN */) {
|
||||
let savedName = name;
|
||||
let savedPayload = payload;
|
||||
let savedMethod = method;
|
||||
let savedArgs = Array.prototype.slice.call(arguments, 3);
|
||||
notify: function WeaveWrap_notify(prefix) {
|
||||
return function NotifyWrapMaker(name, subject, method) {
|
||||
let savedArgs = Array.prototype.slice.call(arguments, 4);
|
||||
return function NotifyWrap() {
|
||||
let self = yield;
|
||||
let ret;
|
||||
let args = Array.prototype.slice.call(arguments);
|
||||
|
||||
return function WeaveNotifyWrapper(/* argN+1, argN+2, ... */) {
|
||||
let self = yield;
|
||||
let ret;
|
||||
let args = Array.prototype.slice.call(arguments);
|
||||
try {
|
||||
this._log.debug("Event: " + prefix + name + ":start");
|
||||
Observers.notify(prefix + name + ":start", subject);
|
||||
|
||||
try {
|
||||
this._log.debug("Event: " + this._osPrefix + savedName + ":start");
|
||||
this._os.notifyObservers(null, this._osPrefix + savedName + ":start", savedPayload);
|
||||
this._os.notifyObservers(null, this._osPrefix + "global:start", savedPayload);
|
||||
args = savedArgs.concat(args);
|
||||
args.unshift(this, method, self.cb);
|
||||
Async.run.apply(Async, args);
|
||||
ret = yield;
|
||||
|
||||
args = savedArgs.concat(args);
|
||||
args.unshift(this, savedMethod, self.cb);
|
||||
Async.run.apply(Async, args);
|
||||
ret = yield;
|
||||
this._log.debug("Event: " + prefix + name + ":finish");
|
||||
let foo = Observers.notify(prefix + name + ":finish", subject);
|
||||
|
||||
this._log.debug("Event: " + this._osPrefix + savedName + ":success");
|
||||
this._os.notifyObservers(null, this._osPrefix + savedName + ":success", savedPayload);
|
||||
this._os.notifyObservers(null, this._osPrefix + "global:success", savedPayload);
|
||||
} catch (e) {
|
||||
this._log.debug("Event: " + prefix + name + ":error");
|
||||
Observers.notify(prefix + name + ":error", subject);
|
||||
throw e;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
this._log.debug("Event: " + this._osPrefix + savedName + ":error");
|
||||
this._os.notifyObservers(null, this._osPrefix + savedName + ":error", savedPayload);
|
||||
this._os.notifyObservers(null, this._osPrefix + "global:error", savedPayload);
|
||||
throw e;
|
||||
}
|
||||
|
||||
self.done(ret);
|
||||
self.done(ret);
|
||||
};
|
||||
};
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user