FetchEventOpParent.h (2453B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_fetcheventopparent_h__ 8 #define mozilla_dom_fetcheventopparent_h__ 9 10 #include "mozilla/dom/FetchEventOpProxyParent.h" 11 #include "mozilla/dom/PFetchEventOpParent.h" 12 #include "nsISupports.h" 13 14 namespace mozilla::dom { 15 16 class FetchEventOpParent final : public PFetchEventOpParent { 17 friend class PFetchEventOpParent; 18 19 public: 20 NS_INLINE_DECL_REFCOUNTING(FetchEventOpParent) 21 22 FetchEventOpParent() = default; 23 24 // Transition from the Pending state to the Started state. Returns the preload 25 // response and response end args, if it has already arrived. 26 std::tuple<Maybe<ParentToParentInternalResponse>, Maybe<ResponseEndArgs>> 27 OnStart( 28 MovingNotNull<RefPtr<FetchEventOpProxyParent>> aFetchEventOpProxyParent); 29 30 // Transition from the Started state to the Finished state. 31 void OnFinish(); 32 33 private: 34 ~FetchEventOpParent() = default; 35 36 // IPDL methods 37 38 mozilla::ipc::IPCResult RecvPreloadResponse( 39 ParentToParentInternalResponse&& aResponse); 40 41 mozilla::ipc::IPCResult RecvPreloadResponseTiming(ResponseTiming&& aTiming); 42 43 mozilla::ipc::IPCResult RecvPreloadResponseEnd(ResponseEndArgs&& aArgs); 44 45 void ActorDestroy(ActorDestroyReason) override; 46 47 struct Pending { 48 Maybe<ParentToParentInternalResponse> mPreloadResponse; 49 Maybe<ResponseTiming> mTiming; 50 Maybe<ResponseEndArgs> mEndArgs; 51 }; 52 53 struct Started { 54 NotNull<RefPtr<FetchEventOpProxyParent>> mFetchEventOpProxyParent; 55 }; 56 57 struct Finished {}; 58 59 using State = Variant<Pending, Started, Finished>; 60 61 // Tracks the state of the fetch event. 62 // 63 // Pending: the fetch event is waiting in RemoteWorkerController::mPendingOps 64 // and if the preload response arrives, we have to save it. 65 // Started: the FetchEventOpProxyParent has been created, and if the preload 66 // response arrives then we should forward it. 67 // Finished: the response has been propagated to the parent process, if the 68 // preload response arrives now then we simply drop it. 69 State mState = AsVariant(Pending()); 70 }; 71 72 } // namespace mozilla::dom 73 74 #endif // mozilla_dom_fetcheventopparent_h__