Bug 1561005 - Add nsINetworkLinkService.networkID r=michal

Differential Revision: https://phabricator.services.mozilla.com/D35683

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2019-06-28 11:11:19 +00:00
parent d36aaea3c9
commit cc4af7a576
3 changed files with 19 additions and 2 deletions

View File

@ -45,6 +45,12 @@ interface nsINetworkLinkService : nsISupports
* The type of network connection.
*/
readonly attribute unsigned long linkType;
/**
* A string uniquely identifying the current active network interfaces.
* Empty when there are no active network interfaces.
*/
readonly attribute ACString networkID;
};
%{C++

View File

@ -106,10 +106,10 @@ NS_IMPL_ISUPPORTS(nsNotifyAddrListener, nsINetworkLinkService, nsIRunnable,
nsIObserver)
nsNotifyAddrListener::nsNotifyAddrListener()
: mLinkUp(true) // assume true by default
,
: mLinkUp(true), // assume true by default
mStatusKnown(false),
mCheckAttempted(false),
mMutex("nsNotifyAddrListener::mMutex"),
mCheckEvent(nullptr),
mShutdown(false),
mIPInterfaceChecksum(0),
@ -150,6 +150,13 @@ nsNotifyAddrListener::GetLinkType(uint32_t* aLinkType) {
return NS_OK;
}
NS_IMETHODIMP
nsNotifyAddrListener::GetNetworkID(nsACString& aNetworkID) {
MutexAutoLock lock(mMutex);
aNetworkID = mNetworkId;
return NS_OK;
}
static bool macAddr(BYTE addr[], DWORD len, char* buf, size_t buflen) {
buf[0] = '\0';
if (!addr || !len || (len * 3 > buflen)) {
@ -210,6 +217,7 @@ bool nsNotifyAddrListener::findMac(char* gateway) {
break;
}
LOG(("networkid: id %s\n", output.get()));
MutexAutoLock lock(mMutex);
if (mNetworkId != output) {
// new id
Telemetry::Accumulate(Telemetry::NETWORK_ID2, 1);

View File

@ -15,6 +15,7 @@
#include "nsThreadUtils.h"
#include "nsCOMPtr.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Mutex.h"
class nsNotifyAddrListener : public nsINetworkLinkService,
public nsIRunnable,
@ -71,6 +72,8 @@ class nsNotifyAddrListener : public nsINetworkLinkService,
// Figure out the current network identification
void calculateNetworkId(void);
bool findMac(char* gateway);
mozilla::Mutex mMutex;
nsCString mNetworkId;
HANDLE mCheckEvent;