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 #include "ui/display/chromeos/query_content_protection_task.h"
7 #include "ui/display/chromeos/display_layout_manager.h"
8 #include "ui/display/types/display_snapshot.h"
9 #include "ui/display/types/native_display_delegate.h"
13 QueryContentProtectionTask::QueryContentProtectionTask(
14 DisplayLayoutManager
* layout_manager
,
15 NativeDisplayDelegate
* native_display_delegate
,
17 const ResponseCallback
& callback
)
18 : layout_manager_(layout_manager
),
19 native_display_delegate_(native_display_delegate
),
20 display_id_(display_id
),
23 weak_ptr_factory_(this) {
26 QueryContentProtectionTask::~QueryContentProtectionTask() {
29 void QueryContentProtectionTask::Run() {
30 std::vector
<DisplaySnapshot
*> hdcp_capable_displays
;
31 for (DisplaySnapshot
* display
: layout_manager_
->GetDisplayStates()) {
32 // Query display if it is in mirror mode or client on the same display.
33 if (!layout_manager_
->IsMirroring() && display
->display_id() != display_id_
)
36 response_
.link_mask
|= display
->type();
38 switch (display
->type()) {
39 case DISPLAY_CONNECTION_TYPE_UNKNOWN
:
40 callback_
.Run(response_
);
42 case DISPLAY_CONNECTION_TYPE_DISPLAYPORT
:
43 case DISPLAY_CONNECTION_TYPE_DVI
:
44 case DISPLAY_CONNECTION_TYPE_HDMI
:
45 hdcp_capable_displays
.push_back(display
);
47 case DISPLAY_CONNECTION_TYPE_INTERNAL
:
48 case DISPLAY_CONNECTION_TYPE_VGA
:
49 case DISPLAY_CONNECTION_TYPE_NETWORK
:
50 // No protections for these types. Do nothing.
52 case DISPLAY_CONNECTION_TYPE_NONE
:
58 response_
.success
= true;
59 pending_requests_
= hdcp_capable_displays
.size();
60 if (pending_requests_
!= 0) {
61 for (DisplaySnapshot
* display
: hdcp_capable_displays
) {
62 native_display_delegate_
->GetHDCPState(
63 *display
, base::Bind(&QueryContentProtectionTask::OnHDCPStateUpdate
,
64 weak_ptr_factory_
.GetWeakPtr()));
67 callback_
.Run(response_
);
71 void QueryContentProtectionTask::OnHDCPStateUpdate(bool success
,
73 response_
.success
&= success
;
74 if (state
== HDCP_STATE_ENABLED
)
75 response_
.enabled
|= CONTENT_PROTECTION_METHOD_HDCP
;
77 response_
.unfulfilled
|= CONTENT_PROTECTION_METHOD_HDCP
;
80 // Wait for all the requests to finish before invoking the callback.
81 if (pending_requests_
!= 0)
84 callback_
.Run(response_
);