Bug 907327 - Updated Dashboard.cpp to use ErrorNames. r=nfroyd
authorAnuj Agarwal <anujagarwal464@gmail.com>
Wed, 22 Oct 2014 08:55:00 +0200
changeset 213068 2a1cd73f279c2dd6a204c53526a67b38c6be4ca1
parent 213067 9965ddd32fd643290eb3d1437cd5554039db5b93
child 213069 17bae3d258dd2c21603cfff73244f706963df8e5
push id51141
push usercbook@mozilla.com
push dateThu, 30 Oct 2014 13:40:28 +0000
treeherdermozilla-inbound@2a1cd73f279c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs907327
milestone36.0a1
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 907327 - Updated Dashboard.cpp to use ErrorNames. r=nfroyd
netwerk/base/src/Dashboard.cpp
--- a/netwerk/base/src/Dashboard.cpp
+++ b/netwerk/base/src/Dashboard.cpp
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http:mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/NetDashboardBinding.h"
 #include "mozilla/dom/ToJSValue.h"
+#include "mozilla/ErrorNames.h"
 #include "mozilla/net/Dashboard.h"
 #include "mozilla/net/HttpInfo.h"
 #include "nsHttp.h"
 #include "nsICancelable.h"
 #include "nsIDNSService.h"
 #include "nsIDNSRecord.h"
 #include "nsIInputStream.h"
 #include "nsISocketTransport.h"
@@ -45,16 +46,18 @@ public:
     nsIThread *mThread;
 
 private:
     virtual ~SocketData()
     {
     }
 };
 
+static void GetErrorString(nsresult rv, nsAString& errorString);
+
 NS_IMPL_ISUPPORTS0(SocketData)
 
 
 class HttpData
     : public nsISupports
 {
     virtual ~HttpData()
     {
@@ -166,17 +169,17 @@ NS_IMPL_ISUPPORTS(ConnectionData, nsITra
 NS_IMETHODIMP
 ConnectionData::OnTransportStatus(nsITransport *aTransport, nsresult aStatus,
                                   uint64_t aProgress, uint64_t aProgressMax)
 {
     if (aStatus == NS_NET_STATUS_CONNECTED_TO) {
         StopTimer();
     }
 
-    CopyASCIItoUTF16(Dashboard::GetErrorString(aStatus), mStatus);
+    GetErrorString(aStatus, mStatus);
     nsCOMPtr<nsIRunnable> event =
         NS_NewRunnableMethodWithArg<nsRefPtr<ConnectionData> >
         (mDashboard, &Dashboard::GetConnectionStatus, this);
     mThread->Dispatch(event, NS_DISPATCH_NORMAL);
 
     return NS_OK;
 }
 
@@ -311,17 +314,17 @@ LookupHelper::ConstructAnswer(LookupArgu
         while (hasMore) {
            nsCString nextAddress;
            aRecord->GetNextAddrAsString(nextAddress);
            CopyASCIItoUTF16(nextAddress, *addresses.AppendElement());
            aRecord->HasMore(&hasMore);
         }
     } else {
         dict.mAnswer = false;
-        CopyASCIItoUTF16(Dashboard::GetErrorString(mStatus), dict.mError);
+        GetErrorString(mStatus, dict.mError);
     }
 
     JS::RootedValue val(cx);
     if (!ToJSValue(cx, dict, &val)) {
         return NS_ERROR_FAILURE;
     }
 
     this->mCallback->OnDashboardDataAvailable(val);
@@ -801,17 +804,17 @@ Dashboard::RequestConnection(const nsACS
     connectionData->mTimeout = aTimeout;
 
     connectionData->mCallback =
         new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
     connectionData->mThread = NS_GetCurrentThread();
 
     rv = TestNewConnection(connectionData);
     if (NS_FAILED(rv)) {
-        CopyASCIItoUTF16(GetErrorString(rv), connectionData->mStatus);
+        mozilla::net::GetErrorString(rv, connectionData->mStatus);
         nsCOMPtr<nsIRunnable> event =
             NS_NewRunnableMethodWithArg<nsRefPtr<ConnectionData> >
             (this, &Dashboard::GetConnectionStatus, connectionData);
         connectionData->mThread->Dispatch(event, NS_DISPATCH_NORMAL);
         return rv;
     }
 
     return NS_OK;
@@ -884,42 +887,35 @@ typedef struct
 {
     nsresult key;
     const char *error;
 } ErrorEntry;
 
 #undef ERROR
 #define ERROR(key, val) {key, #key}
 
-ErrorEntry errors[] = {
-    #include "ErrorList.h"
-};
-
 ErrorEntry socketTransportStatuses[] = {
         ERROR(NS_NET_STATUS_RESOLVING_HOST,  FAILURE(3)),
         ERROR(NS_NET_STATUS_RESOLVED_HOST,   FAILURE(11)),
         ERROR(NS_NET_STATUS_CONNECTING_TO,   FAILURE(7)),
         ERROR(NS_NET_STATUS_CONNECTED_TO,    FAILURE(4)),
         ERROR(NS_NET_STATUS_SENDING_TO,      FAILURE(5)),
         ERROR(NS_NET_STATUS_WAITING_FOR,     FAILURE(10)),
         ERROR(NS_NET_STATUS_RECEIVING_FROM,  FAILURE(6)),
 };
 #undef ERROR
 
-const char *
-Dashboard::GetErrorString(nsresult rv)
+
+static void
+GetErrorString(nsresult rv, nsAString& errorString)
 {
-    int length = sizeof(socketTransportStatuses) / sizeof(ErrorEntry);
-    for (int i = 0;i < length;i++)
+    for (size_t i = 0; i < ArrayLength(socketTransportStatuses); ++i) {
         if (socketTransportStatuses[i].key == rv) {
-            return socketTransportStatuses[i].error;
+            errorString.AssignASCII(socketTransportStatuses[i].error);
+            return;
         }
-
-    length = sizeof(errors) / sizeof(ErrorEntry);
-    for (int i = 0;i < length;i++)
-        if (errors[i].key == rv) {
-            return errors[i].error;
-        }
-
-    return nullptr;
+    }
+    nsAutoCString errorCString;
+    mozilla::GetErrorName(rv, errorCString);
+    CopyUTF8toUTF16(errorCString, errorString);
 }
 
 } } // namespace mozilla::net