Bug 586094 - Enabling Sync regresses Ts on all platforms, r=dolske, a=beltzner

This commit is contained in:
Mike Connor 2010-08-11 21:28:27 -04:00
Родитель f60b3853b6
Коммит 3f6330cd7d
4 изменённых файлов: 106 добавлений и 54 удалений

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

@ -594,7 +594,11 @@
<menu id="tools-menu"
label="&toolsMenu.label;"
accesskey="&toolsMenu.accesskey;">
<menupopup id="menu_ToolsPopup">
<menupopup id="menu_ToolsPopup"
#ifdef MOZ_SERVICES_SYNC
onpopupshowing="gSyncUI.updateUI();"
#endif
>
<menuitem id="menu_search"
label="&search.label;"
accesskey="&search.accesskey;"

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

@ -40,37 +40,31 @@
// gSyncUI handles updating the tools menu
let gSyncUI = {
init: function SUI_init() {
let obs = [["weave:service:sync:start", "onActivityStart"],
["weave:service:sync:finish", "onSyncFinish"],
["weave:service:sync:error", "onSyncError"],
["weave:service:sync:delayed", "onSyncDelay"],
["weave:service:setup-complete", "onLoginFinish"],
["weave:service:login:start", "onActivityStart"],
["weave:service:login:finish", "onLoginFinish"],
["weave:service:login:error", "onLoginError"],
["weave:service:logout:finish", "onLogout"],
["weave:service:start-over", "onStartOver"]];
// this will be the first notification fired during init
// we can set up everything else later
Services.obs.addObserver(this, "weave:service:ready", true);
},
initUI: function SUI_initUI() {
let obs = ["weave:service:sync:start",
"weave:service:sync:finish",
"weave:service:sync:error",
"weave:service:sync:delayed",
"weave:service:setup-complete",
"weave:service:login:start",
"weave:service:login:finish",
"weave:service:login:error",
"weave:service:logout:finish",
"weave:service:start-over"];
// If this is a browser window?
if (gBrowser) {
obs.push(["weave:notification:added", "onNotificationAdded"],
["weave:notification:removed", "onNotificationRemoved"]);
obs.push("weave:notification:added", "weave:notification:removed");
}
// Add the observers now and remove them on unload
let self = this;
let addRem = function(add) {
obs.forEach(function([topic, func]) {
//XXXzpao This should use Services.obs.* but Weave's Obs does nice handling
// of `this`. Fix in a followup. (bug 583347)
if (add)
Weave.Svc.Obs.add(topic, self[func], self);
else
Weave.Svc.Obs.remove(topic, self[func], self);
});
};
addRem(true);
window.addEventListener("unload", function() addRem(false), false);
obs.forEach(function(topic) {
Services.obs.addObserver(self, topic, true);
});
// Find the alltabs-popup, only if there is a gBrowser
if (gBrowser) {
@ -80,7 +74,6 @@ let gSyncUI = {
self.alltabsPopupShowing();
}, true);
}
this.updateUI();
},
@ -242,7 +235,6 @@ let gSyncUI = {
}
},
// Commands
doUpdateMenu: function SUI_doUpdateMenu(event) {
this._updateLastSyncItem();
@ -369,7 +361,50 @@ let gSyncUI = {
this.updateUI();
this._updateLastSyncItem();
}
},
observe: function SUI_observe(subject, topic, data) {
switch (topic) {
case "weave:service:sync:start":
this.onActivityStart();
break;
case "weave:service:sync:finish":
this.onSyncFinish();
break;
case "weave:service:sync:error":
this.onSyncError();
break;
case "weave:service:sync:delayed":
this.onSyncDelay();
break;
case "weave:service:setup-complete":
this.onLoginFinish();
break;
case "weave:service:login:start":
this.onActivityStart();
break;
case "weave:service:login:finish":
this.onLoginFinish();
break;
case "weave:service:login:error":
this.onLoginError();
break;
case "weave:service:logout:finish":
this.onLogout();
break;
case "weave:service:start-over":
this.onStartOver();
break;
case "weave:service:ready":
this.initUI();
break;
}
},
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIObserver,
Ci.nsISupportsWeakReference
])
};
XPCOMUtils.defineLazyGetter(gSyncUI, "_stringBundle", function() {

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

@ -1061,7 +1061,7 @@
onclick="if (event.button == 0 &amp;&amp; event.detail == 1) displaySecurityInfo();"/>
#ifdef MOZ_SERVICES_SYNC
<statusbarpanel id="sync-status-button"
class="statusbarpanel-iconic-text"
class="statusbarpanel-iconic"
image="chrome://browser/skin/sync-16.png"
label="&syncLogInItem.label;"
oncommand="gSyncUI.handleStatusbarButton();"

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

@ -128,6 +128,31 @@ BrowserGlue.prototype = {
Services.prefs.savePrefFile(null);
},
#ifdef MOZ_SERVICES_SYNC
_setSyncAutoconnectDelay: function BG__setSyncAutoconnectDelay() {
// Assume that a non-zero value for services.sync.autoconnectDelay should override
if (Services.prefs.prefHasUserValue("services.sync.autoconnectDelay")) {
let prefDelay = Services.prefs.getIntPref("services.sync.autoconnectDelay");
if (prefDelay > 0)
return;
}
// delays are in seconds
const MAX_DELAY = 300;
let delay = 3;
let enum = Services.wm.getEnumerator("navigator:browser");
while (enum.hasMoreElements()) {
delay += enum.getNext().gBrowser.tabs.length;
}
delay = delay <= MAX_DELAY ? delay : MAX_DELAY;
let syncTemp = {};
Cu.import("resource://services-sync/service.js", syncTemp);
syncTemp.Weave.Service.delayedAutoConnect(delay);
},
#endif
// nsIObserver implementation
observe: function BG_observe(subject, topic, data) {
switch (topic) {
@ -165,6 +190,11 @@ BrowserGlue.prototype = {
case "browser-lastwindow-close-granted":
this._setPrefToSaveSession();
break;
#endif
#ifdef MOZ_SERVICES_SYNC
case "weave:service:ready":
this._setSyncAutoconnectDelay();
break;
#endif
case "session-save":
this._setPrefToSaveSession(true);
@ -238,6 +268,9 @@ BrowserGlue.prototype = {
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
os.addObserver(this, "browser-lastwindow-close-requested", false);
os.addObserver(this, "browser-lastwindow-close-granted", false);
#endif
#ifdef MOZ_SERVICES_SYNC
os.addObserver(this, "weave:service:ready", false);
#endif
os.addObserver(this, "session-save", false);
os.addObserver(this, "places-init-complete", false);
@ -262,6 +295,9 @@ BrowserGlue.prototype = {
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
os.removeObserver(this, "browser-lastwindow-close-requested");
os.removeObserver(this, "browser-lastwindow-close-granted");
#endif
#ifdef MOZ_SERVICES_SYNC
os.removeObserver(this, "weave:service:ready", false);
#endif
os.removeObserver(this, "session-save");
if (this._isIdleObserver)
@ -385,29 +421,6 @@ BrowserGlue.prototype = {
temp.WinTaskbarJumpList.startup();
}
#endif
#endif
#ifdef MOZ_SERVICES_SYNC
// Assume that a non-zero value for services.sync.autoconnectDelay should override
if (Services.prefs.prefHasUserValue("services.sync.autoconnectDelay")) {
let prefDelay = Services.prefs.getIntPref("services.sync.autoconnectDelay");
if (prefDelay > 0)
return;
}
// delays are in seconds
const MAX_DELAY = 300;
let delay = 3;
let enum = Services.wm.getEnumerator("navigator:browser");
while (enum.hasMoreElements()) {
delay += enum.getNext().gBrowser.tabs.length;
}
delay = delay <= MAX_DELAY ? delay : MAX_DELAY;
let syncTemp = {};
Cu.import("resource://services-sync/service.js", syncTemp);
syncTemp.Weave.Service.delayedAutoConnect(delay);
#endif
},
@ -1387,7 +1400,7 @@ GeolocationPrompt.prototype = {
chromeWin.PopupNotifications.show(browser, "geolocation", message, "geo-notification-icon",
mainAction, secondaryActions);
},
}
};
var components = [BrowserGlue, GeolocationPrompt];