Bug 1810816 - P4 Report the preload response timing for ServiceWorker NavigationPreload. r=dom-worker-reviewers,asuth
Response Timing should be reported before the body stream completing. In the original implementation, the response timing is recorded when OnResponseEnd is called, but it is too late. Response timing could not be ready when response.text() or response.blob() resolves the promise. This is the fourth patch for reporting the preload response timing for ServiceWorker NavigationPreload. This patch adds the needed IPCs PFetchEventOp and PFetchEventOpProxy to propagate the preload response timing from the parent process main thread to the content process worker thread. Since navigation preload is an asynchronous action, corresponding promises for asynchronous propagation are also created in FetchService, FetchEventOpChild, FetchEventOpProxyChild, and FetchEventOp. Depends on D167938 Differential Revision: https://phabricator.services.mozilla.com/D167939
This commit is contained in:
@@ -40,9 +40,12 @@ mozilla::LazyLogModule gFetchLog("Fetch");
|
||||
FetchServicePromises::FetchServicePromises()
|
||||
: mAvailablePromise(
|
||||
MakeRefPtr<FetchServiceResponseAvailablePromise::Private>(__func__)),
|
||||
mTimingPromise(
|
||||
MakeRefPtr<FetchServiceResponseTimingPromise::Private>(__func__)),
|
||||
mEndPromise(
|
||||
MakeRefPtr<FetchServiceResponseEndPromise::Private>(__func__)) {
|
||||
mAvailablePromise->UseSynchronousTaskDispatch(__func__);
|
||||
mTimingPromise->UseSynchronousTaskDispatch(__func__);
|
||||
mEndPromise->UseSynchronousTaskDispatch(__func__);
|
||||
}
|
||||
|
||||
@@ -51,6 +54,11 @@ FetchServicePromises::GetResponseAvailablePromise() {
|
||||
return mAvailablePromise;
|
||||
}
|
||||
|
||||
RefPtr<FetchServiceResponseTimingPromise>
|
||||
FetchServicePromises::GetResponseTimingPromise() {
|
||||
return mTimingPromise;
|
||||
}
|
||||
|
||||
RefPtr<FetchServiceResponseEndPromise>
|
||||
FetchServicePromises::GetResponseEndPromise() {
|
||||
return mEndPromise;
|
||||
@@ -70,6 +78,20 @@ void FetchServicePromises::RejectResponseAvailablePromise(
|
||||
}
|
||||
}
|
||||
|
||||
void FetchServicePromises::ResolveResponseTimingPromise(
|
||||
ResponseTiming&& aTiming, const char* aMethodName) {
|
||||
if (mTimingPromise) {
|
||||
mTimingPromise->Resolve(std::move(aTiming), aMethodName);
|
||||
}
|
||||
}
|
||||
|
||||
void FetchServicePromises::RejectResponseTimingPromise(
|
||||
const CopyableErrorResult&& aError, const char* aMethodName) {
|
||||
if (mTimingPromise) {
|
||||
mTimingPromise->Reject(aError, aMethodName);
|
||||
}
|
||||
}
|
||||
|
||||
void FetchServicePromises::ResolveResponseEndPromise(ResponseEndArgs&& aArgs,
|
||||
const char* aMethodName) {
|
||||
if (mEndPromise) {
|
||||
@@ -241,6 +263,8 @@ void FetchService::FetchInstance::Cancel() {
|
||||
mPromises->ResolveResponseAvailablePromise(
|
||||
InternalResponse::NetworkError(NS_ERROR_DOM_ABORT_ERR), __func__);
|
||||
|
||||
mPromises->ResolveResponseTimingPromise(ResponseTiming(), __func__);
|
||||
|
||||
mPromises->ResolveResponseEndPromise(
|
||||
ResponseEndArgs(FetchDriverObserver::eAborted), __func__);
|
||||
}
|
||||
@@ -268,6 +292,11 @@ void FetchService::FetchInstance::OnResponseEnd(
|
||||
|
||||
MOZ_ASSERT(mPromises);
|
||||
|
||||
// If ResponseTimingPromise is not resolved, it means the fetch is aborted.
|
||||
// Resolving ResponseTimingPromise with an emtpy ResponseTiming.
|
||||
if (!mPromises->GetResponseTimingPromise()->IsResolved()) {
|
||||
mPromises->ResolveResponseTimingPromise(ResponseTiming(), __func__);
|
||||
}
|
||||
// Resolve the ResponseEndPromise
|
||||
mPromises->ResolveResponseEndPromise(ResponseEndArgs(aReason), __func__);
|
||||
|
||||
@@ -373,6 +402,11 @@ void FetchService::FetchInstance::FlushConsoleReport() {
|
||||
void FetchService::FetchInstance::OnReportPerformanceTiming() {
|
||||
FETCH_LOG(("FetchInstance::OnReportPerformanceTiming [%p]", this));
|
||||
MOZ_ASSERT(mFetchDriver);
|
||||
MOZ_ASSERT(mPromises);
|
||||
|
||||
if (mPromises->GetResponseTimingPromise()->IsResolved()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResponseTiming timing;
|
||||
UniquePtr<PerformanceTimingData> performanceTiming(
|
||||
@@ -398,6 +432,8 @@ void FetchService::FetchInstance::OnReportPerformanceTiming() {
|
||||
MOZ_ALWAYS_SUCCEEDS(mArgs.as<WorkerFetchArgs>().mEventTarget->Dispatch(
|
||||
r, nsIThread::DISPATCH_NORMAL));
|
||||
}
|
||||
|
||||
mPromises->ResolveResponseTimingPromise(std::move(timing), __func__);
|
||||
}
|
||||
|
||||
// FetchService
|
||||
@@ -429,6 +465,7 @@ RefPtr<FetchServicePromises> FetchService::NetworkErrorResponse(nsresult aRv) {
|
||||
RefPtr<FetchServicePromises> promises = MakeRefPtr<FetchServicePromises>();
|
||||
promises->ResolveResponseAvailablePromise(InternalResponse::NetworkError(aRv),
|
||||
__func__);
|
||||
promises->ResolveResponseTimingPromise(ResponseTiming(), __func__);
|
||||
promises->ResolveResponseEndPromise(
|
||||
ResponseEndArgs(FetchDriverObserver::eAborted), __func__);
|
||||
return promises;
|
||||
|
||||
Reference in New Issue
Block a user