Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: ui/display/manager/chromeos/display_configurator.cc

Issue 2675743002: PPAPI: Make output protection API work with mus+ash (Closed)
Patch Set: Addressed review issues Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/display/manager/chromeos/display_configurator.h" 5 #include "ui/display/manager/chromeos/display_configurator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 weak_ptr_factory_(this) {} 483 weak_ptr_factory_(this) {}
484 484
485 DisplayConfigurator::~DisplayConfigurator() { 485 DisplayConfigurator::~DisplayConfigurator() {
486 if (native_display_delegate_) 486 if (native_display_delegate_)
487 native_display_delegate_->RemoveObserver(this); 487 native_display_delegate_->RemoveObserver(this);
488 488
489 CallAndClearInProgressCallbacks(false); 489 CallAndClearInProgressCallbacks(false);
490 CallAndClearQueuedCallbacks(false); 490 CallAndClearQueuedCallbacks(false);
491 491
492 while (!query_protection_callbacks_.empty()) { 492 while (!query_protection_callbacks_.empty()) {
493 query_protection_callbacks_.front().Run(QueryProtectionResponse()); 493 query_protection_callbacks_.front().Run(false, 0, 0);
494 query_protection_callbacks_.pop(); 494 query_protection_callbacks_.pop();
495 } 495 }
496 496
497 while (!enable_protection_callbacks_.empty()) { 497 while (!set_protection_callbacks_.empty()) {
498 enable_protection_callbacks_.front().Run(false); 498 set_protection_callbacks_.front().Run(false);
499 enable_protection_callbacks_.pop(); 499 set_protection_callbacks_.pop();
500 } 500 }
501 } 501 }
502 502
503 void DisplayConfigurator::SetDelegateForTesting( 503 void DisplayConfigurator::SetDelegateForTesting(
504 std::unique_ptr<NativeDisplayDelegate> display_delegate) { 504 std::unique_ptr<NativeDisplayDelegate> display_delegate) {
505 DCHECK(!native_display_delegate_); 505 DCHECK(!native_display_delegate_);
506 506
507 native_display_delegate_ = std::move(display_delegate); 507 native_display_delegate_ = std::move(display_delegate);
508 configure_display_ = true; 508 configure_display_ = true;
509 } 509 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 634
635 configuration_task_.reset(new UpdateDisplayConfigurationTask( 635 configuration_task_.reset(new UpdateDisplayConfigurationTask(
636 native_display_delegate_.get(), layout_manager_.get(), 636 native_display_delegate_.get(), layout_manager_.get(),
637 requested_display_state_, requested_power_state_, 637 requested_display_state_, requested_power_state_,
638 kSetDisplayPowerForceProbe, background_color_argb, true, 638 kSetDisplayPowerForceProbe, background_color_argb, true,
639 base::Bind(&DisplayConfigurator::OnConfigured, 639 base::Bind(&DisplayConfigurator::OnConfigured,
640 weak_ptr_factory_.GetWeakPtr()))); 640 weak_ptr_factory_.GetWeakPtr())));
641 configuration_task_->Run(); 641 configuration_task_->Run();
642 } 642 }
643 643
644 DisplayConfigurator::ContentProtectionClientId 644 uint64_t DisplayConfigurator::RegisterContentProtectionClient() {
645 DisplayConfigurator::RegisterContentProtectionClient() {
646 if (!configure_display_ || display_externally_controlled_) 645 if (!configure_display_ || display_externally_controlled_)
647 return kInvalidClientId; 646 return INVALID_CLIENT_ID;
648 647
649 return next_display_protection_client_id_++; 648 return next_display_protection_client_id_++;
650 } 649 }
651 650
652 void DisplayConfigurator::UnregisterContentProtectionClient( 651 void DisplayConfigurator::UnregisterContentProtectionClient(
653 ContentProtectionClientId client_id) { 652 uint64_t client_id) {
654 client_protection_requests_.erase(client_id); 653 client_protection_requests_.erase(client_id);
655 654
656 ContentProtections protections; 655 ContentProtections protections;
657 for (const auto& requests_pair : client_protection_requests_) { 656 for (const auto& requests_pair : client_protection_requests_) {
658 for (const auto& protections_pair : requests_pair.second) { 657 for (const auto& protections_pair : requests_pair.second) {
659 protections[protections_pair.first] |= protections_pair.second; 658 protections[protections_pair.first] |= protections_pair.second;
660 } 659 }
661 } 660 }
662 661
663 enable_protection_callbacks_.push(base::Bind(&DoNothing)); 662 set_protection_callbacks_.push(base::Bind(&DoNothing));
664 ApplyContentProtectionTask* task = new ApplyContentProtectionTask( 663 ApplyContentProtectionTask* task = new ApplyContentProtectionTask(
665 layout_manager_.get(), native_display_delegate_.get(), protections, 664 layout_manager_.get(), native_display_delegate_.get(), protections,
666 base::Bind(&DisplayConfigurator::OnContentProtectionClientUnregistered, 665 base::Bind(&DisplayConfigurator::OnContentProtectionClientUnregistered,
667 weak_ptr_factory_.GetWeakPtr())); 666 weak_ptr_factory_.GetWeakPtr()));
668 content_protection_tasks_.push( 667 content_protection_tasks_.push(
669 base::Bind(&ApplyContentProtectionTask::Run, base::Owned(task))); 668 base::Bind(&ApplyContentProtectionTask::Run, base::Owned(task)));
670 669
671 if (content_protection_tasks_.size() == 1) 670 if (content_protection_tasks_.size() == 1)
672 content_protection_tasks_.front().Run(); 671 content_protection_tasks_.front().Run();
673 } 672 }
674 673
675 void DisplayConfigurator::OnContentProtectionClientUnregistered(bool success) { 674 void DisplayConfigurator::OnContentProtectionClientUnregistered(bool success) {
676 DCHECK(!content_protection_tasks_.empty()); 675 DCHECK(!content_protection_tasks_.empty());
677 content_protection_tasks_.pop(); 676 content_protection_tasks_.pop();
678 677
679 DCHECK(!enable_protection_callbacks_.empty()); 678 DCHECK(!set_protection_callbacks_.empty());
680 EnableProtectionCallback callback = enable_protection_callbacks_.front(); 679 SetProtectionCallback callback = set_protection_callbacks_.front();
681 enable_protection_callbacks_.pop(); 680 set_protection_callbacks_.pop();
682 681
683 if (!content_protection_tasks_.empty()) 682 if (!content_protection_tasks_.empty())
684 content_protection_tasks_.front().Run(); 683 content_protection_tasks_.front().Run();
685 } 684 }
686 685
687 void DisplayConfigurator::QueryContentProtectionStatus( 686 void DisplayConfigurator::QueryContentProtectionStatus(
688 ContentProtectionClientId client_id, 687 uint64_t client_id,
689 int64_t display_id, 688 int64_t display_id,
690 const QueryProtectionCallback& callback) { 689 const QueryProtectionCallback& callback) {
691 // Exclude virtual displays so that protected content will not be recaptured 690 // Exclude virtual displays so that protected content will not be recaptured
692 // through the cast stream. 691 // through the cast stream.
693 for (const DisplaySnapshot* display : cached_displays_) { 692 for (const DisplaySnapshot* display : cached_displays_) {
694 if (display->display_id() == display_id && 693 if (display->display_id() == display_id &&
695 !IsPhysicalDisplayType(display->type())) { 694 !IsPhysicalDisplayType(display->type())) {
696 callback.Run(QueryProtectionResponse()); 695 callback.Run(false, 0, 0);
697 return; 696 return;
698 } 697 }
699 } 698 }
700 699
701 if (!configure_display_ || display_externally_controlled_) { 700 if (!configure_display_ || display_externally_controlled_) {
702 callback.Run(QueryProtectionResponse()); 701 callback.Run(false, 0, 0);
703 return; 702 return;
704 } 703 }
705 704
706 query_protection_callbacks_.push(callback); 705 query_protection_callbacks_.push(callback);
707 QueryContentProtectionTask* task = new QueryContentProtectionTask( 706 QueryContentProtectionTask* task = new QueryContentProtectionTask(
708 layout_manager_.get(), native_display_delegate_.get(), display_id, 707 layout_manager_.get(), native_display_delegate_.get(), display_id,
709 base::Bind(&DisplayConfigurator::OnContentProtectionQueried, 708 base::Bind(&DisplayConfigurator::OnContentProtectionQueried,
710 weak_ptr_factory_.GetWeakPtr(), client_id, display_id)); 709 weak_ptr_factory_.GetWeakPtr(), client_id, display_id));
711 content_protection_tasks_.push( 710 content_protection_tasks_.push(
712 base::Bind(&QueryContentProtectionTask::Run, base::Owned(task))); 711 base::Bind(&QueryContentProtectionTask::Run, base::Owned(task)));
713 if (content_protection_tasks_.size() == 1) 712 if (content_protection_tasks_.size() == 1)
714 content_protection_tasks_.front().Run(); 713 content_protection_tasks_.front().Run();
715 } 714 }
716 715
717 void DisplayConfigurator::OnContentProtectionQueried( 716 void DisplayConfigurator::OnContentProtectionQueried(
718 ContentProtectionClientId client_id, 717 uint64_t client_id,
719 int64_t display_id, 718 int64_t display_id,
720 QueryContentProtectionTask::Response task_response) { 719 QueryContentProtectionTask::Response task_response) {
721 QueryProtectionResponse response; 720 bool success = task_response.success;
722 response.success = task_response.success; 721 uint32_t link_mask = task_response.link_mask;
723 response.link_mask = task_response.link_mask; 722 uint32_t protection_mask = 0;
724 723
725 // Don't reveal protections requested by other clients. 724 // Don't reveal protections requested by other clients.
726 ProtectionRequests::iterator it = client_protection_requests_.find(client_id); 725 ProtectionRequests::iterator it = client_protection_requests_.find(client_id);
727 if (response.success && it != client_protection_requests_.end()) { 726 if (success && it != client_protection_requests_.end()) {
728 uint32_t requested_mask = 0; 727 uint32_t requested_mask = 0;
729 if (it->second.find(display_id) != it->second.end()) 728 if (it->second.find(display_id) != it->second.end())
730 requested_mask = it->second[display_id]; 729 requested_mask = it->second[display_id];
731 response.protection_mask = 730 protection_mask =
732 task_response.enabled & ~task_response.unfulfilled & requested_mask; 731 task_response.enabled & ~task_response.unfulfilled & requested_mask;
733 } 732 }
734 733
735 DCHECK(!content_protection_tasks_.empty()); 734 DCHECK(!content_protection_tasks_.empty());
736 content_protection_tasks_.pop(); 735 content_protection_tasks_.pop();
737 736
738 DCHECK(!query_protection_callbacks_.empty()); 737 DCHECK(!query_protection_callbacks_.empty());
739 QueryProtectionCallback callback = query_protection_callbacks_.front(); 738 QueryProtectionCallback callback = query_protection_callbacks_.front();
740 query_protection_callbacks_.pop(); 739 query_protection_callbacks_.pop();
741 callback.Run(response); 740 callback.Run(success, link_mask, protection_mask);
742 741
743 if (!content_protection_tasks_.empty()) 742 if (!content_protection_tasks_.empty())
744 content_protection_tasks_.front().Run(); 743 content_protection_tasks_.front().Run();
745 } 744 }
746 745
747 void DisplayConfigurator::EnableContentProtection( 746 void DisplayConfigurator::SetContentProtection(
748 ContentProtectionClientId client_id, 747 uint64_t client_id,
749 int64_t display_id, 748 int64_t display_id,
750 uint32_t desired_method_mask, 749 uint32_t desired_method_mask,
751 const EnableProtectionCallback& callback) { 750 const SetProtectionCallback& callback) {
752 if (!configure_display_ || display_externally_controlled_) { 751 if (!configure_display_ || display_externally_controlled_) {
753 callback.Run(false); 752 callback.Run(false);
754 return; 753 return;
755 } 754 }
756 755
757 ContentProtections protections; 756 ContentProtections protections;
758 for (const auto& requests_pair : client_protection_requests_) { 757 for (const auto& requests_pair : client_protection_requests_) {
759 for (const auto& protections_pair : requests_pair.second) { 758 for (const auto& protections_pair : requests_pair.second) {
760 if (requests_pair.first == client_id && 759 if (requests_pair.first == client_id &&
761 protections_pair.first == display_id) 760 protections_pair.first == display_id)
762 continue; 761 continue;
763 762
764 protections[protections_pair.first] |= protections_pair.second; 763 protections[protections_pair.first] |= protections_pair.second;
765 } 764 }
766 } 765 }
767 protections[display_id] |= desired_method_mask; 766 protections[display_id] |= desired_method_mask;
768 767
769 enable_protection_callbacks_.push(callback); 768 set_protection_callbacks_.push(callback);
770 ApplyContentProtectionTask* task = new ApplyContentProtectionTask( 769 ApplyContentProtectionTask* task = new ApplyContentProtectionTask(
771 layout_manager_.get(), native_display_delegate_.get(), protections, 770 layout_manager_.get(), native_display_delegate_.get(), protections,
772 base::Bind(&DisplayConfigurator::OnContentProtectionEnabled, 771 base::Bind(&DisplayConfigurator::OnSetContentProtectionCompleted,
773 weak_ptr_factory_.GetWeakPtr(), client_id, display_id, 772 weak_ptr_factory_.GetWeakPtr(), client_id, display_id,
774 desired_method_mask)); 773 desired_method_mask));
775 content_protection_tasks_.push( 774 content_protection_tasks_.push(
776 base::Bind(&ApplyContentProtectionTask::Run, base::Owned(task))); 775 base::Bind(&ApplyContentProtectionTask::Run, base::Owned(task)));
777 if (content_protection_tasks_.size() == 1) 776 if (content_protection_tasks_.size() == 1)
778 content_protection_tasks_.front().Run(); 777 content_protection_tasks_.front().Run();
779 } 778 }
780 779
781 void DisplayConfigurator::OnContentProtectionEnabled( 780 void DisplayConfigurator::OnSetContentProtectionCompleted(
782 ContentProtectionClientId client_id, 781 uint64_t client_id,
783 int64_t display_id, 782 int64_t display_id,
784 uint32_t desired_method_mask, 783 uint32_t desired_method_mask,
785 bool success) { 784 bool success) {
786 DCHECK(!content_protection_tasks_.empty()); 785 DCHECK(!content_protection_tasks_.empty());
787 content_protection_tasks_.pop(); 786 content_protection_tasks_.pop();
788 787
789 DCHECK(!enable_protection_callbacks_.empty()); 788 DCHECK(!set_protection_callbacks_.empty());
790 EnableProtectionCallback callback = enable_protection_callbacks_.front(); 789 SetProtectionCallback callback = set_protection_callbacks_.front();
791 enable_protection_callbacks_.pop(); 790 set_protection_callbacks_.pop();
792 791
793 if (!success) { 792 if (!success) {
794 callback.Run(false); 793 callback.Run(false);
795 return; 794 return;
796 } 795 }
797 796
798 if (desired_method_mask == CONTENT_PROTECTION_METHOD_NONE) { 797 if (desired_method_mask == CONTENT_PROTECTION_METHOD_NONE) {
799 if (client_protection_requests_.find(client_id) != 798 if (client_protection_requests_.find(client_id) !=
800 client_protection_requests_.end()) { 799 client_protection_requests_.end()) {
801 client_protection_requests_[client_id].erase(display_id); 800 client_protection_requests_[client_id].erase(display_id);
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 last_virtual_display_id_ = max_display_id & 0xff; 1191 last_virtual_display_id_ = max_display_id & 0xff;
1193 1192
1194 return true; 1193 return true;
1195 } 1194 }
1196 1195
1197 bool DisplayConfigurator::IsDisplayOn() const { 1196 bool DisplayConfigurator::IsDisplayOn() const {
1198 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; 1197 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF;
1199 } 1198 }
1200 1199
1201 } // namespace display 1200 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/manager/chromeos/display_configurator.h ('k') | ui/display/manager/chromeos/display_configurator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698