Commit 3a066efa authored by Dominik Laskowski's avatar Dominik Laskowski Committed by Commit Bot

chromeos: Clean up OutputProtectionDelegate

This CL changes the type of OutputProtectionDelegate callbacks to
OnceCallback, and fixes an uninitialized member variable.

Bug: 929449
Test: Build
Change-Id: If3bd6cc96fa2056ce59d044e68bc727166a5d720
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1597225
Commit-Queue: Dominik Laskowski <domlaskowski@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671495}
parent 4e86ffc3
...@@ -27,20 +27,20 @@ OutputProtectionControllerAsh::~OutputProtectionControllerAsh() { ...@@ -27,20 +27,20 @@ OutputProtectionControllerAsh::~OutputProtectionControllerAsh() {
manager()->UnregisterClient(client_id_); manager()->UnregisterClient(client_id_);
} }
void OutputProtectionControllerAsh::QueryStatus( void OutputProtectionControllerAsh::QueryStatus(int64_t display_id,
int64_t display_id, QueryStatusCallback callback) {
const OutputProtectionDelegate::QueryStatusCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
manager()->QueryContentProtection(client_id_, display_id, callback); manager()->QueryContentProtection(client_id_, display_id,
std::move(callback));
} }
void OutputProtectionControllerAsh::SetProtection( void OutputProtectionControllerAsh::SetProtection(
int64_t display_id, int64_t display_id,
uint32_t desired_method_mask, uint32_t protection_mask,
const OutputProtectionDelegate::SetProtectionCallback& callback) { SetProtectionCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
manager()->ApplyContentProtection(client_id_, display_id, desired_method_mask, manager()->ApplyContentProtection(client_id_, display_id, protection_mask,
callback); std::move(callback));
} }
} // namespace chromeos } // namespace chromeos
...@@ -20,13 +20,10 @@ class OutputProtectionControllerAsh ...@@ -20,13 +20,10 @@ class OutputProtectionControllerAsh
~OutputProtectionControllerAsh() override; ~OutputProtectionControllerAsh() override;
// OutputProtectionDelegate::Controller: // OutputProtectionDelegate::Controller:
void QueryStatus( void QueryStatus(int64_t display_id, QueryStatusCallback callback) override;
int64_t display_id, void SetProtection(int64_t display_id,
const OutputProtectionDelegate::QueryStatusCallback& callback) override; uint32_t protection_mask,
void SetProtection( SetProtectionCallback callback) override;
int64_t display_id,
uint32_t desired_method_mask,
const OutputProtectionDelegate::SetProtectionCallback& callback) override;
private: private:
const display::ContentProtectionManager::ClientId client_id_; const display::ContentProtectionManager::ClientId client_id_;
......
...@@ -34,17 +34,12 @@ bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) { ...@@ -34,17 +34,12 @@ bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) {
} // namespace } // namespace
OutputProtectionDelegate::Controller::Controller() {} OutputProtectionDelegate::Controller::Controller() = default;
OutputProtectionDelegate::Controller::~Controller() = default;
OutputProtectionDelegate::Controller::~Controller() {}
OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id, OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id,
int render_frame_id) int render_frame_id)
: render_process_id_(render_process_id), : render_process_id_(render_process_id), render_frame_id_(render_frame_id) {
render_frame_id_(render_frame_id),
window_(nullptr),
display_id_(display::kInvalidDisplayId),
weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
display::Screen::GetScreen()->AddObserver(this); display::Screen::GetScreen()->AddObserver(this);
} }
...@@ -85,28 +80,31 @@ void OutputProtectionDelegate::OnWindowDestroying(aura::Window* window) { ...@@ -85,28 +80,31 @@ void OutputProtectionDelegate::OnWindowDestroying(aura::Window* window) {
} }
void OutputProtectionDelegate::QueryStatus( void OutputProtectionDelegate::QueryStatus(
const QueryStatusCallback& callback) { Controller::QueryStatusCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!InitializeControllerIfNecessary()) { if (!InitializeControllerIfNecessary()) {
callback.Run(false, 0, 0); std::move(callback).Run(/*success=*/false,
display::DISPLAY_CONNECTION_TYPE_NONE,
display::CONTENT_PROTECTION_METHOD_NONE);
return; return;
} }
controller_->QueryStatus(display_id_, callback); controller_->QueryStatus(display_id_, std::move(callback));
} }
void OutputProtectionDelegate::SetProtection( void OutputProtectionDelegate::SetProtection(
uint32_t desired_method_mask, uint32_t protection_mask,
const SetProtectionCallback& callback) { Controller::SetProtectionCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!InitializeControllerIfNecessary()) { if (!InitializeControllerIfNecessary()) {
callback.Run(false); std::move(callback).Run(/*success=*/false);
return; return;
} }
controller_->SetProtection(display_id_, desired_method_mask, callback);
desired_method_mask_ = desired_method_mask; controller_->SetProtection(display_id_, protection_mask, std::move(callback));
protection_mask_ = protection_mask;
} }
void OutputProtectionDelegate::OnWindowMayHaveMovedToAnotherDisplay() { void OutputProtectionDelegate::OnWindowMayHaveMovedToAnotherDisplay() {
...@@ -124,9 +122,9 @@ void OutputProtectionDelegate::OnWindowMayHaveMovedToAnotherDisplay() { ...@@ -124,9 +122,9 @@ void OutputProtectionDelegate::OnWindowMayHaveMovedToAnotherDisplay() {
if (display_id_ == new_display_id) if (display_id_ == new_display_id)
return; return;
if (desired_method_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) { if (protection_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) {
DCHECK(controller_); DCHECK(controller_);
controller_->SetProtection(new_display_id, desired_method_mask_, controller_->SetProtection(new_display_id, protection_mask_,
base::DoNothing()); base::DoNothing());
controller_->SetProtection(display_id_, controller_->SetProtection(display_id_,
display::CONTENT_PROTECTION_METHOD_NONE, display::CONTENT_PROTECTION_METHOD_NONE,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/display/display_observer.h" #include "ui/display/display_observer.h"
#include "ui/display/types/display_constants.h"
namespace chromeos { namespace chromeos {
...@@ -22,11 +23,23 @@ namespace chromeos { ...@@ -22,11 +23,23 @@ namespace chromeos {
class OutputProtectionDelegate : public aura::WindowObserver, class OutputProtectionDelegate : public aura::WindowObserver,
public display::DisplayObserver { public display::DisplayObserver {
public: public:
typedef base::Callback<void(bool /* success */, class Controller {
uint32_t /* link_mask */, public:
uint32_t /* protection_mask*/)> using QueryStatusCallback = base::OnceCallback<
QueryStatusCallback; void(bool success, uint32_t connection_mask, uint32_t protection_mask)>;
typedef base::Callback<void(bool /* success */)> SetProtectionCallback; using SetProtectionCallback = base::OnceCallback<void(bool success)>;
Controller();
virtual ~Controller();
virtual void QueryStatus(int64_t display_id,
QueryStatusCallback callback) = 0;
virtual void SetProtection(int64_t display_id,
uint32_t protection_mask,
SetProtectionCallback callback) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Controller);
};
OutputProtectionDelegate(int render_process_id, int render_frame_id); OutputProtectionDelegate(int render_process_id, int render_frame_id);
~OutputProtectionDelegate() override; ~OutputProtectionDelegate() override;
...@@ -40,24 +53,9 @@ class OutputProtectionDelegate : public aura::WindowObserver, ...@@ -40,24 +53,9 @@ class OutputProtectionDelegate : public aura::WindowObserver,
const aura::WindowObserver::HierarchyChangeParams& params) override; const aura::WindowObserver::HierarchyChangeParams& params) override;
void OnWindowDestroying(aura::Window* window) override; void OnWindowDestroying(aura::Window* window) override;
void QueryStatus(const QueryStatusCallback& callback); void QueryStatus(Controller::QueryStatusCallback callback);
void SetProtection(uint32_t desired_method_mask, void SetProtection(uint32_t protection_mask,
const SetProtectionCallback& callback); Controller::SetProtectionCallback callback);
// Display content protection controller interface.
class Controller {
public:
Controller();
virtual ~Controller();
virtual void QueryStatus(int64_t display_id,
const QueryStatusCallback& callback) = 0;
virtual void SetProtection(int64_t display_id,
uint32_t desired_method_mask,
const SetProtectionCallback& callback) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Controller);
};
private: private:
void OnWindowMayHaveMovedToAnotherDisplay(); void OnWindowMayHaveMovedToAnotherDisplay();
...@@ -65,23 +63,23 @@ class OutputProtectionDelegate : public aura::WindowObserver, ...@@ -65,23 +63,23 @@ class OutputProtectionDelegate : public aura::WindowObserver,
bool InitializeControllerIfNecessary(); bool InitializeControllerIfNecessary();
// Used to lookup the WebContents associated with the render frame. // Used to lookup the WebContents associated with the render frame.
int render_process_id_; const int render_process_id_;
int render_frame_id_; const int render_frame_id_;
// Native window being observed. // Native window being observed.
aura::Window* window_; aura::Window* window_ = nullptr;
// The display id which the renderer currently uses. // Display ID of the observed window.
int64_t display_id_; int64_t display_id_ = display::kInvalidDisplayId;
// The last desired method mask. Will enable this mask on new display if // Last requested ContentProtectionMethod bitmask, applied when the observed
// renderer changes display. // window moves to another display.
uint32_t desired_method_mask_; uint32_t protection_mask_ = display::CONTENT_PROTECTION_METHOD_NONE;
// The display content protection controller. // The display content protection controller.
std::unique_ptr<Controller> controller_; std::unique_ptr<Controller> controller_;
base::WeakPtrFactory<OutputProtectionDelegate> weak_ptr_factory_; base::WeakPtrFactory<OutputProtectionDelegate> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(OutputProtectionDelegate); DISALLOW_COPY_AND_ASSIGN(OutputProtectionDelegate);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment