HttpBackgroundChannelParent.h (4715B)
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_HttpBackgroundChannelParent_h 9 #define mozilla_net_HttpBackgroundChannelParent_h 10 11 #include "mozilla/net/PHttpBackgroundChannelParent.h" 12 #include "mozilla/Atomics.h" 13 #include "mozilla/Mutex.h" 14 #include "nsID.h" 15 #include "nsISupportsImpl.h" 16 17 class nsISerialEventTarget; 18 19 namespace mozilla { 20 namespace net { 21 22 class HttpChannelParent; 23 24 class HttpBackgroundChannelParent final : public PHttpBackgroundChannelParent { 25 public: 26 explicit HttpBackgroundChannelParent(); 27 28 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(HttpBackgroundChannelParent, final) 29 30 // Try to find associated HttpChannelParent with the same 31 // channel Id. 32 nsresult Init(const uint64_t& aChannelId); 33 34 // Callbacks for BackgroundChannelRegistrar to notify 35 // the associated HttpChannelParent is found. 36 void LinkToChannel(HttpChannelParent* aChannelParent); 37 38 // Callbacks for HttpChannelParent to close the background 39 // IPC channel. 40 void OnChannelClosed(); 41 42 // To send OnStartRequest message over background channel. 43 bool OnStartRequest(nsHttpResponseHead&& aResponseHead, 44 const bool& aUseResponseHead, 45 const nsHttpHeaderArray& aRequestHeaders, 46 const HttpChannelOnStartRequestArgs& aArgs, 47 const nsCOMPtr<nsICacheEntry>& aCacheEntry, 48 TimeStamp aOnStartRequestStart); 49 50 // To send OnTransportAndData message over background channel. 51 bool OnTransportAndData(const nsresult& aChannelStatus, 52 const nsresult& aTransportStatus, 53 const uint64_t& aOffset, const uint32_t& aCount, 54 const nsCString& aData, 55 TimeStamp aOnDataAvailableStart); 56 57 // To send OnStopRequest message over background channel. 58 bool OnStopRequest(const nsresult& aChannelStatus, 59 const ResourceTimingStructArgs& aTiming, 60 const nsHttpHeaderArray& aResponseTrailers, 61 const nsTArray<ConsoleReportCollected>& aConsoleReports, 62 TimeStamp aOnStopRequestStart); 63 64 // When ODA and OnStopRequest are sending from socket process to child 65 // process, this is the last IPC message sent from parent process. 66 bool OnConsoleReport(const nsTArray<ConsoleReportCollected>& aConsoleReports); 67 68 // To send OnAfterLastPart message over background channel. 69 bool OnAfterLastPart(const nsresult aStatus); 70 71 // To send OnProgress message over background channel. 72 bool OnProgress(const int64_t aProgress, const int64_t aProgressMax); 73 74 // To send OnStatus message over background channel. 75 bool OnStatus(const nsresult aStatus); 76 77 // To send FlushedForDiversion and DivertMessages messages 78 // over background channel. 79 bool OnDiversion(); 80 81 // To send NotifyClassificationFlags message over background channel. 82 bool OnNotifyClassificationFlags(uint32_t aClassificationFlags, 83 bool aIsThirdParty); 84 85 // To send SetClassifierMatchedInfo message over background channel. 86 bool OnSetClassifierMatchedInfo(const nsACString& aList, 87 const nsACString& aProvider, 88 const nsACString& aFullHash); 89 90 // To send SetClassifierMatchedTrackingInfo message over background channel. 91 bool OnSetClassifierMatchedTrackingInfo(const nsACString& aLists, 92 const nsACString& aFullHashes); 93 94 nsISerialEventTarget* GetBackgroundTarget(); 95 96 using ChildEndpointPromise = 97 MozPromise<ipc::Endpoint<extensions::PStreamFilterChild>, bool, true>; 98 [[nodiscard]] RefPtr<ChildEndpointPromise> AttachStreamFilter( 99 Endpoint<extensions::PStreamFilterParent>&& aParentEndpoint, 100 Endpoint<extensions::PStreamFilterChild>&& aChildEndpoint); 101 102 [[nodiscard]] RefPtr<GenericPromise> DetachStreamFilters(); 103 104 protected: 105 void ActorDestroy(ActorDestroyReason aWhy) override; 106 107 private: 108 virtual ~HttpBackgroundChannelParent(); 109 110 Atomic<bool> mIPCOpened; 111 112 // Used to ensure atomicity of mBackgroundThread 113 Mutex mBgThreadMutex MOZ_UNANNOTATED; 114 115 nsCOMPtr<nsISerialEventTarget> mBackgroundThread; 116 117 // associated HttpChannelParent for generating the channel events 118 RefPtr<HttpChannelParent> mChannelParent; 119 }; 120 121 } // namespace net 122 } // namespace mozilla 123 124 #endif // mozilla_net_HttpBackgroundChannelParent_h