1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_DISPLAY_CHROMEOS_APPLY_CONTENT_PROTECTION_TASK_H_
6 #define UI_DISPLAY_CHROMEOS_APPLY_CONTENT_PROTECTION_TASK_H_
11 #include "base/memory/weak_ptr.h"
12 #include "ui/display/chromeos/display_configurator.h"
16 class DisplayLayoutManager
;
17 class DisplaySnapshot
;
18 class NativeDisplayDelegate
;
20 // In order to apply content protection the task executes in the following
23 // a) Query NativeDisplayDelegate for HDCP state on capable displays
24 // b) OnHDCPStateUpdate() called for each display as response to (a)
25 // 2) ApplyProtections()
26 // a) Compute preferred HDCP state for capable displays
27 // b) Call into NativeDisplayDelegate to set HDCP state on capable displays
28 // c) OnHDCPStateApplied() called for each display as reponse to (b)
29 // 3) Call |callback_| to signal end of task.
31 // Note, in steps 1a and 2a, if no HDCP capable displays are found or if errors
32 // are reported, the task finishes early and skips to step 3.
33 class DISPLAY_EXPORT ApplyContentProtectionTask
{
35 typedef base::Callback
<void(bool)> ResponseCallback
;
37 ApplyContentProtectionTask(
38 DisplayLayoutManager
* layout_manager
,
39 NativeDisplayDelegate
* native_display_delegate
,
40 const DisplayConfigurator::ContentProtections
& requests
,
41 const ResponseCallback
& callback
);
42 ~ApplyContentProtectionTask();
47 // Callback to NatvieDisplayDelegate::GetHDCPState()
48 void OnHDCPStateUpdate(int64_t display_id
, bool success
, HDCPState state
);
50 // Callback to NativeDisplayDelegate::SetHDCPState()
51 void OnHDCPStateApplied(bool success
);
53 void ApplyProtections();
55 uint32_t GetDesiredProtectionMask(int64_t display_id
) const;
57 DisplayLayoutManager
* layout_manager_
; // Not owned.
59 NativeDisplayDelegate
* native_display_delegate_
; // Not owned.
61 DisplayConfigurator::ContentProtections requests_
;
63 // Callback used to respond once the task finishes.
64 ResponseCallback callback_
;
66 // Mapping between display IDs and the HDCP state returned by
67 // NativeDisplayDelegate.
68 std::map
<int64_t, HDCPState
> display_hdcp_state_map_
;
70 // Tracks the status of the NativeDisplayDelegate responses. This will be true
71 // if all the queries were successful, false otherwise.
74 // Tracks the number of NativeDisplayDelegate requests sent but not answered
76 size_t pending_requests_
;
78 base::WeakPtrFactory
<ApplyContentProtectionTask
> weak_ptr_factory_
;
80 DISALLOW_COPY_AND_ASSIGN(ApplyContentProtectionTask
);
85 #endif // UI_DISPLAY_CHROMEOS_APPLY_CONTENT_PROTECTION_TASK_H_