Bug 1754365 - Saving NavigationPreload's PerformanceTimingData into worker's PerformanceStorage. r=dom-worker-reviewers,jesup

Differential Revision: https://phabricator.services.mozilla.com/D138252
This commit is contained in:
Eden Chuang
2022-02-26 08:40:26 +00:00
parent cbf1066298
commit 8e34cfb720
5 changed files with 29 additions and 14 deletions

View File

@@ -185,6 +185,8 @@ void FetchService::FetchInstance::OnResponseEnd(
mFetchDriver->GetPerformanceTimingData(initiatorType, entryName));
MOZ_ASSERT(performanceTiming);
initiatorType = u"navigation"_ns;
FetchServiceResponse response =
MakeTuple(std::move(mResponse), performanceTiming->ToIPC(), initiatorType,
entryName);

View File

@@ -120,6 +120,19 @@ void PerformanceStorageWorker::AddEntry(nsIHttpChannel* aChannel,
Unused << NS_WARN_IF(!r->Dispatch());
}
void PerformanceStorageWorker::AddEntry(
const nsString& aEntryName, const nsString& aInitiatorType,
UniquePtr<PerformanceTimingData>&& aData) {
if (!aData) {
return;
}
UniquePtr<PerformanceProxyData> data = MakeUnique<PerformanceProxyData>(
std::move(aData), aInitiatorType, aEntryName);
AddEntryOnWorker(std::move(data));
}
void PerformanceStorageWorker::ShutdownOnWorker() {
MutexAutoLock lock(mMutex);

View File

@@ -29,9 +29,8 @@ class PerformanceStorageWorker final : public PerformanceStorage {
void AddEntry(nsIHttpChannel* aChannel,
nsITimedChannel* aTimedChannel) override;
virtual void AddEntry(const nsString& entryName,
const nsString& initiatorType,
UniquePtr<PerformanceTimingData>&& aData) override {}
void AddEntry(const nsString& aEntryName, const nsString& aInitiatorType,
UniquePtr<PerformanceTimingData>&& aData) override;
void AddEntryOnWorker(UniquePtr<PerformanceProxyData>&& aData);
private:

View File

@@ -47,6 +47,8 @@
#include "mozilla/dom/Notification.h"
#include "mozilla/dom/NotificationEvent.h"
#include "mozilla/dom/NotificationEventBinding.h"
#include "mozilla/dom/PerformanceTiming.h"
#include "mozilla/dom/PerformanceStorage.h"
#include "mozilla/dom/PushEventBinding.h"
#include "mozilla/dom/RemoteWorkerChild.h"
#include "mozilla/dom/RemoteWorkerService.h"
@@ -1678,10 +1680,13 @@ nsresult FetchEventOp::DispatchFetchEvent(JSContext* aCx,
// If preloadResponsePromise has already settled then this callback will get
// run synchronously here.
RefPtr<FetchEventOp> self = this;
RefPtr<PerformanceStorage> performanceStorage =
aWorkerPrivate->GetPerformanceStorage();
preloadResponsePromise
->Then(
GetCurrentSerialEventTarget(), __func__,
[self, globalObjectAsSupports = std::move(globalObjectAsSupports)](
[self, performanceStorage,
globalObjectAsSupports = std::move(globalObjectAsSupports)](
FetchEventPreloadResponseArgs&& aArgs) {
SafeRefPtr<InternalResponse> preloadResponse;
IPCPerformanceTimingData timingData;
@@ -1689,6 +1694,12 @@ nsresult FetchEventOp::DispatchFetchEvent(JSContext* aCx,
nsString entryName;
Tie(preloadResponse, timingData, initiatorType, entryName) =
std::move(aArgs);
if (performanceStorage &&
NS_SUCCEEDED(preloadResponse->GetErrorCode())) {
performanceStorage->AddEntry(
entryName, initiatorType,
MakeUnique<PerformanceTimingData>(timingData));
}
self->mPreloadResponse->MaybeResolve(MakeRefPtr<Response>(
globalObjectAsSupports, std::move(preloadResponse), nullptr));

View File

@@ -1,10 +0,0 @@
[resource-timing.https.html]
expected:
if os == "win": TIMEOUT
if os == "android": TIMEOUT
[TIMEOUT, OK]
[Navigation Preload Resource Timing.]
expected:
if os == "mac": [TIMEOUT, FAIL]
if os == "linux": [TIMEOUT, FAIL]
TIMEOUT