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 "chrome/renderer/page_load_metrics/metrics_render_frame_observer.h" | 5 #include "chrome/renderer/page_load_metrics/metrics_render_frame_observer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 page_timing_metrics_sender_ = base::MakeUnique<PageTimingMetricsSender>( | 73 page_timing_metrics_sender_ = base::MakeUnique<PageTimingMetricsSender>( |
74 this, routing_id(), CreateTimer(), GetTiming()); | 74 this, routing_id(), CreateTimer(), GetTiming()); |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 void MetricsRenderFrameObserver::SendMetrics() { | 78 void MetricsRenderFrameObserver::SendMetrics() { |
79 if (!page_timing_metrics_sender_) | 79 if (!page_timing_metrics_sender_) |
80 return; | 80 return; |
81 if (HasNoRenderFrame()) | 81 if (HasNoRenderFrame()) |
82 return; | 82 return; |
83 PageLoadTiming timing(GetTiming()); | 83 page_timing_metrics_sender_->Send(GetTiming()); |
84 page_timing_metrics_sender_->Send(timing); | |
85 } | 84 } |
86 | 85 |
87 bool MetricsRenderFrameObserver::ShouldSendMetrics() const { | 86 bool MetricsRenderFrameObserver::ShouldSendMetrics() const { |
88 if (HasNoRenderFrame()) | 87 if (HasNoRenderFrame()) |
89 return false; | 88 return false; |
90 const blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); | 89 const blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
91 const blink::WebDocument& document = frame->GetDocument(); | 90 const blink::WebDocument& document = frame->GetDocument(); |
92 return RendererPageTrackDecider(&document, frame->DataSource()).ShouldTrack(); | 91 return RendererPageTrackDecider(&document, frame->DataSource()).ShouldTrack(); |
93 } | 92 } |
94 | 93 |
95 PageLoadTiming MetricsRenderFrameObserver::GetTiming() const { | 94 mojom::PageLoadTimingPtr MetricsRenderFrameObserver::GetTiming() const { |
96 const blink::WebPerformance& perf = | 95 const blink::WebPerformance& perf = |
97 render_frame()->GetWebFrame()->Performance(); | 96 render_frame()->GetWebFrame()->Performance(); |
98 | 97 |
99 PageLoadTiming timing; | 98 mojom::PageLoadTimingPtr timing(CreatePageLoadTiming()); |
100 double start = perf.NavigationStart(); | 99 double start = perf.NavigationStart(); |
101 timing.navigation_start = base::Time::FromDoubleT(start); | 100 timing->navigation_start = base::Time::FromDoubleT(start); |
102 if (perf.ResponseStart() > 0.0) | 101 if (perf.ResponseStart() > 0.0) |
103 timing.response_start = ClampDelta(perf.ResponseStart(), start); | 102 timing->response_start = ClampDelta(perf.ResponseStart(), start); |
104 if (perf.DomContentLoadedEventStart() > 0.0) { | 103 if (perf.DomContentLoadedEventStart() > 0.0) { |
105 timing.document_timing.dom_content_loaded_event_start = | 104 timing->document_timing->dom_content_loaded_event_start = |
106 ClampDelta(perf.DomContentLoadedEventStart(), start); | 105 ClampDelta(perf.DomContentLoadedEventStart(), start); |
107 } | 106 } |
108 if (perf.LoadEventStart() > 0.0) { | 107 if (perf.LoadEventStart() > 0.0) { |
109 timing.document_timing.load_event_start = | 108 timing->document_timing->load_event_start = |
110 ClampDelta(perf.LoadEventStart(), start); | 109 ClampDelta(perf.LoadEventStart(), start); |
111 } | 110 } |
112 if (perf.FirstLayout() > 0.0) | 111 if (perf.FirstLayout() > 0.0) |
113 timing.document_timing.first_layout = ClampDelta(perf.FirstLayout(), start); | 112 timing->document_timing->first_layout = |
| 113 ClampDelta(perf.FirstLayout(), start); |
114 if (perf.FirstPaint() > 0.0) | 114 if (perf.FirstPaint() > 0.0) |
115 timing.paint_timing.first_paint = ClampDelta(perf.FirstPaint(), start); | 115 timing->paint_timing->first_paint = ClampDelta(perf.FirstPaint(), start); |
116 if (perf.FirstTextPaint() > 0.0) { | 116 if (perf.FirstTextPaint() > 0.0) { |
117 timing.paint_timing.first_text_paint = | 117 timing->paint_timing->first_text_paint = |
118 ClampDelta(perf.FirstTextPaint(), start); | 118 ClampDelta(perf.FirstTextPaint(), start); |
119 } | 119 } |
120 if (perf.FirstImagePaint() > 0.0) { | 120 if (perf.FirstImagePaint() > 0.0) { |
121 timing.paint_timing.first_image_paint = | 121 timing->paint_timing->first_image_paint = |
122 ClampDelta(perf.FirstImagePaint(), start); | 122 ClampDelta(perf.FirstImagePaint(), start); |
123 } | 123 } |
124 if (perf.FirstContentfulPaint() > 0.0) { | 124 if (perf.FirstContentfulPaint() > 0.0) { |
125 timing.paint_timing.first_contentful_paint = | 125 timing->paint_timing->first_contentful_paint = |
126 ClampDelta(perf.FirstContentfulPaint(), start); | 126 ClampDelta(perf.FirstContentfulPaint(), start); |
127 } | 127 } |
128 if (perf.FirstMeaningfulPaint() > 0.0) { | 128 if (perf.FirstMeaningfulPaint() > 0.0) { |
129 timing.paint_timing.first_meaningful_paint = | 129 timing->paint_timing->first_meaningful_paint = |
130 ClampDelta(perf.FirstMeaningfulPaint(), start); | 130 ClampDelta(perf.FirstMeaningfulPaint(), start); |
131 } | 131 } |
132 if (perf.ParseStart() > 0.0) | 132 if (perf.ParseStart() > 0.0) |
133 timing.parse_timing.parse_start = ClampDelta(perf.ParseStart(), start); | 133 timing->parse_timing->parse_start = ClampDelta(perf.ParseStart(), start); |
134 if (perf.ParseStop() > 0.0) | 134 if (perf.ParseStop() > 0.0) |
135 timing.parse_timing.parse_stop = ClampDelta(perf.ParseStop(), start); | 135 timing->parse_timing->parse_stop = ClampDelta(perf.ParseStop(), start); |
136 if (timing.parse_timing.parse_start) { | 136 if (timing->parse_timing->parse_start) { |
137 // If we started parsing, record all parser durations such as the amount of | 137 // If we started parsing, record all parser durations such as the amount of |
138 // time blocked on script load, even if those values are zero. | 138 // time blocked on script load, even if those values are zero. |
139 timing.parse_timing.parse_blocked_on_script_load_duration = | 139 timing->parse_timing->parse_blocked_on_script_load_duration = |
140 base::TimeDelta::FromSecondsD(perf.ParseBlockedOnScriptLoadDuration()); | 140 base::TimeDelta::FromSecondsD(perf.ParseBlockedOnScriptLoadDuration()); |
141 timing.parse_timing | 141 timing->parse_timing |
142 .parse_blocked_on_script_load_from_document_write_duration = | 142 ->parse_blocked_on_script_load_from_document_write_duration = |
143 base::TimeDelta::FromSecondsD( | 143 base::TimeDelta::FromSecondsD( |
144 perf.ParseBlockedOnScriptLoadFromDocumentWriteDuration()); | 144 perf.ParseBlockedOnScriptLoadFromDocumentWriteDuration()); |
145 timing.parse_timing.parse_blocked_on_script_execution_duration = | 145 timing->parse_timing->parse_blocked_on_script_execution_duration = |
146 base::TimeDelta::FromSecondsD( | 146 base::TimeDelta::FromSecondsD( |
147 perf.ParseBlockedOnScriptExecutionDuration()); | 147 perf.ParseBlockedOnScriptExecutionDuration()); |
148 timing.parse_timing | 148 timing->parse_timing |
149 .parse_blocked_on_script_execution_from_document_write_duration = | 149 ->parse_blocked_on_script_execution_from_document_write_duration = |
150 base::TimeDelta::FromSecondsD( | 150 base::TimeDelta::FromSecondsD( |
151 perf.ParseBlockedOnScriptExecutionFromDocumentWriteDuration()); | 151 perf.ParseBlockedOnScriptExecutionFromDocumentWriteDuration()); |
152 } | 152 } |
153 | 153 |
154 if (perf.AuthorStyleSheetParseDurationBeforeFCP() > 0.0) { | 154 if (perf.AuthorStyleSheetParseDurationBeforeFCP() > 0.0) { |
155 timing.style_sheet_timing.author_style_sheet_parse_duration_before_fcp = | 155 timing->style_sheet_timing->author_style_sheet_parse_duration_before_fcp = |
156 base::TimeDelta::FromSecondsD( | 156 base::TimeDelta::FromSecondsD( |
157 perf.AuthorStyleSheetParseDurationBeforeFCP()); | 157 perf.AuthorStyleSheetParseDurationBeforeFCP()); |
158 } | 158 } |
159 if (perf.UpdateStyleDurationBeforeFCP() > 0.0) { | 159 if (perf.UpdateStyleDurationBeforeFCP() > 0.0) { |
160 timing.style_sheet_timing.update_style_duration_before_fcp = | 160 timing->style_sheet_timing->update_style_duration_before_fcp = |
161 base::TimeDelta::FromSecondsD(perf.UpdateStyleDurationBeforeFCP()); | 161 base::TimeDelta::FromSecondsD(perf.UpdateStyleDurationBeforeFCP()); |
162 } | 162 } |
163 return timing; | 163 return timing; |
164 } | 164 } |
165 | 165 |
166 std::unique_ptr<base::Timer> MetricsRenderFrameObserver::CreateTimer() const { | 166 std::unique_ptr<base::Timer> MetricsRenderFrameObserver::CreateTimer() const { |
167 return base::WrapUnique(new base::OneShotTimer); | 167 return base::WrapUnique(new base::OneShotTimer); |
168 } | 168 } |
169 | 169 |
170 bool MetricsRenderFrameObserver::HasNoRenderFrame() const { | 170 bool MetricsRenderFrameObserver::HasNoRenderFrame() const { |
171 bool no_frame = !render_frame() || !render_frame()->GetWebFrame(); | 171 bool no_frame = !render_frame() || !render_frame()->GetWebFrame(); |
172 DCHECK(!no_frame); | 172 DCHECK(!no_frame); |
173 return no_frame; | 173 return no_frame; |
174 } | 174 } |
175 | 175 |
176 void MetricsRenderFrameObserver::OnDestruct() { | 176 void MetricsRenderFrameObserver::OnDestruct() { |
177 delete this; | 177 delete this; |
178 } | 178 } |
179 | 179 |
180 } // namespace page_load_metrics | 180 } // namespace page_load_metrics |
OLD | NEW |