# HaTS in Chrome HaTS is the survey feature on ChromeOS. Let's see how HaTS is implemented as ChromeOS UI. ## HaTS Config [HatsConfig](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_config.h;l=14;drc=446950b310f139999a622c7029805504979f798b) struct is created for each type of the survey. For example, [kHatsGeneralSurvey](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_config.cc;l=49-54;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) constant represents the general survey shown after login. Each config holds - `feature`: corresponding flag to decide whether the survey is enabled - `new_device_threshold`: minimum time after initial login - `is_selected_pref_name`: whether we are selected for the current survey cycle - `cycle_end_timestamp_pref_name`: when the current survey cycle end - `survey_last_interaction_timestamp_pref_name`: last time the user interacted with the survey - `threshold_time`: minimum time after the previous interaction - `globcal_cap_opt_out`: opt-out by global cap For example, the general survey struct is like this: ```cpp= const HatsConfig kHatsGeneralSurvey = { ::features::kHappinessTrackingSystem, // feature base::Days(7), // new_device_threshold prefs::kHatsDeviceIsSelected, // is_selected_pref_name prefs::kHatsSurveyCycleEndTimestamp, // cycle_end_timestamp_pref_name }; ``` The feature flags are in [kHappinessTrackingSystem*](https://source.chromium.org/chromium/chromium/src/+/main:chrome/common/chrome_features.cc;l=697-793;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) and they are disabled by default. ## HaTS UI [HatsNotificationController](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_notification_controller.h;l=31;drc=fe132eeb21687c455d695d6af346f15454828d01) controls the UI. Some features (e.g. [OsSettingsHatsManager](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/webui/ash/settings/services/hats/os_settings_hats_manager.cc;l=44-45;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090)) create this controller and handle the notification. [HatsNotificationController::ShowDialog](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_notification_controller.cc;l=331;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) will call the static method [HatsDialog::Show](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_dialog.cc;l=180;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) and construct [HatsDialog](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_dialog.h;l=19;drc=8dd419d33fa6112ca7d4892e0450fc0c8959b090). [HatsDialog](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_dialog.h;l=19;drc=8dd419d33fa6112ca7d4892e0450fc0c8959b090) is a class which represents the happinesss tracking survey dialog. This is implemented as one of [ui::WebDialogDelegate](https://source.chromium.org/chromium/chromium/src/+/main:ui/web_dialogs/web_dialog_delegate.h;l=36;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090), the abstract class to receive notifications. Show is triggered mainly from [MessageCenterImpl](https://source.chromium.org/chromium/chromium/src/+/main:ui/message_center/message_center_impl.cc;l=556;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) on click. ## Hats finch [HatsFinchHelper](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_finch_helper.h;l=23;drc=8f57934dc9dd175acdc5fc56e2e6b7c3cb8e3b95) provides an API for the controller to retrieve processed information about finch experiment. Finch is the A/B experiment platform for Chrome. Whether the feature is enabled on the finch experiment or not for the user is partially stored in this object. For example, the method [IsEnabledForGooglers](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/hats/hats_finch_helper.cc;l=76;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) returns whether it's enabled for googlers obviously. Also, we can get the histogram name, client data and so on.