blob: dd5e550b0eef98bd467ea74d21787269fe0a04c9 [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
Erik Chen46088762024-07-15 20:58:2016namespace whats_new {
Mickey Burks4d1287c12024-07-22 22:38:2017#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2018class WhatsNewRegistry;
Mickey Burks4d1287c12024-07-22 22:38:2019#endif
Erik Chen46088762024-07-15 20:58:2020} // namespace whats_new
21
22// This class owns the core controllers for features that are globally
23// scoped on desktop. It can be subclassed by tests to perform
24// dependency injection.
Jan Lanik826be882024-07-23 23:52:3725class GlobalFeatures {
Erik Chen46088762024-07-15 20:58:2026 public:
Jan Lanik826be882024-07-23 23:52:3727 static std::unique_ptr<GlobalFeatures> CreateGlobalFeatures();
28 virtual ~GlobalFeatures();
Erik Chen46088762024-07-15 20:58:2029
Jan Lanik826be882024-07-23 23:52:3730 GlobalFeatures(const GlobalFeatures&) = delete;
31 GlobalFeatures& operator=(const GlobalFeatures&) = delete;
Erik Chen46088762024-07-15 20:58:2032
Jan Lanik826be882024-07-23 23:52:3733 // Call this method to stub out GlobalFeatures for tests.
34 using GlobalFeaturesFactory =
35 base::RepeatingCallback<std::unique_ptr<GlobalFeatures>()>;
36 static void ReplaceGlobalFeaturesForTesting(GlobalFeaturesFactory factory);
Erik Chen46088762024-07-15 20:58:2037
38 // Called exactly once to initialize features.
39 void Init();
40
41 // Public accessors for features, e.g.
42 // FooFeature* foo_feature() { return foo_feature_.get(); }
43
Jan Lanik8ef553c2024-07-25 14:12:3544 system_permission_settings::PlatformHandle*
45 system_permissions_platform_handle() {
46 return system_permissions_platform_handle_.get();
47 }
Mickey Burks4d1287c12024-07-22 22:38:2048#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2049 whats_new::WhatsNewRegistry* whats_new_registry() {
50 return whats_new_registry_.get();
51 }
Mickey Burks4d1287c12024-07-22 22:38:2052#endif
Erik Chen46088762024-07-15 20:58:2053
54 protected:
Jan Lanik826be882024-07-23 23:52:3755 GlobalFeatures();
Erik Chen46088762024-07-15 20:58:2056
57 // Override these methods to stub out individual feature controllers for
58 // testing. e.g.
59 // virtual std::unique_ptr<FooFeature> CreateFooFeature();
60
Jan Lanik8ef553c2024-07-25 14:12:3561 virtual std::unique_ptr<system_permission_settings::PlatformHandle>
62 CreateSystemPermissionsPlatformHandle();
Mickey Burks4d1287c12024-07-22 22:38:2063#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2064 virtual std::unique_ptr<whats_new::WhatsNewRegistry> CreateWhatsNewRegistry();
Mickey Burks4d1287c12024-07-22 22:38:2065#endif
Erik Chen46088762024-07-15 20:58:2066
67 private:
68 // Features will each have a controller. e.g.
69 // std::unique_ptr<FooFeature> foo_feature_;
70
Jan Lanik8ef553c2024-07-25 14:12:3571 std::unique_ptr<system_permission_settings::PlatformHandle>
72 system_permissions_platform_handle_;
Mickey Burks4d1287c12024-07-22 22:38:2073#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
Erik Chen46088762024-07-15 20:58:2074 std::unique_ptr<whats_new::WhatsNewRegistry> whats_new_registry_;
Mickey Burks4d1287c12024-07-22 22:38:2075#endif
Erik Chen46088762024-07-15 20:58:2076};
77
Jan Lanik826be882024-07-23 23:52:3778#endif // CHROME_BROWSER_GLOBAL_FEATURES_H_