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 | |
| 5 | #ifndef CHROME_BROWSER_GLOBAL_DESKTOP_FEATURES_H_ |
| 6 | #define CHROME_BROWSER_GLOBAL_DESKTOP_FEATURES_H_ |
| 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. |
| 20 | class GlobalDesktopFeatures { |
| 21 | public: |
| 22 | static std::unique_ptr<GlobalDesktopFeatures> CreateGlobalDesktopFeatures(); |
| 23 | virtual ~GlobalDesktopFeatures(); |
| 24 | |
| 25 | GlobalDesktopFeatures(const GlobalDesktopFeatures&) = delete; |
| 26 | GlobalDesktopFeatures& operator=(const GlobalDesktopFeatures&) = delete; |
| 27 | |
| 28 | // Call this method to stub out GlobalDesktopFeatures for tests. |
| 29 | using GlobalDesktopFeaturesFactory = |
| 30 | base::RepeatingCallback<std::unique_ptr<GlobalDesktopFeatures>()>; |
| 31 | static void ReplaceGlobalDesktopFeaturesForTesting( |
| 32 | GlobalDesktopFeaturesFactory factory); |
| 33 | |
| 34 | // Called exactly once to initialize features. |
| 35 | void Init(); |
| 36 | |
| 37 | // Public accessors for features, e.g. |
| 38 | // FooFeature* foo_feature() { return foo_feature_.get(); } |
| 39 | |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame^] | 40 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 41 | whats_new::WhatsNewRegistry* whats_new_registry() { |
| 42 | return whats_new_registry_.get(); |
| 43 | } |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame^] | 44 | #endif |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 45 | |
| 46 | protected: |
| 47 | GlobalDesktopFeatures(); |
| 48 | |
| 49 | // Override these methods to stub out individual feature controllers for |
| 50 | // testing. e.g. |
| 51 | // virtual std::unique_ptr<FooFeature> CreateFooFeature(); |
| 52 | |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame^] | 53 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 54 | virtual std::unique_ptr<whats_new::WhatsNewRegistry> CreateWhatsNewRegistry(); |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame^] | 55 | #endif |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | // Features will each have a controller. e.g. |
| 59 | // std::unique_ptr<FooFeature> foo_feature_; |
| 60 | |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame^] | 61 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 62 | std::unique_ptr<whats_new::WhatsNewRegistry> whats_new_registry_; |
Mickey Burks | 4d1287c1 | 2024-07-22 22:38:20 | [diff] [blame^] | 63 | #endif |
Erik Chen | 4608876 | 2024-07-15 20:58:20 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | #endif // CHROME_BROWSER_GLOBAL_DESKTOP_FEATURES_H_ |