OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/PaintTiming.h" | 5 #include "core/paint/PaintTiming.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/frame/LocalDOMWindow.h" | |
9 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
10 #include "core/loader/DocumentLoader.h" | 11 #include "core/loader/DocumentLoader.h" |
12 #include "core/timing/DOMWindowPerformance.h" | |
13 #include "core/timing/Performance.h" | |
11 #include "platform/tracing/TraceEvent.h" | 14 #include "platform/tracing/TraceEvent.h" |
12 #include "public/platform/WebFrameScheduler.h" | 15 #include "public/platform/WebFrameScheduler.h" |
13 | 16 |
14 namespace blink { | 17 namespace blink { |
15 | 18 |
19 namespace { | |
20 | |
21 Performance* getPerformanceInstance(LocalFrame* frame) { | |
22 Performance* performance = nullptr; | |
23 if (frame) { | |
24 performance = DOMWindowPerformance::performance(*frame->localDOMWindow()); | |
haraken
2016/12/09 00:30:03
frame->localDOMWindow() may return null. Check it.
sunjian
2016/12/09 19:06:49
Done.
| |
25 DCHECK(performance); | |
26 } | |
27 return performance; | |
28 } | |
29 | |
30 } // namespace | |
31 | |
16 static const char kSupplementName[] = "PaintTiming"; | 32 static const char kSupplementName[] = "PaintTiming"; |
17 | 33 |
18 PaintTiming& PaintTiming::from(Document& document) { | 34 PaintTiming& PaintTiming::from(Document& document) { |
19 PaintTiming* timing = static_cast<PaintTiming*>( | 35 PaintTiming* timing = static_cast<PaintTiming*>( |
20 Supplement<Document>::from(document, kSupplementName)); | 36 Supplement<Document>::from(document, kSupplementName)); |
21 if (!timing) { | 37 if (!timing) { |
22 timing = new PaintTiming(document); | 38 timing = new PaintTiming(document); |
23 Supplement<Document>::provideTo(document, kSupplementName, timing); | 39 Supplement<Document>::provideTo(document, kSupplementName, timing); |
24 } | 40 } |
25 return *timing; | 41 return *timing; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 | 131 |
116 void PaintTiming::notifyPaintTimingChanged() { | 132 void PaintTiming::notifyPaintTimingChanged() { |
117 if (m_document && m_document->loader()) | 133 if (m_document && m_document->loader()) |
118 m_document->loader()->didChangePerformanceTiming(); | 134 m_document->loader()->didChangePerformanceTiming(); |
119 } | 135 } |
120 | 136 |
121 void PaintTiming::setFirstPaint(double stamp) { | 137 void PaintTiming::setFirstPaint(double stamp) { |
122 if (m_firstPaint != 0.0) | 138 if (m_firstPaint != 0.0) |
123 return; | 139 return; |
124 m_firstPaint = stamp; | 140 m_firstPaint = stamp; |
141 Performance* performance = getPerformanceInstance(frame()); | |
142 if (performance) | |
143 performance->addFirstPaintTiming(m_firstPaint); | |
144 | |
125 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstPaint", | 145 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstPaint", |
126 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); | 146 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); |
127 } | 147 } |
128 | 148 |
129 void PaintTiming::setFirstContentfulPaint(double stamp) { | 149 void PaintTiming::setFirstContentfulPaint(double stamp) { |
130 if (m_firstContentfulPaint != 0.0) | 150 if (m_firstContentfulPaint != 0.0) |
131 return; | 151 return; |
132 setFirstPaint(stamp); | 152 setFirstPaint(stamp); |
133 m_firstContentfulPaint = stamp; | 153 m_firstContentfulPaint = stamp; |
154 Performance* performance = getPerformanceInstance(frame()); | |
155 if (performance) | |
156 performance->addFirstContentfulPaintTiming(m_firstContentfulPaint); | |
134 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstContentfulPaint", | 157 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstContentfulPaint", |
135 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); | 158 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); |
136 } | 159 } |
137 | 160 |
138 } // namespace blink | 161 } // namespace blink |
OLD | NEW |