Bug 1440771 - Part 2: Use nsCOMPtr<nsIInputStream> directly in PCacheStreamControl, r=baku
authorNika Layzell <nika@thelayzells.com>
Fri, 23 Feb 2018 15:28:11 -0500
changeset 461682 945995a0a8dbc0230b0dee0e2dc9fa0e0a4d5ce5
parent 461681 d506f9eb0db6d368cd0155d8088e362db64daa41
child 461683 02049d16a352bd71963579c0b7b29c96efb5244d
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1440771
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 1440771 - Part 2: Use nsCOMPtr<nsIInputStream> directly in PCacheStreamControl, r=baku MozReview-Commit-ID: 1Ab49lZtxTI
dom/cache/CacheStreamControlChild.cpp
dom/cache/CacheStreamControlParent.cpp
dom/cache/PCacheStreamControl.ipdl
--- a/dom/cache/CacheStreamControlChild.cpp
+++ b/dom/cache/CacheStreamControlChild.cpp
@@ -120,19 +120,18 @@ CacheStreamControlChild::OpenStream(cons
   // If we are on a worker, then we need to hold it alive until the async
   // IPC operation below completes.  While the IPC layer will trigger a
   // rejection here in many cases, we must handle the case where the
   // MozPromise resolve runnable is already in the event queue when the
   // worker wants to shut down.
   RefPtr<CacheWorkerHolder> holder = GetWorkerHolder();
 
   SendOpenStream(aId)->Then(GetCurrentThreadSerialEventTarget(), __func__,
-  [aResolver, holder](const OptionalIPCStream& aOptionalStream) {
-    nsCOMPtr<nsIInputStream> stream = DeserializeIPCStream(aOptionalStream);
-    aResolver(Move(stream));
+  [aResolver, holder](const nsCOMPtr<nsIInputStream>& aOptionalStream) {
+    aResolver(nsCOMPtr<nsIInputStream>(aOptionalStream));
   }, [aResolver, holder](ResponseRejectReason aReason) {
     aResolver(nullptr);
   });
 }
 
 void
 CacheStreamControlChild::NoteClosedAfterForget(const nsID& aId)
 {
--- a/dom/cache/CacheStreamControlParent.cpp
+++ b/dom/cache/CacheStreamControlParent.cpp
@@ -122,30 +122,18 @@ CacheStreamControlParent::ActorDestroy(A
 }
 
 mozilla::ipc::IPCResult
 CacheStreamControlParent::RecvOpenStream(const nsID& aStreamId,
                                          OpenStreamResolver&& aResolver)
 {
   NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
 
-  // This is safe because:
-  //  1. We add ourself to the Manager as an operation Listener in OpenStream().
-  //  2. We remove ourself as a Listener from the Manager in ActorDestroy().
-  //  3. The Manager will not "complete" the operation if the Listener has
-  //     been removed.  This means the lambda will not be invoked.
-  //  4. The ActorDestroy() will also cause the child-side MozPromise for
-  //     this async returning method to be rejected.  So we don't have to
-  //     call the resolver in this case.
-  CacheStreamControlParent* self = this;
-
-  OpenStream(aStreamId, [self, aResolver](nsCOMPtr<nsIInputStream>&& aStream) {
-      AutoIPCStream stream;
-      Unused << stream.Serialize(aStream, self->Manager());
-      aResolver(stream.TakeOptionalValue());
+  OpenStream(aStreamId, [aResolver](nsCOMPtr<nsIInputStream>&& aStream) {
+      aResolver(aStream);
     });
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 CacheStreamControlParent::RecvNoteClosed(const nsID& aId)
 {
--- a/dom/cache/PCacheStreamControl.ipdl
+++ b/dom/cache/PCacheStreamControl.ipdl
@@ -1,30 +1,30 @@
 /* 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 PBackground;
 include protocol PFileDescriptorSet;
 include protocol PChildToParentStream;
 include protocol PParentToChildStream;
-include IPCStream;
 
 using struct nsID from "nsID.h";
+using nsCOMPtr<nsIInputStream> from "mozilla/ipc/IPCStreamUtils.h";
 
 namespace mozilla {
 namespace dom {
 namespace cache {
 
 protocol PCacheStreamControl
 {
   manager PBackground;
 
 parent:
-  async OpenStream(nsID aStreamId) returns(OptionalIPCStream aStream);
+  async OpenStream(nsID aStreamId) returns(nsCOMPtr<nsIInputStream> aStream);
   async NoteClosed(nsID aStreamId);
 
 child:
   async Close(nsID aStreamId);
   async CloseAll();
   async __delete__();
 };