Index: third_party/WebKit/Source/core/timing/PerformanceBase.cpp |
diff --git a/third_party/WebKit/Source/core/timing/PerformanceBase.cpp b/third_party/WebKit/Source/core/timing/PerformanceBase.cpp |
index 0c81e4b50b23fba781fbc1233c2eef3ba2689500..7abaf0bce3644da6ba2269e8a1b881b28b8ee2ba 100644 |
--- a/third_party/WebKit/Source/core/timing/PerformanceBase.cpp |
+++ b/third_party/WebKit/Source/core/timing/PerformanceBase.cpp |
@@ -42,6 +42,7 @@ |
#include "core/timing/PerformanceLongTaskTiming.h" |
#include "core/timing/PerformanceObserver.h" |
#include "core/timing/PerformanceResourceTiming.h" |
+#include "core/timing/PerformanceServerTiming.h" |
#include "core/timing/PerformanceUserTiming.h" |
#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/loader/fetch/ResourceResponse.h" |
@@ -105,6 +106,8 @@ PerformanceEntryVector PerformanceBase::getEntries() { |
entries.appendVector(m_userTiming->getMeasures()); |
} |
+ entries.appendVector(m_serverTimingBuffer); |
+ |
std::sort(entries.begin(), entries.end(), |
PerformanceEntry::startTimeCompareLessThan); |
return entries; |
@@ -143,6 +146,9 @@ PerformanceEntryVector PerformanceBase::getEntriesByType( |
if (m_userTiming) |
entries.appendVector(m_userTiming->getMeasures()); |
break; |
+ case PerformanceEntry::Server: |
+ entries.appendVector(m_serverTimingBuffer); |
+ break; |
// Unsupported for Paint, LongTask, TaskAttribution. |
// Per the spec, these entries can only be accessed via |
// Performance Observer. No separate buffer is maintained. |
@@ -201,6 +207,15 @@ PerformanceEntryVector PerformanceBase::getEntriesByName( |
entries.appendVector(m_userTiming->getMeasures(name)); |
} |
+ if (entryType.isNull() || type == PerformanceEntry::Server) { |
+ // This is inefficient, but because we only buffer until onload, we don't |
+ // expect this buffer to be too big. |
+ for (const auto& entry : m_serverTimingBuffer) { |
+ if (entry->name() == name) |
+ entries.push_back(entry); |
+ } |
+ } |
+ |
std::sort(entries.begin(), entries.end(), |
PerformanceEntry::startTimeCompareLessThan); |
return entries; |
@@ -282,6 +297,38 @@ bool PerformanceBase::allowsTimingRedirect( |
return true; |
} |
+void PerformanceBase::addServerTiming( |
+ const ResourceResponse& response, |
+ const ShouldAddToBuffer& shouldAddToBuffer) { |
+ if (shouldAddToBuffer == ShouldAddToBuffer::Never && |
+ !hasObserverFor(PerformanceEntry::Server)) { |
+ return; |
+ } |
+ |
+ ExecutionContext* context = getExecutionContext(); |
+ SecurityOrigin* securityOrigin = getSecurityOrigin(context); |
+ if (!securityOrigin) { |
+ return; |
+ } |
+ bool allowTimingDetails = passesTimingAllowCheck( |
+ response, *securityOrigin, |
+ response.httpHeaderField(HTTPNames::Timing_Allow_Origin), context); |
+ |
+ std::unique_ptr<ServerTimingHeaderVector> headers = parseServerTimingHeader( |
+ response.httpHeaderField(HTTPNames::Server_Timing)); |
+ for (const auto& header : *headers) { |
+ PerformanceEntry* entry = PerformanceServerTiming::create( |
+ response.url().getString(), header->metric, |
+ allowTimingDetails ? header->duration : 0.0, |
+ allowTimingDetails ? header->description : ""); |
+ |
+ notifyObserversOfEntry(*entry); |
panicker
2017/04/06 22:42:22
would be good to make a notifyObserversOfEntries()
|
+ if (shouldAddToBuffer == ShouldAddToBuffer::Always) { |
+ m_serverTimingBuffer.push_back(*entry); |
panicker
2017/04/06 22:42:22
Could we have a max size for this buffer?
On some
cvazac
2017/04/06 23:58:02
Sure! Like resource timing (https://www.w3.org/TR/
panicker
2017/04/07 23:01:32
Since this API is only exposed on Performance Obse
|
+ } |
+ } |
+} |
+ |
void PerformanceBase::addResourceTiming(const ResourceTimingInfo& info) { |
if (isResourceTimingBufferFull() && |
!hasObserverFor(PerformanceEntry::Resource)) |
@@ -533,6 +580,7 @@ DEFINE_TRACE(PerformanceBase) { |
visitor->trace(m_resourceTimingBuffer); |
visitor->trace(m_navigationTiming); |
visitor->trace(m_userTiming); |
+ visitor->trace(m_serverTimingBuffer); |
visitor->trace(m_observers); |
visitor->trace(m_activeObservers); |
visitor->trace(m_suspendedObservers); |