Skip to content

Commit

Permalink
Introduce controller for notification widget ownership in RemoteActiv…
Browse files Browse the repository at this point in the history
…ityNotificationViewController

Bug: b/293067991
Change-Id: I2fa55840166ee7201ecf3fac1312820d83039614
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4916239
Reviewed-by: Sergey Poromov <poromov@chromium.org>
Reviewed-by: Jeroen Dhollander <jeroendh@google.com>
Commit-Queue: Ashutosh Singhal <macinashutosh@google.com>
Cr-Commit-Position: refs/heads/main@{#1210773}
  • Loading branch information
Ashutosh Singhal authored and Chromium LUCI CQ committed Oct 17, 2023
1 parent 24fe229 commit 1940234
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "ui/compositor/layer.h"
#include "ui/views/widget/widget.h"

namespace policy {

Expand All @@ -33,19 +34,41 @@ views::Widget::InitParams GetWidgetInitParams(aura::Window* parent) {

std::unique_ptr<views::Widget> CreateWidget(
aura::Window* parent,
std::unique_ptr<views::View> contents) {
std::unique_ptr<views::View> contents,
const gfx::Rect widget_bounds) {
auto widget = std::make_unique<views::Widget>();
widget->Init(GetWidgetInitParams(parent));
widget->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
widget->SetContentsView(std::move(contents));
widget->SetSize(gfx::Size(400, 200));
widget->SetBounds(widget_bounds);
widget->GetNativeWindow()->SetId(
ash::kShellWindowId_AdminWasPresentNotificationWindow);
return widget;
}

aura::Window* GetWidgetParentContainer() {
return ash::Shell::GetPrimaryRootWindow()->GetChildById(
ash::kShellWindowId_LockScreenContainersContainer);
}

gfx::Rect GetFullscreenBounds() {
return ash::Shell::GetPrimaryRootWindow()->GetBoundsInRootWindow();
}

} // namespace

class RemoteActivityNotificationController::WidgetController {
public:
explicit WidgetController(std::unique_ptr<views::Widget> widget)
: widget_(std::move(widget)) {
widget_->Show();
}
~WidgetController() { widget_->Hide(); }

private:
std::unique_ptr<views::Widget> widget_;
};

RemoteActivityNotificationController::RemoteActivityNotificationController(
PrefService& local_state,
base::RepeatingCallback<bool()> is_current_session_curtained)
Expand Down Expand Up @@ -75,10 +98,7 @@ void RemoteActivityNotificationController::ClickNotificationButtonForTesting() {
}

void RemoteActivityNotificationController::OnNotificationCloseButtonClick() {
if (widget_) {
widget_->Hide();
widget_.reset();
}
HideNotification();

// To make sure remote admin cannot dismiss the notification permanently
// themselves by starting a new session.
Expand All @@ -99,15 +119,18 @@ void RemoteActivityNotificationController::ShowNotification() {
CHECK(ash::Shell::HasInstance());
CHECK(ash::Shell::GetPrimaryRootWindow()->GetRootWindow());

widget_ = CreateWidget(
ash::Shell::GetPrimaryRootWindow()->GetChildById(
ash::kShellWindowId_LockScreenContainersContainer),
auto notification_view =
std::make_unique<RemoteActivityNotificationView>(base::BindRepeating(
&RemoteActivityNotificationController::OnNotificationCloseButtonClick,
base::Unretained(this))));
widget_->Show();
widget_->SetBounds(
ash::Shell::GetPrimaryRootWindow()->GetBoundsInRootWindow());
base::Unretained(this)));

widget_controller_ = std::make_unique<WidgetController>(
CreateWidget(GetWidgetParentContainer(), std::move(notification_view),
GetFullscreenBounds()));
}

void RemoteActivityNotificationController::HideNotification() {
widget_controller_ = nullptr;
}

} // namespace policy
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#define CHROME_BROWSER_ASH_POLICY_REMOTE_COMMANDS_REMOTE_ACTIVITY_NOTIFICATION_CONTROLLER_H_

#include "base/memory/raw_ref.h"
#include "base/scoped_observation.h"
#include "components/prefs/pref_service.h"
#include "components/session_manager/core/session_manager.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "ui/views/widget/widget.h"

namespace policy {

Expand All @@ -29,14 +29,17 @@ class RemoteActivityNotificationController
void ClickNotificationButtonForTesting();

private:
class WidgetController;

void OnNotificationCloseButtonClick();

void Init();

void ShowNotification();
void HideNotification();

raw_ref<PrefService> local_state_;
std::unique_ptr<views::Widget> widget_;
std::unique_ptr<WidgetController> widget_controller_;
base::RepeatingCallback<bool()> is_current_session_curtained_;
base::ScopedObservation<session_manager::SessionManager,
session_manager::SessionManagerObserver>
Expand Down

0 comments on commit 1940234

Please sign in to comment.