Daniel Erat | be44a2f | 2017-07-27 02:28:43 | [diff] [blame] | 1 | # Passing Chrome flags from `session_manager` |
| 2 | |
Daniel Erat | 240572b | 2018-04-25 20:03:22 | [diff] [blame] | 3 | ## Runtime configuration |
| 4 | |
Daniel Erat | be44a2f | 2017-07-27 02:28:43 | [diff] [blame] | 5 | Chrome sometimes needs to behave differently on different Chrome OS devices. |
| 6 | It's preferable to test for the hardware features that you care about directly |
| 7 | within Chrome: if you want to do something special on Chromebooks that have |
| 8 | accelerometers, just check if an accelerometer device is present. |
| 9 | |
Daniel Erat | 240572b | 2018-04-25 20:03:22 | [diff] [blame] | 10 | ## Build-time configuration |
| 11 | |
Daniel Erat | be44a2f | 2017-07-27 02:28:43 | [diff] [blame] | 12 | Sometimes it's not possible to check for these features from within Chrome, |
| 13 | though. In that case, the recommended approach is to add a command-line flag to |
| 14 | Chrome and update `session_manager` to pass it with the appropriate value (if |
| 15 | any). |
| 16 | |
| 17 | Chrome's command line is constructed by [chrome_setup.cc]. This file uses the |
Hidehiko Abe | 40f1528 | 2024-10-11 05:25:21 | [diff] [blame] | 18 | [ChromiumCommandBuilder] class to create directories |
Daniel Erat | be44a2f | 2017-07-27 02:28:43 | [diff] [blame] | 19 | needed by Chrome, configure its environment, and build its command line. |
| 20 | |
| 21 | `ChromiumCommandBuilder` reads a subset of the Portage USE flags that were set |
| 22 | when the system was built from `/etc/ui_use_flags.txt`; these can be used to |
| 23 | determine which flags should be passed. To start using a new USE flag (including |
| 24 | a board name), add it to the [libchromeos-use-flags] ebuild file. (Relegating |
| 25 | this file to a tiny dedicated package allows us to use the same prebuilt |
| 26 | `chromeos-chrome` and `chromeos-login` packages on devices that have different |
| 27 | sets of USE flags.) |
| 28 | |
Daniel Erat | 240572b | 2018-04-25 20:03:22 | [diff] [blame] | 29 | ### Configuration location |
| 30 | |
Daniel Erat | be44a2f | 2017-07-27 02:28:43 | [diff] [blame] | 31 | Configuration that would apply both to the Chrome browser and to other products |
| 32 | that could be built using the Chromium codebase (e.g. a simple shell that runs a |
| 33 | dedicated web app) should be placed in `ChromiumCommandBuilder`. This includes |
| 34 | most compositor- and audio-related flags. |
| 35 | |
| 36 | Configuration that is specific to the Chrome browser should instead be placed in |
| 37 | [chrome_setup.cc]. This includes most flags that are implemented within Chrome's |
| 38 | `//ash` and `//chrome` directories. |
| 39 | |
Jack Rosenthal | c89e49a | 2021-04-29 22:16:53 | [diff] [blame] | 40 | ### Translating chromeos-config to switches |
| 41 | |
| 42 | The preferred way to add model-specific switches to the command line |
| 43 | is to use [chromeos-config] to specify the model specific |
| 44 | configuration. |
| 45 | |
| 46 | To do so, no changes to `session_manager` are required. Simply |
| 47 | generate the corresponding switches in [cros_config_schema] (search |
| 48 | for `AshSwitches`). |
| 49 | |
Daniel Erat | 240572b | 2018-04-25 20:03:22 | [diff] [blame] | 50 | ### Use feature-based USE flags |
| 51 | |
Jack Rosenthal | c89e49a | 2021-04-29 22:16:53 | [diff] [blame] | 52 | If you need a model-specific configuration for a pre-unibuild device |
| 53 | (2016 and before), or you need to apply a feature to experimental |
| 54 | builds, the best way to do this is USE flags. |
| 55 | |
| 56 | Note: USE flags are not able to introduce model-specific switches in |
| 57 | the unibuild world. |
| 58 | |
Daniel Erat | 240572b | 2018-04-25 20:03:22 | [diff] [blame] | 59 | If possible, introduce a new USE flag named after the feature that you're adding |
| 60 | and set it in the appropriate [board overlays] rather than making |
| 61 | `session_manager` examine board USE flags like `samus` or `eve`. Using |
| 62 | feature-specific USE flags reduces the number of changes needed to enable the |
| 63 | feature for a new board — just set the USE flag in the new board's overlay. In |
| 64 | contrast, if `session_manager` contains an expression like this: |
| 65 | |
| 66 | ```c++ |
| 67 | if (builder->UseFlagIsSet("samus") || builder->UseFlagIsSet("eve")) |
| 68 | builder->AddArgs("--enable-my-feature"); |
| 69 | ``` |
| 70 | |
| 71 | then additionally enabling the feature for `newboard` will require: |
| 72 | |
| 73 | * Adding `newboard` to `IUSE` in [libchromeos-use-flags] if it's not there |
| 74 | already |
| 75 | * Updating `session_manager` to additionally check for the `newboard` USE flag |
| 76 | |
Daniel Erat | be44a2f | 2017-07-27 02:28:43 | [diff] [blame] | 77 | ## Making quick changes |
| 78 | |
| 79 | [/etc/chrome_dev.conf] can be modified on dev-mode Chrome OS systems (after |
| 80 | making the root partition writable) to add or remove flags from Chrome's command |
| 81 | line or modify Chrome's environment. The file contains documentation about its |
| 82 | format. |
| 83 | |
| 84 | [chrome_setup.cc]: ../chrome_setup.cc |
Hidehiko Abe | 40f1528 | 2024-10-11 05:25:21 | [diff] [blame] | 85 | [ChromiumCommandBuilder]: https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/login_manager/chromium_command_builder.h |
Keith Lee | b132e74 | 2021-05-05 04:25:24 | [diff] [blame] | 86 | [libchromeos-use-flags]: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/HEAD/chromeos-base/libchromeos-use-flags/libchromeos-use-flags-9999.ebuild |
Tom Hughes | 18251f9 | 2020-12-07 21:38:14 | [diff] [blame] | 87 | [board overlays]: https://chromium.googlesource.com/chromiumos/overlays/board-overlays/+/HEAD |
| 88 | [chromeos-config]: https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/chromeos-config/ |
Jack Rosenthal | c89e49a | 2021-04-29 22:16:53 | [diff] [blame] | 89 | [cros_config_schema]: https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/chromeos-config/cros_config_host/cros_config_schema.py |
Daniel Erat | be44a2f | 2017-07-27 02:28:43 | [diff] [blame] | 90 | [/etc/chrome_dev.conf]: ../chrome_dev.conf |