Bug 939318 - Send network changed event when returning from sleep. r=mcmanus

Coming back from hibernation, the network situation is unknown and may
have changed since the computer went into sleep.
This commit is contained in:
Daniel Stenberg 2014-08-24 23:21:00 -04:00
parent 0678ab3012
commit 6c9dba028a

View File

@ -40,6 +40,7 @@
#include "MainThreadUtils.h"
#include "nsThreadUtils.h"
#include "mozilla/net/NeckoCommon.h"
#include "nsIWidget.h"
#ifdef MOZ_WIDGET_GONK
#include "nsINetworkManager.h"
@ -213,6 +214,7 @@ nsIOService::Init()
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
observerService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
observerService->AddObserver(this, kNetworkActiveChanged, true);
observerService->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true);
}
else
NS_WARNING("failed to get observer service");
@ -980,14 +982,12 @@ nsIOService::Observe(nsISupports *subject,
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(subject);
if (prefBranch)
PrefsChanged(prefBranch, NS_ConvertUTF16toUTF8(data).get());
}
else if (!strcmp(topic, kProfileChangeNetTeardownTopic)) {
} else if (!strcmp(topic, kProfileChangeNetTeardownTopic)) {
if (!mOffline) {
mOfflineForProfileChange = true;
SetOffline(true);
}
}
else if (!strcmp(topic, kProfileChangeNetRestoreTopic)) {
} else if (!strcmp(topic, kProfileChangeNetRestoreTopic)) {
if (mOfflineForProfileChange) {
mOfflineForProfileChange = false;
if (!mManageOfflineStatus ||
@ -995,8 +995,7 @@ nsIOService::Observe(nsISupports *subject,
SetOffline(false);
}
}
}
else if (!strcmp(topic, kProfileDoChange)) {
} else if (!strcmp(topic, kProfileDoChange)) {
if (data && NS_LITERAL_STRING("startup").Equals(data)) {
// Lazy initialization of network link service (see bug 620472)
InitializeNetworkLinkService();
@ -1008,8 +1007,7 @@ nsIOService::Observe(nsISupports *subject,
GetPrefBranch(getter_AddRefs(prefBranch));
PrefsChanged(prefBranch, MANAGE_OFFLINE_STATUS_PREF);
}
}
else if (!strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
} else if (!strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
// Remember we passed XPCOM shutdown notification to prevent any
// changes of the offline status from now. We must not allow going
// online after this point.
@ -1019,13 +1017,11 @@ nsIOService::Observe(nsISupports *subject,
// Break circular reference.
mProxyService = nullptr;
}
else if (!strcmp(topic, NS_NETWORK_LINK_TOPIC)) {
} else if (!strcmp(topic, NS_NETWORK_LINK_TOPIC)) {
if (!mOfflineForProfileChange) {
OnNetworkLinkEvent(NS_ConvertUTF16toUTF8(data).get());
}
}
else if (!strcmp(topic, kNetworkActiveChanged)) {
} else if (!strcmp(topic, kNetworkActiveChanged)) {
#ifdef MOZ_WIDGET_GONK
if (IsNeckoChild()) {
return NS_OK;
@ -1054,6 +1050,19 @@ nsIOService::Observe(nsISupports *subject,
mPreviousWifiState = newWifiState;
#endif
} else if (!strcmp(topic, NS_WIDGET_WAKE_OBSERVER_TOPIC)) {
// coming back alive from sleep
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
NS_ASSERTION(observerService, "The observer service should not be null");
if (observerService) {
(void)observerService->
NotifyObservers(nullptr,
NS_NETWORK_LINK_TOPIC,
MOZ_UTF16(NS_NETWORK_LINK_DATA_CHANGED));
}
}
return NS_OK;