OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_EXPERIMENTS_DELAY_NAVIGATION_THROTTLE_H
_ |
| 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_EXPERIMENTS_DELAY_NAVIGATION_THROTTLE_H
_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/feature_list.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/task_runner.h" |
| 15 #include "base/time/time.h" |
| 16 #include "content/public/browser/navigation_throttle.h" |
| 17 |
| 18 // This feature controls whether the DelayNavigationThrottle should be |
| 19 // instantiated. |
| 20 extern const base::Feature kDelayNavigationFeature; |
| 21 |
| 22 // DelayNavigationThrottle introduces a delay to main frame navigations. |
| 23 class DelayNavigationThrottle : public content::NavigationThrottle { |
| 24 public: |
| 25 // The duration of the delay to add to the start of each navigation, in |
| 26 // milliseconds. |
| 27 static const char kParamDelayNavigationDurationMillis[]; |
| 28 |
| 29 // The probability that the navigation delay should be introduced. Should be a |
| 30 // double in the interval [0, 1], where a value of 0 indicates the delay |
| 31 // should never be introduced, and a value of 1 indicates the delay should |
| 32 // always be introduced. |
| 33 static const char kParamDelayNavigationProbability[]; |
| 34 |
| 35 // Creates a DelayNavigationThrottle if the DelayNavigation feature is |
| 36 // enabled and configured. |
| 37 static std::unique_ptr<content::NavigationThrottle> MaybeCreateThrottleFor( |
| 38 content::NavigationHandle* handle); |
| 39 |
| 40 // Creates a DelayNavigationThrottle directly. Only intended for use in |
| 41 // tests. Production code should use MaybeCreateThrottleFor. |
| 42 DelayNavigationThrottle(content::NavigationHandle* handle, |
| 43 scoped_refptr<base::TaskRunner> task_runner, |
| 44 base::TimeDelta navigation_delay); |
| 45 ~DelayNavigationThrottle() override; |
| 46 |
| 47 // content::NavigationThrottle: |
| 48 content::NavigationThrottle::ThrottleCheckResult WillStartRequest() override; |
| 49 |
| 50 private: |
| 51 void OnDelayComplete(); |
| 52 |
| 53 const scoped_refptr<base::TaskRunner> task_runner_; |
| 54 const base::TimeDelta navigation_delay_; |
| 55 |
| 56 // This has to be the last member of the class. |
| 57 base::WeakPtrFactory<DelayNavigationThrottle> weak_ptr_factory_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(DelayNavigationThrottle); |
| 60 }; |
| 61 |
| 62 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_EXPERIMENTS_DELAY_NAVIGATION_THROTTL
E_H_ |
OLD | NEW |