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