OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/experiments/delay_navigation_throttle .h" | 5 #include "chrome/browser/page_load_metrics/experiments/delay_navigation_throttle .h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/field_trial_params.h" | 8 #include "base/metrics/field_trial_params.h" |
9 #include "base/metrics/histogram_macros.h" | |
9 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/search/search.h" | 13 #include "chrome/browser/search/search.h" |
13 #include "content/public/browser/navigation_handle.h" | 14 #include "content/public/browser/navigation_handle.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
19 const char kHistogramNavigationDelaySpecified[] = | |
20 "DelayNavigationThrottle.Delay.Specified"; | |
21 const char kHistogramNavigationDelayActual[] = | |
22 "DelayNavigationThrottle.Delay.Actual"; | |
23 const char kHistogramNavigationDelayDelta[] = | |
24 "DelayNavigationThrottle.Delay.Delta"; | |
25 | |
18 base::TimeDelta GetNavigationDelayFromParams() { | 26 base::TimeDelta GetNavigationDelayFromParams() { |
19 double delay_probability = base::GetFieldTrialParamByFeatureAsDouble( | 27 double delay_probability = base::GetFieldTrialParamByFeatureAsDouble( |
20 kDelayNavigationFeature, | 28 kDelayNavigationFeature, |
21 DelayNavigationThrottle::kParamDelayNavigationProbability, | 29 DelayNavigationThrottle::kParamDelayNavigationProbability, |
22 0 /* default value */); | 30 0 /* default value */); |
23 | 31 |
24 DCHECK_GE(delay_probability, 0.0); | 32 DCHECK_GE(delay_probability, 0.0); |
25 DCHECK_LE(delay_probability, 1.0); | 33 DCHECK_LE(delay_probability, 1.0); |
26 if (delay_probability == 0 || delay_probability < base::RandDouble()) | 34 if (delay_probability == 0 || delay_probability < base::RandDouble()) |
27 return base::TimeDelta(); | 35 return base::TimeDelta(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 base::TimeDelta navigation_delay) | 101 base::TimeDelta navigation_delay) |
94 : content::NavigationThrottle(handle), | 102 : content::NavigationThrottle(handle), |
95 task_runner_(task_runner), | 103 task_runner_(task_runner), |
96 navigation_delay_(navigation_delay), | 104 navigation_delay_(navigation_delay), |
97 weak_ptr_factory_(this) {} | 105 weak_ptr_factory_(this) {} |
98 | 106 |
99 DelayNavigationThrottle::~DelayNavigationThrottle() {} | 107 DelayNavigationThrottle::~DelayNavigationThrottle() {} |
100 | 108 |
101 content::NavigationThrottle::ThrottleCheckResult | 109 content::NavigationThrottle::ThrottleCheckResult |
102 DelayNavigationThrottle::WillStartRequest() { | 110 DelayNavigationThrottle::WillStartRequest() { |
111 UMA_HISTOGRAM_TIMES(kHistogramNavigationDelaySpecified, navigation_delay_); | |
112 delay_start_time_ = base::TimeTicks::Now(); | |
103 task_runner_->PostDelayedTask( | 113 task_runner_->PostDelayedTask( |
104 FROM_HERE, | 114 FROM_HERE, |
105 base::Bind(&DelayNavigationThrottle::OnDelayComplete, | 115 base::Bind(&DelayNavigationThrottle::OnDelayComplete, |
106 weak_ptr_factory_.GetWeakPtr()), | 116 weak_ptr_factory_.GetWeakPtr()), |
107 navigation_delay_); | 117 navigation_delay_); |
108 return content::NavigationThrottle::DEFER; | 118 return content::NavigationThrottle::DEFER; |
109 } | 119 } |
110 | 120 |
111 void DelayNavigationThrottle::OnDelayComplete() { | 121 void DelayNavigationThrottle::OnDelayComplete() { |
122 base::TimeDelta actual_delay = base::TimeTicks::Now() - delay_start_time_; | |
123 base::TimeDelta delay_delta = actual_delay - navigation_delay_; | |
124 UMA_HISTOGRAM_TIMES(kHistogramNavigationDelayActual, actual_delay); | |
125 UMA_HISTOGRAM_TIMES(kHistogramNavigationDelayDelta, delay_delta.magnitude()); | |
Charlie Harrison
2017/04/05 16:54:37
if actual_delay < navigation_delay_ this could be
Bryan McQuade
2017/04/05 20:11:05
copying the relevant part of my general reply here
| |
112 navigation_handle()->Resume(); | 126 navigation_handle()->Resume(); |
113 } | 127 } |
OLD | NEW |