diff options
author | Moonchild <moonchild@palemoon.org> | 2020-12-16 06:36:21 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-12-16 07:41:43 +0000 |
commit | 0ea6dd009f7fa59c21fb56deb82a96595b78ab3c (patch) | |
tree | b6247f4e62ff20f7118e972ba5f3eb2a6d07bd1d | |
parent | cd17592001225e2d988c3aca9bd700de3c8ce4a3 (diff) | |
download | UXP-0ea6dd009f7fa59c21fb56deb82a96595b78ab3c.tar UXP-0ea6dd009f7fa59c21fb56deb82a96595b78ab3c.tar.gz UXP-0ea6dd009f7fa59c21fb56deb82a96595b78ab3c.tar.lz UXP-0ea6dd009f7fa59c21fb56deb82a96595b78ab3c.tar.xz UXP-0ea6dd009f7fa59c21fb56deb82a96595b78ab3c.zip |
Issue #1695 - Restore Sleep/Wake timer that was erroneously removed.
This was fallout from PR #929 for Issue #21
-rw-r--r-- | netwerk/base/nsSocketTransportService2.cpp | 27 | ||||
-rw-r--r-- | netwerk/base/nsSocketTransportService2.h | 3 |
2 files changed, 30 insertions, 0 deletions
diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 956332953..4112d24e9 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -123,6 +123,7 @@ nsSocketTransportService::nsSocketTransportService() , mMaxTimePerPollIter(100) , mClampSocketTimeout(false) , mMaxTimeForPrClosePref(PR_SecondsToInterval(5)) + , mSleepPhase(false) , mProbedMaxCount(false) #if defined(XP_WIN) , mPolling(false) @@ -572,6 +573,8 @@ nsSocketTransportService::Init() if (obsSvc) { obsSvc->AddObserver(this, "profile-initial-state", 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); } @@ -638,9 +641,16 @@ nsSocketTransportService::ShutdownThread() if (obsSvc) { obsSvc->RemoveObserver(this, "profile-initial-state"); 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"); } + if (mAfterWakeUpTimer) { + mAfterWakeUpTimer->Cancel(); + mAfterWakeUpTimer = nullptr; + } + NetworkActivityMonitor::Shutdown(); mInitialized = false; @@ -1245,6 +1255,10 @@ nsSocketTransportService::Observe(nsISupports *subject, if (!strcmp(topic, NS_TIMER_CALLBACK_TOPIC)) { nsCOMPtr<nsITimer> timer = do_QueryInterface(subject); + if (timer == mAfterWakeUpTimer) { + mAfterWakeUpTimer = nullptr; + mSleepPhase = false; + } #if defined(XP_WIN) if (timer == mPollRepairTimer) { @@ -1252,6 +1266,19 @@ nsSocketTransportService::Observe(nsISupports *subject, } #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")) { ShutdownThread(); } diff --git a/netwerk/base/nsSocketTransportService2.h b/netwerk/base/nsSocketTransportService2.h index 9360dd905..c0f9b0075 100644 --- a/netwerk/base/nsSocketTransportService2.h +++ b/netwerk/base/nsSocketTransportService2.h @@ -263,6 +263,9 @@ private: Atomic<int32_t, Relaxed> mMaxTimePerPollIter; Atomic<PRIntervalTime, Relaxed> mMaxTimeForPrClosePref; + Atomic<bool, Relaxed> mSleepPhase; + nsCOMPtr<nsITimer> mAfterWakeUpTimer; + void OnKeepaliveEnabledPrefChange(); void NotifyKeepaliveEnabledPrefChange(SocketContext *sock); |