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-29 01:11:00 -04:00
Родитель 047c33b3d7
Коммит a34f73bd67
7 изменённых файлов: 42 добавлений и 3 удалений

Просмотреть файл

@ -990,6 +990,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);

Просмотреть файл

@ -55,6 +55,7 @@ using namespace mozilla;
// 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
@ -149,6 +150,7 @@ nsIOService::nsIOService()
, mNetworkLinkServiceInitialized(false)
, mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY)
, mAutoDialEnabled(false)
, mNetworkNotifyChanged(true)
{
}
@ -188,6 +190,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);
}
@ -852,6 +855,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
@ -958,7 +969,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,

Просмотреть файл

@ -129,6 +129,7 @@ private:
nsTArray<int32_t> mRestrictedPortList;
bool mAutoDialEnabled;
bool mNetworkNotifyChanged;
public:
// Used for all default buffer sizes that necko allocates.
static uint32_t gDefaultSegmentSize;

Просмотреть файл

@ -27,10 +27,13 @@
#include "nsAutoPtr.h"
#include "mozilla/Services.h"
#include "nsCRT.h"
#include "mozilla/Preferences.h"
#include <iptypes.h>
#include <iphlpapi.h>
using namespace mozilla;
static HMODULE sNetshell;
static decltype(NcFreeNetconProperties)* sNcFreeNetconProperties;
@ -38,6 +41,8 @@ static HMODULE sIphlpapi;
static decltype(NotifyIpInterfaceChange)* sNotifyIpInterfaceChange;
static decltype(CancelMibChangeNotify2)* sCancelMibChangeNotify2;
#define NETWORK_NOTIFY_CHANGED_PREF "network.notify.changed"
static void InitIphlpapi(void)
{
if (!sIphlpapi) {
@ -90,6 +95,7 @@ nsNotifyAddrListener::nsNotifyAddrListener()
, mStatusKnown(false)
, mCheckAttempted(false)
, mShutdownEvent(nullptr)
, mAllowChangedEvent(true)
{
InitIphlpapi();
}
@ -211,6 +217,9 @@ nsNotifyAddrListener::Init(void)
false);
NS_ENSURE_SUCCESS(rv, rv);
Preferences::AddBoolVarCache(&mAllowChangedEvent,
NETWORK_NOTIFY_CHANGED_PREF, true);
mShutdownEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
NS_ENSURE_TRUE(mShutdownEvent, NS_ERROR_OUT_OF_MEMORY);
@ -494,8 +503,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

Просмотреть файл

@ -65,6 +65,9 @@ private:
// 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_ */

Просмотреть файл

@ -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);

Просмотреть файл

@ -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");