Issue #3061 - Remove network tickler.

Resolves #3061
This commit is contained in:
Moonchild committed 2026-07-19 08:17:05 +02:00
1 parent dfd0ea4e8a
commit 22d945430b
6 files changed
+1 -460

No files matched your search

+1 -1
View File
@@ -22,4 +22,4 @@
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
# don't change CLOBBER for WebIDL changes any more.
Clobber for Idle GC backout
Clobber for removal of network tickler
-277
View File
@@ -1,277 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Tickler.h"
#ifdef MOZ_USE_WIFI_TICKLER
#include "nsComponentManagerUtils.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "prnetdb.h"
#include "mozilla/jni/Utils.h"
#include "GeneratedJNIWrappers.h"
namespace mozilla {
namespace net {
NS_IMPL_ISUPPORTS(Tickler, nsISupportsWeakReference, Tickler)
Tickler::Tickler()
: mLock("Tickler::mLock")
, mActive(false)
, mCanceled(false)
, mEnabled(false)
, mDelay(16)
, mDuration(TimeDuration::FromMilliseconds(400))
, mFD(nullptr)
{
MOZ_ASSERT(NS_IsMainThread());
}
Tickler::~Tickler()
{
// non main thread uses of the tickler should hold weak
// references to it if they must hold a reference at all
MOZ_ASSERT(NS_IsMainThread());
if (mThread) {
mThread->AsyncShutdown();
mThread = nullptr;
}
if (mTimer)
mTimer->Cancel();
if (mFD)
PR_Close(mFD);
}
nsresult
Tickler::Init()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mTimer);
MOZ_ASSERT(!mActive);
MOZ_ASSERT(!mThread);
MOZ_ASSERT(!mFD);
if (jni::IsAvailable()) {
java::GeckoAppShell::EnableNetworkNotifications();
}
mFD = PR_OpenUDPSocket(PR_AF_INET);
if (!mFD)
return NS_ERROR_FAILURE;
// make sure new socket has a ttl of 1
// failure is not fatal.
PRSocketOptionData opt;
opt.option = PR_SockOpt_IpTimeToLive;
opt.value.ip_ttl = 1;
PR_SetSocketOption(mFD, &opt);
nsresult rv = NS_NewNamedThread("wifi tickler",
getter_AddRefs(mThread));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsITimer> tmpTimer(do_CreateInstance(NS_TIMER_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
rv = tmpTimer->SetTarget(mThread);
if (NS_FAILED(rv))
return rv;
mTimer.swap(tmpTimer);
mAddr.inet.family = PR_AF_INET;
mAddr.inet.port = PR_htons (4886);
mAddr.inet.ip = 0;
return NS_OK;
}
void Tickler::Tickle()
{
MutexAutoLock lock(mLock);
MOZ_ASSERT(mThread);
mLastTickle = TimeStamp::Now();
if (!mActive)
MaybeStartTickler();
}
void Tickler::PostCheckTickler()
{
mLock.AssertCurrentThreadOwns();
mThread->Dispatch(NewRunnableMethod(this, &Tickler::CheckTickler),
NS_DISPATCH_NORMAL);
return;
}
void Tickler::MaybeStartTicklerUnlocked()
{
MutexAutoLock lock(mLock);
MaybeStartTickler();
}
void Tickler::MaybeStartTickler()
{
mLock.AssertCurrentThreadOwns();
if (!NS_IsMainThread()) {
NS_DispatchToMainThread(
NewRunnableMethod(this, &Tickler::MaybeStartTicklerUnlocked));
return;
}
if (!mPrefs)
mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (mPrefs) {
int32_t val;
bool boolVal;
if (NS_SUCCEEDED(mPrefs->GetBoolPref("network.tickle-wifi.enabled", &boolVal)))
mEnabled = boolVal;
if (NS_SUCCEEDED(mPrefs->GetIntPref("network.tickle-wifi.duration", &val))) {
if (val < 1)
val = 1;
if (val > 100000)
val = 100000;
mDuration = TimeDuration::FromMilliseconds(val);
}
if (NS_SUCCEEDED(mPrefs->GetIntPref("network.tickle-wifi.delay", &val))) {
if (val < 1)
val = 1;
if (val > 1000)
val = 1000;
mDelay = static_cast<uint32_t>(val);
}
}
PostCheckTickler();
}
void Tickler::CheckTickler()
{
MutexAutoLock lock(mLock);
MOZ_ASSERT(mThread == NS_GetCurrentThread());
bool shouldRun = (!mCanceled) &&
((TimeStamp::Now() - mLastTickle) <= mDuration);
if ((shouldRun && mActive) || (!shouldRun && !mActive))
return; // no change in state
if (mActive)
StopTickler();
else
StartTickler();
}
void Tickler::Cancel()
{
MutexAutoLock lock(mLock);
MOZ_ASSERT(NS_IsMainThread());
mCanceled = true;
if (mThread)
PostCheckTickler();
}
void Tickler::StopTickler()
{
mLock.AssertCurrentThreadOwns();
MOZ_ASSERT(mThread == NS_GetCurrentThread());
MOZ_ASSERT(mTimer);
MOZ_ASSERT(mActive);
mTimer->Cancel();
mActive = false;
}
class TicklerTimer final : public nsITimerCallback
{
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSITIMERCALLBACK
TicklerTimer(Tickler *aTickler)
{
mTickler = do_GetWeakReference(aTickler);
}
private:
~TicklerTimer() {}
nsWeakPtr mTickler;
};
void Tickler::StartTickler()
{
mLock.AssertCurrentThreadOwns();
MOZ_ASSERT(mThread == NS_GetCurrentThread());
MOZ_ASSERT(!mActive);
MOZ_ASSERT(mTimer);
if (NS_SUCCEEDED(mTimer->InitWithCallback(new TicklerTimer(this),
mEnabled ? mDelay : 1000,
nsITimer::TYPE_REPEATING_SLACK)))
mActive = true;
}
// argument should be in network byte order
void Tickler::SetIPV4Address(uint32_t address)
{
mAddr.inet.ip = address;
}
// argument should be in network byte order
void Tickler::SetIPV4Port(uint16_t port)
{
mAddr.inet.port = port;
}
NS_IMPL_ISUPPORTS(TicklerTimer, nsITimerCallback)
NS_IMETHODIMP TicklerTimer::Notify(nsITimer *timer)
{
RefPtr<Tickler> tickler = do_QueryReferent(mTickler);
if (!tickler)
return NS_ERROR_FAILURE;
MutexAutoLock lock(tickler->mLock);
if (!tickler->mFD) {
tickler->StopTickler();
return NS_ERROR_FAILURE;
}
if (tickler->mCanceled ||
((TimeStamp::Now() - tickler->mLastTickle) > tickler->mDuration)) {
tickler->StopTickler();
return NS_OK;
}
if (!tickler->mEnabled)
return NS_OK;
PR_SendTo(tickler->mFD, "", 0, 0, &tickler->mAddr, 0);
return NS_OK;
}
} // namespace mozilla::net
} // namespace mozilla
#else // not defined MOZ_USE_WIFI_TICKLER
namespace mozilla {
namespace net {
NS_IMPL_ISUPPORTS0(Tickler)
} // namespace net
} // namespace mozilla
#endif // defined MOZ_USE_WIFI_TICKLER
-127
View File
@@ -1,127 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_net_Tickler_h
#define mozilla_net_Tickler_h
// The tickler sends a regular 0 byte UDP heartbeat out to a
// particular address for a short time after it has been touched. This
// is used on some mobile wifi chipsets to mitigate Power Save Polling
// (PSP) Mode when we are anticipating a response packet
// soon. Typically PSP adds 100ms of latency to a read event because
// the packet delivery is not triggered until the 802.11 beacon is
// delivered to the host (100ms is the standard Access Point
// configuration for the beacon interval.) Requesting a frequent
// transmission and getting a CTS frame from the AP at least that
// frequently allows for low latency receives when we have reason to
// expect them (e.g a SYN-ACK).
//
// The tickler is used to allow RTT based phases of web transport to
// complete quickly when on wifi - ARP, DNS, TCP handshake, SSL
// handshake, HTTP headers, and the TCP slow start phase. The
// transaction is given up to 400 miliseconds by default to get
// through those phases before the tickler is disabled.
//
// The tickler only applies to wifi on mobile right now. Hopefully it
// can also be restricted to particular handset models in the future.
#include "mozilla/Attributes.h"
#include "nsISupports.h"
#include <stdint.h>
#ifdef MOZ_USE_WIFI_TICKLER
#include "mozilla/Mutex.h"
#include "mozilla/TimeStamp.h"
#include "nsAutoPtr.h"
#include "nsISupports.h"
#include "nsIThread.h"
#include "nsITimer.h"
#include "nsWeakReference.h"
#include "prio.h"
class nsIPrefBranch;
#endif
namespace mozilla {
namespace net {
#ifdef MOZ_USE_WIFI_TICKLER
// 8f769ed6-207c-4af9-9f7e-9e832da3754e
#define NS_TICKLER_IID \
{ 0x8f769ed6, 0x207c, 0x4af9, \
{ 0x9f, 0x7e, 0x9e, 0x83, 0x2d, 0xa3, 0x75, 0x4e } }
class Tickler final : public nsSupportsWeakReference
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECLARE_STATIC_IID_ACCESSOR(NS_TICKLER_IID)
// These methods are main thread only
Tickler();
void Cancel();
nsresult Init();
void SetIPV4Address(uint32_t address);
void SetIPV4Port(uint16_t port);
// Tickle the tickler to (re-)start the activity.
// May call from any thread
void Tickle();
private:
~Tickler();
friend class TicklerTimer;
Mutex mLock;
nsCOMPtr<nsIThread> mThread;
nsCOMPtr<nsITimer> mTimer;
nsCOMPtr<nsIPrefBranch> mPrefs;
bool mActive;
bool mCanceled;
bool mEnabled;
uint32_t mDelay;
TimeDuration mDuration;
PRFileDesc* mFD;
TimeStamp mLastTickle;
PRNetAddr mAddr;
// These functions may be called from any thread
void PostCheckTickler();
void MaybeStartTickler();
void MaybeStartTicklerUnlocked();
// Tickler thread only
void CheckTickler();
void StartTickler();
void StopTickler();
};
NS_DEFINE_STATIC_IID_ACCESSOR(Tickler, NS_TICKLER_IID)
#else // not defined MOZ_USE_WIFI_TICKLER
class Tickler final : public nsISupports
{
~Tickler() { }
public:
NS_DECL_THREADSAFE_ISUPPORTS
Tickler() { }
nsresult Init() { return NS_ERROR_NOT_IMPLEMENTED; }
void Cancel() { }
void SetIPV4Address(uint32_t) { };
void SetIPV4Port(uint16_t) { }
void Tickle() { }
};
#endif // defined MOZ_USE_WIFI_TICKLER
} // namespace net
} // namespace mozilla
#endif // mozilla_net_Tickler_h
-1
View File
@@ -245,7 +245,6 @@ UNIFIED_SOURCES += [
'SimpleBuffer.cpp',
'StreamingProtocolService.cpp',
'ThrottleQueue.cpp',
'Tickler.cpp',
'TLSServerSocket.cpp',
]
-48
View File
@@ -34,7 +34,6 @@
#include "nsAlgorithm.h"
#include "ASpdySession.h"
#include "EventTokenBucket.h"
#include "Tickler.h"
#include "nsIXULAppInfo.h"
#include "nsICookieService.h"
#include "nsIObserverService.h"
@@ -396,9 +395,6 @@ nsHttpHandler::Init()
}
MakeNewRequestTokenBucket();
mWifiTickler = new Tickler();
if (NS_FAILED(mWifiTickler->Init()))
mWifiTickler = nullptr;
nsCOMPtr<nsIParentalControlsService> pc = do_CreateInstance("@mozilla.org/parental-controls-service;1");
if (pc) {
@@ -2124,8 +2120,6 @@ nsHttpHandler::Observe(nsISupports *subject,
// clear cache of all authentication credentials.
mAuthCache.ClearAll();
mPrivateAuthCache.ClearAll();
if (mWifiTickler)
mWifiTickler->Cancel();
// Inform nsIOService that network is tearing down.
gIOService->SetHttpHandlerAlreadyShutingDown();
@@ -2338,48 +2332,6 @@ nsHttpHandler::SpeculativeAnonymousConnect2(nsIURI *aURI,
return SpeculativeConnectInternal(aURI, aPrincipal, aCallbacks, true);
}
void
nsHttpHandler::TickleWifi(nsIInterfaceRequestor *cb)
{
if (!cb || !mWifiTickler)
return;
// If B2G requires a similar mechanism nsINetworkManager, currently only avail
// on B2G, contains the necessary information on wifi and gateway
nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(cb);
nsCOMPtr<nsPIDOMWindowOuter> piWindow = do_QueryInterface(domWindow);
if (!piWindow)
return;
nsCOMPtr<nsIDOMNavigator> domNavigator = piWindow->GetNavigator();
nsCOMPtr<nsIMozNavigatorNetwork> networkNavigator =
do_QueryInterface(domNavigator);
if (!networkNavigator)
return;
nsCOMPtr<nsINetworkProperties> networkProperties;
networkNavigator->GetProperties(getter_AddRefs(networkProperties));
if (!networkProperties)
return;
uint32_t gwAddress;
bool isWifi;
nsresult rv;
rv = networkProperties->GetDhcpGateway(&gwAddress);
if (NS_SUCCEEDED(rv))
rv = networkProperties->GetIsWifi(&isWifi);
if (NS_FAILED(rv))
return;
if (!gwAddress || !isWifi)
return;
mWifiTickler->SetIPV4Address(gwAddress);
mWifiTickler->Tickle();
}
//-----------------------------------------------------------------------------
// nsHttpsHandler implementation
//-----------------------------------------------------------------------------
-6
View File
@@ -39,7 +39,6 @@ extern Atomic<PRThread*, Relaxed> gSocketThread;
class ATokenBucketEvent;
class EventTokenBucket;
class Tickler;
class nsHttpConnection;
class nsHttpConnectionInfo;
class nsHttpTransaction;
@@ -245,7 +244,6 @@ public:
nsIInterfaceRequestor *callbacks,
uint32_t caps = 0)
{
TickleWifi(callbacks);
RefPtr<nsHttpConnectionInfo> clone = ci->Clone();
return mConnMgr->SpeculativeConnect(clone, callbacks, caps);
}
@@ -645,10 +643,6 @@ public:
}
}
private:
RefPtr<Tickler> mWifiTickler;
void TickleWifi(nsIInterfaceRequestor *cb);
private:
nsresult SpeculativeConnectInternal(nsIURI *aURI,
nsIPrincipal *aPrincipal,