Bug 513944 - Weave should not load / do anything until it absolutely needs to

Weave already triggers on a late notification and puts itself on the event loop, so just additionally delay startup based on the number of open tabs (which will all be busy at startup).
This commit is contained in:
Edward Lee 2009-09-25 08:13:12 -07:00
Родитель d6af22e0ca
Коммит 0087e7aedb
2 изменённых файлов: 27 добавлений и 5 удалений

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

@ -62,7 +62,7 @@ WeaveService.prototype = {
*/
case "sessionstore-windows-restored":
Cu.import("resource://weave/service.js");
Weave.Utils.delay(function() Weave.Service.onStartup());
Weave.Service.onStartup();
break;
}
}

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

@ -303,14 +303,36 @@ WeaveSvc.prototype = {
onWindowOpened: function WeaveSvc__onWindowOpened() {
},
/**
* Prepare to initialize the rest of Weave after waiting a little bit
*/
onStartup: function onStartup() {
this._status = new StatusRecord();
this.status.service = STATUS_DELAYED;
// Figure out how many seconds to delay loading Weave based on the app
let wait = 0;
switch (Svc.AppInfo.ID) {
case FIREFOX_ID:
// Add one second delay for each tab in every window
let enum = Svc.WinMediator.getEnumerator("navigator:browser");
while (enum.hasMoreElements())
wait += enum.getNext().gBrowser.mTabs.length;
}
// Make sure we wait a little but but not too long in the worst case
wait = Math.ceil(Math.max(5, Math.min(20, wait)));
this._initLogs();
this._log.info("Loading Weave " + WEAVE_VERSION + " in " + wait + " sec.");
Utils.delay(this._onStartup, wait * 1000, this, "_startupTimer");
},
// one-time initialization like setting up observers and the like
// xxx we might need to split some of this out into something we can call
// again when username/server/etc changes
onStartup: function WeaveSvc_onStartup() {
this._initLogs();
this._log.info("Weave " + WEAVE_VERSION + " initializing");
_onStartup: function _onStartup() {
this._registerEngines();
this._status = new StatusRecord();
// Reset our sync id if we're upgrading, so sync knows to reset local data
if (WEAVE_VERSION != Svc.Prefs.get("lastversion")) {