Bug 1437114 - ExternalHelperAppChild should send data to the parent actor in chunks, r=froydnj
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 12 Feb 2018 17:41:34 +0100
changeset 403462 75b746a5d92cf7c7b67b27bf8721f1039660e0ab
parent 403461 5c126d7831a3c83bc5b92ac36fb4ae6a0e2815af
child 403463 39b39fc61d53e08fc6371e612195beb71529c70a
push id33433
push useraciure@mozilla.com
push dateMon, 12 Feb 2018 22:08:56 +0000
treeherdermozilla-central@6d8f470b2579 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1437114
milestone60.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 1437114 - ExternalHelperAppChild should send data to the parent actor in chunks, r=froydnj
uriloader/exthandler/ExternalHelperAppChild.cpp
--- a/uriloader/exthandler/ExternalHelperAppChild.cpp
+++ b/uriloader/exthandler/ExternalHelperAppChild.cpp
@@ -38,23 +38,38 @@ ExternalHelperAppChild::OnDataAvailable(
                                         nsISupports *ctx,
                                         nsIInputStream *input,
                                         uint64_t offset,
                                         uint32_t count)
 {
   if (NS_FAILED(mStatus))
     return mStatus;
 
+  static uint32_t const kCopyChunkSize = 128 * 1024;
+  uint32_t toRead = std::min<uint32_t>(count, kCopyChunkSize);
+
   nsCString data;
-  nsresult rv = NS_ReadInputStreamToString(input, data, count);
-  if (NS_FAILED(rv))
-    return rv;
+  if (NS_WARN_IF(!data.SetCapacity(toRead, fallible))) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
-  if (!SendOnDataAvailable(data, offset, count))
-    return NS_ERROR_UNEXPECTED;
+  while (count) {
+    nsresult rv = NS_ReadInputStreamToString(input, data, toRead);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+
+    if (NS_WARN_IF(!SendOnDataAvailable(data, offset, toRead))) {
+      return NS_ERROR_UNEXPECTED;
+    }
+
+    count -= toRead;
+    offset += toRead;
+    toRead = std::min<uint32_t>(count, kCopyChunkSize);
+  }
 
   return NS_OK;
 }
 
 //////////////////////////////////////////////////////////////////////////////
 // nsIRequestObserver
 //////////////////////////////////////////////////////////////////////////////