OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/page_load_metrics/observers/data_reduction_proxy_metric s_observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/data_reduction_proxy_metric s_observer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/optional.h" | 10 #include "base/optional.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 const char kBytesInflation[] = "Experimental.Bytes.Network.Inflation"; | 111 const char kBytesInflation[] = "Experimental.Bytes.Network.Inflation"; |
112 | 112 |
113 } // namespace internal | 113 } // namespace internal |
114 | 114 |
115 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver() | 115 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver() |
116 : browser_context_(nullptr), | 116 : browser_context_(nullptr), |
117 num_data_reduction_proxy_resources_(0), | 117 num_data_reduction_proxy_resources_(0), |
118 num_network_resources_(0), | 118 num_network_resources_(0), |
119 original_network_bytes_(0), | 119 original_network_bytes_(0), |
120 network_bytes_proxied_(0), | 120 network_bytes_proxied_(0), |
121 network_bytes_(0) {} | 121 network_bytes_(0), |
122 tab_identifier_key_(nullptr) {} | |
122 | 123 |
123 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {} | 124 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {} |
124 | 125 |
125 // Check if the NavigationData indicates anything about the DataReductionProxy. | 126 // Check if the NavigationData indicates anything about the DataReductionProxy. |
126 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 127 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
127 DataReductionProxyMetricsObserver::OnCommit( | 128 DataReductionProxyMetricsObserver::OnCommit( |
128 content::NavigationHandle* navigation_handle) { | 129 content::NavigationHandle* navigation_handle) { |
129 // This BrowserContext is valid for the lifetime of | 130 // This BrowserContext is valid for the lifetime of |
130 // DataReductionProxyMetricsObserver. BrowserContext is always valid and | 131 // DataReductionProxyMetricsObserver. BrowserContext is always valid and |
131 // non-nullptr in NavigationControllerImpl, which is a member of WebContents. | 132 // non-nullptr in NavigationControllerImpl, which is a member of WebContents. |
132 // A raw pointer to BrowserContext taken at this point will be valid until | 133 // A raw pointer to BrowserContext taken at this point will be valid until |
133 // after WebContent's destructor. The latest that PageLoadTracker's destructor | 134 // after WebContent's destructor. The latest that PageLoadTracker's destructor |
134 // will be called is in MetricsWebContentsObserver's destrcutor, which is | 135 // will be called is in MetricsWebContentsObserver's destrcutor, which is |
135 // called in WebContents destructor. | 136 // called in WebContents destructor. |
136 browser_context_ = navigation_handle->GetWebContents()->GetBrowserContext(); | 137 browser_context_ = navigation_handle->GetWebContents()->GetBrowserContext(); |
137 // As documented in content/public/browser/navigation_handle.h, this | 138 // As documented in content/public/browser/navigation_handle.h, this |
138 // NavigationData is a clone of the NavigationData instance returned from | 139 // NavigationData is a clone of the NavigationData instance returned from |
139 // ResourceDispatcherHostDelegate::GetNavigationData during commit. | 140 // ResourceDispatcherHostDelegate::GetNavigationData during commit. |
140 // Because ChromeResourceDispatcherHostDelegate always returns a | 141 // Because ChromeResourceDispatcherHostDelegate always returns a |
141 // ChromeNavigationData, it is safe to static_cast here. | 142 // ChromeNavigationData, it is safe to static_cast here. |
142 ChromeNavigationData* chrome_navigation_data = | 143 ChromeNavigationData* chrome_navigation_data = |
143 static_cast<ChromeNavigationData*>( | 144 static_cast<ChromeNavigationData*>( |
144 navigation_handle->GetNavigationData()); | 145 navigation_handle->GetNavigationData()); |
145 if (!chrome_navigation_data) | 146 if (!chrome_navigation_data) |
146 return STOP_OBSERVING; | 147 return STOP_OBSERVING; |
147 data_reduction_proxy::DataReductionProxyData* data = | 148 data_reduction_proxy::DataReductionProxyData* data = |
148 chrome_navigation_data->GetDataReductionProxyData(); | 149 chrome_navigation_data->GetDataReductionProxyData(); |
149 if (!data || !data->used_data_reduction_proxy()) | 150 if (!data || !data->used_data_reduction_proxy()) |
150 return STOP_OBSERVING; | 151 return STOP_OBSERVING; |
152 tab_identifier_key_ = navigation_handle->GetWebContents(); | |
Charlie Harrison
2017/04/20 14:09:00
This makes me really nervous. Is there any evidenc
RyanSturm
2017/04/20 15:37:57
I agree this is a little odd. How about I rework t
Charlie Harrison
2017/04/20 16:35:06
This approach sounds much better, though I'm not s
bengr
2017/04/20 17:36:18
Likewise, I'm not sure either.
RyanSturm
2017/04/20 20:25:44
Done.
| |
151 data_ = data->DeepCopy(); | 153 data_ = data->DeepCopy(); |
152 // DataReductionProxy page loads should only occur on HTTP navigations. | 154 // DataReductionProxy page loads should only occur on HTTP navigations. |
153 DCHECK(!navigation_handle->GetURL().SchemeIsCryptographic()); | 155 DCHECK(!navigation_handle->GetURL().SchemeIsCryptographic()); |
154 return CONTINUE_OBSERVING; | 156 return CONTINUE_OBSERVING; |
155 } | 157 } |
156 | 158 |
157 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 159 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
158 DataReductionProxyMetricsObserver::OnStart( | 160 DataReductionProxyMetricsObserver::OnStart( |
159 content::NavigationHandle* navigation_handle, | 161 content::NavigationHandle* navigation_handle, |
160 const GURL& currently_committed_url, | 162 const GURL& currently_committed_url, |
161 bool started_in_foreground) { | 163 bool started_in_foreground) { |
162 if (!started_in_foreground) | 164 if (!started_in_foreground) |
163 return STOP_OBSERVING; | 165 return STOP_OBSERVING; |
164 return CONTINUE_OBSERVING; | 166 return CONTINUE_OBSERVING; |
165 } | 167 } |
166 | 168 |
167 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 169 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
168 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( | 170 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( |
169 const page_load_metrics::PageLoadTiming& timing, | 171 const page_load_metrics::PageLoadTiming& timing, |
170 const page_load_metrics::PageLoadExtraInfo& info) { | 172 const page_load_metrics::PageLoadExtraInfo& info) { |
171 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | 173 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the |
172 // app is about to be backgrounded, as part of the Activity.onPause() | 174 // app is about to be backgrounded, as part of the Activity.onPause() |
173 // flow. After this method is invoked, Chrome may be killed without further | 175 // flow. After this method is invoked, Chrome may be killed without further |
174 // notification, so we send a pingback with data collected up to this point. | 176 // notification, so we send a pingback with data collected up to this point. |
175 if (info.did_commit) { | 177 if (info.did_commit) { |
176 RecordPageSizeUMA(); | 178 RecordPageSizeUMA(); |
177 SendPingback(timing, info); | 179 SendPingback(timing, info, true /* app_background_occured */); |
178 } | 180 } |
179 return STOP_OBSERVING; | 181 return STOP_OBSERVING; |
180 } | 182 } |
181 | 183 |
182 void DataReductionProxyMetricsObserver::OnComplete( | 184 void DataReductionProxyMetricsObserver::OnComplete( |
183 const page_load_metrics::PageLoadTiming& timing, | 185 const page_load_metrics::PageLoadTiming& timing, |
184 const page_load_metrics::PageLoadExtraInfo& info) { | 186 const page_load_metrics::PageLoadExtraInfo& info) { |
185 RecordPageSizeUMA(); | 187 RecordPageSizeUMA(); |
186 SendPingback(timing, info); | 188 SendPingback(timing, info, false /* app_background_occured */); |
187 } | 189 } |
188 | 190 |
189 void DataReductionProxyMetricsObserver::RecordPageSizeUMA() const { | 191 void DataReductionProxyMetricsObserver::RecordPageSizeUMA() const { |
190 if (!data_) | 192 if (!data_) |
191 return; | 193 return; |
192 | 194 |
193 // If the first request didn't complete, don't record UMA. | 195 // If the first request didn't complete, don't record UMA. |
194 if (num_network_resources_ == 0) | 196 if (num_network_resources_ == 0) |
195 return; | 197 return; |
196 | 198 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 PAGE_BYTES_HISTOGRAM(GetConstHistogramWithSuffix(internal::kBytesSavings), | 266 PAGE_BYTES_HISTOGRAM(GetConstHistogramWithSuffix(internal::kBytesSavings), |
265 original_network_bytes_ - network_bytes_); | 267 original_network_bytes_ - network_bytes_); |
266 } else { | 268 } else { |
267 PAGE_BYTES_HISTOGRAM(GetConstHistogramWithSuffix(internal::kBytesInflation), | 269 PAGE_BYTES_HISTOGRAM(GetConstHistogramWithSuffix(internal::kBytesInflation), |
268 network_bytes_proxied_ - original_network_bytes_); | 270 network_bytes_proxied_ - original_network_bytes_); |
269 } | 271 } |
270 } | 272 } |
271 | 273 |
272 void DataReductionProxyMetricsObserver::SendPingback( | 274 void DataReductionProxyMetricsObserver::SendPingback( |
273 const page_load_metrics::PageLoadTiming& timing, | 275 const page_load_metrics::PageLoadTiming& timing, |
274 const page_load_metrics::PageLoadExtraInfo& info) { | 276 const page_load_metrics::PageLoadExtraInfo& info, |
277 bool app_background_occured) { | |
bengr
2017/04/20 17:36:18
occurred!
RyanSturm
2017/04/20 20:25:44
Done.
| |
275 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast | 278 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast |
276 // shutdown cases. crbug.com/618072 | 279 // shutdown cases. crbug.com/618072 |
277 if (!browser_context_ || !data_) | 280 if (!browser_context_ || !data_) |
278 return; | 281 return; |
279 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || | 282 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || |
280 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { | 283 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { |
281 return; | 284 return; |
282 } | 285 } |
283 // Only consider timing events that happened before the first background | 286 // Only consider timing events that happened before the first background |
284 // event. | 287 // event. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 if (WasStartedInForegroundOptionalEventInForeground(timing.parse_stop, | 320 if (WasStartedInForegroundOptionalEventInForeground(timing.parse_stop, |
318 info)) { | 321 info)) { |
319 parse_stop = timing.parse_stop; | 322 parse_stop = timing.parse_stop; |
320 } | 323 } |
321 | 324 |
322 DataReductionProxyPageLoadTiming data_reduction_proxy_timing( | 325 DataReductionProxyPageLoadTiming data_reduction_proxy_timing( |
323 timing.navigation_start, response_start, load_event_start, | 326 timing.navigation_start, response_start, load_event_start, |
324 first_image_paint, first_contentful_paint, | 327 first_image_paint, first_contentful_paint, |
325 experimental_first_meaningful_paint, | 328 experimental_first_meaningful_paint, |
326 parse_blocked_on_script_load_duration, parse_stop, network_bytes_, | 329 parse_blocked_on_script_load_duration, parse_stop, network_bytes_, |
327 original_network_bytes_); | 330 original_network_bytes_, app_background_occured); |
328 GetPingbackClient()->SendPingback(*data_, data_reduction_proxy_timing); | 331 GetPingbackClient()->SendPingback(*data_, data_reduction_proxy_timing, |
332 tab_identifier_key_); | |
329 } | 333 } |
330 | 334 |
331 void DataReductionProxyMetricsObserver::OnDomContentLoadedEventStart( | 335 void DataReductionProxyMetricsObserver::OnDomContentLoadedEventStart( |
332 const page_load_metrics::PageLoadTiming& timing, | 336 const page_load_metrics::PageLoadTiming& timing, |
333 const page_load_metrics::PageLoadExtraInfo& info) { | 337 const page_load_metrics::PageLoadExtraInfo& info) { |
334 RECORD_FOREGROUND_HISTOGRAMS_FOR_SUFFIX( | 338 RECORD_FOREGROUND_HISTOGRAMS_FOR_SUFFIX( |
335 info, data_, timing.dom_content_loaded_event_start, | 339 info, data_, timing.dom_content_loaded_event_start, |
336 internal::kHistogramDOMContentLoadedEventFiredSuffix); | 340 internal::kHistogramDOMContentLoadedEventFiredSuffix); |
337 } | 341 } |
338 | 342 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 timing.parse_stop.value() - timing.parse_start.value(); | 411 timing.parse_stop.value() - timing.parse_start.value(); |
408 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, | 412 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, |
409 internal::kHistogramParseDurationSuffix); | 413 internal::kHistogramParseDurationSuffix); |
410 RECORD_HISTOGRAMS_FOR_SUFFIX( | 414 RECORD_HISTOGRAMS_FOR_SUFFIX( |
411 data_, timing.parse_blocked_on_script_load_duration.value(), | 415 data_, timing.parse_blocked_on_script_load_duration.value(), |
412 internal::kHistogramParseBlockedOnScriptLoadSuffix); | 416 internal::kHistogramParseBlockedOnScriptLoadSuffix); |
413 } | 417 } |
414 | 418 |
415 void DataReductionProxyMetricsObserver::OnLoadedResource( | 419 void DataReductionProxyMetricsObserver::OnLoadedResource( |
416 const page_load_metrics::ExtraRequestInfo& extra_request_info) { | 420 const page_load_metrics::ExtraRequestInfo& extra_request_info) { |
421 if (extra_request_info.was_lofi_response) | |
422 data_->set_lofi_received(true); | |
417 if (extra_request_info.was_cached) | 423 if (extra_request_info.was_cached) |
418 return; | 424 return; |
419 original_network_bytes_ += extra_request_info.original_network_content_length; | 425 original_network_bytes_ += extra_request_info.original_network_content_length; |
420 network_bytes_ += extra_request_info.raw_body_bytes; | 426 network_bytes_ += extra_request_info.raw_body_bytes; |
421 num_network_resources_++; | 427 num_network_resources_++; |
422 if (!extra_request_info.data_reduction_proxy_used) | 428 if (!extra_request_info.data_reduction_proxy_used) |
423 return; | 429 return; |
424 num_data_reduction_proxy_resources_++; | 430 num_data_reduction_proxy_resources_++; |
425 network_bytes_proxied_ += extra_request_info.raw_body_bytes; | 431 network_bytes_proxied_ += extra_request_info.raw_body_bytes; |
426 } | 432 } |
427 | 433 |
428 DataReductionProxyPingbackClient* | 434 DataReductionProxyPingbackClient* |
429 DataReductionProxyMetricsObserver::GetPingbackClient() const { | 435 DataReductionProxyMetricsObserver::GetPingbackClient() const { |
430 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 436 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
431 browser_context_) | 437 browser_context_) |
432 ->data_reduction_proxy_service() | 438 ->data_reduction_proxy_service() |
433 ->pingback_client(); | 439 ->pingback_client(); |
434 } | 440 } |
435 | 441 |
436 } // namespace data_reduction_proxy | 442 } // namespace data_reduction_proxy |
OLD | NEW |