[WebView] Lower the warm-up renderer's priority after a delay

To prevent spare renderer process from lingering indefinitely and
leaking memory if the host app never creates a WebView, this CL add a
timeout to lower the priority of the connection from VISIBLE to WAIVED.

This CL adds the WebViewLowerWarmUpProcessPriority feature. When
enabled, the warm-up process is lowered to WAIVED if no launch has
consumed it after lower_priority_delay_ms (a negative value disables
lowering), so the OS can reclaim it. Apps that create a WebView soon
after startup keep the warm-up's benefit. The binding is only lowered
while the connection is unused.

New metrics, to evaluate the trade-off. Deaths only count when the
browser didn't cause them (a crash or the OS killing the process), using
a new ChildProcessConnection.isServiceDisconnected():
- Android.SpareChildConnection.LifecycleEvent: created, consumed,
  priority lowered, died unused (e.g. reclaimed by the OS), or died
  while the launch that consumed it was still in progress (launch
  failure).
- Android.SpareChildConnection.LoweredStatus: whether the connection was
  consumed, or died unused, before or after it was lowered. Helps tune
  the delay.
- Android.SpareChildConnection.AliveWhenRequested: whether the
  connection was still alive when a launch could have used it.
- Android.SpareChildConnection.TimeFromConsumedToDeath: deaths shortly
  after the connection is consumed, i.e. before the raised binding took
  effect, which would show up as unexpected renderer termination.

Bug: 424423704
Change-Id: I0284a6262caa4ddd718917e1958d14317a6fb212
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8139189
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Michael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Chidera Olibie <colibie@google.com>
Cr-Commit-Position: refs/heads/main@{#1755622}
NOKEYCHECK=True
GitOrigin-RevId: 614add7cd9e911d646929c4a7bff867a50811800
2 files changed
tree: 04e3ee9dcd478ed580802e2489ae931e6f04963c
  1. allocator/
  2. android/
  3. apple/
  4. containers/
  5. debug/
  6. feature/
  7. files/
  8. fuchsia/
  9. functional/
  10. hash/
  11. i18n/
  12. ios/
  13. json/
  14. logging/
  15. mac/
  16. macros/
  17. memory/
  18. memory_coordinator/
  19. message_loop/
  20. metrics/
  21. nix/
  22. numerics/
  23. posix/
  24. power_monitor/
  25. process/
  26. profiler/
  27. sampling_heap_profiler/
  28. strings/
  29. substring_set_matcher/
  30. synchronization/
  31. system/
  32. task/
  33. test/
  34. third_party/
  35. threading/
  36. time/
  37. timer/
  38. tools/
  39. trace_event/
  40. tracing/
  41. types/
  42. version_info/
  43. win/
  44. .ruff.toml
  45. at_exit.cc
  46. at_exit.h
  47. at_exit_unittest.cc
  48. atomic_ref_count.h
  49. atomic_sequence_num.h
  50. atomicops.cc
  51. atomicops.h
  52. atomicops_internals_portable.h
  53. atomicops_unittest.cc
  54. auto_reset.h
  55. auto_reset_unittest.cc
  56. barrier_callback.h
  57. barrier_callback_unittest.cc
  58. barrier_closure.cc
  59. barrier_closure.h
  60. barrier_closure_unittest.cc
  61. base64.cc
  62. base64.h
  63. base64_decode_fuzzer.cc
  64. base64_encode_fuzzer.cc
  65. base64_perftest.cc
  66. base64_rust_shim.rs
  67. base64_unittest.cc
  68. base64url.cc
  69. base64url.h
  70. base64url_unittest.cc
  71. base_export.h
  72. base_paths.cc
  73. base_paths.h
  74. base_paths_android.cc
  75. base_paths_android.h
  76. base_paths_apple.cc
  77. base_paths_apple.h
  78. base_paths_fuchsia.cc
  79. base_paths_ios.h
  80. base_paths_ios.mm
  81. base_paths_mac.h
  82. base_paths_mac.mm
  83. base_paths_posix.cc
  84. base_paths_posix.h
  85. base_paths_win.cc
  86. base_paths_win.h
  87. base_rust_unittests.rs
  88. base_switches.h
  89. bit_cast.h
  90. bit_cast_unittest.cc
  91. bits.h
  92. bits_unittest.cc
  93. BUILD.gn
  94. build_time.h
  95. build_time_unittest.cc
  96. byte_conversions_perftest.cc
  97. byte_size.cc
  98. byte_size.h
  99. byte_size_nocompile.nc
  100. byte_size_unittest.cc
  101. callback_list.cc
  102. callback_list.h
  103. callback_list_nocompile.nc
  104. callback_list_unittest.cc
  105. cancelable_callback.h
  106. cancelable_callback_unittest.cc
  107. check.cc
  108. check.h
  109. check_deref.h
  110. check_deref_nocompile.nc
  111. check_deref_unittest.cc
  112. check_example.cc
  113. check_is_test.cc
  114. check_is_test.h
  115. check_is_test_unittest.cc
  116. check_nocompile.nc
  117. check_op.cc
  118. check_op.h
  119. check_unittest.cc
  120. check_version_internal.h.in
  121. command_line.cc
  122. command_line.h
  123. command_line.rs
  124. command_line_fuzzer.cc
  125. command_line_rust_shim.cc
  126. command_line_rust_shim.h
  127. command_line_unittest.cc
  128. command_line_unittest.rs
  129. compiler_hardening_test.cc
  130. compiler_specific.h
  131. component_export.h
  132. component_export_unittest.cc
  133. cpu.cc
  134. cpu.h
  135. cpu_unittest.cc
  136. critical_closure.h
  137. critical_closure_internal_ios.mm
  138. dcheck_is_on.h
  139. DEPS
  140. DIR_METADATA
  141. enterprise_util.cc
  142. enterprise_util.h
  143. enterprise_util_mac.mm
  144. enterprise_util_mac_unittest.mm
  145. enterprise_util_win.cc
  146. environment.cc
  147. environment.h
  148. environment_unittest.cc
  149. export_template.h
  150. feature.h
  151. feature.rs
  152. feature_internal.h
  153. feature_list.cc
  154. feature_list.h
  155. feature_list_internal.cc
  156. feature_list_internal.h
  157. feature_list_unittest.cc
  158. feature_nocompile.nc
  159. feature_rust_shim.cc
  160. feature_rust_shim.h
  161. feature_unittest.rs
  162. feature_visitor.h
  163. features.cc
  164. features.h
  165. file_descriptor_posix.cc
  166. file_descriptor_posix.h
  167. file_descriptor_store.cc
  168. file_descriptor_store.h
  169. file_version_info.h
  170. file_version_info_apple.h
  171. file_version_info_apple.mm
  172. file_version_info_win.cc
  173. file_version_info_win.h
  174. file_version_info_win_unittest.cc
  175. format_macros.h
  176. gmock_unittest.cc
  177. gtest_prod_util.h
  178. immediate_crash.h
  179. immediate_crash_unittest.cc
  180. lazy_instance.h
  181. lazy_instance_helpers.cc
  182. lazy_instance_helpers.h
  183. lazy_instance_unittest.cc
  184. libcpp_hardening_test.cc
  185. linux_util.cc
  186. linux_util.h
  187. linux_util_unittest.cc
  188. location.cc
  189. location.h
  190. location.rs
  191. location_unittest.cc
  192. location_unittest.rs
  193. logging.cc
  194. logging.h
  195. logging_chromeos.cc
  196. logging_nocompile.nc
  197. logging_unittest.cc
  198. logging_win.cc
  199. logging_win.h
  200. moving_window.h
  201. moving_window_unittest.cc
  202. native_library.h
  203. native_library_apple.mm
  204. native_library_fuchsia.cc
  205. native_library_posix.cc
  206. native_library_unittest.cc
  207. native_library_win.cc
  208. no_destructor.h
  209. no_destructor_nocompile.nc
  210. no_destructor_unittest.cc
  211. not_fatal_until.h
  212. not_fatal_until_severity_override.cc
  213. not_fatal_until_severity_override.h
  214. notimplemented.h
  215. notreached.h
  216. observer_list.h
  217. observer_list_internal.cc
  218. observer_list_internal.h
  219. observer_list_nocompile.nc
  220. observer_list_perftest.cc
  221. observer_list_threadsafe.cc
  222. observer_list_threadsafe.h
  223. observer_list_threadsafe_unittest.cc
  224. observer_list_types.cc
  225. observer_list_types.h
  226. observer_list_unittest.cc
  227. one_shot_event.cc
  228. one_shot_event.h
  229. one_shot_event_unittest.cc
  230. os_compat_android.cc
  231. os_compat_android.h
  232. OWNERS
  233. parameter_pack.h
  234. parameter_pack_unittest.cc
  235. path_service.cc
  236. path_service.h
  237. path_service_unittest.cc
  238. pending_task.cc
  239. pending_task.h
  240. pickle.cc
  241. pickle.h
  242. pickle_fuzzer.cc
  243. pickle_unittest.cc
  244. PRESUBMIT.py
  245. protobuf_hardening_test.cc
  246. protobuf_hardening_test_support.proto
  247. rand_util.cc
  248. rand_util.h
  249. rand_util_fuchsia.cc
  250. rand_util_perftest.cc
  251. rand_util_posix.cc
  252. rand_util_unittest.cc
  253. rand_util_win.cc
  254. README.md
  255. run_loop.cc
  256. run_loop.h
  257. run_loop.rs
  258. run_loop_nocompile.nc
  259. run_loop_rust_shim.cc
  260. run_loop_rust_shim.h
  261. run_loop_unittest.cc
  262. safe_numerics_nocompile.nc
  263. safe_numerics_unittest.cc
  264. scoped_add_feature_flags.cc
  265. scoped_add_feature_flags.h
  266. scoped_add_feature_flags_unittest.cc
  267. scoped_clear_last_error.h
  268. scoped_clear_last_error_unittest.cc
  269. scoped_clear_last_error_win.cc
  270. scoped_environment_variable_override.cc
  271. scoped_environment_variable_override.h
  272. scoped_generic.h
  273. scoped_generic_unittest.cc
  274. scoped_multi_source_observation.h
  275. scoped_multi_source_observation_unittest.cc
  276. scoped_native_library.cc
  277. scoped_native_library.h
  278. scoped_native_library_unittest.cc
  279. scoped_observation.h
  280. scoped_observation_traits.h
  281. scoped_observation_unittest.cc
  282. SECURITY_OWNERS
  283. security_unittest.cc
  284. sequence_checker.cc
  285. sequence_checker.h
  286. sequence_checker_impl.cc
  287. sequence_checker_impl.h
  288. sequence_checker_nocompile.nc
  289. sequence_checker_unittest.cc
  290. sequence_token.cc
  291. sequence_token.h
  292. sequence_token_unittest.cc
  293. stack_canary_linux.cc
  294. stack_canary_linux.h
  295. stack_canary_linux_unittest.cc
  296. state_transitions.h
  297. state_transitions_unittest.cc
  298. std_clamp_unittest.cc
  299. stl_util.h
  300. stl_util_unittest.cc
  301. supports_user_data.cc
  302. supports_user_data.h
  303. supports_user_data_unittest.cc
  304. sync_socket.cc
  305. sync_socket.h
  306. sync_socket_posix.cc
  307. sync_socket_unittest.cc
  308. sync_socket_win.cc
  309. sys_byteorder.h
  310. sys_byteorder_unittest.cc
  311. syslog_logging.cc
  312. syslog_logging.h
  313. thread_annotations.h
  314. thread_annotations_nocompile.nc
  315. thread_annotations_unittest.cc
  316. token.cc
  317. token.h
  318. token_unittest.cc
  319. tools_sanity_unittest.cc
  320. traits_bag.h
  321. traits_bag_nocompile.nc
  322. traits_bag_unittest.cc
  323. tuple.h
  324. tuple_unittest.cc
  325. unguessable_token.cc
  326. unguessable_token.h
  327. unguessable_token.rs
  328. unguessable_token_unittest.cc
  329. unsafe_buffers_nocompile.nc
  330. unsafe_buffers_unittest.cc
  331. uuid.cc
  332. uuid.h
  333. uuid_unittest.cc
  334. value_iterators.cc
  335. value_iterators.h
  336. value_iterators_unittest.cc
  337. values.cc
  338. values.h
  339. values_nocompile.nc
  340. values_unittest.cc
  341. version.cc
  342. version.h
  343. version_unittest.cc
  344. vlog.cc
  345. vlog.h
  346. vlog_unittest.cc
  347. write_build_date_header.py
README.md

What is this

Contains a written down set of principles and other information on //base. Please add to it!

About //base:

Chromium is a very mature project. Most things that are generally useful are already here and things not here aren't generally useful.

The bar for adding stuff to base is that it must have demonstrated wide applicability. Prefer to add things closer to where they're used (i.e. “not base”), and pull into base only when needed. In a project our size, sometimes even duplication is OK and inevitable.

Adding a new logging macro DPVELOG_NE is not more clear than just writing the stuff you want to log in a regular logging statement, even if it makes your calling code longer. Just add it to your own code.

If the code in question does not need to be used inside base, but will have multiple consumers across the codebase, consider placing it in a new directory under components/ instead.

base is written for the Chromium project and is not intended to be used outside it. Using base outside of src.git is explicitly not supported, and base makes no guarantees about API (or even ABI) stability (like all other code in Chromium). New code that depends on base/ must be in src.git. Code that's not in src.git but pulled in through DEPS (for example, v8) cannot use base.

Qualifications for being in //base OWNERS

  • interest and ability to learn low level/high detail/complex c++ stuff
  • inclination to always ask why and understand everything (including external interactions like win32) rather than just hoping the author did it right
  • mentorship/experience
  • demonstrated good judgement (esp with regards to public APIs) over a length of time

Owners are added when a contributor has shown the above qualifications and when they express interest. There isn't an upper bound on the number of OWNERS.

Design and naming

  • Be sure to use the base namespace.
  • STL-like constructs should adhere as closely to STL as possible. Functions and behaviors not present in STL should only be added when they are related to the specific data structure implemented by the container.
  • For STL-like constructs our policy is that they should use STL-like naming even when it may conflict with the style guide. So functions and class names should be lower case with underscores. Non-STL-like classes and functions should use Google naming.

Performance testing

Since the primitives provided by //base are used very widely, it is important to ensure they scale to the necessary workloads and perform well under all supported platforms. The base_perftests target is a suite of synthetic microbenchmarks that measure performance in various scenarios:

  • BasicPostTaskPerfTest: Exercises MessageLoopTaskRunner's multi-threaded queue in isolation.
  • ConditionVariablePerfTest: Measures thread switching cost of condition variables.
  • IntegratedPostTaskPerfTest: Exercises the full MessageLoop/RunLoop machinery.
  • JSONPerfTest: Tests JSONWriter and JSONReader performance.
  • MessageLoopPerfTest: Measures the speed of task posting in various configurations.
  • ObserverListPerfTest: Exercises adding, removing and signalling observers.
  • PartitionLockPerfTest: Tests the implementation of Lock used in PartitionAlloc
  • PthreadEventPerfTest: Establishes the baseline thread switching cost using pthreads.
  • RandUtilPerfTest: Measures the time it takes to generate random numbers.
  • ScheduleWorkTest: Measures the overhead of MessagePump::ScheduleWork.
  • SequenceManagerPerfTest: Benchmarks SequenceManager scheduling with various underlying task runners.
  • TaskObserverPerfTest: Measures the incremental cost of adding task observers.
  • TaskPerfTest: Checks the cost of posting tasks between threads.
  • ThreadLocalStoragePerfTest: Exercises different mechanisms for accessing data associated with the current thread (C++ thread_local, the implementation in //base, the POSIX/WinAPI directly)
  • WaitableEvent{Thread,}PerfTest: Measures waitable events in single and multithreaded scenarios.

Regressions in these benchmarks can generally by caused by 1) operating system changes, 2) compiler version or flag changes or 3) changes in //base code itself.

Rust code

Rust code in base should be organized into very small crates, split up by function. Merging crates is sometimes unavoidable (due to dependency cycles or the orphaning rule).

Rust files should live near the equivalent C++ files (if any), and use the same naming scheme (for example, run_loop.rs, not run_loop_rust.rs).

When adding FFI shims, prefer separate _shim.h files rather than adding code to existing C++ files. This helps avoid circular dependencies with the //base target. It also avoids adding code to commonly-used headers, which can increase compile size by a lot.

Crates which you expect to be widely used should be added to the public_deps of the //base:base_rust target, so that developers can simply depend on //base:base_rust the same way they do with //base.