Bug 1564960 - Calaulate network id on stream transport thread r=michal

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kershaw Chang 2019-08-14 13:20:25 +00:00
Родитель ba042b192b
Коммит 91a9c98998
2 изменённых файлов: 18 добавлений и 2 удалений

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

@ -14,7 +14,7 @@
class nsNetworkLinkService : public nsINetworkLinkService, public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSINETWORKLINKSERVICE
NS_DECL_NSIOBSERVER
@ -45,6 +45,7 @@ class nsNetworkLinkService : public nsINetworkLinkService, public nsIObserver {
static void IPConfigChanged(SCDynamicStoreRef store, CFArrayRef changedKeys,
void* info);
void calculateNetworkId(void);
void calculateNetworkIdInternal(void);
mozilla::Mutex mMutex;
nsCString mNetworkId;

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

@ -20,13 +20,14 @@
#include "nsServiceManagerUtils.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsNetCID.h"
#include "nsThreadUtils.h"
#include "mozilla/Logging.h"
#include "mozilla/Preferences.h"
#include "mozilla/SHA1.h"
#include "mozilla/Base64.h"
#include "mozilla/Telemetry.h"
#include "nsNetworkLinkService.h"
#include "MainThreadUtils.h"
#include "../../base/IPv6Utils.h"
#import <Cocoa/Cocoa.h>
@ -323,6 +324,20 @@ static bool ipv6NetworkId(SHA1Sum* sha1) {
}
void nsNetworkLinkService::calculateNetworkId(void) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
if (!target) {
return;
}
MOZ_ALWAYS_SUCCEEDS(
target->Dispatch(NewRunnableMethod("nsNetworkLinkService::calculateNetworkIdInternal", this,
&nsNetworkLinkService::calculateNetworkIdInternal),
NS_DISPATCH_NORMAL));
}
void nsNetworkLinkService::calculateNetworkIdInternal(void) {
MOZ_ASSERT(!NS_IsMainThread(), "Should not be called on the main thread");
SHA1Sum sha1;
bool found4 = ipv4NetworkId(&sha1);