Bug 298705 - live bookmarks should only refresh when browser is active r=mano@mozilla.com (Asaf Romano) Toolkit only, no approval needed.

This commit is contained in:
gijskruitbosch@gmail.com 2007-08-31 13:33:54 -07:00
parent e507924848
commit 9228e23715

View File

@ -78,6 +78,7 @@ const FAV_CONTRACTID = "@mozilla.org/browser/favicon-service;1";
const LG_CONTRACTID = "@mozilla.org/network/load-group;1";
const FP_CONTRACTID = "@mozilla.org/feed-processor;1";
const SEC_CONTRACTID = "@mozilla.org/scriptsecuritymanager;1";
const IS_CONTRACTID = "@mozilla.org/widget/idleservice;1";
const SEC_FLAGS = Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL;
// Check every hour by default
@ -86,6 +87,9 @@ var gExpiration = 3600000;
// Check every 10 minutes on error
const ERROR_EXPIRATION = 600000;
// Don't check when the user is idle for longer than half an hour:
const IDLE_TIMELIMIT = 1800000;
var gIoService = Cc[IO_CONTRACTID].getService(Ci.nsIIOService);
var gStringBundle;
function GetString(name)
@ -131,6 +135,9 @@ function LivemarkService() {
new G_Alarm(BindToObject(this._fireTimer, this), LIVEMARK_TIMEOUT,
true /* repeat */);
if (IS_CONTRACTID in Cc)
this._idleService = Cc[IS_CONTRACTID].getService(Ci.nsIIdleService);
// this is giving a reentrant getService warning in XPCShell. bug 194568.
this._ans = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService);
@ -220,7 +227,20 @@ LivemarkService.prototype = {
livemark.locked = false;
return;
}
}
// Check the user idle time. If the user isn't using their computer, don't
// bother updating - save the internet some bandwidth. If we can't
// get the idle time, assume the user isn't idle.
var idleTime = 0;
try {
idleTime = this._idleService.idleTime;
} catch (ex) { /* We don't care */ }
if (idleTime > IDLE_TIMELIMIT)
{
livemark.locked = false;
return;
}
}
catch (ex) {
// This livemark has never been loaded, since it has no expire time.
this.insertLivemarkLoadingItem(this._bms, livemark);