mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1561005 - Implement nsINetworkLinkService.networkID on mac r=michal
Depends on D35780 Differential Revision: https://phabricator.services.mozilla.com/D35781 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
c657dcfafe
commit
49e0220e23
@ -7,6 +7,7 @@
|
||||
|
||||
#include "nsINetworkLinkService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
|
||||
#include <SystemConfiguration/SCNetworkReachability.h>
|
||||
#include <SystemConfiguration/SystemConfiguration.h>
|
||||
@ -44,6 +45,8 @@ class nsNetworkLinkService : public nsINetworkLinkService, public nsIObserver {
|
||||
static void IPConfigChanged(SCDynamicStoreRef store, CFArrayRef changedKeys,
|
||||
void* info);
|
||||
void calculateNetworkId(void);
|
||||
|
||||
mozilla::Mutex mMutex;
|
||||
nsCString mNetworkId;
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "mozilla/Base64.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "nsNetworkLinkService.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "../../base/IPv6Utils.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@ -74,7 +75,8 @@ nsNetworkLinkService::nsNetworkLinkService()
|
||||
mReachability(nullptr),
|
||||
mCFRunLoop(nullptr),
|
||||
mRunLoopSource(nullptr),
|
||||
mStoreRef(nullptr) {}
|
||||
mStoreRef(nullptr),
|
||||
mMutex("nsNetworkLinkService::mMutex") {}
|
||||
|
||||
nsNetworkLinkService::~nsNetworkLinkService() = default;
|
||||
|
||||
@ -99,6 +101,13 @@ nsNetworkLinkService::GetLinkType(uint32_t* aLinkType) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNetworkLinkService::GetNetworkID(nsACString& aNetworkID) {
|
||||
MutexAutoLock lock(mMutex);
|
||||
aNetworkID = mNetworkId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifndef SA_SIZE
|
||||
# define SA_SIZE(sa) \
|
||||
((!(sa) || ((struct sockaddr*)(sa))->sa_len == 0) \
|
||||
@ -315,6 +324,7 @@ static bool ipv6NetworkId(SHA1Sum* sha1) {
|
||||
}
|
||||
|
||||
void nsNetworkLinkService::calculateNetworkId(void) {
|
||||
MOZ_ASSERT(!NS_IsMainThread(), "Should not be called on the main thread");
|
||||
SHA1Sum sha1;
|
||||
bool found4 = ipv4NetworkId(&sha1);
|
||||
bool found6 = ipv6NetworkId(&sha1);
|
||||
@ -331,6 +341,7 @@ void nsNetworkLinkService::calculateNetworkId(void) {
|
||||
nsresult rv = Base64Encode(newString, output);
|
||||
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
|
||||
LOG(("networkid: id %s\n", output.get()));
|
||||
MutexAutoLock lock(mMutex);
|
||||
if (mNetworkId != output) {
|
||||
// new id
|
||||
if (found4 && !found6) {
|
||||
@ -343,10 +354,14 @@ void nsNetworkLinkService::calculateNetworkId(void) {
|
||||
mNetworkId = output;
|
||||
} else {
|
||||
// same id
|
||||
LOG(("Same network id"));
|
||||
Telemetry::Accumulate(Telemetry::NETWORK_ID2, 2);
|
||||
}
|
||||
} else {
|
||||
// no id
|
||||
LOG(("No network id"));
|
||||
MutexAutoLock lock(mMutex);
|
||||
mNetworkId.Truncate();
|
||||
Telemetry::Accumulate(Telemetry::NETWORK_ID2, 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user