fixup! Fix for Geolocation webTCT failures
[platform/framework/web/chromium-efl.git] / ash / display / privacy_screen_controller.h
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.
4
5 #ifndef ASH_DISPLAY_PRIVACY_SCREEN_CONTROLLER_H_
6 #define ASH_DISPLAY_PRIVACY_SCREEN_CONTROLLER_H_
7
8 #include <memory>
9
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"
16
17 class PrefRegistrySimple;
18 class PrefService;
19 class PrefChangeRegistrar;
20
21 namespace ash {
22
23 // Controls the privacy screen feature.
24 class ASH_EXPORT PrivacyScreenController
25     : public PrivacyScreenDlpHelper,
26       public SessionObserver,
27       display::DisplayConfigurator::Observer {
28  public:
29   class Observer : public base::CheckedObserver {
30    public:
31     // Called when the privacy screen setting is changed.
32     virtual void OnPrivacyScreenSettingChanged(bool enabled, bool notify_ui) {}
33
34    protected:
35     ~Observer() override = default;
36   };
37
38   PrivacyScreenController();
39   ~PrivacyScreenController() override;
40
41   PrivacyScreenController(const PrivacyScreenController&) = delete;
42   PrivacyScreenController& operator=(const PrivacyScreenController&) = delete;
43
44   static void RegisterProfilePrefs(PrefRegistrySimple* registry);
45
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);
52
53   void AddObserver(Observer* observer);
54   void RemoveObserver(Observer* observer);
55
56   // PrivacyScreenDlpHelper:
57   bool IsSupported() const override;
58   void SetEnforced(bool enforced) override;
59
60   // SessionObserver:
61   void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
62   void OnSigninScreenPrefServiceInitialized(PrefService* pref_service) override;
63
64   // DisplayConfigurator::Observer:
65   void OnDisplayModeChanged(
66       const std::vector<display::DisplaySnapshot*>& displays) override;
67
68  private:
69   // Calculates PrivacyScreen's logical status.
70   bool CalculateCurrentStatus() const;
71
72   // Called when the user pref or DLP enforcement for the state of PrivacyScreen
73   // is changed.
74   void OnStateChanged(bool notify_observers);
75
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,
80                                   bool success);
81
82   // Called when a change to |active_user_pref_service_| is detected (i.e. when
83   // OnActiveUserPrefServiceChanged() is called.
84   void InitFromUserPrefs();
85
86   // Retrieves the current user's PrivacyScreen preference.
87   bool GetStateFromActiveUserPreference() const;
88
89   // Whether or not to alert observers about PrivacyScreen state change.
90   bool ShouldNotifyObservers(bool from_user_pref_init) const;
91
92   // The pref service of the currently active user. Can be null in
93   // ash_unittests.
94   raw_ptr<PrefService, ExperimentalAsh> active_user_pref_service_ = nullptr;
95
96   // Set to true when entering the login screen. This should happen once per
97   // Chrome restart.
98   bool applying_login_screen_prefs_ = false;
99
100   // Indicates if the PrivacyScreen is currently on or off.
101   bool current_status_ = false;
102
103   // Indicates whether PrivacyScreen is enforced by Data Leak Protection
104   // feature.
105   bool dlp_enforced_ = false;
106
107   base::ObserverList<Observer> observers_;
108
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
113   // settings.
114   std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
115
116   // This must be the last variable.
117   base::WeakPtrFactory<PrivacyScreenController> weak_ptr_factory_{this};
118 };
119
120 }  // namespace ash
121
122 #endif  // ASH_DISPLAY_PRIVACY_SCREEN_CONTROLLER_H_