blob: 119a7d2295d98306a242f739116736c908ec7023 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
Alan Cuttere294b342020-08-03 06:30:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Song Fangzhencda4af62021-09-09 05:24:025#include "chrome/browser/web_applications/preinstalled_app_install_features.h"
Alan Cuttere294b342020-08-03 06:30:076
7#include "base/feature_list.h"
Xiaohan Wangd711bf32022-01-16 04:29:018#include "build/build_config.h"
Alan Cutter52914e72021-05-05 09:35:489#include "chrome/browser/policy/profile_policy_connector.h"
10#include "chrome/browser/profiles/profile.h"
Alan Cuttere294b342020-08-03 06:30:0711
Jeevan Shikaram10472fc2022-06-07 04:18:2912#if BUILDFLAG(IS_CHROMEOS)
13#include "chromeos/constants/chromeos_features.h"
14#endif // IS_CHROMEOS
15
Alan Cuttere294b342020-08-03 06:30:0716namespace web_app {
17
Alan Cutter19bfe8c2022-11-15 07:29:2518namespace {
19
Alan Cutter2ab7a042020-09-14 03:57:4020// A hard coded list of features available for externally installed apps to
21// gate their installation on via their config file settings. See
Daniel Murphy3657906d2021-04-13 20:33:1222// |kFeatureName| in preinstalled_web_app_utils.h.
Alan Cutter19bfe8c2022-11-15 07:29:2523// 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 Sergeant3cf624b2023-09-05 00:58:2926constexpr const base::Feature* kPreinstalledAppInstallFeatures[] = {};
Alan Cuttere294b342020-08-03 06:30:0727
Alan Cutter19bfe8c2022-11-15 07:29:2528constexpr 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 Willigersfd319d712023-01-14 00:41:0032
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 Sergeantb9d83a952023-08-17 05:55:0340
41 // Enables installing the Messages app on unmanaged devices.
42 "MessagesPreinstall",
Tim Sergeant3cf624b2023-09-05 00:58:2943
44 // Enables installing the Cursive device on managed stylus-enabled devices.
45 "CursiveManagedStylusPreinstall",
Alan Cutter19bfe8c2022-11-15 07:29:2546};
Alan Cuttere294b342020-08-03 06:30:0747
Alan Cutter19bfe8c2022-11-15 07:29:2548bool g_always_enabled_for_testing = false;
Dibyajyoti Pal2888b672021-11-30 00:54:5649
Tim Sergeantef39c6e2022-08-08 00:38:2650struct 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.
58const FeatureWithEnabledFunction
59 kPreinstalledAppInstallFeaturesWithEnabledFunctions[] = {
60#if BUILDFLAG(IS_CHROMEOS)
61 {chromeos::features::kCloudGamingDevice.name,
62 &chromeos::features::IsCloudGamingDeviceEnabled}
63#endif
64};
65
Alan Cuttere294b342020-08-03 06:30:0766} // namespace
67
Alan Cutter52914e72021-05-05 09:35:4868bool IsPreinstalledAppInstallFeatureEnabled(base::StringPiece feature_name,
69 const Profile& profile) {
Tim Sergeant3cf624b2023-09-05 00:58:2970 if (g_always_enabled_for_testing) {
Alan Cuttere294b342020-08-03 06:30:0771 return true;
Tim Sergeant3cf624b2023-09-05 00:58:2972 }
Alan Cuttere294b342020-08-03 06:30:0773
Alan Cutter19bfe8c2022-11-15 07:29:2574 for (const base::StringPiece& feature :
75 kShippedPreinstalledAppInstallFeatures) {
Tim Sergeant3cf624b2023-09-05 00:58:2976 if (feature == feature_name) {
Alan Cutter19bfe8c2022-11-15 07:29:2577 return true;
Tim Sergeant3cf624b2023-09-05 00:58:2978 }
Alan Cutter19bfe8c2022-11-15 07:29:2579 }
80
Daniel Murphy3657906d2021-04-13 20:33:1281 for (const base::Feature* feature : kPreinstalledAppInstallFeatures) {
Tim Sergeant3cf624b2023-09-05 00:58:2982 if (feature->name == feature_name) {
Alan Cutter2ab7a042020-09-14 03:57:4083 return base::FeatureList::IsEnabled(*feature);
Tim Sergeant3cf624b2023-09-05 00:58:2984 }
Alan Cuttere294b342020-08-03 06:30:0785 }
86
Tim Sergeantef39c6e2022-08-08 00:38:2687 for (const auto& feature :
88 kPreinstalledAppInstallFeaturesWithEnabledFunctions) {
Tim Sergeant3cf624b2023-09-05 00:58:2989 if (feature.name == feature_name) {
Tim Sergeantef39c6e2022-08-08 00:38:2690 return feature.enabled_func();
Tim Sergeant3cf624b2023-09-05 00:58:2991 }
Tim Sergeantef39c6e2022-08-08 00:38:2692 }
93
Alan Cuttere294b342020-08-03 06:30:0794 return false;
95}
96
Daniel Murphy3657906d2021-04-13 20:33:1297base::AutoReset<bool>
98SetPreinstalledAppInstallFeatureAlwaysEnabledForTesting() {
Alan Cuttere294b342020-08-03 06:30:0799 return base::AutoReset<bool>(&g_always_enabled_for_testing, true);
100}
101
102} // namespace web_app