[Sync] Clean up deprecated ProfileSyncService.get(context).
[chromium-blink-merge.git] / ui / display / chromeos / query_content_protection_task.cc
blobd90d55fd9b20621be02c37ad504013eb8868b810
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"
11 namespace ui {
13 QueryContentProtectionTask::QueryContentProtectionTask(
14 DisplayLayoutManager* layout_manager,
15 NativeDisplayDelegate* native_display_delegate,
16 int64_t display_id,
17 const ResponseCallback& callback)
18 : layout_manager_(layout_manager),
19 native_display_delegate_(native_display_delegate),
20 display_id_(display_id),
21 callback_(callback),
22 pending_requests_(0),
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_)
34 continue;
36 response_.link_mask |= display->type();
38 switch (display->type()) {
39 case DISPLAY_CONNECTION_TYPE_UNKNOWN:
40 callback_.Run(response_);
41 return;
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);
46 break;
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.
51 break;
52 case DISPLAY_CONNECTION_TYPE_NONE:
53 NOTREACHED();
54 break;
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()));
66 } else {
67 callback_.Run(response_);
71 void QueryContentProtectionTask::OnHDCPStateUpdate(bool success,
72 HDCPState state) {
73 response_.success &= success;
74 if (state == HDCP_STATE_ENABLED)
75 response_.enabled |= CONTENT_PROTECTION_METHOD_HDCP;
76 else
77 response_.unfulfilled |= CONTENT_PROTECTION_METHOD_HDCP;
79 pending_requests_--;
80 // Wait for all the requests to finish before invoking the callback.
81 if (pending_requests_ != 0)
82 return;
84 callback_.Run(response_);
87 } // namespace ui