IPCTransportProvider.h (2861B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set sw=2 ts=8 et ft=cpp : */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_net_IPCTransportProvider_h 8 #define mozilla_net_IPCTransportProvider_h 9 10 #include "nsISupportsImpl.h" 11 #include "mozilla/net/PTransportProviderParent.h" 12 #include "mozilla/net/PTransportProviderChild.h" 13 #include "nsIHttpChannelInternal.h" 14 #include "nsITransportProvider.h" 15 16 /* 17 * No, the ownership model for TransportProvider is that the child object is 18 * refcounted "normally". I.e. ipdl code doesn't hold a strong reference to 19 * TransportProviderChild. 20 * 21 * When TransportProviderChild goes away, it sends a __delete__ message to the 22 * parent. 23 * 24 * On the parent side, ipdl holds a strong reference to TransportProviderParent. 25 * When the actor is deallocatde it releases the reference to the 26 * TransportProviderParent. 27 * 28 * So effectively the child holds a strong reference to the parent, and are 29 * otherwise normally refcounted and have their lifetime determined by that 30 * refcount. 31 * 32 * The only other caveat is that the creation happens from the parent. 33 * So to create a TransportProvider, a constructor is sent from the parent to 34 * the child. At this time the child gets its first addref. 35 * 36 * A reference to the TransportProvider is then sent as part of some other 37 * message from the parent to the child. 38 * 39 * The receiver of that message can then grab the TransportProviderChild and 40 * without addreffing it, effectively using the refcount that the 41 * TransportProviderChild got on creation. 42 */ 43 44 class nsISocketTransport; 45 class nsIAsyncInputStream; 46 class nsIAsyncOutputStream; 47 48 namespace mozilla { 49 namespace net { 50 51 class TransportProviderParent final : public PTransportProviderParent, 52 public nsITransportProvider, 53 public nsIHttpUpgradeListener { 54 public: 55 TransportProviderParent() = default; 56 57 NS_DECL_ISUPPORTS 58 NS_DECL_NSITRANSPORTPROVIDER 59 NS_DECL_NSIHTTPUPGRADELISTENER 60 61 void ActorDestroy(ActorDestroyReason aWhy) override {} 62 63 private: 64 ~TransportProviderParent() = default; 65 66 void MaybeNotify(); 67 68 nsCOMPtr<nsIHttpUpgradeListener> mListener; 69 nsCOMPtr<nsISocketTransport> mTransport; 70 nsCOMPtr<nsIAsyncInputStream> mSocketIn; 71 nsCOMPtr<nsIAsyncOutputStream> mSocketOut; 72 }; 73 74 class TransportProviderChild final : public PTransportProviderChild, 75 public nsITransportProvider { 76 public: 77 TransportProviderChild() = default; 78 79 NS_DECL_ISUPPORTS 80 NS_DECL_NSITRANSPORTPROVIDER 81 82 private: 83 ~TransportProviderChild(); 84 }; 85 86 } // namespace net 87 } // namespace mozilla 88 89 #endif