Line data Source code
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. For example in the
38 : * PFlyWebPublishedServer.WebSocketRequest message.
39 : *
40 : * The receiver of that message can then grab the TransportProviderChild and
41 : * without addreffing it, effectively using the refcount that the
42 : * TransportProviderChild got on creation.
43 : */
44 :
45 : class nsISocketTransport;
46 : class nsIAsyncInputStream;
47 : class nsIAsyncOutputStream;
48 :
49 : namespace mozilla {
50 : namespace net {
51 :
52 : class TransportProviderParent final : public PTransportProviderParent
53 : , public nsITransportProvider
54 : , public nsIHttpUpgradeListener
55 : {
56 : public:
57 : TransportProviderParent();
58 :
59 : NS_DECL_ISUPPORTS
60 : NS_DECL_NSITRANSPORTPROVIDER
61 : NS_DECL_NSIHTTPUPGRADELISTENER
62 :
63 0 : void ActorDestroy(ActorDestroyReason aWhy) override {};
64 :
65 : private:
66 : ~TransportProviderParent();
67 :
68 : void MaybeNotify();
69 :
70 : nsCOMPtr<nsIHttpUpgradeListener> mListener;
71 : nsCOMPtr<nsISocketTransport> mTransport;
72 : nsCOMPtr<nsIAsyncInputStream> mSocketIn;
73 : nsCOMPtr<nsIAsyncOutputStream> mSocketOut;
74 : };
75 :
76 : class TransportProviderChild final : public PTransportProviderChild
77 : , public nsITransportProvider
78 : {
79 : public:
80 : TransportProviderChild();
81 :
82 : NS_DECL_ISUPPORTS
83 : NS_DECL_NSITRANSPORTPROVIDER
84 :
85 : private:
86 : ~TransportProviderChild();
87 : };
88 :
89 : } // namespace net
90 : } // namespace mozilla
91 :
92 : #endif
|