Bug 912259 - about:networking DNS Lookup Diagnostic Tool - patch over backend. r=mcmanus
authorCatalin Iordache <catalinn.iordache@gmail.com>
Wed, 04 Sep 2013 12:50:11 -0400
changeset 145430 e56e7c0e83f2de1c4ca6a52a61c1a5c6e4405806
parent 145429 cff37b5ea5fb7da9d737981d959c63318b562b13
child 145431 31d86f50d43786c44ed6b8ec728442a66306490f
push id2493
push userryanvm@gmail.com
push dateWed, 04 Sep 2013 16:53:06 +0000
treeherderfx-team@00209f73f7b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs912259
milestone26.0a1
Bug 912259 - about:networking DNS Lookup Diagnostic Tool - patch over backend. r=mcmanus
netwerk/base/src/Dashboard.cpp
netwerk/base/src/Dashboard.h
--- a/netwerk/base/src/Dashboard.cpp
+++ b/netwerk/base/src/Dashboard.cpp
@@ -20,16 +20,18 @@ using mozilla::dom::Sequence;
 
 Dashboard::Dashboard()
 {
     mEnableLogging = false;
 }
 
 Dashboard::~Dashboard()
 {
+    if (mDnsup.cancel)
+        mDnsup.cancel->Cancel(NS_ERROR_ABORT);
 }
 
 NS_IMETHODIMP
 Dashboard::RequestSockets(NetDashboardCallback* cb)
 {
     if (mSock.cb)
         return NS_ERROR_FAILURE;
     mSock.cb = cb;
@@ -398,76 +400,16 @@ Dashboard::RequestDNSInfo(NetDashboardCa
             return rv;
     }
 
     nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &Dashboard::GetDnsInfoDispatch);
     gSocketTransportService->Dispatch(event, NS_DISPATCH_NORMAL);
     return NS_OK;
 }
 
-NS_IMETHODIMP
-Dashboard::RequestDNSLookup(const nsACString &aHost, NetDashboardCallback* cb)
-{
-    if (mDnsup.cb)
-        return NS_ERROR_FAILURE;
-    mDnsup.cb = cb;
-    nsresult rv;
-    mDnsup.thread = NS_GetCurrentThread();
-
-    if (!mDnsup.serv) {
-        mDnsup.serv = do_GetService("@mozilla.org/network/dns-service;1", &rv);
-        if (NS_FAILED(rv)) {
-            mDnsup.cb = nullptr;
-            return rv;
-        }
-    }
-    mDnsup.serv->AsyncResolve(aHost, 0, this, mDnsup.thread, getter_AddRefs(mDnsup.mCancel));
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-Dashboard::OnLookupComplete(nsICancelable *aRequest, nsIDNSRecord *aRecord, nsresult aStatus)
-{
-    AutoSafeJSContext cx;
-
-    mozilla::dom::DNSLookupDict dict;
-    dict.mAddress.Construct();
-    dict.mError.Construct();
-    dict.mAnswer.Construct();
-
-    Sequence<nsString> &addresses = dict.mAddress.Value();
-    nsString &error = dict.mError.Value();
-    bool &answer = dict.mAnswer.Value();
-
-    if (!NS_FAILED(aStatus)) {
-        answer = true;
-        bool hasMore;
-        aRecord->HasMore(&hasMore);
-        while(hasMore) {
-           nsCString nextAddress;
-           aRecord->GetNextAddrAsString(nextAddress);
-           CopyASCIItoUTF16(nextAddress, *addresses.AppendElement());
-           aRecord->HasMore(&hasMore);
-        }
-    } else {
-        answer = false;
-        CopyASCIItoUTF16(GetErrorString(aStatus), error);
-    }
-
-    JS::RootedValue val(cx);
-    if (!dict.ToObject(cx, JS::NullPtr(), &val)) {
-        mDnsup.cb = nullptr;
-        return NS_ERROR_FAILURE;
-    }
-    mDnsup.cb->OnDashboardDataAvailable(val);
-    mDnsup.cb = nullptr;
-
-    return NS_OK;
-}
-
 void
 Dashboard::GetDnsInfoDispatch()
 {
     if (mDns.serv)
         mDns.serv->GetDNSCacheEntries(&mDns.data);
     nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &Dashboard::GetDNSCacheEntries);
     mDns.thread->Dispatch(event, NS_DISPATCH_NORMAL);
 }
@@ -525,16 +467,82 @@ Dashboard::GetDNSCacheEntries()
         return NS_ERROR_FAILURE;
     }
     mDns.cb->OnDashboardDataAvailable(val);
     mDns.cb = nullptr;
 
     return NS_OK;
 }
 
+NS_IMETHODIMP
+Dashboard::RequestDNSLookup(const nsACString &aHost, NetDashboardCallback *cb)
+{
+    if (mDnsup.cb)
+        return NS_ERROR_FAILURE;
+    nsresult rv;
+
+    if (!mDnsup.serv) {
+        mDnsup.serv = do_GetService("@mozilla.org/network/dns-service;1", &rv);
+        if (NS_FAILED(rv))
+            return rv;
+    }
+
+    mDnsup.cb = cb;
+    rv = mDnsup.serv->AsyncResolve(aHost, 0, this, NS_GetCurrentThread(), getter_AddRefs(mDnsup.cancel));
+    if (NS_FAILED(rv)) {
+        mDnsup.cb = nullptr;
+        return rv;
+    }
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+Dashboard::OnLookupComplete(nsICancelable *aRequest, nsIDNSRecord *aRecord, nsresult aStatus)
+{
+    MOZ_ASSERT(aRequest == mDnsup.cancel);
+    mDnsup.cancel = nullptr;
+
+    AutoSafeJSContext cx;
+
+    mozilla::dom::DNSLookupDict dict;
+    dict.mAddress.Construct();
+    dict.mError.Construct();
+    dict.mAnswer.Construct();
+
+    Sequence<nsString> &addresses = dict.mAddress.Value();
+    nsString &error = dict.mError.Value();
+    bool &answer = dict.mAnswer.Value();
+
+    if (NS_SUCCEEDED(aStatus)) {
+        answer = true;
+        bool hasMore;
+        aRecord->HasMore(&hasMore);
+        while(hasMore) {
+           nsCString nextAddress;
+           aRecord->GetNextAddrAsString(nextAddress);
+           CopyASCIItoUTF16(nextAddress, *addresses.AppendElement());
+           aRecord->HasMore(&hasMore);
+        }
+    } else {
+        answer = false;
+        CopyASCIItoUTF16(GetErrorString(aStatus), error);
+    }
+
+    JS::RootedValue val(cx);
+    if (!dict.ToObject(cx, JS::NullPtr(), &val)) {
+        mDnsup.cb = nullptr;
+        return NS_ERROR_FAILURE;
+    }
+    mDnsup.cb->OnDashboardDataAvailable(val);
+    mDnsup.cb = nullptr;
+
+    return NS_OK;
+}
+
 void
 HttpConnInfo::SetHTTP1ProtocolVersion(uint8_t pv)
 {
     switch (pv) {
     case NS_HTTP_VERSION_0_9:
         protocolVersion.Assign(NS_LITERAL_STRING("http/0.9"));
         break;
     case NS_HTTP_VERSION_1_0:
--- a/netwerk/base/src/Dashboard.h
+++ b/netwerk/base/src/Dashboard.h
@@ -120,19 +120,18 @@ private:
         nsTArray<DNSCacheEntries> data;
         nsCOMPtr<NetDashboardCallback> cb;
         nsIThread* thread;
     };
 
     struct DnsLookup
     {
         nsCOMPtr<nsIDNSService> serv;
-        nsCOMPtr<nsICancelable> mCancel;
+        nsCOMPtr<nsICancelable> cancel;
         nsCOMPtr<NetDashboardCallback> cb;
-        nsIThread* thread;
     };
 
     struct ConnectionData
     {
         nsCOMPtr<nsISocketTransport> socket;
         nsCOMPtr<nsIInputStream> streamIn;
         nsCOMPtr<nsITimer> timer;
         nsCOMPtr<NetDashboardCallback> cb;