1 // Copyright (c) 2012 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.
5 #include "content/browser/android/content_startup_flags.h"
7 #include "base/android/build_info.h"
8 #include "base/base_switches.h"
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/sys_info.h"
13 #include "cc/base/switches.h"
14 #include "cc/trees/layer_tree_settings.h"
15 #include "content/public/browser/android/compositor.h"
16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/common/content_constants.h"
18 #include "content/public/common/content_switches.h"
19 #include "gpu/command_buffer/service/gpu_switches.h"
20 #include "ui/base/ui_base_switches.h"
21 #include "ui/native_theme/native_theme_switches.h"
25 void SetContentCommandLineFlags(bool single_process
,
26 const std::string
& plugin_descriptor
) {
27 // May be called multiple times, to cover all possible program entry points.
28 static bool already_initialized
= false;
29 if (already_initialized
)
31 already_initialized
= true;
33 base::CommandLine
* parsed_command_line
=
34 base::CommandLine::ForCurrentProcess();
36 int command_line_renderer_limit
= -1;
37 if (parsed_command_line
->HasSwitch(switches::kRendererProcessLimit
)) {
38 std::string limit
= parsed_command_line
->GetSwitchValueASCII(
39 switches::kRendererProcessLimit
);
41 if (base::StringToInt(limit
, &value
)) {
42 command_line_renderer_limit
= std::max(0, value
);
46 if (command_line_renderer_limit
> 0) {
47 int limit
= std::min(command_line_renderer_limit
,
48 static_cast<int>(kMaxRendererProcessCount
));
49 RenderProcessHost::SetMaxRendererProcessCount(limit
);
52 if (single_process
|| command_line_renderer_limit
== 0) {
53 // Need to ensure the command line flag is consistent as a lot of chrome
54 // internal code checks this directly, but it wouldn't normally get set when
55 // we are implementing an embedded WebView.
56 parsed_command_line
->AppendSwitch(switches::kSingleProcess
);
59 parsed_command_line
->AppendSwitch(cc::switches::kEnableBeginFrameScheduling
);
61 parsed_command_line
->AppendSwitch(switches::kEnablePinch
);
62 parsed_command_line
->AppendSwitch(switches::kEnableOverlayScrollbar
);
63 parsed_command_line
->AppendSwitch(switches::kValidateInputEventStream
);
65 // TODO(jdduke): Use the proper SDK version when available, crbug.com/466749.
66 if (base::android::BuildInfo::GetInstance()->sdk_int() >
67 base::android::SDK_VERSION_LOLLIPOP_MR1
) {
68 parsed_command_line
->AppendSwitch(switches::kEnableLongpressDragSelection
);
69 parsed_command_line
->AppendSwitchASCII(
70 switches::kTouchTextSelectionStrategy
, "direction");
73 // There is no software fallback on Android, so don't limit GPU crashes.
74 parsed_command_line
->AppendSwitch(switches::kDisableGpuProcessCrashLimit
);
76 // On legacy low-memory devices the behavior has not been studied with regard
77 // to having an extra process with similar priority as the foreground renderer
78 // and given that the system will often be looking for a process to be killed
80 if (base::SysInfo::IsLowEndDevice())
81 parsed_command_line
->AppendSwitch(switches::kInProcessGPU
);
83 parsed_command_line
->AppendSwitch(
84 switches::kMainFrameResizesAreOrientationChanges
);
86 // Disable anti-aliasing.
87 parsed_command_line
->AppendSwitch(
88 cc::switches::kDisableCompositedAntialiasing
);
90 parsed_command_line
->AppendSwitch(switches::kUIPrioritizeInGpuProcess
);
92 parsed_command_line
->AppendSwitch(switches::kEnableDelegatedRenderer
);
94 if (!plugin_descriptor
.empty()) {
95 parsed_command_line
->AppendSwitchNative(
96 switches::kRegisterPepperPlugins
, plugin_descriptor
);
99 // Disable profiler timing by default.
100 if (!parsed_command_line
->HasSwitch(switches::kProfilerTiming
)) {
101 parsed_command_line
->AppendSwitchASCII(
102 switches::kProfilerTiming
, switches::kProfilerTimingDisabledValue
);
105 cc::LayerSettings layer_settings
;
106 if (parsed_command_line
->HasSwitch(
107 switches::kEnableAndroidCompositorAnimationTimelines
))
108 layer_settings
.use_compositor_animation_timelines
= true;
109 Compositor::SetLayerSettings(layer_settings
);
112 } // namespace content