Handle more cases of display changes for output protection

Originally the observer was only listening on DisplayMetricsChanged, but
in testing I noticed that was not sufficient as it didn't cover the case
of display removal. I've also added handling display added/removed so it
should catch all cases of display change now.

BUG=b:170780507,b:153111783
TEST=Display plug/unplug repeatedly is now handled for HDCP

(cherry picked from commit da82bf1bea37ee5ce7f17ebb19ac117b856ec7ce)

Change-Id: Ie2ecbe2d494908dc51b4efd7bf4acf93555c09ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2472020
Auto-Submit: Jeffrey Kardatzke <[email protected]>
Commit-Queue: Xiaohan Wang <[email protected]>
Reviewed-by: Xiaohan Wang <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#817156}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485627
Reviewed-by: Jeffrey Kardatzke <[email protected]>
Commit-Queue: Jeffrey Kardatzke <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#519}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/chromeos/components/cdm_factory_daemon/output_protection_impl.cc b/chromeos/components/cdm_factory_daemon/output_protection_impl.cc
index 6b774e0..54e09bf 100644
--- a/chromeos/components/cdm_factory_daemon/output_protection_impl.cc
+++ b/chromeos/components/cdm_factory_daemon/output_protection_impl.cc
@@ -286,9 +286,7 @@
                           ConvertProtection(aggregate_protection_mask));
 }
 
-void OutputProtectionImpl::OnDisplayMetricsChanged(
-    const display::Display& display,
-    uint32_t changed_metrics) {
+void OutputProtectionImpl::HandleDisplayChange() {
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
   display_id_list_ = GetDisplayIdsFromSnapshots(delegate_->cached_displays());
   if (desired_protection_mask_) {
@@ -299,4 +297,18 @@
   }
 }
 
+void OutputProtectionImpl::OnDisplayAdded(const display::Display& display) {
+  HandleDisplayChange();
+}
+
+void OutputProtectionImpl::OnDisplayMetricsChanged(
+    const display::Display& display,
+    uint32_t changed_metrics) {
+  HandleDisplayChange();
+}
+
+void OutputProtectionImpl::OnDisplayRemoved(const display::Display& display) {
+  HandleDisplayChange();
+}
+
 }  // namespace chromeos
diff --git a/chromeos/components/cdm_factory_daemon/output_protection_impl.h b/chromeos/components/cdm_factory_daemon/output_protection_impl.h
index 1acf057..a8ac4bf 100644
--- a/chromeos/components/cdm_factory_daemon/output_protection_impl.h
+++ b/chromeos/components/cdm_factory_daemon/output_protection_impl.h
@@ -97,9 +97,13 @@
                                      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 OnDisplayRemoved(const display::Display& display) override;
 
   std::unique_ptr<DisplaySystemDelegate> delegate_;
   display::ContentProtectionManager::ClientId client_id_;