1 // Copyright 2022 The Chromium Authors
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 "base/features.h"
6
7 #include "base/cpu_reduction_experiment.h"
8 #include "base/task/sequence_manager/sequence_manager_impl.h"
9 #include "base/threading/platform_thread.h"
10 #include "build/buildflag.h"
11
12 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
13 #include "base/message_loop/message_pump_libevent.h"
14 #endif
15
16 #if BUILDFLAG(IS_APPLE)
17 #include "base/files/file.h"
18 #include "base/message_loop/message_pump_apple.h"
19 #include "base/message_loop/message_pump_kqueue.h"
20 #include "base/synchronization/condition_variable.h"
21 #endif
22
23 #if BUILDFLAG(IS_ANDROID)
24 #include "base/android/input_hint_checker.h"
25 #endif
26
27 #if BUILDFLAG(IS_WIN)
28 #include "base/task/sequence_manager/thread_controller_power_monitor.h"
29 #include "base/threading/platform_thread_win.h"
30 #endif
31
32 namespace base::features {
33
34 // Alphabetical:
35
36 // Enforce that writeable file handles passed to untrusted processes are not
37 // backed by executable files.
38 BASE_FEATURE(kEnforceNoExecutableFileHandles,
39 "EnforceNoExecutableFileHandles",
40 FEATURE_ENABLED_BY_DEFAULT);
41
42 // TODO(crbug.com/851128): Roll out this to 100% before replacing existing
43 // NOTREACHED()s with NOTREACHED_NORETURN() as part of NOTREACHED() migration.
44 // Note that a prerequisite for rolling out this experiment is that existing
45 // NOTREACHED reports are at a very low rate. Once this rolls out we should
46 // monitor that crash rates for the experiment population is within a 1-5% or
47 // lower than the control group.
48 BASE_FEATURE(kNotReachedIsFatal,
49 "NotReachedIsFatal",
50 FEATURE_DISABLED_BY_DEFAULT);
51
52 // Optimizes parsing and loading of data: URLs.
53 BASE_FEATURE(kOptimizeDataUrls, "OptimizeDataUrls", FEATURE_ENABLED_BY_DEFAULT);
54
55 BASE_FEATURE(kUseRustJsonParser,
56 "UseRustJsonParser",
57 FEATURE_DISABLED_BY_DEFAULT);
58
59 BASE_FEATURE(kJsonNegativeZero, "JsonNegativeZero", FEATURE_ENABLED_BY_DEFAULT);
60
61 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
62 // Force to enable LowEndDeviceMode partially on Android 3Gb devices.
63 // (see PartialLowEndModeOnMidRangeDevices below)
64 BASE_FEATURE(kPartialLowEndModeOn3GbDevices,
65 "PartialLowEndModeOn3GbDevices",
66 FEATURE_DISABLED_BY_DEFAULT);
67
68 // Used to enable LowEndDeviceMode partially on Android and ChromeOS mid-range
69 // devices. Such devices aren't considered low-end, but we'd like experiment
70 // with a subset of low-end features to see if we get a good memory vs.
71 // performance tradeoff.
72 //
73 // TODO(crbug.com/1434873): |#if| out 32-bit before launching or going to
74 // high Stable %, because we will enable the feature only for <8GB 64-bit
75 // devices, where we didn't ship yet. However, we first need a larger
76 // population to collect data.
77 BASE_FEATURE(kPartialLowEndModeOnMidRangeDevices,
78 "PartialLowEndModeOnMidRangeDevices",
79 #if BUILDFLAG(IS_ANDROID)
80 FEATURE_ENABLED_BY_DEFAULT);
81 #elif BUILDFLAG(IS_CHROMEOS)
82 FEATURE_DISABLED_BY_DEFAULT);
83 #endif
84
85 #endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
86
87 #if BUILDFLAG(IS_ANDROID)
88 // Whether to report frame metrics to the Android.FrameTimeline.* histograms.
89 BASE_FEATURE(kCollectAndroidFrameTimelineMetrics,
90 "CollectAndroidFrameTimelineMetrics",
91 FEATURE_DISABLED_BY_DEFAULT);
92 #endif // BUILDFLAG(IS_ANDROID)
93
Init(EmitThreadControllerProfilerMetadata emit_thread_controller_profiler_metadata)94 void Init(EmitThreadControllerProfilerMetadata
95 emit_thread_controller_profiler_metadata) {
96 InitializeCpuReductionExperiment();
97 sequence_manager::internal::SequenceManagerImpl::InitializeFeatures();
98 sequence_manager::internal::ThreadController::InitializeFeatures(
99 emit_thread_controller_profiler_metadata);
100
101 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
102 MessagePumpLibevent::InitializeFeatures();
103 #endif
104
105 #if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_CHROMEOS)
106 PlatformThread::InitializeFeatures();
107 #endif
108
109 #if BUILDFLAG(IS_APPLE)
110 ConditionVariable::InitializeFeatures();
111 File::InitializeFeatures();
112 MessagePumpCFRunLoopBase::InitializeFeatures();
113 MessagePumpKqueue::InitializeFeatures();
114 #endif
115
116 #if BUILDFLAG(IS_ANDROID)
117 android::InputHintChecker::InitializeFeatures();
118 #endif
119
120 #if BUILDFLAG(IS_WIN)
121 sequence_manager::internal::ThreadControllerPowerMonitor::
122 InitializeFeatures();
123 InitializePlatformThreadFeatures();
124 #endif
125 }
126
127 } // namespace base::features
128