blob: aef6e032520a301d6a9c074296474ae9cce7f64e [file] [log] [blame]
Erik Chen46088762024-07-15 20:58:201// 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 Lanik826be882024-07-23 23:52:375#ifndef CHROME_BROWSER_GLOBAL_FEATURES_H_
6#define CHROME_BROWSER_GLOBAL_FEATURES_H_
Erik Chen46088762024-07-15 20:58:207
Jan Lanik8ef553c2024-07-25 14:12:358#include <memory.h>
9
Erik Chen46088762024-07-15 20:58:2010#include "base/functional/callback.h"
Foromo Daniel Soromou615461c2025-05-16 14:05:3111#include "build/branding_buildflags.h"
Erik Chen46088762024-07-15 20:58:2012#include "build/build_config.h"
David Bokan97177ce02024-12-19 18:47:4513#include "chrome/common/buildflags.h"
Erik Chen46088762024-07-15 20:58:2014
Jan Lanik8ef553c2024-07-25 14:12:3515namespace system_permission_settings {
16class PlatformHandle;
17} // namespace system_permission_settings
Mickey Burks4d1287c12024-07-22 22:38:2018#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Ian Wells9aad2922024-12-09 18:51:0019namespace whats_new {
Erik Chen46088762024-07-15 20:58:2020class WhatsNewRegistry;
21} // namespace whats_new
David Bokan97177ce02024-12-19 18:47:4522#endif
23#if BUILDFLAG(ENABLE_GLIC)
Dan Harringtonb8b82742024-12-06 17:32:3924namespace glic {
Charles Meng896d6e02024-11-21 19:56:2725class GlicBackgroundModeManager;
Ian Wells9aad2922024-12-09 18:51:0026class GlicProfileManager;
Nick Birnieb06de3f2025-03-04 18:38:5427class GlicSyntheticTrialManager;
Ian Wells9aad2922024-12-09 18:51:0028} // namespace glic
29#endif
Charles Meng896d6e02024-11-21 19:56:2730
Jun Ishiguroa65a6e42025-04-03 03:51:1531class ApplicationLocaleStorage;
32
Foromo Daniel Soromou615461c2025-05-16 14:05:3133namespace installer_downloader {
34class InstallerDownloaderController;
35}
36
Erik Chen46088762024-07-15 20:58:2037// This class owns the core controllers for features that are globally
38// scoped on desktop. It can be subclassed by tests to perform
39// dependency injection.
Jan Lanik826be882024-07-23 23:52:3740class GlobalFeatures {
Erik Chen46088762024-07-15 20:58:2041 public:
Jan Lanik826be882024-07-23 23:52:3742 static std::unique_ptr<GlobalFeatures> CreateGlobalFeatures();
43 virtual ~GlobalFeatures();
Erik Chen46088762024-07-15 20:58:2044
Jan Lanik826be882024-07-23 23:52:3745 GlobalFeatures(const GlobalFeatures&) = delete;
46 GlobalFeatures& operator=(const GlobalFeatures&) = delete;
Erik Chen46088762024-07-15 20:58:2047
Jan Lanik826be882024-07-23 23:52:3748 // Call this method to stub out GlobalFeatures for tests.
49 using GlobalFeaturesFactory =
50 base::RepeatingCallback<std::unique_ptr<GlobalFeatures>()>;
51 static void ReplaceGlobalFeaturesForTesting(GlobalFeaturesFactory factory);
Erik Chen46088762024-07-15 20:58:2052
53 // Called exactly once to initialize features.
54 void Init();
55
David Bokan7412e912025-01-10 19:07:3256 // Called exactly once when the browser starts to shutdown.
57 void Shutdown();
58
Erik Chen46088762024-07-15 20:58:2059 // Public accessors for features, e.g.
60 // FooFeature* foo_feature() { return foo_feature_.get(); }
61
Jan Lanik8ef553c2024-07-25 14:12:3562 system_permission_settings::PlatformHandle*
63 system_permissions_platform_handle() {
64 return system_permissions_platform_handle_.get();
65 }
Mickey Burks4d1287c12024-07-22 22:38:2066#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2067 whats_new::WhatsNewRegistry* whats_new_registry() {
68 return whats_new_registry_.get();
69 }
David Bokan97177ce02024-12-19 18:47:4570#endif
Ian Wells9aad2922024-12-09 18:51:0071
David Bokan97177ce02024-12-19 18:47:4572#if BUILDFLAG(ENABLE_GLIC)
Ian Wells9aad2922024-12-09 18:51:0073 glic::GlicProfileManager* glic_profile_manager() {
74 return glic_profile_manager_.get();
75 }
Erik Chen46088762024-07-15 20:58:2076
Dan Harringtonb8b82742024-12-06 17:32:3977 glic::GlicBackgroundModeManager* glic_background_mode_manager() {
Charles Meng896d6e02024-11-21 19:56:2778 return glic_background_mode_manager_.get();
79 }
Nick Birnieb06de3f2025-03-04 18:38:5480
81 glic::GlicSyntheticTrialManager* glic_synthetic_trial_manager() {
82 return synthetic_trial_manager_.get();
83 }
Charles Meng896d6e02024-11-21 19:56:2784#endif
85
Jun Ishiguroa65a6e42025-04-03 03:51:1586 ApplicationLocaleStorage* application_locale_storage() {
87 return application_locale_storage_.get();
88 }
89
Foromo Daniel Soromou615461c2025-05-16 14:05:3190#if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
91 installer_downloader::InstallerDownloaderController*
92 installer_downloader_controller() {
93 return installer_downloader_controller_.get();
94 }
95#endif
96
Erik Chen46088762024-07-15 20:58:2097 protected:
Jan Lanik826be882024-07-23 23:52:3798 GlobalFeatures();
Erik Chen46088762024-07-15 20:58:2099
100 // Override these methods to stub out individual feature controllers for
101 // testing. e.g.
102 // virtual std::unique_ptr<FooFeature> CreateFooFeature();
103
Jan Lanik8ef553c2024-07-25 14:12:35104 virtual std::unique_ptr<system_permission_settings::PlatformHandle>
105 CreateSystemPermissionsPlatformHandle();
Mickey Burks4d1287c12024-07-22 22:38:20106#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:20107 virtual std::unique_ptr<whats_new::WhatsNewRegistry> CreateWhatsNewRegistry();
Mickey Burks4d1287c12024-07-22 22:38:20108#endif
Erik Chen46088762024-07-15 20:58:20109
110 private:
111 // Features will each have a controller. e.g.
112 // std::unique_ptr<FooFeature> foo_feature_;
113
Jan Lanik8ef553c2024-07-25 14:12:35114 std::unique_ptr<system_permission_settings::PlatformHandle>
115 system_permissions_platform_handle_;
Mickey Burks4d1287c12024-07-22 22:38:20116#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:20117 std::unique_ptr<whats_new::WhatsNewRegistry> whats_new_registry_;
Mickey Burks4d1287c12024-07-22 22:38:20118#endif
Charles Meng896d6e02024-11-21 19:56:27119
David Bokan97177ce02024-12-19 18:47:45120#if BUILDFLAG(ENABLE_GLIC)
121 std::unique_ptr<glic::GlicProfileManager> glic_profile_manager_;
Dan Harringtonb8b82742024-12-06 17:32:39122 std::unique_ptr<glic::GlicBackgroundModeManager>
123 glic_background_mode_manager_;
Nick Birnieb06de3f2025-03-04 18:38:54124 std::unique_ptr<glic::GlicSyntheticTrialManager> synthetic_trial_manager_;
Charles Meng896d6e02024-11-21 19:56:27125#endif
Jun Ishiguroa65a6e42025-04-03 03:51:15126
127 std::unique_ptr<ApplicationLocaleStorage> application_locale_storage_;
Foromo Daniel Soromou615461c2025-05-16 14:05:31128
129#if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
130 std::unique_ptr<installer_downloader::InstallerDownloaderController>
131 installer_downloader_controller_;
132#endif
Erik Chen46088762024-07-15 20:58:20133};
134
Jan Lanik826be882024-07-23 23:52:37135#endif // CHROME_BROWSER_GLOBAL_FEATURES_H_