1 // Copyright 2020 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.
5 #ifndef ASH_DISPLAY_PRIVACY_SCREEN_CONTROLLER_H_
6 #define ASH_DISPLAY_PRIVACY_SCREEN_CONTROLLER_H_
10 #include "ash/ash_export.h"
11 #include "ash/public/cpp/privacy_screen_dlp_helper.h"
12 #include "ash/public/cpp/session/session_observer.h"
13 #include "base/memory/raw_ptr.h"
14 #include "base/observer_list.h"
15 #include "ui/display/manager/display_configurator.h"
17 class PrefRegistrySimple;
19 class PrefChangeRegistrar;
23 // Controls the privacy screen feature.
24 class ASH_EXPORT PrivacyScreenController
25 : public PrivacyScreenDlpHelper,
26 public SessionObserver,
27 display::DisplayConfigurator::Observer {
29 class Observer : public base::CheckedObserver {
31 // Called when the privacy screen setting is changed.
32 virtual void OnPrivacyScreenSettingChanged(bool enabled, bool notify_ui) {}
35 ~Observer() override = default;
38 PrivacyScreenController();
39 ~PrivacyScreenController() override;
41 PrivacyScreenController(const PrivacyScreenController&) = delete;
42 PrivacyScreenController& operator=(const PrivacyScreenController&) = delete;
44 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
46 // Whether or not the privacy screen feature is enforced by policy.
47 bool IsManaged() const;
48 // Get the PrivacyScreen settings stored in the current active user prefs.
49 bool GetEnabled() const;
50 // Set the desired PrivacyScreen settings in the current active user prefs.
51 void SetEnabled(bool enabled);
53 void AddObserver(Observer* observer);
54 void RemoveObserver(Observer* observer);
56 // PrivacyScreenDlpHelper:
57 bool IsSupported() const override;
58 void SetEnforced(bool enforced) override;
61 void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
62 void OnSigninScreenPrefServiceInitialized(PrefService* pref_service) override;
64 // DisplayConfigurator::Observer:
65 void OnDisplayModeChanged(
66 const std::vector<display::DisplaySnapshot*>& displays) override;
69 // Calculates PrivacyScreen's logical status.
70 bool CalculateCurrentStatus() const;
72 // Called when the user pref or DLP enforcement for the state of PrivacyScreen
74 void OnStateChanged(bool notify_observers);
76 // Called when GPU/DRM is done setting the privacy screen panel to
77 // |requested_config|.
78 void OnSetPrivacyScreenComplete(bool from_user_pref_init,
79 bool requested_config,
82 // Called when a change to |active_user_pref_service_| is detected (i.e. when
83 // OnActiveUserPrefServiceChanged() is called.
84 void InitFromUserPrefs();
86 // Retrieves the current user's PrivacyScreen preference.
87 bool GetStateFromActiveUserPreference() const;
89 // Whether or not to alert observers about PrivacyScreen state change.
90 bool ShouldNotifyObservers(bool from_user_pref_init) const;
92 // The pref service of the currently active user. Can be null in
94 raw_ptr<PrefService, ExperimentalAsh> active_user_pref_service_ = nullptr;
96 // Set to true when entering the login screen. This should happen once per
98 bool applying_login_screen_prefs_ = false;
100 // Indicates if the PrivacyScreen is currently on or off.
101 bool current_status_ = false;
103 // Indicates whether PrivacyScreen is enforced by Data Leak Protection
105 bool dlp_enforced_ = false;
107 base::ObserverList<Observer> observers_;
109 // The registrar used to watch privacy screen prefs changes in the above
110 // |active_user_pref_service_| from outside ash.
111 // NOTE: Prefs are how Chrome communicates changes to the
112 // PrivacyScreenController settings controlled by this class from the WebUI
114 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
116 // This must be the last variable.
117 base::WeakPtrFactory<PrivacyScreenController> weak_ptr_factory_{this};
122 #endif // ASH_DISPLAY_PRIVACY_SCREEN_CONTROLLER_H_