Commit 81202dfd authored by Tatsuhisa Yamaguchi's avatar Tatsuhisa Yamaguchi Committed by Commit Bot

Ash: Show managed icon only when in public session mode.

The managed device icon in the system tray should only be shown while
in the public session mode, unlike the "managed" indicator shown in the
unified system tray bubble.

Bug: 895718
Test: manually tested with public session on an enrolled device
Change-Id: Ic86be2a42e5d3a0be89cf5eb6c80aab14bec0f32
Reviewed-on: https://chromium-review.googlesource.com/c/1288093
Commit-Queue: Tatsuhisa Yamaguchi <yamaguchi@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601845}
parent 40e8e763
......@@ -200,6 +200,14 @@ bool SessionController::IsUserChild() const {
return active_user_type == user_manager::USER_TYPE_CHILD;
}
bool SessionController::IsUserPublicAccount() const {
if (!IsActiveUserSessionStarted())
return false;
user_manager::UserType active_user_type = GetUserSession(0)->user_info->type;
return active_user_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT;
}
base::Optional<user_manager::UserType> SessionController::GetUserType() const {
if (!IsActiveUserSessionStarted())
return base::nullopt;
......
......@@ -116,6 +116,9 @@ class ASH_EXPORT SessionController : public mojom::SessionController {
// Returns true if the current user is a child account.
bool IsUserChild() const;
// Returns true if the current user is a public account.
bool IsUserPublicAccount() const;
// Returns the type of the current user, or empty if there is no current user
// logged in.
base::Optional<user_manager::UserType> GetUserType() const;
......
......@@ -17,34 +17,23 @@
namespace ash {
ManagedDeviceView::ManagedDeviceView() : TrayItemView(nullptr) {
Shell::Get()->system_tray_model()->enterprise_domain()->AddObserver(this);
Shell::Get()->session_controller()->AddObserver(this);
CreateImageView();
Update();
OnLoginStatusChanged(Shell::Get()->session_controller()->login_status());
}
ManagedDeviceView::~ManagedDeviceView() {
Shell::Get()->system_tray_model()->enterprise_domain()->RemoveObserver(this);
Shell::Get()->session_controller()->RemoveObserver(this);
}
void ManagedDeviceView::OnEnterpriseDomainChanged() {
EnterpriseDomainModel* model =
Shell::Get()->system_tray_model()->enterprise_domain();
bool old_value = is_enterprise_;
is_enterprise_ = model->active_directory_managed() ||
!model->enterprise_display_domain().empty();
if (is_enterprise_ != old_value)
Update();
}
void ManagedDeviceView::Update() {
if (is_enterprise_) {
void ManagedDeviceView::OnLoginStatusChanged(LoginStatus status) {
SessionController* session = Shell::Get()->session_controller();
if (session->IsUserPublicAccount()) {
image_view()->SetImage(gfx::CreateVectorIcon(
kSystemTrayManagedIcon,
TrayIconColor(Shell::Get()->session_controller()->GetSessionState())));
SetVisible(true);
} else if (is_child_) {
} else if (session->IsUserChild()) {
image_view()->SetImage(gfx::CreateVectorIcon(
kSystemTrayFamilyLinkIcon,
TrayIconColor(Shell::Get()->session_controller()->GetSessionState())));
......@@ -54,9 +43,4 @@ void ManagedDeviceView::Update() {
}
}
void ManagedDeviceView::OnLoginStatusChanged(LoginStatus status) {
SessionController* session = Shell::Get()->session_controller();
is_child_ = status == LoginStatus::SUPERVISED && session->IsUserChild();
}
} // namespace ash
......@@ -6,33 +6,24 @@
#define ASH_SYSTEM_UNIFIED_MANAGED_DEVICE_VIEW_H_
#include "ash/session/session_observer.h"
#include "ash/system/enterprise/enterprise_domain_observer.h"
#include "ash/system/tray/tray_item_view.h"
#include "base/macros.h"
namespace ash {
// A view to show an icon in the status tray when the device is managed by
// an organization admin. Observes change of the enterprise domain in order to
// show/hide the icon reflecting the latest status.
// an organization admin. Observes login status in order to show/hide the
// icon reflecting the latest status.
class ManagedDeviceView : public TrayItemView,
public EnterpriseDomainObserver,
public SessionObserver {
public:
ManagedDeviceView();
~ManagedDeviceView() override;
// EnterpriseDomainObserver:
void OnEnterpriseDomainChanged() override;
// SessionObserver:
void OnLoginStatusChanged(LoginStatus status) override;
private:
void Update();
bool is_child_ = false;
bool is_enterprise_ = false;
DISALLOW_COPY_AND_ASSIGN(ManagedDeviceView);
};
......
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