Bug 939318 - Introduce the "network.notify.changed" prefs. r=mcmanus

Makes it possible to disable 'changed' events.

Disable the events in test_ping_aboutnetworking.js and in
test_proxy-failover_passing.js
This commit is contained in:
Daniel Stenberg 2014-08-24 23:22:00 -04:00
parent a7a3db782c
commit 4ac4e242f4
7 changed files with 68 additions and 4 deletions

View File

@ -986,6 +986,10 @@ pref("security.fileuri.strict_origin_policy", true);
// the results
pref("network.allow-experiments", true);
// Allow the network changed event to get sent when a network topology or
// setup change is noticed while running.
pref("network.notify.changed", true);
// Transmit UDP busy-work to the LAN when anticipating low latency
// network reads and on wifi to mitigate 802.11 Power Save Polling delays
pref("network.tickle-wifi.enabled", false);

View File

@ -63,6 +63,7 @@ using mozilla::net::IsNeckoChild;
// but the old names are still used to preserve backward compatibility.
#define NECKO_BUFFER_CACHE_COUNT_PREF "network.buffer.cache.count"
#define NECKO_BUFFER_CACHE_SIZE_PREF "network.buffer.cache.size"
#define NETWORK_NOTIFY_CHANGED_PREF "network.notify.changed"
#define MAX_RECURSION_COUNT 50
@ -161,6 +162,7 @@ nsIOService::nsIOService()
, mNetworkLinkServiceInitialized(false)
, mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY)
, mAutoDialEnabled(false)
, mNetworkNotifyChanged(true)
, mPreviousWifiState(-1)
{
}
@ -201,6 +203,7 @@ nsIOService::Init()
prefBranch->AddObserver(MANAGE_OFFLINE_STATUS_PREF, this, true);
prefBranch->AddObserver(NECKO_BUFFER_CACHE_COUNT_PREF, this, true);
prefBranch->AddObserver(NECKO_BUFFER_CACHE_SIZE_PREF, this, true);
prefBranch->AddObserver(NETWORK_NOTIFY_CHANGED_PREF, this, true);
PrefsChanged(prefBranch);
}
@ -866,6 +869,14 @@ nsIOService::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
gDefaultSegmentSize = size;
NS_WARN_IF_FALSE( (!(size & (size - 1))) , "network segment size is not a power of 2!");
}
if (!pref || strcmp(pref, NETWORK_NOTIFY_CHANGED_PREF) == 0) {
bool allow;
nsresult rv = prefs->GetBoolPref(NETWORK_NOTIFY_CHANGED_PREF, &allow);
if (NS_SUCCEEDED(rv)) {
mNetworkNotifyChanged = allow;
}
}
}
void
@ -1057,7 +1068,7 @@ nsIOService::Observe(nsISupports *subject,
NS_ASSERTION(observerService, "The observer service should not be null");
if (observerService) {
if (observerService && mNetworkNotifyChanged) {
(void)observerService->
NotifyObservers(nullptr,
NS_NETWORK_LINK_TOPIC,

View File

@ -144,6 +144,7 @@ private:
nsTArray<int32_t> mRestrictedPortList;
bool mAutoDialEnabled;
bool mNetworkNotifyChanged;
int32_t mPreviousWifiState;
// Hashtable of (appId, nsIAppOffineInfo::mode) pairs

View File

@ -27,6 +27,7 @@
#include "nsAutoPtr.h"
#include "mozilla/Services.h"
#include "nsCRT.h"
#include "nsIPrefService.h"
#include <iptypes.h>
#include <iphlpapi.h>
@ -38,6 +39,8 @@ static HMODULE sIphlpapi;
static decltype(NotifyIpInterfaceChange)* sNotifyIpInterfaceChange;
static decltype(CancelMibChangeNotify2)* sCancelMibChangeNotify2;
static const char kAllowChangedEvents[] = "network.notify.changed";
static void InitIphlpapi(void)
{
if (!sIphlpapi) {
@ -90,6 +93,7 @@ nsNotifyAddrListener::nsNotifyAddrListener()
, mStatusKnown(false)
, mCheckAttempted(false)
, mShutdownEvent(nullptr)
, mAllowChangedEvent(true)
{
InitIphlpapi();
}
@ -188,13 +192,30 @@ nsNotifyAddrListener::Run()
return NS_OK;
}
void
nsNotifyAddrListener::updateFromPref(nsIPrefBranch *prefs)
{
MOZ_ASSERT(NS_IsMainThread());
bool allow=true;
nsresult rv = prefs->GetBoolPref(kAllowChangedEvents, &allow);
if (NS_SUCCEEDED(rv)) {
mAllowChangedEvent = allow;
}
}
NS_IMETHODIMP
nsNotifyAddrListener::Observe(nsISupports *subject,
const char *topic,
const char16_t *data)
{
if (!strcmp("xpcom-shutdown-threads", topic))
if (!strcmp("xpcom-shutdown-threads", topic)) {
Shutdown();
} else if (!strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, topic)) {
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(subject);
if (prefs) {
updateFromPref(prefs);
}
}
return NS_OK;
}
@ -211,6 +232,13 @@ nsNotifyAddrListener::Init(void)
false);
NS_ENSURE_SUCCESS(rv, rv);
// monitor preference change
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
prefs->AddObserver(kAllowChangedEvents, this, true);
updateFromPref(prefs);
}
mShutdownEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
NS_ENSURE_TRUE(mShutdownEvent, NS_ERROR_OUT_OF_MEMORY);
@ -494,8 +522,10 @@ nsNotifyAddrListener::CheckLinkStatus(void)
if (mLinkUp && (prevCsum != mIPInterfaceChecksum)) {
// Network is online. Topology has changed. Always send CHANGED
// before UP.
SendEvent(NS_NETWORK_LINK_DATA_CHANGED);
// before UP - if allowed to.
if (mAllowChangedEvent) {
SendEvent(NS_NETWORK_LINK_DATA_CHANGED);
}
}
if (prevLinkUp != mLinkUp) {
// UP/DOWN status changed, send appropriate UP/DOWN event

View File

@ -14,6 +14,9 @@
#include "nsIObserver.h"
#include "nsThreadUtils.h"
#include "nsCOMPtr.h"
#include "nsIPrefBranch.h"
class nsIPrefBranch;
class nsNotifyAddrListener : public nsINetworkLinkService,
public nsIRunnable,
@ -62,9 +65,15 @@ protected:
HANDLE mShutdownEvent;
private:
// read the pref value and set mAllowChangedEvent
void updateFromPref(nsIPrefBranch *prefs);
// This is a checksum of various meta data for all network interfaces
// considered UP at last check.
ULONG mIPInterfaceChecksum;
// Network changed events are enabled
bool mAllowChangedEvent;
};
#endif /* NSNOTIFYADDRLISTENER_H_ */

View File

@ -42,6 +42,12 @@ function test_sockets(serverSocket) {
}
function run_test() {
var ps = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
// disable network changed events to avoid the the risk of having the dns
// cache getting flushed behind our back
ps.setBoolPref("network.notify.changed", false);
let serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
.createInstance(Ci.nsIServerSocket);
serverSocket.init(-1, true, -1);

View File

@ -36,6 +36,9 @@ function run_test()
"function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:" +
httpServer.identity.primaryPort + "';}"
);
// disable network changed events to avoid the the risk of having the
// proxyservice reset in the middle
prefserv.setBoolPref("network.notify.changed", false);
var chan = make_channel("http://localhost:" +
httpServer.identity.primaryPort + "/content");