Bug 577073 - Make nsPACMan respect network.dns.disablePrefetch, don't call NS_RELEASE_THIS() before Complete(). r=bz
authorCorentin Chary <corentin.chary@gmail.com>
Sun, 18 Jul 2010 10:18:55 +0200
changeset 47869 0e1da826a6042f45d6a245b1e14570192029422c
parent 47868 3a54d39f2fbb1bde6277c79809001f07e367a512
child 47870 83550fdf1b23182330f5115bc62e8f8ad49e9e9b
push id14456
push userdgottwald@mozilla.com
push dateSun, 18 Jul 2010 08:27:01 +0000
treeherderautoland@358360ecb806 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs577073
milestone2.0b2pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 577073 - Make nsPACMan respect network.dns.disablePrefetch, don't call NS_RELEASE_THIS() before Complete(). r=bz
netwerk/base/src/nsPACMan.cpp
--- a/netwerk/base/src/nsPACMan.cpp
+++ b/netwerk/base/src/nsPACMan.cpp
@@ -84,48 +84,48 @@ public:
   PendingPACQuery(nsPACMan *pacMan, nsIURI *uri, nsPACManCallback *callback)
     : mPACMan(pacMan)
     , mURI(uri)
     , mCallback(callback)
   {
     PR_INIT_CLIST(this);
   }
 
-  nsresult Start();
+  nsresult Start(PRUint32 flags);
   void     Complete(nsresult status, const nsCString &pacString);
 
 private:
   nsPACMan                  *mPACMan;  // weak reference
   nsCOMPtr<nsIURI>           mURI;
   nsRefPtr<nsPACManCallback> mCallback;
   nsCOMPtr<nsICancelable>    mDNSRequest;
 };
 
 // This is threadsafe because we implement nsIDNSListener
 NS_IMPL_THREADSAFE_ISUPPORTS1(PendingPACQuery, nsIDNSListener)
 
 nsresult
-PendingPACQuery::Start()
+PendingPACQuery::Start(PRUint32 flags)
 {
   if (mDNSRequest)
     return NS_OK;  // already started
 
   nsresult rv;
   nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
   if (NS_FAILED(rv)) {
     NS_WARNING("unable to get the DNS service");
     return rv;
   }
 
   nsCAutoString host;
   rv = mURI->GetAsciiHost(host);
   if (NS_FAILED(rv))
     return rv;
 
-  rv = dns->AsyncResolve(host, 0, this, NS_GetCurrentThread(),
+  rv = dns->AsyncResolve(host, flags, this, NS_GetCurrentThread(),
                          getter_AddRefs(mDNSRequest));
   if (NS_FAILED(rv))
     NS_WARNING("DNS AsyncResolve failed");
 
   return rv;
 }
 
 // This may be called before or after OnLookupComplete
@@ -155,21 +155,22 @@ PendingPACQuery::OnLookupComplete(nsICan
   mDNSRequest = nsnull;  // break reference cycle
 
   // If we've already completed this query then do nothing.
   if (!mCallback)
     return NS_OK;
 
   // We're no longer pending, so we can remove ourselves.
   PR_REMOVE_LINK(this);
-  NS_RELEASE_THIS();
 
   nsCAutoString pacString;
   status = mPACMan->GetProxyForURI(mURI, pacString);
   Complete(status, pacString);
+
+  NS_RELEASE_THIS();
   return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 
 nsPACMan::nsPACMan()
   : mLoadPending(PR_FALSE)
   , mShutdown(PR_FALSE)
@@ -233,21 +234,26 @@ nsPACMan::AsyncGetProxyForURI(nsIURI *ur
   NS_ADDREF(query);
   PR_APPEND_LINK(query, &mPendingQ);
 
   // If we're waiting for the PAC file to load, then delay starting the query.
   // See OnStreamComplete.  However, if this is the PAC URI then query right
   // away since we know the result will be DIRECT.  We could shortcut some code
   // in this case by issuing the callback directly from here, but that would
   // require extra code, so we just go through the usual async code path.
-  if (IsLoading() && !IsPACURI(uri))
+  int isPACURI = IsPACURI(uri);
+
+  if (IsLoading() && !isPACURI)
     return NS_OK;
 
-  nsresult rv = query->Start();
-  if (NS_FAILED(rv)) {
+  nsresult rv = query->Start(isPACURI ? 0 : nsIDNSService::RESOLVE_SPECULATE);
+  if (rv == NS_ERROR_DNS_LOOKUP_QUEUE_FULL && !isPACURI) {
+    query->OnLookupComplete(NULL, NULL, NS_OK);
+    rv = NS_OK;
+  } else if (NS_FAILED(rv)) {
     NS_WARNING("failed to start PAC query");
     PR_REMOVE_LINK(query);
     NS_RELEASE(query);
   }
 
   return rv;
 }
 
@@ -374,19 +380,22 @@ nsPACMan::ProcessPendingQ(nsresult statu
   // Now, start any pending queries
   PRCList *node = PR_LIST_HEAD(&mPendingQ);
   while (node != &mPendingQ) {
     PendingPACQuery *query = static_cast<PendingPACQuery *>(node);
     node = PR_NEXT_LINK(node);
     if (NS_SUCCEEDED(status)) {
       // keep the query in the list (so we can complete it from Shutdown if
       // necessary).
-      status = query->Start();
+      status = query->Start(nsIDNSService::RESOLVE_SPECULATE);
     }
-    if (NS_FAILED(status)) {
+    if (status == NS_ERROR_DNS_LOOKUP_QUEUE_FULL) {
+      query->OnLookupComplete(NULL, NULL, NS_OK);
+      status = NS_OK;
+    } else if (NS_FAILED(status)) {
       // remove the query from the list
       PR_REMOVE_LINK(query);
       query->Complete(status, EmptyCString());
       NS_RELEASE(query);
     }
   }
 }