File: display_settings_handler.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (112 lines) | stat: -rw-r--r-- 4,676 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_POLICY_DISPLAY_DISPLAY_SETTINGS_HANDLER_H_
#define CHROME_BROWSER_ASH_POLICY_DISPLAY_DISPLAY_SETTINGS_HANDLER_H_

#include <memory>
#include <vector>

#include "base/memory/weak_ptr.h"
#include "chromeos/ash/components/settings/cros_settings.h"
#include "chromeos/crosapi/mojom/cros_display_config.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"

namespace policy {

// Provides an interface for display configuration policies. Each policy should
// provide a handler that implements this interface and register it in
// the |DisplaySettingsHandler| instance.
class DisplaySettingsPolicyHandler {
 public:
  virtual ~DisplaySettingsPolicyHandler() = default;

  // Returns a name of setting stored in CrosSettings that should be used to
  // subscribe to setting changes for this policy.
  virtual const char* SettingName() = 0;

  // Is called on each setting update before |ApplyChanges| to provide
  // updated settings for the handler.
  virtual void OnSettingUpdate() = 0;

  // Applies settings enforced by the policy to each display from |info_list|.
  // Is called on each configuration change or settings update.
  virtual void ApplyChanges(
      crosapi::mojom::CrosDisplayConfigController* cros_display_config,
      const std::vector<crosapi::mojom::DisplayUnitInfoPtr>& info_list) = 0;
};

// Enforces the settings controlled by device policies related to display
// configuration (i.e. DisplayRotationDefault, DeviceDisplayResolution)
// On construction this class registers itself with
// crosapi::mojom::CrosDisplayConfigObserver for display changes and with
// CrosSettings for settings changes. Every display configuration policy
// provides a handler class inherited from |DisplaySettingsPolicyHandler|
// and is registered in |DisplaySettingsHandler| instance.
// see |DisplayResolutionHandler| and |DisplayRotationDefaultHandler|
class DisplaySettingsHandler
    : public crosapi::mojom::CrosDisplayConfigObserver {
 public:
  // This class must be constructed after CrosSettings is initialized.
  DisplaySettingsHandler();

  DisplaySettingsHandler(const DisplaySettingsHandler&) = delete;
  DisplaySettingsHandler& operator=(const DisplaySettingsHandler&) = delete;

  ~DisplaySettingsHandler() override;

  // crosapi::mojom::CrosDisplayConfigObserver
  void OnDisplayConfigChanged() override;

  // Registers handler for some policy-controlled setting. All handlers must be
  // registered before calling |Start|.
  void RegisterHandler(std::unique_ptr<DisplaySettingsPolicyHandler> handler);

  // Subscribes to all needed events and initiates initial display configuration
  // fetching to apply the settings controlled by registered handlers.
  void Start();

 private:
  // Receives the initial display info list and initializes the class.
  void OnGetInitialDisplayInfo(
      std::vector<crosapi::mojom::DisplayUnitInfoPtr> info_list);

  // Requests the list of displays and applies each setting.
  void RequestDisplaysAndApplyChanges();

  // Apply all default settings defined by policies to all connected displays.
  void ApplyChanges(std::vector<crosapi::mojom::DisplayUnitInfoPtr> info_list);

  // Called on each update of the setting provided by |handler|. Requests the
  // list of displays and applies |handler| to each display.
  void OnSettingUpdate(DisplaySettingsPolicyHandler* handler);

  // Applies |handler| to each display from |info_list|.
  void UpdateSettingAndApplyChanges(
      DisplaySettingsPolicyHandler* handler,
      const std::vector<crosapi::mojom::DisplayUnitInfoPtr>& info_list);

  // Called on display configuration changes for each handler.
  void OnConfigurationChangeForHandler(
      DisplaySettingsPolicyHandler* handler,
      std::vector<crosapi::mojom::DisplayUnitInfoPtr> info_list);

  // Provides access to the current display configurations, both for reading and
  // updating.
  mojo::Remote<crosapi::mojom::CrosDisplayConfigController>
      cros_display_config_;
  std::vector<std::unique_ptr<DisplaySettingsPolicyHandler>> handlers_;
  mojo::AssociatedReceiver<crosapi::mojom::CrosDisplayConfigObserver>
      cros_display_config_observer_receiver_{this};
  std::vector<base::CallbackListSubscription> settings_subscriptions_;
  bool started_ = false;

  // Must be the last member.
  base::WeakPtrFactory<DisplaySettingsHandler> weak_ptr_factory_{this};
};

}  // namespace policy

#endif  // CHROME_BROWSER_ASH_POLICY_DISPLAY_DISPLAY_SETTINGS_HANDLER_H_