• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_epoll.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 // Activate base::FeatureParamWithCache internal cache.
37 // TODO(https://crbug.com/340824113): Remove the feature flag below.
38 BASE_FEATURE(kFeatureParamWithCache,
39              "FeatureParamWithCache",
40              FEATURE_ENABLED_BY_DEFAULT);
41 
42 // Use the Rust JSON parser. Enabled everywhere except Android, where the switch
43 // from using the C++ parser in-thread to using the Rust parser in a thread-pool
44 // introduces too much latency.
45 BASE_FEATURE(kUseRustJsonParser,
46              "UseRustJsonParser",
47 #if BUILDFLAG(IS_ANDROID)
48              FEATURE_DISABLED_BY_DEFAULT
49 #else
50              FEATURE_ENABLED_BY_DEFAULT
51 #endif  // BUILDFLAG(IS_ANDROID)
52 );
53 
54 // If true, use the Rust JSON parser in-thread; otherwise, it runs in a thread
55 // pool.
56 const base::FeatureParam<bool> kUseRustJsonParserInCurrentSequence{
57     &kUseRustJsonParser, "UseRustJsonParserInCurrentSequence", false};
58 
59 // Use non default low memory device threshold.
60 // Value should be given via |LowMemoryDeviceThresholdMB|.
61 #if BUILDFLAG(IS_IOS)
62 // For M99, 45% of devices have 2GB of RAM, and 55% have more.
63 #define LOW_MEMORY_DEVICE_THRESHOLD_MB 1024
64 #else
65 // Updated Desktop default threshold to match the Android 2021 definition.
66 #define LOW_MEMORY_DEVICE_THRESHOLD_MB 2048
67 #endif
68 BASE_FEATURE(kLowEndMemoryExperiment,
69              "LowEndMemoryExperiment",
70              FEATURE_DISABLED_BY_DEFAULT);
71 const base::FeatureParam<int> kLowMemoryDeviceThresholdMB{
72     &kLowEndMemoryExperiment, "LowMemoryDeviceThresholdMB",
73     LOW_MEMORY_DEVICE_THRESHOLD_MB};
74 
75 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
76 // Force to enable LowEndDeviceMode partially on Android 3Gb devices.
77 // (see PartialLowEndModeOnMidRangeDevices below)
78 BASE_FEATURE(kPartialLowEndModeOn3GbDevices,
79              "PartialLowEndModeOn3GbDevices",
80              FEATURE_DISABLED_BY_DEFAULT);
81 
82 // Used to enable LowEndDeviceMode partially on Android and ChromeOS mid-range
83 // devices. Such devices aren't considered low-end, but we'd like experiment
84 // with a subset of low-end features to see if we get a good memory vs.
85 // performance tradeoff.
86 //
87 // TODO(crbug.com/40264947): |#if| out 32-bit before launching or going to
88 // high Stable %, because we will enable the feature only for <8GB 64-bit
89 // devices, where we didn't ship yet. However, we first need a larger
90 // population to collect data.
91 BASE_FEATURE(kPartialLowEndModeOnMidRangeDevices,
92              "PartialLowEndModeOnMidRangeDevices",
93 #if BUILDFLAG(IS_ANDROID)
94              FEATURE_ENABLED_BY_DEFAULT);
95 #elif BUILDFLAG(IS_CHROMEOS)
96              FEATURE_DISABLED_BY_DEFAULT);
97 #endif
98 
99 #endif  // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
100 
101 #if BUILDFLAG(IS_ANDROID)
102 // Whether to report frame metrics to the Android.FrameTimeline.* histograms.
103 BASE_FEATURE(kCollectAndroidFrameTimelineMetrics,
104              "CollectAndroidFrameTimelineMetrics",
105              FEATURE_DISABLED_BY_DEFAULT);
106 
107 // If enabled, post registering PowerMonitor broadcast receiver to a background
108 // thread,
109 BASE_FEATURE(kPostPowerMonitorBroadcastReceiverInitToBackground,
110              "PostPowerMonitorBroadcastReceiverInitToBackground",
111              FEATURE_ENABLED_BY_DEFAULT);
112 // If enabled, getMyMemoryState IPC will be posted to background.
113 BASE_FEATURE(kPostGetMyMemoryStateToBackground,
114              "PostGetMyMemoryStateToBackground",
115              FEATURE_ENABLED_BY_DEFAULT);
116 #endif  // BUILDFLAG(IS_ANDROID)
117 
Init(EmitThreadControllerProfilerMetadata emit_thread_controller_profiler_metadata)118 void Init(EmitThreadControllerProfilerMetadata
119               emit_thread_controller_profiler_metadata) {
120   InitializeCpuReductionExperiment();
121   sequence_manager::internal::SequenceManagerImpl::InitializeFeatures();
122   sequence_manager::internal::ThreadController::InitializeFeatures(
123       emit_thread_controller_profiler_metadata);
124 
125 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
126   MessagePumpEpoll::InitializeFeatures();
127 #endif
128 
129 #if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_CHROMEOS)
130   PlatformThread::InitializeFeatures();
131 #endif
132 
133 #if BUILDFLAG(IS_APPLE)
134   ConditionVariable::InitializeFeatures();
135   File::InitializeFeatures();
136   MessagePumpCFRunLoopBase::InitializeFeatures();
137   MessagePumpKqueue::InitializeFeatures();
138 #endif
139 
140 #if BUILDFLAG(IS_ANDROID)
141   android::InputHintChecker::InitializeFeatures();
142 #endif
143 
144 #if BUILDFLAG(IS_WIN)
145   sequence_manager::internal::ThreadControllerPowerMonitor::
146       InitializeFeatures();
147   InitializePlatformThreadFeatures();
148 #endif
149 }
150 
151 }  // namespace base::features
152