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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" | 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 9 #include "components/page_load_metrics/common/page_load_metrics_messages.h" |
10 #include "components/page_load_metrics/common/page_load_timing.h" | 10 #include "components/page_load_metrics/common/page_load_timing.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 timing.response_start <= timing.load_event_start && | 44 timing.response_start <= timing.load_event_start && |
45 timing.dom_content_loaded_event_start <= timing.load_event_start); | 45 timing.dom_content_loaded_event_start <= timing.load_event_start); |
46 | 46 |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 MetricsWebContentsObserver::MetricsWebContentsObserver( | 52 MetricsWebContentsObserver::MetricsWebContentsObserver( |
53 content::WebContents* web_contents) | 53 content::WebContents* web_contents) |
54 : content::WebContentsObserver(web_contents) {} | 54 : content::WebContentsObserver(web_contents), |
55 current_navigation_stayed_in_foreground_(false), | |
56 previous_navigation_stayed_in_foreground_(false), | |
57 in_foreground_(false) {} | |
Bryan McQuade
2015/09/22 23:27:47
can webcontents ever start foregrounded (such that
Charlie Harrison
2015/09/23 22:15:23
I couldn't find a case where we don't get the WasS
| |
55 | 58 |
56 // This object is tied to a single WebContents for its entire lifetime. | 59 // This object is tied to a single WebContents for its entire lifetime. |
57 MetricsWebContentsObserver::~MetricsWebContentsObserver() { | 60 MetricsWebContentsObserver::~MetricsWebContentsObserver() { |
58 RecordTimingHistograms(); | 61 RecordTimingHistograms(); |
59 } | 62 } |
60 | 63 |
61 bool MetricsWebContentsObserver::OnMessageReceived( | 64 bool MetricsWebContentsObserver::OnMessageReceived( |
62 const IPC::Message& message, | 65 const IPC::Message& message, |
63 content::RenderFrameHost* render_frame_host) { | 66 content::RenderFrameHost* render_frame_host) { |
64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 14 matching lines...) Expand all Loading... | |
79 current_timing_.reset(new PageLoadTiming()); | 82 current_timing_.reset(new PageLoadTiming()); |
80 } | 83 } |
81 | 84 |
82 // This will occur when the process for the main RenderFrameHost exits. | 85 // This will occur when the process for the main RenderFrameHost exits. |
83 // This will happen with a normal exit or a crash. | 86 // This will happen with a normal exit or a crash. |
84 void MetricsWebContentsObserver::RenderProcessGone( | 87 void MetricsWebContentsObserver::RenderProcessGone( |
85 base::TerminationStatus status) { | 88 base::TerminationStatus status) { |
86 RecordTimingHistograms(); | 89 RecordTimingHistograms(); |
87 } | 90 } |
88 | 91 |
92 void MetricsWebContentsObserver::DidStartNavigation( | |
93 content::NavigationHandle* navigation_handle) { | |
94 if (!navigation_handle->IsInMainFrame()) | |
95 return; | |
96 current_navigation_stayed_in_foreground_ = in_foreground_; | |
clamy
2015/09/22 23:54:31
This could break down in certain edge cases. You m
clamy
2015/09/23 00:06:18
Similarly, we can have the following case:
1) You
| |
97 } | |
98 | |
99 void MetricsWebContentsObserver::DidFinishLoad( | |
100 content::RenderFrameHost* render_frame_host, | |
101 const GURL& validated_url) { | |
102 if (render_frame_host == web_contents()->GetMainFrame()) { | |
103 previous_navigation_stayed_in_foreground_ = | |
104 current_navigation_stayed_in_foreground_; | |
105 } | |
106 } | |
107 | |
108 void MetricsWebContentsObserver::DidFailLoad( | |
109 content::RenderFrameHost* render_frame_host, | |
110 const GURL& validated_url, | |
111 int error_code, | |
112 const base::string16& error_description, | |
113 bool was_ignored_by_handler) { | |
114 if (render_frame_host == web_contents()->GetMainFrame()) { | |
115 previous_navigation_stayed_in_foreground_ = | |
116 current_navigation_stayed_in_foreground_; | |
117 } | |
118 } | |
119 void MetricsWebContentsObserver::WasShown() { | |
120 in_foreground_ = true; | |
121 } | |
122 void MetricsWebContentsObserver::WasHidden() { | |
123 in_foreground_ = false; | |
124 current_navigation_stayed_in_foreground_ = false; | |
125 } | |
126 | |
89 #define PAGE_LOAD_HISTOGRAM(name, sample) \ | 127 #define PAGE_LOAD_HISTOGRAM(name, sample) \ |
90 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, \ | 128 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, \ |
91 base::TimeDelta::FromMilliseconds(10), \ | 129 base::TimeDelta::FromMilliseconds(10), \ |
92 base::TimeDelta::FromMinutes(10), 100); | 130 base::TimeDelta::FromMinutes(10), 100); |
93 | 131 |
94 void MetricsWebContentsObserver::OnTimingUpdated( | 132 void MetricsWebContentsObserver::OnTimingUpdated( |
95 content::RenderFrameHost* render_frame_host, | 133 content::RenderFrameHost* render_frame_host, |
96 const PageLoadTiming& timing) { | 134 const PageLoadTiming& timing) { |
97 if (!current_timing_) | 135 if (!current_timing_) |
98 return; | 136 return; |
(...skipping 17 matching lines...) Expand all Loading... | |
116 } | 154 } |
117 | 155 |
118 *current_timing_ = timing; | 156 *current_timing_ = timing; |
119 } | 157 } |
120 | 158 |
121 void MetricsWebContentsObserver::RecordTimingHistograms() { | 159 void MetricsWebContentsObserver::RecordTimingHistograms() { |
122 if (!current_timing_ || !IsValidPageLoadTiming(*current_timing_)) | 160 if (!current_timing_ || !IsValidPageLoadTiming(*current_timing_)) |
123 return; | 161 return; |
124 | 162 |
125 if (!current_timing_->dom_content_loaded_event_start.is_zero()) { | 163 if (!current_timing_->dom_content_loaded_event_start.is_zero()) { |
126 PAGE_LOAD_HISTOGRAM( | 164 if (previous_navigation_stayed_in_foreground_) { |
127 "PageLoad.Timing.NavigationToDOMContentLoadedEventFired", | 165 PAGE_LOAD_HISTOGRAM( |
128 current_timing_->dom_content_loaded_event_start); | 166 "PageLoad.Timing.NavigationToDOMContentLoadedEventFired", |
167 current_timing_->dom_content_loaded_event_start); | |
168 } else { | |
169 PAGE_LOAD_HISTOGRAM( | |
170 "PageLoad.Timing.BG.NavigationToDOMContentLoadedEventFired", | |
171 current_timing_->dom_content_loaded_event_start); | |
172 } | |
129 } | 173 } |
130 | 174 |
131 if (!current_timing_->load_event_start.is_zero()) { | 175 if (!current_timing_->load_event_start.is_zero()) { |
132 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.NavigationToLoadEventFired", | 176 if (previous_navigation_stayed_in_foreground_) { |
133 current_timing_->load_event_start); | 177 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.NavigationToLoadEventFired", |
178 current_timing_->load_event_start); | |
179 } else { | |
180 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.BG.NavigationToLoadEventFired", | |
181 current_timing_->load_event_start); | |
182 } | |
134 } | 183 } |
135 | 184 |
136 if (!current_timing_->first_layout.is_zero()) { | 185 if (!current_timing_->first_layout.is_zero()) { |
137 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.NavigationToFirstLayout", | 186 if (previous_navigation_stayed_in_foreground_) { |
138 current_timing_->first_layout); | 187 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.NavigationToFirstLayout", |
188 current_timing_->first_layout); | |
189 } else { | |
190 PAGE_LOAD_HISTOGRAM("PageLoad.Timing.BG.NavigationToFirstLayout", | |
191 current_timing_->first_layout); | |
192 } | |
139 } | 193 } |
140 current_timing_.reset(); | 194 current_timing_.reset(); |
141 } | 195 } |
142 | 196 |
143 bool MetricsWebContentsObserver::IsRelevantNavigation( | 197 bool MetricsWebContentsObserver::IsRelevantNavigation( |
144 content::NavigationHandle* navigation_handle) { | 198 content::NavigationHandle* navigation_handle) { |
145 // The url we see from the renderer side is not always the same as what | 199 // The url we see from the renderer side is not always the same as what |
146 // we see from the browser side (e.g. chrome://newtab). We want to be | 200 // we see from the browser side (e.g. chrome://newtab). We want to be |
147 // sure here that we aren't logging UMA for internal pages. | 201 // sure here that we aren't logging UMA for internal pages. |
148 const GURL& browser_url = web_contents()->GetLastCommittedURL(); | 202 const GURL& browser_url = web_contents()->GetLastCommittedURL(); |
149 return navigation_handle->IsInMainFrame() && | 203 return navigation_handle->IsInMainFrame() && |
150 !navigation_handle->IsSamePage() && | 204 !navigation_handle->IsSamePage() && |
151 navigation_handle->HasCommittedDocument() && | 205 navigation_handle->HasCommittedDocument() && |
152 navigation_handle->GetURL().SchemeIsHTTPOrHTTPS() && | 206 navigation_handle->GetURL().SchemeIsHTTPOrHTTPS() && |
153 browser_url.SchemeIsHTTPOrHTTPS(); | 207 browser_url.SchemeIsHTTPOrHTTPS(); |
154 } | 208 } |
155 | 209 |
156 } // namespace page_load_metrics | 210 } // namespace page_load_metrics |
OLD | NEW |