Bug 1534666 - replace OptionalInputStreamParams with InputStreamParams? in IPDL; r=mccr8
authorAlex Gaynor <agaynor@mozilla.com>
Tue, 12 Mar 2019 15:52:26 +0000
changeset 521580 7f2ca89b9801e747dfcd556908dd6f9e712a66a9
parent 521579 4f66d73a9466c86797238dca29fe4f9d7ffdde14
child 521581 7d1ef08b4ceab853ac395b0c36e046252ddc8730
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1534666
milestone67.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 1534666 - replace OptionalInputStreamParams with InputStreamParams? in IPDL; r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D23153
ipc/glue/InputStreamParams.ipdlh
ipc/glue/InputStreamUtils.cpp
ipc/glue/InputStreamUtils.h
netwerk/base/nsBufferedStreams.cpp
netwerk/base/nsMIMEInputStream.cpp
--- a/ipc/glue/InputStreamParams.ipdlh
+++ b/ipc/glue/InputStreamParams.ipdlh
@@ -82,31 +82,25 @@ union InputStreamParams
   MIMEInputStreamParams;
   MultiplexInputStreamParams;
   SlicedInputStreamParams;
   IPCBlobInputStreamParams;
   InputStreamLengthWrapperParams;
   IPCRemoteStreamParams;
 };
 
-union OptionalInputStreamParams
-{
-  void_t;
-  InputStreamParams;
-};
-
 struct BufferedInputStreamParams
 {
-  OptionalInputStreamParams optionalStream;
+  InputStreamParams? optionalStream;
   uint32_t bufferSize;
 };
 
 struct MIMEInputStreamParams
 {
-  OptionalInputStreamParams optionalStream;
+  InputStreamParams? optionalStream;
   HeaderEntry[] headers;
   bool startedReading;
 };
 
 struct InputStreamLengthWrapperParams
 {
   InputStreamParams stream;
   int64_t length;
--- a/ipc/glue/InputStreamUtils.cpp
+++ b/ipc/glue/InputStreamUtils.cpp
@@ -271,21 +271,21 @@ void InputStreamHelper::PostSerializatio
     default:
       MOZ_CRASH(
           "A new stream? Should decide if it must be processed recursively or "
           "not.");
   }
 }
 
 void InputStreamHelper::PostSerializationActivation(
-    OptionalInputStreamParams& aParams, bool aConsumedByIPC,
+    Maybe<InputStreamParams>& aParams, bool aConsumedByIPC,
     bool aDelayedStart) {
-  if (aParams.type() == OptionalInputStreamParams::TInputStreamParams) {
+  if (aParams.isSome()) {
     InputStreamHelper::PostSerializationActivation(
-        aParams.get_InputStreamParams(), aConsumedByIPC, aDelayedStart);
+        aParams.ref(), aConsumedByIPC, aDelayedStart);
   }
 }
 
 already_AddRefed<nsIInputStream> InputStreamHelper::DeserializeInputStream(
     const InputStreamParams& aParams,
     const nsTArray<FileDescriptor>& aFileDescriptors) {
   // IPCBlobInputStreams are not deserializable on the parent side.
   if (aParams.type() == InputStreamParams::TIPCBlobInputStreamParams) {
--- a/ipc/glue/InputStreamUtils.h
+++ b/ipc/glue/InputStreamUtils.h
@@ -79,17 +79,17 @@ class InputStreamHelper {
 
   // After the sending of the inputStream into the IPC pipe, some of the
   // InputStreamParams data struct needs to be activated (IPCRemoteStream).
   // These 2 methods do that.
   static void PostSerializationActivation(InputStreamParams& aParams,
                                           bool aConsumedByIPC,
                                           bool aDelayedStart);
 
-  static void PostSerializationActivation(OptionalInputStreamParams& aParams,
+  static void PostSerializationActivation(Maybe<InputStreamParams>& aParams,
                                           bool aConsumedByIPC,
                                           bool aDelayedStart);
 
   static already_AddRefed<nsIInputStream> DeserializeInputStream(
       const InputStreamParams& aParams,
       const nsTArray<FileDescriptor>& aFileDescriptors);
 };
 
--- a/netwerk/base/nsBufferedStreams.cpp
+++ b/netwerk/base/nsBufferedStreams.cpp
@@ -630,19 +630,17 @@ void nsBufferedInputStream::SerializeInt
     nsCOMPtr<nsIInputStream> stream = do_QueryInterface(mStream);
     MOZ_ASSERT(stream);
 
     InputStreamParams wrappedParams;
     InputStreamHelper::SerializeInputStream(stream, wrappedParams,
                                             aFileDescriptors, aDelayedStart,
                                             aMaxSize, aSizeUsed, aManager);
 
-    params.optionalStream() = wrappedParams;
-  } else {
-    params.optionalStream() = mozilla::void_t();
+    params.optionalStream().emplace(wrappedParams);
   }
 
   params.bufferSize() = mBufferSize;
 
   aParams = params;
 }
 
 bool nsBufferedInputStream::Deserialize(
@@ -650,29 +648,26 @@ bool nsBufferedInputStream::Deserialize(
     const FileDescriptorArray& aFileDescriptors) {
   if (aParams.type() != InputStreamParams::TBufferedInputStreamParams) {
     NS_ERROR("Received unknown parameters from the other process!");
     return false;
   }
 
   const BufferedInputStreamParams& params =
       aParams.get_BufferedInputStreamParams();
-  const OptionalInputStreamParams& wrappedParams = params.optionalStream();
+  const Maybe<InputStreamParams>& wrappedParams = params.optionalStream();
 
   nsCOMPtr<nsIInputStream> stream;
-  if (wrappedParams.type() == OptionalInputStreamParams::TInputStreamParams) {
-    stream = InputStreamHelper::DeserializeInputStream(
-        wrappedParams.get_InputStreamParams(), aFileDescriptors);
+  if (wrappedParams.isSome()) {
+    stream = InputStreamHelper::DeserializeInputStream(wrappedParams.ref(),
+                                                       aFileDescriptors);
     if (!stream) {
       NS_WARNING("Failed to deserialize wrapped stream!");
       return false;
     }
-  } else {
-    NS_ASSERTION(wrappedParams.type() == OptionalInputStreamParams::Tvoid_t,
-                 "Unknown type for OptionalInputStreamParams!");
   }
 
   nsresult rv = Init(stream, params.bufferSize());
   NS_ENSURE_SUCCESS(rv, false);
 
   return true;
 }
 
--- a/netwerk/base/nsMIMEInputStream.cpp
+++ b/netwerk/base/nsMIMEInputStream.cpp
@@ -386,19 +386,17 @@ void nsMIMEInputStream::SerializeInterna
     InputStreamParams wrappedParams;
     InputStreamHelper::SerializeInputStream(mStream, wrappedParams,
                                             aFileDescriptors, aDelayedStart,
                                             aMaxSize, aSizeUsed, aManager);
 
     NS_ASSERTION(wrappedParams.type() != InputStreamParams::T__None,
                  "Wrapped stream failed to serialize!");
 
-    params.optionalStream() = wrappedParams;
-  } else {
-    params.optionalStream() = mozilla::void_t();
+    params.optionalStream().emplace(wrappedParams);
   }
 
   params.headers() = mHeaders;
   params.startedReading() = mStartedReading;
 
   aParams = params;
 }
 
@@ -406,34 +404,31 @@ bool nsMIMEInputStream::Deserialize(
     const InputStreamParams& aParams,
     const FileDescriptorArray& aFileDescriptors) {
   if (aParams.type() != InputStreamParams::TMIMEInputStreamParams) {
     NS_ERROR("Received unknown parameters from the other process!");
     return false;
   }
 
   const MIMEInputStreamParams& params = aParams.get_MIMEInputStreamParams();
-  const OptionalInputStreamParams& wrappedParams = params.optionalStream();
+  const Maybe<InputStreamParams>& wrappedParams = params.optionalStream();
 
   mHeaders = params.headers();
   mStartedReading = params.startedReading();
 
-  if (wrappedParams.type() == OptionalInputStreamParams::TInputStreamParams) {
+  if (wrappedParams.isSome()) {
     nsCOMPtr<nsIInputStream> stream;
-    stream = InputStreamHelper::DeserializeInputStream(
-        wrappedParams.get_InputStreamParams(), aFileDescriptors);
+    stream = InputStreamHelper::DeserializeInputStream(wrappedParams.ref(),
+                                                       aFileDescriptors);
     if (!stream) {
       NS_WARNING("Failed to deserialize wrapped stream!");
       return false;
     }
 
     mStream = stream;
-  } else {
-    NS_ASSERTION(wrappedParams.type() == OptionalInputStreamParams::Tvoid_t,
-                 "Unknown type for OptionalInputStreamParams!");
   }
 
   return true;
 }
 
 NS_IMETHODIMP
 nsMIMEInputStream::Length(int64_t* aLength) {
   nsCOMPtr<nsIInputStreamLength> stream = do_QueryInterface(mStream);