| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   86  |   86  | 
|   87 void FirstMeaningfulPaintDetector::NotifyPaint() { |   87 void FirstMeaningfulPaintDetector::NotifyPaint() { | 
|   88   if (!next_paint_is_meaningful_) |   88   if (!next_paint_is_meaningful_) | 
|   89     return; |   89     return; | 
|   90  |   90  | 
|   91   // Skip document background-only paints. |   91   // Skip document background-only paints. | 
|   92   if (paint_timing_->FirstPaint() == 0.0) |   92   if (paint_timing_->FirstPaint() == 0.0) | 
|   93     return; |   93     return; | 
|   94  |   94  | 
|   95   provisional_first_meaningful_paint_ = MonotonicallyIncreasingTime(); |   95   provisional_first_meaningful_paint_ = MonotonicallyIncreasingTime(); | 
 |   96   had_user_input_before_provisional_first_meaningful_paint_ = had_user_input_; | 
|   96   next_paint_is_meaningful_ = false; |   97   next_paint_is_meaningful_ = false; | 
|   97  |   98  | 
|   98   if (network2_quiet_reached_) |   99   if (network2_quiet_reached_) | 
|   99     return; |  100     return; | 
|  100  |  101  | 
|  101   TRACE_EVENT_MARK_WITH_TIMESTAMP1( |  102   TRACE_EVENT_MARK_WITH_TIMESTAMP1( | 
|  102       "loading,devtools.timeline", "firstMeaningfulPaintCandidate", |  103       "loading,devtools.timeline", "firstMeaningfulPaintCandidate", | 
|  103       TraceEvent::ToTraceTimestamp(provisional_first_meaningful_paint_), |  104       TraceEvent::ToTraceTimestamp(provisional_first_meaningful_paint_), | 
|  104       "frame", GetDocument()->GetFrame()); |  105       "frame", GetDocument()->GetFrame()); | 
|  105   // Ignore the first meaningful paint candidate as this generally is the first |  106   // Ignore the first meaningful paint candidate as this generally is the first | 
|  106   // contentful paint itself. |  107   // contentful paint itself. | 
|  107   if (!seen_first_meaningful_paint_candidate_) { |  108   if (!seen_first_meaningful_paint_candidate_) { | 
|  108     seen_first_meaningful_paint_candidate_ = true; |  109     seen_first_meaningful_paint_candidate_ = true; | 
|  109     return; |  110     return; | 
|  110   } |  111   } | 
|  111   paint_timing_->SetFirstMeaningfulPaintCandidate( |  112   paint_timing_->SetFirstMeaningfulPaintCandidate( | 
|  112       provisional_first_meaningful_paint_); |  113       provisional_first_meaningful_paint_); | 
|  113 } |  114 } | 
|  114  |  115  | 
 |  116 // This is called only on FirstMeaningfulPaintDetector for main frame. | 
 |  117 void FirstMeaningfulPaintDetector::NotifyInputEvent() { | 
 |  118   // Ignore user inputs before first paint. | 
 |  119   if (paint_timing_->FirstPaint() == 0.0) | 
 |  120     return; | 
 |  121   had_user_input_ = kHadUserInput; | 
 |  122 } | 
 |  123  | 
|  115 int FirstMeaningfulPaintDetector::ActiveConnections() { |  124 int FirstMeaningfulPaintDetector::ActiveConnections() { | 
|  116   DCHECK(GetDocument()); |  125   DCHECK(GetDocument()); | 
|  117   ResourceFetcher* fetcher = GetDocument()->Fetcher(); |  126   ResourceFetcher* fetcher = GetDocument()->Fetcher(); | 
|  118   return fetcher->BlockingRequestCount() + fetcher->NonblockingRequestCount(); |  127   return fetcher->BlockingRequestCount() + fetcher->NonblockingRequestCount(); | 
|  119 } |  128 } | 
|  120  |  129  | 
|  121 // This function is called when the number of active connections is decreased. |  130 // This function is called when the number of active connections is decreased. | 
|  122 void FirstMeaningfulPaintDetector::CheckNetworkStable() { |  131 void FirstMeaningfulPaintDetector::CheckNetworkStable() { | 
|  123   DCHECK(GetDocument()); |  132   DCHECK(GetDocument()); | 
|  124   if (!GetDocument()->HasFinishedParsing()) |  133   if (!GetDocument()->HasFinishedParsing()) | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  169     // If there's only been one contentful paint, then there won't have been |  178     // If there's only been one contentful paint, then there won't have been | 
|  170     // a meaningful paint signalled to the Scheduler, so mark one now. |  179     // a meaningful paint signalled to the Scheduler, so mark one now. | 
|  171     // This is a no-op if a FMPC has already been marked. |  180     // This is a no-op if a FMPC has already been marked. | 
|  172     paint_timing_->SetFirstMeaningfulPaintCandidate( |  181     paint_timing_->SetFirstMeaningfulPaintCandidate( | 
|  173         provisional_first_meaningful_paint_); |  182         provisional_first_meaningful_paint_); | 
|  174     // Enforce FirstContentfulPaint <= FirstMeaningfulPaint. |  183     // Enforce FirstContentfulPaint <= FirstMeaningfulPaint. | 
|  175     first_meaningful_paint2_quiet_ = |  184     first_meaningful_paint2_quiet_ = | 
|  176         std::max(provisional_first_meaningful_paint_, |  185         std::max(provisional_first_meaningful_paint_, | 
|  177                  paint_timing_->FirstContentfulPaint()); |  186                  paint_timing_->FirstContentfulPaint()); | 
|  178     // Report FirstMeaningfulPaint when the page reached network 2-quiet. |  187     // Report FirstMeaningfulPaint when the page reached network 2-quiet. | 
|  179     paint_timing_->SetFirstMeaningfulPaint(first_meaningful_paint2_quiet_); |  188     paint_timing_->SetFirstMeaningfulPaint( | 
 |  189         first_meaningful_paint2_quiet_, | 
 |  190         had_user_input_before_provisional_first_meaningful_paint_); | 
|  180   } |  191   } | 
|  181   ReportHistograms(); |  192   ReportHistograms(); | 
|  182 } |  193 } | 
|  183  |  194  | 
|  184 void FirstMeaningfulPaintDetector::ReportHistograms() { |  195 void FirstMeaningfulPaintDetector::ReportHistograms() { | 
|  185   // This enum backs an UMA histogram, and should be treated as append-only. |  196   // This enum backs an UMA histogram, and should be treated as append-only. | 
|  186   enum HadNetworkQuiet { |  197   enum HadNetworkQuiet { | 
|  187     kHadNetwork0Quiet, |  198     kHadNetwork0Quiet, | 
|  188     kHadNetwork2Quiet, |  199     kHadNetwork2Quiet, | 
|  189     kHadNetworkQuietEnumMax |  200     kHadNetworkQuietEnumMax | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  222   } else if (first_meaningful_paint2_quiet_) { |  233   } else if (first_meaningful_paint2_quiet_) { | 
|  223     had_network_quiet_histogram.Count(kHadNetwork2Quiet); |  234     had_network_quiet_histogram.Count(kHadNetwork2Quiet); | 
|  224   } |  235   } | 
|  225 } |  236 } | 
|  226  |  237  | 
|  227 DEFINE_TRACE(FirstMeaningfulPaintDetector) { |  238 DEFINE_TRACE(FirstMeaningfulPaintDetector) { | 
|  228   visitor->Trace(paint_timing_); |  239   visitor->Trace(paint_timing_); | 
|  229 } |  240 } | 
|  230  |  241  | 
|  231 }  // namespace blink |  242 }  // namespace blink | 
| OLD | NEW |