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 tw=80 : */
3 :
4 : /* This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 :
8 : #ifndef mozilla_net_HttpBackgroundChannelChild_h
9 : #define mozilla_net_HttpBackgroundChannelChild_h
10 :
11 : #include "mozilla/net/PHttpBackgroundChannelChild.h"
12 : #include "nsIRunnable.h"
13 : #include "nsTArray.h"
14 :
15 : using mozilla::ipc::IPCResult;
16 : using mozilla::dom::ClassifierInfo;
17 :
18 : namespace mozilla {
19 : namespace net {
20 :
21 : class HttpChannelChild;
22 :
23 : class HttpBackgroundChannelChild final : public PHttpBackgroundChannelChild
24 : {
25 : friend class BackgroundChannelCreateCallback;
26 : public:
27 : explicit HttpBackgroundChannelChild();
28 :
29 48 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(HttpBackgroundChannelChild)
30 :
31 : // Associate this background channel with a HttpChannelChild and
32 : // initiate the createion of the PBackground IPC channel.
33 : nsresult Init(HttpChannelChild* aChannelChild);
34 :
35 : // Callback while the associated HttpChannelChild is not going to
36 : // handle any incoming messages over background channel.
37 : void OnChannelClosed();
38 :
39 : // Callback when OnStartRequest is received and handled by HttpChannelChild.
40 : // Enqueued messages in background channel will be flushed.
41 : void OnStartRequestReceived();
42 :
43 : // Callback while failed to create PBackground IPC channel.
44 : void OnBackgroundChannelCreationFailed();
45 :
46 : protected:
47 : IPCResult RecvOnTransportAndData(const nsresult& aChannelStatus,
48 : const nsresult& aTransportStatus,
49 : const uint64_t& aOffset,
50 : const uint32_t& aCount,
51 : const nsCString& aData) override;
52 :
53 : IPCResult RecvOnStopRequest(const nsresult& aChannelStatus,
54 : const ResourceTimingStruct& aTiming) override;
55 :
56 : IPCResult RecvOnProgress(const int64_t& aProgress,
57 : const int64_t& aProgressMax) override;
58 :
59 : IPCResult RecvOnStatus(const nsresult& aStatus) override;
60 :
61 : IPCResult RecvFlushedForDiversion() override;
62 :
63 : IPCResult RecvDivertMessages() override;
64 :
65 : IPCResult RecvOnStartRequestSent() override;
66 :
67 : IPCResult RecvNotifyTrackingProtectionDisabled() override;
68 :
69 : IPCResult RecvNotifyTrackingResource() override;
70 :
71 : IPCResult RecvSetClassifierMatchedInfo(const ClassifierInfo& info) override;
72 :
73 : void ActorDestroy(ActorDestroyReason aWhy) override;
74 :
75 : private:
76 : virtual ~HttpBackgroundChannelChild();
77 :
78 : // Initiate the creation of the PBckground IPC channel.
79 : // Return false if failed.
80 : bool CreateBackgroundChannel();
81 :
82 : // Check OnStartRequest is sent by parent process over main thread IPC
83 : // but not yet received on child process.
84 : // return true before RecvOnStartRequestSent is invoked.
85 : // return false if RecvOnStartRequestSent is invoked but not
86 : // OnStartRequestReceived.
87 : // return true after both RecvOnStartRequestSend and OnStartRequestReceived
88 : // are invoked.
89 : bool IsWaitingOnStartRequest();
90 :
91 : // Associated HttpChannelChild for handling the channel events.
92 : // Will be removed while failed to create background channel,
93 : // destruction of the background channel, or explicitly dissociation
94 : // via OnChannelClosed callback.
95 : RefPtr<HttpChannelChild> mChannelChild;
96 :
97 : // True if OnStartRequest is received by HttpChannelChild.
98 : // Should only access on STS thread.
99 : bool mStartReceived = false;
100 :
101 : // True if OnStartRequest is sent by HttpChannelParent.
102 : // Should only access on STS thread.
103 : bool mStartSent = false;
104 :
105 : // Store pending messages that require to be handled after OnStartRequest.
106 : // Should be flushed after OnStartRequest is received and handled.
107 : // Should only access on STS thread.
108 : nsTArray<nsCOMPtr<nsIRunnable>> mQueuedRunnables;
109 : };
110 :
111 : } // namespace net
112 : } // namespace mozilla
113 :
114 : #endif // mozilla_net_HttpBackgroundChannelChild_h
|