| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/page_load_metrics/observers/data_reduction_proxy_metric
s_observer.h" |
| 6 |
| 7 #include "chrome/browser/renderer_host/chrome_navigation_data.h" |
| 8 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data
.h" |
| 9 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
| 10 #include "components/page_load_metrics/browser/page_load_metrics_observer.h" |
| 11 #include "components/page_load_metrics/browser/page_load_metrics_util.h" |
| 12 #include "components/page_load_metrics/common/page_load_timing.h" |
| 13 #include "content/public/browser/navigation_data.h" |
| 14 #include "content/public/browser/navigation_handle.h" |
| 15 |
| 16 namespace data_reduction_proxy { |
| 17 |
| 18 namespace internal { |
| 19 |
| 20 const char kHistogramFirstContentfulPaintDataReductionProxy[] = |
| 21 "PageLoad.Clients.DataReductionProxy.Timing2." |
| 22 "NavigationToFirstContentfulPaint"; |
| 23 const char kHistogramFirstContentfulPaintDataReductionProxyLoFiOn[] = |
| 24 "PageLoad.Clients.DataReductionProxy.LoFiOn.Timing2." |
| 25 "NavigationToFirstContentfulPaint"; |
| 26 |
| 27 } // namespace internal |
| 28 |
| 29 DataReductionProxyMetricsObserver::DataReductionProxyMetricsObserver() |
| 30 : lofi_requested_(false), used_data_reduction_proxy_(false) {} |
| 31 |
| 32 DataReductionProxyMetricsObserver::~DataReductionProxyMetricsObserver() {} |
| 33 |
| 34 // Check if the NavigationData indicates anything about the DataReductionProxy. |
| 35 void DataReductionProxyMetricsObserver::OnCommit( |
| 36 content::NavigationHandle* navigation_handle) { |
| 37 // As documented in content/public/browser/navigation_handle.h, this |
| 38 // NavigationData is a clone of the NavigationData instance returned from |
| 39 // ResourceDispatcherHostDelegate::GetNavigationData during commit. |
| 40 // Because ChromeResourceDispatcherHostDelegate always returns a |
| 41 // ChromeNavigationData, it is safe to static_cast here. |
| 42 ChromeNavigationData* chrome_navigation_data = |
| 43 static_cast<ChromeNavigationData*>( |
| 44 navigation_handle->GetNavigationData()); |
| 45 if (!chrome_navigation_data) |
| 46 return; |
| 47 data_reduction_proxy::DataReductionProxyData* data = |
| 48 chrome_navigation_data->GetDataReductionProxyData(); |
| 49 if (!data) |
| 50 return; |
| 51 used_data_reduction_proxy_ = data->used_data_reduction_proxy(); |
| 52 lofi_requested_ = data->lofi_requested(); |
| 53 } |
| 54 |
| 55 void DataReductionProxyMetricsObserver::OnComplete( |
| 56 const page_load_metrics::PageLoadTiming& timing, |
| 57 const page_load_metrics::PageLoadExtraInfo& info) { |
| 58 RecordTimingHistograms(timing, info); |
| 59 } |
| 60 |
| 61 // Record first contentful paint UMA for various DataReductionProxy |
| 62 // configurations. |
| 63 void DataReductionProxyMetricsObserver::RecordTimingHistograms( |
| 64 const page_load_metrics::PageLoadTiming& timing, |
| 65 const page_load_metrics::PageLoadExtraInfo& info) const { |
| 66 if (!used_data_reduction_proxy_ || |
| 67 !WasStartedInForegroundEventInForeground(timing.first_contentful_paint, |
| 68 info)) |
| 69 return; |
| 70 PAGE_LOAD_HISTOGRAM( |
| 71 internal::kHistogramFirstContentfulPaintDataReductionProxy, |
| 72 timing.first_contentful_paint); |
| 73 if (!lofi_requested_) |
| 74 return; |
| 75 PAGE_LOAD_HISTOGRAM( |
| 76 internal::kHistogramFirstContentfulPaintDataReductionProxyLoFiOn, |
| 77 timing.first_contentful_paint); |
| 78 } |
| 79 |
| 80 } // namespace data_reduction_proxy |
| OLD | NEW |