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/. */
7 #include "FetchEventOpParent.h"
9 #include "mozilla/dom/FetchTypes.h"
12 #include "mozilla/Assertions.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/Unused.h"
15 #include "mozilla/dom/FetchEventOpProxyParent.h"
16 #include "mozilla/dom/FetchStreamUtils.h"
17 #include "mozilla/dom/InternalResponse.h"
18 #include "mozilla/dom/RemoteWorkerControllerParent.h"
19 #include "mozilla/dom/RemoteWorkerParent.h"
20 #include "mozilla/ipc/BackgroundParent.h"
28 std::tuple
<Maybe
<ParentToParentInternalResponse
>, Maybe
<ResponseEndArgs
>>
29 FetchEventOpParent::OnStart(
30 MovingNotNull
<RefPtr
<FetchEventOpProxyParent
>> aFetchEventOpProxyParent
) {
31 Maybe
<ParentToParentInternalResponse
> preloadResponse
=
32 std::move(mState
.as
<Pending
>().mPreloadResponse
);
33 Maybe
<ResponseEndArgs
> preloadResponseEndArgs
=
34 std::move(mState
.as
<Pending
>().mEndArgs
);
35 mState
= AsVariant(Started
{std::move(aFetchEventOpProxyParent
)});
36 return std::make_tuple(preloadResponse
, preloadResponseEndArgs
);
39 void FetchEventOpParent::OnFinish() {
40 MOZ_ASSERT(mState
.is
<Started
>());
41 mState
= AsVariant(Finished());
44 mozilla::ipc::IPCResult
FetchEventOpParent::RecvPreloadResponse(
45 ParentToParentInternalResponse
&& aResponse
) {
46 AssertIsOnBackgroundThread();
49 [&aResponse
](Pending
& aPending
) {
50 MOZ_ASSERT(aPending
.mPreloadResponse
.isNothing());
51 aPending
.mPreloadResponse
= Some(std::move(aResponse
));
53 [&aResponse
](Started
& aStarted
) {
54 auto backgroundParent
= WrapNotNull(
55 WrapNotNull(aStarted
.mFetchEventOpProxyParent
->Manager())
57 Unused
<< aStarted
.mFetchEventOpProxyParent
->SendPreloadResponse(
58 ToParentToChild(aResponse
, backgroundParent
));
60 [](const Finished
&) {});
65 mozilla::ipc::IPCResult
FetchEventOpParent::RecvPreloadResponseTiming(
66 ResponseTiming
&& aTiming
) {
67 AssertIsOnBackgroundThread();
70 [&aTiming
](Pending
& aPending
) {
71 MOZ_ASSERT(aPending
.mTiming
.isNothing());
72 aPending
.mTiming
= Some(std::move(aTiming
));
74 [&aTiming
](Started
& aStarted
) {
75 Unused
<< aStarted
.mFetchEventOpProxyParent
->SendPreloadResponseTiming(
78 [](const Finished
&) {});
83 mozilla::ipc::IPCResult
FetchEventOpParent::RecvPreloadResponseEnd(
84 ResponseEndArgs
&& aArgs
) {
85 AssertIsOnBackgroundThread();
88 [&aArgs
](Pending
& aPending
) {
89 MOZ_ASSERT(aPending
.mEndArgs
.isNothing());
90 aPending
.mEndArgs
= Some(std::move(aArgs
));
92 [&aArgs
](Started
& aStarted
) {
93 Unused
<< aStarted
.mFetchEventOpProxyParent
->SendPreloadResponseEnd(
96 [](const Finished
&) {});
101 void FetchEventOpParent::ActorDestroy(ActorDestroyReason
) {
102 AssertIsOnBackgroundThread();
106 } // namespace mozilla