File: output_protection_impl.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 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 (131 lines) | stat: -rw-r--r-- 5,305 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_COMPONENTS_CDM_FACTORY_DAEMON_OUTPUT_PROTECTION_IMPL_H_
#define CHROMEOS_COMPONENTS_CDM_FACTORY_DAEMON_OUTPUT_PROTECTION_IMPL_H_

#include <memory>
#include <vector>

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/components/cdm_factory_daemon/mojom/output_protection.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "ui/display/display_observer.h"
#include "ui/display/manager/content_protection_manager.h"
#include "ui/display/types/display_snapshot.h"

namespace chromeos {

// Provides a Mojo implementation of the OutputProtection interface which then
// calls into the ContentProtectionManger singleton owned by the ash shell.
class COMPONENT_EXPORT(CDM_FACTORY_DAEMON) OutputProtectionImpl
    : public cdm::mojom::OutputProtection,
      public display::DisplayObserver {
 public:
  // Mainly to enable testing, this abstracts out calls that would normally
  // be made into display::ContentProtectionManager, ash::Screen and
  // display::DisplayConfigurator.
  class DisplaySystemDelegate {
   public:
    virtual ~DisplaySystemDelegate() = default;

    // Delegate to display::ContentProtectionManager.
    virtual void ApplyContentProtection(
        display::ContentProtectionManager::ClientId client_id,
        int64_t display_id,
        uint32_t protection_mask,
        display::ContentProtectionManager::ApplyContentProtectionCallback
            callback) = 0;
    virtual void QueryContentProtection(
        display::ContentProtectionManager::ClientId client_id,
        int64_t display_id,
        display::ContentProtectionManager::QueryContentProtectionCallback
            callback) = 0;
    virtual display::ContentProtectionManager::ClientId RegisterClient() = 0;
    virtual void UnregisterClient(
        display::ContentProtectionManager::ClientId client_id) = 0;

    // Delegate to display::DisplayConfigurator.
    virtual const std::vector<
        raw_ptr<display::DisplaySnapshot, VectorExperimental>>&
    cached_displays() const = 0;
  };

  static void Create(
      mojo::PendingReceiver<cdm::mojom::OutputProtection> receiver,
      std::unique_ptr<DisplaySystemDelegate> delegate = nullptr);

  explicit OutputProtectionImpl(
      std::unique_ptr<DisplaySystemDelegate> delegate);

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

  ~OutputProtectionImpl() override;

  // chromeos::cdm::mojom::OutputProtection:
  void QueryStatus(QueryStatusCallback callback) override;
  void EnableProtection(
      cdm::mojom::OutputProtection::ProtectionType desired_protection,
      EnableProtectionCallback callback) override;

 private:
  void Initialize();

  // This is used to successively enable protection on all the displays and
  // aggregate the overall result and fire the callback when complete.
  void EnableProtectionCallbackAggregator(
      std::vector<int64_t> remaining_displays,
      EnableProtectionCallback callback,
      bool aggregate_success,
      bool success);

  // This is used to query multiple displays for the status and then aggregate
  // that into one before we invoke the callback.
  void QueryStatusCallbackAggregator(std::vector<int64_t> remaining_displays,
                                     QueryStatusCallback callback,
                                     bool aggregate_success,
                                     uint32_t aggregate_link_mask,
                                     uint32_t aggregate_protection_mask,
                                     uint32_t aggregate_no_protection_mask,
                                     bool success,
                                     uint32_t link_mask,
                                     uint32_t protection_mask);

  void HandleDisplayChange();

  // display::DisplayObserver:
  void OnDisplayAdded(const display::Display& display) override;
  void OnDisplayMetricsChanged(const display::Display& display,
                               uint32_t changed_metrics) override;
  void OnDisplaysRemoved(const display::Displays& removed_displays) override;

  // Helper methods to report output protection UMAs.
  void ReportOutputProtectionQuery();
  void ReportOutputProtectionQueryResult(uint32_t link_mask,
                                         uint32_t protection_mask);

  std::unique_ptr<DisplaySystemDelegate> delegate_;
  display::ContentProtectionManager::ClientId client_id_;

  std::optional<display::ScopedOptionalDisplayObserver> display_observer_;

  std::vector<int64_t> display_id_list_;

  uint32_t desired_protection_mask_{0};

  // Tracks whether an output protection query and a positive query result (no
  // unprotected external link) have been reported to UMA.
  bool uma_for_output_protection_query_reported_ = false;
  bool uma_for_output_protection_positive_result_reported_ = false;

  // WeakPtrFactory to use for callbacks.
  base::WeakPtrFactory<OutputProtectionImpl> weak_factory_{this};
};

}  // namespace chromeos

#endif  // CHROMEOS_COMPONENTS_CDM_FACTORY_DAEMON_OUTPUT_PROTECTION_IMPL_H_