1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/common/content_navigation_policy.h"
#include <bitset>
#include "base/metrics/field_trial_params.h"
#include "base/system/sys_info.h"
#include "content/public/common/content_features.h"
namespace content {
bool DeviceHasEnoughMemoryForBackForwardCache() {
// This method make sure that the physical memory of device is greater than
// the allowed threshold and enables back-forward cache if the feature
// kBackForwardCacheMemoryControl is enabled.
// It is important to check the base::FeatureList to avoid activating any
// field trial groups if BFCache is disabled due to memory threshold.
if (base::FeatureList::IsEnabled(features::kBackForwardCacheMemoryControl)) {
int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt(
features::kBackForwardCacheMemoryControl,
"memory_threshold_for_back_forward_cache_in_mb", 0);
return base::SysInfo::AmountOfPhysicalMemoryMB() > memory_threshold_mb;
}
// If the feature kBackForwardCacheMemoryControl is not enabled, all the
// devices are included by default.
return true;
}
bool IsBackForwardCacheEnabled() {
if (!DeviceHasEnoughMemoryForBackForwardCache())
return false;
// The feature needs to be checked last, because checking the feature
// activates the field trial and assigns the client either to a control or an
// experiment group - such assignment should be final.
return base::FeatureList::IsEnabled(features::kBackForwardCache);
}
const char kProactivelySwapBrowsingInstanceLevelParameterName[] = "level";
constexpr base::FeatureParam<ProactivelySwapBrowsingInstanceLevel>::Option
proactively_swap_browsing_instance_levels[] = {
{ProactivelySwapBrowsingInstanceLevel::kDisabled, "Disabled"},
{ProactivelySwapBrowsingInstanceLevel::kCrossSiteSwapProcess,
"CrossSiteSwapProcess"},
{ProactivelySwapBrowsingInstanceLevel::kCrossSiteReuseProcess,
"CrossSiteReuseProcess"},
{ProactivelySwapBrowsingInstanceLevel::kSameSite, "SameSite"}};
const base::FeatureParam<ProactivelySwapBrowsingInstanceLevel>
proactively_swap_browsing_instance_level{
&features::kProactivelySwapBrowsingInstance,
kProactivelySwapBrowsingInstanceLevelParameterName,
ProactivelySwapBrowsingInstanceLevel::kDisabled,
&proactively_swap_browsing_instance_levels};
std::string GetProactivelySwapBrowsingInstanceLevelName(
ProactivelySwapBrowsingInstanceLevel level) {
return proactively_swap_browsing_instance_level.GetName(level);
}
std::array<std::string,
static_cast<size_t>(ProactivelySwapBrowsingInstanceLevel::kMaxValue)>
ProactivelySwapBrowsingInstanceFeatureEnabledLevelValues() {
return {
GetProactivelySwapBrowsingInstanceLevelName(
ProactivelySwapBrowsingInstanceLevel::kCrossSiteSwapProcess),
GetProactivelySwapBrowsingInstanceLevelName(
ProactivelySwapBrowsingInstanceLevel::kCrossSiteReuseProcess),
GetProactivelySwapBrowsingInstanceLevelName(
ProactivelySwapBrowsingInstanceLevel::kSameSite),
};
}
ProactivelySwapBrowsingInstanceLevel GetProactivelySwapBrowsingInstanceLevel() {
if (base::FeatureList::IsEnabled(features::kProactivelySwapBrowsingInstance))
return proactively_swap_browsing_instance_level.Get();
return ProactivelySwapBrowsingInstanceLevel::kDisabled;
}
bool IsProactivelySwapBrowsingInstanceEnabled() {
return GetProactivelySwapBrowsingInstanceLevel() >=
ProactivelySwapBrowsingInstanceLevel::kCrossSiteSwapProcess;
}
bool IsProactivelySwapBrowsingInstanceWithProcessReuseEnabled() {
return GetProactivelySwapBrowsingInstanceLevel() >=
ProactivelySwapBrowsingInstanceLevel::kCrossSiteReuseProcess;
}
bool IsProactivelySwapBrowsingInstanceOnSameSiteNavigationEnabled() {
return GetProactivelySwapBrowsingInstanceLevel() >=
ProactivelySwapBrowsingInstanceLevel::kSameSite;
}
const char kRenderDocumentLevelParameterName[] = "level";
constexpr base::FeatureParam<RenderDocumentLevel>::Option
render_document_levels[] = {
{RenderDocumentLevel::kDisabled, "disabled"},
{RenderDocumentLevel::kCrashedFrame, "crashed-frame"},
{RenderDocumentLevel::kSubframe, "subframe"}};
const base::FeatureParam<RenderDocumentLevel> render_document_level{
&features::kRenderDocument, kRenderDocumentLevelParameterName,
RenderDocumentLevel::kDisabled, &render_document_levels};
RenderDocumentLevel GetRenderDocumentLevel() {
if (base::FeatureList::IsEnabled(features::kRenderDocument))
return render_document_level.Get();
return RenderDocumentLevel::kDisabled;
}
std::string GetRenderDocumentLevelName(RenderDocumentLevel level) {
return render_document_level.GetName(level);
}
bool CreateNewHostForSameSiteSubframe() {
return GetRenderDocumentLevel() >= RenderDocumentLevel::kSubframe;
}
} // namespace content
|