Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 1 | // Copyright 2024 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_GLOBAL_FEATURES_H_ |
| 6 | #define CHROME_BROWSER_GLOBAL_FEATURES_H_ |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 7 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 8 | #include <memory.h> |
| 9 | |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 10 | #include "base/functional/callback.h" |
Foromo Daniel Soromou | 615461c | 2025-05-16 14:05:31 | [diff] [blame] | 11 | #include "build/branding_buildflags.h" |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 12 | #include "build/build_config.h" |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 13 | #include "chrome/common/buildflags.h" |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 14 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 15 | namespace system_permission_settings { |
| 16 | class PlatformHandle; |
| 17 | } // namespace system_permission_settings |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 18 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 19 | namespace whats_new { |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 20 | class WhatsNewRegistry; |
| 21 | } // namespace whats_new |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 22 | #endif |
| 23 | #if BUILDFLAG(ENABLE_GLIC) |
Dan Harrington | b8b8274 | 2024-12-06 17:32:39 | [diff] [blame] | 24 | namespace glic { |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 25 | class GlicBackgroundModeManager; |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 26 | class GlicProfileManager; |
Nick Birnie | b06de3f | 2025-03-04 18:38:54 | [diff] [blame] | 27 | class GlicSyntheticTrialManager; |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 28 | } // namespace glic |
| 29 | #endif |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 30 | |
Jun Ishiguro | a65a6e4 | 2025-04-03 03:51:15 | [diff] [blame] | 31 | class ApplicationLocaleStorage; |
| 32 | |
Foromo Daniel Soromou | 615461c | 2025-05-16 14:05:31 | [diff] [blame] | 33 | namespace installer_downloader { |
| 34 | class InstallerDownloaderController; |
| 35 | } |
| 36 | |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 37 | // This class owns the core controllers for features that are globally |
| 38 | // scoped on desktop. It can be subclassed by tests to perform |
| 39 | // dependency injection. |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 40 | class GlobalFeatures { |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 41 | public: |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 42 | static std::unique_ptr<GlobalFeatures> CreateGlobalFeatures(); |
| 43 | virtual ~GlobalFeatures(); |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 44 | |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 45 | GlobalFeatures(const GlobalFeatures&) = delete; |
| 46 | GlobalFeatures& operator=(const GlobalFeatures&) = delete; |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 47 | |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 48 | // Call this method to stub out GlobalFeatures for tests. |
| 49 | using GlobalFeaturesFactory = |
| 50 | base::RepeatingCallback<std::unique_ptr<GlobalFeatures>()>; |
| 51 | static void ReplaceGlobalFeaturesForTesting(GlobalFeaturesFactory factory); |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 52 | |
| 53 | // Called exactly once to initialize features. |
| 54 | void Init(); |
| 55 | |
David Bokan | 7412e91 | 2025-01-10 19:07:32 | [diff] [blame] | 56 | // Called exactly once when the browser starts to shutdown. |
| 57 | void Shutdown(); |
| 58 | |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 59 | // Public accessors for features, e.g. |
| 60 | // FooFeature* foo_feature() { return foo_feature_.get(); } |
| 61 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 62 | system_permission_settings::PlatformHandle* |
| 63 | system_permissions_platform_handle() { |
| 64 | return system_permissions_platform_handle_.get(); |
| 65 | } |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 66 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 67 | whats_new::WhatsNewRegistry* whats_new_registry() { |
| 68 | return whats_new_registry_.get(); |
| 69 | } |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 70 | #endif |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 71 | |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 72 | #if BUILDFLAG(ENABLE_GLIC) |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 73 | glic::GlicProfileManager* glic_profile_manager() { |
| 74 | return glic_profile_manager_.get(); |
| 75 | } |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 76 | |
Dan Harrington | b8b8274 | 2024-12-06 17:32:39 | [diff] [blame] | 77 | glic::GlicBackgroundModeManager* glic_background_mode_manager() { |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 78 | return glic_background_mode_manager_.get(); |
| 79 | } |
Nick Birnie | b06de3f | 2025-03-04 18:38:54 | [diff] [blame] | 80 | |
| 81 | glic::GlicSyntheticTrialManager* glic_synthetic_trial_manager() { |
| 82 | return synthetic_trial_manager_.get(); |
| 83 | } |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 84 | #endif |
| 85 | |
Jun Ishiguro | a65a6e4 | 2025-04-03 03:51:15 | [diff] [blame] | 86 | ApplicationLocaleStorage* application_locale_storage() { |
| 87 | return application_locale_storage_.get(); |
| 88 | } |
| 89 | |
Foromo Daniel Soromou | 615461c | 2025-05-16 14:05:31 | [diff] [blame] | 90 | #if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) |
| 91 | installer_downloader::InstallerDownloaderController* |
| 92 | installer_downloader_controller() { |
| 93 | return installer_downloader_controller_.get(); |
| 94 | } |
| 95 | #endif |
| 96 | |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 97 | protected: |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 98 | GlobalFeatures(); |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 99 | |
| 100 | // Override these methods to stub out individual feature controllers for |
| 101 | // testing. e.g. |
| 102 | // virtual std::unique_ptr<FooFeature> CreateFooFeature(); |
| 103 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 104 | virtual std::unique_ptr<system_permission_settings::PlatformHandle> |
| 105 | CreateSystemPermissionsPlatformHandle(); |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 106 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 107 | virtual std::unique_ptr<whats_new::WhatsNewRegistry> CreateWhatsNewRegistry(); |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 108 | #endif |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 109 | |
| 110 | private: |
| 111 | // Features will each have a controller. e.g. |
| 112 | // std::unique_ptr<FooFeature> foo_feature_; |
| 113 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 114 | std::unique_ptr<system_permission_settings::PlatformHandle> |
| 115 | system_permissions_platform_handle_; |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 116 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 117 | std::unique_ptr<whats_new::WhatsNewRegistry> whats_new_registry_; |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 118 | #endif |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 119 | |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 120 | #if BUILDFLAG(ENABLE_GLIC) |
| 121 | std::unique_ptr<glic::GlicProfileManager> glic_profile_manager_; |
Dan Harrington | b8b8274 | 2024-12-06 17:32:39 | [diff] [blame] | 122 | std::unique_ptr<glic::GlicBackgroundModeManager> |
| 123 | glic_background_mode_manager_; |
Nick Birnie | b06de3f | 2025-03-04 18:38:54 | [diff] [blame] | 124 | std::unique_ptr<glic::GlicSyntheticTrialManager> synthetic_trial_manager_; |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 125 | #endif |
Jun Ishiguro | a65a6e4 | 2025-04-03 03:51:15 | [diff] [blame] | 126 | |
| 127 | std::unique_ptr<ApplicationLocaleStorage> application_locale_storage_; |
Foromo Daniel Soromou | 615461c | 2025-05-16 14:05:31 | [diff] [blame] | 128 | |
| 129 | #if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING) |
| 130 | std::unique_ptr<installer_downloader::InstallerDownloaderController> |
| 131 | installer_downloader_controller_; |
| 132 | #endif |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 133 | }; |
| 134 | |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 135 | #endif // CHROME_BROWSER_GLOBAL_FEATURES_H_ |