Chromium Code Reviews| Index: chrome/browser/chromeos/display/output_protection_delegate.cc |
| diff --git a/chrome/browser/chromeos/display/output_protection_delegate.cc b/chrome/browser/chromeos/display/output_protection_delegate.cc |
| index 1797d5ff37d3e3cf5d1986f2c0334bae724a2ebc..3adb0cf268b49a0cf6695824fcfebd1c7fc1807f 100644 |
| --- a/chrome/browser/chromeos/display/output_protection_delegate.cc |
| +++ b/chrome/browser/chromeos/display/output_protection_delegate.cc |
| @@ -9,13 +9,23 @@ |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "content/public/common/service_manager_connection.h" |
| +#include "services/service_manager/public/cpp/connector.h" |
| +#include "services/service_manager/runner/common/client_util.h" |
| +#include "services/ui/public/interfaces/display/display_controller.mojom.h" |
| #include "ui/display/display.h" |
| +#include "ui/display/manager/chromeos/display_configurator.h" |
| #include "ui/display/screen.h" |
| +#include "ui/display/types/display_constants.h" |
| namespace chromeos { |
| namespace { |
| +bool IsRunningInMash() { |
| + return service_manager::ServiceManagerIsRemote(); |
| +} |
| + |
| bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| DCHECK(rfh); |
| @@ -33,53 +43,156 @@ bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) { |
| void DoNothing(bool status) { |
| } |
| +// Display content protection controller for running on Aura. |
|
rjkroege
2017/02/09 00:44:43
On Aura? This code already presumes Aura.
This is
sadrul
2017/02/09 02:51:10
Maybe call this ControllerAsh instead (since it ge
Peng
2017/02/10 15:57:02
Done.
|
| +class ControllerAura : public OutputProtectionDelegate::Controller { |
| + public: |
| + ControllerAura() {} |
| + |
| + ~ControllerAura() override { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
|
sadrul
2017/02/09 02:51:10
I suggest using a ThreadChecker instead. (and may
Peng
2017/02/10 15:57:02
Done.
|
| + if (client_id_ == display::DisplayConfigurator::kInvalidClientId) |
| + return; |
| + display::DisplayConfigurator* configurator = |
| + ash::Shell::GetInstance()->display_configurator(); |
| + configurator->UnregisterContentProtectionClient(client_id_); |
| + } |
| + |
| + bool Init() override { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + display::DisplayConfigurator* configurator = |
| + ash::Shell::GetInstance()->display_configurator(); |
| + client_id_ = configurator->RegisterContentProtectionClient(); |
| + return client_id_ != display::DisplayConfigurator::kInvalidClientId; |
| + } |
| + |
| + void QueryStatus( |
| + int64_t display_id, |
| + const OutputProtectionDelegate::QueryStatusCallback& callback) override { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + display::DisplayConfigurator* configurator = |
| + ash::Shell::GetInstance()->display_configurator(); |
| + configurator->QueryContentProtectionStatus(client_id_, display_id, |
| + callback); |
| + } |
| + |
| + void EnableProtection( |
| + int64_t display_id, |
| + uint32_t desired_method_mask, |
| + const OutputProtectionDelegate::EnableProtectionCallback& callback) |
| + override { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + display::DisplayConfigurator* configurator = |
| + ash::Shell::GetInstance()->display_configurator(); |
| + configurator->EnableContentProtection(client_id_, display_id, |
| + desired_method_mask, callback); |
| + } |
| + |
| + private: |
| + display::DisplayConfigurator::ContentProtectionClientId client_id_ = |
| + display::DisplayConfigurator::kInvalidClientId; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ControllerAura); |
| +}; |
| + |
| +// Display content protection controller for running with Mus server. |
| +class ControllerMus : public OutputProtectionDelegate::Controller { |
| + public: |
| + ControllerMus() {} |
| + |
| + ~ControllerMus() override { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + if (client_id_ == display::DisplayConfigurator::kInvalidClientId) |
| + return; |
| + display_controller_->UnregisterContentProtectionClient(client_id_); |
| + } |
| + |
| + bool Init() override { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + content::ServiceManagerConnection::GetForProcess() |
| + ->GetConnector() |
| + ->BindInterface("ui", &display_controller_); |
| + return display_controller_->RegisterContentProtectionClient(&client_id_) && |
| + client_id_ != display::DisplayConfigurator::kInvalidClientId; |
| + } |
| + |
| + void QueryStatus( |
| + int64_t display_id, |
| + const OutputProtectionDelegate::QueryStatusCallback& callback) override { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + display_controller_->QueryContentProtectionStatus(client_id_, display_id, |
| + callback); |
| + } |
| + |
| + void EnableProtection( |
| + int64_t display_id, |
| + uint32_t desired_method_mask, |
| + const OutputProtectionDelegate::EnableProtectionCallback& callback) |
| + override { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + display_controller_->EnableContentProtection(client_id_, display_id, |
| + desired_method_mask, callback); |
| + } |
| + |
| + private: |
| + display::mojom::DisplayControllerPtr display_controller_; |
| + display::DisplayConfigurator::ContentProtectionClientId client_id_ = |
| + display::DisplayConfigurator::kInvalidClientId; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ControllerMus); |
| +}; |
| + |
| } // namespace |
| +OutputProtectionDelegate::Controller::Controller() {} |
| + |
| +OutputProtectionDelegate::Controller::~Controller() {} |
| + |
| OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id, |
| int render_frame_id) |
| : render_process_id_(render_process_id), |
| render_frame_id_(render_frame_id), |
| window_(nullptr), |
| - client_id_(display::DisplayConfigurator::kInvalidClientId), |
| - display_id_(0), |
| + display_id_(display::kInvalidDisplayId), |
| weak_ptr_factory_(this) { |
| // This can be constructed on IO or UI thread. |
| } |
| OutputProtectionDelegate::~OutputProtectionDelegate() { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| - |
| - display::DisplayConfigurator* configurator = |
| - ash::Shell::GetInstance()->display_configurator(); |
| - configurator->UnregisterContentProtectionClient(client_id_); |
| - |
| + controller_.reset(); |
| if (window_) |
| window_->RemoveObserver(this); |
| } |
| -display::DisplayConfigurator::ContentProtectionClientId |
| -OutputProtectionDelegate::GetClientId() { |
| +bool OutputProtectionDelegate::InitializeControllerIfNecessary() { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| - if (client_id_ == display::DisplayConfigurator::kInvalidClientId) { |
| - content::RenderFrameHost* rfh = |
| - content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); |
| - if (!rfh || !GetCurrentDisplayId(rfh, &display_id_)) |
| - return display::DisplayConfigurator::kInvalidClientId; |
| + if (controller_) |
| + return true; |
| - aura::Window* window = rfh->GetNativeView(); |
| - if (!window) |
| - return display::DisplayConfigurator::kInvalidClientId; |
| + content::RenderFrameHost* rfh = |
| + content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); |
| + if (!rfh || !GetCurrentDisplayId(rfh, &display_id_)) |
| + return false; |
| - display::DisplayConfigurator* configurator = |
| - ash::Shell::GetInstance()->display_configurator(); |
| - client_id_ = configurator->RegisterContentProtectionClient(); |
| + aura::Window* window = rfh->GetNativeView(); |
| + if (!window) { |
| + display_id_ = display::kInvalidDisplayId; |
| + return false; |
| + } |
| - if (client_id_ != display::DisplayConfigurator::kInvalidClientId) { |
| - window->AddObserver(this); |
| - window_ = window; |
| - } |
| + if (IsRunningInMash()) |
| + controller_ = base::MakeUnique<ControllerMus>(); |
| + else |
| + controller_ = base::MakeUnique<ControllerAura>(); |
| + if (!controller_->Init()) { |
| + display_id_ = display::kInvalidDisplayId; |
| + controller_.reset(); |
| + return false; |
| } |
| - return client_id_; |
| + |
| + window->AddObserver(this); |
| + window_ = window; |
| + return true; |
| } |
| void OutputProtectionDelegate::QueryStatus( |
| @@ -94,31 +207,30 @@ void OutputProtectionDelegate::QueryStatus( |
| return; |
| } |
| - display::DisplayConfigurator* configurator = |
| - ash::Shell::GetInstance()->display_configurator(); |
| - configurator->QueryContentProtectionStatus( |
| - GetClientId(), display_id_, |
| - base::Bind(&OutputProtectionDelegate::QueryStatusComplete, |
| - weak_ptr_factory_.GetWeakPtr(), callback)); |
| + if (!InitializeControllerIfNecessary()) { |
| + callback.Run(false, 0, 0); |
|
sadrul
2017/02/09 02:51:10
It looks like both calls to InitializeControllerIf
Peng
2017/02/10 15:57:02
I removed sync RegisterContentProtectionClient() m
|
| + return; |
| + } |
| + controller_->QueryStatus(display_id_, callback); |
| } |
| void OutputProtectionDelegate::EnableProtection( |
| uint32_t desired_method_mask, |
| const EnableProtectionCallback& callback) { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| - |
| - display::DisplayConfigurator* configurator = |
| - ash::Shell::GetInstance()->display_configurator(); |
| - configurator->EnableContentProtection( |
| - GetClientId(), display_id_, desired_method_mask, |
| - base::Bind(&OutputProtectionDelegate::EnableProtectionComplete, |
| - weak_ptr_factory_.GetWeakPtr(), callback)); |
| + if (!InitializeControllerIfNecessary()) { |
| + callback.Run(false); |
| + return; |
| + } |
| + controller_->EnableProtection(display_id_, desired_method_mask, callback); |
| desired_method_mask_ = desired_method_mask; |
| } |
| void OutputProtectionDelegate::QueryStatusComplete( |
| const QueryStatusCallback& callback, |
| - const display::DisplayConfigurator::QueryProtectionResponse& response) { |
| + bool success, |
| + uint32_t link_mask, |
| + uint32_t protection_mask) { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| content::RenderFrameHost* rfh = |
| @@ -130,8 +242,7 @@ void OutputProtectionDelegate::QueryStatusComplete( |
| callback.Run(false, 0, 0); |
| return; |
| } |
| - |
| - callback.Run(response.success, response.link_mask, response.protection_mask); |
| + callback.Run(success, link_mask, protection_mask); |
| } |
| void OutputProtectionDelegate::EnableProtectionComplete( |
| @@ -151,22 +262,19 @@ void OutputProtectionDelegate::OnWindowHierarchyChanged( |
| return; |
| } |
| - int64_t new_display_id = 0; |
| + int64_t new_display_id = display::kInvalidDisplayId; |
| if (!GetCurrentDisplayId(rfh, &new_display_id)) |
| return; |
| if (display_id_ == new_display_id) |
| return; |
| if (desired_method_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) { |
| - // Display changed and should enable output protections on new display. |
| - display::DisplayConfigurator* configurator = |
| - ash::Shell::GetInstance()->display_configurator(); |
| - configurator->EnableContentProtection(GetClientId(), new_display_id, |
| - desired_method_mask_, |
| - base::Bind(&DoNothing)); |
| - configurator->EnableContentProtection( |
| - GetClientId(), display_id_, display::CONTENT_PROTECTION_METHOD_NONE, |
| - base::Bind(&DoNothing)); |
| + DCHECK(controller_); |
| + controller_->EnableProtection(new_display_id, desired_method_mask_, |
| + base::Bind(&DoNothing)); |
| + controller_->EnableProtection(display_id_, |
| + display::CONTENT_PROTECTION_METHOD_NONE, |
| + base::Bind(&DoNothing)); |
| } |
| display_id_ = new_display_id; |
| } |