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