| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/FirstMeaningfulPaintDetector.h" | 5 #include "core/paint/FirstMeaningfulPaintDetector.h" |
| 6 | 6 |
| 7 #include "core/css/FontFaceSet.h" | 7 #include "core/css/FontFaceSet.h" |
| 8 #include "core/dom/TaskRunnerHelper.h" | 8 #include "core/dom/TaskRunnerHelper.h" |
| 9 #include "core/paint/PaintTiming.h" | 9 #include "core/paint/PaintTiming.h" |
| 10 #include "platform/Histogram.h" | 10 #include "platform/Histogram.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 TRACE_EVENT_MARK_WITH_TIMESTAMP1( | 106 TRACE_EVENT_MARK_WITH_TIMESTAMP1( |
| 107 "loading", "firstMeaningfulPaintCandidate", | 107 "loading", "firstMeaningfulPaintCandidate", |
| 108 TraceEvent::toTraceTimestamp(m_provisionalFirstMeaningfulPaint), "frame", | 108 TraceEvent::toTraceTimestamp(m_provisionalFirstMeaningfulPaint), "frame", |
| 109 document()->frame()); | 109 document()->frame()); |
| 110 // Ignore the first meaningful paint candidate as this generally is the first | 110 // Ignore the first meaningful paint candidate as this generally is the first |
| 111 // contentful paint itself. | 111 // contentful paint itself. |
| 112 if (!m_seenFirstMeaningfulPaintCandidate) { | 112 if (!m_seenFirstMeaningfulPaintCandidate) { |
| 113 m_seenFirstMeaningfulPaintCandidate = true; | 113 m_seenFirstMeaningfulPaintCandidate = true; |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 m_paintTiming->markFirstMeaningfulPaintCandidate(); | 116 m_paintTiming->setFirstMeaningfulPaintCandidate( |
| 117 m_provisionalFirstMeaningfulPaint); |
| 117 } | 118 } |
| 118 | 119 |
| 119 int FirstMeaningfulPaintDetector::activeConnections() { | 120 int FirstMeaningfulPaintDetector::activeConnections() { |
| 120 DCHECK(document()); | 121 DCHECK(document()); |
| 121 ResourceFetcher* fetcher = document()->fetcher(); | 122 ResourceFetcher* fetcher = document()->fetcher(); |
| 122 return fetcher->blockingRequestCount() + fetcher->nonblockingRequestCount(); | 123 return fetcher->blockingRequestCount() + fetcher->nonblockingRequestCount(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 // This function is called when the number of active connections is decreased. | 126 // This function is called when the number of active connections is decreased. |
| 126 void FirstMeaningfulPaintDetector::checkNetworkStable() { | 127 void FirstMeaningfulPaintDetector::checkNetworkStable() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 reportHistograms(); | 164 reportHistograms(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 void FirstMeaningfulPaintDetector::network2QuietTimerFired(TimerBase*) { | 167 void FirstMeaningfulPaintDetector::network2QuietTimerFired(TimerBase*) { |
| 167 if (!document() || m_network2QuietReached || activeConnections() > 2 || | 168 if (!document() || m_network2QuietReached || activeConnections() > 2 || |
| 168 !m_paintTiming->firstContentfulPaint()) | 169 !m_paintTiming->firstContentfulPaint()) |
| 169 return; | 170 return; |
| 170 m_network2QuietReached = true; | 171 m_network2QuietReached = true; |
| 171 | 172 |
| 172 if (m_provisionalFirstMeaningfulPaint) { | 173 if (m_provisionalFirstMeaningfulPaint) { |
| 174 // If there's only been one contentful paint, then there won't have been |
| 175 // a meaningful paint signalled to the Scheduler, so mark one now. |
| 176 // This is a no-op if a FMPC has already been marked. |
| 177 m_paintTiming->setFirstMeaningfulPaintCandidate( |
| 178 m_provisionalFirstMeaningfulPaint); |
| 173 // Enforce FirstContentfulPaint <= FirstMeaningfulPaint. | 179 // Enforce FirstContentfulPaint <= FirstMeaningfulPaint. |
| 174 m_firstMeaningfulPaint2Quiet = | 180 m_firstMeaningfulPaint2Quiet = |
| 175 std::max(m_provisionalFirstMeaningfulPaint, | 181 std::max(m_provisionalFirstMeaningfulPaint, |
| 176 m_paintTiming->firstContentfulPaint()); | 182 m_paintTiming->firstContentfulPaint()); |
| 177 // Report FirstMeaningfulPaint when the page reached network 2-quiet. | 183 // Report FirstMeaningfulPaint when the page reached network 2-quiet. |
| 178 m_paintTiming->setFirstMeaningfulPaint(m_firstMeaningfulPaint2Quiet); | 184 m_paintTiming->setFirstMeaningfulPaint(m_firstMeaningfulPaint2Quiet); |
| 179 } | 185 } |
| 180 reportHistograms(); | 186 reportHistograms(); |
| 181 } | 187 } |
| 182 | 188 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } else if (m_firstMeaningfulPaint2Quiet) { | 226 } else if (m_firstMeaningfulPaint2Quiet) { |
| 221 hadNetworkQuietHistogram.count(HadNetwork2Quiet); | 227 hadNetworkQuietHistogram.count(HadNetwork2Quiet); |
| 222 } | 228 } |
| 223 } | 229 } |
| 224 | 230 |
| 225 DEFINE_TRACE(FirstMeaningfulPaintDetector) { | 231 DEFINE_TRACE(FirstMeaningfulPaintDetector) { |
| 226 visitor->trace(m_paintTiming); | 232 visitor->trace(m_paintTiming); |
| 227 } | 233 } |
| 228 | 234 |
| 229 } // namespace blink | 235 } // namespace blink |
| OLD | NEW |