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

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

Issue 2528513003: first-paint and first-contentful paint (Closed)
Patch Set: Got rid of DCHECK cause it breaks unit tests Created 3 years, 11 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 150 }
151 break; 151 break;
152 case PerformanceEntry::Mark: 152 case PerformanceEntry::Mark:
153 if (m_userTiming) 153 if (m_userTiming)
154 entries.appendVector(m_userTiming->getMarks()); 154 entries.appendVector(m_userTiming->getMarks());
155 break; 155 break;
156 case PerformanceEntry::Measure: 156 case PerformanceEntry::Measure:
157 if (m_userTiming) 157 if (m_userTiming)
158 entries.appendVector(m_userTiming->getMeasures()); 158 entries.appendVector(m_userTiming->getMeasures());
159 break; 159 break;
160 // Unsupported for LongTask, TaskAttribution. 160 // Unsupported for Paint, LongTask, TaskAttribution.
161 // Per the spec, these entries can only be accessed via 161 // Per the spec, these entries can only be accessed via
162 // Performance Observer. No separate buffer is maintained. 162 // Performance Observer. No separate buffer is maintained.
163 case PerformanceEntry::Paint:
164 break;
163 case PerformanceEntry::LongTask: 165 case PerformanceEntry::LongTask:
164 break; 166 break;
165 case PerformanceEntry::TaskAttribution: 167 case PerformanceEntry::TaskAttribution:
166 break; 168 break;
167 case PerformanceEntry::Invalid: 169 case PerformanceEntry::Invalid:
168 break; 170 break;
169 } 171 }
170 172
171 std::sort(entries.begin(), entries.end(), 173 std::sort(entries.begin(), entries.end(),
172 PerformanceEntry::startTimeCompareLessThan); 174 PerformanceEntry::startTimeCompareLessThan);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 documentTiming ? documentTiming->domComplete() : 0, type, 395 documentTiming ? documentTiming->domComplete() : 0, type,
394 documentLoadTiming.redirectStart(), documentLoadTiming.redirectEnd(), 396 documentLoadTiming.redirectStart(), documentLoadTiming.redirectEnd(),
395 documentLoadTiming.fetchStart(), documentLoadTiming.responseEnd(), 397 documentLoadTiming.fetchStart(), documentLoadTiming.responseEnd(),
396 allowRedirectDetails, 398 allowRedirectDetails,
397 documentLoadTiming.hasSameOriginAsPreviousDocument(), resourceLoadTiming, 399 documentLoadTiming.hasSameOriginAsPreviousDocument(), resourceLoadTiming,
398 lastRedirectEndTime, finishTime, transferSize, encodedBodyLength, 400 lastRedirectEndTime, finishTime, transferSize, encodedBodyLength,
399 decodedBodyLength, didReuseConnection); 401 decodedBodyLength, didReuseConnection);
400 notifyObserversOfEntry(*m_navigationTiming); 402 notifyObserversOfEntry(*m_navigationTiming);
401 } 403 }
402 404
405 void PerformanceBase::addFirstPaintTiming(double startTime) {
406 addPaintTiming(PerformancePaintTiming::PaintType::FirstPaint, startTime);
407 }
408
409 void PerformanceBase::addFirstContentfulPaintTiming(double startTime) {
410 addPaintTiming(PerformancePaintTiming::PaintType::FirstContentfulPaint,
411 startTime);
412 }
413
414 void PerformanceBase::addPaintTiming(PerformancePaintTiming::PaintType type,
415 double startTime) {
416 if (!RuntimeEnabledFeatures::performancePaintTimingEnabled())
417 return;
418 PerformanceEntry* entry = new PerformancePaintTiming(
419 type, monotonicTimeToDOMHighResTimeStamp(startTime));
420 notifyObserversOfEntry(*entry);
421 }
422
403 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) { 423 void PerformanceBase::addResourceTimingBuffer(PerformanceEntry& entry) {
404 m_resourceTimingBuffer.push_back(&entry); 424 m_resourceTimingBuffer.push_back(&entry);
405 425
406 if (isResourceTimingBufferFull()) 426 if (isResourceTimingBufferFull())
407 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull)); 427 dispatchEvent(Event::create(EventTypeNames::resourcetimingbufferfull));
408 } 428 }
409 429
410 bool PerformanceBase::isResourceTimingBufferFull() { 430 bool PerformanceBase::isResourceTimingBufferFull() {
411 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; 431 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize;
412 } 432 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 570 }
551 571
552 DOMHighResTimeStamp PerformanceBase::monotonicTimeToDOMHighResTimeStamp( 572 DOMHighResTimeStamp PerformanceBase::monotonicTimeToDOMHighResTimeStamp(
553 double timeOrigin, 573 double timeOrigin,
554 double monotonicTime) { 574 double monotonicTime) {
555 // Avoid exposing raw platform timestamps. 575 // Avoid exposing raw platform timestamps.
556 if (!monotonicTime || !timeOrigin) 576 if (!monotonicTime || !timeOrigin)
557 return 0.0; 577 return 0.0;
558 578
559 double timeInSeconds = monotonicTime - timeOrigin; 579 double timeInSeconds = monotonicTime - timeOrigin;
560 DCHECK_GE(timeInSeconds, 0); 580 if (timeInSeconds < 0)
581 return 0.0;
561 return convertSecondsToDOMHighResTimeStamp( 582 return convertSecondsToDOMHighResTimeStamp(
562 clampTimeResolution(timeInSeconds)); 583 clampTimeResolution(timeInSeconds));
563 } 584 }
564 585
565 DOMHighResTimeStamp PerformanceBase::monotonicTimeToDOMHighResTimeStamp( 586 DOMHighResTimeStamp PerformanceBase::monotonicTimeToDOMHighResTimeStamp(
566 double monotonicTime) const { 587 double monotonicTime) const {
567 return monotonicTimeToDOMHighResTimeStamp(m_timeOrigin, monotonicTime); 588 return monotonicTimeToDOMHighResTimeStamp(m_timeOrigin, monotonicTime);
568 } 589 }
569 590
570 DOMHighResTimeStamp PerformanceBase::now() const { 591 DOMHighResTimeStamp PerformanceBase::now() const {
571 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime()); 592 return monotonicTimeToDOMHighResTimeStamp(monotonicallyIncreasingTime());
572 } 593 }
573 594
574 DEFINE_TRACE(PerformanceBase) { 595 DEFINE_TRACE(PerformanceBase) {
575 visitor->trace(m_frameTimingBuffer); 596 visitor->trace(m_frameTimingBuffer);
576 visitor->trace(m_resourceTimingBuffer); 597 visitor->trace(m_resourceTimingBuffer);
577 visitor->trace(m_navigationTiming); 598 visitor->trace(m_navigationTiming);
578 visitor->trace(m_userTiming); 599 visitor->trace(m_userTiming);
579 visitor->trace(m_observers); 600 visitor->trace(m_observers);
580 visitor->trace(m_activeObservers); 601 visitor->trace(m_activeObservers);
581 visitor->trace(m_suspendedObservers); 602 visitor->trace(m_suspendedObservers);
582 EventTargetWithInlineData::trace(visitor); 603 EventTargetWithInlineData::trace(visitor);
583 } 604 }
584 605
585 } // namespace blink 606 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/timing/PerformanceBase.h ('k') | third_party/WebKit/Source/core/timing/PerformanceEntry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698