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" |
| 11 | #include "build/build_config.h" |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 12 | #include "chrome/common/buildflags.h" |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 13 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 14 | namespace system_permission_settings { |
| 15 | class PlatformHandle; |
| 16 | } // namespace system_permission_settings |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 17 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 18 | namespace whats_new { |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 19 | class WhatsNewRegistry; |
| 20 | } // namespace whats_new |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 21 | #endif |
| 22 | #if BUILDFLAG(ENABLE_GLIC) |
Dan Harrington | b8b8274 | 2024-12-06 17:32:39 | [diff] [blame] | 23 | namespace glic { |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 24 | class GlicBackgroundModeManager; |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 25 | class GlicProfileManager; |
| 26 | } // namespace glic |
| 27 | #endif |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 28 | |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 29 | // This class owns the core controllers for features that are globally |
| 30 | // scoped on desktop. It can be subclassed by tests to perform |
| 31 | // dependency injection. |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 32 | class GlobalFeatures { |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 33 | public: |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 34 | static std::unique_ptr<GlobalFeatures> CreateGlobalFeatures(); |
| 35 | virtual ~GlobalFeatures(); |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 36 | |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 37 | GlobalFeatures(const GlobalFeatures&) = delete; |
| 38 | GlobalFeatures& operator=(const GlobalFeatures&) = delete; |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 39 | |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 40 | // Call this method to stub out GlobalFeatures for tests. |
| 41 | using GlobalFeaturesFactory = |
| 42 | base::RepeatingCallback<std::unique_ptr<GlobalFeatures>()>; |
| 43 | static void ReplaceGlobalFeaturesForTesting(GlobalFeaturesFactory factory); |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 44 | |
| 45 | // Called exactly once to initialize features. |
| 46 | void Init(); |
| 47 | |
| 48 | // Public accessors for features, e.g. |
| 49 | // FooFeature* foo_feature() { return foo_feature_.get(); } |
| 50 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 51 | system_permission_settings::PlatformHandle* |
| 52 | system_permissions_platform_handle() { |
| 53 | return system_permissions_platform_handle_.get(); |
| 54 | } |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 55 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 56 | whats_new::WhatsNewRegistry* whats_new_registry() { |
| 57 | return whats_new_registry_.get(); |
| 58 | } |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 59 | #endif |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 60 | |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 61 | #if BUILDFLAG(ENABLE_GLIC) |
Ian Wells | 9aad292 | 2024-12-09 18:51:00 | [diff] [blame] | 62 | glic::GlicProfileManager* glic_profile_manager() { |
| 63 | return glic_profile_manager_.get(); |
| 64 | } |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 65 | |
Dan Harrington | b8b8274 | 2024-12-06 17:32:39 | [diff] [blame] | 66 | glic::GlicBackgroundModeManager* glic_background_mode_manager() { |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 67 | return glic_background_mode_manager_.get(); |
| 68 | } |
| 69 | #endif |
| 70 | |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 71 | protected: |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 72 | GlobalFeatures(); |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 73 | |
| 74 | // Override these methods to stub out individual feature controllers for |
| 75 | // testing. e.g. |
| 76 | // virtual std::unique_ptr<FooFeature> CreateFooFeature(); |
| 77 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 78 | virtual std::unique_ptr<system_permission_settings::PlatformHandle> |
| 79 | CreateSystemPermissionsPlatformHandle(); |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 80 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 81 | virtual std::unique_ptr<whats_new::WhatsNewRegistry> CreateWhatsNewRegistry(); |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 82 | #endif |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | // Features will each have a controller. e.g. |
| 86 | // std::unique_ptr<FooFeature> foo_feature_; |
| 87 | |
Jan Lanik | 8ef553c | 2024-07-25 14:12:35 | [diff] [blame] | 88 | std::unique_ptr<system_permission_settings::PlatformHandle> |
| 89 | system_permissions_platform_handle_; |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 90 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 91 | std::unique_ptr<whats_new::WhatsNewRegistry> whats_new_registry_; |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame] | 92 | #endif |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 93 | |
David Bokan | 97177ce0 | 2024-12-19 18:47:45 | [diff] [blame] | 94 | #if BUILDFLAG(ENABLE_GLIC) |
| 95 | std::unique_ptr<glic::GlicProfileManager> glic_profile_manager_; |
Dan Harrington | b8b8274 | 2024-12-06 17:32:39 | [diff] [blame] | 96 | std::unique_ptr<glic::GlicBackgroundModeManager> |
| 97 | glic_background_mode_manager_; |
Charles Meng | 896d6e0 | 2024-11-21 19:56:27 | [diff] [blame] | 98 | #endif |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 99 | }; |
| 100 | |
Jan Lanik | 826be88 | 2024-07-23 23:52:37 | [diff] [blame] | 101 | #endif // CHROME_BROWSER_GLOBAL_FEATURES_H_ |