Bug 1494469 - Removed duplicate IPC::MAX_MESSAGE_SIZE constant r=jld
authorhafsa <hijitsuhisa@gmail.com>
Fri, 12 Apr 2019 13:01:41 +0000
changeset 469512 e25e95c59e6b
parent 469511 2e9b1056dca8
child 469513 ea02b41a2b1d
push id35873
push userccoroiu@mozilla.com
push dateMon, 15 Apr 2019 21:36:26 +0000
treeherdermozilla-central@b8f49a14c458 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjld
bugs1494469
milestone68.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 1494469 - Removed duplicate IPC::MAX_MESSAGE_SIZE constant r=jld The maximum size of an IPC message is defined twice; IPC::Channel::kMaximumMessageSize = 256 MiB and IPC::MAX_MESSAGE_SIZE = 65 KiB . The latter one is used for Windows printing and its small size could cause errors. I removed the small constant, and made changes to the files using it : - The windows printing file now uses kMaximumMessageSize / 2 - nsWebBrowserPersist uses its old constant Differential Revision: https://phabricator.services.mozilla.com/D24972
dom/webbrowserpersist/WebBrowserPersistSerializeChild.cpp
ipc/glue/IPCMessageUtils.h
widget/windows/nsPrintSettingsServiceWin.cpp
--- a/dom/webbrowserpersist/WebBrowserPersistSerializeChild.cpp
+++ b/dom/webbrowserpersist/WebBrowserPersistSerializeChild.cpp
@@ -4,17 +4,16 @@
  * 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 "WebBrowserPersistSerializeChild.h"
 
 #include <algorithm>
 
 #include "nsThreadUtils.h"
-#include "ipc/IPCMessageUtils.h"
 
 namespace mozilla {
 
 NS_IMPL_ISUPPORTS(WebBrowserPersistSerializeChild,
                   nsIWebBrowserPersistWriteCompletion,
                   nsIWebBrowserPersistURIMap, nsIOutputStream)
 
 WebBrowserPersistSerializeChild::WebBrowserPersistSerializeChild(
@@ -77,24 +76,28 @@ WebBrowserPersistSerializeChild::Write(c
   // thread (which also means it's difficult to test the
   // thread-safety code this class doesn't yet have).
   //
   // This is *not* an NS_ERROR_NOT_IMPLEMENTED, because at this
   // point we've probably already misused the non-thread-safe
   // refcounting.
   MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Fix this class to be thread-safe.");
 
+  // Limit the message size to 64k because large messages are
+  // potentially bad for the latency of other messages on the same channel.
+  static const uint32_t kMaxWrite = 65536;
+
   // Work around bug 1181433 by sending multiple messages if
   // necessary to write the entire aCount bytes, even though
   // nsIOutputStream.idl says we're allowed to do a short write.
   const char* buf = aBuf;
   uint32_t count = aCount;
   *aWritten = 0;
   while (count > 0) {
-    uint32_t toWrite = std::min(IPC::MAX_MESSAGE_SIZE, count);
+    uint32_t toWrite = std::min(kMaxWrite, count);
     nsTArray<uint8_t> arrayBuf;
     // It would be nice if this extra copy could be avoided.
     arrayBuf.AppendElements(buf, toWrite);
     SendWriteData(std::move(arrayBuf));
     *aWritten += toWrite;
     buf += toWrite;
     count -= toWrite;
   }
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -99,21 +99,16 @@ struct SerializedStructuredCloneBuffer f
   JSStructuredCloneData data;
 };
 
 }  // namespace mozilla
 
 namespace IPC {
 
 /**
- * Maximum size, in bytes, of a single IPC message.
- */
-static const uint32_t MAX_MESSAGE_SIZE = 65536;
-
-/**
  * Generic enum serializer.
  *
  * Consider using the specializations below, such as ContiguousEnumSerializer.
  *
  * This is a generic serializer for any enum type used in IPDL.
  * Programmers can define ParamTraits<E> for enum type E by deriving
  * EnumSerializer<E, MyEnumValidator> where MyEnumValidator is a struct
  * that has to define a static IsLegalValue function returning whether
--- a/widget/windows/nsPrintSettingsServiceWin.cpp
+++ b/widget/windows/nsPrintSettingsServiceWin.cpp
@@ -66,17 +66,17 @@ nsPrintSettingsServiceWin::SerializeToPr
                                      // to do this.
     if (devModeRaw) {
       nsAutoDevMode devMode(devModeRaw);
       devModeRaw = nullptr;
 
       size_t devModeTotalSize = devMode->dmSize + devMode->dmDriverExtra;
       size_t msgTotalSize = sizeof(PrintData) + devModeTotalSize;
 
-      if (msgTotalSize > IPC::MAX_MESSAGE_SIZE) {
+      if (msgTotalSize > IPC::Channel::kMaximumMessageSize / 2) {
         return NS_ERROR_FAILURE;
       }
 
       // Instead of reaching in and manually reading each member, we'll just
       // copy the bits over.
       const char* devModeData = reinterpret_cast<const char*>(devMode.get());
       nsTArray<uint8_t> arrayBuf;
       arrayBuf.AppendElements(devModeData, devModeTotalSize);