+2017-12-12 John Wilander <wilander@apple.com>
+
+ Dispatch resource load statistics telemetry on the main thread
+ https://bugs.webkit.org/show_bug.cgi?id=180602
+ <rdar://problem/35942205>
+
+ Reviewed by Brent Fulgham.
+
+ * UIProcess/WebResourceLoadStatisticsTelemetry.cpp:
+ (WebKit::WebResourceLoadStatisticsTelemetry::calculateAndSubmit):
+ Now switches to the main thread for the telemetry submission
+ through a webpage proxy. The reason is that the webpage we
+ use may go away while we're still using it. This kind of
+ telemetry isn't associated with a specific webpage but the
+ infrastructure requires a webpage proxy.
+
2017-12-12 Myles C. Maxfield <mmaxfield@apple.com>
IPC code doesn't understand NSDictionaries with non-NSString keys
sortedPrevalentResourcesWithoutUserInteraction.uncheckedAppend(prevalentResource);
}
- auto webPageProxy = nonEphemeralWebPageProxy();
- if (!webPageProxy) {
- if (notifyPagesWhenTelemetryWasCaptured)
- notifyPages(0, 0, 0);
- return;
- }
-
- if (notifyPagesWhenTelemetryWasCaptured) {
- notifyPages(sortedPrevalentResources, sortedPrevalentResourcesWithoutUserInteraction, prevalentResourcesDaysSinceUserInteraction.size());
- // The notify pages function is for testing so we don't need to do an actual submission.
- return;
- }
-
- webPageProxy->logDiagnosticMessageWithValue(DiagnosticLoggingKeys::resourceLoadStatisticsTelemetryKey(), ASCIILiteral("totalNumberOfPrevalentResources"), sortedPrevalentResources.size(), significantFiguresForLoggedValues, ShouldSample::No);
- webPageProxy->logDiagnosticMessageWithValue(DiagnosticLoggingKeys::resourceLoadStatisticsTelemetryKey(), ASCIILiteral("totalNumberOfPrevalentResourcesWithUserInteraction"), prevalentResourcesDaysSinceUserInteraction.size(), significantFiguresForLoggedValues, ShouldSample::No);
-
- if (prevalentResourcesDaysSinceUserInteraction.size() > 0)
- webPageProxy->logDiagnosticMessageWithValue(DiagnosticLoggingKeys::resourceLoadStatisticsTelemetryKey(), ASCIILiteral("topPrevalentResourceWithUserInteractionDaysSinceUserInteraction"), prevalentResourcesDaysSinceUserInteraction[0], significantFiguresForLoggedValues, ShouldSample::No);
- if (prevalentResourcesDaysSinceUserInteraction.size() > 1)
- webPageProxy->logDiagnosticMessageWithValue(DiagnosticLoggingKeys::resourceLoadStatisticsTelemetryKey(), ASCIILiteral("medianPrevalentResourcesWithUserInteractionDaysSinceUserInteraction"), median(prevalentResourcesDaysSinceUserInteraction), significantFiguresForLoggedValues, ShouldSample::No);
-
- submitTopLists(sortedPrevalentResources, sortedPrevalentResourcesWithoutUserInteraction, *webPageProxy);
+ // Dispatch on the main thread to make sure the WebPageProxy we're using doesn't go away.
+ RunLoop::main().dispatch([sortedPrevalentResources = WTFMove(sortedPrevalentResources), sortedPrevalentResourcesWithoutUserInteraction = WTFMove(sortedPrevalentResourcesWithoutUserInteraction), prevalentResourcesDaysSinceUserInteraction = WTFMove(prevalentResourcesDaysSinceUserInteraction)] () {
+ auto webPageProxy = nonEphemeralWebPageProxy();
+ if (!webPageProxy) {
+ if (notifyPagesWhenTelemetryWasCaptured)
+ notifyPages(0, 0, 0);
+ return;
+ }
+
+ if (notifyPagesWhenTelemetryWasCaptured) {
+ notifyPages(sortedPrevalentResources, sortedPrevalentResourcesWithoutUserInteraction, prevalentResourcesDaysSinceUserInteraction.size());
+ // The notify pages function is for testing so we don't need to do an actual submission.
+ return;
+ }
+
+ webPageProxy->logDiagnosticMessageWithValue(DiagnosticLoggingKeys::resourceLoadStatisticsTelemetryKey(), ASCIILiteral("totalNumberOfPrevalentResources"), sortedPrevalentResources.size(), significantFiguresForLoggedValues, ShouldSample::No);
+ webPageProxy->logDiagnosticMessageWithValue(DiagnosticLoggingKeys::resourceLoadStatisticsTelemetryKey(), ASCIILiteral("totalNumberOfPrevalentResourcesWithUserInteraction"), prevalentResourcesDaysSinceUserInteraction.size(), significantFiguresForLoggedValues, ShouldSample::No);
+
+ if (prevalentResourcesDaysSinceUserInteraction.size() > 0)
+ webPageProxy->logDiagnosticMessageWithValue(DiagnosticLoggingKeys::resourceLoadStatisticsTelemetryKey(), ASCIILiteral("topPrevalentResourceWithUserInteractionDaysSinceUserInteraction"), prevalentResourcesDaysSinceUserInteraction[0], significantFiguresForLoggedValues, ShouldSample::No);
+ if (prevalentResourcesDaysSinceUserInteraction.size() > 1)
+ webPageProxy->logDiagnosticMessageWithValue(DiagnosticLoggingKeys::resourceLoadStatisticsTelemetryKey(), ASCIILiteral("medianPrevalentResourcesWithUserInteractionDaysSinceUserInteraction"), median(prevalentResourcesDaysSinceUserInteraction), significantFiguresForLoggedValues, ShouldSample::No);
+
+ submitTopLists(sortedPrevalentResources, sortedPrevalentResourcesWithoutUserInteraction, *webPageProxy);
+ });
}
void WebResourceLoadStatisticsTelemetry::setNotifyPagesWhenTelemetryWasCaptured(bool always)