Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame] | 5 | #include "chrome/browser/web_applications/preinstalled_app_install_features.h" |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 6 | |
| 7 | #include "base/feature_list.h" |
Xiaohan Wang | d711bf3 | 2022-01-16 04:29:01 | [diff] [blame] | 8 | #include "build/build_config.h" |
Alan Cutter | 52914e7 | 2021-05-05 09:35:48 | [diff] [blame] | 9 | #include "chrome/browser/policy/profile_policy_connector.h" |
| 10 | #include "chrome/browser/profiles/profile.h" |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 11 | |
Jeevan Shikaram | 10472fc | 2022-06-07 04:18:29 | [diff] [blame] | 12 | #if BUILDFLAG(IS_CHROMEOS) |
| 13 | #include "chromeos/constants/chromeos_features.h" |
| 14 | #endif // IS_CHROMEOS |
| 15 | |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 16 | namespace web_app { |
| 17 | |
Alan Cutter | 19bfe8c | 2022-11-15 07:29:25 | [diff] [blame] | 18 | namespace { |
| 19 | |
Alan Cutter | 2ab7a04 | 2020-09-14 03:57:40 | [diff] [blame] | 20 | // A hard coded list of features available for externally installed apps to |
| 21 | // gate their installation on via their config file settings. See |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 22 | // |kFeatureName| in preinstalled_web_app_utils.h. |
Alan Cutter | 19bfe8c | 2022-11-15 07:29:25 | [diff] [blame] | 23 | // After a feature flag has been shipped and should be cleaned up, move it into |
| 24 | // kShippedPreinstalledAppInstallFeatures to ensure any external installation |
| 25 | // configs that reference it continue to see it as enabled. |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 26 | constexpr const base::Feature* kPreinstalledAppInstallFeatures[] = {}; |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 27 | |
Alan Cutter | 19bfe8c | 2022-11-15 07:29:25 | [diff] [blame] | 28 | constexpr const base::StringPiece kShippedPreinstalledAppInstallFeatures[] = { |
| 29 | // Enables installing the PWA version of the chrome os calculator instead of |
| 30 | // the deprecated chrome app. |
| 31 | "DefaultCalculatorWebApp", |
Eric Willigers | fd319d71 | 2023-01-14 00:41:00 | [diff] [blame] | 32 | |
| 33 | // Enables migration of default installed GSuite apps over to their |
| 34 | // replacement web apps. |
| 35 | "MigrateDefaultChromeAppToWebAppsGSuite", |
| 36 | |
| 37 | // Enables migration of default installed non-GSuite apps over to their |
| 38 | // replacement web apps. |
| 39 | "MigrateDefaultChromeAppToWebAppsNonGSuite", |
Tim Sergeant | b9d83a95 | 2023-08-17 05:55:03 | [diff] [blame] | 40 | |
| 41 | // Enables installing the Messages app on unmanaged devices. |
| 42 | "MessagesPreinstall", |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 43 | |
| 44 | // Enables installing the Cursive device on managed stylus-enabled devices. |
| 45 | "CursiveManagedStylusPreinstall", |
Alan Cutter | 19bfe8c | 2022-11-15 07:29:25 | [diff] [blame] | 46 | }; |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 47 | |
Alan Cutter | 19bfe8c | 2022-11-15 07:29:25 | [diff] [blame] | 48 | bool g_always_enabled_for_testing = false; |
Dibyajyoti Pal | 2888b67 | 2021-11-30 00:54:56 | [diff] [blame] | 49 | |
Tim Sergeant | ef39c6e | 2022-08-08 00:38:26 | [diff] [blame] | 50 | struct FeatureWithEnabledFunction { |
| 51 | const char* const name; |
| 52 | bool (*enabled_func)(); |
| 53 | }; |
| 54 | |
| 55 | // Features which have a function to be run to determine whether they are |
| 56 | // enabled. Prefer using a base::Feature with |kPreinstalledAppInstallFeatures| |
| 57 | // when possible. |
| 58 | const FeatureWithEnabledFunction |
| 59 | kPreinstalledAppInstallFeaturesWithEnabledFunctions[] = { |
| 60 | #if BUILDFLAG(IS_CHROMEOS) |
| 61 | {chromeos::features::kCloudGamingDevice.name, |
| 62 | &chromeos::features::IsCloudGamingDeviceEnabled} |
| 63 | #endif |
| 64 | }; |
| 65 | |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 66 | } // namespace |
| 67 | |
Alan Cutter | 52914e7 | 2021-05-05 09:35:48 | [diff] [blame] | 68 | bool IsPreinstalledAppInstallFeatureEnabled(base::StringPiece feature_name, |
| 69 | const Profile& profile) { |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 70 | if (g_always_enabled_for_testing) { |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 71 | return true; |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 72 | } |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 73 | |
Alan Cutter | 19bfe8c | 2022-11-15 07:29:25 | [diff] [blame] | 74 | for (const base::StringPiece& feature : |
| 75 | kShippedPreinstalledAppInstallFeatures) { |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 76 | if (feature == feature_name) { |
Alan Cutter | 19bfe8c | 2022-11-15 07:29:25 | [diff] [blame] | 77 | return true; |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 78 | } |
Alan Cutter | 19bfe8c | 2022-11-15 07:29:25 | [diff] [blame] | 79 | } |
| 80 | |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 81 | for (const base::Feature* feature : kPreinstalledAppInstallFeatures) { |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 82 | if (feature->name == feature_name) { |
Alan Cutter | 2ab7a04 | 2020-09-14 03:57:40 | [diff] [blame] | 83 | return base::FeatureList::IsEnabled(*feature); |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 84 | } |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 85 | } |
| 86 | |
Tim Sergeant | ef39c6e | 2022-08-08 00:38:26 | [diff] [blame] | 87 | for (const auto& feature : |
| 88 | kPreinstalledAppInstallFeaturesWithEnabledFunctions) { |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 89 | if (feature.name == feature_name) { |
Tim Sergeant | ef39c6e | 2022-08-08 00:38:26 | [diff] [blame] | 90 | return feature.enabled_func(); |
Tim Sergeant | 3cf624b | 2023-09-05 00:58:29 | [diff] [blame] | 91 | } |
Tim Sergeant | ef39c6e | 2022-08-08 00:38:26 | [diff] [blame] | 92 | } |
| 93 | |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 94 | return false; |
| 95 | } |
| 96 | |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 97 | base::AutoReset<bool> |
| 98 | SetPreinstalledAppInstallFeatureAlwaysEnabledForTesting() { |
Alan Cutter | e294b34 | 2020-08-03 06:30:07 | [diff] [blame] | 99 | return base::AutoReset<bool>(&g_always_enabled_for_testing, true); |
| 100 | } |
| 101 | |
| 102 | } // namespace web_app |