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 a6b5dab967f663a46b87f14048107ca2e153acf7..9e4f665e03947e65025e77e207dc5b43a938f95b 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" |
@@ -65,6 +66,7 @@ using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>; |
static const size_t kDefaultResourceTimingBufferSize = 150; |
static const size_t kDefaultFrameTimingBufferSize = 150; |
+static const size_t kServerTimingBufferSize = 1000; |
panicker
2017/04/14 19:31:04
Curious - How did you come up with 1000?
This seem
cvazac
2017/04/17 17:48:42
Was a WAG, changed to 150! :)
On 2017/04/14 19:31
|
PerformanceBase::PerformanceBase(double time_origin, |
RefPtr<WebTaskRunner> task_runner) |
@@ -105,6 +107,8 @@ PerformanceEntryVector PerformanceBase::getEntries() { |
entries.AppendVector(user_timing_->GetMeasures()); |
} |
+ entries.AppendVector(server_timing_buffer_); |
+ |
std::sort(entries.begin(), entries.end(), |
PerformanceEntry::StartTimeCompareLessThan); |
return entries; |
@@ -143,6 +147,9 @@ PerformanceEntryVector PerformanceBase::getEntriesByType( |
if (user_timing_) |
entries.AppendVector(user_timing_->GetMeasures()); |
break; |
+ case PerformanceEntry::kServer: |
+ entries.AppendVector(server_timing_buffer_); |
+ 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 +208,15 @@ PerformanceEntryVector PerformanceBase::getEntriesByName( |
entries.AppendVector(user_timing_->GetMeasures(name)); |
} |
+ if (entry_type.IsNull() || type == PerformanceEntry::kServer) { |
+ // This is inefficient, but because we only buffer until onload, we don't |
+ // expect this buffer to be too big. |
panicker
2017/04/14 19:31:04
can you update this comment to reflect that the bu
cvazac
2017/04/17 17:48:42
Acknowledged.
|
+ for (const auto& entry : server_timing_buffer_) { |
+ if (entry->name() == name) |
+ entries.push_back(entry); |
+ } |
+ } |
+ |
std::sort(entries.begin(), entries.end(), |
PerformanceEntry::StartTimeCompareLessThan); |
return entries; |
@@ -282,6 +298,45 @@ bool PerformanceBase::AllowsTimingRedirect( |
return true; |
} |
+void PerformanceBase::AddServerTiming(const ResourceResponse& response, |
+ ShouldAddToBuffer shouldAddToBuffer) { |
+ if (shouldAddToBuffer == ShouldAddToBuffer::Never && |
+ !HasObserverFor(PerformanceEntry::kServer)) { |
+ 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)); |
+ if ((*headers).size() == 0) { |
+ return; |
+ } |
+ |
+ PerformanceEntryVector entries; |
+ for (const auto& header : *headers) { |
+ PerformanceEntry* entry = PerformanceServerTiming::create( |
+ response.Url().GetString(), header->metric, |
+ allowTimingDetails ? header->duration : 0.0, |
+ allowTimingDetails ? header->description : ""); |
+ entries.push_back(*entry); |
+ } |
+ |
+ NotifyObserversOfEntries(entries); |
+ if (shouldAddToBuffer == ShouldAddToBuffer::Always && |
+ server_timing_buffer_.size() + entries.size() <= |
+ kServerTimingBufferSize) { |
+ server_timing_buffer_.AppendVector(entries); |
+ } |
+} |
+ |
void PerformanceBase::AddResourceTiming(const ResourceTimingInfo& info) { |
if (IsResourceTimingBufferFull() && |
!HasObserverFor(PerformanceEntry::kResource)) |
@@ -460,6 +515,15 @@ void PerformanceBase::NotifyObserversOfEntry(PerformanceEntry& entry) { |
} |
} |
+void PerformanceBase::NotifyObserversOfEntries( |
+ PerformanceEntryVector& entries) { |
+ for (const auto& entry : entries) { |
+ for (auto& observer : observers_) { |
panicker
2017/04/14 19:31:04
call NotifyObserversOfEntry() here and remove "May
cvazac
2017/04/17 17:48:42
I'm fairly certain we still need this logic to det
panicker
2017/04/18 17:07:32
This is already there on line #513 above
|
+ observer->MaybeEnqueuePerformanceEntry(*entry.Get()); |
+ } |
+ } |
+} |
+ |
bool PerformanceBase::HasObserverFor( |
PerformanceEntry::EntryType filter_type) const { |
return observer_filter_options_ & filter_type; |
@@ -533,6 +597,7 @@ DEFINE_TRACE(PerformanceBase) { |
visitor->Trace(resource_timing_buffer_); |
visitor->Trace(navigation_timing_); |
visitor->Trace(user_timing_); |
+ visitor->Trace(server_timing_buffer_); |
visitor->Trace(observers_); |
visitor->Trace(active_observers_); |
visitor->Trace(suspended_observers_); |