From 8939aa6688dbf14583d95443a1f321e22f0971e8 Mon Sep 17 00:00:00 2001 From: "Dragana Damjanovic dd.mozilla@gmail.com" Date: Thu, 4 Feb 2016 04:14:00 +0100 Subject: [PATCH] Bug 1242755 - Move nsHttpConnectionMgr->Shutdown back to nsHttpHandler. r=mcmanus --- netwerk/base/nsIOService.cpp | 28 ++++++++++++++++--------- netwerk/base/nsIOService.h | 12 ++++++++++- netwerk/protocol/http/nsHttpHandler.cpp | 6 ++++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index 349767ec0609..e72ebafe374c 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -51,7 +51,6 @@ #include "CaptivePortalService.h" #include "ReferrerPolicy.h" #include "nsContentSecurityManager.h" -#include "nsHttpHandler.h" #ifdef MOZ_WIDGET_GONK #include "nsINetworkManager.h" @@ -65,7 +64,6 @@ using namespace mozilla; using mozilla::net::IsNeckoChild; using mozilla::net::CaptivePortalService; -using mozilla::net::gHttpHandler; #define PORT_PREF_PREFIX "network.security.ports." #define PORT_PREF(x) PORT_PREF_PREFIX x @@ -182,6 +180,7 @@ nsIOService::nsIOService() , mSettingOffline(false) , mSetOfflineValue(false) , mShutdown(false) + , mHttpHandlerAlreadyShutingDown(false) , mNetworkLinkServiceInitialized(false) , mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY) , mAutoDialEnabled(false) @@ -1407,6 +1406,15 @@ nsIOService::NotifyWakeup() return NS_OK; } +void +nsIOService::SetHttpHandlerAlreadyShutingDown() +{ + if (!mShutdown && !mOfflineForProfileChange) { + mNetTearingDownStarted = PR_IntervalNow(); + mHttpHandlerAlreadyShutingDown = true; + } +} + // nsIObserver interface NS_IMETHODIMP nsIOService::Observe(nsISupports *subject, @@ -1418,12 +1426,12 @@ nsIOService::Observe(nsISupports *subject, if (prefBranch) PrefsChanged(prefBranch, NS_ConvertUTF16toUTF8(data).get()); } else if (!strcmp(topic, kProfileChangeNetTeardownTopic)) { + if (!mHttpHandlerAlreadyShutingDown) { + mNetTearingDownStarted = PR_IntervalNow(); + } + mHttpHandlerAlreadyShutingDown = false; if (!mOffline) { mOfflineForProfileChange = true; - mNetTearingDownStarted = PR_IntervalNow(); - if (gHttpHandler) { - gHttpHandler->ShutdownConnectionManager(); - } SetOffline(true); } } else if (!strcmp(topic, kProfileChangeNetRestoreTopic)) { @@ -1449,12 +1457,12 @@ nsIOService::Observe(nsISupports *subject, // changes of the offline status from now. We must not allow going // online after this point. mShutdown = true; - if (!mOfflineForProfileChange) { + + if (!mHttpHandlerAlreadyShutingDown && !mOfflineForProfileChange) { mNetTearingDownStarted = PR_IntervalNow(); } - if (gHttpHandler) { - gHttpHandler->ShutdownConnectionManager(); - } + mHttpHandlerAlreadyShutingDown = false; + SetOffline(true); if (mCaptivePortalService) { diff --git a/netwerk/base/nsIOService.h b/netwerk/base/nsIOService.h index 73e1d42acb4d..64e516d3afe8 100644 --- a/netwerk/base/nsIOService.h +++ b/netwerk/base/nsIOService.h @@ -84,8 +84,17 @@ public: PRIntervalTime LastOfflineStateChange() { return mLastOfflineStateChange; } PRIntervalTime LastConnectivityChange() { return mLastConnectivityChange; } PRIntervalTime LastNetworkLinkChange() { return mLastNetworkLinkChange; } - bool IsNetTearingDown() { return mShutdown || mOfflineForProfileChange; } + bool IsNetTearingDown() { return mShutdown || mOfflineForProfileChange || + mHttpHandlerAlreadyShutingDown; } PRIntervalTime NetTearingDownStarted() { return mNetTearingDownStarted; } + + // nsHttpHandler is going to call this function to inform nsIOService that network + // is in process of tearing down. Moving nsHttpConnectionMgr::Shutdown to nsIOService + // caused problems (bug 1242755) so we doing it in this way. + // As soon as nsIOService gets notification that it is shutdown it is going to + // reset mHttpHandlerAlreadyShutingDown. + void SetHttpHandlerAlreadyShutingDown(); + bool IsLinkUp(); // Should only be called from NeckoChild. Use SetAppOffline instead. @@ -152,6 +161,7 @@ private: bool mSetOfflineValue; mozilla::Atomic mShutdown; + mozilla::Atomic mHttpHandlerAlreadyShutingDown; nsCOMPtr mSocketTransportService; nsCOMPtr mDNSService; diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 75c92c53a315..57e70bf51779 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -53,6 +53,7 @@ #include "nsServiceManagerUtils.h" #include "nsComponentManagerUtils.h" #include "nsSocketTransportService2.h" +#include "nsIOService.h" #include "mozilla/net/NeckoChild.h" #include "mozilla/ipc/URIUtils.h" @@ -2058,6 +2059,11 @@ nsHttpHandler::Observe(nsISupports *subject, if (mWifiTickler) mWifiTickler->Cancel(); + // Inform nsIOService that network is tearing down. + gIOService->SetHttpHandlerAlreadyShutingDown(); + + ShutdownConnectionManager(); + // need to reset the session start time since cache validation may // depend on this value. mSessionStartTime = NowInSeconds();