зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1589448 - Add network id changed event on MacOS r=dragana
Differential Revision: https://phabricator.services.mozilla.com/D50463 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d19c1272ca
Коммит
07ce7a231c
|
@ -80,6 +80,10 @@ interface nsINetworkLinkService : nsISupports
|
|||
* linkStatusKnown is true.
|
||||
*/
|
||||
#define NS_NETWORK_LINK_DATA_CHANGED "changed"
|
||||
/**
|
||||
* network ID has changed.
|
||||
*/
|
||||
#define NS_NETWORK_LINK_DATA_NETWORKID_CHANGED "networkid-changed"
|
||||
/**
|
||||
* linkStatusKnown is now false.
|
||||
*/
|
||||
|
|
|
@ -1612,6 +1612,8 @@ nsresult nsIOService::OnNetworkLinkEvent(const char* data) {
|
|||
} else if (!strcmp(data, NS_NETWORK_LINK_DATA_UNKNOWN)) {
|
||||
nsresult rv = mNetworkLinkService->GetIsLinkUp(&isUp);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else if (!strcmp(data, NS_NETWORK_LINK_DATA_NETWORKID_CHANGED)) {
|
||||
LOG(("nsIOService::OnNetworkLinkEvent Network id changed"));
|
||||
} else {
|
||||
NS_WARNING("Unhandled network event!");
|
||||
return NS_OK;
|
||||
|
|
|
@ -48,7 +48,10 @@ class nsNetworkLinkService : public nsINetworkLinkService,
|
|||
SCDynamicStoreRef mStoreRef;
|
||||
|
||||
void UpdateReachability();
|
||||
void SendEvent(bool aNetworkChanged);
|
||||
void OnIPConfigChanged();
|
||||
void OnNetworkIdChanged();
|
||||
void OnReachabilityChanged();
|
||||
void SendEvent(const char* aEventID);
|
||||
static void ReachabilityChanged(SCNetworkReachabilityRef target,
|
||||
SCNetworkConnectionFlags flags, void* info);
|
||||
static void NetworkConfigChanged(SCDynamicStoreRef store,
|
||||
|
|
|
@ -630,8 +630,9 @@ void nsNetworkLinkService::calculateNetworkIdInternal(void) {
|
|||
static bool initialIDCalculation = true;
|
||||
if (idChanged && !initialIDCalculation) {
|
||||
RefPtr<nsNetworkLinkService> self = this;
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"nsNetworkLinkService::calculateNetworkIdInternal", [self]() { self->SendEvent(true); }));
|
||||
NS_DispatchToMainThread(
|
||||
NS_NewRunnableFunction("nsNetworkLinkService::calculateNetworkIdInternal",
|
||||
[self]() { self->OnNetworkIdChanged(); }));
|
||||
}
|
||||
|
||||
initialIDCalculation = false;
|
||||
|
@ -665,7 +666,7 @@ void nsNetworkLinkService::NetworkConfigChanged(SCDynamicStoreRef aStoreREf,
|
|||
|
||||
nsNetworkLinkService* service = static_cast<nsNetworkLinkService*>(aInfo);
|
||||
if (ipConfigChanged) {
|
||||
service->calculateNetworkIdWithDelay(kNetworkIdDelayAfterChange);
|
||||
service->OnIPConfigChanged();
|
||||
}
|
||||
|
||||
if (dnsConfigChanged) {
|
||||
|
@ -846,35 +847,50 @@ void nsNetworkLinkService::UpdateReachability() {
|
|||
mStatusKnown = true;
|
||||
}
|
||||
|
||||
void nsNetworkLinkService::SendEvent(bool aNetworkChanged) {
|
||||
void nsNetworkLinkService::OnIPConfigChanged() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (!observerService) {
|
||||
calculateNetworkIdWithDelay(kNetworkIdDelayAfterChange);
|
||||
if (!StaticPrefs::network_notify_changed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char* event;
|
||||
if (aNetworkChanged) {
|
||||
if (!StaticPrefs::network_notify_changed()) {
|
||||
return;
|
||||
}
|
||||
event = NS_NETWORK_LINK_DATA_CHANGED;
|
||||
|
||||
if (!mNetworkChangeTime.IsNull()) {
|
||||
Telemetry::AccumulateTimeDelta(Telemetry::NETWORK_TIME_BETWEEN_NETWORK_CHANGE_EVENTS,
|
||||
mNetworkChangeTime);
|
||||
}
|
||||
mNetworkChangeTime = TimeStamp::Now();
|
||||
} else if (!mStatusKnown) {
|
||||
event = NS_NETWORK_LINK_DATA_UNKNOWN;
|
||||
} else {
|
||||
event = mLinkUp ? NS_NETWORK_LINK_DATA_UP : NS_NETWORK_LINK_DATA_DOWN;
|
||||
if (!mNetworkChangeTime.IsNull()) {
|
||||
Telemetry::AccumulateTimeDelta(Telemetry::NETWORK_TIME_BETWEEN_NETWORK_CHANGE_EVENTS,
|
||||
mNetworkChangeTime);
|
||||
}
|
||||
LOG(("SendEvent: network is '%s'\n", event));
|
||||
mNetworkChangeTime = TimeStamp::Now();
|
||||
|
||||
observerService->NotifyObservers(static_cast<nsINetworkLinkService*>(this), NS_NETWORK_LINK_TOPIC,
|
||||
NS_ConvertASCIItoUTF16(event).get());
|
||||
SendEvent(NS_NETWORK_LINK_DATA_CHANGED);
|
||||
}
|
||||
|
||||
void nsNetworkLinkService::OnNetworkIdChanged() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
SendEvent(NS_NETWORK_LINK_DATA_NETWORKID_CHANGED);
|
||||
}
|
||||
|
||||
void nsNetworkLinkService::OnReachabilityChanged() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!mStatusKnown) {
|
||||
SendEvent(NS_NETWORK_LINK_DATA_UNKNOWN);
|
||||
return;
|
||||
}
|
||||
|
||||
SendEvent(mLinkUp ? NS_NETWORK_LINK_DATA_UP : NS_NETWORK_LINK_DATA_DOWN);
|
||||
}
|
||||
|
||||
void nsNetworkLinkService::SendEvent(const char* aEventID) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
LOG(("SendEvent: network is '%s'\n", aEventID));
|
||||
|
||||
nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (observerService) {
|
||||
observerService->NotifyObservers(static_cast<nsINetworkLinkService*>(this),
|
||||
NS_NETWORK_LINK_TOPIC, NS_ConvertASCIItoUTF16(aEventID).get());
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
@ -884,7 +900,7 @@ void nsNetworkLinkService::ReachabilityChanged(SCNetworkReachabilityRef target,
|
|||
nsNetworkLinkService* service = static_cast<nsNetworkLinkService*>(info);
|
||||
|
||||
service->UpdateReachability();
|
||||
service->SendEvent(false);
|
||||
service->OnReachabilityChanged();
|
||||
service->calculateNetworkIdWithDelay(kNetworkIdDelayAfterChange);
|
||||
// If a new interface is up or the order of interfaces is changed, we should
|
||||
// update the DNS suffix list.
|
||||
|
|
Загрузка…
Ссылка в новой задаче