Merge for backout of bug 419562
authorDave Camp <dcamp@mozilla.com>
Wed, 20 Aug 2008 02:41:51 -0700
changeset 17157 d5d084c82d4f02aacb7a948179cb7662a587895c
parent 17155 926993b7baf813c3b954c93f4c5fc5d9b8713d04 (current diff)
parent 17156 ada680794b55d8ff552d5c3d73811725fef56e08 (diff)
child 17159 21c24bbd01c029ebee70f4017e88d46ed0aa9edf
push idunknown
push userunknown
push dateunknown
bugs419562
milestone1.9.1a2pre
Merge for backout of bug 419562
--- a/netwerk/protocol/http/src/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/src/nsHttpHandler.cpp
@@ -147,17 +147,18 @@ NewURI(const nsACString &aSpec,
 
 //-----------------------------------------------------------------------------
 // nsHttpHandler <public>
 //-----------------------------------------------------------------------------
 
 nsHttpHandler *gHttpHandler = nsnull;
 
 nsHttpHandler::nsHttpHandler()
-    : mHttpVersion(NS_HTTP_VERSION_1_1)
+    : mConnMgr(nsnull)
+    , mHttpVersion(NS_HTTP_VERSION_1_1)
     , mProxyHttpVersion(NS_HTTP_VERSION_1_1)
     , mCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
     , mProxyCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
     , mReferrerLevel(0xff) // by default we always send a referrer
     , mIdleTimeout(10)
     , mMaxRequestAttempts(10)
     , mMaxRequestDelay(10)
     , mMaxConnections(24)
@@ -191,16 +192,17 @@ nsHttpHandler::~nsHttpHandler()
     // We do not deal with the timer cancellation in the destructor since
     // it is taken care of in xpcom shutdown event in the Observe method.
 
     LOG(("Deleting nsHttpHandler [this=%x]\n", this));
 
     // make sure the connection manager is shutdown
     if (mConnMgr) {
         mConnMgr->Shutdown();
+        NS_RELEASE(mConnMgr);
     }
 
     nsHttp::DestroyAtomTable();
 
     gHttpHandler = nsnull;
 }
 
 nsresult
@@ -275,46 +277,42 @@ nsHttpHandler::Init()
                                   static_cast<nsISupports*>(static_cast<void*>(this)),
                                   NS_HTTP_STARTUP_TOPIC);    
     
     mObserverService = do_GetService("@mozilla.org/observer-service;1");
     if (mObserverService) {
         mObserverService->AddObserver(this, "profile-change-net-teardown", PR_TRUE);
         mObserverService->AddObserver(this, "profile-change-net-restore", PR_TRUE);
         mObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
-        mObserverService->AddObserver(this, NS_IOSERVICE_GOING_OFFLINE_TOPIC,
-                                      PR_TRUE);
-        mObserverService->AddObserver(this, NS_IOSERVICE_OFFLINE_STATUS_TOPIC,
-                                      PR_TRUE);
     }
  
     StartPruneDeadConnectionsTimer();
     return NS_OK;
 }
 
 nsresult
 nsHttpHandler::InitConnectionMgr()
 {
-    if (!mConnMgr) {
-        nsRefPtr<nsHttpConnectionMgr> mgr = new nsHttpConnectionMgr();
-        NS_ENSURE_TRUE(mgr, NS_ERROR_OUT_OF_MEMORY);
+    nsresult rv;
 
-        nsresult rv = mgr->Init(mMaxConnections,
-                                mMaxConnectionsPerServer,
-                                mMaxConnectionsPerServer,
-                                mMaxPersistentConnectionsPerServer,
-                                mMaxPersistentConnectionsPerProxy,
-                                mMaxRequestDelay,
-                                mMaxPipelinedRequests);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        mgr.swap(mConnMgr);
+    if (!mConnMgr) {
+        mConnMgr = new nsHttpConnectionMgr();
+        if (!mConnMgr)
+            return NS_ERROR_OUT_OF_MEMORY;
+        NS_ADDREF(mConnMgr);
     }
 
-    return NS_OK;
+    rv = mConnMgr->Init(mMaxConnections,
+                        mMaxConnectionsPerServer,
+                        mMaxConnectionsPerServer,
+                        mMaxPersistentConnectionsPerServer,
+                        mMaxPersistentConnectionsPerProxy,
+                        mMaxRequestDelay,
+                        mMaxPipelinedRequests);
+    return rv;
 }
 
 void
 nsHttpHandler::StartPruneDeadConnectionsTimer()
 {
     LOG(("nsHttpHandler::StartPruneDeadConnectionsTimer\n"));
 
     mTimer = do_CreateInstance("@mozilla.org/timer;1");
@@ -1692,36 +1690,31 @@ nsHttpHandler::Observe(nsISupports *subj
     if (strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0) {
         nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(subject);
         if (prefBranch)
             PrefsChanged(prefBranch, NS_ConvertUTF16toUTF8(data).get());
     }
     else if (strcmp(topic, "profile-change-net-teardown")    == 0 ||
              strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)    == 0) {
 
+        // kill off the "prune dead connections" timer
+        StopPruneDeadConnectionsTimer();
+
         // clear cache of all authentication credentials.
         mAuthCache.ClearAll();
 
+        // ensure connection manager is shutdown
+        if (mConnMgr)
+            mConnMgr->Shutdown();
+
         // need to reset the session start time since cache validation may
         // depend on this value.
         mSessionStartTime = NowInSeconds();
     }
-    else if (strcmp(topic, NS_IOSERVICE_GOING_OFFLINE_TOPIC) == 0) {
-        // kill off the "prune dead connections" timer
-        StopPruneDeadConnectionsTimer();
-
-        // ensure connection manager is shutdown
-        if (mConnMgr) {
-            mConnMgr->Shutdown();
-            mConnMgr = nsnull;
-        }
-    }
-    else if (strcmp(topic, "profile-change-net-restore") == 0 ||
-             (strcmp(topic, NS_IOSERVICE_OFFLINE_STATUS_TOPIC) == 0 &&
-              nsDependentString(data).EqualsLiteral(NS_IOSERVICE_ONLINE))) {
+    else if (strcmp(topic, "profile-change-net-restore") == 0) {
         // initialize connection manager
         InitConnectionMgr();
 
         // restart the "prune dead connections" timer
         StartPruneDeadConnectionsTimer();
     }
     else if (strcmp(topic, "timer-callback") == 0) {
         // prune dead connections
--- a/netwerk/protocol/http/src/nsHttpHandler.h
+++ b/netwerk/protocol/http/src/nsHttpHandler.h
@@ -224,17 +224,17 @@ private:
     nsCOMPtr<nsICookieService>          mCookieService;
     nsCOMPtr<nsIIDNService>             mIDNConverter;
     nsCOMPtr<nsITimer>                  mTimer;
 
     // the authentication credentials cache
     nsHttpAuthCache mAuthCache;
 
     // the connection manager
-    nsRefPtr<nsHttpConnectionMgr> mConnMgr;
+    nsHttpConnectionMgr *mConnMgr;
 
     //
     // prefs
     //
 
     PRUint8  mHttpVersion;
     PRUint8  mProxyHttpVersion;
     PRUint8  mCapabilities;