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 { ...@@ -200,6 +200,14 @@ bool SessionController::IsUserChild() const {
return active_user_type == user_manager::USER_TYPE_CHILD; 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 { base::Optional<user_manager::UserType> SessionController::GetUserType() const {
if (!IsActiveUserSessionStarted()) if (!IsActiveUserSessionStarted())
return base::nullopt; return base::nullopt;
......
...@@ -116,6 +116,9 @@ class ASH_EXPORT SessionController : public mojom::SessionController { ...@@ -116,6 +116,9 @@ class ASH_EXPORT SessionController : public mojom::SessionController {
// Returns true if the current user is a child account. // Returns true if the current user is a child account.
bool IsUserChild() const; 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 // Returns the type of the current user, or empty if there is no current user
// logged in. // logged in.
base::Optional<user_manager::UserType> GetUserType() const; base::Optional<user_manager::UserType> GetUserType() const;
......
...@@ -17,34 +17,23 @@ ...@@ -17,34 +17,23 @@
namespace ash { namespace ash {
ManagedDeviceView::ManagedDeviceView() : TrayItemView(nullptr) { ManagedDeviceView::ManagedDeviceView() : TrayItemView(nullptr) {
Shell::Get()->system_tray_model()->enterprise_domain()->AddObserver(this);
Shell::Get()->session_controller()->AddObserver(this); Shell::Get()->session_controller()->AddObserver(this);
CreateImageView(); CreateImageView();
Update(); OnLoginStatusChanged(Shell::Get()->session_controller()->login_status());
} }
ManagedDeviceView::~ManagedDeviceView() { ManagedDeviceView::~ManagedDeviceView() {
Shell::Get()->system_tray_model()->enterprise_domain()->RemoveObserver(this);
Shell::Get()->session_controller()->RemoveObserver(this); Shell::Get()->session_controller()->RemoveObserver(this);
} }
void ManagedDeviceView::OnEnterpriseDomainChanged() { void ManagedDeviceView::OnLoginStatusChanged(LoginStatus status) {
EnterpriseDomainModel* model = SessionController* session = Shell::Get()->session_controller();
Shell::Get()->system_tray_model()->enterprise_domain(); if (session->IsUserPublicAccount()) {
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_) {
image_view()->SetImage(gfx::CreateVectorIcon( image_view()->SetImage(gfx::CreateVectorIcon(
kSystemTrayManagedIcon, kSystemTrayManagedIcon,
TrayIconColor(Shell::Get()->session_controller()->GetSessionState()))); TrayIconColor(Shell::Get()->session_controller()->GetSessionState())));
SetVisible(true); SetVisible(true);
} else if (is_child_) { } else if (session->IsUserChild()) {
image_view()->SetImage(gfx::CreateVectorIcon( image_view()->SetImage(gfx::CreateVectorIcon(
kSystemTrayFamilyLinkIcon, kSystemTrayFamilyLinkIcon,
TrayIconColor(Shell::Get()->session_controller()->GetSessionState()))); TrayIconColor(Shell::Get()->session_controller()->GetSessionState())));
...@@ -54,9 +43,4 @@ void ManagedDeviceView::Update() { ...@@ -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 } // namespace ash
...@@ -6,33 +6,24 @@ ...@@ -6,33 +6,24 @@
#define ASH_SYSTEM_UNIFIED_MANAGED_DEVICE_VIEW_H_ #define ASH_SYSTEM_UNIFIED_MANAGED_DEVICE_VIEW_H_
#include "ash/session/session_observer.h" #include "ash/session/session_observer.h"
#include "ash/system/enterprise/enterprise_domain_observer.h"
#include "ash/system/tray/tray_item_view.h" #include "ash/system/tray/tray_item_view.h"
#include "base/macros.h" #include "base/macros.h"
namespace ash { namespace ash {
// A view to show an icon in the status tray when the device is managed by // 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 // an organization admin. Observes login status in order to show/hide the
// show/hide the icon reflecting the latest status. // icon reflecting the latest status.
class ManagedDeviceView : public TrayItemView, class ManagedDeviceView : public TrayItemView,
public EnterpriseDomainObserver,
public SessionObserver { public SessionObserver {
public: public:
ManagedDeviceView(); ManagedDeviceView();
~ManagedDeviceView() override; ~ManagedDeviceView() override;
// EnterpriseDomainObserver:
void OnEnterpriseDomainChanged() override;
// SessionObserver: // SessionObserver:
void OnLoginStatusChanged(LoginStatus status) override; void OnLoginStatusChanged(LoginStatus status) override;
private: private:
void Update();
bool is_child_ = false;
bool is_enterprise_ = false;
DISALLOW_COPY_AND_ASSIGN(ManagedDeviceView); 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