Commit d890119a authored by Toni Barzic's avatar Toni Barzic Committed by Chromium LUCI CQ

Improvements for camera privacy switch UI

When the camera privacy switch state changes, and a toast describing the
new state is shown, cancel the toast for the previous state so it gets
hidden immediately (the new toast is enqueued, so it won't hide the old
one).

Also, do not show toast when the privacy switch state changes from
unknown to off state, so "Camera is on" toast is not shown for the
default initial state.

BUG=1165937

Change-Id: Ief3be58a89b52e17a597475baa1230dc3f2fbd4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626187
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842769}
parent 863abd84
......@@ -5,6 +5,8 @@
#ifndef ASH_PUBLIC_CPP_TOAST_MANAGER_H_
#define ASH_PUBLIC_CPP_TOAST_MANAGER_H_
#include <string>
#include "ash/public/cpp/ash_public_export.h"
namespace ash {
......@@ -20,6 +22,9 @@ class ASH_PUBLIC_EXPORT ToastManager {
// well, and are shown one by one.
virtual void Show(const ToastData& data) = 0;
// Cancels a toast with the provided ID.
virtual void Cancel(const std::string& id) = 0;
protected:
ToastManager();
virtual ~ToastManager();
......
......@@ -28,8 +28,7 @@ class ASH_EXPORT ToastManagerImpl : public ToastManager,
// ToastManager overrides:
void Show(const ToastData& data) override;
void Cancel(const std::string& id);
void Cancel(const std::string& id) override;
// ToastOverlay::Delegate overrides:
void OnClosed() override;
......
......@@ -319,13 +319,12 @@ void MediaClientImpl::OnVmCameraMicActiveChanged(
void MediaClientImpl::OnCameraPrivacySwitchStatusChanged(
cros::mojom::CameraPrivacySwitchState state) {
camera_privacy_switch_state_ = state;
// Show camera privacy switch toast.
switch (state) {
case cros::mojom::CameraPrivacySwitchState::UNKNOWN:
break;
case cros::mojom::CameraPrivacySwitchState::ON: {
ash::ToastManager::Get()->Cancel(kCameraPrivacySwitchOffToastId);
ash::ToastData toast(
kCameraPrivacySwitchOnToastId,
l10n_util::GetStringUTF16(IDS_CAMERA_PRIVACY_SWITCH_ON_TOAST),
......@@ -336,6 +335,13 @@ void MediaClientImpl::OnCameraPrivacySwitchStatusChanged(
break;
}
case cros::mojom::CameraPrivacySwitchState::OFF: {
// Only show the "Camera is on" toast if the privacy switch state changed
// from ON (avoiding the toast when the state changes from UNKNOWN).
if (camera_privacy_switch_state_ !=
cros::mojom::CameraPrivacySwitchState::ON) {
break;
}
ash::ToastManager::Get()->Cancel(kCameraPrivacySwitchOnToastId);
ash::ToastData toast(
kCameraPrivacySwitchOffToastId,
l10n_util::GetStringUTF16(IDS_CAMERA_PRIVACY_SWITCH_OFF_TOAST),
......@@ -347,11 +353,12 @@ void MediaClientImpl::OnCameraPrivacySwitchStatusChanged(
}
}
if (camera_privacy_switch_state_ ==
cros::mojom::CameraPrivacySwitchState::OFF) {
if (state == cros::mojom::CameraPrivacySwitchState::OFF) {
SystemNotificationHelper::GetInstance()->Close(
kCameraPrivacySwitchOnNotificationId);
}
camera_privacy_switch_state_ = state;
}
void MediaClientImpl::OnActiveClientChange(cros::mojom::CameraClientType type,
......
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