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

Side by Side Diff: components/page_load_metrics/renderer/metrics_render_frame_observer.cc

Issue 2111073003: Update PageLoadTiming to use base::Optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@optionalbug
Patch Set: remove comment Created 4 years, 5 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
« no previous file with comments | « components/page_load_metrics/common/page_load_timing.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/page_load_metrics/renderer/metrics_render_frame_observer.h" 5 #include "components/page_load_metrics/renderer/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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return true; 111 return true;
112 } 112 }
113 113
114 PageLoadTiming MetricsRenderFrameObserver::GetTiming() const { 114 PageLoadTiming MetricsRenderFrameObserver::GetTiming() const {
115 const blink::WebPerformance& perf = 115 const blink::WebPerformance& perf =
116 render_frame()->GetWebFrame()->performance(); 116 render_frame()->GetWebFrame()->performance();
117 117
118 PageLoadTiming timing; 118 PageLoadTiming timing;
119 double start = perf.navigationStart(); 119 double start = perf.navigationStart();
120 timing.navigation_start = base::Time::FromDoubleT(start); 120 timing.navigation_start = base::Time::FromDoubleT(start);
121 timing.response_start = ClampDelta(perf.responseStart(), start); 121 if (perf.responseStart() > 0.0)
122 timing.dom_loading = ClampDelta(perf.domLoading(), start); 122 timing.response_start = ClampDelta(perf.responseStart(), start);
123 timing.dom_content_loaded_event_start = 123 if (perf.domLoading() > 0.0)
124 ClampDelta(perf.domContentLoadedEventStart(), start); 124 timing.dom_loading = ClampDelta(perf.domLoading(), start);
125 timing.load_event_start = ClampDelta(perf.loadEventStart(), start); 125 if (perf.domContentLoadedEventStart() > 0.0)
126 timing.first_layout = ClampDelta(perf.firstLayout(), start); 126 timing.dom_content_loaded_event_start =
127 timing.first_paint = ClampDelta(perf.firstPaint(), start); 127 ClampDelta(perf.domContentLoadedEventStart(), start);
128 timing.first_text_paint = ClampDelta(perf.firstTextPaint(), start); 128 if (perf.loadEventStart() > 0.0)
129 timing.first_image_paint = ClampDelta(perf.firstImagePaint(), start); 129 timing.load_event_start = ClampDelta(perf.loadEventStart(), start);
130 timing.first_contentful_paint = 130 if (perf.firstLayout() > 0.0)
131 ClampDelta(perf.firstContentfulPaint(), start); 131 timing.first_layout = ClampDelta(perf.firstLayout(), start);
132 timing.parse_start = ClampDelta(perf.parseStart(), start); 132 if (perf.firstPaint() > 0.0)
133 timing.parse_stop = ClampDelta(perf.parseStop(), start); 133 timing.first_paint = ClampDelta(perf.firstPaint(), start);
134 timing.parse_blocked_on_script_load_duration = 134 if (perf.firstTextPaint() > 0.0)
135 base::TimeDelta::FromSecondsD(perf.parseBlockedOnScriptLoadDuration()); 135 timing.first_text_paint = ClampDelta(perf.firstTextPaint(), start);
136 timing.parse_blocked_on_script_load_from_document_write_duration = 136 if (perf.firstImagePaint() > 0.0)
137 base::TimeDelta::FromSecondsD( 137 timing.first_image_paint = ClampDelta(perf.firstImagePaint(), start);
138 perf.parseBlockedOnScriptLoadFromDocumentWriteDuration()); 138 if (perf.firstContentfulPaint() > 0.0)
139 timing.first_contentful_paint =
140 ClampDelta(perf.firstContentfulPaint(), start);
141 if (perf.parseStart() > 0.0)
142 timing.parse_start = ClampDelta(perf.parseStart(), start);
143 if (perf.parseStop() > 0.0)
144 timing.parse_stop = ClampDelta(perf.parseStop(), start);
145 if (timing.parse_start) {
146 // If we started parsing, record all parser durations such as the amount of
147 // time blocked on script load, even if those values are zero.
148 timing.parse_blocked_on_script_load_duration =
149 base::TimeDelta::FromSecondsD(perf.parseBlockedOnScriptLoadDuration());
150 timing.parse_blocked_on_script_load_from_document_write_duration =
151 base::TimeDelta::FromSecondsD(
152 perf.parseBlockedOnScriptLoadFromDocumentWriteDuration());
153 }
139 return timing; 154 return timing;
140 } 155 }
141 156
142 std::unique_ptr<base::Timer> MetricsRenderFrameObserver::CreateTimer() const { 157 std::unique_ptr<base::Timer> MetricsRenderFrameObserver::CreateTimer() const {
143 return base::WrapUnique(new base::OneShotTimer); 158 return base::WrapUnique(new base::OneShotTimer);
144 } 159 }
145 160
146 bool MetricsRenderFrameObserver::HasNoRenderFrame() const { 161 bool MetricsRenderFrameObserver::HasNoRenderFrame() const {
147 bool no_frame = !render_frame() || !render_frame()->GetWebFrame(); 162 bool no_frame = !render_frame() || !render_frame()->GetWebFrame();
148 DCHECK(!no_frame); 163 DCHECK(!no_frame);
149 return no_frame; 164 return no_frame;
150 } 165 }
151 166
152 void MetricsRenderFrameObserver::OnDestruct() { 167 void MetricsRenderFrameObserver::OnDestruct() {
153 delete this; 168 delete this;
154 } 169 }
155 170
156 } // namespace page_load_metrics 171 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « components/page_load_metrics/common/page_load_timing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698