blob: 481f563b9ae7aa0691f2c93e348d88e888754727 [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"
12
Jan Lanik8ef553c2024-07-25 14:12:3513namespace system_permission_settings {
14class PlatformHandle;
15} // namespace system_permission_settings
Mickey Burks4d1287c12024-07-22 22:38:2016#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Ian Wells9aad2922024-12-09 18:51:0017namespace whats_new {
Erik Chen46088762024-07-15 20:58:2018class WhatsNewRegistry;
19} // namespace whats_new
Dan Harringtonb8b82742024-12-06 17:32:3920namespace glic {
Charles Meng896d6e02024-11-21 19:56:2721class GlicBackgroundModeManager;
Ian Wells9aad2922024-12-09 18:51:0022class GlicProfileManager;
23} // namespace glic
24#endif
Charles Meng896d6e02024-11-21 19:56:2725
Erik Chen46088762024-07-15 20:58:2026// This class owns the core controllers for features that are globally
27// scoped on desktop. It can be subclassed by tests to perform
28// dependency injection.
Jan Lanik826be882024-07-23 23:52:3729class GlobalFeatures {
Erik Chen46088762024-07-15 20:58:2030 public:
Jan Lanik826be882024-07-23 23:52:3731 static std::unique_ptr<GlobalFeatures> CreateGlobalFeatures();
32 virtual ~GlobalFeatures();
Erik Chen46088762024-07-15 20:58:2033
Jan Lanik826be882024-07-23 23:52:3734 GlobalFeatures(const GlobalFeatures&) = delete;
35 GlobalFeatures& operator=(const GlobalFeatures&) = delete;
Erik Chen46088762024-07-15 20:58:2036
Jan Lanik826be882024-07-23 23:52:3737 // Call this method to stub out GlobalFeatures for tests.
38 using GlobalFeaturesFactory =
39 base::RepeatingCallback<std::unique_ptr<GlobalFeatures>()>;
40 static void ReplaceGlobalFeaturesForTesting(GlobalFeaturesFactory factory);
Erik Chen46088762024-07-15 20:58:2041
42 // Called exactly once to initialize features.
43 void Init();
44
45 // Public accessors for features, e.g.
46 // FooFeature* foo_feature() { return foo_feature_.get(); }
47
Jan Lanik8ef553c2024-07-25 14:12:3548 system_permission_settings::PlatformHandle*
49 system_permissions_platform_handle() {
50 return system_permissions_platform_handle_.get();
51 }
Mickey Burks4d1287c12024-07-22 22:38:2052#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2053 whats_new::WhatsNewRegistry* whats_new_registry() {
54 return whats_new_registry_.get();
55 }
Ian Wells9aad2922024-12-09 18:51:0056
57 glic::GlicProfileManager* glic_profile_manager() {
58 return glic_profile_manager_.get();
59 }
David Bokan3c77efe2024-12-13 18:59:4860#endif
Erik Chen46088762024-07-15 20:58:2061
David Bokan3c77efe2024-12-13 18:59:4862#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
Dan Harringtonb8b82742024-12-06 17:32:3963 glic::GlicBackgroundModeManager* glic_background_mode_manager() {
Charles Meng896d6e02024-11-21 19:56:2764 return glic_background_mode_manager_.get();
65 }
66#endif
67
Erik Chen46088762024-07-15 20:58:2068 protected:
Jan Lanik826be882024-07-23 23:52:3769 GlobalFeatures();
Erik Chen46088762024-07-15 20:58:2070
71 // Override these methods to stub out individual feature controllers for
72 // testing. e.g.
73 // virtual std::unique_ptr<FooFeature> CreateFooFeature();
74
Jan Lanik8ef553c2024-07-25 14:12:3575 virtual std::unique_ptr<system_permission_settings::PlatformHandle>
76 CreateSystemPermissionsPlatformHandle();
Mickey Burks4d1287c12024-07-22 22:38:2077#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2078 virtual std::unique_ptr<whats_new::WhatsNewRegistry> CreateWhatsNewRegistry();
Mickey Burks4d1287c12024-07-22 22:38:2079#endif
Erik Chen46088762024-07-15 20:58:2080
81 private:
82 // Features will each have a controller. e.g.
83 // std::unique_ptr<FooFeature> foo_feature_;
84
Jan Lanik8ef553c2024-07-25 14:12:3585 std::unique_ptr<system_permission_settings::PlatformHandle>
86 system_permissions_platform_handle_;
Mickey Burks4d1287c12024-07-22 22:38:2087#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2088 std::unique_ptr<whats_new::WhatsNewRegistry> whats_new_registry_;
David Bokan3c77efe2024-12-13 18:59:4889 std::unique_ptr<glic::GlicProfileManager> glic_profile_manager_;
Mickey Burks4d1287c12024-07-22 22:38:2090#endif
Charles Meng896d6e02024-11-21 19:56:2791
David Bokan3c77efe2024-12-13 18:59:4892#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
Dan Harringtonb8b82742024-12-06 17:32:3993 std::unique_ptr<glic::GlicBackgroundModeManager>
94 glic_background_mode_manager_;
Charles Meng896d6e02024-11-21 19:56:2795#endif
Erik Chen46088762024-07-15 20:58:2096};
97
Jan Lanik826be882024-07-23 23:52:3798#endif // CHROME_BROWSER_GLOBAL_FEATURES_H_