blob: 7a7ee1659d10aff767dc450840db4b3da4920444 [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"
11#include "build/build_config.h"
David Bokan97177ce02024-12-19 18:47:4512#include "chrome/common/buildflags.h"
Erik Chen46088762024-07-15 20:58:2013
Jan Lanik8ef553c2024-07-25 14:12:3514namespace system_permission_settings {
15class PlatformHandle;
16} // namespace system_permission_settings
Mickey Burks4d1287c12024-07-22 22:38:2017#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Ian Wells9aad2922024-12-09 18:51:0018namespace whats_new {
Erik Chen46088762024-07-15 20:58:2019class WhatsNewRegistry;
20} // namespace whats_new
David Bokan97177ce02024-12-19 18:47:4521#endif
22#if BUILDFLAG(ENABLE_GLIC)
Dan Harringtonb8b82742024-12-06 17:32:3923namespace glic {
Charles Meng896d6e02024-11-21 19:56:2724class GlicBackgroundModeManager;
Ian Wells9aad2922024-12-09 18:51:0025class GlicProfileManager;
26} // namespace glic
27#endif
Charles Meng896d6e02024-11-21 19:56:2728
Erik Chen46088762024-07-15 20:58:2029// This class owns the core controllers for features that are globally
30// scoped on desktop. It can be subclassed by tests to perform
31// dependency injection.
Jan Lanik826be882024-07-23 23:52:3732class GlobalFeatures {
Erik Chen46088762024-07-15 20:58:2033 public:
Jan Lanik826be882024-07-23 23:52:3734 static std::unique_ptr<GlobalFeatures> CreateGlobalFeatures();
35 virtual ~GlobalFeatures();
Erik Chen46088762024-07-15 20:58:2036
Jan Lanik826be882024-07-23 23:52:3737 GlobalFeatures(const GlobalFeatures&) = delete;
38 GlobalFeatures& operator=(const GlobalFeatures&) = delete;
Erik Chen46088762024-07-15 20:58:2039
Jan Lanik826be882024-07-23 23:52:3740 // Call this method to stub out GlobalFeatures for tests.
41 using GlobalFeaturesFactory =
42 base::RepeatingCallback<std::unique_ptr<GlobalFeatures>()>;
43 static void ReplaceGlobalFeaturesForTesting(GlobalFeaturesFactory factory);
Erik Chen46088762024-07-15 20:58:2044
45 // Called exactly once to initialize features.
46 void Init();
47
48 // Public accessors for features, e.g.
49 // FooFeature* foo_feature() { return foo_feature_.get(); }
50
Jan Lanik8ef553c2024-07-25 14:12:3551 system_permission_settings::PlatformHandle*
52 system_permissions_platform_handle() {
53 return system_permissions_platform_handle_.get();
54 }
Mickey Burks4d1287c12024-07-22 22:38:2055#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2056 whats_new::WhatsNewRegistry* whats_new_registry() {
57 return whats_new_registry_.get();
58 }
David Bokan97177ce02024-12-19 18:47:4559#endif
Ian Wells9aad2922024-12-09 18:51:0060
David Bokan97177ce02024-12-19 18:47:4561#if BUILDFLAG(ENABLE_GLIC)
Ian Wells9aad2922024-12-09 18:51:0062 glic::GlicProfileManager* glic_profile_manager() {
63 return glic_profile_manager_.get();
64 }
Erik Chen46088762024-07-15 20:58:2065
Dan Harringtonb8b82742024-12-06 17:32:3966 glic::GlicBackgroundModeManager* glic_background_mode_manager() {
Charles Meng896d6e02024-11-21 19:56:2767 return glic_background_mode_manager_.get();
68 }
69#endif
70
Erik Chen46088762024-07-15 20:58:2071 protected:
Jan Lanik826be882024-07-23 23:52:3772 GlobalFeatures();
Erik Chen46088762024-07-15 20:58:2073
74 // Override these methods to stub out individual feature controllers for
75 // testing. e.g.
76 // virtual std::unique_ptr<FooFeature> CreateFooFeature();
77
Jan Lanik8ef553c2024-07-25 14:12:3578 virtual std::unique_ptr<system_permission_settings::PlatformHandle>
79 CreateSystemPermissionsPlatformHandle();
Mickey Burks4d1287c12024-07-22 22:38:2080#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2081 virtual std::unique_ptr<whats_new::WhatsNewRegistry> CreateWhatsNewRegistry();
Mickey Burks4d1287c12024-07-22 22:38:2082#endif
Erik Chen46088762024-07-15 20:58:2083
84 private:
85 // Features will each have a controller. e.g.
86 // std::unique_ptr<FooFeature> foo_feature_;
87
Jan Lanik8ef553c2024-07-25 14:12:3588 std::unique_ptr<system_permission_settings::PlatformHandle>
89 system_permissions_platform_handle_;
Mickey Burks4d1287c12024-07-22 22:38:2090#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2091 std::unique_ptr<whats_new::WhatsNewRegistry> whats_new_registry_;
Mickey Burks4d1287c12024-07-22 22:38:2092#endif
Charles Meng896d6e02024-11-21 19:56:2793
David Bokan97177ce02024-12-19 18:47:4594#if BUILDFLAG(ENABLE_GLIC)
95 std::unique_ptr<glic::GlicProfileManager> glic_profile_manager_;
Dan Harringtonb8b82742024-12-06 17:32:3996 std::unique_ptr<glic::GlicBackgroundModeManager>
97 glic_background_mode_manager_;
Charles Meng896d6e02024-11-21 19:56:2798#endif
Erik Chen46088762024-07-15 20:58:2099};
100
Jan Lanik826be882024-07-23 23:52:37101#endif // CHROME_BROWSER_GLOBAL_FEATURES_H_