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