Bug 1353475 - Implement AutoIPCStream with delayed start - part 1 - changing the IPDL dictionaries for streams, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 24 Apr 2017 12:09:39 +0200
changeset 354613 f6f3a2c33c8f0faaff9f06e13bdf99f07e4e0a37
parent 354612 ffe6a7d2c74c07ac6ecf8a6b890141dacbaa9b9e
child 354614 322035f4e78366fd25b74cbee77ddf18c5565962
push id31707
push userkwierso@gmail.com
push dateMon, 24 Apr 2017 22:53:41 +0000
treeherdermozilla-central@abdcc8dfc283 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1353475
milestone55.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 1353475 - Implement AutoIPCStream with delayed start - part 1 - changing the IPDL dictionaries for streams, r=smaug
ipc/glue/IPCStream.ipdlh
ipc/glue/IPCStreamUtils.cpp
--- a/ipc/glue/IPCStream.ipdlh
+++ b/ipc/glue/IPCStream.ipdlh
@@ -1,35 +1,47 @@
 /* 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 protocol PChildToParentStream;
 include protocol PParentToChildStream;
+
 include BlobTypes;
 include InputStreamParams;
+include ProtocolTypes;
 
 namespace mozilla {
 namespace ipc {
 
 // Do not use this directly.  See IPCStream below.
 struct InputStreamParamsWithFds
 {
   InputStreamParams stream;
   OptionalFileDescriptorSet optionalFds;
 };
 
+union IPCRemoteStreamType
+{
+  PChildToParentStream;
+  PParentToChildStream;
+};
+
+struct IPCRemoteStream
+{
+  IPCRemoteStreamType stream;
+};
+
 // Use IPCStream or OptionalIPCStream in your ipdl to represent serialized
 // nsIInputStreams.  Then use AutoIPCStream from IPCStreamUtils.h to perform
 // the serialization.
 union IPCStream
 {
   InputStreamParamsWithFds;
-  PChildToParentStream;
-  PParentToChildStream;
+  IPCRemoteStream;
 };
 
 union OptionalIPCStream
 {
   IPCStream;
   void_t;
 };
 
--- a/ipc/glue/IPCStreamUtils.cpp
+++ b/ipc/glue/IPCStreamUtils.cpp
@@ -31,18 +31,17 @@ using namespace mozilla::dom;
 namespace mozilla {
 namespace ipc {
 
 namespace {
 
 void
 AssertValidValueToTake(const IPCStream& aVal)
 {
-  MOZ_ASSERT(aVal.type() == IPCStream::TPChildToParentStreamChild ||
-             aVal.type() == IPCStream::TPParentToChildStreamParent ||
+  MOZ_ASSERT(aVal.type() == IPCStream::TIPCRemoteStream ||
              aVal.type() == IPCStream::TInputStreamParamsWithFds);
 }
 
 void
 AssertValidValueToTake(const OptionalIPCStream& aVal)
 {
   MOZ_ASSERT(aVal.type() == OptionalIPCStream::Tvoid_t ||
              aVal.type() == OptionalIPCStream::TIPCStream);
@@ -159,17 +158,21 @@ SerializeInputStream(nsIInputStream* aSt
     rv = NS_AsyncCopy(aStream, sink, target, NS_ASYNCCOPY_VIA_READSEGMENTS,
                       kBufferSize);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return false;
     }
   }
 
   MOZ_ASSERT(asyncStream);
-  aValue = IPCStreamSource::Create(asyncStream, aManager);
+
+  IPCRemoteStream remoteStream;
+  remoteStream.stream() = IPCStreamSource::Create(asyncStream, aManager);
+  aValue = remoteStream;
+
   return true;
 }
 
 template<typename M>
 bool
 SerializeInputStreamChild(nsIInputStream* aStream, M* aManager,
                           IPCStream* aValue,
                           OptionalIPCStream* aOptionalValue)
@@ -287,22 +290,26 @@ CleanupIPCStream(IPCStream& aValue, bool
       if (!aConsumedByIPC) {
         Unused << fdSetActor->Send__delete__(fdSetActor);
       }
     }
 
     return;
   }
 
+  MOZ_ASSERT(aValue.type() == IPCStream::TIPCRemoteStream);
+  IPCRemoteStreamType& remoteInputStream =
+    aValue.get_IPCRemoteStream().stream();
+
   IPCStreamSource* source = nullptr;
-  if (aValue.type() == IPCStream::TPChildToParentStreamChild) {
-    source = IPCStreamSource::Cast(aValue.get_PChildToParentStreamChild());
+  if (remoteInputStream.type() == IPCRemoteStreamType::TPChildToParentStreamChild) {
+    source = IPCStreamSource::Cast(remoteInputStream.get_PChildToParentStreamChild());
   } else {
-    MOZ_ASSERT(aValue.type() == IPCStream::TPParentToChildStreamParent);
-    source = IPCStreamSource::Cast(aValue.get_PParentToChildStreamParent());
+    MOZ_ASSERT(remoteInputStream.type() == IPCRemoteStreamType::TPParentToChildStreamParent);
+    source = IPCStreamSource::Cast(remoteInputStream.get_PParentToChildStreamParent());
   }
 
   MOZ_ASSERT(source);
 
   if (!aConsumedByIPC) {
     source->StartDestroy();
     return;
   }
@@ -343,25 +350,29 @@ NormalizeOptionalValue(nsIInputStream* a
   return true;
 }
 
 } // anonymous namespace
 
 already_AddRefed<nsIInputStream>
 DeserializeIPCStream(const IPCStream& aValue)
 {
-  if (aValue.type() == IPCStream::TPChildToParentStreamParent) {
+  if (aValue.type() == IPCStream::TIPCRemoteStream) {
+    const IPCRemoteStreamType& remoteInputStream =
+      aValue.get_IPCRemoteStream().stream();
+    if (remoteInputStream.type() == IPCRemoteStreamType::TPChildToParentStreamParent) {
+      auto sendStream =
+        IPCStreamDestination::Cast(remoteInputStream.get_PChildToParentStreamParent());
+      return sendStream->TakeReader();
+    }
+
+    MOZ_ASSERT(remoteInputStream.type() == IPCRemoteStreamType::TPParentToChildStreamChild);
+
     auto sendStream =
-      IPCStreamDestination::Cast(aValue.get_PChildToParentStreamParent());
-    return sendStream->TakeReader();
-  }
-
-  if (aValue.type() == IPCStream::TPParentToChildStreamChild) {
-    auto sendStream =
-      IPCStreamDestination::Cast(aValue.get_PParentToChildStreamChild());
+      IPCStreamDestination::Cast(remoteInputStream.get_PParentToChildStreamChild());
     return sendStream->TakeReader();
   }
 
   // Note, we explicitly do not support deserializing the PChildToParentStream actor on
   // the child side nor the PParentToChildStream actor on the parent side.
   MOZ_ASSERT(aValue.type() == IPCStream::TInputStreamParamsWithFds);
 
   const InputStreamParamsWithFds& streamWithFds =