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/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
22 #include "content/public/browser/navigation_data.h" | 22 #include "content/public/browser/navigation_data.h" |
23 #include "content/public/browser/navigation_handle.h" | 23 #include "content/public/browser/navigation_handle.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 | 25 |
26 namespace data_reduction_proxy { | 26 namespace data_reduction_proxy { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 bool ShouldRecordHistogram(const DataReductionProxyData* data, | 30 bool ShouldRecordHistogram(const DataReductionProxyData* data, |
31 const base::TimeDelta& event, | 31 const base::Optional<base::TimeDelta>& event, |
32 const page_load_metrics::PageLoadExtraInfo& info) { | 32 const page_load_metrics::PageLoadExtraInfo& info) { |
33 return data && data->used_data_reduction_proxy() && | 33 return data && data->used_data_reduction_proxy() && |
34 WasStartedInForegroundEventInForeground(event, info); | 34 WasStartedInForegroundOptionalEventInForeground(event, info); |
35 } | 35 } |
36 | 36 |
37 // A macro is needed because PAGE_LOAD_HISTOGRAM creates a static instance of | 37 // A macro is needed because PAGE_LOAD_HISTOGRAM creates a static instance of |
38 // the histogram. A distinct histogram is needed for each place that calls | 38 // the histogram. A distinct histogram is needed for each place that calls |
39 // RECORD_HISTOGRAMS_FOR_SUFFIX. | 39 // RECORD_HISTOGRAMS_FOR_SUFFIX. |
40 #define RECORD_HISTOGRAMS_FOR_SUFFIX(data, event, info, histogram_suffix) \ | 40 #define RECORD_HISTOGRAMS_FOR_SUFFIX(data, event, info, histogram_suffix) \ |
41 do { \ | 41 do { \ |
42 if (ShouldRecordHistogram(data.get(), event, info)) { \ | 42 if (ShouldRecordHistogram(data.get(), event, info)) { \ |
43 PAGE_LOAD_HISTOGRAM( \ | 43 PAGE_LOAD_HISTOGRAM( \ |
44 std::string(internal::kHistogramDataReductionProxyPrefix) \ | 44 std::string(internal::kHistogramDataReductionProxyPrefix) \ |
45 .append(histogram_suffix), \ | 45 .append(histogram_suffix), \ |
46 event); \ | 46 event.value()); \ |
47 if (data->lofi_requested()) { \ | 47 if (data->lofi_requested()) { \ |
48 PAGE_LOAD_HISTOGRAM( \ | 48 PAGE_LOAD_HISTOGRAM( \ |
49 std::string(internal::kHistogramDataReductionProxyLoFiOnPrefix) \ | 49 std::string(internal::kHistogramDataReductionProxyLoFiOnPrefix) \ |
50 .append(histogram_suffix), \ | 50 .append(histogram_suffix), \ |
51 event); \ | 51 event.value()); \ |
52 } \ | 52 } \ |
53 } \ | 53 } \ |
54 } while (false) | 54 } while (false) |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 namespace internal { | 58 namespace internal { |
59 | 59 |
60 const char kHistogramDataReductionProxyPrefix[] = | 60 const char kHistogramDataReductionProxyPrefix[] = |
61 "PageLoad.Clients.DataReductionProxy."; | 61 "PageLoad.Clients.DataReductionProxy."; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || | 123 if (data_reduction_proxy::params::IsIncludedInHoldbackFieldTrial() || |
124 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { | 124 data_reduction_proxy::params::IsIncludedInTamperDetectionExperiment()) { |
125 return; | 125 return; |
126 } | 126 } |
127 // Only consider timing events that happened before the first background | 127 // Only consider timing events that happened before the first background |
128 // event. | 128 // event. |
129 base::TimeDelta response_start; | 129 base::TimeDelta response_start; |
130 base::TimeDelta load_event_start; | 130 base::TimeDelta load_event_start; |
131 base::TimeDelta first_image_paint; | 131 base::TimeDelta first_image_paint; |
132 base::TimeDelta first_contentful_paint; | 132 base::TimeDelta first_contentful_paint; |
133 if (WasStartedInForegroundEventInForeground(timing.response_start, info)) | 133 if (WasStartedInForegroundOptionalEventInForeground(timing.response_start, |
134 response_start = timing.response_start; | 134 info)) |
135 if (WasStartedInForegroundEventInForeground(timing.load_event_start, info)) | 135 response_start = timing.response_start.value(); |
RyanSturm
2016/07/06 17:10:51
nit: add braces for these since the if is spanning
Bryan McQuade
2016/07/08 18:39:35
Done (and for other cases below)
| |
136 load_event_start = timing.load_event_start; | 136 if (WasStartedInForegroundOptionalEventInForeground(timing.load_event_start, |
137 if (WasStartedInForegroundEventInForeground(timing.first_image_paint, info)) | 137 info)) |
138 first_image_paint = timing.first_image_paint; | 138 load_event_start = timing.load_event_start.value(); |
139 if (WasStartedInForegroundEventInForeground(timing.first_contentful_paint, | 139 if (WasStartedInForegroundOptionalEventInForeground(timing.first_image_paint, |
140 info)) { | 140 info)) |
141 first_contentful_paint = timing.first_contentful_paint; | 141 first_image_paint = timing.first_image_paint.value(); |
142 if (WasStartedInForegroundOptionalEventInForeground( | |
143 timing.first_contentful_paint, info)) { | |
144 first_contentful_paint = timing.first_contentful_paint.value(); | |
142 } | 145 } |
146 // TODO(ryansturm): consider changing DataReductionProxyPageLoadTiming to take | |
RyanSturm
2016/07/06 17:10:51
I opened a bug, can you add crbug.com/626040 to th
Bryan McQuade
2016/07/08 18:39:35
Thanks! Comment updated.
| |
147 // base::Optionals, so we can distinguish zeroes from unset timings. | |
143 DataReductionProxyPageLoadTiming data_reduction_proxy_timing( | 148 DataReductionProxyPageLoadTiming data_reduction_proxy_timing( |
144 timing.navigation_start, response_start, load_event_start, | 149 timing.navigation_start, response_start, load_event_start, |
145 first_image_paint, first_contentful_paint); | 150 first_image_paint, first_contentful_paint); |
146 GetPingbackClient()->SendPingback(*data_, data_reduction_proxy_timing); | 151 GetPingbackClient()->SendPingback(*data_, data_reduction_proxy_timing); |
147 } | 152 } |
148 | 153 |
149 void DataReductionProxyMetricsObserver::OnDomContentLoadedEventStart( | 154 void DataReductionProxyMetricsObserver::OnDomContentLoadedEventStart( |
150 const page_load_metrics::PageLoadTiming& timing, | 155 const page_load_metrics::PageLoadTiming& timing, |
151 const page_load_metrics::PageLoadExtraInfo& info) { | 156 const page_load_metrics::PageLoadExtraInfo& info) { |
152 RECORD_HISTOGRAMS_FOR_SUFFIX( | 157 RECORD_HISTOGRAMS_FOR_SUFFIX( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 | 210 |
206 DataReductionProxyPingbackClient* | 211 DataReductionProxyPingbackClient* |
207 DataReductionProxyMetricsObserver::GetPingbackClient() const { | 212 DataReductionProxyMetricsObserver::GetPingbackClient() const { |
208 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 213 return DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
209 browser_context_) | 214 browser_context_) |
210 ->data_reduction_proxy_service() | 215 ->data_reduction_proxy_service() |
211 ->pingback_client(); | 216 ->pingback_client(); |
212 } | 217 } |
213 | 218 |
214 } // namespace data_reduction_proxy | 219 } // namespace data_reduction_proxy |
OLD | NEW |