Skip to content

Commit

Permalink
Bug 939318 - Introduce the "network.notify.changed" prefs. r=mcmanus
Browse files Browse the repository at this point in the history
Makes it possible to disable 'changed' events.

Disable the events in test_ping_aboutnetworking.js and in
test_proxy-failover_passing.js
  • Loading branch information
bagder committed Aug 29, 2014
1 parent 047c33b commit a34f73b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion netwerk/base/src/nsIOService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -149,6 +150,7 @@ nsIOService::nsIOService()
, mNetworkLinkServiceInitialized(false)
, mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY)
, mAutoDialEnabled(false)
, mNetworkNotifyChanged(true)
{
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions netwerk/base/src/nsIOService.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class nsIOService MOZ_FINAL : public nsIIOService2
nsTArray<int32_t> mRestrictedPortList;

bool mAutoDialEnabled;
bool mNetworkNotifyChanged;
public:
// Used for all default buffer sizes that necko allocates.
static uint32_t gDefaultSegmentSize;
Expand Down
15 changes: 13 additions & 2 deletions netwerk/system/win32/nsNotifyAddrListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@
#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;

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) {
Expand Down Expand Up @@ -90,6 +95,7 @@ nsNotifyAddrListener::nsNotifyAddrListener()
, mStatusKnown(false)
, mCheckAttempted(false)
, mShutdownEvent(nullptr)
, mAllowChangedEvent(true)
{
InitIphlpapi();
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions netwerk/system/win32/nsNotifyAddrListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class nsNotifyAddrListener : public nsINetworkLinkService,
// 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_ */
6 changes: 6 additions & 0 deletions netwerk/test/unit/test_ping_aboutnetworking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions netwerk/test/unit/test_proxy-failover_passing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit a34f73b

Please sign in to comment.