From b9bfc1ea31470a6ba12f1cf46b4963e32bb0d4b4 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Wed, 11 Jun 2008 18:47:56 -0700 Subject: [PATCH 1/6] numChanged should be the number of shared items whose data is different, not the same --- services/sync/modules/engines/tabs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/sync/modules/engines/tabs.js b/services/sync/modules/engines/tabs.js index 9ebae8da490a..194210e4dac9 100644 --- a/services/sync/modules/engines/tabs.js +++ b/services/sync/modules/engines/tabs.js @@ -460,7 +460,7 @@ TabTracker.prototype = { return 0; // The number of shared items whose data is different. - let numChanged = c.filter(function(v) v).length; + let numChanged = c.filter(function(v) !v).length; let fractionSimilar = (numShared - (numChanged / 2)) / numTotal; let fractionDissimilar = 1 - fractionSimilar; From 7233ee2c1480c3828e45f57b6016483dafee68dc Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Wed, 11 Jun 2008 20:00:48 -0700 Subject: [PATCH 2/6] don't sync tab entry IDs, which change with every session, to avoid generating edit commands for every tab on restart even when the tabs haven't actually changed --- services/sync/modules/engines/tabs.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/sync/modules/engines/tabs.js b/services/sync/modules/engines/tabs.js index 194210e4dac9..893ba5a75473 100644 --- a/services/sync/modules/engines/tabs.js +++ b/services/sync/modules/engines/tabs.js @@ -349,6 +349,13 @@ TabStore.prototype = { let tabID = currentEntry.url; this._log.debug("_wrapRealTabs: tab " + tabID); + // The ID property of each entry in the tab, which I think contains + // nsISHEntry::ID, changes every time session store restores the tab, + // so we can't sync them, or we would generate edit commands on every + // restart (even though nothing has actually changed). + for each (let entry in tab.entries) + delete entry.ID; + items[tabID] = { // Identify this item as a tab in case we start serializing windows // in the future. From 3087d30c1b049a271f97de381b87a0c39f568580 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Wed, 11 Jun 2008 20:07:35 -0700 Subject: [PATCH 3/6] only retrieve score once per engine when doing a scheduled sync, since retrieving the score can be a non-negligible cost for trackers that calculate the score on-demand (like the tab tracker) --- services/sync/modules/service.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index 290310a6dd2b..1501a9fb7df3 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -566,8 +566,9 @@ WeaveSvc.prototype = { if (!(engine.name in this._syncThresholds)) this._syncThresholds[engine.name] = INITIAL_THRESHOLD; - if (engine._tracker.score >= this._syncThresholds[engine.name]) { - this._log.debug(engine.name + " score " + engine._tracker.score + + let score = engine._tracker.score; + if (score >= this._syncThresholds[engine.name]) { + this._log.debug(engine.name + " score " + score + " reaches threshold " + this._syncThresholds[engine.name] + "; syncing"); this._notify(engine.name + "-engine:sync", @@ -589,7 +590,7 @@ WeaveSvc.prototype = { } } else { - this._log.debug(engine.name + " score " + engine._tracker.score + + this._log.debug(engine.name + " score " + score + " does not reach threshold " + this._syncThresholds[engine.name] + "; not syncing"); From b60c082c900392ddc834ede9f0f44a2a92b7c06a Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Thu, 12 Jun 2008 12:00:19 -0700 Subject: [PATCH 4/6] Changed some of the debug() logging statements I added a few commits ago into trace() statemetns b/c they were drowning the log. --- services/sync/modules/async.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/services/sync/modules/async.js b/services/sync/modules/async.js index 2c4d7f38ee33..619de53e7579 100644 --- a/services/sync/modules/async.js +++ b/services/sync/modules/async.js @@ -93,8 +93,7 @@ Generator.prototype = { get cb() { let caller = Components.stack.caller; this._outstandingCbs++; - this._log.debug(this.name + - ": self.cb generated at " + + this._log.trace(this.name + ": self.cb generated at " + caller.filename + ":" + caller.lineNumber); let self = this, cb = function(data) { self.cont(data); }; cb.parentGenerator = this; @@ -135,7 +134,7 @@ Generator.prototype = { _handleException: function AsyncGen__handleException(e) { if (e instanceof StopIteration) { - this._log.debug(this.name + ": End of coroutine reached."); + this._log.trace(this.name + ": End of coroutine reached."); // skip to calling done() } else if (this.onComplete.parentGenerator instanceof Generator) { @@ -190,7 +189,7 @@ Generator.prototype = { cont: function AsyncGen_cont(data) { this._outstandingCbs--; - this._log.debug(this.name + ": self.cb() called, resuming coroutine."); + this._log.trace(this.name + ": self.cb() called, resuming coroutine."); this._continued = true; try { this.generator.send(data); @@ -221,7 +220,7 @@ Generator.prototype = { return; let self = this; let cb = function() { self._done(retval); }; - this._log.debug(this.name + ": done() called."); + this._log.trace(this.name + ": done() called."); if (this._outstandingCbs > 0) this._log.warn("Async method '" + this.name + "' may have outstanding callbacks."); From 8194366c430a1ae95476590fbc3be959ab4bef5f Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Thu, 12 Jun 2008 12:36:58 -0700 Subject: [PATCH 5/6] bug 410550: stop running scheduled sync when the user is not logged into weave --- services/sync/modules/service.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index 1501a9fb7df3..063a06d02698 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -19,6 +19,7 @@ * * Contributor(s): * Dan Mills + * Myk Melez * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -130,8 +131,6 @@ function WeaveSvc() { this._log.info("Weave Sync disabled"); return; } - - this._setSchedule(this.schedule); } WeaveSvc.prototype = { @@ -139,6 +138,7 @@ WeaveSvc.prototype = { _lock: Wrap.lock, _localLock: Wrap.localLock, _osPrefix: "weave:service:", + _loggedIn: false, __os: null, get _os() { @@ -464,11 +464,14 @@ WeaveSvc.prototype = { this._loggedIn = true; + this._setSchedule(this.schedule); + self.done(true); }, logout: function WeaveSync_logout() { this._log.info("Logging out"); + this._disableSchedule(); this._loggedIn = false; ID.get('WeaveID').setTempPassword(null); // clear cached password ID.get('WeaveCryptoID').setTempPassword(null); // and passphrase From 815dae2a8583d0553bce214713f470ca9c3a073e Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Thu, 12 Jun 2008 16:23:59 -0700 Subject: [PATCH 6/6] work around XmlHttpRequest bug 317600 by pausing for a 0ms timeout before trying to log in --- services/sync/modules/service.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index 063a06d02698..ed2bbe9b08b8 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -427,6 +427,15 @@ WeaveSvc.prototype = { _login: function WeaveSync__login(password, passphrase) { let self = yield; + // XmlHttpRequests fail when the window that triggers them goes away + // because of bug 317600, and the first XmlHttpRequest we do happens + // just before the login dialog closes itself (for logins prompted by + // that dialog), so it triggers the bug. To work around it, we pause + // here and then continue after a 0ms timeout. + let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); + timer.initWithCallback({ notify: self.cb }, 0, Ci.nsITimer.TYPE_ONE_SHOT); + yield; + // cache password & passphrase // if null, we'll try to get them from the pw manager below ID.get('WeaveID').setTempPassword(password);