Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 14 matching lines...) Expand all Loading... | |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "core/timing/PerformanceBase.h" | 32 #include "core/timing/PerformanceBase.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/DocumentTiming.h" | |
| 36 #include "core/dom/Element.h" | |
| 35 #include "core/events/Event.h" | 37 #include "core/events/Event.h" |
| 38 #include "core/frame/LocalFrame.h" | |
| 36 #include "core/frame/UseCounter.h" | 39 #include "core/frame/UseCounter.h" |
| 40 #include "core/loader/DocumentLoadTiming.h" | |
| 41 #include "core/loader/DocumentLoader.h" | |
| 37 #include "core/timing/PerformanceLongTaskTiming.h" | 42 #include "core/timing/PerformanceLongTaskTiming.h" |
| 43 #include "core/timing/PerformanceNavigationTiming.h" | |
| 38 #include "core/timing/PerformanceObserver.h" | 44 #include "core/timing/PerformanceObserver.h" |
| 39 #include "core/timing/PerformanceResourceTiming.h" | 45 #include "core/timing/PerformanceResourceTiming.h" |
| 40 #include "core/timing/PerformanceUserTiming.h" | 46 #include "core/timing/PerformanceUserTiming.h" |
| 47 #include "platform/RuntimeEnabledFeatures.h" | |
| 41 #include "platform/network/ResourceTimingInfo.h" | 48 #include "platform/network/ResourceTimingInfo.h" |
| 42 #include "platform/weborigin/SecurityOrigin.h" | 49 #include "platform/weborigin/SecurityOrigin.h" |
| 43 #include "wtf/CurrentTime.h" | 50 #include "wtf/CurrentTime.h" |
| 44 #include <algorithm> | 51 #include <algorithm> |
| 45 | 52 |
| 46 namespace blink { | 53 namespace blink { |
| 47 | 54 |
| 55 namespace { | |
| 56 const DocumentLoader* documentLoader(LocalFrame* frame) { | |
| 57 if (!frame) | |
| 58 return nullptr; | |
| 59 return frame->loader().documentLoader(); | |
| 60 } | |
| 61 | |
| 62 const DocumentLoadTiming* documentLoadTiming(LocalFrame* frame) { | |
| 63 const DocumentLoader* loader = documentLoader(frame); | |
| 64 if (!loader) | |
| 65 return nullptr; | |
| 66 return &loader->timing(); | |
| 67 } | |
| 68 | |
| 69 const DocumentTiming* documentTiming(LocalFrame* frame) { | |
| 70 if (!frame) | |
| 71 return nullptr; | |
| 72 | |
| 73 Document* document = frame->document(); | |
| 74 if (!document) | |
| 75 return nullptr; | |
| 76 | |
| 77 return &document->timing(); | |
| 78 } | |
| 79 | |
| 80 AtomicString getNavigationType(LocalFrame* frame) { | |
| 81 if (!frame) | |
| 82 return "navigate"; | |
| 83 | |
| 84 DocumentLoader* documentLoader = frame->loader().documentLoader(); | |
| 85 if (!documentLoader) | |
| 86 return "navigate"; | |
| 87 | |
| 88 switch (documentLoader->getNavigationType()) { | |
| 89 case NavigationTypeReload: | |
| 90 return "reload"; | |
| 91 case NavigationTypeBackForward: | |
| 92 return "back_forward"; | |
| 93 default: | |
| 94 return "navigate"; | |
| 95 } | |
| 96 } | |
| 97 } | |
| 98 | |
| 48 using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>; | 99 using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>; |
| 49 | 100 |
| 50 static const size_t defaultResourceTimingBufferSize = 150; | 101 static const size_t defaultResourceTimingBufferSize = 150; |
| 51 static const size_t defaultFrameTimingBufferSize = 150; | 102 static const size_t defaultFrameTimingBufferSize = 150; |
| 52 | 103 |
| 53 PerformanceBase::PerformanceBase(double timeOrigin) | 104 PerformanceBase::PerformanceBase(double timeOrigin) |
| 54 : m_frameTimingBufferSize(defaultFrameTimingBufferSize), | 105 : m_frameTimingBufferSize(defaultFrameTimingBufferSize), |
| 55 m_resourceTimingBufferSize(defaultResourceTimingBufferSize), | 106 m_resourceTimingBufferSize(defaultResourceTimingBufferSize), |
| 56 m_userTiming(nullptr), | 107 m_userTiming(nullptr), |
|
panicker
2016/11/04 18:55:32
initialize m_navigationTiming to nullptr
| |
| 57 m_timeOrigin(timeOrigin), | 108 m_timeOrigin(timeOrigin), |
| 58 m_observerFilterOptions(PerformanceEntry::Invalid), | 109 m_observerFilterOptions(PerformanceEntry::Invalid), |
| 59 m_deliverObservationsTimer( | 110 m_deliverObservationsTimer( |
| 60 this, | 111 this, |
| 61 &PerformanceBase::deliverObservationsTimerFired) {} | 112 &PerformanceBase::deliverObservationsTimerFired) {} |
| 62 | 113 |
| 63 PerformanceBase::~PerformanceBase() {} | 114 PerformanceBase::~PerformanceBase() {} |
| 64 | 115 |
| 65 const AtomicString& PerformanceBase::interfaceName() const { | 116 const AtomicString& PerformanceBase::interfaceName() const { |
| 66 return EventTargetNames::Performance; | 117 return EventTargetNames::Performance; |
| 67 } | 118 } |
| 68 | 119 |
| 69 PerformanceTiming* PerformanceBase::timing() const { | 120 PerformanceTiming* PerformanceBase::timing() const { |
| 70 return nullptr; | 121 return nullptr; |
| 71 } | 122 } |
| 72 | 123 |
| 73 PerformanceEntryVector PerformanceBase::getEntries() const { | 124 PerformanceEntryVector PerformanceBase::getEntries() const { |
| 74 PerformanceEntryVector entries; | 125 PerformanceEntryVector entries; |
| 75 | 126 |
| 76 entries.appendVector(m_resourceTimingBuffer); | 127 entries.appendVector(m_resourceTimingBuffer); |
| 128 if (RuntimeEnabledFeatures::performanceNavigationTimingEnabled()) | |
| 129 entries.append(m_navigationTiming); | |
| 77 entries.appendVector(m_frameTimingBuffer); | 130 entries.appendVector(m_frameTimingBuffer); |
| 78 | 131 |
| 79 if (m_userTiming) { | 132 if (m_userTiming) { |
| 80 entries.appendVector(m_userTiming->getMarks()); | 133 entries.appendVector(m_userTiming->getMarks()); |
| 81 entries.appendVector(m_userTiming->getMeasures()); | 134 entries.appendVector(m_userTiming->getMeasures()); |
| 82 } | 135 } |
| 83 | 136 |
| 84 std::sort(entries.begin(), entries.end(), | 137 std::sort(entries.begin(), entries.end(), |
| 85 PerformanceEntry::startTimeCompareLessThan); | 138 PerformanceEntry::startTimeCompareLessThan); |
| 86 return entries; | 139 return entries; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); | 338 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); |
| 286 | 339 |
| 287 PerformanceEntry* entry = PerformanceResourceTiming::create( | 340 PerformanceEntry* entry = PerformanceResourceTiming::create( |
| 288 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, | 341 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, |
| 289 allowRedirectDetails); | 342 allowRedirectDetails); |
| 290 notifyObserversOfEntry(*entry); | 343 notifyObserversOfEntry(*entry); |
| 291 if (!isResourceTimingBufferFull()) | 344 if (!isResourceTimingBufferFull()) |
| 292 addResourceTimingBuffer(*entry); | 345 addResourceTimingBuffer(*entry); |
| 293 } | 346 } |
| 294 | 347 |
| 348 void PerformanceBase::addNavigationTiming(LocalFrame* frame) { | |
| 349 if (!RuntimeEnabledFeatures::performanceNavigationTimingEnabled()) | |
| 350 return; | |
| 351 DCHECK(frame); | |
| 352 const DocumentLoader* docLoader = documentLoader(frame); | |
| 353 DCHECK(docLoader); | |
| 354 const DocumentLoadTiming* docLoadTiming = documentLoadTiming(frame); | |
| 355 const DocumentTiming* docTiming = documentTiming(frame); | |
| 356 DCHECK(docLoadTiming); | |
| 357 DCHECK(docTiming); | |
| 358 | |
| 359 ResourceResponse finalResponse = docLoader->response(); | |
| 360 | |
| 361 // TODO(sunjian) Right now NavigationType doesn't seem to have a Prerender | |
| 362 // type yet, need to look into this | |
| 363 AtomicString type = getNavigationType(frame); | |
| 364 | |
| 365 ResourceLoadTiming* resourceLoadTiming = finalResponse.resourceLoadTiming(); | |
| 366 double lastRedirectEndTime = docLoadTiming->redirectEnd(); | |
| 367 double finishTime = docLoadTiming->loadEventEnd(); | |
| 368 | |
| 369 // TODO(sunjian) for now just set it to 0 | |
|
panicker
2016/11/04 18:55:32
"TODO(sunjian): Implement transfer size."
sunjian
2016/11/04 22:25:18
Done.
| |
| 370 unsigned long long transferSize = 0; | |
| 371 unsigned long long encodedBodyLength = finalResponse.encodedBodyLength(); | |
| 372 unsigned long long decodedBodyLength = finalResponse.decodedBodyLength(); | |
| 373 bool didReuseConnection = finalResponse.connectionReused(); | |
| 374 | |
| 375 m_navigationTiming = PerformanceNavigationTiming::create( | |
| 376 timeOrigin(), docLoadTiming->unloadEventStart(), | |
| 377 docLoadTiming->unloadEventEnd(), docLoadTiming->loadEventStart(), | |
| 378 docLoadTiming->loadEventEnd(), docLoadTiming->redirectCount(), | |
| 379 docTiming->domInteractive(), docTiming->domContentLoadedEventStart(), | |
| 380 docTiming->domContentLoadedEventEnd(), docTiming->domComplete(), type, | |
| 381 docLoadTiming->redirectStart(), docLoadTiming->redirectEnd(), | |
| 382 docLoadTiming->fetchStart(), docLoadTiming->responseEnd(), | |
| 383 docLoadTiming->hasCrossOriginRedirect(), | |
| 384 docLoadTiming->hasSameOriginAsPreviousDocument(), resourceLoadTiming, | |
| 385 lastRedirectEndTime, finishTime, transferSize, encodedBodyLength, | |
| 386 decodedBodyLength, didReuseConnection); | |
| 387 notifyObserversOfEntry(*m_navigationTiming); | |
| 388 } | |
| 389 | |
| 295 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) { | 390 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) { |
| 296 m_resourceTimingBuffer.append(&entry); | 391 m_resourceTimingBuffer.append(&entry); |
| 297 | 392 |
| 298 if (isResourceTimingBufferFull()) { | 393 if (isResourceTimingBufferFull()) { |
| 299 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull)); | 394 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull)); |
| 300 dispatchEvent( | 395 dispatchEvent( |
| 301 Event::create(EventTypeNames::webkitresourcetimingbufferfull)); | 396 Event::create(EventTypeNames::webkitresourcetimingbufferfull)); |
| 302 } | 397 } |
| 303 } | 398 } |
| 304 | 399 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 return monotonicTimeToDOMHighResTimeStamp(monotonicTime) * 1000; | 552 return monotonicTimeToDOMHighResTimeStamp(monotonicTime) * 1000; |
| 458 } | 553 } |
| 459 | 554 |
| 460 DOMHighResTimeStamp PerformanceBase::now() const { | 555 DOMHighResTimeStamp PerformanceBase::now() const { |
| 461 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime()); | 556 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime()); |
| 462 } | 557 } |
| 463 | 558 |
| 464 DEFINE_TRACE(PerformanceBase) { | 559 DEFINE_TRACE(PerformanceBase) { |
| 465 visitor->trace(m_frameTimingBuffer); | 560 visitor->trace(m_frameTimingBuffer); |
| 466 visitor->trace(m_resourceTimingBuffer); | 561 visitor->trace(m_resourceTimingBuffer); |
| 562 visitor->trace(m_navigationTiming); | |
| 467 visitor->trace(m_userTiming); | 563 visitor->trace(m_userTiming); |
| 468 visitor->trace(m_observers); | 564 visitor->trace(m_observers); |
| 469 visitor->trace(m_activeObservers); | 565 visitor->trace(m_activeObservers); |
| 470 visitor->trace(m_suspendedObservers); | 566 visitor->trace(m_suspendedObservers); |
| 471 EventTargetWithInlineData::trace(visitor); | 567 EventTargetWithInlineData::trace(visitor); |
| 472 } | 568 } |
| 473 | 569 |
| 474 } // namespace blink | 570 } // namespace blink |
| OLD | NEW |