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() {
manager()->UnregisterClient(client_id_);
}
void OutputProtectionControllerAsh::QueryStatus(
int64_t display_id,
const OutputProtectionDelegate::QueryStatusCallback& callback) {
void OutputProtectionControllerAsh::QueryStatus(int64_t display_id,
QueryStatusCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
manager()->QueryContentProtection(client_id_, display_id, callback);
manager()->QueryContentProtection(client_id_, display_id,
std::move(callback));
}
void OutputProtectionControllerAsh::SetProtection(
int64_t display_id,
uint32_t desired_method_mask,
const OutputProtectionDelegate::SetProtectionCallback& callback) {
uint32_t protection_mask,
SetProtectionCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
manager()->ApplyContentProtection(client_id_, display_id, desired_method_mask,
callback);
manager()->ApplyContentProtection(client_id_, display_id, protection_mask,
std::move(callback));
}
} // namespace chromeos
......@@ -20,13 +20,10 @@ class OutputProtectionControllerAsh
~OutputProtectionControllerAsh() override;
// OutputProtectionDelegate::Controller:
void QueryStatus(
int64_t display_id,
const OutputProtectionDelegate::QueryStatusCallback& callback) override;
void SetProtection(
int64_t display_id,
uint32_t desired_method_mask,
const OutputProtectionDelegate::SetProtectionCallback& callback) override;
void QueryStatus(int64_t display_id, QueryStatusCallback callback) override;
void SetProtection(int64_t display_id,
uint32_t protection_mask,
SetProtectionCallback callback) override;
private:
const display::ContentProtectionManager::ClientId client_id_;
......
......@@ -34,17 +34,12 @@ bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) {
} // namespace
OutputProtectionDelegate::Controller::Controller() {}
OutputProtectionDelegate::Controller::~Controller() {}
OutputProtectionDelegate::Controller::Controller() = default;
OutputProtectionDelegate::Controller::~Controller() = default;
OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id,
int render_frame_id)
: render_process_id_(render_process_id),
render_frame_id_(render_frame_id),
window_(nullptr),
display_id_(display::kInvalidDisplayId),
weak_ptr_factory_(this) {
: render_process_id_(render_process_id), render_frame_id_(render_frame_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
display::Screen::GetScreen()->AddObserver(this);
}
......@@ -85,28 +80,31 @@ void OutputProtectionDelegate::OnWindowDestroying(aura::Window* window) {
}
void OutputProtectionDelegate::QueryStatus(
const QueryStatusCallback& callback) {
Controller::QueryStatusCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!InitializeControllerIfNecessary()) {
callback.Run(false, 0, 0);
std::move(callback).Run(/*success=*/false,
display::DISPLAY_CONNECTION_TYPE_NONE,
display::CONTENT_PROTECTION_METHOD_NONE);
return;
}
controller_->QueryStatus(display_id_, callback);
controller_->QueryStatus(display_id_, std::move(callback));
}
void OutputProtectionDelegate::SetProtection(
uint32_t desired_method_mask,
const SetProtectionCallback& callback) {
uint32_t protection_mask,
Controller::SetProtectionCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!InitializeControllerIfNecessary()) {
callback.Run(false);
std::move(callback).Run(/*success=*/false);
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() {
......@@ -124,9 +122,9 @@ void OutputProtectionDelegate::OnWindowMayHaveMovedToAnotherDisplay() {
if (display_id_ == new_display_id)
return;
if (desired_method_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) {
if (protection_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) {
DCHECK(controller_);
controller_->SetProtection(new_display_id, desired_method_mask_,
controller_->SetProtection(new_display_id, protection_mask_,
base::DoNothing());
controller_->SetProtection(display_id_,
display::CONTENT_PROTECTION_METHOD_NONE,
......
......@@ -14,6 +14,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/display/display_observer.h"
#include "ui/display/types/display_constants.h"
namespace chromeos {
......@@ -22,11 +23,23 @@ namespace chromeos {
class OutputProtectionDelegate : public aura::WindowObserver,
public display::DisplayObserver {
public:
typedef base::Callback<void(bool /* success */,
uint32_t /* link_mask */,
uint32_t /* protection_mask*/)>
QueryStatusCallback;
typedef base::Callback<void(bool /* success */)> SetProtectionCallback;
class Controller {
public:
using QueryStatusCallback = base::OnceCallback<
void(bool success, uint32_t connection_mask, uint32_t protection_mask)>;
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() override;
......@@ -40,24 +53,9 @@ class OutputProtectionDelegate : public aura::WindowObserver,
const aura::WindowObserver::HierarchyChangeParams& params) override;
void OnWindowDestroying(aura::Window* window) override;
void QueryStatus(const QueryStatusCallback& callback);
void SetProtection(uint32_t desired_method_mask,
const 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);
};
void QueryStatus(Controller::QueryStatusCallback callback);
void SetProtection(uint32_t protection_mask,
Controller::SetProtectionCallback callback);
private:
void OnWindowMayHaveMovedToAnotherDisplay();
......@@ -65,23 +63,23 @@ class OutputProtectionDelegate : public aura::WindowObserver,
bool InitializeControllerIfNecessary();
// Used to lookup the WebContents associated with the render frame.
int render_process_id_;
int render_frame_id_;
const int render_process_id_;
const int render_frame_id_;
// Native window being observed.
aura::Window* window_;
aura::Window* window_ = nullptr;
// The display id which the renderer currently uses.
int64_t display_id_;
// Display ID of the observed window.
int64_t display_id_ = display::kInvalidDisplayId;
// The last desired method mask. Will enable this mask on new display if
// renderer changes display.
uint32_t desired_method_mask_;
// Last requested ContentProtectionMethod bitmask, applied when the observed
// window moves to another display.
uint32_t protection_mask_ = display::CONTENT_PROTECTION_METHOD_NONE;
// The display content protection controller.
std::unique_ptr<Controller> controller_;
base::WeakPtrFactory<OutputProtectionDelegate> weak_ptr_factory_;
base::WeakPtrFactory<OutputProtectionDelegate> weak_ptr_factory_{this};
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