Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/page_load_metrics/experiments/delay_navigation_throttle.h

Issue 2763613002: Add DelayNavigationThrottle (Closed)
Patch Set: add dchecks Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // Whether the delay should be randomized in the interval 0ms and
30 // kParamDelayNavigationDurationMillis.
31 static const char kParamDelayNavigationRandomize[];
32
33 // The probability that the navigation delay should be introduced. Should be a
34 // double in the interval [0, 1], where a value of 0 indicates the delay
35 // should never be introduced, and a value of 1 indicates the delay should
36 // always be introduced.
37 static const char kParamDelayNavigationProbability[];
38
39 // Creates a DelayNavigationThrottle if the DelayNavigation feature is
40 // enabled and configured.
41 static std::unique_ptr<DelayNavigationThrottle> MaybeCreateThrottleFor(
42 content::NavigationHandle* handle);
43
44 // Creates a DelayNavigationThrottle directly. Only intended for use in
45 // tests. Production code should use MaybeCreateThrottleFor.
46 DelayNavigationThrottle(content::NavigationHandle* handle,
47 scoped_refptr<base::TaskRunner> task_runner,
48 base::TimeDelta navigation_delay);
49 ~DelayNavigationThrottle() override;
50
51 // Return the navigation delay for this throttle.
52 base::TimeDelta navigation_delay() const { return navigation_delay_; }
53
54 // content::NavigationThrottle:
55 content::NavigationThrottle::ThrottleCheckResult WillStartRequest() override;
56
57 private:
58 void OnDelayComplete();
59
60 const scoped_refptr<base::TaskRunner> task_runner_;
61 const base::TimeDelta navigation_delay_;
62
63 // This has to be the last member of the class.
64 base::WeakPtrFactory<DelayNavigationThrottle> weak_ptr_factory_;
65
66 DISALLOW_COPY_AND_ASSIGN(DelayNavigationThrottle);
67 };
68
69 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_EXPERIMENTS_DELAY_NAVIGATION_THROTTL E_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698