Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: third_party/WebKit/Source/core/timing/PerformanceBase.cpp

Issue 2799093004: Enable ServerTiming support
Patch Set: update code formatting and comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Intel Inc. All rights reserved. 3 * Copyright (C) 2012 Intel Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 24 matching lines...) Expand all
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/DocumentTiming.h" 36 #include "core/dom/DocumentTiming.h"
37 #include "core/events/Event.h" 37 #include "core/events/Event.h"
38 #include "core/frame/LocalFrame.h" 38 #include "core/frame/LocalFrame.h"
39 #include "core/frame/UseCounter.h" 39 #include "core/frame/UseCounter.h"
40 #include "core/loader/DocumentLoadTiming.h" 40 #include "core/loader/DocumentLoadTiming.h"
41 #include "core/loader/DocumentLoader.h" 41 #include "core/loader/DocumentLoader.h"
42 #include "core/timing/PerformanceLongTaskTiming.h" 42 #include "core/timing/PerformanceLongTaskTiming.h"
43 #include "core/timing/PerformanceObserver.h" 43 #include "core/timing/PerformanceObserver.h"
44 #include "core/timing/PerformanceResourceTiming.h" 44 #include "core/timing/PerformanceResourceTiming.h"
45 #include "core/timing/PerformanceServerTiming.h"
45 #include "core/timing/PerformanceUserTiming.h" 46 #include "core/timing/PerformanceUserTiming.h"
46 #include "platform/RuntimeEnabledFeatures.h" 47 #include "platform/RuntimeEnabledFeatures.h"
47 #include "platform/loader/fetch/ResourceResponse.h" 48 #include "platform/loader/fetch/ResourceResponse.h"
48 #include "platform/loader/fetch/ResourceTimingInfo.h" 49 #include "platform/loader/fetch/ResourceTimingInfo.h"
49 #include "platform/weborigin/SecurityOrigin.h" 50 #include "platform/weborigin/SecurityOrigin.h"
50 #include "wtf/CurrentTime.h" 51 #include "wtf/CurrentTime.h"
51 52
52 namespace blink { 53 namespace blink {
53 54
54 namespace { 55 namespace {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // calls this method. 99 // calls this method.
99 if (m_navigationTiming) 100 if (m_navigationTiming)
100 entries.push_back(m_navigationTiming); 101 entries.push_back(m_navigationTiming);
101 entries.appendVector(m_frameTimingBuffer); 102 entries.appendVector(m_frameTimingBuffer);
102 103
103 if (m_userTiming) { 104 if (m_userTiming) {
104 entries.appendVector(m_userTiming->getMarks()); 105 entries.appendVector(m_userTiming->getMarks());
105 entries.appendVector(m_userTiming->getMeasures()); 106 entries.appendVector(m_userTiming->getMeasures());
106 } 107 }
107 108
109 entries.appendVector(m_serverTimingBuffer);
110
108 std::sort(entries.begin(), entries.end(), 111 std::sort(entries.begin(), entries.end(),
109 PerformanceEntry::startTimeCompareLessThan); 112 PerformanceEntry::startTimeCompareLessThan);
110 return entries; 113 return entries;
111 } 114 }
112 115
113 PerformanceEntryVector PerformanceBase::getEntriesByType( 116 PerformanceEntryVector PerformanceBase::getEntriesByType(
114 const String& entryType) { 117 const String& entryType) {
115 PerformanceEntryVector entries; 118 PerformanceEntryVector entries;
116 PerformanceEntry::EntryType type = 119 PerformanceEntry::EntryType type =
117 PerformanceEntry::toEntryTypeEnum(entryType); 120 PerformanceEntry::toEntryTypeEnum(entryType);
(...skipping 18 matching lines...) Expand all
136 } 139 }
137 break; 140 break;
138 case PerformanceEntry::Mark: 141 case PerformanceEntry::Mark:
139 if (m_userTiming) 142 if (m_userTiming)
140 entries.appendVector(m_userTiming->getMarks()); 143 entries.appendVector(m_userTiming->getMarks());
141 break; 144 break;
142 case PerformanceEntry::Measure: 145 case PerformanceEntry::Measure:
143 if (m_userTiming) 146 if (m_userTiming)
144 entries.appendVector(m_userTiming->getMeasures()); 147 entries.appendVector(m_userTiming->getMeasures());
145 break; 148 break;
149 case PerformanceEntry::Server:
150 entries.appendVector(m_serverTimingBuffer);
151 break;
146 // Unsupported for Paint, LongTask, TaskAttribution. 152 // Unsupported for Paint, LongTask, TaskAttribution.
147 // Per the spec, these entries can only be accessed via 153 // Per the spec, these entries can only be accessed via
148 // Performance Observer. No separate buffer is maintained. 154 // Performance Observer. No separate buffer is maintained.
149 case PerformanceEntry::Paint: 155 case PerformanceEntry::Paint:
150 break; 156 break;
151 case PerformanceEntry::LongTask: 157 case PerformanceEntry::LongTask:
152 break; 158 break;
153 case PerformanceEntry::TaskAttribution: 159 case PerformanceEntry::TaskAttribution:
154 break; 160 break;
155 case PerformanceEntry::Invalid: 161 case PerformanceEntry::Invalid:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 200 }
195 } 201 }
196 202
197 if (m_userTiming) { 203 if (m_userTiming) {
198 if (entryType.isNull() || type == PerformanceEntry::Mark) 204 if (entryType.isNull() || type == PerformanceEntry::Mark)
199 entries.appendVector(m_userTiming->getMarks(name)); 205 entries.appendVector(m_userTiming->getMarks(name));
200 if (entryType.isNull() || type == PerformanceEntry::Measure) 206 if (entryType.isNull() || type == PerformanceEntry::Measure)
201 entries.appendVector(m_userTiming->getMeasures(name)); 207 entries.appendVector(m_userTiming->getMeasures(name));
202 } 208 }
203 209
210 if (entryType.isNull() || type == PerformanceEntry::Server) {
211 // This is inefficient, but because we only buffer until onload, we don't
212 // expect this buffer to be too big.
213 for (const auto& entry : m_serverTimingBuffer) {
214 if (entry->name() == name)
215 entries.push_back(entry);
216 }
217 }
218
204 std::sort(entries.begin(), entries.end(), 219 std::sort(entries.begin(), entries.end(),
205 PerformanceEntry::startTimeCompareLessThan); 220 PerformanceEntry::startTimeCompareLessThan);
206 return entries; 221 return entries;
207 } 222 }
208 223
209 void PerformanceBase::clearResourceTimings() { 224 void PerformanceBase::clearResourceTimings() {
210 m_resourceTimingBuffer.clear(); 225 m_resourceTimingBuffer.clear();
211 } 226 }
212 227
213 void PerformanceBase::setResourceTimingBufferSize(unsigned size) { 228 void PerformanceBase::setResourceTimingBufferSize(unsigned size) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 290
276 for (const ResourceResponse& response : redirectChain) { 291 for (const ResourceResponse& response : redirectChain) {
277 if (!passesTimingAllowCheck(response, initiatorSecurityOrigin, 292 if (!passesTimingAllowCheck(response, initiatorSecurityOrigin,
278 AtomicString(), context)) 293 AtomicString(), context))
279 return false; 294 return false;
280 } 295 }
281 296
282 return true; 297 return true;
283 } 298 }
284 299
300 void PerformanceBase::addServerTiming(
301 const ResourceResponse& response,
302 const ShouldAddToBuffer& shouldAddToBuffer) {
303 if (shouldAddToBuffer == ShouldAddToBuffer::Never &&
304 !hasObserverFor(PerformanceEntry::Server)) {
305 return;
306 }
307
308 ExecutionContext* context = getExecutionContext();
309 SecurityOrigin* securityOrigin = getSecurityOrigin(context);
310 if (!securityOrigin) {
311 return;
312 }
313 bool allowTimingDetails = passesTimingAllowCheck(
314 response, *securityOrigin,
315 response.httpHeaderField(HTTPNames::Timing_Allow_Origin), context);
316
317 std::unique_ptr<ServerTimingHeaderVector> headers = parseServerTimingHeader(
318 response.httpHeaderField(HTTPNames::Server_Timing));
319 for (const auto& header : *headers) {
320 PerformanceEntry* entry = PerformanceServerTiming::create(
321 response.url().getString(), header->metric,
322 allowTimingDetails ? header->duration : 0.0,
323 allowTimingDetails ? header->description : "");
324
325 notifyObserversOfEntry(*entry);
panicker 2017/04/06 22:42:22 would be good to make a notifyObserversOfEntries()
326 if (shouldAddToBuffer == ShouldAddToBuffer::Always) {
327 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
328 }
329 }
330 }
331
285 void PerformanceBase::addResourceTiming(const ResourceTimingInfo& info) { 332 void PerformanceBase::addResourceTiming(const ResourceTimingInfo& info) {
286 if (isResourceTimingBufferFull() && 333 if (isResourceTimingBufferFull() &&
287 !hasObserverFor(PerformanceEntry::Resource)) 334 !hasObserverFor(PerformanceEntry::Resource))
288 return; 335 return;
289 ExecutionContext* context = getExecutionContext(); 336 ExecutionContext* context = getExecutionContext();
290 SecurityOrigin* securityOrigin = getSecurityOrigin(context); 337 SecurityOrigin* securityOrigin = getSecurityOrigin(context);
291 if (!securityOrigin) 338 if (!securityOrigin)
292 return; 339 return;
293 340
294 const ResourceResponse& finalResponse = info.finalResponse(); 341 const ResourceResponse& finalResponse = info.finalResponse();
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 573
527 DOMHighResTimeStamp PerformanceBase::now() const { 574 DOMHighResTimeStamp PerformanceBase::now() const {
528 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime()); 575 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime());
529 } 576 }
530 577
531 DEFINE_TRACE(PerformanceBase) { 578 DEFINE_TRACE(PerformanceBase) {
532 visitor->trace(m_frameTimingBuffer); 579 visitor->trace(m_frameTimingBuffer);
533 visitor->trace(m_resourceTimingBuffer); 580 visitor->trace(m_resourceTimingBuffer);
534 visitor->trace(m_navigationTiming); 581 visitor->trace(m_navigationTiming);
535 visitor->trace(m_userTiming); 582 visitor->trace(m_userTiming);
583 visitor->trace(m_serverTimingBuffer);
536 visitor->trace(m_observers); 584 visitor->trace(m_observers);
537 visitor->trace(m_activeObservers); 585 visitor->trace(m_activeObservers);
538 visitor->trace(m_suspendedObservers); 586 visitor->trace(m_suspendedObservers);
539 EventTargetWithInlineData::trace(visitor); 587 EventTargetWithInlineData::trace(visitor);
540 } 588 }
541 589
542 } // namespace blink 590 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698