mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-22 23:27:30 +09:00
Fix timer overflow on converting from sec to msec in idleService
This commit is contained in:
parent
07df2cf12a
commit
640ededc60
1 changed files with 8 additions and 4 deletions
|
|
@ -46,6 +46,10 @@ using namespace mozilla;
|
||||||
// Number of seconds in a day.
|
// Number of seconds in a day.
|
||||||
#define SECONDS_PER_DAY 86400
|
#define SECONDS_PER_DAY 86400
|
||||||
|
|
||||||
|
// MAX_DELTA_SEC * 1000 should be less than UINT32_MAX to prevent overflow on
|
||||||
|
// converting from sec to msec
|
||||||
|
#define MAX_DELTA_SEC (SECONDS_PER_DAY * 10)
|
||||||
|
|
||||||
static PRLogModuleInfo *sLog = nullptr;
|
static PRLogModuleInfo *sLog = nullptr;
|
||||||
|
|
||||||
#define LOG_TAG "GeckoIdleService"
|
#define LOG_TAG "GeckoIdleService"
|
||||||
|
|
@ -391,7 +395,7 @@ nsIdleService::GetInstance()
|
||||||
|
|
||||||
nsIdleService::nsIdleService() : mCurrentlySetToTimeoutAt(TimeStamp()),
|
nsIdleService::nsIdleService() : mCurrentlySetToTimeoutAt(TimeStamp()),
|
||||||
mIdleObserverCount(0),
|
mIdleObserverCount(0),
|
||||||
mDeltaToNextIdleSwitchInS(UINT32_MAX),
|
mDeltaToNextIdleSwitchInS(MAX_DELTA_SEC),
|
||||||
mLastUserInteraction(TimeStamp::Now())
|
mLastUserInteraction(TimeStamp::Now())
|
||||||
{
|
{
|
||||||
if (sLog == nullptr)
|
if (sLog == nullptr)
|
||||||
|
|
@ -544,7 +548,7 @@ nsIdleService::ResetIdleTimeOut(uint32_t idleDeltaInMS)
|
||||||
|
|
||||||
// Mark all idle services as non-idle, and calculate the next idle timeout.
|
// Mark all idle services as non-idle, and calculate the next idle timeout.
|
||||||
nsCOMArray<nsIObserver> notifyList;
|
nsCOMArray<nsIObserver> notifyList;
|
||||||
mDeltaToNextIdleSwitchInS = UINT32_MAX;
|
mDeltaToNextIdleSwitchInS = MAX_DELTA_SEC;
|
||||||
|
|
||||||
// Loop through all listeners, and find any that have detected idle.
|
// Loop through all listeners, and find any that have detected idle.
|
||||||
for (uint32_t i = 0; i < mArrayListeners.Length(); i++) {
|
for (uint32_t i = 0; i < mArrayListeners.Length(); i++) {
|
||||||
|
|
@ -717,7 +721,7 @@ nsIdleService::IdleTimerCallback(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to initialise the time to the next idle switch.
|
// We need to initialise the time to the next idle switch.
|
||||||
mDeltaToNextIdleSwitchInS = UINT32_MAX;
|
mDeltaToNextIdleSwitchInS = MAX_DELTA_SEC;
|
||||||
|
|
||||||
// Create list of observers that should be notified.
|
// Create list of observers that should be notified.
|
||||||
nsCOMArray<nsIObserver> notifyList;
|
nsCOMArray<nsIObserver> notifyList;
|
||||||
|
|
@ -839,7 +843,7 @@ void
|
||||||
nsIdleService::ReconfigureTimer(void)
|
nsIdleService::ReconfigureTimer(void)
|
||||||
{
|
{
|
||||||
// Check if either someone is idle, or someone will become idle.
|
// Check if either someone is idle, or someone will become idle.
|
||||||
if ((mIdleObserverCount == 0) && UINT32_MAX == mDeltaToNextIdleSwitchInS) {
|
if ((mIdleObserverCount == 0) && MAX_DELTA_SEC == mDeltaToNextIdleSwitchInS) {
|
||||||
// If not, just let any existing timers run to completion
|
// If not, just let any existing timers run to completion
|
||||||
// And bail out.
|
// And bail out.
|
||||||
MOZ_LOG(sLog, LogLevel::Debug,
|
MOZ_LOG(sLog, LogLevel::Debug,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue