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

Side by Side Diff: third_party/WebKit/Source/core/paint/FirstMeaningfulPaintDetector.cpp

Issue 2039363003: FirstMeaningfulPaint UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ready for review Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/paint/FirstMeaningfulPaintDetector.h"
6
7 #include "core/css/FontFaceSet.h"
8 #include "core/fetch/ResourceFetcher.h"
9 #include "core/paint/PaintTiming.h"
10
11 namespace blink {
12
13 namespace {
14
15 // Web fonts that laid out more than this number of characters block First
16 // Meaningful Paint.
17 const int kBlankCharactersThreshold = 200;
18
19 // FirstMeaningfulPaintDetector stops observing layouts and reports First
20 // Meaningful Paint when this duration passed from last network activity.
21 const double kTimeWithoutNetworkActivity = 2.0;
22
23 } // namespace
24
25 FirstMeaningfulPaintDetector& FirstMeaningfulPaintDetector::from(Document& docum ent)
26 {
27 return PaintTiming::from(document).firstMeaningfulPaintDetector();
28 }
29
30 FirstMeaningfulPaintDetector::FirstMeaningfulPaintDetector(PaintTiming* paintTim ing)
31 : m_paintTiming(paintTiming)
32 , m_networkStableTimer(this, &FirstMeaningfulPaintDetector::networkStableTim erFired)
33 {
34 }
35
36 Document* FirstMeaningfulPaintDetector::document()
37 {
38 return m_paintTiming->document();
39 }
40
41 void FirstMeaningfulPaintDetector::computeLayoutSignificance(
42 const LayoutObjectCounter& counter, int contentsHeightBeforeLayout,
43 int contentsHeightAfterLayout, int visibleHeight)
44 {
45 if (m_state == Reported)
46 return;
47
48 unsigned delta = counter.count() - m_prevLayoutObjectCount;
49 m_prevLayoutObjectCount = counter.count();
50
51 double ratioBefore = std::max(1.0, static_cast<double>(contentsHeightBeforeL ayout) / visibleHeight);
52 double ratioAfter = std::max(1.0, static_cast<double>(contentsHeightAfterLay out) / visibleHeight);
53 double significance = delta / ((ratioBefore + ratioAfter) / 2);
54
55 int approximateBlankCharacterCount = FontFaceSet::approximateBlankCharacterC ount(*document());
56 if (approximateBlankCharacterCount > kBlankCharactersThreshold) {
57 m_accumulatedSignificanceWhileHavingBlankText += significance;
58 } else {
59 significance += m_accumulatedSignificanceWhileHavingBlankText;
60 m_accumulatedSignificanceWhileHavingBlankText = 0;
61 if (significance > m_maxSignificanceSoFar) {
62 m_state = NextPaintIsMeaningful;
63 m_maxSignificanceSoFar = significance;
64 }
65 }
66 }
67
68 void FirstMeaningfulPaintDetector::notifyPaint()
69 {
70 if (m_state == NextPaintIsMeaningful) {
71 m_provisionalFirstMeaningfulPaint = monotonicallyIncreasingTime();
72 m_state = NextPaintIsNotMeaningful;
73 }
74 }
75
76 void FirstMeaningfulPaintDetector::checkNetworkStable()
77 {
78 if (m_state == Reported || !document() || document()->fetcher()->hasPendingR equest())
kouhei (in TOK) 2016/07/28 03:45:04 s/hasPendingRequest/!document()->frame()->isLoadin
Kunihiko Sakamoto 2016/08/01 08:52:07 IIUC frame()->isLoading() never returns true after
79 return;
80
81 if (m_networkStableTimer.isActive())
82 m_networkStableTimer.stop();
83 m_networkStableTimer.startOneShot(kTimeWithoutNetworkActivity, BLINK_FROM_HE RE);
84 }
85
86 void FirstMeaningfulPaintDetector::networkStableTimerFired(Timer<FirstMeaningful PaintDetector>*)
87 {
88 if (m_state == Reported || !document() || document()->fetcher()->hasPendingR equest())
89 return;
90
91 m_paintTiming->setFirstMeaningfulPaint(m_provisionalFirstMeaningfulPaint);
92 m_state = Reported;
93 }
94
95 DEFINE_TRACE(FirstMeaningfulPaintDetector)
96 {
97 visitor->trace(m_paintTiming);
98 }
99
100 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698