| 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/optional.h" | 9 #include "base/optional.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/navigation_data.h" | 23 #include "content/public/browser/navigation_data.h" |
| 24 #include "content/public/browser/navigation_handle.h" | 24 #include "content/public/browser/navigation_handle.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 namespace data_reduction_proxy { | 28 namespace data_reduction_proxy { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 bool ShouldRecordHistogram(const DataReductionProxyData* data, | |
| 33 const base::Optional<base::TimeDelta>& event, | |
| 34 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 35 return data && data->used_data_reduction_proxy() && | |
| 36 WasStartedInForegroundOptionalEventInForeground(event, info); | |
| 37 } | |
| 38 | |
| 39 // A macro is needed because PAGE_LOAD_HISTOGRAM creates a static instance of | 32 // A macro is needed because PAGE_LOAD_HISTOGRAM creates a static instance of |
| 40 // the histogram. A distinct histogram is needed for each place that calls | 33 // the histogram. A distinct histogram is needed for each place that calls |
| 41 // RECORD_HISTOGRAMS_FOR_SUFFIX. |event| is the timing event representing when | 34 // RECORD_HISTOGRAMS_FOR_SUFFIX. |event| is the timing event representing when |
| 42 // |value| became available. | 35 // |value| became available. |
| 43 #define RECORD_HISTOGRAMS_FOR_SUFFIX(data, event, value, info, \ | 36 #define RECORD_HISTOGRAMS_FOR_SUFFIX(data, value, histogram_suffix) \ |
| 44 histogram_suffix) \ | 37 do { \ |
| 45 do { \ | 38 PAGE_LOAD_HISTOGRAM( \ |
| 46 if (ShouldRecordHistogram(data.get(), event, info)) { \ | 39 std::string(internal::kHistogramDataReductionProxyPrefix) \ |
| 47 PAGE_LOAD_HISTOGRAM( \ | 40 .append(histogram_suffix), \ |
| 48 std::string(internal::kHistogramDataReductionProxyPrefix) \ | 41 value); \ |
| 49 .append(histogram_suffix), \ | 42 if (data->lofi_requested()) { \ |
| 50 value); \ | 43 PAGE_LOAD_HISTOGRAM( \ |
| 51 if (data->lofi_requested()) { \ | 44 std::string(internal::kHistogramDataReductionProxyLoFiOnPrefix) \ |
| 52 PAGE_LOAD_HISTOGRAM( \ | 45 .append(histogram_suffix), \ |
| 53 std::string(internal::kHistogramDataReductionProxyLoFiOnPrefix) \ | 46 value); \ |
| 54 .append(histogram_suffix), \ | 47 } \ |
| 55 value); \ | |
| 56 } \ | |
| 57 } \ | |
| 58 } while (false) | 48 } while (false) |
| 59 | 49 |
| 60 } // namespace | 50 } // namespace |
| 61 | 51 |
| 62 namespace internal { | 52 namespace internal { |
| 63 | 53 |
| 64 const char kHistogramDataReductionProxyPrefix[] = | 54 const char kHistogramDataReductionProxyPrefix[] = |
| 65 "PageLoad.Clients.DataReductionProxy."; | 55 "PageLoad.Clients.DataReductionProxy."; |
| 66 const char kHistogramDataReductionProxyLoFiOnPrefix[] = | 56 const char kHistogramDataReductionProxyLoFiOnPrefix[] = |
| 67 "PageLoad.Clients.DataReductionProxy.LoFiOn."; | 57 "PageLoad.Clients.DataReductionProxy.LoFiOn."; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // ResourceDispatcherHostDelegate::GetNavigationData during commit. | 99 // ResourceDispatcherHostDelegate::GetNavigationData during commit. |
| 110 // Because ChromeResourceDispatcherHostDelegate always returns a | 100 // Because ChromeResourceDispatcherHostDelegate always returns a |
| 111 // ChromeNavigationData, it is safe to static_cast here. | 101 // ChromeNavigationData, it is safe to static_cast here. |
| 112 ChromeNavigationData* chrome_navigation_data = | 102 ChromeNavigationData* chrome_navigation_data = |
| 113 static_cast<ChromeNavigationData*>( | 103 static_cast<ChromeNavigationData*>( |
| 114 navigation_handle->GetNavigationData()); | 104 navigation_handle->GetNavigationData()); |
| 115 if (!chrome_navigation_data) | 105 if (!chrome_navigation_data) |
| 116 return STOP_OBSERVING; | 106 return STOP_OBSERVING; |
| 117 data_reduction_proxy::DataReductionProxyData* data = | 107 data_reduction_proxy::DataReductionProxyData* data = |
| 118 chrome_navigation_data->GetDataReductionProxyData(); | 108 chrome_navigation_data->GetDataReductionProxyData(); |
| 119 if (!data) | 109 if (!data || !data->used_data_reduction_proxy()) |
| 120 return STOP_OBSERVING; | 110 return STOP_OBSERVING; |
| 121 data_ = data->DeepCopy(); | 111 data_ = data->DeepCopy(); |
| 122 // DataReductionProxy page loads should only occur on HTTP navigations. | 112 // DataReductionProxy page loads should only occur on HTTP navigations. |
| 123 DCHECK(!data_->used_data_reduction_proxy() || | 113 DCHECK(!navigation_handle->GetURL().SchemeIsCryptographic()); |
| 124 !navigation_handle->GetURL().SchemeIsCryptographic()); | |
| 125 return CONTINUE_OBSERVING; | 114 return CONTINUE_OBSERVING; |
| 126 } | 115 } |
| 127 | 116 |
| 117 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 118 DataReductionProxyMetricsObserver::OnStart( |
| 119 content::NavigationHandle* navigation_handle, |
| 120 const GURL& currently_committed_url, |
| 121 bool started_in_foreground) { |
| 122 if (!started_in_foreground) |
| 123 return STOP_OBSERVING; |
| 124 return CONTINUE_OBSERVING; |
| 125 } |
| 126 |
| 127 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 128 DataReductionProxyMetricsObserver::OnHidden( |
| 129 const page_load_metrics::PageLoadTiming& timing, |
| 130 const page_load_metrics::PageLoadExtraInfo& info) { |
| 131 SendPingback(timing, info); |
| 132 return STOP_OBSERVING; |
| 133 } |
| 134 |
| 128 void DataReductionProxyMetricsObserver::OnComplete( | 135 void DataReductionProxyMetricsObserver::OnComplete( |
| 129 const page_load_metrics::PageLoadTiming& timing, | 136 const page_load_metrics::PageLoadTiming& timing, |
| 130 const page_load_metrics::PageLoadExtraInfo& info) { | 137 const page_load_metrics::PageLoadExtraInfo& info) { |
| 138 SendPingback(timing, info); |
| 139 } |
| 140 |
| 141 void DataReductionProxyMetricsObserver::SendPingback( |
| 142 const page_load_metrics::PageLoadTiming& timing, |
| 143 const page_load_metrics::PageLoadExtraInfo& info) { |
| 131 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast | 144 // TODO(ryansturm): Move to OnFirstBackgroundEvent to handle some fast |
| 132 // shutdown cases. crbug.com/618072 | 145 // shutdown cases. crbug.com/618072 |
| 133 if (!browser_context_) | 146 if (!browser_context_) |
| 134 return; | 147 return; |
| 135 if (!data_ || !data_->used_data_reduction_proxy()) | |
| 136 return; | |
| 137 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || | 148 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || |
| 138 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { | 149 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { |
| 139 return; | 150 return; |
| 140 } | 151 } |
| 141 // Only consider timing events that happened before the first background | 152 // Only consider timing events that happened before the first background |
| 142 // event. | 153 // event. |
| 143 base::Optional<base::TimeDelta> response_start; | 154 base::Optional<base::TimeDelta> response_start; |
| 144 base::Optional<base::TimeDelta> load_event_start; | 155 base::Optional<base::TimeDelta> load_event_start; |
| 145 base::Optional<base::TimeDelta> first_image_paint; | 156 base::Optional<base::TimeDelta> first_image_paint; |
| 146 base::Optional<base::TimeDelta> first_contentful_paint; | 157 base::Optional<base::TimeDelta> first_contentful_paint; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 first_image_paint, first_contentful_paint, | 193 first_image_paint, first_contentful_paint, |
| 183 experimental_first_meaningful_paint, | 194 experimental_first_meaningful_paint, |
| 184 parse_blocked_on_script_load_duration, parse_stop); | 195 parse_blocked_on_script_load_duration, parse_stop); |
| 185 GetPingbackClient()->SendPingback(*data_, data_reduction_proxy_timing); | 196 GetPingbackClient()->SendPingback(*data_, data_reduction_proxy_timing); |
| 186 } | 197 } |
| 187 | 198 |
| 188 void DataReductionProxyMetricsObserver::OnDomContentLoadedEventStart( | 199 void DataReductionProxyMetricsObserver::OnDomContentLoadedEventStart( |
| 189 const page_load_metrics::PageLoadTiming& timing, | 200 const page_load_metrics::PageLoadTiming& timing, |
| 190 const page_load_metrics::PageLoadExtraInfo& info) { | 201 const page_load_metrics::PageLoadExtraInfo& info) { |
| 191 RECORD_HISTOGRAMS_FOR_SUFFIX( | 202 RECORD_HISTOGRAMS_FOR_SUFFIX( |
| 192 data_, timing.dom_content_loaded_event_start, | 203 data_, timing.dom_content_loaded_event_start.value(), |
| 193 timing.dom_content_loaded_event_start.value(), info, | |
| 194 internal::kHistogramDOMContentLoadedEventFiredSuffix); | 204 internal::kHistogramDOMContentLoadedEventFiredSuffix); |
| 195 } | 205 } |
| 196 | 206 |
| 197 void DataReductionProxyMetricsObserver::OnLoadEventStart( | 207 void DataReductionProxyMetricsObserver::OnLoadEventStart( |
| 198 const page_load_metrics::PageLoadTiming& timing, | 208 const page_load_metrics::PageLoadTiming& timing, |
| 199 const page_load_metrics::PageLoadExtraInfo& info) { | 209 const page_load_metrics::PageLoadExtraInfo& info) { |
| 200 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.load_event_start, | 210 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.load_event_start.value(), |
| 201 timing.load_event_start.value(), info, | |
| 202 internal::kHistogramLoadEventFiredSuffix); | 211 internal::kHistogramLoadEventFiredSuffix); |
| 203 } | 212 } |
| 204 | 213 |
| 205 void DataReductionProxyMetricsObserver::OnFirstLayout( | 214 void DataReductionProxyMetricsObserver::OnFirstLayout( |
| 206 const page_load_metrics::PageLoadTiming& timing, | 215 const page_load_metrics::PageLoadTiming& timing, |
| 207 const page_load_metrics::PageLoadExtraInfo& info) { | 216 const page_load_metrics::PageLoadExtraInfo& info) { |
| 208 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_layout, | 217 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_layout.value(), |
| 209 timing.first_layout.value(), info, | |
| 210 internal::kHistogramFirstLayoutSuffix); | 218 internal::kHistogramFirstLayoutSuffix); |
| 211 } | 219 } |
| 212 | 220 |
| 213 void DataReductionProxyMetricsObserver::OnFirstPaint( | 221 void DataReductionProxyMetricsObserver::OnFirstPaint( |
| 214 const page_load_metrics::PageLoadTiming& timing, | 222 const page_load_metrics::PageLoadTiming& timing, |
| 215 const page_load_metrics::PageLoadExtraInfo& info) { | 223 const page_load_metrics::PageLoadExtraInfo& info) { |
| 216 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_paint, | 224 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_paint.value(), |
| 217 timing.first_paint.value(), info, | |
| 218 internal::kHistogramFirstPaintSuffix); | 225 internal::kHistogramFirstPaintSuffix); |
| 219 } | 226 } |
| 220 | 227 |
| 221 void DataReductionProxyMetricsObserver::OnFirstTextPaint( | 228 void DataReductionProxyMetricsObserver::OnFirstTextPaint( |
| 222 const page_load_metrics::PageLoadTiming& timing, | 229 const page_load_metrics::PageLoadTiming& timing, |
| 223 const page_load_metrics::PageLoadExtraInfo& info) { | 230 const page_load_metrics::PageLoadExtraInfo& info) { |
| 224 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_text_paint, | 231 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_text_paint.value(), |
| 225 timing.first_text_paint.value(), info, | |
| 226 internal::kHistogramFirstTextPaintSuffix); | 232 internal::kHistogramFirstTextPaintSuffix); |
| 227 } | 233 } |
| 228 | 234 |
| 229 void DataReductionProxyMetricsObserver::OnFirstImagePaint( | 235 void DataReductionProxyMetricsObserver::OnFirstImagePaint( |
| 230 const page_load_metrics::PageLoadTiming& timing, | 236 const page_load_metrics::PageLoadTiming& timing, |
| 231 const page_load_metrics::PageLoadExtraInfo& info) { | 237 const page_load_metrics::PageLoadExtraInfo& info) { |
| 232 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_image_paint, | 238 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_image_paint.value(), |
| 233 timing.first_image_paint.value(), info, | |
| 234 internal::kHistogramFirstImagePaintSuffix); | 239 internal::kHistogramFirstImagePaintSuffix); |
| 235 } | 240 } |
| 236 | 241 |
| 237 void DataReductionProxyMetricsObserver::OnFirstContentfulPaint( | 242 void DataReductionProxyMetricsObserver::OnFirstContentfulPaint( |
| 238 const page_load_metrics::PageLoadTiming& timing, | 243 const page_load_metrics::PageLoadTiming& timing, |
| 239 const page_load_metrics::PageLoadExtraInfo& info) { | 244 const page_load_metrics::PageLoadExtraInfo& info) { |
| 240 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_contentful_paint, | 245 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_contentful_paint.value(), |
| 241 timing.first_contentful_paint.value(), info, | |
| 242 internal::kHistogramFirstContentfulPaintSuffix); | 246 internal::kHistogramFirstContentfulPaintSuffix); |
| 243 } | 247 } |
| 244 | 248 |
| 245 void DataReductionProxyMetricsObserver::OnFirstMeaningfulPaint( | 249 void DataReductionProxyMetricsObserver::OnFirstMeaningfulPaint( |
| 246 const page_load_metrics::PageLoadTiming& timing, | 250 const page_load_metrics::PageLoadTiming& timing, |
| 247 const page_load_metrics::PageLoadExtraInfo& info) { | 251 const page_load_metrics::PageLoadExtraInfo& info) { |
| 248 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_meaningful_paint, | 252 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.first_meaningful_paint.value(), |
| 249 timing.first_meaningful_paint.value(), info, | |
| 250 internal::kHistogramFirstMeaningfulPaintSuffix); | 253 internal::kHistogramFirstMeaningfulPaintSuffix); |
| 251 } | 254 } |
| 252 | 255 |
| 253 void DataReductionProxyMetricsObserver::OnParseStart( | 256 void DataReductionProxyMetricsObserver::OnParseStart( |
| 254 const page_load_metrics::PageLoadTiming& timing, | 257 const page_load_metrics::PageLoadTiming& timing, |
| 255 const page_load_metrics::PageLoadExtraInfo& info) { | 258 const page_load_metrics::PageLoadExtraInfo& info) { |
| 256 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.parse_start, | 259 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.parse_start.value(), |
| 257 timing.parse_start.value(), info, | |
| 258 internal::kHistogramParseStartSuffix); | 260 internal::kHistogramParseStartSuffix); |
| 259 } | 261 } |
| 260 | 262 |
| 261 void DataReductionProxyMetricsObserver::OnParseStop( | 263 void DataReductionProxyMetricsObserver::OnParseStop( |
| 262 const page_load_metrics::PageLoadTiming& timing, | 264 const page_load_metrics::PageLoadTiming& timing, |
| 263 const page_load_metrics::PageLoadExtraInfo& info) { | 265 const page_load_metrics::PageLoadExtraInfo& info) { |
| 264 base::TimeDelta parse_duration = | 266 base::TimeDelta parse_duration = |
| 265 timing.parse_stop.value() - timing.parse_start.value(); | 267 timing.parse_stop.value() - timing.parse_start.value(); |
| 266 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, timing.parse_stop, parse_duration, info, | 268 RECORD_HISTOGRAMS_FOR_SUFFIX(data_, parse_duration, |
| 267 internal::kHistogramParseDurationSuffix); | 269 internal::kHistogramParseDurationSuffix); |
| 268 RECORD_HISTOGRAMS_FOR_SUFFIX( | 270 RECORD_HISTOGRAMS_FOR_SUFFIX( |
| 269 data_, timing.parse_stop, | 271 data_, timing.parse_blocked_on_script_load_duration.value(), |
| 270 timing.parse_blocked_on_script_load_duration.value(), info, | |
| 271 internal::kHistogramParseBlockedOnScriptLoadSuffix); | 272 internal::kHistogramParseBlockedOnScriptLoadSuffix); |
| 272 } | 273 } |
| 273 | 274 |
| 274 DataReductionProxyPingbackClient* | 275 DataReductionProxyPingbackClient* |
| 275 DataReductionProxyMetricsObserver::GetPingbackClient() const { | 276 DataReductionProxyMetricsObserver::GetPingbackClient() const { |
| 276 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 277 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 277 browser_context_) | 278 browser_context_) |
| 278 ->data_reduction_proxy_service() | 279 ->data_reduction_proxy_service() |
| 279 ->pingback_client(); | 280 ->pingback_client(); |
| 280 } | 281 } |
| 281 | 282 |
| 282 } // namespace data_reduction_proxy | 283 } // namespace data_reduction_proxy |
| OLD | NEW |