Restore Sleep/Wake timer that was erroneously removed.

master
Fedor 2020-12-23 03:02:53 +02:00
parent 7823ac1d4c
commit 2ee57d93d2
2 changed files with 30 additions and 0 deletions

View File

@ -121,6 +121,7 @@ nsSocketTransportService::nsSocketTransportService()
, mServingPendingQueue(false) , mServingPendingQueue(false)
, mMaxTimePerPollIter(100) , mMaxTimePerPollIter(100)
, mMaxTimeForPrClosePref(PR_SecondsToInterval(5)) , mMaxTimeForPrClosePref(PR_SecondsToInterval(5))
, mSleepPhase(false)
, mProbedMaxCount(false) , mProbedMaxCount(false)
#if defined(XP_WIN) #if defined(XP_WIN)
, mPolling(false) , mPolling(false)
@ -562,6 +563,8 @@ nsSocketTransportService::Init()
if (obsSvc) { if (obsSvc) {
obsSvc->AddObserver(this, "profile-initial-state", false); obsSvc->AddObserver(this, "profile-initial-state", false);
obsSvc->AddObserver(this, "last-pb-context-exited", false); obsSvc->AddObserver(this, "last-pb-context-exited", false);
obsSvc->AddObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC, true);
obsSvc->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true);
obsSvc->AddObserver(this, "xpcom-shutdown-threads", false); obsSvc->AddObserver(this, "xpcom-shutdown-threads", false);
} }
@ -628,9 +631,16 @@ nsSocketTransportService::ShutdownThread()
if (obsSvc) { if (obsSvc) {
obsSvc->RemoveObserver(this, "profile-initial-state"); obsSvc->RemoveObserver(this, "profile-initial-state");
obsSvc->RemoveObserver(this, "last-pb-context-exited"); obsSvc->RemoveObserver(this, "last-pb-context-exited");
obsSvc->RemoveObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC);
obsSvc->RemoveObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC);
obsSvc->RemoveObserver(this, "xpcom-shutdown-threads"); obsSvc->RemoveObserver(this, "xpcom-shutdown-threads");
} }
if (mAfterWakeUpTimer) {
mAfterWakeUpTimer->Cancel();
mAfterWakeUpTimer = nullptr;
}
NetworkActivityMonitor::Shutdown(); NetworkActivityMonitor::Shutdown();
mInitialized = false; mInitialized = false;
@ -1228,6 +1238,10 @@ nsSocketTransportService::Observe(nsISupports *subject,
if (!strcmp(topic, NS_TIMER_CALLBACK_TOPIC)) { if (!strcmp(topic, NS_TIMER_CALLBACK_TOPIC)) {
nsCOMPtr<nsITimer> timer = do_QueryInterface(subject); nsCOMPtr<nsITimer> timer = do_QueryInterface(subject);
if (timer == mAfterWakeUpTimer) {
mAfterWakeUpTimer = nullptr;
mSleepPhase = false;
}
#if defined(XP_WIN) #if defined(XP_WIN)
if (timer == mPollRepairTimer) { if (timer == mPollRepairTimer) {
@ -1235,6 +1249,19 @@ nsSocketTransportService::Observe(nsISupports *subject,
} }
#endif #endif
} else if (!strcmp(topic, NS_WIDGET_SLEEP_OBSERVER_TOPIC)) {
mSleepPhase = true;
if (mAfterWakeUpTimer) {
mAfterWakeUpTimer->Cancel();
mAfterWakeUpTimer = nullptr;
}
} else if (!strcmp(topic, NS_WIDGET_WAKE_OBSERVER_TOPIC)) {
if (mSleepPhase && !mAfterWakeUpTimer) {
mAfterWakeUpTimer = do_CreateInstance("@mozilla.org/timer;1");
if (mAfterWakeUpTimer) {
mAfterWakeUpTimer->Init(this, 2000, nsITimer::TYPE_ONE_SHOT);
}
}
} else if (!strcmp(topic, "xpcom-shutdown-threads")) { } else if (!strcmp(topic, "xpcom-shutdown-threads")) {
ShutdownThread(); ShutdownThread();
} }

View File

@ -258,6 +258,9 @@ private:
Atomic<int32_t, Relaxed> mMaxTimePerPollIter; Atomic<int32_t, Relaxed> mMaxTimePerPollIter;
Atomic<PRIntervalTime, Relaxed> mMaxTimeForPrClosePref; Atomic<PRIntervalTime, Relaxed> mMaxTimeForPrClosePref;
Atomic<bool, Relaxed> mSleepPhase;
nsCOMPtr<nsITimer> mAfterWakeUpTimer;
void OnKeepaliveEnabledPrefChange(); void OnKeepaliveEnabledPrefChange();
void NotifyKeepaliveEnabledPrefChange(SocketContext *sock); void NotifyKeepaliveEnabledPrefChange(SocketContext *sock);