Bug 1152048 - Send wakeup notification asynchronously to avoid reentrancy issues. r=bagder

--HG--
extra : rebase_source : 059c2292f443c972e144256298987e05f22c58f3
extra : histedit_source : 1ff8d3674fc3c911f83b80d920ee57f7d00def1a
This commit is contained in:
Nicholas Hurley 2015-07-31 13:39:48 -07:00
Родитель e3cddeaf6a
Коммит abb4485542
2 изменённых файлов: 51 добавлений и 16 удалений

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

@ -275,7 +275,7 @@ interface nsIAppOfflineInfo : nsISupports
#define NS_IOSERVICE_APP_OFFLINE_STATUS_TOPIC "network:app-offline-status-changed"
%}
[builtinclass, uuid(cd66ffef-3bc3-40de-841a-e2dcbea213a2)]
[builtinclass, uuid(6633c0bf-d97a-428f-8ece-cb6a655fb95a)]
interface nsIIOServiceInternal : nsISupports
{
/**
@ -284,4 +284,10 @@ interface nsIIOServiceInternal : nsISupports
* content process. It throws if called outside the content process.
*/
void SetConnectivity(in boolean connectivity);
/**
* An internal method to asynchronously run our notifications that happen
* when we wake from sleep
*/
void NotifyWakeup();
};

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

@ -1362,6 +1362,46 @@ nsIOService::EnumerateWifiAppsChangingState(const unsigned int &aKey,
return PL_DHASH_NEXT;
}
class
nsWakeupNotifier : public nsRunnable
{
public:
explicit nsWakeupNotifier(nsIIOServiceInternal *ioService)
:mIOService(ioService)
{ }
NS_IMETHOD Run()
{
return mIOService->NotifyWakeup();
}
private:
virtual ~nsWakeupNotifier() { }
nsCOMPtr<nsIIOServiceInternal> mIOService;
};
NS_IMETHODIMP
nsIOService::NotifyWakeup()
{
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
NS_ASSERTION(observerService, "The observer service should not be null");
if (observerService && mNetworkNotifyChanged) {
(void)observerService->
NotifyObservers(nullptr,
NS_NETWORK_LINK_TOPIC,
MOZ_UTF16(NS_NETWORK_LINK_DATA_CHANGED));
}
if (mCaptivePortalService) {
mCaptivePortalService->RecheckCaptivePortal();
}
return NS_OK;
}
// nsIObserver interface
NS_IMETHODIMP
nsIOService::Observe(nsISupports *subject,
@ -1414,21 +1454,10 @@ nsIOService::Observe(nsISupports *subject,
OnNetworkLinkEvent(NS_ConvertUTF16toUTF8(data).get());
} 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 && mNetworkNotifyChanged) {
(void)observerService->
NotifyObservers(nullptr,
NS_NETWORK_LINK_TOPIC,
MOZ_UTF16(NS_NETWORK_LINK_DATA_CHANGED));
}
if (mCaptivePortalService) {
mCaptivePortalService->RecheckCaptivePortal();
}
// this indirection brought to you by:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1152048#c19
nsCOMPtr<nsIRunnable> wakeupNotifier = new nsWakeupNotifier(this);
NS_DispatchToMainThread(wakeupNotifier);
} else if (!strcmp(topic, kNetworkActiveChanged)) {
#ifdef MOZ_WIDGET_GONK
if (IsNeckoChild()) {