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 #include "chrome/browser/resource_coordinator/tab_manager_features.h"
6
7 #include "base/metrics/field_trial_params.h"
8 #include "base/numerics/ranges.h"
9 #include "chrome/common/chrome_features.h"
10
11 namespace {
12
13 constexpr char kTabLoadTimeoutInMsParameterName[] = "tabLoadTimeoutInMs";
14
15 } // namespace
16
17 namespace features {
18
19 // Enables using customized value for tab load timeout. This is used by both
20 // staggered background tab opening and session restore in finch experiment to
21 // see what timeout value is better. The default timeout is used when this
22 // feature is disabled.
23 const base::Feature kCustomizedTabLoadTimeout{
24 "CustomizedTabLoadTimeout", base::FEATURE_DISABLED_BY_DEFAULT};
25
26 // Enables delaying the navigation of background tabs in order to improve
27 // foreground tab's user experience.
28 const base::Feature kStaggeredBackgroundTabOpening{
29 "StaggeredBackgroundTabOpening", base::FEATURE_DISABLED_BY_DEFAULT};
30
31 // This controls whether we are running experiment with staggered background
32 // tab opening feature. For control group, this should be disabled. This depends
33 // on |kStaggeredBackgroundTabOpening| above.
34 const base::Feature kStaggeredBackgroundTabOpeningExperiment{
35 "StaggeredBackgroundTabOpeningExperiment",
36 base::FEATURE_ENABLED_BY_DEFAULT};
37
38 // Enables using the Tab Ranker to score tabs for discarding instead of relying
39 // on last focused time.
40 const base::Feature kTabRanker{"TabRanker", base::FEATURE_DISABLED_BY_DEFAULT};
41
42 } // namespace features
43
44 namespace resource_coordinator {
45
GetTabLoadTimeout(const base::TimeDelta & default_timeout)46 base::TimeDelta GetTabLoadTimeout(const base::TimeDelta& default_timeout) {
47 int timeout_in_ms = base::GetFieldTrialParamByFeatureAsInt(
48 features::kCustomizedTabLoadTimeout, kTabLoadTimeoutInMsParameterName,
49 default_timeout.InMilliseconds());
50
51 if (timeout_in_ms <= 0)
52 return default_timeout;
53
54 return base::TimeDelta::FromMilliseconds(timeout_in_ms);
55 }
56
GetNumOldestTabsToScoreWithTabRanker()57 int GetNumOldestTabsToScoreWithTabRanker() {
58 return base::GetFieldTrialParamByFeatureAsInt(
59 features::kTabRanker, "number_of_oldest_tabs_to_score_with_TabRanker",
60 50);
61 }
62
GetProcessTypeToScoreWithTabRanker()63 int GetProcessTypeToScoreWithTabRanker() {
64 return base::GetFieldTrialParamByFeatureAsInt(
65 features::kTabRanker, "process_type_of_tabs_to_score_with_TabRanker", 3);
66 }
67
GetNumOldestTabsToLogWithTabRanker()68 int GetNumOldestTabsToLogWithTabRanker() {
69 return base::GetFieldTrialParamByFeatureAsInt(
70 features::kTabRanker, "number_of_oldest_tabs_to_log_with_TabRanker", 0);
71 }
72
DisableBackgroundLogWithTabRanker()73 bool DisableBackgroundLogWithTabRanker() {
74 return base::GetFieldTrialParamByFeatureAsBool(
75 features::kTabRanker, "disable_background_log_with_TabRanker", true);
76 }
77
GetDiscardCountPenaltyTabRanker()78 float GetDiscardCountPenaltyTabRanker() {
79 return static_cast<float>(base::GetFieldTrialParamByFeatureAsDouble(
80 features::kTabRanker, "discard_count_penalty", 0.0));
81 }
82
GetMRUScorerPenaltyTabRanker()83 float GetMRUScorerPenaltyTabRanker() {
84 return static_cast<float>(base::GetFieldTrialParamByFeatureAsDouble(
85 features::kTabRanker, "mru_scorer_penalty", 1.0));
86 }
87
GetScorerTypeForTabRanker()88 int GetScorerTypeForTabRanker() {
89 return base::GetFieldTrialParamByFeatureAsInt(features::kTabRanker,
90 "scorer_type", 1);
91 }
92
93 } // namespace resource_coordinator
94