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/WebFrameScheduler.h" | 14 #include "platform/WebFrameScheduler.h" |
12 #include "platform/instrumentation/tracing/TraceEvent.h" | 15 #include "platform/instrumentation/tracing/TraceEvent.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 && frame->domWindow()) { |
| 24 performance = DOMWindowPerformance::performance(*frame->domWindow()); |
| 25 } |
| 26 return performance; |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
16 static const char kSupplementName[] = "PaintTiming"; | 31 static const char kSupplementName[] = "PaintTiming"; |
17 | 32 |
18 PaintTiming& PaintTiming::from(Document& document) { | 33 PaintTiming& PaintTiming::from(Document& document) { |
19 PaintTiming* timing = static_cast<PaintTiming*>( | 34 PaintTiming* timing = static_cast<PaintTiming*>( |
20 Supplement<Document>::from(document, kSupplementName)); | 35 Supplement<Document>::from(document, kSupplementName)); |
21 if (!timing) { | 36 if (!timing) { |
22 timing = new PaintTiming(document); | 37 timing = new PaintTiming(document); |
23 Supplement<Document>::provideTo(document, kSupplementName, timing); | 38 Supplement<Document>::provideTo(document, kSupplementName, timing); |
24 } | 39 } |
25 return *timing; | 40 return *timing; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 128 |
114 void PaintTiming::notifyPaintTimingChanged() { | 129 void PaintTiming::notifyPaintTimingChanged() { |
115 if (host()->loader()) | 130 if (host()->loader()) |
116 host()->loader()->didChangePerformanceTiming(); | 131 host()->loader()->didChangePerformanceTiming(); |
117 } | 132 } |
118 | 133 |
119 void PaintTiming::setFirstPaint(double stamp) { | 134 void PaintTiming::setFirstPaint(double stamp) { |
120 if (m_firstPaint != 0.0) | 135 if (m_firstPaint != 0.0) |
121 return; | 136 return; |
122 m_firstPaint = stamp; | 137 m_firstPaint = stamp; |
| 138 Performance* performance = getPerformanceInstance(frame()); |
| 139 if (performance) |
| 140 performance->addFirstPaintTiming(m_firstPaint); |
| 141 |
123 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstPaint", | 142 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstPaint", |
124 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); | 143 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); |
125 } | 144 } |
126 | 145 |
127 void PaintTiming::setFirstContentfulPaint(double stamp) { | 146 void PaintTiming::setFirstContentfulPaint(double stamp) { |
128 if (m_firstContentfulPaint != 0.0) | 147 if (m_firstContentfulPaint != 0.0) |
129 return; | 148 return; |
130 setFirstPaint(stamp); | 149 setFirstPaint(stamp); |
131 m_firstContentfulPaint = stamp; | 150 m_firstContentfulPaint = stamp; |
| 151 Performance* performance = getPerformanceInstance(frame()); |
| 152 if (performance) |
| 153 performance->addFirstContentfulPaintTiming(m_firstContentfulPaint); |
132 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstContentfulPaint", | 154 TRACE_EVENT_INSTANT1("blink.user_timing,rail", "firstContentfulPaint", |
133 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); | 155 TRACE_EVENT_SCOPE_PROCESS, "frame", frame()); |
134 } | 156 } |
135 | 157 |
136 } // namespace blink | 158 } // namespace blink |
OLD | NEW |