| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 167 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 168 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( | 168 DataReductionProxyMetricsObserver::FlushMetricsOnAppEnterBackground( |
| 169 const page_load_metrics::PageLoadTiming& timing, | 169 const page_load_metrics::PageLoadTiming& timing, |
| 170 const page_load_metrics::PageLoadExtraInfo& info) { | 170 const page_load_metrics::PageLoadExtraInfo& info) { |
| 171 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | 171 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the |
| 172 // app is about to be backgrounded, as part of the Activity.onPause() | 172 // 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 | 173 // 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. | 174 // notification, so we send a pingback with data collected up to this point. |
| 175 if (info.did_commit) { | 175 if (info.did_commit) { |
| 176 RecordPageSizeUMA(); | 176 RecordPageSizeUMA(); |
| 177 SendPingback(timing, info); | 177 SendPingback(timing, info, true /* app_background_occurred */); |
| 178 } | 178 } |
| 179 return STOP_OBSERVING; | 179 return STOP_OBSERVING; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void DataReductionProxyMetricsObserver::OnComplete( | 182 void DataReductionProxyMetricsObserver::OnComplete( |
| 183 const page_load_metrics::PageLoadTiming& timing, | 183 const page_load_metrics::PageLoadTiming& timing, |
| 184 const page_load_metrics::PageLoadExtraInfo& info) { | 184 const page_load_metrics::PageLoadExtraInfo& info) { |
| 185 RecordPageSizeUMA(); | 185 RecordPageSizeUMA(); |
| 186 SendPingback(timing, info); | 186 SendPingback(timing, info, false /* app_background_occurred */); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void DataReductionProxyMetricsObserver::RecordPageSizeUMA() const { | 189 void DataReductionProxyMetricsObserver::RecordPageSizeUMA() const { |
| 190 if (!data_) | 190 if (!data_) |
| 191 return; | 191 return; |
| 192 | 192 |
| 193 // If the first request didn't complete, don't record UMA. | 193 // If the first request didn't complete, don't record UMA. |
| 194 if (num_network_resources_ == 0) | 194 if (num_network_resources_ == 0) |
| 195 return; | 195 return; |
| 196 | 196 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 PAGE_BYTES_HISTOGRAM(GetConstHistogramWithSuffix(internal::kBytesSavings), | 264 PAGE_BYTES_HISTOGRAM(GetConstHistogramWithSuffix(internal::kBytesSavings), |
| 265 original_network_bytes_ - network_bytes_); | 265 original_network_bytes_ - network_bytes_); |
| 266 } else { | 266 } else { |
| 267 PAGE_BYTES_HISTOGRAM(GetConstHistogramWithSuffix(internal::kBytesInflation), | 267 PAGE_BYTES_HISTOGRAM(GetConstHistogramWithSuffix(internal::kBytesInflation), |
| 268 network_bytes_proxied_ - original_network_bytes_); | 268 network_bytes_proxied_ - original_network_bytes_); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 void DataReductionProxyMetricsObserver::SendPingback( | 272 void DataReductionProxyMetricsObserver::SendPingback( |
| 273 const page_load_metrics::PageLoadTiming& timing, | 273 const page_load_metrics::PageLoadTiming& timing, |
| 274 const page_load_metrics::PageLoadExtraInfo& info) { | 274 const page_load_metrics::PageLoadExtraInfo& info, |
| 275 bool app_background_occurred) { |
| 275 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast | 276 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast |
| 276 // shutdown cases. crbug.com/618072 | 277 // shutdown cases. crbug.com/618072 |
| 277 if (!browser_context_ || !data_) | 278 if (!browser_context_ || !data_) |
| 278 return; | 279 return; |
| 279 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || | 280 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || |
| 280 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { | 281 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { |
| 281 return; | 282 return; |
| 282 } | 283 } |
| 283 // Only consider timing events that happened before the first background | 284 // Only consider timing events that happened before the first background |
| 284 // event. | 285 // event. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 if (WasStartedInForegroundOptionalEventInForeground(timing.parse_stop, | 318 if (WasStartedInForegroundOptionalEventInForeground(timing.parse_stop, |
| 318 info)) { | 319 info)) { |
| 319 parse_stop = timing.parse_stop; | 320 parse_stop = timing.parse_stop; |
| 320 } | 321 } |
| 321 | 322 |
| 322 DataReductionProxyPageLoadTiming data_reduction_proxy_timing( | 323 DataReductionProxyPageLoadTiming data_reduction_proxy_timing( |
| 323 timing.navigation_start, response_start, load_event_start, | 324 timing.navigation_start, response_start, load_event_start, |
| 324 first_image_paint, first_contentful_paint, | 325 first_image_paint, first_contentful_paint, |
| 325 experimental_first_meaningful_paint, | 326 experimental_first_meaningful_paint, |
| 326 parse_blocked_on_script_load_duration, parse_stop, network_bytes_, | 327 parse_blocked_on_script_load_duration, parse_stop, network_bytes_, |
| 327 original_network_bytes_); | 328 original_network_bytes_, app_background_occurred); |
| 328 GetPingbackClient()->SendPingback(*data_, data_reduction_proxy_timing); | 329 GetPingbackClient()->SendPingback(*data_, data_reduction_proxy_timing); |
| 329 } | 330 } |
| 330 | 331 |
| 331 void DataReductionProxyMetricsObserver::OnDomContentLoadedEventStart( | 332 void DataReductionProxyMetricsObserver::OnDomContentLoadedEventStart( |
| 332 const page_load_metrics::PageLoadTiming& timing, | 333 const page_load_metrics::PageLoadTiming& timing, |
| 333 const page_load_metrics::PageLoadExtraInfo& info) { | 334 const page_load_metrics::PageLoadExtraInfo& info) { |
| 334 RECORD_FOREGROUND_HISTOGRAMS_FOR_SUFFIX( | 335 RECORD_FOREGROUND_HISTOGRAMS_FOR_SUFFIX( |
| 335 info, data_, timing.dom_content_loaded_event_start, | 336 info, data_, timing.dom_content_loaded_event_start, |
| 336 internal::kHistogramDOMContentLoadedEventFiredSuffix); | 337 internal::kHistogramDOMContentLoadedEventFiredSuffix); |
| 337 } | 338 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 timing.parse_stop.value() - timing.parse_start.value(); | 408 timing.parse_stop.value() - timing.parse_start.value(); |
| 408 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, | 409 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, |
| 409 internal::kHistogramParseDurationSuffix); | 410 internal::kHistogramParseDurationSuffix); |
| 410 RECORD_HISTOGRAMS_FOR_SUFFIX( | 411 RECORD_HISTOGRAMS_FOR_SUFFIX( |
| 411 data_, timing.parse_blocked_on_script_load_duration.value(), | 412 data_, timing.parse_blocked_on_script_load_duration.value(), |
| 412 internal::kHistogramParseBlockedOnScriptLoadSuffix); | 413 internal::kHistogramParseBlockedOnScriptLoadSuffix); |
| 413 } | 414 } |
| 414 | 415 |
| 415 void DataReductionProxyMetricsObserver::OnLoadedResource( | 416 void DataReductionProxyMetricsObserver::OnLoadedResource( |
| 416 const page_load_metrics::ExtraRequestInfo& extra_request_info) { | 417 const page_load_metrics::ExtraRequestInfo& extra_request_info) { |
| 418 if (extra_request_info.data_reduction_proxy_data && |
| 419 extra_request_info.data_reduction_proxy_data->lofi_received()) { |
| 420 data_->set_lofi_received(true); |
| 421 } |
| 417 if (extra_request_info.was_cached) | 422 if (extra_request_info.was_cached) |
| 418 return; | 423 return; |
| 419 original_network_bytes_ += extra_request_info.original_network_content_length; | 424 original_network_bytes_ += extra_request_info.original_network_content_length; |
| 420 network_bytes_ += extra_request_info.raw_body_bytes; | 425 network_bytes_ += extra_request_info.raw_body_bytes; |
| 421 num_network_resources_++; | 426 num_network_resources_++; |
| 422 if (!extra_request_info.data_reduction_proxy_used) | 427 if (!extra_request_info.data_reduction_proxy_data || |
| 428 !extra_request_info.data_reduction_proxy_data |
| 429 ->used_data_reduction_proxy()) { |
| 423 return; | 430 return; |
| 431 } |
| 424 num_data_reduction_proxy_resources_++; | 432 num_data_reduction_proxy_resources_++; |
| 425 network_bytes_proxied_ += extra_request_info.raw_body_bytes; | 433 network_bytes_proxied_ += extra_request_info.raw_body_bytes; |
| 426 } | 434 } |
| 427 | 435 |
| 428 DataReductionProxyPingbackClient* | 436 DataReductionProxyPingbackClient* |
| 429 DataReductionProxyMetricsObserver::GetPingbackClient() const { | 437 DataReductionProxyMetricsObserver::GetPingbackClient() const { |
| 430 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 438 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 431 browser_context_) | 439 browser_context_) |
| 432 ->data_reduction_proxy_service() | 440 ->data_reduction_proxy_service() |
| 433 ->pingback_client(); | 441 ->pingback_client(); |
| 434 } | 442 } |
| 435 | 443 |
| 436 } // namespace data_reduction_proxy | 444 } // namespace data_reduction_proxy |
| OLD | NEW |